feat(plugins): search plugins can answer the place search as you type

A searchProvider plugin can now implement an optional suggest() beside
search(). Its places then show up in the place search's typed-ahead list,
after the core suggestions and marked with the plugin's name, on desktop
and phone. An index that cannot take a request per keystroke leaves it
out and keeps answering the full search only.

The child reports which functions each hook object carries at load, so
GET /api/plugin-search/suggest only asks the plugins that implement
suggest: from the second character, three rows at most across all of
them, 800 ms to answer. The feed marks plugins holding
hook:search-provider and the client only asks the route while one is
installed. A plugin row carries its whole place, so picking it skips the
details lookup, which knows no plugin id. The phone's search results now
name their source as the desktop ones do, and the desktop dropdown
scrolls instead of running past the dialog.

Addresses discussion #2221.
This commit is contained in:
Maurice
2026-09-25 09:19:11 +02:00
parent 1727732841
commit 2a8071f642
38 changed files with 1248 additions and 96 deletions
+14 -1
View File
@@ -33,6 +33,7 @@ const CONTRACTS: Array<[hook: string, fn: string, timeoutMs: number]> = [
['calendarSource', 'getEvents', 5000],
['placeDetailProvider', 'getDetails', 5000],
['searchProvider', 'search', 2000],
['searchProvider', 'suggest', 800],
['poiCategoryProvider', 'getPois', 8000],
['warningProvider', 'getWarnings', 5000],
['tableContributor', 'getContributions', 5000],
@@ -82,7 +83,7 @@ describe('PluginHooks contracts', () => {
it('PLUGHOOK-005 providersOf is passed straight through to the runtime', () => {
const { hooks: h, providersOf } = hooks();
expect(h.providersOf('photoProvider')).toEqual(['p1', 'p2']);
expect(providersOf).toHaveBeenCalledWith('photoProvider');
expect(providersOf).toHaveBeenCalledWith('photoProvider', undefined);
});
it('PLUGHOOK-006 the read hooks forward their arguments and the acting user', async () => {
@@ -160,6 +161,18 @@ describe('PluginHooks contracts', () => {
expect(invokeHook).toHaveBeenCalledWith('p', 'poiCategoryProvider', 'getPois', [request], 7, 8000);
});
it('PLUGHOOK-012: a typed-ahead suggestion binds the requesting user and takes the shortest budget (#2221)', async () => {
// Asked per keystroke, beside core suggestions that arrive in a few hundred
// milliseconds; the next keystroke replaces the question, so a later answer is dead.
const { hooks: h, invokeHook, providersOf } = hooks();
const request = { query: 'ichi', limit: 3, lang: 'ja', near: { lat: 35.66, lng: 139.7 } };
await h.suggestPlaces('p', request, 7);
expect(invokeHook).toHaveBeenCalledWith('p', 'searchProvider', 'suggest', [request], 7, 800);
// Only the providers whose hook carries the optional function are asked.
h.providersOf('searchProvider', 'suggest');
expect(providersOf).toHaveBeenLastCalledWith('searchProvider', 'suggest');
});
it('PLUGHOOK-009 the class is listed in its module providers', () => {
// A decorated class no module registers is invisible to discovery, which would
// now fail boot on "no host-side consumer" rather than fail quietly. Cheapest