mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
fix(maps): name the index as the source, and stop it being asked twice
Attribution first, because this branch argues the point itself: the card names the sources with the comment that naming them is a licence obligation rather than decoration, and the copy beside it promises that every field says where it came from. The POI path then stamped Overture rows as OpenStreetMap. Overture is not OpenStreetMap — it carries OSM among other sources under other licences — so that is a wrong attribution rather than a rounded one. The wire contract keeps `source` an open string and nothing on the client switches on it, so saying `trek-places` costs nothing. The MCP tool description no longer calls itself an OpenStreetMap tool either, and says which source answered. Adding one place cost two round trips to the index. The details lookup fetches the place and its answer carries the description; toPlaceRecord dropped that field, so the enrichment fetched the same place again a moment later to read it. It is carried through now and read from what the caller already has, with the second lookup left as the fallback for when there is nothing to read. That description's source URL becomes an href on the client and was taken on `typeof === 'string'` alone. It now goes through the same allow-list a place's website goes through — the file already does this for menu_url, with the comment explaining why — so anything but http(s) loses the link and keeps the text. The instance token was hashed from raw APP_URL, which the shipped compose file leaves commented out. Every default install therefore sent the same token, and a token every caller shares is not a caller: one instance running a large import would rate-limit all the others, who would fall back to Nominatim with nothing to point at. getAppUrl() falls through to ALLOWED_ORIGINS and then to the port, so unconfigured instances still differ. Two client-side leaks. A pick made out of the offline cache was recorded into the shadow corpus, where it moved the two figures the corpus exists to measure — and offline is a setting, so the network is usually reachable and the row landed. And the prefetch never re-checked the session after its request came back: a logout in that window repoints the handle at the anonymous database, so one person's trip area was written where the next person's offline search reads. The cache path also ignored the abort signal, so an answer for a keystroke two keystrokes old could overwrite a newer suggestion list. It rejects the way both surfaces already know to swallow. Left alone, and said in a comment rather than hidden: the index cannot localise. The Overpass path picks name:<lang> and falls back to int_name; the service has no language parameter at all, so a German reader exploring Tokyo gets the Japanese primary names on this path.
This commit is contained in:
@@ -261,7 +261,13 @@ export interface OverpassPoi {
|
||||
phone: string | null;
|
||||
opening_hours: string | null;
|
||||
cuisine: string | null;
|
||||
source: 'openstreetmap';
|
||||
/**
|
||||
* Which index the row came from. Overture is not OpenStreetMap: it carries
|
||||
* OSM among other sources under other licences, so a row from the TREK index
|
||||
* says so rather than borrowing OSM's name. The wire contract keeps this an
|
||||
* open string, so widening it here breaks nothing.
|
||||
*/
|
||||
source: 'openstreetmap' | 'trek-places';
|
||||
}
|
||||
|
||||
// Each pill category → the OSM tag selectors it searches. Keys here are the
|
||||
|
||||
@@ -89,7 +89,7 @@ export class MapsMcp {
|
||||
*/
|
||||
@Tool({
|
||||
name: 'search_pois',
|
||||
description: 'List OpenStreetMap points of interest of one category inside a map rectangle, with address, opening hours, website, phone and cuisine wherever OSM carries them. This is the discovery tool: use it to answer "what is around here" for a neighbourhood or a whole city district. Prefer search_place when the user already named the place they mean. Never calls Google, so it costs nothing and works on an instance with no Places key.',
|
||||
description: 'List points of interest of one category inside a map rectangle, with address, opening hours, website, phone and cuisine wherever the source carries them. Answers from the TREK place index where it can and from OpenStreetMap otherwise; each result names which one it came from in its `source` field. This is the discovery tool: use it to answer "what is around here" for a neighbourhood or a whole city district. Prefer search_place when the user already named the place they mean. Never calls Google, so it costs nothing and works on an instance with no Places key.',
|
||||
inputSchema: {
|
||||
category: z.enum(POI_CATEGORY_KEYS).describe('Which kind of place to look for'),
|
||||
bbox: z.object({
|
||||
|
||||
@@ -434,7 +434,13 @@ interface OverpassPoiElement {
|
||||
|
||||
interface PoiSearchResult {
|
||||
pois: OverpassPoi[];
|
||||
source: 'openstreetmap';
|
||||
/**
|
||||
* Which index answered. Not decoration: this branch calls naming the sources
|
||||
* a licence obligation rather than a courtesy, and Overture carries more than
|
||||
* OpenStreetMap under more than one licence, so stamping its rows as OSM is a
|
||||
* wrong attribution rather than a rounding of one.
|
||||
*/
|
||||
source: 'openstreetmap' | 'trek-places';
|
||||
truncated: boolean;
|
||||
// True when the requested viewport was too large and got shrunk to a centred
|
||||
// window before querying — the results then cover the middle of the view only.
|
||||
@@ -666,10 +672,17 @@ export class MapsService {
|
||||
});
|
||||
if (found.length > 0) {
|
||||
// Same shape the Overpass path produces, so the client and the map
|
||||
// renderer need no branch. `source` stays 'openstreetmap' because it
|
||||
// is a typed contract the client switches on, and the places are the
|
||||
// same places; where they came from is an implementation detail of
|
||||
// this method, not something the pill should render differently.
|
||||
// renderer need no branch — but named as what it is. Overture is not
|
||||
// OpenStreetMap: it carries OSM among other sources under other
|
||||
// licences, and this branch argues elsewhere that naming a source is
|
||||
// a licence obligation. The wire contract keeps `source` an open
|
||||
// string, so widening it costs nothing.
|
||||
//
|
||||
// One thing the index cannot do is localise. The Overpass path picks
|
||||
// `name:<lang>` and falls back to `int_name`; the service has no
|
||||
// language parameter at all, so a German user exploring Tokyo gets
|
||||
// the Japanese primary names here. Named rather than hidden: whoever
|
||||
// adds localisation upstream should find this comment.
|
||||
return {
|
||||
pois: found.map(p => ({
|
||||
osm_id: `gers:${p.gers}`,
|
||||
@@ -685,9 +698,9 @@ export class MapsService {
|
||||
// The index has no cuisine field, so this null is the truth
|
||||
// rather than a field being dropped on the way through.
|
||||
cuisine: null,
|
||||
source: 'openstreetmap' as const,
|
||||
source: 'trek-places' as const,
|
||||
})),
|
||||
source: 'openstreetmap' as const,
|
||||
source: 'trek-places' as const,
|
||||
truncated: found.length >= 50,
|
||||
// A wide viewport is narrowed here too, and the caller is told so
|
||||
// for the same reason the Overpass path tells it.
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* to configure and no quota to exhaust, so the failure modes are the network
|
||||
* and the service being down, both of which fall back to what TREK did before.
|
||||
*/
|
||||
import { readEnv } from '../../app-config';
|
||||
import { readEnv, getAppUrl } from '../../app-config';
|
||||
|
||||
/** The public instance. An operator may point at their own copy instead. */
|
||||
export const DEFAULT_TREK_PLACES_URL = 'https://places.liketrek.com';
|
||||
@@ -89,7 +89,14 @@ export interface TrekPlacesSearchResponse {
|
||||
* identifies a person. It is never resolved back to anything on the far side.
|
||||
*/
|
||||
function instanceToken(): string {
|
||||
const url = readEnv().app.appUrl || 'unconfigured';
|
||||
// getAppUrl(), not the raw APP_URL. The variable is commented out in the
|
||||
// shipped compose file, so reading it raw gave every default install the same
|
||||
// string — and a token every caller shares is not a caller. One install
|
||||
// running a large import would then rate-limit all the others, who would fall
|
||||
// back to Nominatim with nothing to point at. The resolver falls through to
|
||||
// ALLOWED_ORIGINS and then to the port, so an unconfigured instance still
|
||||
// differs from its neighbours.
|
||||
const url = getAppUrl();
|
||||
let hash = 0;
|
||||
for (let i = 0; i < url.length; i++) {
|
||||
hash = ((hash << 5) - hash + url.charCodeAt(i)) | 0;
|
||||
@@ -358,6 +365,11 @@ export function toPlaceRecord(p: TrekPlace): Record<string, unknown> {
|
||||
// with the chain's logo and described as the company, which is the failure
|
||||
// readBrandIdentity and WIKI_IDENTITY_TAGS exist to prevent.
|
||||
'brand:wikidata': p.brand?.wikidata ?? null,
|
||||
// Carried rather than dropped: the enrichment wants exactly this field a
|
||||
// moment later, and re-fetching the same place to get it made adding one
|
||||
// place cost two full round trips to the index. Left as the service shaped
|
||||
// it — the reader validates the URL before it becomes a link.
|
||||
description: p.description ?? null,
|
||||
source: 'trek-places',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -586,17 +586,32 @@ export class PlaceEnrichmentService {
|
||||
* it from there. Only places carrying a GERS id can be looked up, which is
|
||||
* exactly the ones that came from the API in the first place.
|
||||
*/
|
||||
private async websiteDescription(placeId: string): Promise<PlaceDescription | null> {
|
||||
private async websiteDescription(
|
||||
placeId: string,
|
||||
details?: Record<string, unknown> | null,
|
||||
): Promise<PlaceDescription | null> {
|
||||
if (!placeId.startsWith('gers:')) return null;
|
||||
try {
|
||||
const place = await trekPlacesById(placeId.slice(5));
|
||||
const got = (place as { description?: { text?: string; sourceUrl?: string } } | null)?.description;
|
||||
// The details lookup already fetched this place and now carries its
|
||||
// description, so the ordinary path costs nothing. Asking again meant two
|
||||
// full round trips to the index for one added place, each with its own
|
||||
// timeout budget, for a field the first answer already contained.
|
||||
const carried = (details as { description?: { text?: string; sourceUrl?: string } } | null | undefined)
|
||||
?.description;
|
||||
const got = carried
|
||||
?? (await trekPlacesById(placeId.slice(5)) as { description?: { text?: string; sourceUrl?: string } } | null)
|
||||
?.description;
|
||||
const text = typeof got?.text === 'string' ? got.text.trim() : '';
|
||||
if (!text) return null;
|
||||
// Through the same allow-list a place's website goes through: this
|
||||
// becomes an href on the client, and the value comes from whatever the
|
||||
// configured index answered with. Anything but http(s) loses the link and
|
||||
// keeps the text, rather than being rendered as one.
|
||||
const rawUrl = typeof got?.sourceUrl === 'string' ? got.sourceUrl : null;
|
||||
return {
|
||||
text,
|
||||
source: 'website',
|
||||
sourceUrl: typeof got?.sourceUrl === 'string' ? got.sourceUrl : null,
|
||||
sourceUrl: rawUrl && placeWebsiteSchema.safeParse(rawUrl).success ? rawUrl : null,
|
||||
// Not a licensed corpus: a quoted summary from the operator's own page,
|
||||
// credited and linked back. Saying "CC-something" here would be a claim
|
||||
// about terms nobody granted.
|
||||
@@ -647,7 +662,7 @@ export class PlaceEnrichmentService {
|
||||
// exists, and it is published in JSON-LD or og:description precisely so
|
||||
// machines can read it. That covers roughly 43 percent of places, where the
|
||||
// encyclopaedias cover a fraction of a percent.
|
||||
const fromSite = await this.websiteDescription(placeId);
|
||||
const fromSite = await this.websiteDescription(placeId, details);
|
||||
if (fromSite) return fromSite;
|
||||
|
||||
const apiKey = this.maps.getMapsKey(userId);
|
||||
|
||||
Reference in New Issue
Block a user