feat(street-level): "show me X on Street View" action, street_level view field and sl= links

show_street_level (voice and typed) flies to a place and opens its nearest
street-level photo from Google Street View, Mapillary, KartaView or
Panoramax; Street View switches to Google 3D first. The view model gains a
street_level field, share links carry sl=<source>,<lat>,<lon>, and
show_in_gods_eye_view can open a photo. A plain sl=google link only arms the
point and waits for OPEN, so it never bills a key without a click.

Embed pages show an open photo in an overlay that Esc closes. On-screen
strings are translated into es, ru, zh-CN and zh-Hant. Covered by unit tests
and three new steps in the Street Level browser suite.
This commit is contained in:
Said Turksever committed 2026-11-03 14:32:02 +00:00
1 parent f3adccd01a
commit 98de41c94a
64 files changed
+4147 -66

No files matched your search

+30
View File
@@ -103,6 +103,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: {
+29 -11
View File
@@ -38,21 +38,38 @@ test('the complete Realtime tool payload pins the manifest-generated layer relea
// consolidated tool wording (each policy stated once); model-facing tools
// omit top-level anyOf (OpenAI rejects it). Contacts list routing preserves
// requested radius and center authority in descriptions only.
// Street Level and GNSS extend the manifest; tracked and analyst aircraft describe broadcasts.
// Air quality (ECCC AQHI) extends the manifest.
// Globe rotation adds one motion; visual keyhole fit and explicit
// reset guidance/defaults update only move_camera and mode descriptions.
// S2 GhostMaps extends the generated layer enums.
// The Utilities panel (Directions, Draw, Import) adds one panel target.
// Panel adds named voice targets and timeout; shared Panel/Cockpit guidance
// is consolidated without changing either feature's arguments.
// Snow leaves the set_visual_style enum.
// The Operator HUD layout leaves set_hud's layout enum.
// The layer alias hint leaves out aliases the layer id already spells.
// Street Level, GNSS and air quality (ECCC AQHI) extend the manifest;
// tracked and analyst aircraft describe broadcasts; globe rotation adds
// one motion; S2 GhostMaps, the Utilities panel target and the voice panel
// (named targets, timeout) follow; Snow leaves the set_visual_style enum, the Operator HUD layout
// leaves set_hud's layout enum and the layer alias hint leaves out aliases
// the layer id already spells; show_street_level (map, source, photo) is
// the only change on top of main.
SHOW_STREET_LEVEL_PAYLOAD_DIGEST,
);
// Every shipped tool is byte-identical to the previous release: the new
// tool is the whole difference, so a later edit cannot hide in a re-pin.
const shipped = createHash('sha256')
.update(
JSON.stringify(
stable(
GEV_REALTIME_TOOLS.filter(
(tool) =>
!['set_cyber_sonar', 'show_street_level'].includes(tool.name),
),
),
),
)
.digest('hex');
assert.equal(
shipped,
'dc2bac1be93a503dc88d637beea2f1bc457e1f9167422bd91548b44756a8aca5',
);
});
const SHOW_STREET_LEVEL_PAYLOAD_DIGEST =
'2198c1f95cfbc19e89ba8814ad0fd8303a74a7b254703f2e7a4893f5798d9aed';
test('descriptions customize wording without changing immutable shared arguments', () => {
const descriptions = {
fly_to_location: {
@@ -112,6 +129,7 @@ test('all legacy action arguments are byte-identical after removing the delibera
'next_satellite_pass',
'set_cyber_sonar',
'set_voice_inactivity_timeout',
'show_street_level',
].includes(tool.name),
);
// Layer enums are generated from the voice layer manifest and pinned by
+1
View File
@@ -330,6 +330,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,
+7
View File
@@ -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' });
});
+364
View File
@@ -34,6 +34,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,
@@ -731,6 +735,18 @@ export function createGevActionRunner({
};
}
if (name === 'show_street_level') {
return showStreetLevel(args, {
dataManager,
styleManager,
placeSearch,
runGevAction,
runOptions,
current,
reportProgress,
});
}
if (name === 'set_visual_style') {
const style = normalizeStyle(args.style);
if (!style)
@@ -2582,6 +2598,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.
@@ -2589,6 +2628,7 @@ function stopAllTracking(viewer, dataManager) {
* detection so the framed entities are labeled, and reports
* detectionEnabled so the voice agent can mention labels are on.
*/
async function frameOverhead(viewer, dataManager, styleManager, args = {}) {
const targetRaw = String(args.target || 'flights').toLowerCase();
const layerId =
@@ -3245,6 +3285,311 @@ function normalizeStyle(value) {
return null;
}
/**
* "Show me <place> on Street View / on Mapillary": fly to the place, make sure
* the imagery source's map is up, light that source in Street Level, turn the
* layer on and open the nearest image. One source at a time, as the panel
* does; the choice persists like a chip click. The key is checked before
* anything changes, and each stage reports its own failure so speech can say
* which part did not happen. With no place at all, the view centre is used.
* `autoOpen: false` (links, not the model) stops short of loading a photo
* from a source that bills every load: the panel is armed and the OPEN
* button is one click away.
*/
export async function showStreetLevel(
args,
{
dataManager,
styleManager,
placeSearch,
runGevAction,
runOptions = {},
current = () => true,
reportProgress = () => {},
},
) {
const action = 'show_street_level';
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 } : {}),
...extra,
});
const query = String(args.query || '').trim();
const latitude = Number(args.latitude);
const longitude = Number(args.longitude);
const hasCoordinates =
args.latitude != null &&
args.longitude != null &&
Number.isFinite(latitude) &&
Number.isFinite(longitude);
// 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, on any map: a chip without a key explains it and switches
// nothing, and so does this.
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 || [],
});
// 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';
const atViewCentre = !query && !hasCoordinates && !entity;
let point = null;
let location = null;
if (args.fly === false || atViewCentre) {
if (hasCoordinates) point = { lat: latitude, lon: longitude };
else if (entity) {
// Where it is now, as the flying path does: the coordinates a list
// saved go stale as soon as the item moves or unloads.
const located = locateLayerEntity(dataManager, entity);
if (!located) return fail('location', `${label} is no longer loaded`);
point = { lat: located.lat, lon: located.lon };
} else if (query) {
reportProgress('search', query);
const outcome = await placeSearch.geocode(query, {
signal: runOptions.signal,
});
const place = outcome?.place;
if (!current())
return fail('location', 'Street-level request was cancelled');
if (!Number.isFinite(place?.lat) || !Number.isFinite(place?.lng))
return fail('location', `Could not find ${query}`);
point = { lat: place.lat, lon: place.lng };
label = place.label || query;
}
// No place at all: the layer looks under the view centre.
} else {
location = await runGevAction(
'fly_to_location',
{
...(entity
? { entity }
: hasCoordinates
? { latitude, longitude }
: { query }),
viewMode: 'close',
waitForArrival: true,
},
runOptions,
);
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 keeps its name: the flight to it reports only coordinates.
label = entity ? 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 };
}
// 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 },
);
}
// Light the source the way a chip click does, so the choice is kept.
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: 'voice',
}) !== 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: !current() || Boolean(layer?.cancelled), layer, location },
);
}
// 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 billed source never loads from a link without a click: everything is
// ready and OPEN is one press away at the view centre.
if (args.autoOpen === false && status?.billed === true) {
// The next OPEN press loads exactly what the link asked for.
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 } : {}),
};
}
// A source with no coverage to click (Street View) is searched wider: a
// geocoded landmark is rarely within 50 m of a street. A newer turn
// retires the lookup: nothing opens after the user moved on.
reportProgress('imagery', label);
const opened = await layerModule.openNearest(point, {
providerIds: [provider],
frame: false,
...(runOptions.signal ? { signal: runOptions.signal } : {}),
...(snapshot.groundClick === true
? { radiusM: STREET_LEVEL_WIDE_RADIUS_M }
: {}),
});
const street = layerModule.getUIState?.()?.street || {};
// A cancelled request opens nothing (the lookup and the viewer both honour
// the turn's signal); a photo that did open is reported as open.
if (opened !== true && !current())
return fail('imagery', 'Street-level request was cancelled', {
cancelled: true,
location,
});
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 },
);
// 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, ...(filter ? { filter } : {}) },
);
}
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,
...(location ? { location: location.label } : {}),
};
}
async function flyToRequestedLocation(
viewer,
args,
@@ -3309,11 +3654,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'
@@ -3374,6 +3733,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,
};
@@ -3404,6 +3764,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,
};
+533
View File
@@ -20,6 +20,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';
import { attachVoiceResult } from './speech.js';
@@ -3987,6 +3988,538 @@ 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,
} = {}) {
const order = [];
const { viewer, styleManager } = createVoiceNavigationHarness();
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;
return { ok: true, activeStack: id, error: null };
};
let params = { ...lit };
let keyRejected = keyRejectedAtStart;
const street = { 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 },
}),
armNearest(point, options) {
order.push(`arm:${options.providerIds.join('+')}:${options.radiusM ?? 'default'}:${point ? `${point.lat},${point.lon}` : 'view-centre'}`);
},
async openNearest(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;
}
}
if (!nearest) {
street.error = `No street-level imagery within ${options.radiusM ?? 50} m of ${point ? 'that point' : 'the view centre'}`;
return false;
}
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 }) {
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) {
order.push(`enable:${id}`);
if (enableResult === false) return false;
enabled = true;
return true;
},
getAll: () => [{ id: 'street-level', name: 'Street Level', enabled }],
};
const runner = createGevActionRunner({ viewer, styleManager, dataManager });
return { runner, order, finishFlight: () => completeFlight?.(), layer, dataManager };
}
/** 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);
});
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 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']);
// Without a flight the entity's own position is used.
const still = withCamera(createStreetLevelHarness({ enabled: true, activeStack: 'photoreal' }));
const kept = await still.runner('show_street_level', {
provider: 'google',
fly: false,
entity: { layerId: 'cctv', id: 'cam-9', lat: 38.58, lon: -121.5 },
});
assert.equal(kept.ok, true, kept.error);
assert.deepEqual(still.order, ['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 without a flight geocodes a name, locates an item, and reports what it cannot place', async () => {
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
const hit = createStreetLevelHarness({ enabled: true, activeStack: 'osm' });
const points = [];
const open = hit.layer.openNearest;
hit.layer.openNearest = (point, options) => {
points.push(point);
return open(point, options);
};
const runner = createGevActionRunner({
viewer: createVoiceNavigationHarness().viewer,
styleManager: { mapStackController: { getActiveId: () => 'osm' }, setMapStack: async () => ({ ok: true }) },
dataManager: hit.dataManager,
placeSearch: {
geocode: async (query) =>
query === 'Capitol Mall'
? { place: { lat: 38.5792, lng: -121.4958, label: 'Capitol Mall, Sacramento' } }
: { place: null, answered: true },
},
});
const found = await runner('show_street_level', { query: 'Capitol Mall', provider: 'mapillary', fly: false });
assert.equal(found.ok, true, found.error);
assert.equal(found.label, 'Capitol Mall, Sacramento');
assert.deepEqual(points.at(-1), { lat: 38.5792, lon: -121.4958 });
assert.equal(found.flew, false);
const miss = await runner('show_street_level', { query: 'Atlantis Boulevard', provider: 'mapillary', fly: false });
assert.deepEqual([miss.ok, miss.stage], [false, 'location']);
assert.equal(miss.say, "Couldn't find Atlantis Boulevard.");
assert.equal(points.length, 1, 'a miss asks for no imagery');
const gone = await runner('show_street_level', {
provider: 'mapillary', fly: false, entity: { layerId: 'cctv', id: 'cam-gone', label: 'Camera 7' },
});
assert.deepEqual([gone.ok, gone.stage], [false, 'location']);
assert.equal(gone.say, "Couldn't find Camera 7.");
// 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('show_street_level without a flight needs the item where it is now, not where a list saw it', async () => {
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
const harness = createStreetLevelHarness({ enabled: true, activeStack: 'photoreal' });
// The referent carries the coordinates the list saved, but it is no longer loaded.
const stale = await harness.runner('show_street_level', {
provider: 'google',
fly: false,
entity: { layerId: 'cctv', id: 'cam-gone', label: 'Camera 7', lat: 38.58, lon: -121.5 },
});
assert.deepEqual([stale.ok, stale.stage], [false, 'location']);
assert.match(stale.error, /no longer loaded/);
assert.ok(!harness.order.some((entry) => entry.startsWith('open:')), 'nothing looked up at the stale point');
});
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('set_panel_open accepts the Authoring name for the scene panel', async () => {
const calls = [];
const runner = createGevActionRunner({
+6 -1
View File
@@ -352,7 +352,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',
},
+1
View File
@@ -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',
};
+1
View File
@@ -27,6 +27,7 @@ const CAMERA_TOOLS = new Set([
'fly_route',
'frame_overhead',
'select_nearest_aircraft',
'show_street_level',
'control_cockpit',
]);
+112
View File
@@ -24,6 +24,7 @@
import { analystHeadline } from './resultDisplay.js';
import {
formatDate,
formatNumber,
getLocale,
msg,
@@ -564,6 +565,87 @@ 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');
const shown = 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 === 'imagery')
say = result?.filter?.label
? `No ${source} imagery near ${place} with the ${result.filter.label} on.`
: `No ${source} 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}`,
@@ -771,6 +853,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,
@@ -826,6 +909,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) {
@@ -897,6 +988,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 =
@@ -940,6 +1042,8 @@ export function narrationLabel(name, args = {}) {
presetPlaceName(args.locationQuery || args.locationId || ''),
32,
);
case 'show_street_level':
return shownPlace(args.query || '', 32);
default:
return '';
}
@@ -954,6 +1058,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'),
});
/** On-screen label for a progress step. */
@@ -988,6 +1094,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:
+148
View File
@@ -489,6 +489,154 @@ test('labels are bounded and cleaned before they are spoken', () => {
);
});
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.",
imagery: 'No Google Street View 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 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 {