mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Merge upstream main into denis/rail-layer
This commit is contained in:
commit
13818d0b9f
87 files changed
+7438
-144
No files matched your search
@@ -107,6 +107,36 @@ const schemas = [
|
||||
required: ['layerId'],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'show_street_level',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
query: {
|
||||
type: 'string',
|
||||
maxLength: 160,
|
||||
},
|
||||
latitude: {
|
||||
type: 'number',
|
||||
minimum: -90,
|
||||
maximum: 90,
|
||||
},
|
||||
longitude: {
|
||||
type: 'number',
|
||||
minimum: -180,
|
||||
maximum: 180,
|
||||
},
|
||||
provider: {
|
||||
type: 'string',
|
||||
enum: ['google', 'mapillary', 'kartaview', 'panoramax'],
|
||||
},
|
||||
referent: {
|
||||
type: 'integer',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'adjust_camera_zoom',
|
||||
parameters: {
|
||||
|
||||
@@ -58,7 +58,8 @@ test('the complete Realtime tool payload pins the manifest-generated layer relea
|
||||
// control_cockpit states the own-layer entry rule (Contacts not required).
|
||||
// move_camera tilt takes an optional pitchDeg angle, described as
|
||||
// absolute with its -45 default, with steps sent as a direction.
|
||||
'6a0d154e68beb787c4e20f12d29a5c86577dc343f3e71d8b5651998ea45d8c3c',
|
||||
// show_street_level (map, source, photo) adds one tool.
|
||||
'0c27f62062001e6a07241cd301c3d357f55e9b74f66cd2904d16590510337468',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -155,6 +156,7 @@ test('all legacy action arguments are byte-identical after removing the delibera
|
||||
'resolve_area',
|
||||
'find_imagery',
|
||||
'osm_query',
|
||||
'show_street_level',
|
||||
].includes(tool.name),
|
||||
);
|
||||
// Layer enums are generated from the voice layer manifest and pinned by
|
||||
|
||||
@@ -143,6 +143,8 @@ function resolveFly(args, { pointer, referents }) {
|
||||
entity: {
|
||||
layerId: target.layerId,
|
||||
id: target.id,
|
||||
// The answer names it, not its id ("near cam-9").
|
||||
...(target.label ? { label: target.label } : {}),
|
||||
...(hasPosition(target) ? { lat: target.lat, lon: target.lon } : {}),
|
||||
},
|
||||
},
|
||||
@@ -345,6 +347,7 @@ function resolveCropPixels(args, { imageFrame, cameraKey }) {
|
||||
const RESOLVERS = Object.freeze({
|
||||
track_entity: resolveTrack,
|
||||
fly_to_location: resolveFly,
|
||||
show_street_level: resolveFly,
|
||||
get_entity_context: resolveContext,
|
||||
analyst_query: resolveAnalyst,
|
||||
annotate_map: resolveAnnotate,
|
||||
|
||||
@@ -104,7 +104,7 @@ test('referents: numbered items resolve for track, fly and context', () => {
|
||||
const last = resolveDeicticArgs('track_entity', { query: 'x', referent: -1 }, { referents });
|
||||
assert.equal(last.args.query, 'ccc333', '-1 is the last one');
|
||||
const fly = resolveDeicticArgs('fly_to_location', { referent: 1 }, { referents });
|
||||
assert.deepEqual(fly.args, { entity: { layerId: 'flights', id: 'aaa111' } }, 'moving contacts are located at run time');
|
||||
assert.deepEqual(fly.args, { entity: { layerId: 'flights', id: 'aaa111', label: 'SWA12' } }, 'moving contacts are located at run time');
|
||||
const context = resolveDeicticArgs('get_entity_context', { referent: 3 }, { referents });
|
||||
assert.equal(context.args.scope, 'target');
|
||||
assert.equal(context.args.target.label, 'AAL9');
|
||||
@@ -180,3 +180,10 @@ test('numbered custom-labeled pins retain their resolved coordinates', () => {
|
||||
assert.deepEqual(resolveDeicticArgs('fly_to_location', { referent: 1 }, { referents }).args,
|
||||
{ latitude: 30.27, longitude: -97.74 });
|
||||
});
|
||||
|
||||
test('show_street_level: "street view of this" opens photos at the pointed ground point', () => {
|
||||
const out = resolveDeicticArgs('show_street_level', { query: 'pointer', provider: 'google' }, { pointer: ground });
|
||||
assert.deepEqual(out.args, { provider: 'google', latitude: 30.27, longitude: -97.74 });
|
||||
assert.equal(out.used.source, 'pointer');
|
||||
assert.deepEqual(resolveDeicticArgs('show_street_level', { query: 'Eiffel Tower' }, { pointer: ground }).args, { query: 'Eiffel Tower' });
|
||||
});
|
||||
+482
-1
@@ -15,6 +15,7 @@ import { applicationPinia } from '../ui/vueRuntime.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { CITY_POIS } from '../cityPois.js';
|
||||
import { greatCircleKm } from '../geoDistance.js';
|
||||
import { EXCLUSIVE_SURFACE_CLASSES } from '../exclusiveSurfaces.js';
|
||||
import {
|
||||
hudViewportSamples,
|
||||
placeLookupView,
|
||||
@@ -35,6 +36,10 @@ import {
|
||||
isContextRecordActive,
|
||||
} from '../data/contextStore.js';
|
||||
import { CCTV_FOCUS_RESULT } from '../layers/cctv/index.js';
|
||||
import {
|
||||
NEAREST_RADIUS_MAX_M as STREET_LEVEL_WIDE_RADIUS_M,
|
||||
STREET_LEVEL_LAYER_ID,
|
||||
} from '../layers/streetLevel/policy.js';
|
||||
import {
|
||||
createAnalystEngine,
|
||||
normalizeAnalystSpec,
|
||||
@@ -55,6 +60,7 @@ import {
|
||||
import * as defaultFloorServices from '../data/groundFloor.js';
|
||||
import { isPickedWorldPosition } from '../data/scenePick.js';
|
||||
import { unavailablePlaceSearch } from '../search/placeSearch.js';
|
||||
import { watchCameraOwner } from '../navigationPolicy.js';
|
||||
import * as defaultAnnotationResolver from '../annotations/annotationResolver.js';
|
||||
import { normalizeRadioCountryInput } from '../data/radioCountry.js';
|
||||
import { TR3B_CLASS } from '../data/tr3bRegistry.js';
|
||||
@@ -503,7 +509,7 @@ export function createGevActionRunner({
|
||||
const pending = dataManager.getAll?.().find((l) => l.id === layerId);
|
||||
reportProgress('layer', pending?.name || layerId);
|
||||
}
|
||||
const changeOptions = { origin: 'voice' };
|
||||
const changeOptions = { origin: actionIntentOrigin(runOptions) };
|
||||
if (runOptions.signal) changeOptions.signal = runOptions.signal;
|
||||
let changed = false;
|
||||
let changeError = null;
|
||||
@@ -796,6 +802,20 @@ export function createGevActionRunner({
|
||||
};
|
||||
}
|
||||
|
||||
if (name === 'show_street_level') {
|
||||
return showStreetLevel(args, {
|
||||
viewer,
|
||||
dataManager,
|
||||
styleManager,
|
||||
placeSearch,
|
||||
runGevAction,
|
||||
runOptions,
|
||||
current,
|
||||
reportProgress,
|
||||
otherHandoffs,
|
||||
});
|
||||
}
|
||||
|
||||
if (name === 'set_visual_style') {
|
||||
const style = normalizeStyle(args.style);
|
||||
if (!style)
|
||||
@@ -2936,6 +2956,29 @@ function stopAllTracking(viewer, dataManager) {
|
||||
return { ok: true, action: 'stop_tracking', released };
|
||||
}
|
||||
|
||||
/**
|
||||
* The imagery filter the lit source honours when it is narrower than the
|
||||
* default (360° or flat only, or SINCE), or null.
|
||||
* @returns {{ pano?: string, sinceDays?: number, label: string } | null}
|
||||
*/
|
||||
export function activeImageryFilter(ui) {
|
||||
const filter = ui?.filter || {};
|
||||
const controls = ui?.filterControls || {};
|
||||
const out = {};
|
||||
const names = [];
|
||||
if (controls.pano && (filter.pano === 'pano' || filter.pano === 'flat')) {
|
||||
out.pano = filter.pano;
|
||||
names.push(filter.pano === 'pano' ? '360°' : 'flat-photo');
|
||||
}
|
||||
if (controls.since && Number(filter.sinceDays) > 0) {
|
||||
out.sinceDays = Number(filter.sinceDays);
|
||||
names.push('SINCE');
|
||||
}
|
||||
if (!names.length) return null;
|
||||
out.label = `${names.join(' and ')} filter${names.length > 1 ? 's' : ''}`;
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frames entities near the current view target with a cinematic pull-back:
|
||||
* oblique high pitch for aircraft/ships, shallow wide pitch for satellites.
|
||||
@@ -3709,6 +3752,425 @@ function normalizeStyle(value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The application panel that holds the street-level photo. */
|
||||
const STREET_LEVEL_PANEL_ID = 'street-level-panel';
|
||||
|
||||
/**
|
||||
* The layer-state origin of an action's changes. The assistant's are the
|
||||
* user's own choices and persist; a link replays someone else's view
|
||||
* (`origin: 'programmatic'`) and never writes the recipient's preferences.
|
||||
*/
|
||||
function actionIntentOrigin(runOptions) {
|
||||
return runOptions?.origin === 'programmatic' ? 'programmatic' : 'voice';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether cockpit, clean view, recording or scene playback hides the panel a
|
||||
* street-level photo opens in. Embed mode uses clean view for its globe but
|
||||
* lifts the photo out of the hidden rail.
|
||||
*/
|
||||
function streetLevelPanelHidden() {
|
||||
const body = globalThis.document?.body;
|
||||
const embedded = body?.classList?.contains('ui-embed') === true;
|
||||
return EXCLUSIVE_SURFACE_CLASSES.some(
|
||||
(mode) =>
|
||||
body?.classList?.contains(mode) &&
|
||||
!(embedded && mode === 'ui-clean-view'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Show me <place> on Street View / on Mapillary": fly there, light the source
|
||||
* (and its map) and open the nearest image. Each stage reports its own
|
||||
* failure, so speech can say which part did not happen. `autoOpen: false`
|
||||
* (links) stops short of a billed load: the panel is armed for OPEN.
|
||||
*/
|
||||
export async function showStreetLevel(args, context) {
|
||||
// After any await a newer turn, a navigation, a globe gesture or a mode
|
||||
// that hides the panel may have taken over: each later stage checks again.
|
||||
const owner = watchCameraOwner(context.viewer, context.styleManager);
|
||||
// A photo held up while the request switches its source is let go however
|
||||
// the request ends: replaced by then, or closed if its source stayed off.
|
||||
let releaseViewer = null;
|
||||
const holdViewer = (layerModule) => {
|
||||
releaseViewer ??= layerModule.holdViewer?.() ?? null;
|
||||
};
|
||||
try {
|
||||
return await requestStreetLevel(args, { ...context, owner, holdViewer });
|
||||
} finally {
|
||||
releaseViewer?.();
|
||||
owner.stop();
|
||||
}
|
||||
}
|
||||
|
||||
async function requestStreetLevel(
|
||||
args,
|
||||
{
|
||||
dataManager,
|
||||
styleManager,
|
||||
runGevAction,
|
||||
owner,
|
||||
holdViewer = () => {},
|
||||
runOptions = {},
|
||||
current = () => true,
|
||||
reportProgress = () => {},
|
||||
otherHandoffs = () => 0,
|
||||
},
|
||||
) {
|
||||
const action = 'show_street_level';
|
||||
// Navigations other than voice fly-tos (this request's own flight) so far.
|
||||
const handoffs = otherHandoffs();
|
||||
let provider = null;
|
||||
let providerName = null;
|
||||
let label = null;
|
||||
const fail = (stage, error, extra = {}) => ({
|
||||
ok: false,
|
||||
action,
|
||||
stage,
|
||||
cancelled: !current(),
|
||||
error,
|
||||
...(provider ? { provider } : {}),
|
||||
...(providerName ? { providerName } : {}),
|
||||
...(label ? { label } : {}),
|
||||
...(atViewCentre ? { atViewCentre } : {}),
|
||||
...extra,
|
||||
});
|
||||
let atViewCentre = false;
|
||||
const query = String(args.query || '').trim();
|
||||
const latitude = Number(args.latitude);
|
||||
const longitude = Number(args.longitude);
|
||||
const coordinatesGiven = args.latitude != null && args.longitude != null;
|
||||
const hasCoordinates =
|
||||
coordinatesGiven && Math.abs(latitude) <= 90 && Math.abs(longitude) <= 180;
|
||||
if (coordinatesGiven && !hasCoordinates)
|
||||
return fail(
|
||||
'location',
|
||||
'Latitude must be within ±90° and longitude within ±180°',
|
||||
);
|
||||
// A referent that is a layer entity (deixis): located when the flight starts.
|
||||
const entity =
|
||||
args.entity && typeof args.entity === 'object' && args.entity.id
|
||||
? args.entity
|
||||
: null;
|
||||
const layerModule =
|
||||
dataManager?.layers?.get?.(STREET_LEVEL_LAYER_ID)?.module || null;
|
||||
if (!layerModule || typeof layerModule.openNearest !== 'function')
|
||||
return fail('provider', 'Street Level is unavailable');
|
||||
const providerIds = Array.isArray(layerModule.providerIds)
|
||||
? layerModule.providerIds
|
||||
: [];
|
||||
|
||||
// The source: asked for, else the one lit now, else the first registered.
|
||||
const requested = String(args.provider || '')
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (requested) {
|
||||
if (!providerIds.includes(requested))
|
||||
return fail(
|
||||
'provider',
|
||||
`${requested} is not a street-level imagery source here`,
|
||||
);
|
||||
provider = requested;
|
||||
} else {
|
||||
const params = dataManager.getLayerParams?.(STREET_LEVEL_LAYER_ID) || {};
|
||||
provider =
|
||||
providerIds.find((id) => params[id] === true) || providerIds[0] || null;
|
||||
}
|
||||
if (!provider)
|
||||
return fail('provider', 'No street-level imagery source is configured');
|
||||
const status = layerModule.providerStatus?.(provider) || null;
|
||||
providerName = status?.name || provider;
|
||||
|
||||
// The key first: without one nothing changes, as with a chip.
|
||||
if (status && (status.keyRequired === true || status.configured === false))
|
||||
return fail('key', status.error || `${providerName} needs its key`, {
|
||||
keyRejected: status.keyRejected === true,
|
||||
keyAlternatives: layerModule.getUIState?.()?.keyAlternatives || [],
|
||||
});
|
||||
|
||||
// A hidden panel refuses before the camera leaves a recording or scene.
|
||||
const hidden = (extra = {}) =>
|
||||
fail(
|
||||
'view',
|
||||
msg(
|
||||
'Street-level photos are hidden in the current view. Leave it first.',
|
||||
),
|
||||
extra,
|
||||
);
|
||||
if (streetLevelPanelHidden()) return hidden();
|
||||
const interrupted = (stage, extra = {}) => {
|
||||
if (!current())
|
||||
return fail(stage, 'Street-level request was cancelled', {
|
||||
cancelled: true,
|
||||
location,
|
||||
...extra,
|
||||
});
|
||||
if (owner.taken())
|
||||
return fail(stage, 'The camera moved on before the photo opened', {
|
||||
cancelled: true,
|
||||
superseded: true,
|
||||
location,
|
||||
...extra,
|
||||
});
|
||||
if (streetLevelPanelHidden()) return hidden({ location, ...extra });
|
||||
return null;
|
||||
};
|
||||
|
||||
// Then the place: a name that geocodes to nothing changes nothing else.
|
||||
label =
|
||||
query ||
|
||||
(entity ? String(entity.label || entity.id) : '') ||
|
||||
(hasCoordinates ? `${latitude.toFixed(4)}, ${longitude.toFixed(4)}` : '') ||
|
||||
'the view centre';
|
||||
atViewCentre = !query && !hasCoordinates && !entity;
|
||||
let point = null;
|
||||
let location = null;
|
||||
// No place at all: the layer looks at the ground under the screen centre,
|
||||
// as the OPEN button does. `fly: false` (tests) keeps the camera for a
|
||||
// point given by its coordinates.
|
||||
if (atViewCentre || (args.fly === false && hasCoordinates)) {
|
||||
if (hasCoordinates) point = { lat: latitude, lon: longitude };
|
||||
} else {
|
||||
try {
|
||||
location = await runGevAction(
|
||||
'fly_to_location',
|
||||
{
|
||||
...(entity
|
||||
? { entity }
|
||||
: hasCoordinates
|
||||
? { latitude, longitude }
|
||||
: { query }),
|
||||
viewMode: 'close',
|
||||
waitForArrival: true,
|
||||
},
|
||||
runOptions,
|
||||
);
|
||||
} catch (error) {
|
||||
// A geocoder that throws (offline, a provider down) is this stage's
|
||||
// failure too, not an error past the action.
|
||||
return fail('location', `Could not arrive at ${label}`, {
|
||||
cancelled: !current(),
|
||||
detail: String(error?.message || error),
|
||||
});
|
||||
}
|
||||
if (location?.ok !== true || !current())
|
||||
return fail(
|
||||
'location',
|
||||
location?.error || `Could not arrive at ${location?.label || label}`,
|
||||
{ cancelled: !current() || Boolean(location?.cancelled), location },
|
||||
);
|
||||
// An item, or a named place flown to by its coordinates, keeps its name:
|
||||
// such a flight reports only coordinates.
|
||||
label =
|
||||
entity || (query && hasCoordinates) ? label : location.label || label;
|
||||
if (
|
||||
!Number.isFinite(location.latitude) ||
|
||||
!Number.isFinite(location.longitude)
|
||||
)
|
||||
return fail(
|
||||
'location',
|
||||
`${label} has no position to look for imagery at`,
|
||||
{ location },
|
||||
);
|
||||
point = { lat: location.latitude, lon: location.longitude };
|
||||
}
|
||||
|
||||
// A mode that hides the panel may have started during the flight. The
|
||||
// camera is the request's from where its flight landed, unless another
|
||||
// navigation took it during the flight.
|
||||
if (location && otherHandoffs() === handoffs) owner.claim();
|
||||
const arrived = interrupted('view');
|
||||
if (arrived) return arrived;
|
||||
|
||||
// The source's map, when it needs one (Street View: Google 3D only).
|
||||
const requiredStack = layerModule.requiredMapStack?.(provider) || null;
|
||||
const activeStack = styleManager?.mapStackController?.getActiveId?.() ?? null;
|
||||
if (requiredStack && activeStack !== requiredStack) {
|
||||
reportProgress('map', requiredStack);
|
||||
const map = await runGevAction(
|
||||
'set_map_stack',
|
||||
{ stack: requiredStack },
|
||||
runOptions,
|
||||
);
|
||||
if (map?.ok !== true && current())
|
||||
return fail(
|
||||
'map',
|
||||
map?.error ||
|
||||
`${providerName} needs the ${requiredStack} map, which is not available`,
|
||||
{ map, location },
|
||||
);
|
||||
const stop = interrupted('map', { map });
|
||||
if (stop) return stop;
|
||||
}
|
||||
|
||||
// Light the source the way a chip click does, so the choice is kept. An
|
||||
// open photo of another source stays up until this request replaces it.
|
||||
const openPhoto = layerModule.getUIState?.()?.street;
|
||||
if (openPhoto?.open === true && openPhoto.providerId !== provider)
|
||||
holdViewer(layerModule);
|
||||
const switches = Object.fromEntries(
|
||||
providerIds.map((id) => [id, id === provider]),
|
||||
);
|
||||
let accepted = true;
|
||||
if (typeof dataManager.setLayerParams === 'function')
|
||||
accepted =
|
||||
dataManager.setLayerParams(STREET_LEVEL_LAYER_ID, switches, {
|
||||
origin: actionIntentOrigin(runOptions),
|
||||
}) !== false;
|
||||
else layerModule.setProviderEnabled?.(provider, true);
|
||||
if (!accepted)
|
||||
return fail('provider', `${providerName} could not be switched on`, {
|
||||
location,
|
||||
});
|
||||
let layer = null;
|
||||
if (!dataManager.isEnabled?.(STREET_LEVEL_LAYER_ID)) {
|
||||
layer = await runGevAction(
|
||||
'set_layer_visibility',
|
||||
{ layerId: STREET_LEVEL_LAYER_ID, enabled: true },
|
||||
runOptions,
|
||||
);
|
||||
if (layer?.ok !== true && current())
|
||||
return fail(
|
||||
'layer',
|
||||
layer?.error || 'Street Level could not be enabled',
|
||||
{ cancelled: Boolean(layer?.cancelled), layer, location },
|
||||
);
|
||||
const stop = interrupted('layer', { layer });
|
||||
if (stop) return stop;
|
||||
}
|
||||
|
||||
// Listed now that its map is up, and lit.
|
||||
const ui = layerModule.getUIState?.() || {};
|
||||
const snapshot =
|
||||
(ui.providers || []).find((entry) => entry.id === provider) || null;
|
||||
if (!snapshot)
|
||||
return fail(
|
||||
'provider',
|
||||
ui.coverage?.hint || `${providerName} is not available on this map`,
|
||||
{ location },
|
||||
);
|
||||
if (snapshot.on !== true)
|
||||
return fail('provider', `${providerName} could not be switched on`, {
|
||||
location,
|
||||
});
|
||||
|
||||
// A link never loads a billed photo by itself: it arms OPEN instead.
|
||||
if (args.autoOpen === false && status?.billed === true) {
|
||||
// A photo of another place must not stay up beside the armed request.
|
||||
if (layerModule.getUIState?.()?.street?.open === true)
|
||||
layerModule.closeViewer?.();
|
||||
layerModule.armNearest?.(point, {
|
||||
providerIds: [provider],
|
||||
...(snapshot.groundClick === true
|
||||
? { radiusM: STREET_LEVEL_WIDE_RADIUS_M }
|
||||
: {}),
|
||||
});
|
||||
return {
|
||||
ok: true,
|
||||
action,
|
||||
provider,
|
||||
providerName,
|
||||
label,
|
||||
armed: true,
|
||||
flew: location !== null,
|
||||
...(location ? { location: location.label } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
// Street View has no coverage to click, so it searches wider: a geocoded
|
||||
// landmark is rarely within 50 m of a street. An open photo stays up while
|
||||
// this looks and closes if nothing opens; a found photo loads only while
|
||||
// the camera and the panel are still the request's.
|
||||
reportProgress('imagery', label);
|
||||
const opened = await layerModule.openNearest(point, {
|
||||
providerIds: [provider],
|
||||
frame: false,
|
||||
replace: true,
|
||||
proceed: () => current() && !owner.taken() && !streetLevelPanelHidden(),
|
||||
// Under the screen centre, not the middle of a tilted view's footprint;
|
||||
// this request is the user's own, not a link's armed one.
|
||||
...(point ? {} : { aim: 'screen-centre', armed: false }),
|
||||
...(runOptions.signal ? { signal: runOptions.signal } : {}),
|
||||
...(snapshot.groundClick === true
|
||||
? { radiusM: STREET_LEVEL_WIDE_RADIUS_M }
|
||||
: {}),
|
||||
});
|
||||
const street = layerModule.getUIState?.()?.street || {};
|
||||
// A photo that opened after the camera moved on, or into a panel hidden
|
||||
// meanwhile, is closed again.
|
||||
const late = interrupted('imagery');
|
||||
if (late) {
|
||||
if (opened === true) layerModule.closeViewer?.();
|
||||
return late;
|
||||
}
|
||||
if (opened !== true) {
|
||||
// Why nothing opened: the key, a change under the lookup, or no imagery.
|
||||
const after = layerModule.providerStatus?.(provider) || status || {};
|
||||
if (after.keyRequired === true || after.keyRejected === true)
|
||||
return fail(
|
||||
'key',
|
||||
street.error || after.error || `${providerName} needs its key`,
|
||||
{ keyRejected: after.keyRejected === true, location },
|
||||
);
|
||||
if (
|
||||
!dataManager.isEnabled?.(STREET_LEVEL_LAYER_ID) ||
|
||||
after.on === false ||
|
||||
after.available === false
|
||||
)
|
||||
return fail(
|
||||
'imagery',
|
||||
street.error || 'Street Level changed while it looked for imagery',
|
||||
{ cancelled: true, location },
|
||||
);
|
||||
// The screen centre is sky: nothing was looked up.
|
||||
if (street.nearestOutcome === 'sky')
|
||||
return fail('imagery', street.error || 'Aim the view at a street', {
|
||||
location,
|
||||
aim: 'sky',
|
||||
});
|
||||
// The source or the viewer failed: an error, not missing coverage.
|
||||
if (street.nearestOutcome !== 'empty')
|
||||
return fail(
|
||||
'imagery',
|
||||
street.error || `${providerName} imagery could not be opened`,
|
||||
{ location, imageryError: true },
|
||||
);
|
||||
// An imagery filter the source honours can hide every photo here; say
|
||||
// so, or the answer reads as "no coverage" when one switch would do.
|
||||
const filter = activeImageryFilter(layerModule.getUIState?.());
|
||||
const reason = street.error || `No ${providerName} imagery near ${label}`;
|
||||
return fail(
|
||||
'imagery',
|
||||
filter ? `${reason} with the ${filter.label} on` : reason,
|
||||
{ location, noImagery: true, ...(filter ? { filter } : {}) },
|
||||
);
|
||||
}
|
||||
// Every explicit request shows its photo, also one replacing a photo whose
|
||||
// panel or phone sheet the user had closed. Embed mode lifts the photo.
|
||||
if (!globalThis.document?.body?.classList?.contains('ui-embed')) {
|
||||
styleManager?.setPanelCollapsed?.(STREET_LEVEL_PANEL_ID, false, {
|
||||
persist: false,
|
||||
});
|
||||
styleManager?.revealPanel?.(STREET_LEVEL_PANEL_ID);
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
action,
|
||||
provider,
|
||||
providerName,
|
||||
label,
|
||||
imageId: street.imageId ?? null,
|
||||
title: street.title ?? null,
|
||||
capturedAt: street.capturedAt ?? null,
|
||||
capturedAtPrecision: street.capturedAtPrecision ?? null,
|
||||
position: street.position ?? null,
|
||||
externalUrl: street.externalUrl ?? null,
|
||||
flew: location !== null,
|
||||
...(atViewCentre ? { atViewCentre } : {}),
|
||||
...(location ? { location: location.label } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
async function flyToRequestedLocation(
|
||||
viewer,
|
||||
args,
|
||||
@@ -3781,11 +4243,25 @@ async function flyToRequestedLocation(
|
||||
);
|
||||
if (result === false)
|
||||
return cancelled(CITY_POIS[locationId]?.name || locationId);
|
||||
// Where the camera went: the first POI for a close view, else the middle
|
||||
// of the city's overview bounds.
|
||||
const city = CITY_POIS[locationId];
|
||||
const overview =
|
||||
!(rangeM || args.viewMode === 'close') && Boolean(city?.viewBounds);
|
||||
const centre = overview
|
||||
? {
|
||||
lat:
|
||||
(city.viewBounds.southwest.lat + city.viewBounds.northeast.lat) / 2,
|
||||
lon:
|
||||
(city.viewBounds.southwest.lng + city.viewBounds.northeast.lng) / 2,
|
||||
}
|
||||
: city?.pois?.[0] || null;
|
||||
const response = {
|
||||
ok: Boolean(result),
|
||||
action: 'fly_to_location',
|
||||
locationId,
|
||||
label: CITY_POIS[locationId]?.name || locationId,
|
||||
...(centre ? { latitude: centre.lat, longitude: centre.lon } : {}),
|
||||
rangeM: result?.range ? Math.round(result.range) : rangeM || null,
|
||||
navigationMode: rangeM
|
||||
? 'explicit-range'
|
||||
@@ -3846,6 +4322,7 @@ async function flyToRequestedLocation(
|
||||
action: 'fly_to_location',
|
||||
query,
|
||||
label: poi?.name || query,
|
||||
...(poi ? { latitude: poi.lat, longitude: poi.lon } : {}),
|
||||
navigationMode: rangeM ? 'preset-poi-range' : 'preset-poi',
|
||||
rangeM: result?.range ? Math.round(result.range) : rangeM || null,
|
||||
};
|
||||
@@ -3876,6 +4353,10 @@ async function flyToRequestedLocation(
|
||||
action: 'fly_to_location',
|
||||
query,
|
||||
label: destination?.label || query,
|
||||
...(Number.isFinite(destination?.latitude) &&
|
||||
Number.isFinite(destination?.longitude)
|
||||
? { latitude: destination.latitude, longitude: destination.longitude }
|
||||
: {}),
|
||||
navigationMode: destination?.navigationMode || null,
|
||||
rangeM: destination?.rangeM || rangeM || null,
|
||||
};
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
normalizeStackId,
|
||||
} from './gevActions.js';
|
||||
import { MAP_STACKS } from '../mapStackController.js';
|
||||
import { KEY_REJECTED_MESSAGE } from '../layers/streetLevel/providers/google/policy.js';
|
||||
import { GEV_REALTIME_TOOLS } from '../../server/providers/openai/tools.js';
|
||||
import { presentResult } from './resultDisplay.js';
|
||||
|
||||
@@ -6548,6 +6549,568 @@ test('analyst-only lookup distinguishes duplicate names and uses canonical aircr
|
||||
assert.equal(plane.latitude, 36, 'canonical ID resolves the current position, not old coordinates');
|
||||
});
|
||||
|
||||
/** A Street Level layer stub, a map stack and a data manager for show_street_level. */
|
||||
function createStreetLevelHarness({
|
||||
activeStack = 'osm',
|
||||
lit = { mapillary: true, google: false },
|
||||
enabled = false,
|
||||
keyRequired = false,
|
||||
configured = !keyRequired,
|
||||
nearest = 'pano-a',
|
||||
paramsAccepted = true,
|
||||
enableResult = true,
|
||||
listGoogle = true,
|
||||
duringLookup = null,
|
||||
keyRejectedAtStart = false,
|
||||
lightFails = false,
|
||||
imageryError = null,
|
||||
sky = false,
|
||||
photoOpen = false,
|
||||
duringMapSwitch = null,
|
||||
duringEnable = null,
|
||||
} = {}) {
|
||||
const order = [];
|
||||
const lookups = [];
|
||||
const origins = [];
|
||||
const revealed = [];
|
||||
const { viewer, styleManager, currentGeneration, panelSearch } = createVoiceNavigationHarness();
|
||||
// Who owns the camera: the shell's navigation stamps and globe gestures.
|
||||
Object.defineProperty(styleManager, '_navigationGeneration', {
|
||||
get: () => currentGeneration(),
|
||||
});
|
||||
viewer.scene.canvas = Object.assign(new EventTarget(), { clientWidth: 1200, clientHeight: 800 });
|
||||
let completeFlight = null;
|
||||
viewer.camera.lookAt = () => {};
|
||||
viewer.camera.flyToBoundingSphere = (_sphere, options) => {
|
||||
order.push('fly');
|
||||
completeFlight = options.complete;
|
||||
};
|
||||
styleManager.runImmediateLocationNavigation = (navigate) =>
|
||||
styleManager.runImmediateNavigation('location', navigate);
|
||||
let stack = activeStack;
|
||||
styleManager.mapStackController = { getActiveId: () => stack };
|
||||
styleManager.setMapStack = async (id) => {
|
||||
order.push(`map:${id}`);
|
||||
stack = id;
|
||||
duringMapSwitch?.();
|
||||
return { ok: true, activeStack: id, error: null };
|
||||
};
|
||||
let params = { ...lit };
|
||||
let keyRejected = keyRejectedAtStart;
|
||||
const street = photoOpen
|
||||
? { open: true, imageId: 'eiffel-photo', error: null }
|
||||
: { open: false, imageId: null, error: null };
|
||||
const names = { google: 'Google Street View', mapillary: 'Mapillary' };
|
||||
const layer = {
|
||||
providerIds: ['mapillary', 'google'],
|
||||
requiredMapStack: (id) => (id === 'google' ? 'photoreal' : null),
|
||||
providerStatus: (id) =>
|
||||
names[id]
|
||||
? {
|
||||
id,
|
||||
name: names[id],
|
||||
on: params[id] === true,
|
||||
configured,
|
||||
keyRequired: keyRequired || keyRejected,
|
||||
keyRejected,
|
||||
error: keyRejected ? KEY_REJECTED_MESSAGE : keyRequired ? `${names[id]} needs its key` : null,
|
||||
groundClick: id === 'google',
|
||||
billed: id === 'google',
|
||||
available: id !== 'google' || stack === 'photoreal',
|
||||
}
|
||||
: null,
|
||||
getUIState: () => ({
|
||||
providers: ['mapillary', 'google']
|
||||
.filter((id) => id !== 'google' || (stack === 'photoreal' && listGoogle))
|
||||
.map((id) => ({
|
||||
id,
|
||||
name: id === 'google' ? 'Google Street View' : 'Mapillary',
|
||||
on: params[id] === true,
|
||||
configured: !keyRequired,
|
||||
keyRequired,
|
||||
groundClick: id === 'google',
|
||||
hint: keyRequired ? `${id} needs its key` : '',
|
||||
error: null,
|
||||
})),
|
||||
keyAlternatives: [],
|
||||
coverage: { hint: 'not on this map' },
|
||||
street: { ...street },
|
||||
}),
|
||||
closeViewer() {
|
||||
order.push('close');
|
||||
Object.assign(street, { open: false, imageId: null, error: null, nearestOutcome: null });
|
||||
},
|
||||
armNearest(point, options) {
|
||||
order.push(`arm:${options.providerIds.join('+')}:${options.radiusM ?? 'default'}:${point ? `${point.lat},${point.lon}` : 'view-centre'}`);
|
||||
},
|
||||
async openNearest(point, options) {
|
||||
lookups.push({ point, ...options });
|
||||
order.push(`open:${options.providerIds.join('+')}:${options.radiusM ?? 'default'}:${options.frame}${point ? '' : ':view-centre'}`);
|
||||
if (options.signal?.aborted) return false;
|
||||
if (duringLookup) {
|
||||
const effect = duringLookup();
|
||||
if (effect === 'key-rejected') {
|
||||
keyRejected = true;
|
||||
street.error = KEY_REJECTED_MESSAGE;
|
||||
return false;
|
||||
}
|
||||
if (effect === 'layer-off') {
|
||||
enabled = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Like the layer: a lookup its caller gave up leaves the panel alone,
|
||||
// and a replacing lookup that opens nothing closes the photo.
|
||||
if (options.proceed && options.proceed() !== true) return false;
|
||||
const closeReplaced = () => {
|
||||
if (options.replace && street.open) layer.closeViewer();
|
||||
};
|
||||
if (imageryError) {
|
||||
closeReplaced();
|
||||
street.error = imageryError;
|
||||
street.nearestOutcome = null;
|
||||
return false;
|
||||
}
|
||||
if (!nearest) {
|
||||
closeReplaced();
|
||||
street.nearestOutcome = options.aim === 'screen-centre' && sky ? 'sky' : 'empty';
|
||||
street.error = `No street-level imagery within ${options.radiusM ?? 50} m of ${point ? 'that point' : 'the view centre'}`;
|
||||
return false;
|
||||
}
|
||||
street.open = true;
|
||||
street.imageId = nearest;
|
||||
street.title = '10th St, Sacramento';
|
||||
street.position = point;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
const dataManager = {
|
||||
layers: new Map([['street-level', { module: layer }]]),
|
||||
isEnabled: () => enabled,
|
||||
getLayerParams: () => ({ ...params }),
|
||||
setLayerParams(id, next, { origin }) {
|
||||
origins.push(origin);
|
||||
order.push(`params:${Object.entries(next).filter(([, on]) => on).map(([k]) => k).join('+')}:${origin}`);
|
||||
if (paramsAccepted === false) return false;
|
||||
if (!lightFails) params = { ...params, ...next };
|
||||
return true;
|
||||
},
|
||||
async setEnabled(id, _on, options) {
|
||||
origins.push(options?.origin);
|
||||
order.push(`enable:${id}`);
|
||||
if (enableResult === false) return false;
|
||||
enabled = true;
|
||||
duringEnable?.();
|
||||
return true;
|
||||
},
|
||||
getAll: () => [{ id: 'street-level', name: 'Street Level', enabled }],
|
||||
};
|
||||
styleManager.setPanelCollapsed = (id, collapsed) => revealed.push(`collapse:${id}:${collapsed}`);
|
||||
styleManager.revealPanel = (id) => revealed.push(`reveal:${id}`);
|
||||
const runner = createGevActionRunner({ viewer, styleManager, dataManager });
|
||||
return {
|
||||
runner,
|
||||
order,
|
||||
finishFlight: () => completeFlight?.(),
|
||||
layer,
|
||||
dataManager,
|
||||
lookups,
|
||||
origins,
|
||||
revealed,
|
||||
street,
|
||||
// The user searches or flies elsewhere (a stamp, as the shell's), or
|
||||
// drags the globe.
|
||||
navigate: panelSearch,
|
||||
gesture: () => viewer.scene.canvas.dispatchEvent(new Event('pointerdown')),
|
||||
};
|
||||
}
|
||||
|
||||
/** A loaded CCTV camera the entity branch can locate. */
|
||||
function withCamera(harness) {
|
||||
harness.dataManager.layers.set('cctv', {
|
||||
module: {
|
||||
findByQuery: (id) => (id === 'cam-9' ? { latitude: 38.58, longitude: -121.5 } : null),
|
||||
},
|
||||
});
|
||||
const wasEnabled = harness.dataManager.isEnabled;
|
||||
harness.dataManager.isEnabled = (id) => id === 'cctv' || wasEnabled(id);
|
||||
return harness;
|
||||
}
|
||||
|
||||
test('show_street_level flies first, then switches the map, lights the source, turns the layer on and opens the nearest photo', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const { runner, order, finishFlight } = createStreetLevelHarness();
|
||||
const pending = runner('show_street_level', { latitude: 38.5799, longitude: -121.4937, provider: 'google' });
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.deepEqual(order, ['fly'], 'nothing changes until the place is reached');
|
||||
finishFlight();
|
||||
const result = await pending;
|
||||
assert.equal(result.ok, true, result.error);
|
||||
assert.deepEqual(order, [
|
||||
'fly',
|
||||
'map:photoreal',
|
||||
'params:google:voice',
|
||||
'enable:street-level',
|
||||
'open:google:250:false',
|
||||
]);
|
||||
assert.equal(result.provider, 'google');
|
||||
assert.equal(result.providerName, 'Google Street View');
|
||||
assert.equal(result.imageId, 'pano-a');
|
||||
assert.equal(result.title, '10th St, Sacramento');
|
||||
assert.equal(result.flew, true);
|
||||
// A name given with its coordinates is what the answer says.
|
||||
const named = createStreetLevelHarness();
|
||||
const naming = named.runner('show_street_level', {
|
||||
query: 'Capitol Mall', latitude: 38.5799, longitude: -121.4937, provider: 'google',
|
||||
});
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
named.finishFlight();
|
||||
assert.equal((await naming).label, 'Capitol Mall');
|
||||
});
|
||||
|
||||
test('show_street_level on Mapillary keeps the map, searches at the default radius and skips what is already on', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const { runner, order } = createStreetLevelHarness({ enabled: true, activeStack: 'osm' });
|
||||
const result = await runner('show_street_level', {
|
||||
latitude: 38.58,
|
||||
longitude: -121.49,
|
||||
provider: 'mapillary',
|
||||
fly: false,
|
||||
});
|
||||
assert.equal(result.ok, true, result.error);
|
||||
assert.deepEqual(order, ['params:mapillary:voice', 'open:mapillary:default:false']);
|
||||
assert.equal(result.flew, false);
|
||||
});
|
||||
|
||||
test('show_street_level without a source uses the one lit in the panel', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const { runner, order } = createStreetLevelHarness({
|
||||
activeStack: 'photoreal',
|
||||
lit: { mapillary: false, google: true },
|
||||
enabled: true,
|
||||
});
|
||||
const result = await runner('show_street_level', { latitude: 1, longitude: 2, fly: false });
|
||||
assert.equal(result.ok, true, result.error);
|
||||
assert.equal(result.provider, 'google');
|
||||
assert.deepEqual(order, ['params:google:voice', 'open:google:250:false']);
|
||||
});
|
||||
|
||||
test('show_street_level reports each stage it could not pass', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const centre = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal' });
|
||||
const none = await centre.runner('show_street_level', { provider: 'google' });
|
||||
assert.equal(none.ok, true, 'no place at all means the view centre');
|
||||
assert.equal(none.label, 'the view centre');
|
||||
assert.deepEqual(centre.order, ['params:google:voice', 'open:google:250:false:view-centre']);
|
||||
|
||||
const offGlobe = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal' });
|
||||
const outOfRange = await offGlobe.runner('show_street_level', { latitude: 95, longitude: 2, provider: 'google' });
|
||||
assert.deepEqual([outOfRange.ok, outOfRange.stage], [false, 'location']);
|
||||
assert.deepEqual(offGlobe.order, [], 'nothing flies, switches or looks up');
|
||||
|
||||
const unknown = await createStreetLevelHarness().runner('show_street_level', {
|
||||
latitude: 1, longitude: 2, provider: 'openstreetcam', fly: false,
|
||||
});
|
||||
assert.deepEqual([unknown.ok, unknown.stage], [false, 'provider']);
|
||||
assert.match(unknown.error, /openstreetcam/);
|
||||
|
||||
const keylessHarness = createStreetLevelHarness({ enabled: true, keyRequired: true });
|
||||
const keyless = await keylessHarness.runner('show_street_level', {
|
||||
latitude: 1, longitude: 2, provider: 'google', fly: false,
|
||||
});
|
||||
assert.deepEqual([keyless.ok, keyless.stage], [false, 'key']);
|
||||
assert.match(keyless.error, /needs its key/);
|
||||
assert.equal(keyless.providerName, 'Google Street View');
|
||||
assert.deepEqual(keylessHarness.order, [], 'a keyless source changes nothing: no flight, no map, no switch');
|
||||
|
||||
const refusedSwitch = await createStreetLevelHarness({ enabled: true, paramsAccepted: false }).runner(
|
||||
'show_street_level',
|
||||
{ latitude: 1, longitude: 2, provider: 'google', fly: false },
|
||||
);
|
||||
assert.deepEqual([refusedSwitch.ok, refusedSwitch.stage], [false, 'provider']);
|
||||
assert.match(refusedSwitch.error, /could not be switched on/);
|
||||
|
||||
const empty = await createStreetLevelHarness({ enabled: true, nearest: null }).runner(
|
||||
'show_street_level',
|
||||
{ latitude: 1, longitude: 2, provider: 'google', fly: false },
|
||||
);
|
||||
assert.deepEqual([empty.ok, empty.stage], [false, 'imagery']);
|
||||
assert.match(empty.error, /within 250 m/);
|
||||
});
|
||||
|
||||
test('show_street_level stops at the map when the source’s map is refused, before touching the panel', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const { layer, order } = createStreetLevelHarness({ enabled: true });
|
||||
const reason = 'Google 3D needs GOOGLE_MAPS_API_KEY';
|
||||
const dataManager = {
|
||||
layers: new Map([['street-level', { module: layer }]]),
|
||||
isEnabled: () => true,
|
||||
getLayerParams: () => ({ mapillary: true, google: false }),
|
||||
setLayerParams: () => order.push('params'),
|
||||
getAll: () => [],
|
||||
};
|
||||
const { viewer, styleManager } = createVoiceNavigationHarness();
|
||||
styleManager.mapStackController = { getActiveId: () => 'osm' };
|
||||
styleManager.setMapStack = async () => ({ ok: false, activeStack: 'osm', error: reason });
|
||||
const runner = createGevActionRunner({ viewer, styleManager, dataManager });
|
||||
const result = await runner('show_street_level', { latitude: 1, longitude: 2, provider: 'google', fly: false });
|
||||
assert.deepEqual([result.ok, result.stage, result.error], [false, 'map', reason]);
|
||||
assert.deepEqual(order, [], 'the source is not switched when its map is refused');
|
||||
});
|
||||
|
||||
test('show_street_level opens photos of a numbered item or a pointed spot through its entity', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const { runner, order, finishFlight } = withCamera(
|
||||
createStreetLevelHarness({ enabled: true, activeStack: 'photoreal' }),
|
||||
);
|
||||
const pending = runner('show_street_level', {
|
||||
provider: 'google',
|
||||
entity: { layerId: 'cctv', id: 'cam-9', label: 'Camera 9', lat: 38.58, lon: -121.5 },
|
||||
});
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.deepEqual(order, ['fly'], 'the entity position is flown to');
|
||||
finishFlight();
|
||||
const result = await pending;
|
||||
assert.equal(result.ok, true, result.error);
|
||||
assert.equal(result.label, 'Camera 9');
|
||||
assert.deepEqual(order, ['fly', 'params:google:voice', 'open:google:250:false']);
|
||||
});
|
||||
|
||||
test('show_street_level hands the point from a named place, a preset and a curated POI to the lookup', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const points = [];
|
||||
const make = () => {
|
||||
const harness = createStreetLevelHarness({ enabled: true, activeStack: 'osm' });
|
||||
const open = harness.layer.openNearest;
|
||||
harness.layer.openNearest = async (point, options) => {
|
||||
points.push(point);
|
||||
return open(point, options);
|
||||
};
|
||||
return harness;
|
||||
};
|
||||
// A geocoded name: the flight reports where it landed.
|
||||
const named = make();
|
||||
const viewerFor = () => ({ ...createVoiceNavigationHarness().viewer });
|
||||
const runnerWithSearch = createGevActionRunner({
|
||||
viewer: viewerFor(),
|
||||
styleManager: { mapStackController: { getActiveId: () => 'osm' }, setMapStack: async () => ({ ok: true }) },
|
||||
dataManager: {
|
||||
layers: new Map([['street-level', { module: named.layer }]]),
|
||||
isEnabled: () => true,
|
||||
getLayerParams: () => ({ mapillary: true, google: false }),
|
||||
setLayerParams: () => true,
|
||||
getAll: () => [],
|
||||
},
|
||||
searchNavigation: async (_viewer, query, options) => {
|
||||
options.onComplete?.();
|
||||
return { label: `${query}, CA`, latitude: 38.5799, longitude: -121.4937, navigationMode: 'precise-place', rangeM: 250 };
|
||||
},
|
||||
});
|
||||
const geocoded = await runnerWithSearch('show_street_level', { query: '10th Street, Sacramento', provider: 'mapillary' });
|
||||
assert.equal(geocoded.ok, true, geocoded.error);
|
||||
assert.equal(geocoded.label, '10th Street, Sacramento, CA');
|
||||
assert.deepEqual(points.at(-1), { lat: 38.5799, lon: -121.4937 });
|
||||
// A curated POI and a city preset fly to their hand-tuned poses and report them.
|
||||
for (const [args, expected] of [
|
||||
[{ query: 'Golden Gate Bridge', provider: 'mapillary' }, { lat: 37.8199, lon: -122.4783 }],
|
||||
[{ query: 'austin', provider: 'mapillary' }, null],
|
||||
]) {
|
||||
const harness = make();
|
||||
const pending = harness.runner('show_street_level', args);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
harness.finishFlight();
|
||||
const result = await pending;
|
||||
assert.equal(result.ok, true, `${args.query}: ${result.error}`);
|
||||
const point = points.at(-1);
|
||||
if (expected) assert.deepEqual(point, expected);
|
||||
else assert.ok(Number.isFinite(point.lat) && Number.isFinite(point.lon), 'a preset flight reports its point');
|
||||
}
|
||||
});
|
||||
|
||||
test('show_street_level retires its lookup when the turn is superseded, and says so', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const { runner, order, layer } = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal' });
|
||||
const controller = new AbortController();
|
||||
let currentTurn = true;
|
||||
layer.openNearest = async (_point, options) => {
|
||||
order.push(`open:signal:${Boolean(options.signal)}`);
|
||||
controller.abort();
|
||||
currentTurn = false;
|
||||
return false;
|
||||
};
|
||||
const result = await runner(
|
||||
'show_street_level',
|
||||
{ latitude: 1, longitude: 2, provider: 'google', fly: false },
|
||||
{ signal: controller.signal, isCurrent: () => currentTurn },
|
||||
);
|
||||
assert.deepEqual([result.ok, result.cancelled, result.stage], [false, true, 'imagery']);
|
||||
assert.doesNotMatch(result.error, /No .* imagery/);
|
||||
assert.ok(order.includes('open:signal:true'), 'the lookup gets the turn signal');
|
||||
});
|
||||
|
||||
test('show_street_level with autoOpen:false arms a billed source and leaves the load to a click; a free source still opens', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const armedHarness = createStreetLevelHarness({ enabled: true, activeStack: 'osm' });
|
||||
const armed = await armedHarness.runner('show_street_level', {
|
||||
latitude: 38.5799, longitude: -121.4937, provider: 'google', fly: false, autoOpen: false,
|
||||
});
|
||||
assert.equal(armed.ok, true, armed.error);
|
||||
assert.equal(armed.armed, true);
|
||||
assert.equal(armed.imageId, undefined);
|
||||
assert.deepEqual(
|
||||
armedHarness.order,
|
||||
['map:photoreal', 'params:google:voice', 'arm:google:250:38.5799,-121.4937'],
|
||||
'map and source are ready, the lookup is armed at the point, nothing is loaded',
|
||||
);
|
||||
assert.match(armed.say, /^Google Street View is ready at .*press OPEN/);
|
||||
assert.deepEqual(
|
||||
{ ...armed, say: undefined, display: undefined },
|
||||
{ ok: true, action: 'show_street_level', provider: 'google', providerName: 'Google Street View', label: '38.5799, -121.4937', armed: true, flew: false, say: undefined, display: undefined },
|
||||
);
|
||||
const free = createStreetLevelHarness({ enabled: true, activeStack: 'osm' });
|
||||
const opened = await free.runner('show_street_level', {
|
||||
latitude: 38.5799, longitude: -121.4937, provider: 'mapillary', fly: false, autoOpen: false,
|
||||
});
|
||||
assert.equal(opened.ok, true, opened.error);
|
||||
assert.equal(opened.armed, undefined);
|
||||
assert.equal(opened.imageId, 'pano-a');
|
||||
});
|
||||
|
||||
test('show_street_level tells a failed enable, a delisted source, a key refused mid-lookup and a layer switched off apart', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const at = { latitude: 1, longitude: 2, provider: 'google', fly: false };
|
||||
const notEnabled = await createStreetLevelHarness({ activeStack: 'photoreal', enableResult: false }).runner('show_street_level', at);
|
||||
assert.deepEqual([notEnabled.ok, notEnabled.stage, notEnabled.cancelled], [false, 'layer', false]);
|
||||
assert.match(notEnabled.say, /Couldn't turn on Street Level/);
|
||||
|
||||
const delisted = await createStreetLevelHarness({ enabled: true, activeStack: 'photoreal', listGoogle: false }).runner('show_street_level', at);
|
||||
assert.deepEqual([delisted.ok, delisted.stage], [false, 'provider']);
|
||||
assert.equal(delisted.error, 'not on this map');
|
||||
|
||||
const refused = await createStreetLevelHarness({ enabled: true, activeStack: 'photoreal', duringLookup: () => 'key-rejected' }).runner('show_street_level', at);
|
||||
assert.deepEqual([refused.ok, refused.stage, refused.keyRejected], [false, 'key', true]);
|
||||
assert.equal(refused.say, 'Google Street View refused its key.');
|
||||
|
||||
const switchedOff = await createStreetLevelHarness({ enabled: true, activeStack: 'photoreal', duringLookup: () => 'layer-off' }).runner('show_street_level', at);
|
||||
assert.deepEqual([switchedOff.ok, switchedOff.stage, switchedOff.cancelled], [false, 'imagery', true]);
|
||||
assert.equal(switchedOff.say, undefined, 'a request the user withdrew is not spoken');
|
||||
|
||||
// A source whose status call says it is not configured is key-gated even
|
||||
// before its coverage reports a missing key.
|
||||
const unconfigured = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal', configured: false });
|
||||
const gated = await unconfigured.runner('show_street_level', at);
|
||||
assert.deepEqual([gated.ok, gated.stage], [false, 'key']);
|
||||
assert.deepEqual(unconfigured.order, [], 'nothing changed');
|
||||
});
|
||||
|
||||
test('show_street_level reports a geocoder that throws as its location stage', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const h = createStreetLevelHarness({ enabled: true, activeStack: 'osm' });
|
||||
const runner = createGevActionRunner({
|
||||
viewer: createVoiceNavigationHarness().viewer,
|
||||
styleManager: { mapStackController: { getActiveId: () => 'osm' }, setMapStack: async () => ({ ok: true }) },
|
||||
dataManager: h.dataManager,
|
||||
placeSearch: {
|
||||
geocode: async () => {
|
||||
throw new Error('geocoder unreachable');
|
||||
},
|
||||
},
|
||||
});
|
||||
const result = await runner('show_street_level', { query: 'Capitol Mall', provider: 'mapillary' });
|
||||
assert.deepEqual([result.ok, result.stage], [false, 'location']);
|
||||
assert.equal(result.error, 'Could not arrive at Capitol Mall');
|
||||
assert.deepEqual(h.order.filter((step) => /^(params|open|arm)/.test(step)), [], 'nothing switched or looked up');
|
||||
});
|
||||
|
||||
test('show_street_level reports a flight that lands without a position', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const hit = createStreetLevelHarness({ enabled: true, activeStack: 'osm' });
|
||||
// A flight that reports no coordinates cannot be followed by a lookup.
|
||||
const noPoint = createGevActionRunner({
|
||||
viewer: createVoiceNavigationHarness().viewer,
|
||||
styleManager: { mapStackController: { getActiveId: () => 'osm' }, setMapStack: async () => ({ ok: true }) },
|
||||
dataManager: hit.dataManager,
|
||||
searchNavigation: async (_viewer, query, options) => {
|
||||
options.onComplete?.();
|
||||
return { label: query, navigationMode: 'city-overview', rangeM: null };
|
||||
},
|
||||
});
|
||||
const unplaced = await noPoint('show_street_level', { query: 'Somewhere', provider: 'mapillary' });
|
||||
assert.deepEqual([unplaced.ok, unplaced.stage], [false, 'location']);
|
||||
assert.match(unplaced.error, /no position/);
|
||||
});
|
||||
|
||||
test('fly_to_location reports the overview centre for a city framed as a whole, and the first POI for a close view', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const { viewer, styleManager } = createVoiceNavigationHarness();
|
||||
viewer.camera.lookAt = () => {};
|
||||
viewer.camera.flyTo = (options) => options.complete?.();
|
||||
viewer.camera.flyToBoundingSphere = (_s, options) => options.complete?.();
|
||||
styleManager.runImmediateLocationNavigation = (navigate) => styleManager.runImmediateNavigation('location', navigate);
|
||||
const runner = createGevActionRunner({ viewer, styleManager, dataManager: { layers: new Map(), getAll: () => [] } });
|
||||
const overview = await runner('fly_to_location', { locationId: 'austin' });
|
||||
assert.equal(overview.ok, true);
|
||||
assert.ok(Math.abs(overview.latitude - 30.31) < 0.001, String(overview.latitude));
|
||||
assert.ok(Math.abs(overview.longitude - -97.75) < 0.001, String(overview.longitude));
|
||||
const close = await runner('fly_to_location', { locationId: 'austin', viewMode: 'close' });
|
||||
assert.deepEqual([close.latitude, close.longitude], [30.2747, -97.7403]);
|
||||
});
|
||||
|
||||
test('show_street_level arms the view centre when a billed link names no place, and keeps the flight label when it flew', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const centre = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal' });
|
||||
const armed = await centre.runner('show_street_level', { provider: 'google', autoOpen: false });
|
||||
assert.equal(armed.ok, true, armed.error);
|
||||
assert.equal(armed.armed, true);
|
||||
assert.deepEqual(centre.order, ['params:google:voice', 'arm:google:250:view-centre'], 'armed at the view centre, nothing opened');
|
||||
const flown = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal' });
|
||||
const pending = flown.runner('show_street_level', { latitude: 38.5799, longitude: -121.4937, provider: 'google', autoOpen: false });
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
flown.finishFlight();
|
||||
const result = await pending;
|
||||
assert.equal(result.armed, true);
|
||||
assert.equal(result.flew, true);
|
||||
assert.equal(result.location, '38.5799, -121.4937');
|
||||
assert.ok(!flown.order.some((entry) => entry.startsWith('open:')), 'no load after the flight');
|
||||
});
|
||||
|
||||
test('show_street_level says "refused its key" when Google already refused it, and fails when the source will not light', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const refusedHarness = createStreetLevelHarness({ enabled: true, keyRejectedAtStart: true });
|
||||
const refused = await refusedHarness.runner('show_street_level', { latitude: 1, longitude: 2, provider: 'google', fly: false });
|
||||
assert.deepEqual([refused.ok, refused.stage, refused.keyRejected], [false, 'key', true]);
|
||||
assert.equal(refused.error, KEY_REJECTED_MESSAGE);
|
||||
assert.equal(refused.say, 'Google Street View refused its key.');
|
||||
assert.deepEqual(refusedHarness.order, [], 'nothing changed');
|
||||
const dark = await createStreetLevelHarness({ enabled: true, activeStack: 'photoreal', lightFails: true }).runner(
|
||||
'show_street_level',
|
||||
{ latitude: 1, longitude: 2, provider: 'google', fly: false },
|
||||
);
|
||||
assert.deepEqual([dark.ok, dark.stage], [false, 'provider']);
|
||||
assert.match(dark.error, /could not be switched on/);
|
||||
});
|
||||
|
||||
test('activeImageryFilter reports only the narrowing filters the lit source honours', async () => {
|
||||
const { activeImageryFilter } = await import('./gevActions.js');
|
||||
const both = { pano: true, since: true };
|
||||
assert.equal(activeImageryFilter({ filter: { pano: 'all', sinceDays: 0 }, filterControls: both }), null);
|
||||
assert.deepEqual(activeImageryFilter({ filter: { pano: 'pano', sinceDays: 0 }, filterControls: both }), {
|
||||
pano: 'pano',
|
||||
label: '360° filter',
|
||||
});
|
||||
assert.deepEqual(activeImageryFilter({ filter: { pano: 'flat', sinceDays: 365 }, filterControls: both }), {
|
||||
pano: 'flat',
|
||||
sinceDays: 365,
|
||||
label: 'flat-photo and SINCE filters',
|
||||
});
|
||||
assert.equal(
|
||||
activeImageryFilter({ filter: { pano: 'pano', sinceDays: 365 }, filterControls: { pano: false, since: false } }),
|
||||
null,
|
||||
'Street View honours neither',
|
||||
);
|
||||
assert.equal(activeImageryFilter(undefined), null);
|
||||
});
|
||||
|
||||
test('analyst item display strings are single-line and bounded for voice', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const rows = [{ id: 'stable-id', name: 'Şehir\n' + 'x'.repeat(3000), label: 'Town\tStation', operator: 'City\nPD', lat: 30, lon: -97 }];
|
||||
@@ -6688,3 +7251,296 @@ test('a partial analyst card shows one partial chip', () => {
|
||||
const labels = card.display.chips.map((chip) => chip.label);
|
||||
assert.equal(new Set(labels).size, labels.length, JSON.stringify(labels));
|
||||
});
|
||||
|
||||
test('show_street_level superseded during its flight switches nothing', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const h = createStreetLevelHarness();
|
||||
let current = true;
|
||||
const pending = h.runner('show_street_level', { latitude: 38.5799, longitude: -121.4937, provider: 'google' }, { isCurrent: () => current });
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
current = false;
|
||||
h.finishFlight();
|
||||
const result = await pending;
|
||||
assert.deepEqual(h.order.filter((step) => /^(map|params|open|arm|enable)/.test(step)), [], 'the stale turn switched nothing');
|
||||
assert.equal(result.cancelled, true);
|
||||
});
|
||||
|
||||
test('show_street_level superseded during its map switch lights no source', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const h = createStreetLevelHarness({ enabled: true });
|
||||
let current = true;
|
||||
const runner = createGevActionRunner({
|
||||
viewer: createVoiceNavigationHarness().viewer,
|
||||
styleManager: {
|
||||
mapStackController: { getActiveId: () => 'osm' },
|
||||
setMapStack: async (id) => {
|
||||
h.order.push(`map:${id}`);
|
||||
current = false;
|
||||
return { ok: true, activeStack: id };
|
||||
},
|
||||
},
|
||||
dataManager: h.dataManager,
|
||||
});
|
||||
const result = await runner('show_street_level', { latitude: 1, longitude: 2, provider: 'google', fly: false }, { isCurrent: () => current });
|
||||
assert.deepEqual(h.order.filter((step) => /^(params|open|arm)/.test(step)), [], 'the stale turn lit nothing');
|
||||
assert.deepEqual([result.stage, result.cancelled], ['map', true]);
|
||||
});
|
||||
|
||||
test('show_street_level goes ahead while a source’s key status is still unknown', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
// A freshly loaded sl= link meets the source before its status call answers.
|
||||
const { runner, order } = createStreetLevelHarness({ enabled: true, configured: null });
|
||||
const result = await runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'mapillary', fly: false });
|
||||
assert.equal(result.ok, true);
|
||||
assert.ok(order.some((step) => step.startsWith('open:mapillary')));
|
||||
});
|
||||
|
||||
test('show_street_level in a view that hides its panel stops before anything loads unseen', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const saved = globalThis.document;
|
||||
for (const mode of ['cockpit-mode', 'ui-clean-view', 'recording-mode', 'scene-playback-mode']) {
|
||||
globalThis.document = { body: { classList: { contains: (name) => name === mode } } };
|
||||
try {
|
||||
const { runner, order } = createStreetLevelHarness({ enabled: true });
|
||||
const result = await runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'google', fly: false });
|
||||
assert.deepEqual([result.ok, result.stage], [false, 'view'], mode);
|
||||
assert.match(result.error, /hidden in the current view/);
|
||||
assert.deepEqual(order.filter((step) => /^(map|params|open|arm|enable)/.test(step)), [], `${mode}: nothing switched`);
|
||||
} finally {
|
||||
globalThis.document = saved;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('show_street_level checks the panel again after every wait: a mode entered meanwhile loads nothing unseen', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const saved = globalThis.document;
|
||||
const classes = new Set();
|
||||
globalThis.document = { body: { classList: { contains: (name) => classes.has(name) } } };
|
||||
try {
|
||||
for (const [mode, when] of [
|
||||
['ui-clean-view', 'duringEnable'],
|
||||
['cockpit-mode', 'duringMapSwitch'],
|
||||
]) {
|
||||
classes.clear();
|
||||
const h = createStreetLevelHarness({ [when]: () => classes.add(mode) });
|
||||
const result = await h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'google', fly: false });
|
||||
assert.deepEqual([result.ok, result.stage], [false, 'view'], mode);
|
||||
assert.deepEqual(h.order.filter((step) => /^(open|arm)/.test(step)), [], `${mode}: no billed load`);
|
||||
assert.deepEqual(h.revealed, [], `${mode}: nothing revealed`);
|
||||
}
|
||||
// Entered while the photo loaded: it is closed again, not reported as shown.
|
||||
classes.clear();
|
||||
const late = createStreetLevelHarness({ enabled: true });
|
||||
const open = late.layer.openNearest;
|
||||
late.layer.openNearest = async (...call) => {
|
||||
const opened = await open(...call);
|
||||
classes.add('recording-mode');
|
||||
return opened;
|
||||
};
|
||||
const result = await late.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'mapillary', fly: false });
|
||||
assert.deepEqual([result.ok, result.stage], [false, 'view']);
|
||||
assert.equal(late.order.at(-1), 'close');
|
||||
assert.deepEqual(late.revealed, []);
|
||||
} finally {
|
||||
globalThis.document = saved;
|
||||
}
|
||||
});
|
||||
|
||||
test('show_street_level refuses a hidden panel before the camera leaves a recording', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const saved = globalThis.document;
|
||||
globalThis.document = { body: { classList: { contains: (name) => name === 'recording-mode' } } };
|
||||
try {
|
||||
const { runner, order } = createStreetLevelHarness();
|
||||
const result = await runner('show_street_level', { query: 'Eiffel Tower', provider: 'mapillary' });
|
||||
assert.deepEqual([result.ok, result.stage], [false, 'view']);
|
||||
assert.deepEqual(order, [], 'no flight');
|
||||
} finally {
|
||||
globalThis.document = saved;
|
||||
}
|
||||
});
|
||||
|
||||
test('show_street_level stops once the camera is someone else’s: a navigation or a gesture during the map switch', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
for (const take of ['navigate', 'gesture']) {
|
||||
let h;
|
||||
h = createStreetLevelHarness({ duringMapSwitch: () => h[take]() });
|
||||
const result = await h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'mapillary', fly: false });
|
||||
assert.equal(result.ok, true, `${take}: Mapillary needs no map switch`);
|
||||
h = createStreetLevelHarness({ duringMapSwitch: () => h[take]() });
|
||||
const google = await h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'google', fly: false });
|
||||
assert.deepEqual([google.ok, google.stage, google.cancelled, google.superseded], [false, 'map', true, true], take);
|
||||
assert.deepEqual(h.order.filter((step) => /^(params|enable|open|arm)/.test(step)), [], `${take}: nothing lit for the old place`);
|
||||
}
|
||||
// During the layer switch-on: the photo lookup never runs.
|
||||
let h;
|
||||
h = createStreetLevelHarness({ duringEnable: () => h.navigate() });
|
||||
const result = await h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'mapillary', fly: false });
|
||||
assert.deepEqual([result.ok, result.stage, result.superseded], [false, 'layer', true]);
|
||||
assert.ok(!h.order.some((step) => step.startsWith('open:')));
|
||||
});
|
||||
|
||||
test('show_street_level loads no photo it found once the camera or the panel moved on during the lookup', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
for (const take of ['navigate', 'gesture']) {
|
||||
let h;
|
||||
h = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal', duringLookup: () => h[take]() });
|
||||
const result = await h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'google', fly: false });
|
||||
assert.deepEqual([result.ok, result.stage, result.superseded], [false, 'imagery', true], take);
|
||||
assert.equal(h.lookups.length, 1);
|
||||
assert.equal(h.street.open, false, `${take}: the billed panorama never loads`);
|
||||
assert.ok(!h.order.includes('close'), `${take}: nothing opened, nothing to close`);
|
||||
}
|
||||
const saved = globalThis.document;
|
||||
const classes = new Set();
|
||||
globalThis.document = { body: { classList: { contains: (name) => classes.has(name) } } };
|
||||
try {
|
||||
const h = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal', duringLookup: () => classes.add('ui-clean-view') });
|
||||
const result = await h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'google', fly: false });
|
||||
assert.deepEqual([result.ok, result.stage], [false, 'view']);
|
||||
assert.equal(h.street.open, false, 'nothing loads into the hidden panel');
|
||||
} finally {
|
||||
globalThis.document = saved;
|
||||
}
|
||||
});
|
||||
|
||||
test('show_street_level replaces an open photo in place: the viewer (and EXPAND) stays up while it looks', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const h = createStreetLevelHarness({ enabled: true, photoOpen: true, nearest: 'pano-b' });
|
||||
const result = await h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'mapillary', fly: false });
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(h.lookups[0].replace, true, 'the lookup takes over the open photo');
|
||||
assert.ok(!h.order.includes('close'), 'never closed on the way');
|
||||
assert.deepEqual([h.street.open, h.street.imageId], [true, 'pano-b']);
|
||||
});
|
||||
|
||||
test('show_street_level owns the camera from where its own flight lands', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const h = createStreetLevelHarness();
|
||||
const pending = h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'mapillary' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
h.finishFlight();
|
||||
const result = await pending;
|
||||
assert.equal(result.ok, true, result.error);
|
||||
assert.ok(h.order.some((step) => step.startsWith('open:mapillary')));
|
||||
});
|
||||
|
||||
// A camera taken during the action's own flight. 'navigate' is a
|
||||
// location-panel search: a stamp that leaves the flight flying. 'gesture' is a
|
||||
// press on the globe, which does not cancel a Cesium flight either.
|
||||
for (const take of ['navigate', 'gesture']) {
|
||||
test(`show_street_level stands down when the camera is taken during its own flight (${take})`, async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const h = createStreetLevelHarness();
|
||||
const pending = h.runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'google' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.deepEqual(h.order, ['fly'], 'the flight is under way');
|
||||
h[take]();
|
||||
h.finishFlight();
|
||||
const result = await pending;
|
||||
assert.deepEqual([result.ok, result.superseded], [false, true], result.error);
|
||||
assert.deepEqual(
|
||||
h.order.filter((step) => /^(map|params|open|arm|enable)/.test(step)),
|
||||
[],
|
||||
'no map switch, no source, no billed photo for the place the user left',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
test('show_street_level closes the previous photo, so one that finds nothing leaves no other place on screen', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const empty = createStreetLevelHarness({ enabled: true, photoOpen: true, nearest: null });
|
||||
const result = await empty.runner('show_street_level', { latitude: 23.4, longitude: 12.5, provider: 'mapillary', fly: false });
|
||||
assert.deepEqual([result.ok, result.noImagery], [false, true]);
|
||||
assert.equal(empty.street.open, false, 'the Paris photo is gone');
|
||||
assert.match(empty.street.error, /No street-level imagery/, 'the panel shows why');
|
||||
// A link that only arms a billed source closes it too.
|
||||
const armed = createStreetLevelHarness({ enabled: true, photoOpen: true, activeStack: 'photoreal' });
|
||||
await armed.runner('show_street_level', { latitude: 23.4, longitude: 12.5, provider: 'google', fly: false, autoOpen: false });
|
||||
assert.deepEqual(armed.order.filter((step) => /^(close|arm)/.test(step)).map((step) => step.split(':')[0]), ['close', 'arm']);
|
||||
});
|
||||
|
||||
test('show_street_level opens over the clean embedded globe but respects its other exclusive modes', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const saved = globalThis.document;
|
||||
try {
|
||||
for (const mode of [null, 'cockpit-mode', 'recording-mode', 'scene-playback-mode']) {
|
||||
const classes = new Set(['ui-embed', 'ui-clean-view', mode]);
|
||||
globalThis.document = { body: { classList: { contains: (name) => classes.has(name) } } };
|
||||
const { runner, order } = createStreetLevelHarness({ enabled: true });
|
||||
const result = await runner('show_street_level', { latitude: 38.58, longitude: -121.49, provider: 'mapillary', fly: false });
|
||||
if (mode) {
|
||||
assert.deepEqual([result.ok, result.stage], [false, 'view'], mode);
|
||||
assert.deepEqual(order.filter((step) => /^(map|params|open|arm|enable)/.test(step)), [], `${mode}: nothing switched`);
|
||||
} else {
|
||||
assert.equal(result.ok, true, 'embed clean view lifts the photo over the globe');
|
||||
assert.ok(order.some((step) => step.startsWith('open:mapillary')));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
globalThis.document = saved;
|
||||
}
|
||||
});
|
||||
|
||||
test('show_street_level from a link keeps the recipient’s preferences: its switches are not the user’s', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const link = createStreetLevelHarness();
|
||||
const linked = await link.runner(
|
||||
'show_street_level',
|
||||
{ latitude: 1, longitude: 2, provider: 'mapillary', fly: false },
|
||||
{ origin: 'programmatic' },
|
||||
);
|
||||
assert.equal(linked.ok, true, linked.error);
|
||||
assert.deepEqual(link.origins, ['programmatic', 'programmatic'], 'source switch and layer on');
|
||||
const asked = createStreetLevelHarness();
|
||||
await asked.runner('show_street_level', { latitude: 1, longitude: 2, provider: 'mapillary', fly: false });
|
||||
assert.deepEqual(asked.origins, ['voice', 'voice'], 'the assistant’s request is the user’s choice');
|
||||
});
|
||||
|
||||
test('show_street_level with no place looks under the screen centre, not a link’s armed point', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const here = createStreetLevelHarness({ enabled: true });
|
||||
const result = await here.runner('show_street_level', { provider: 'mapillary' });
|
||||
assert.equal(result.ok, true, result.error);
|
||||
assert.equal(result.atViewCentre, true);
|
||||
assert.equal(here.lookups[0].point, null);
|
||||
assert.equal(here.lookups[0].aim, 'screen-centre');
|
||||
assert.equal(here.lookups[0].armed, false);
|
||||
const placed = createStreetLevelHarness({ enabled: true });
|
||||
await placed.runner('show_street_level', { latitude: 1, longitude: 2, provider: 'mapillary', fly: false });
|
||||
assert.equal(placed.lookups[0].aim, undefined, 'a place is looked up where it is');
|
||||
const sky = createStreetLevelHarness({ enabled: true, nearest: null, sky: true });
|
||||
const refused = await sky.runner('show_street_level', { provider: 'mapillary' });
|
||||
assert.deepEqual([refused.ok, refused.stage, refused.aim], [false, 'imagery', 'sky']);
|
||||
});
|
||||
|
||||
test('show_street_level tells missing imagery from a failing source', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const empty = await createStreetLevelHarness({ enabled: true, nearest: null }).runner('show_street_level', {
|
||||
latitude: 1, longitude: 2, provider: 'mapillary', fly: false,
|
||||
});
|
||||
assert.deepEqual([empty.stage, empty.noImagery, empty.imageryError], ['imagery', true, undefined]);
|
||||
const broken = await createStreetLevelHarness({ enabled: true, imageryError: 'Mapillary graph HTTP 500' }).runner(
|
||||
'show_street_level',
|
||||
{ latitude: 1, longitude: 2, provider: 'mapillary', fly: false },
|
||||
);
|
||||
assert.deepEqual([broken.stage, broken.noImagery, broken.imageryError], ['imagery', undefined, true]);
|
||||
assert.equal(broken.error, 'Mapillary graph HTTP 500');
|
||||
});
|
||||
|
||||
test('show_street_level shows every photo it opens, also over a panel the user had closed', async () => {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const harness = createStreetLevelHarness({ enabled: true });
|
||||
await harness.runner('show_street_level', { latitude: 1, longitude: 2, provider: 'mapillary', fly: false });
|
||||
await harness.runner('show_street_level', { latitude: 3, longitude: 4, provider: 'mapillary', fly: false });
|
||||
assert.deepEqual(harness.revealed, [
|
||||
'collapse:street-level-panel:false',
|
||||
'reveal:street-level-panel',
|
||||
'collapse:street-level-panel:false',
|
||||
'reveal:street-level-panel',
|
||||
]);
|
||||
const missing = createStreetLevelHarness({ enabled: true, nearest: null });
|
||||
await missing.runner('show_street_level', { latitude: 1, longitude: 2, provider: 'mapillary', fly: false });
|
||||
assert.deepEqual(missing.revealed, [], 'nothing opened, nothing revealed');
|
||||
});
|
||||
@@ -714,13 +714,13 @@ test('without an operator Overpass the prompt never offers place search', () =>
|
||||
});
|
||||
|
||||
test('the Realtime prompt stays within its size budget', () => {
|
||||
// Instructions plus tool schemas, in characters, under the same 55,500
|
||||
// Instructions plus tool schemas, in characters, under the same 56,500
|
||||
// ceiling as the deixis prompt lint. Voice geometry adds resolve_area,
|
||||
// find_imagery and the analyst area scopes (osm_query only with an
|
||||
// operator Overpass).
|
||||
// operator Overpass); show_street_level adds its tool and routing rule.
|
||||
const size = (overpass) =>
|
||||
realtimeInstructions(undefined, { overpass }).length +
|
||||
JSON.stringify(realtimeTools({ overpass })).length;
|
||||
assert.ok(size(false) <= 55_500, `default prompt ${size(false)} chars`);
|
||||
assert.ok(size(true) <= 55_500, `with Overpass ${size(true)} chars`);
|
||||
assert.ok(size(false) <= 56_500, `default prompt ${size(false)} chars`);
|
||||
assert.ok(size(true) <= 56_500, `with Overpass ${size(true)} chars`);
|
||||
});
|
||||
@@ -364,7 +364,12 @@ const layers = [
|
||||
},
|
||||
{
|
||||
id: 'street-level',
|
||||
aliases: ['street level', 'street-level imagery', 'mapillary'],
|
||||
aliases: [
|
||||
'street level',
|
||||
'street-level imagery',
|
||||
'mapillary',
|
||||
'street view',
|
||||
],
|
||||
context: false,
|
||||
noQuery: 'street-level imagery; no countable records',
|
||||
},
|
||||
|
||||
@@ -119,6 +119,7 @@ test('spoken aliases resolve to real layers, keep every legacy phrase and never
|
||||
'weather radar': 'weather-radar', lightning: 'weather-lightning', 'military bases': 'military-installations',
|
||||
'recent imagery': 'recent-imagery', 'bike share': 'bikeshare', 'rocket launches': 'rocket-launches',
|
||||
'street level': 'street-level', mapillary: 'street-level',
|
||||
'street view': 'street-level',
|
||||
wind: 'wind', directions: 'directions', 'fire perimeters': 'fire-perimeters',
|
||||
'wildfire perimeters': 'fire-perimeters', 'burn areas': 'fire-perimeters',
|
||||
};
|
||||
|
||||
@@ -343,19 +343,11 @@ test('deixis prompt lint: one short rule, and every sentinel it names exists in
|
||||
tool('annotate_map').annotations.items.properties.target.description,
|
||||
/"pointer"/,
|
||||
);
|
||||
// Budget: the whole Realtime prompt (instructions + tools), measured in
|
||||
// characters. It was 56,308 after the area/imagery/OSM merge; stating each
|
||||
// policy once (WHERE precedence, AREAS routing, AFTER TOOLS speech) brought
|
||||
// it to 51,646. Voice geometry (resolve_area, find_imagery, osm_query and
|
||||
// the analyst area scopes) raised the ceiling to 55,500; tightening the
|
||||
// AREAS rule and the area tool descriptions left it at 55,103 as measured
|
||||
// below (every tool, osm_query included); main's Sea Marks and Ski Pistes
|
||||
// layers bring it to 55,210, and the tilt pitchDeg argument (with its -45
|
||||
// default) and main's cockpit entry rule to 55,339. integrationContract's
|
||||
// Overpass prompt is the tightest, at 55,499 (1 under). A new tool or rule
|
||||
// has to fit under this ceiling.
|
||||
// Budget: the whole Realtime prompt (instructions + every tool, osm_query
|
||||
// included), in characters. Every session pays for it in latency and cost,
|
||||
// so a new tool or rule has to fit under this ceiling or earn a raise.
|
||||
const size = instructions.length + JSON.stringify(GEV_REALTIME_TOOLS).length;
|
||||
assert.ok(size <= 55_500, `prompt size ${size}`);
|
||||
assert.ok(size <= 56_500, `prompt size ${size}`);
|
||||
});
|
||||
|
||||
test('after-tool speech allows returned items to answer requested lists and rankings', () => {
|
||||
|
||||
@@ -27,6 +27,7 @@ const CAMERA_TOOLS = new Set([
|
||||
'fly_route',
|
||||
'frame_overhead',
|
||||
'select_nearest_aircraft',
|
||||
'show_street_level',
|
||||
'control_cockpit',
|
||||
]);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
import { voiceLayer } from './layerManifest.js';
|
||||
import {
|
||||
formatDate,
|
||||
formatNumber,
|
||||
getLocale,
|
||||
msg,
|
||||
@@ -178,9 +179,27 @@ const KNOWN_ERRORS = new Map(
|
||||
),
|
||||
msg('Could not arrive at the requested place'),
|
||||
msg('The nearest airborne aircraft could not be selected'),
|
||||
// show_street_level
|
||||
msg('Latitude must be within ±90° and longitude within ±180°'),
|
||||
msg('Street Level is unavailable'),
|
||||
msg('No street-level imagery source is configured'),
|
||||
msg('Street Level could not be enabled'),
|
||||
msg('Street Level changed while it looked for imagery'),
|
||||
msg('Aim the view at a street'),
|
||||
].map((text) => [text, text]),
|
||||
);
|
||||
|
||||
/** The imagery filters an empty street-level result names, as its chips say them. */
|
||||
function shownImageryFilters(label) {
|
||||
return [
|
||||
label.includes('360°') ? '360°' : null,
|
||||
label.includes('flat-photo') ? t('FLAT') : null,
|
||||
label.includes('SINCE') ? t('SINCE') : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
function noneWithinView(target, radius) {
|
||||
switch (target) {
|
||||
case 'flights':
|
||||
@@ -258,6 +277,69 @@ const ERROR_PATTERNS = [
|
||||
/^No (\S+) within (\d+(?:\.\d+)?) km of the current view$/,
|
||||
([, target, km]) => noneWithinView(target, shownKm(km)),
|
||||
],
|
||||
// show_street_level: the filter clause first, around the reason it extends.
|
||||
[
|
||||
/^(.+) with the (.+ filters?) on$/,
|
||||
([, reason, filters]) =>
|
||||
t('{reason} (filters on: {filters})', {
|
||||
reason: shownError(reason),
|
||||
filters: shownImageryFilters(filters),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^(.+) is not a street-level imagery source here$/,
|
||||
([, source]) =>
|
||||
t('{source} is not a street-level imagery source here', { source }),
|
||||
],
|
||||
[
|
||||
/^(.+) needs its key$/,
|
||||
([, source]) =>
|
||||
t('{source} needs its key', { source: translateKnown(source) }),
|
||||
],
|
||||
[
|
||||
/^(.+) needs the (.+) map, which is not available$/,
|
||||
([, source, map]) =>
|
||||
t('{source} needs the {map} map, which is not available', {
|
||||
source: translateKnown(source),
|
||||
map: map === 'photoreal' ? 'Google 3D' : map,
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^(.+) could not be switched on$/,
|
||||
([, source]) =>
|
||||
t('{source} could not be switched on', {
|
||||
source: translateKnown(source),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^(.+) is not available on this map$/,
|
||||
([, source]) =>
|
||||
t('{source} is not available on this map', {
|
||||
source: translateKnown(source),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^(.+) imagery could not be opened$/,
|
||||
([, source]) =>
|
||||
t('{source} imagery could not be opened', {
|
||||
source: translateKnown(source),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^(.+) has no position to look for imagery at$/,
|
||||
([, place]) =>
|
||||
t('{place} has no position to look for imagery at', {
|
||||
place: localizePlaceName(place),
|
||||
}),
|
||||
],
|
||||
[
|
||||
/^No (.+) imagery near (.+)$/,
|
||||
([, source, place]) =>
|
||||
t('No {source} imagery near {place}', {
|
||||
source: translateKnown(source),
|
||||
place: localizePlaceName(place),
|
||||
}),
|
||||
],
|
||||
];
|
||||
|
||||
/** A tool error as the card shows it. */
|
||||
@@ -594,6 +676,98 @@ function selectNearestAircraft(result) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Month and year an image was captured, or ''. */
|
||||
function capturedMonth(capturedAt) {
|
||||
const ms = Number(capturedAt);
|
||||
if (!Number.isFinite(ms) || ms <= 0) return '';
|
||||
try {
|
||||
// Dates are UTC months (Google: the first of the month).
|
||||
return formatDate(new Date(ms), {
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
timeZone: 'UTC',
|
||||
});
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function showStreetLevel(result) {
|
||||
// `location` is the flight's own result on a failed flight; its label is
|
||||
// the place, never the object.
|
||||
const place = spokenLabel(
|
||||
result?.label ||
|
||||
(typeof result?.location === 'string'
|
||||
? result.location
|
||||
: result?.location?.label) ||
|
||||
'there',
|
||||
);
|
||||
const source = spokenLabel(result?.providerName || 'Street Level');
|
||||
// The card in the interface language; the spoken line stays English.
|
||||
const shownSource = result?.providerName
|
||||
? spokenLabel(result.providerName)
|
||||
: t('Street Level');
|
||||
// The view centre is a phrase, not a place name: the card says it in the
|
||||
// interface language.
|
||||
const shown = result?.atViewCentre
|
||||
? t('the view centre')
|
||||
: spokenLabel(localizePlaceName(result?.label || '')) || place;
|
||||
if (result?.cancelled) return null;
|
||||
if (!result?.ok) {
|
||||
let say;
|
||||
if (result?.stage === 'location') say = `Couldn't find ${place}.`;
|
||||
else if (result?.stage === 'map')
|
||||
say = `${source} needs the Google 3D map, which isn't available.`;
|
||||
else if (result?.stage === 'key')
|
||||
say = result?.keyRejected
|
||||
? `${source} refused its key.`
|
||||
: `${source} needs its key.`;
|
||||
else if (result?.stage === 'layer') say = "Couldn't turn on Street Level.";
|
||||
else if (result?.stage === 'view')
|
||||
say = 'Street-level photos are hidden in this view. Leave it first.';
|
||||
else if (result?.stage === 'imagery' && result?.aim === 'sky')
|
||||
say = 'Aim the middle of the view at a street first.';
|
||||
else if (result?.stage === 'imagery' && result?.filter?.label)
|
||||
say = `No ${source} imagery near ${place} with the ${result.filter.label} on.`;
|
||||
else if (result?.stage === 'imagery' && result?.noImagery === true)
|
||||
say = `No ${source} imagery near ${place}.`;
|
||||
// A service or viewer failure is not missing coverage.
|
||||
else if (result?.stage === 'imagery')
|
||||
say = `${source} could not open imagery near ${place}.`;
|
||||
else say = `Couldn't open ${source}.`;
|
||||
return {
|
||||
say,
|
||||
display: {
|
||||
title: shownSource,
|
||||
lines: errorLines(result),
|
||||
sources: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
if (result.armed === true)
|
||||
return {
|
||||
say: sentence(`${source} is ready at ${place}: press OPEN to load it`),
|
||||
display: {
|
||||
title: shownSource,
|
||||
lines: [shown, t('Press OPEN to load the photo')],
|
||||
sources: [{ label: shownSource }],
|
||||
},
|
||||
};
|
||||
const title = spokenLabel(result.title || '', 60);
|
||||
const month = capturedMonth(result.capturedAt);
|
||||
return {
|
||||
say: sentence(`${source} at ${title || place}`),
|
||||
display: {
|
||||
title: shownSource,
|
||||
lines: [
|
||||
title || shown,
|
||||
month ? t('Captured {month}', { month }) : null,
|
||||
].filter(Boolean),
|
||||
sources: [{ label: shownSource }],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const SPOKEN_ROUTE = Object.freeze({
|
||||
between: (origin, destination) => `${origin} to ${destination}`,
|
||||
from: (origin) => `from ${origin}`,
|
||||
@@ -801,6 +975,7 @@ export const SPEECH_BUILDERS = Object.freeze({
|
||||
fly_to_location: flyToLocation,
|
||||
frame_overhead: frameOverhead,
|
||||
select_nearest_aircraft: selectNearestAircraft,
|
||||
show_street_level: showStreetLevel,
|
||||
get_entity_context: getEntityContext,
|
||||
get_current_view_state: getCurrentViewState,
|
||||
annotate_map: annotateMap,
|
||||
@@ -856,6 +1031,14 @@ function annotationTargets(args) {
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
/** Street-level sources as a plan step names them. */
|
||||
const STREET_LEVEL_SOURCE_NAMES = Object.freeze({
|
||||
google: 'Street View',
|
||||
mapillary: 'Mapillary',
|
||||
kartaview: 'KartaView',
|
||||
panoramax: 'Panoramax',
|
||||
});
|
||||
|
||||
// frame_overhead targets as the schema names them.
|
||||
function frameStepLabel(target) {
|
||||
switch (target) {
|
||||
@@ -927,6 +1110,17 @@ export function planStepLabel(name, args = {}) {
|
||||
? t('Nearest aircraft to {place}', { place: shownPlace(place, 32) })
|
||||
: t('Nearest aircraft to Here');
|
||||
}
|
||||
case 'show_street_level': {
|
||||
const source = STREET_LEVEL_SOURCE_NAMES[args.provider];
|
||||
const place = args.query
|
||||
? shownPlace(args.query, 32)
|
||||
: args.latitude != null
|
||||
? t('this spot')
|
||||
: t('the view centre');
|
||||
return source
|
||||
? t('{source} at {place}', { source, place })
|
||||
: t('Street level at {place}', { place });
|
||||
}
|
||||
case 'set_layer_visibility': {
|
||||
const on = args.enabled !== false;
|
||||
const label =
|
||||
@@ -988,6 +1182,8 @@ export function narrationLabel(name, args = {}) {
|
||||
presetPlaceName(args.locationQuery || args.locationId || ''),
|
||||
32,
|
||||
);
|
||||
case 'show_street_level':
|
||||
return shownPlace(args.query || '', 32);
|
||||
case 'resolve_area':
|
||||
return displayName(args.query || '', 32);
|
||||
case 'find_imagery':
|
||||
@@ -1008,6 +1204,8 @@ const STEP_LABELS = Object.freeze({
|
||||
layer: msg('Turning on layer'),
|
||||
refresh: msg('Loading aircraft'),
|
||||
nearest: msg('Picking nearest'),
|
||||
map: msg('Switching map'),
|
||||
imagery: msg('Opening imagery'),
|
||||
draw: msg('Drawing outline'),
|
||||
catalog: msg('Searching imagery catalog'),
|
||||
drape: msg('Loading imagery'),
|
||||
@@ -1056,6 +1254,12 @@ export function progressLine(step, label) {
|
||||
return 'Loading aircraft there.';
|
||||
case 'nearest':
|
||||
return 'Picking the nearest aircraft.';
|
||||
case 'map':
|
||||
return place === 'photoreal'
|
||||
? 'Switching to Google 3D.'
|
||||
: 'Switching the map.';
|
||||
case 'imagery':
|
||||
return place ? `Looking for imagery at ${place}.` : null;
|
||||
case 'still':
|
||||
return place ? `Still working on ${place}.` : 'Still working on it.';
|
||||
default:
|
||||
|
||||
@@ -536,6 +536,238 @@ test('labels are bounded and cleaned before they are spoken', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('the street-level card says "the view centre" in the interface language', () => {
|
||||
setLocale('de');
|
||||
try {
|
||||
const out = envelope('show_street_level', {
|
||||
ok: true,
|
||||
providerName: 'Mapillary',
|
||||
label: 'the view centre',
|
||||
atViewCentre: true,
|
||||
});
|
||||
assert.equal(out.display.lines[0], 'die Bildmitte');
|
||||
assert.match(out.say, /the view centre/, 'speech stays English');
|
||||
} finally {
|
||||
setLocale('en');
|
||||
}
|
||||
});
|
||||
|
||||
test('street-level failure cards are in the interface language; speech stays English', () => {
|
||||
setLocale('de');
|
||||
try {
|
||||
const card = (error, extra = {}) =>
|
||||
envelope('show_street_level', {
|
||||
ok: false,
|
||||
action: 'show_street_level',
|
||||
providerName: 'Google Street View',
|
||||
label: 'Paris',
|
||||
error,
|
||||
...extra,
|
||||
});
|
||||
const lines = (error, extra) => card(error, extra).display.lines;
|
||||
assert.deepEqual(lines('Google Street View needs its key', { stage: 'key' }), [
|
||||
'Google Street View braucht seinen Schlüssel',
|
||||
]);
|
||||
assert.deepEqual(
|
||||
lines('Google Street View needs the photoreal map, which is not available', { stage: 'map' }),
|
||||
['Google Street View braucht die Google 3D-Karte, die nicht verfügbar ist'],
|
||||
);
|
||||
assert.deepEqual(lines('Mapillary could not be switched on', { stage: 'provider' }), [
|
||||
'Mapillary konnte nicht eingeschaltet werden',
|
||||
]);
|
||||
assert.deepEqual(lines('Street Level could not be enabled', { stage: 'layer' }), [
|
||||
'Straßenebene konnte nicht eingeschaltet werden',
|
||||
]);
|
||||
assert.deepEqual(
|
||||
lines('Latitude must be within ±90° and longitude within ±180°', { stage: 'location' }),
|
||||
['Der Breitengrad muss innerhalb von ±90° und der Längengrad innerhalb von ±180° liegen'],
|
||||
);
|
||||
assert.deepEqual(lines('Mapillary imagery could not be opened', { stage: 'imagery' }), [
|
||||
'Bilder von Mapillary konnten nicht geöffnet werden',
|
||||
]);
|
||||
// The filter clause wraps the reason, already in the interface language,
|
||||
// and names the filters as their chips do.
|
||||
const filtered = card('No Mapillary imagery near Paris with the 360° and SINCE filters on', {
|
||||
stage: 'imagery',
|
||||
noImagery: true,
|
||||
filter: { label: '360° and SINCE filters' },
|
||||
});
|
||||
assert.deepEqual(filtered.display.lines, [
|
||||
'Keine Bilder von Mapillary in der Nähe von Paris (aktive Filter: 360°, SEIT)',
|
||||
]);
|
||||
assert.match(filtered.say, /with the 360° and SINCE filters on/, 'speech stays English');
|
||||
} finally {
|
||||
setLocale('en');
|
||||
}
|
||||
});
|
||||
|
||||
test('street-level speech names the source and the place, and says which step failed', () => {
|
||||
const ok = envelope('show_street_level', {
|
||||
ok: true,
|
||||
action: 'show_street_level',
|
||||
provider: 'google',
|
||||
providerName: 'Google Street View',
|
||||
label: '10th Street, Sacramento',
|
||||
title: '1000 10th St, Sacramento, CA',
|
||||
capturedAt: Date.UTC(2024, 4, 1), // Google dates: the first of the month, UTC
|
||||
});
|
||||
assert.equal(ok.say, 'Google Street View at 1000 10th St, Sacramento, CA.');
|
||||
assertSpeakable(ok.say);
|
||||
assert.equal(ok.display.title, 'Google Street View');
|
||||
assert.equal(ok.display.lines[1], 'Captured May 2024');
|
||||
|
||||
const stages = {
|
||||
location: "Couldn't find Nowhere.",
|
||||
map: "Google Street View needs the Google 3D map, which isn't available.",
|
||||
key: 'Google Street View needs its key.',
|
||||
layer: "Couldn't turn on Street Level.",
|
||||
// A service or viewer failure, not missing coverage.
|
||||
imagery: 'Google Street View could not open imagery near Nowhere.',
|
||||
};
|
||||
for (const [stage, say] of Object.entries(stages)) {
|
||||
const out = envelope('show_street_level', {
|
||||
ok: false,
|
||||
stage,
|
||||
label: 'Nowhere',
|
||||
providerName: 'Google Street View',
|
||||
error: 'detail',
|
||||
});
|
||||
assert.equal(out.say, say, stage);
|
||||
assertSpeakable(out.say);
|
||||
assert.deepEqual(out.display.lines, ['detail']);
|
||||
}
|
||||
const empty = envelope('show_street_level', {
|
||||
ok: false,
|
||||
stage: 'imagery',
|
||||
noImagery: true,
|
||||
label: 'Nowhere',
|
||||
providerName: 'Mapillary',
|
||||
});
|
||||
assert.equal(empty.say, 'No Mapillary imagery near Nowhere.');
|
||||
const sky = envelope('show_street_level', {
|
||||
ok: false,
|
||||
stage: 'imagery',
|
||||
aim: 'sky',
|
||||
atViewCentre: true,
|
||||
label: 'the view centre',
|
||||
providerName: 'Mapillary',
|
||||
});
|
||||
assert.equal(sky.say, 'Aim the middle of the view at a street first.');
|
||||
assertSpeakable(sky.say);
|
||||
const armed = envelope('show_street_level', {
|
||||
ok: true,
|
||||
armed: true,
|
||||
providerName: 'Google Street View',
|
||||
label: '10th St, Sacramento',
|
||||
});
|
||||
assert.equal(armed.say, 'Google Street View is ready at 10th St, Sacramento: press OPEN to load it.');
|
||||
assertSpeakable(armed.say);
|
||||
assert.deepEqual(armed.display.lines, ['10th St, Sacramento', 'Press OPEN to load the photo']);
|
||||
const unfound = envelope('show_street_level', {
|
||||
ok: false,
|
||||
stage: 'location',
|
||||
location: { ok: false, action: 'fly_to_location', label: 'Nowhere Town' },
|
||||
});
|
||||
assert.equal(unfound.say, "Couldn't find Nowhere Town.");
|
||||
assert.equal(unfound.display.title, 'Street Level');
|
||||
const refused = envelope('show_street_level', {
|
||||
ok: false,
|
||||
stage: 'key',
|
||||
keyRejected: true,
|
||||
providerName: 'Google Street View',
|
||||
});
|
||||
assert.equal(refused.say, 'Google Street View refused its key.');
|
||||
assert.equal(
|
||||
envelope('show_street_level', { ok: false, cancelled: true }).say,
|
||||
undefined,
|
||||
);
|
||||
assert.equal(
|
||||
planStepLabel('show_street_level', {
|
||||
query: 'Eiffel Tower',
|
||||
provider: 'google',
|
||||
}),
|
||||
'Street View at Eiffel Tower',
|
||||
);
|
||||
assert.equal(
|
||||
planStepLabel('show_street_level', {
|
||||
query: 'Times Square',
|
||||
provider: 'mapillary',
|
||||
}),
|
||||
'Mapillary at Times Square',
|
||||
);
|
||||
assert.equal(
|
||||
progressStepLabel('imagery', 'Eiffel Tower'),
|
||||
'Opening imagery: Eiffel Tower',
|
||||
);
|
||||
assert.equal(progressLine('map', 'photoreal'), 'Switching to Google 3D.');
|
||||
assert.equal(
|
||||
progressLine('imagery', 'Eiffel Tower'),
|
||||
'Looking for imagery at Eiffel Tower.',
|
||||
);
|
||||
});
|
||||
|
||||
test('the capture month is a UTC month whatever the timezone, and labels name the place', async () => {
|
||||
const { execFileSync } = await import('node:child_process');
|
||||
const speech = new URL('./speech.js', import.meta.url).href;
|
||||
// Google dates a panorama 2024-05 as the first of the month, UTC. West of
|
||||
// Greenwich that instant is still April; the card must still say May.
|
||||
const out = execFileSync(
|
||||
process.execPath,
|
||||
[
|
||||
'--input-type=module',
|
||||
'-e',
|
||||
`import { attachVoiceResult } from ${JSON.stringify(speech)};
|
||||
const r = attachVoiceResult('show_street_level', { ok: true, providerName: 'Google Street View', label: 'x', capturedAt: Date.UTC(2024, 4, 1) });
|
||||
process.stdout.write(r.display.lines[1]);`,
|
||||
],
|
||||
{ env: { ...process.env, TZ: 'America/Los_Angeles' }, encoding: 'utf8' },
|
||||
);
|
||||
assert.equal(out, 'Captured May 2024');
|
||||
const { narrationLabel } = await import('./speech.js');
|
||||
assert.equal(narrationLabel('show_street_level', { query: 'Eiffel Tower' }), 'Eiffel Tower');
|
||||
assert.equal(narrationLabel('show_street_level', {}), '');
|
||||
assert.equal(
|
||||
planStepLabel('show_street_level', { latitude: 1, longitude: 2 }),
|
||||
'Street level at this spot',
|
||||
);
|
||||
assert.equal(planStepLabel('show_street_level', {}), 'Street level at the view centre');
|
||||
});
|
||||
|
||||
test('the plan step names KartaView as a source', () => {
|
||||
assert.equal(
|
||||
planStepLabel('show_street_level', {
|
||||
query: 'Alexanderplatz',
|
||||
provider: 'kartaview',
|
||||
}),
|
||||
'KartaView at Alexanderplatz',
|
||||
);
|
||||
});
|
||||
|
||||
test('an empty street-level search names the imagery filter that hid the photos', () => {
|
||||
const out = envelope('show_street_level', {
|
||||
ok: false,
|
||||
stage: 'imagery',
|
||||
label: 'Alexanderplatz',
|
||||
providerName: 'KartaView',
|
||||
filter: { pano: 'pano', label: '360° filter' },
|
||||
});
|
||||
assert.equal(
|
||||
out.say,
|
||||
'No KartaView imagery near Alexanderplatz with the 360° filter on.',
|
||||
);
|
||||
assertSpeakable(out.say);
|
||||
});
|
||||
|
||||
test('the plan step names Panoramax as a source', () => {
|
||||
assert.equal(
|
||||
planStepLabel('show_street_level', {
|
||||
query: 'Montmartre',
|
||||
provider: 'panoramax',
|
||||
}),
|
||||
'Panoramax at Montmartre',
|
||||
);
|
||||
});
|
||||
|
||||
test('progress step labels join through the catalog colon', () => {
|
||||
setLocale('fr');
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user