mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
feat(plugins): let a plugin answer place searches from its own index
TREK searches its own place index and OpenStreetMap. Neither carries a rating, so "the best rated hotel around here" has never been answerable, and an operator with a better index for their region had no way to reach the search box at all. The searchProvider hook is that way in: a plugin is handed the query, a limit, the language and the coordinate the search is biased toward, and answers with places in the same shape the core search returns, plus a rating. It sits beside the core search rather than inside it. The plugin runtime already imports PlacesModule, which imports MapsModule, so asking the providers from the maps service would close a module cycle — the same reason the other fourteen contribution controllers stand next to what they contribute to. The client asks both at once and merges, at the single point every caller already goes through, so all nine search surfaces get plugin hits without knowing the hook exists. A plugin index may never hold up the list: the client stops waiting at two and a half seconds and the host gives a provider two, which is also why the budget is the shortest of any hook here. With no such plugin installed the route answers without reaching the runtime at all. Every hit is normalized host-side and shared by the REST route and the MCP tool, so a cap that holds for the browser holds for the assistant: coordinates are range-checked, strings capped, the rating clamped to 0..5, a website must be http or https, and ids are namespaced so they can never collide with an OSM one. search_places_via_plugins is the MCP half, because what the user can see the assistant has to be able to see; search_place now points at it.
This commit is contained in:
@@ -18,6 +18,21 @@ export interface HookMcpToolCall {
|
||||
args: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* What a search provider is asked to look for.
|
||||
*
|
||||
* `near` is the same bias the core search uses, and it is what decides which of the
|
||||
* four places called "Hase-dera" the answer is about. Optional, because a search from
|
||||
* a trip with no places yet has nothing to bias toward.
|
||||
*/
|
||||
export interface HookSearchRequest {
|
||||
query: string;
|
||||
limit: number;
|
||||
/** The caller's language tag, for providers that return localized names. */
|
||||
lang?: string;
|
||||
near?: { lat: number; lng: number };
|
||||
}
|
||||
|
||||
/** The waypoint request a route provider is asked to solve. */
|
||||
export interface HookRouteRequest {
|
||||
tripId: number;
|
||||
@@ -29,7 +44,7 @@ export interface HookRouteRequest {
|
||||
/**
|
||||
* Every host-to-plugin hook call, in one place.
|
||||
*
|
||||
* The 15 hooks the consent screen offers used to be invoked straight from the
|
||||
* The 16 hooks the consent screen offers used to be invoked straight from the
|
||||
* controllers, with the fn name and the timeout written out at each call site. That
|
||||
* made three things impossible to check: that a granted `hook:*` permission actually
|
||||
* has a consumer (a dead grant on the consent screen looks exactly like a live one),
|
||||
@@ -81,6 +96,20 @@ export class PluginHooks {
|
||||
return this.runtime.invokeHook(pluginId, 'placeDetailProvider', 'getDetails', [placeId], userId, 5000);
|
||||
}
|
||||
|
||||
/**
|
||||
* The shortest leash of any hook here, because a person is waiting on a list.
|
||||
*
|
||||
* The core search and this one run side by side, so the wait is the slower of the
|
||||
* two rather than their sum, and the client stops waiting at two and a half seconds
|
||||
* whatever happens. Two seconds is therefore the whole of what a provider can
|
||||
* usefully spend: past it the list is already drawn and its answer is discarded, so
|
||||
* a longer budget would only hold an IPC call open for nothing.
|
||||
*/
|
||||
@PluginHook('searchProvider', { permission: 'hook:search-provider', fn: 'search', timeoutMs: 2000 })
|
||||
searchPlaces(pluginId: string, request: HookSearchRequest, userId: number): Promise<unknown> {
|
||||
return this.runtime.invokeHook(pluginId, 'searchProvider', 'search', [request], userId, 2000);
|
||||
}
|
||||
|
||||
@PluginHook('warningProvider', { permission: 'hook:trip-warning-provider', fn: 'getWarnings', timeoutMs: 5000 })
|
||||
tripWarnings(pluginId: string, tripId: number, userId: number): Promise<unknown> {
|
||||
return this.runtime.invokeHook(pluginId, 'warningProvider', 'getWarnings', [tripId], userId, 5000);
|
||||
|
||||
Reference in New Issue
Block a user