fix(places): follow-ups from the review of the schemeless website fix

create_place_accommodation refused the whole booking again once its website
went through the place contract, for '' and free text as well, which it always
took. It keeps its old input schema now and leaves a website off when the
contract refuses it, so a bare host still gains https and a script link is
still not stored.

normalizePlaceWebsite keeps an http or https value whenever a browser opens it,
the way the write contract does, so a plugin or source answering with an
intranet host, an IPv6 literal or a trailing dot keeps its website. The dot
check only tells a bare host from a word. A details row cached before the fix
(a week for Google and Amap, until a refresh for an expanded one) hands its
website out through the same helper.

Tests: SHARED-WEBSITE-007 adjusted, SHARED-WEBSITE-013 and 014,
MCP-ACCOM-2483-01 narrowed, MCP-ACCOM-2483-02, MAPS-2483-06 and 07, AMAP-079,
PLUGIN-SEARCH-2483-02.
This commit is contained in:
Maurice
2026-09-23 21:25:02 +02:00
parent 2350c3ae14
commit 1423ba8933
8 changed files with 147 additions and 23 deletions
@@ -93,8 +93,7 @@ export class AccommodationsMcp {
google_ftid: z.string().optional().describe('Google Maps feature ID from search_place — enables direct Google Maps links'),
osm_id: z.string().optional().describe('OpenStreetMap ID from search_place (e.g. "way:12345")'),
place_notes: z.string().max(2000).optional().describe('Notes for the place'),
// The place contract create_place uses: a bare host gains https (#2483).
website: placeWebsiteSchema.optional(),
website: z.string().max(500).optional(),
phone: z.string().max(50).optional(),
start_day_id: z.number().int().positive().describe('Check-in day ID'),
end_day_id: z.number().int().positive().describe('Check-out day ID'),
@@ -124,9 +123,13 @@ export class AccommodationsMcp {
if (!this.guards.hasTripPermission('day_edit', tripId, ctx.userId)) return permissionDenied();
const dayErrors = this.accommodations.validateAccommodationRefs(tripId, undefined, start_day_id, end_day_id);
if (dayErrors.length > 0) return { content: [{ type: 'text' as const, text: dayErrors.map(e => e.message).join(', ') }], isError: true };
// The website takes the place contract create_place uses, so a bare host
// gains https (#2483). A value that contract refuses is left off instead of
// failing the booking: this tool always took any text here, '' as none.
const site = website ? placeWebsiteSchema.safeParse(website) : null;
try {
const result = this.db.transaction(() => {
const place = this.places.create(String(tripId), { name, description, lat, lng, address, category_id, google_place_id, google_ftid, osm_id, notes: place_notes, website, phone, price, currency });
const place = this.places.create(String(tripId), { name, description, lat, lng, address, category_id, google_place_id, google_ftid, osm_id, notes: place_notes, website: site?.success ? site.data : undefined, phone, price, currency });
const { accommodation, mirror } = this.accommodations.createAccommodation(tripId, { place_id: place.id, start_day_id, end_day_id, check_in, check_in_end, check_out, confirmation, notes: accommodation_notes });
return { place, accommodation, mirror };
});
+14 -3
View File
@@ -672,6 +672,17 @@ export const PLACES_PROVIDER_SETTING = 'places_provider';
*/
export const PLACES_GOOGLE_ONLY_SETTING = 'places_google_only';
/**
* A details row as the cache holds it. A row written before #2483 still has a
* source's website as it came, `www.hotel.cn` from Amap for one, and keeps for a
* week (an expanded one until a refresh), so the website is normalized on the
* way out of the cache as well as on the way in.
*/
function cachedDetails(payload: string): Record<string, unknown> | null {
const place = JSON.parse(payload) as Record<string, unknown> | null;
return place && 'website' in place ? { ...place, website: normalizePlaceWebsite(place.website) } : place;
}
/**
* Whoever holds the keyed slot beside the index for one request: Google's
* credential, an Amap provider, or nobody (the OpenStreetMap stack alone).
@@ -2532,7 +2543,7 @@ export class MapsService {
placeId,
langKey,
);
if (cached && Date.now() - cached.fetched_at < DETAILS_TTL) return { place: JSON.parse(cached.payload_json) };
if (cached && Date.now() - cached.fetched_at < DETAILS_TTL) return { place: cachedDetails(cached.payload_json) };
// Closes the autocomplete session this lookup belongs to, so Google bills
// the search once instead of per keystroke. A cache hit above never reaches
@@ -2625,7 +2636,7 @@ export class MapsService {
placeId,
langKey,
);
if (cached && Date.now() - cached.fetched_at < DETAILS_TTL) return { place: JSON.parse(cached.payload_json) };
if (cached && Date.now() - cached.fetched_at < DETAILS_TTL) return { place: cachedDetails(cached.payload_json) };
const place = await provider.placeDetails(placeId, lang);
if (!place) return { place: null };
@@ -2681,7 +2692,7 @@ export class MapsService {
placeId,
langKey,
);
if (cached) return { place: JSON.parse(cached.payload_json) };
if (cached) return { place: cachedDetails(cached.payload_json) };
}
const response = await googleFetch(