mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Merge main into german/transit-bikeshare-empty-state
Conflict in src/layers/transit/queries.js: keep the branch's shared note with the gate's enter altitude and main's distinct region count.
This commit is contained in:
commit
3a78f40024
218 files changed
+29736
-599
No files matched your search
@@ -753,6 +753,7 @@ const schemas = [
|
||||
type: 'string',
|
||||
enum: ['once', 'continuous'],
|
||||
},
|
||||
pitchDeg: { type: 'number' },
|
||||
},
|
||||
required: ['motion'],
|
||||
},
|
||||
|
||||
@@ -55,7 +55,10 @@ test('the complete Realtime tool payload pins the manifest-generated layer relea
|
||||
// Voice geometry adds resolve_area, find_imagery, osm_query, the analyst
|
||||
// area scopes and the osm-places layer; natural-region candidates and the
|
||||
// tightened area tool wording follow review.
|
||||
'd0c5ad733670972713a54cb10676c42b7c6e78834bfff52b473c0e8a45e742c3',
|
||||
// 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',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -174,6 +177,8 @@ test('all legacy action arguments are byte-identical after removing the delibera
|
||||
'stop',
|
||||
]);
|
||||
motion.enum = motion.enum.filter((value) => value !== 'rotate_globe');
|
||||
// Tilt to an angle is additive.
|
||||
delete property('move_camera').pitchDeg;
|
||||
const panels = property('set_panel_open').panelId;
|
||||
panels.enum = panels.enum.filter(
|
||||
(id) =>
|
||||
@@ -319,3 +324,15 @@ test('direct voice timeout schema accepts None and exact integers, rejects malfo
|
||||
for (const minutes of [-1, 61, 1.5, '5'])
|
||||
assert.ok(validateArgs(tool.parameters, { minutes }).length > 0);
|
||||
});
|
||||
|
||||
test('tilt accepts an angle with no direction', () => {
|
||||
const schema = GEV_ACTION_SCHEMAS.find(
|
||||
(tool) => tool.name === 'move_camera',
|
||||
).parameters;
|
||||
assert.deepEqual(validateArgs(schema, { motion: 'tilt', pitchDeg: -45 }), []);
|
||||
assert.deepEqual(validateArgs(schema, { motion: 'tilt' }), []);
|
||||
// No range in the schema (prompt budget): the runner clamps to -89..-5.
|
||||
assert.ok(
|
||||
validateArgs(schema, { motion: 'tilt', pitchDeg: 'steep' }).length > 0,
|
||||
);
|
||||
});
|
||||
+32
-10
@@ -1,6 +1,7 @@
|
||||
import { bindChatAttachments } from './chatAttachments.js';
|
||||
import { bindChatPreferences } from './chatPreferences.js';
|
||||
import { readStoredCloudVoiceAuthMode } from './cloudVoiceAuth.js';
|
||||
import { isStoppable } from './session.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
|
||||
/**
|
||||
@@ -94,7 +95,9 @@ export function bindChatControl({ ui, session, onOpen, dataManager }) {
|
||||
: '';
|
||||
function open({ focus = true } = {}) {
|
||||
leaveChatSettings();
|
||||
if (!isTyped() && session.isActive()) session.stop();
|
||||
// Chat replaces voice, a stale voice error included, so the dock stops
|
||||
// showing it.
|
||||
if (!isTyped() && isStoppable(session)) session.stop();
|
||||
onOpen?.();
|
||||
ui.update('chat', { open: true, minimized: false, rows: 2, authNote });
|
||||
sync();
|
||||
@@ -389,15 +392,7 @@ export function bindChatControl({ ui, session, onOpen, dataManager }) {
|
||||
}
|
||||
const frame = ui.element('chatPanel')?.getBoundingClientRect?.();
|
||||
close();
|
||||
ui.update('voicePanel', {
|
||||
context: 'chat',
|
||||
...(frame?.width && {
|
||||
frameWidth: frame.width,
|
||||
frameHeight: frame.height,
|
||||
}),
|
||||
});
|
||||
ui.update('chat', { backVisible: true });
|
||||
sync();
|
||||
showChatSettings(frame);
|
||||
void ui.focus(['chatBack']);
|
||||
}),
|
||||
// The panel clears its context as it closes, so chat tracks its own.
|
||||
@@ -413,10 +408,37 @@ export function bindChatControl({ ui, session, onOpen, dataManager }) {
|
||||
}),
|
||||
];
|
||||
sync();
|
||||
// Settings shown from chat, in chat's frame when it has one.
|
||||
function showChatSettings(frame) {
|
||||
ui.update('voicePanel', {
|
||||
context: 'chat',
|
||||
...(frame?.width && {
|
||||
frameWidth: frame.width,
|
||||
frameHeight: frame.height,
|
||||
}),
|
||||
});
|
||||
ui.update('chat', { backVisible: true });
|
||||
sync();
|
||||
}
|
||||
// What a provider switch carries to the next mount: chat's Settings, never
|
||||
// the conversation. The provider choice lives only in Settings, so chat
|
||||
// itself is never open during a switch.
|
||||
function presentation() {
|
||||
if (!inChatSettings()) return null;
|
||||
const { frameWidth: width, frameHeight: height } = ui.state.voicePanel;
|
||||
return { view: 'settings', frame: width ? { width, height } : null };
|
||||
}
|
||||
// Restored without moving focus: the switch keeps it on the provider choice.
|
||||
function restorePresentation(state) {
|
||||
if (disposed || state?.view !== 'settings') return;
|
||||
showChatSettings(state.frame);
|
||||
}
|
||||
return {
|
||||
close,
|
||||
minimize,
|
||||
restore: open,
|
||||
presentation,
|
||||
restorePresentation,
|
||||
get minimized() {
|
||||
return chat().open && chat().minimized;
|
||||
},
|
||||
|
||||
@@ -364,3 +364,35 @@ test('the chat gear is named for the settings it opens', async (t) => {
|
||||
'Settings',
|
||||
);
|
||||
});
|
||||
|
||||
test('a provider switch carries chat Settings to the next mount', async (t) => {
|
||||
const mount = () => {
|
||||
const ui = createTestVoiceUi({ panel: true });
|
||||
const chat = bindChatControl({ ui, session: typedSession() });
|
||||
t.after(() => chat.destroy());
|
||||
return { ui, chat };
|
||||
};
|
||||
// Chat's Settings: the next mount shows Settings in chat's frame again.
|
||||
const before = mount();
|
||||
before.ui.emit('chat-button');
|
||||
before.ui.update('voicePanel', { hidden: false });
|
||||
before.ui.emit('settings-button');
|
||||
before.ui.update('voicePanel', { frameWidth: 320, frameHeight: 480 });
|
||||
const settings = before.chat.presentation();
|
||||
assert.deepEqual(settings, {
|
||||
view: 'settings',
|
||||
frame: { width: 320, height: 480 },
|
||||
});
|
||||
const after = mount();
|
||||
after.chat.restorePresentation(settings);
|
||||
assert.equal(after.ui.state.voicePanel.context, 'chat');
|
||||
assert.equal(after.ui.state.voicePanel.frameWidth, 320);
|
||||
assert.equal(after.ui.state.voicePanel.frameHeight, 480);
|
||||
assert.equal(after.ui.state.chat.backVisible, true);
|
||||
assert.equal(after.ui.state.root.assistantMode, 'chat');
|
||||
// Chat itself, or no chat at all, carries nothing.
|
||||
const open = mount();
|
||||
open.ui.emit('chat-button');
|
||||
assert.equal(open.chat.presentation(), null);
|
||||
assert.equal(mount().chat.presentation(), null);
|
||||
});
|
||||
@@ -184,6 +184,9 @@ export class GeminiSessionController {
|
||||
this.model = null;
|
||||
this.epoch = 0;
|
||||
this.turn = 0;
|
||||
// Identifies one turn's tool calls to the runner as one reply; a new
|
||||
// object each turn, so no two sessions or turns share it.
|
||||
this.turnReply = {};
|
||||
this.globeToolsBlocked = false;
|
||||
this.globeResetFailed = false;
|
||||
this.inputGeneration = 0;
|
||||
@@ -971,6 +974,7 @@ export class GeminiSessionController {
|
||||
const tools = [...this.tools.values()];
|
||||
this.turnAbort = new AbortController();
|
||||
this.turn++;
|
||||
this.turnReply = {};
|
||||
this.typedIntent = null;
|
||||
this.radioStrongerCommit = null;
|
||||
this.pruneControls();
|
||||
@@ -1544,6 +1548,7 @@ export class GeminiSessionController {
|
||||
)
|
||||
throw new Error(msg('Gemini requested too many simultaneous actions'));
|
||||
const turn = this.turn;
|
||||
const reply = this.turnReply;
|
||||
this.userTurnPending = false;
|
||||
this.modelComplete = false;
|
||||
// Admit each valid native call ID once per connection.
|
||||
@@ -1565,6 +1570,7 @@ export class GeminiSessionController {
|
||||
const action = new AbortController();
|
||||
action.call = { id: call.id, name: call.name };
|
||||
action.sequence = ++this.toolSequence;
|
||||
action.reply = reply;
|
||||
this.tools.set(call.id, action);
|
||||
const priorTools = this.toolQueue;
|
||||
const args =
|
||||
@@ -1674,6 +1680,9 @@ export class GeminiSessionController {
|
||||
this.runAction(call.name, args, {
|
||||
signal: toolSignal,
|
||||
callId: call.id,
|
||||
// Calls run one by one, so a motion can follow a fly-to of the
|
||||
// same reply that already found nothing.
|
||||
reply: action.reply,
|
||||
progress: (update) => {
|
||||
if (actionCurrent()) this.narration.progress(call.id, update);
|
||||
},
|
||||
|
||||
@@ -1241,6 +1241,34 @@ test('successful stronger Radio stop still invalidates the prepared group', asyn
|
||||
h.c.stop();
|
||||
});
|
||||
|
||||
test('Gemini tools of one turn share a reply identity, and a new turn gets another', async () => {
|
||||
const replies = [];
|
||||
const h = harness({
|
||||
runAction: (name, _args, next) => {
|
||||
replies.push([name, next.reply]);
|
||||
return { ok: true, action: name };
|
||||
},
|
||||
});
|
||||
await h.c.start({ pushToTalk: true });
|
||||
h.c.sendTextCommand('Fly to Xyzzyville and pan left');
|
||||
const ws = h.sockets[0];
|
||||
requestTool(ws, 'fly', 'fly_to_location', { query: 'Xyzzyville' });
|
||||
requestTool(ws, 'pan', 'move_camera', { motion: 'pan', direction: 'left' });
|
||||
await h.c.toolQueue;
|
||||
assert.equal(replies.length, 2);
|
||||
assert.ok(replies[0][1], 'a sequentially run call carries its reply');
|
||||
assert.equal(replies[1][1], replies[0][1]);
|
||||
drainRadioReply(h);
|
||||
await tick();
|
||||
assert.equal(h.c.sendTextCommand('Pan left'), true);
|
||||
requestTool(ws, 'pan-2', 'move_camera', { motion: 'pan', direction: 'left' });
|
||||
await h.c.toolQueue;
|
||||
assert.equal(replies.length, 3);
|
||||
assert.ok(replies[2][1]);
|
||||
assert.notEqual(replies[2][1], replies[0][1]);
|
||||
h.c.stop();
|
||||
});
|
||||
|
||||
test('slow Gemini tools reuse shared progress timing without injecting a conversation turn', async () => {
|
||||
const pending = deferred();
|
||||
let options;
|
||||
|
||||
+328
-17
@@ -47,6 +47,9 @@ import {
|
||||
flyRoute,
|
||||
interruptCameraMotion,
|
||||
adjustOrbitRange,
|
||||
manualCameraInputCount,
|
||||
moveCameraArgsError,
|
||||
getActiveCameraMotion,
|
||||
} from '../cameraVerbs.js';
|
||||
import * as defaultFloorServices from '../data/groundFloor.js';
|
||||
import { isPickedWorldPosition } from '../data/scenePick.js';
|
||||
@@ -286,6 +289,28 @@ export function createGevActionRunner({
|
||||
? { ...SPEECH_BUILDERS, ...speechBuilders }
|
||||
: SPEECH_BUILDERS;
|
||||
const _layerEnabledAt = new Map();
|
||||
// The latest voice flight. A tilt, orbit, pan or rotate in the same reply
|
||||
// as "fly to X" waits for it to land: run at once, its navigation
|
||||
// cancelled the flight, or the flight (still geocoding) then replaced the
|
||||
// motion. The wait follows later fly-tos (voiceFlightTarget).
|
||||
let voiceFlight = null;
|
||||
// Waiters to tell when a newer voice flight begins.
|
||||
const voiceFlightWatchers = new Set();
|
||||
// Camera handoffs (navigation stamps) seen, and how many of them voice
|
||||
// fly-tos made. A search, share link or import that stamps during a flight
|
||||
// leaves it flying; the motion queued behind it then yields to that one.
|
||||
// The voice fly-tos of the latest reply that sent one: whether any moved
|
||||
// the camera, and whether one found nothing. A motion of that reply run
|
||||
// after its fly-to found nothing (Gemini runs a reply's calls one by one)
|
||||
// has no flight to wait on, and must not move the old view instead.
|
||||
let replyFlights = null;
|
||||
let cameraHandoffs = 0;
|
||||
let voiceFlightHandoffs = 0;
|
||||
const otherHandoffs = () => cameraHandoffs - voiceFlightHandoffs;
|
||||
const unsubscribeCameraHandoff =
|
||||
styleManager?.subscribeCameraHandoff?.(() => {
|
||||
cameraHandoffs += 1;
|
||||
}) ?? null;
|
||||
let analystEngine;
|
||||
// Area handles live for this runner (the page): resolve_area, the
|
||||
// analyst's region/area/drawn scopes, find_imagery and osm_query all read
|
||||
@@ -427,13 +452,30 @@ export function createGevActionRunner({
|
||||
const zoomOut = String(args.direction || '').toLowerCase() === 'out';
|
||||
const amt = String(args.amount || 'medium').toLowerCase();
|
||||
const factor = { little: 1.25, medium: 1.6, lot: 2.4 }[amt] || 1.6;
|
||||
if (adjustOrbitRange(zoomOut ? factor : 1 / factor)) {
|
||||
const held = adjustOrbitRange(zoomOut ? factor : 1 / factor);
|
||||
if (held) {
|
||||
const direction = zoomOut ? 'out' : 'in';
|
||||
if (!held.changed) {
|
||||
return {
|
||||
ok: false,
|
||||
action: 'adjust_camera_zoom',
|
||||
direction,
|
||||
amount: amt,
|
||||
error: `Not zoomed: the ${held.kind} is already at its ${zoomOut ? 'farthest' : 'closest'} range.`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
action: 'adjust_camera_zoom',
|
||||
direction: zoomOut ? 'out' : 'in',
|
||||
direction,
|
||||
amount: amt,
|
||||
orbitRadiusAdjusted: true,
|
||||
[held.kind === 'tilt' ? 'tiltRangeAdjusted' : 'orbitRadiusAdjusted']:
|
||||
true,
|
||||
// A tilt to an angle names the angle the new range now ends it at.
|
||||
...(held.pitchDeg !== undefined && {
|
||||
pitchDeg: held.pitchDeg,
|
||||
note: held.note,
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1125,34 +1167,104 @@ export function createGevActionRunner({
|
||||
runOptions,
|
||||
);
|
||||
}
|
||||
return flyToRequestedLocation(viewer, args, {
|
||||
// Chained fly-tos: a grab during an earlier one still flying counts.
|
||||
// The flight replaced is the last one that moved, past lookups that
|
||||
// found nothing.
|
||||
const prior = voiceFlightTarget(voiceFlight);
|
||||
const flight = trackVoiceFlight(
|
||||
prior && !prior.done ? prior.inputCount : undefined,
|
||||
prior,
|
||||
);
|
||||
// Navigation by anything but a voice fly-to since this one began.
|
||||
flight.handoffs = otherHandoffs();
|
||||
voiceFlight = flight;
|
||||
const reply = voiceReplyOf(runOptions);
|
||||
if (reply !== null && replyFlights?.reply !== reply)
|
||||
replyFlights = { reply, moved: false, foundNothing: false };
|
||||
const replyRecord = reply !== null ? replyFlights : null;
|
||||
for (const notify of [...voiceFlightWatchers]) notify();
|
||||
// A motion already running (one the model sent before this fly-to) is
|
||||
// stopped when the flight takes navigation; the result says so.
|
||||
let stoppedMotion = null;
|
||||
const noteStop =
|
||||
(hook) =>
|
||||
(...hookArgs) => {
|
||||
const before = getActiveCameraMotion();
|
||||
const handoffsBefore = cameraHandoffs;
|
||||
try {
|
||||
return hook(...hookArgs);
|
||||
} finally {
|
||||
// A voice fly-to's own stamps are not another navigation, even
|
||||
// for the flight it replaces (a later lookup may find nothing).
|
||||
voiceFlightHandoffs += cameraHandoffs - handoffsBefore;
|
||||
if (
|
||||
before &&
|
||||
!stoppedMotion &&
|
||||
getActiveCameraMotion()?.motionId !== before.motionId
|
||||
)
|
||||
stoppedMotion = before.kind;
|
||||
}
|
||||
};
|
||||
const flown = flyToRequestedLocation(viewer, args, {
|
||||
onFlightEnd: flight.settle,
|
||||
onProgress: reportProgress,
|
||||
placeSearch,
|
||||
searchNavigation,
|
||||
signal: runOptions.signal,
|
||||
runImmediate:
|
||||
typeof styleManager?.runImmediateLocationNavigation === 'function'
|
||||
? (navigate) =>
|
||||
styleManager.runImmediateLocationNavigation(navigate)
|
||||
? noteStop((navigate) =>
|
||||
styleManager.runImmediateLocationNavigation(navigate),
|
||||
)
|
||||
: null,
|
||||
beginDeferred:
|
||||
typeof styleManager?.beginDeferredLocationNavigation === 'function'
|
||||
? () => styleManager.beginDeferredLocationNavigation()
|
||||
? noteStop(() => styleManager.beginDeferredLocationNavigation())
|
||||
: null,
|
||||
reassertDeferred:
|
||||
typeof styleManager?.reassertDeferredLocationNavigation === 'function'
|
||||
? (generation) =>
|
||||
styleManager.reassertDeferredLocationNavigation(generation)
|
||||
? noteStop((generation) =>
|
||||
styleManager.reassertDeferredLocationNavigation(generation),
|
||||
)
|
||||
: null,
|
||||
onStart: () => {
|
||||
onStart: noteStop(() => {
|
||||
if (typeof styleManager?.beginLocationNavigation === 'function') {
|
||||
styleManager.beginLocationNavigation();
|
||||
return;
|
||||
}
|
||||
interruptCameraMotion('nav:fly_to_location');
|
||||
if (viewer.trackedEntity) stopAllTracking(viewer, dataManager);
|
||||
},
|
||||
}),
|
||||
});
|
||||
// No flight started: nothing to wait for. A lookup that was not found,
|
||||
// threw, or was cancelled once a newer voice fly-to had begun (which
|
||||
// takes navigation from it) moved nothing, so a queued motion looks
|
||||
// past it to the flight it replaced. One cancelled while still the
|
||||
// latest voice flight lost navigation to something else (a search, a
|
||||
// share link, Cockpit): the motion then refuses. A flight its own hooks
|
||||
// already settled (cancelled mid-air) keeps its status.
|
||||
const notStarted = () => {
|
||||
if (!flight.done) flight.movedNothing = true;
|
||||
flight.settle('failed');
|
||||
};
|
||||
flown.then((result) => {
|
||||
if (result?.ok === true) return;
|
||||
if (result?.cancelled && voiceFlight === flight)
|
||||
flight.settle('failed');
|
||||
else notStarted();
|
||||
}, notStarted);
|
||||
// After the outcome above, which marks a lookup that moved nothing.
|
||||
const noteReply = (result) => {
|
||||
if (!replyRecord) return;
|
||||
if (result?.ok === true) replyRecord.moved = true;
|
||||
else if (flight.movedNothing) replyRecord.foundNothing = true;
|
||||
};
|
||||
flown.then(noteReply, () => noteReply(null));
|
||||
return flown.then((result) =>
|
||||
stoppedMotion && result && typeof result === 'object'
|
||||
? { ...result, stoppedMotion }
|
||||
: result,
|
||||
);
|
||||
}
|
||||
|
||||
if (name === 'adjust_camera_zoom') {
|
||||
@@ -1254,6 +1366,85 @@ export function createGevActionRunner({
|
||||
}
|
||||
|
||||
if (name === 'move_camera') {
|
||||
const motion = String(args.motion || '').toLowerCase();
|
||||
// A lookup that already found nothing does not hide the last flight
|
||||
// that moved: running now would cancel that flight mid-air.
|
||||
const pending = voiceFlightTarget(voiceFlight);
|
||||
const reply = voiceReplyOf(runOptions);
|
||||
if (
|
||||
VOICE_FLIGHT_WAITING_MOTIONS.has(motion) &&
|
||||
!(pending && !pending.done) &&
|
||||
reply !== null &&
|
||||
replyFlights?.reply === reply &&
|
||||
replyFlights.foundNothing &&
|
||||
!replyFlights.moved
|
||||
)
|
||||
return {
|
||||
ok: false,
|
||||
action: 'move_camera',
|
||||
motion,
|
||||
error: `Not run: the fly-to in this reply found nothing, so the ${motion} was not run at the old view.`,
|
||||
};
|
||||
if (
|
||||
VOICE_FLIGHT_WAITING_MOTIONS.has(motion) &&
|
||||
pending &&
|
||||
!pending.done
|
||||
) {
|
||||
// Bad arguments are refused now, not after waiting on the flight.
|
||||
const argsError = moveCameraArgsError(args);
|
||||
if (argsError) return argsError;
|
||||
const deadline = Date.now() + VOICE_FLIGHT_WAIT_MS;
|
||||
const start = pending;
|
||||
// Act on where the camera lands. Whatever a flight reports, a later
|
||||
// fly-to replaces it, and the wait moves to that one as soon as it
|
||||
// begins (a stalled geocode must not hold the motion past a newer
|
||||
// flight that landed). A geocode that loses navigation reports
|
||||
// failed, and a flight left flying while the next place is looked up
|
||||
// can still land; running there would take navigation and cancel the
|
||||
// newer one. A later lookup that found nothing moved nothing, so the
|
||||
// motion looks past it to the last flight that did move the camera.
|
||||
let flight = start;
|
||||
let status;
|
||||
for (;;) {
|
||||
status = await waitForVoiceFlight(
|
||||
flight,
|
||||
runOptions.signal,
|
||||
deadline,
|
||||
voiceFlightWatchers,
|
||||
);
|
||||
if (status === 'aborted' || status === 'timeout' || !current()) break;
|
||||
const target = voiceFlightTarget(voiceFlight, start);
|
||||
if (!target || (target === flight && status !== 'newer')) break;
|
||||
flight = target;
|
||||
}
|
||||
if (!current())
|
||||
return { ok: false, action: 'move_camera', cancelled: true };
|
||||
if (status !== 'arrived' || flight.movedNothing)
|
||||
return {
|
||||
ok: false,
|
||||
action: 'move_camera',
|
||||
motion,
|
||||
error: `Not run: the flight this ${motion} was waiting for did not arrive.`,
|
||||
};
|
||||
// The flight lands even when the user grabs the globe mid-flight;
|
||||
// the queued motion must not take the camera back from them.
|
||||
if (manualCameraInputCount() !== flight.inputCount)
|
||||
return {
|
||||
ok: false,
|
||||
action: 'move_camera',
|
||||
motion,
|
||||
error: `Not run: the user moved the camera during the flight, so the ${motion} was dropped.`,
|
||||
};
|
||||
// A search, share link or import that took navigation during the
|
||||
// flight leaves it flying; running now would cancel that navigation.
|
||||
if (otherHandoffs() !== flight.handoffs)
|
||||
return {
|
||||
ok: false,
|
||||
action: 'move_camera',
|
||||
motion,
|
||||
error: `Not run: another navigation took the camera during the flight, so the ${motion} was dropped.`,
|
||||
};
|
||||
}
|
||||
return moveCamera(args, (navigate, releaseOptions) =>
|
||||
runManagedVoiceNavigation(
|
||||
styleManager,
|
||||
@@ -1569,6 +1760,7 @@ export function createGevActionRunner({
|
||||
* forget the analyst's "last answer". Area handles stay (page lifetime).
|
||||
*/
|
||||
runVoiceAction.resetConversation = () => {
|
||||
replyFlights = null;
|
||||
conversationAbort.abort();
|
||||
conversationAbort = new AbortController();
|
||||
conversation++;
|
||||
@@ -1582,6 +1774,7 @@ export function createGevActionRunner({
|
||||
if (disposed) return;
|
||||
runVoiceAction.resetConversation();
|
||||
disposed = true;
|
||||
unsubscribeCameraHandoff?.();
|
||||
voiceAreas.dispose();
|
||||
};
|
||||
return runVoiceAction;
|
||||
@@ -2854,6 +3047,116 @@ async function frameOverhead(viewer, dataManager, styleManager, args = {}) {
|
||||
);
|
||||
}
|
||||
|
||||
let voiceFlightCount = 0;
|
||||
|
||||
/**
|
||||
* The model reply a voice call belongs to: Gemini's turn (`reply`), or the
|
||||
* OpenAI response its sibling calls share (`authorityGroup`). Null when the
|
||||
* caller names none.
|
||||
*/
|
||||
function voiceReplyOf(options) {
|
||||
return options?.reply ?? options?.authorityGroup ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A voice flight's end: 'arrived', 'cancelled' or 'failed', settled once.
|
||||
* `replaced` is the last flight that moved when this one began (past lookups
|
||||
* that found nothing), landed or not. It is kept only while this one may turn
|
||||
* out to have moved nothing (a lookup that found no place), so a queued
|
||||
* motion can look past it to that flight and its outcome.
|
||||
*/
|
||||
function trackVoiceFlight(
|
||||
inputCount = manualCameraInputCount(),
|
||||
replaced = null,
|
||||
) {
|
||||
const flight = {
|
||||
done: false,
|
||||
seq: (voiceFlightCount += 1),
|
||||
replaced,
|
||||
movedNothing: false,
|
||||
// Manual input after this means the user took the camera mid-flight.
|
||||
inputCount,
|
||||
status: null,
|
||||
// Waiters to tell when this flight ends.
|
||||
watchers: new Set(),
|
||||
settle: (status) => {
|
||||
if (flight.done) return;
|
||||
flight.done = true;
|
||||
flight.status = status;
|
||||
// Kept only past a lookup that found nothing, and then straight to the
|
||||
// flight that moved, so a run of such lookups holds no chain.
|
||||
flight.replaced = flight.movedNothing
|
||||
? voiceFlightTarget(flight.replaced)
|
||||
: null;
|
||||
for (const notify of [...flight.watchers]) notify(status);
|
||||
flight.watchers.clear();
|
||||
},
|
||||
};
|
||||
return flight;
|
||||
}
|
||||
|
||||
/**
|
||||
* The flight a motion queued since `start` acts on: the latest one that
|
||||
* actually started. A lookup that found nothing moved nothing, so look past
|
||||
* it to the flight it replaced, but never to one older than `start` (a flight
|
||||
* from an earlier reply). Null when every later lookup found nothing. With
|
||||
* no `start`, the latest flight that started, back through lookups that
|
||||
* found nothing.
|
||||
*/
|
||||
function voiceFlightTarget(latest, start = null) {
|
||||
let flight = latest;
|
||||
while (flight?.movedNothing) flight = flight.replaced;
|
||||
return flight && (!start || flight.seq >= start.seq) ? flight : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Longest a motion waits for its flight (geocode plus flight, which is about
|
||||
* 2 s) before giving up. The wait also holds the tool output, and on Gemini
|
||||
* the later tools in the turn.
|
||||
*/
|
||||
const VOICE_FLIGHT_WAIT_MS = 15_000;
|
||||
|
||||
/**
|
||||
* Motions that act on the place the camera ends up at, so one sent beside a
|
||||
* fly-to waits for it. Stop is not one, and rotate_globe turns the
|
||||
* whole Earth from Globe View rather than at a place.
|
||||
*/
|
||||
const VOICE_FLIGHT_WAITING_MOTIONS = new Set([
|
||||
'tilt',
|
||||
'orbit',
|
||||
'pan',
|
||||
'rotate',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Wait for a voice flight to end, or for a newer one to begin ('newer'):
|
||||
* 'timeout' or 'aborted' if neither happens. A flight that has ended answers
|
||||
* at once. Every listener is removed when the wait ends, so a flight that
|
||||
* never settles holds nothing.
|
||||
*/
|
||||
function waitForVoiceFlight(flight, signal, deadline, newerWatchers) {
|
||||
if (signal?.aborted) return Promise.resolve('aborted');
|
||||
if (flight.done) return Promise.resolve(flight.status);
|
||||
return new Promise((resolve) => {
|
||||
const finish = (status) => {
|
||||
clearTimeout(timer);
|
||||
signal?.removeEventListener?.('abort', onAbort);
|
||||
flight.watchers.delete(finish);
|
||||
newerWatchers?.delete(onNewer);
|
||||
resolve(status);
|
||||
};
|
||||
const onAbort = () => finish('aborted');
|
||||
const onNewer = () => finish('newer');
|
||||
const timer = setTimeout(
|
||||
() => finish('timeout'),
|
||||
Math.max(0, deadline - Date.now()),
|
||||
);
|
||||
signal?.addEventListener?.('abort', onAbort, { once: true });
|
||||
flight.watchers.add(finish);
|
||||
newerWatchers?.add(onNewer);
|
||||
});
|
||||
}
|
||||
|
||||
/** Run one validated voice camera mutation through the UI-owned authority seam. */
|
||||
function runManagedVoiceNavigation(
|
||||
styleManager,
|
||||
@@ -3417,6 +3720,7 @@ async function flyToRequestedLocation(
|
||||
runImmediate = null,
|
||||
beginDeferred = null,
|
||||
reassertDeferred = null,
|
||||
onFlightEnd = null,
|
||||
} = {},
|
||||
) {
|
||||
const requestedRangeM = Number(args.rangeM);
|
||||
@@ -3440,12 +3744,19 @@ async function flyToRequestedLocation(
|
||||
settleArrival = resolve;
|
||||
})
|
||||
: null;
|
||||
const arrivalHooks = arrival
|
||||
? {
|
||||
onComplete: () => settleArrival?.('arrived'),
|
||||
onCancel: () => settleArrival?.('cancelled'),
|
||||
}
|
||||
: {};
|
||||
const arrivalHooks =
|
||||
arrival || onFlightEnd
|
||||
? {
|
||||
onComplete: () => {
|
||||
settleArrival?.('arrived');
|
||||
onFlightEnd?.('arrived');
|
||||
},
|
||||
onCancel: () => {
|
||||
settleArrival?.('cancelled');
|
||||
onFlightEnd?.('cancelled');
|
||||
},
|
||||
}
|
||||
: {};
|
||||
const afterArrival = async (result, label) => {
|
||||
if (!arrival || result?.ok !== true) return result;
|
||||
onProgress('fly', label);
|
||||
|
||||
@@ -143,6 +143,14 @@ test('track_entity runner narrates a callsign-less aircraft by its registration'
|
||||
function createVoiceNavigationHarness({ cockpitActive = false } = {}) {
|
||||
const order = [];
|
||||
let generation = 0;
|
||||
// Camera handoffs, published on every navigation stamp as the shell does.
|
||||
const handoffListeners = new Set();
|
||||
const stamp = (noun) => {
|
||||
generation += 1;
|
||||
order.push(`stamp:${noun}`);
|
||||
for (const listener of [...handoffListeners]) listener({ generation });
|
||||
return generation;
|
||||
};
|
||||
const position = Cesium.Cartesian3.fromDegrees(-97.74, 30.26, 500);
|
||||
const viewer = {
|
||||
trackedEntity: { id: 'prior-aircraft' },
|
||||
@@ -179,11 +187,7 @@ function createVoiceNavigationHarness({ cockpitActive = false } = {}) {
|
||||
return runExplicitNavigation({
|
||||
cockpitActive,
|
||||
noun,
|
||||
stamp: () => {
|
||||
generation += 1;
|
||||
order.push(`stamp:${noun}`);
|
||||
return generation;
|
||||
},
|
||||
stamp: () => stamp(noun),
|
||||
release: () => {
|
||||
order.push('release');
|
||||
viewer.trackedEntity = undefined;
|
||||
@@ -195,12 +199,21 @@ function createVoiceNavigationHarness({ cockpitActive = false } = {}) {
|
||||
});
|
||||
},
|
||||
getDetectionState: () => ({ detectionMode: 'DENSE' }),
|
||||
subscribeCameraHandoff(listener) {
|
||||
handoffListeners.add(listener);
|
||||
return () => handoffListeners.delete(listener);
|
||||
},
|
||||
// A voice lookup stamps when it begins and leaves any flight flying.
|
||||
beginDeferredLocationNavigation: () => stamp('location-lookup'),
|
||||
reassertDeferredLocationNavigation: (stamped) => stamped === generation,
|
||||
};
|
||||
return {
|
||||
order,
|
||||
viewer,
|
||||
styleManager,
|
||||
currentGeneration: () => generation,
|
||||
// A location-panel search: a deferred stamp that leaves a flight flying.
|
||||
panelSearch: () => stamp('panel-search'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -276,6 +289,841 @@ test('dependent voice navigation waits for the destination viewport to arrive',
|
||||
assert.equal(result.arrived, true);
|
||||
});
|
||||
|
||||
// "fly to London and tilt the camera" arrives as two sibling calls.
|
||||
// Run at once, the tilt's navigation cancelled the flight; with a geocoded
|
||||
// place, the late flight replaced the tilt.
|
||||
function tiltAfterFlightHarness() {
|
||||
globalThis.window = globalThis.window || { clearTimeout, setTimeout, requestIdleCallback: null };
|
||||
const harness = createVoiceNavigationHarness();
|
||||
const { viewer, styleManager } = harness;
|
||||
const flights = [];
|
||||
viewer.camera.flyTo = (options) => {
|
||||
harness.order.push('fly');
|
||||
flights.push(options);
|
||||
};
|
||||
styleManager.runImmediateLocationNavigation = (navigate) => (
|
||||
styleManager.runImmediateNavigation('location', navigate)
|
||||
);
|
||||
return { ...harness, flights };
|
||||
}
|
||||
|
||||
const settledYet = (promise) => {
|
||||
let settled = false;
|
||||
promise.then(() => { settled = true; });
|
||||
return () => settled;
|
||||
};
|
||||
|
||||
test('a tilt in the same reply as a fly-to waits for the flight to land', async () => {
|
||||
const { viewer, styleManager, order, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
const fly = await runner('fly_to_location', { locationId: 'austin' });
|
||||
assert.equal(fly.ok, true);
|
||||
const tilt = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
const tiltDone = settledYet(tilt);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(tiltDone(), false, 'the tilt must wait while the camera flies');
|
||||
assert.equal(
|
||||
order.slice(order.indexOf('fly')).includes('cancel'),
|
||||
false,
|
||||
'the tilt must not cancel the flight',
|
||||
);
|
||||
flights[0].complete();
|
||||
const result = await tilt;
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.motion, 'tilt');
|
||||
});
|
||||
|
||||
test('a tilt waits through a geocoded fly-to search, then for its flight', async () => {
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
let finishSearch;
|
||||
let landFlight;
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
finishSearch = () => {
|
||||
landFlight = options.onComplete;
|
||||
resolve({ label: query, navigationMode: 'city-overview' });
|
||||
};
|
||||
}),
|
||||
});
|
||||
const fly = runner('fly_to_location', { query: 'Somewhere Far' });
|
||||
const tilt = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
const tiltDone = settledYet(tilt);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(tiltDone(), false, 'the tilt must wait for the place lookup');
|
||||
finishSearch();
|
||||
assert.equal((await fly).ok, true);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(tiltDone(), false, 'the tilt must wait for the flight too');
|
||||
landFlight();
|
||||
assert.equal((await tilt).ok, true);
|
||||
});
|
||||
|
||||
test('a tilt waiting on a flight that never lands is not run', async () => {
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
await runner('fly_to_location', { locationId: 'austin' });
|
||||
const tilt = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
flights[0].cancel();
|
||||
const result = await tilt;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /did not arrive/);
|
||||
});
|
||||
|
||||
test('a tilt beside a fly-to that found nothing is not run', async () => {
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: async () => null,
|
||||
});
|
||||
const fly = runner('fly_to_location', { query: 'Nowhere' });
|
||||
const tilt = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
assert.equal((await fly).ok, false);
|
||||
// Nothing flew: the tilt answers at once and honestly, never at the old view.
|
||||
const result = await tilt;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /did not arrive/);
|
||||
// A later, separate tilt is not held by the failed lookup.
|
||||
assert.equal((await runner('move_camera', { motion: 'tilt', pitchDeg: -45 })).ok, true);
|
||||
});
|
||||
|
||||
test('a tilt with no voice flight pending runs at once', async () => {
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
await runner('fly_to_location', { locationId: 'austin' });
|
||||
flights[0].complete();
|
||||
const result = await runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
assert.equal(result.ok, true);
|
||||
});
|
||||
|
||||
// Orbit, pan and rotate also act at the place the camera ends up, so "fly to
|
||||
// Paris and orbit it" holds the orbit the same way.
|
||||
for (const motion of [
|
||||
{ motion: 'orbit' },
|
||||
{ motion: 'pan', direction: 'left' },
|
||||
{ motion: 'rotate', direction: 'right' },
|
||||
]) {
|
||||
test(`${motion.motion} in the same reply as a fly-to waits for the flight to land`, async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, order, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', motion);
|
||||
const movedDone = settledYet(moved);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), false, `the ${motion.motion} must wait while the camera flies`);
|
||||
assert.equal(
|
||||
order.slice(order.indexOf('fly')).includes('cancel'),
|
||||
false,
|
||||
`the ${motion.motion} must not cancel the flight`,
|
||||
);
|
||||
flights[0].complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.motion, motion.motion);
|
||||
});
|
||||
|
||||
test(`${motion.motion} waits through a geocoded fly-to search, then for its flight`, async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
let finishSearch;
|
||||
let landFlight;
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
finishSearch = () => {
|
||||
landFlight = options.onComplete;
|
||||
resolve({ label: query, navigationMode: 'city-overview' });
|
||||
};
|
||||
}),
|
||||
});
|
||||
const fly = runner('fly_to_location', { query: 'Somewhere Far' });
|
||||
const moved = runner('move_camera', motion);
|
||||
const movedDone = settledYet(moved);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), false, `the ${motion.motion} must wait for the place lookup`);
|
||||
assert.equal(getActiveCameraMotion(), null, 'nothing moves before the flight');
|
||||
finishSearch();
|
||||
assert.equal((await fly).ok, true);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), false, `the ${motion.motion} must wait for the flight too`);
|
||||
landFlight();
|
||||
assert.equal((await moved).ok, true);
|
||||
assert.equal(getActiveCameraMotion()?.kind, motion.motion);
|
||||
});
|
||||
|
||||
test(`${motion.motion} waiting on a flight that never lands is not run`, async () => {
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
await runner('fly_to_location', { locationId: 'austin' });
|
||||
const moved = runner('move_camera', motion);
|
||||
flights[0].cancel();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.motion, motion.motion);
|
||||
assert.match(result.error, new RegExp(`this ${motion.motion} was waiting for did not arrive`));
|
||||
assert.equal(getActiveCameraMotion(), null);
|
||||
});
|
||||
}
|
||||
|
||||
// Cesium lands a flight even when the user grabs the globe mid-flight, so the
|
||||
// motion queued behind it must not then take the camera back.
|
||||
for (const motion of [
|
||||
{ motion: 'orbit' },
|
||||
{ motion: 'tilt', pitchDeg: -45 },
|
||||
]) {
|
||||
test(`${motion.motion} queued behind a fly-to is dropped when the user drags mid-flight`, async () => {
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const canvasListeners = new Map();
|
||||
viewer.scene.canvas.addEventListener = (type, listener) => {
|
||||
canvasListeners.set(type, listener);
|
||||
};
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', motion);
|
||||
canvasListeners.get('pointerdown')();
|
||||
flights[0].complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.motion, motion.motion);
|
||||
assert.match(result.error, /moved the camera during the flight/);
|
||||
assert.equal(getActiveCameraMotion(), null);
|
||||
});
|
||||
}
|
||||
|
||||
test('a drag during the first of two chained fly-tos still drops the queued motion', async () => {
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const canvasListeners = new Map();
|
||||
viewer.scene.canvas.addEventListener = (type, listener) => {
|
||||
canvasListeners.set(type, listener);
|
||||
};
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
canvasListeners.get('touchstart')();
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
flights.at(-1).complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /moved the camera during the flight/);
|
||||
});
|
||||
|
||||
test('input before a fly-to does not drop the motion queued behind it', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const canvasListeners = new Map();
|
||||
viewer.scene.canvas.addEventListener = (type, listener) => {
|
||||
canvasListeners.set(type, listener);
|
||||
};
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
canvasListeners.get('wheel')();
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
flights[0].complete();
|
||||
assert.equal((await moved).ok, true);
|
||||
});
|
||||
|
||||
test('a motion follows a later fly-to in the same reply that cancels its flight', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
const movedDone = settledYet(moved);
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
// The second flight supersedes the first, as Cesium's flyTo does.
|
||||
flights[0].cancel();
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), false, 'the orbit must wait for the second flight');
|
||||
flights[1].complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.motion, 'orbit');
|
||||
});
|
||||
|
||||
test('a motion follows a later fly-to whose start cancels its geocode', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
const flyA = runner('fly_to_location', { query: 'Place A' });
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
const movedDone = settledYet(moved);
|
||||
const flyB = runner('fly_to_location', { query: 'Place B' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
// B takes navigation authority, so A's lookup comes back cancelled.
|
||||
searches[0].resolve({ cancelled: true });
|
||||
assert.equal((await flyA).cancelled, true);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), false, 'the orbit must follow B, not drop');
|
||||
searches[1].resolve({ label: 'Place B', navigationMode: 'city-overview' });
|
||||
assert.equal((await flyB).ok, true);
|
||||
searches[1].options.onComplete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.motion, 'orbit');
|
||||
});
|
||||
|
||||
test('a motion does not run at a flight that lands while the next place is looked up', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, order, flights } = tiltAfterFlightHarness();
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
const movedDone = settledYet(moved);
|
||||
const flyB = runner('fly_to_location', { query: 'Place B' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
// Deferred navigation leaves A flying while B is looked up, and A lands.
|
||||
const before = order.length;
|
||||
flights[0].complete();
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), false, 'the tilt must wait for B');
|
||||
assert.equal(
|
||||
order.slice(before).includes('cancel'),
|
||||
false,
|
||||
'the tilt must not take navigation and cancel B',
|
||||
);
|
||||
searches[0].resolve({ label: 'Place B', navigationMode: 'city-overview' });
|
||||
assert.equal((await flyB).ok, true);
|
||||
searches[0].options.onComplete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.motion, 'tilt');
|
||||
});
|
||||
|
||||
// A later fly-to that finds nothing moves nothing: the motion still runs where
|
||||
// the earlier flight lands, whether the lookup fails before or after that.
|
||||
for (const order of ['lands first', 'not found first']) {
|
||||
test(`a motion runs at its flight when a later fly-to finds nothing (${order})`, async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const harness = tiltAfterFlightHarness();
|
||||
const { viewer, styleManager, flights } = harness;
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
const flyB = runner('fly_to_location', { query: 'Nowhere' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
if (order === 'lands first') flights[0].complete();
|
||||
searches[0].resolve(null);
|
||||
assert.equal((await flyB).ok, false);
|
||||
if (order !== 'lands first') flights[0].complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true, result.error);
|
||||
assert.equal(result.motion, 'tilt');
|
||||
});
|
||||
}
|
||||
|
||||
test('a motion beside a fly-to that finds nothing never acts at an earlier reply\'s flight', async () => {
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
// Reply 1: "fly to Austin", still flying.
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
// Reply 2: "fly to Nowhere and tilt".
|
||||
const flyB = runner('fly_to_location', { query: 'Nowhere' });
|
||||
const moved = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
searches[0].resolve(null);
|
||||
assert.equal((await flyB).ok, false);
|
||||
flights[0].complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /did not arrive/);
|
||||
});
|
||||
|
||||
// Two later lookups that both find nothing, in either order, leave the motion
|
||||
// acting where the first flight landed.
|
||||
for (const first of [0, 1]) {
|
||||
test(`a motion looks past two lookups that found nothing (lookup ${first + 1} fails first)`, async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
const flyB = runner('fly_to_location', { query: 'Nowhere B' });
|
||||
const flyC = runner('fly_to_location', { query: 'Nowhere C' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
searches[first].resolve(null);
|
||||
searches[1 - first].resolve(null);
|
||||
assert.equal((await flyB).ok, false);
|
||||
assert.equal((await flyC).ok, false);
|
||||
flights[0].complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true, result.error);
|
||||
});
|
||||
}
|
||||
|
||||
test('a lookup cancelled by a newer one that finds nothing does not hide the flight that landed', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
const flyB = runner('fly_to_location', { query: 'Place B' });
|
||||
const flyC = runner('fly_to_location', { query: 'Nowhere C' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
flights[0].complete();
|
||||
// C's start takes navigation from B's lookup; C then finds nothing.
|
||||
searches[0].resolve({ cancelled: true });
|
||||
searches[1].resolve(null);
|
||||
assert.equal((await flyB).cancelled, true);
|
||||
assert.equal((await flyC).ok, false);
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true, result.error);
|
||||
});
|
||||
|
||||
test('a motion sent after a fly-to that found nothing still waits for the flight before it', async (t) => {
|
||||
// Serial dispatch: "fly to Austin, fly to Nowhere, tilt", one call at a time.
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, order, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: async () => null,
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
assert.equal((await runner('fly_to_location', { query: 'Nowhere' })).ok, false);
|
||||
const before = order.length;
|
||||
const moved = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
const movedDone = settledYet(moved);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), false, 'the tilt must wait for the Austin flight');
|
||||
assert.equal(order.slice(before).includes('cancel'), false);
|
||||
flights[0].complete();
|
||||
assert.equal((await moved).ok, true);
|
||||
});
|
||||
|
||||
test('two lookups that found nothing in a row still leave the motion waiting for the flight', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, order, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: async () => null,
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
assert.equal((await runner('fly_to_location', { query: 'Nowhere' })).ok, false);
|
||||
assert.equal((await runner('fly_to_location', { query: 'Nowhere 2' })).ok, false);
|
||||
const before = order.length;
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
const movedDone = settledYet(moved);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), false, 'the orbit must wait for the Austin flight');
|
||||
assert.equal(order.slice(before).includes('cancel'), false);
|
||||
flights[0].complete();
|
||||
assert.equal((await moved).ok, true);
|
||||
});
|
||||
|
||||
// A flight that already settled is still what a later failed lookup replaced.
|
||||
test('a motion acts at a landed flight that a later failed lookup replaced', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
const flyA = runner('fly_to_location', { query: 'Slow A' });
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
flights[0].complete();
|
||||
const flyC = runner('fly_to_location', { query: 'Nowhere C' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
// B's start made A's lookup stale; C then finds nothing.
|
||||
searches[0].resolve({ cancelled: true });
|
||||
searches[1].resolve(null);
|
||||
assert.equal((await flyA).cancelled, true);
|
||||
assert.equal((await flyC).ok, false);
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true, result.error);
|
||||
});
|
||||
|
||||
test('a motion refuses when the flight a later failed lookup replaced was cancelled', async () => {
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
const flyA = runner('fly_to_location', { query: 'Slow A' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
// The motion sees Austin land, then follows A's lookup.
|
||||
flights[0].complete();
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
flights[1].cancel();
|
||||
const flyC = runner('fly_to_location', { query: 'Nowhere C' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
searches[0].resolve({ cancelled: true });
|
||||
searches[1].resolve(null);
|
||||
assert.equal((await flyA).cancelled, true);
|
||||
assert.equal((await flyC).ok, false);
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /did not arrive/);
|
||||
});
|
||||
|
||||
test('a stale motion does not follow a newer reply\'s fly-to', async () => {
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
let live = true;
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'orbit' }, { isCurrent: () => live });
|
||||
// A newer reply takes over and flies elsewhere; this reply is stale.
|
||||
live = false;
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
flights[0].cancel();
|
||||
// The newer flight never lands here: following it would hold this answer.
|
||||
const result = await Promise.race([
|
||||
moved,
|
||||
new Promise((resolve) => setTimeout(() => resolve('still waiting'), 50)),
|
||||
]);
|
||||
assert.notEqual(result, 'still waiting');
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.cancelled, true);
|
||||
});
|
||||
|
||||
test('a motion gives up on a flight that has not landed in 15 s', async (t) => {
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
t.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
const movedDone = settledYet(moved);
|
||||
await Promise.resolve();
|
||||
t.mock.timers.tick(14_999);
|
||||
await Promise.resolve();
|
||||
assert.equal(movedDone(), false);
|
||||
t.mock.timers.tick(1);
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /did not arrive/);
|
||||
});
|
||||
|
||||
test('a motion follows a newer fly-to that lands while its own lookup stalls', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
// Place A's lookup never answers.
|
||||
searchNavigation: () => new Promise(() => {}),
|
||||
});
|
||||
t.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
|
||||
runner('fly_to_location', { query: 'Place A' });
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
const movedDone = settledYet(moved);
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
t.mock.timers.tick(2_000);
|
||||
await Promise.resolve();
|
||||
assert.equal(movedDone(), false, 'the orbit must wait for the newer flight to land');
|
||||
flights[0].complete();
|
||||
for (let i = 0; i < 5 && !movedDone(); i += 1) await Promise.resolve();
|
||||
assert.equal(movedDone(), true, 'the orbit must not wait out A');
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.motion, 'orbit');
|
||||
});
|
||||
|
||||
// "Fly to Paris and orbit it", then a location-panel search while the camera
|
||||
// flies: the search stamps a deferred navigation without stopping the flight.
|
||||
// Run where the flight landed, the orbit took navigation and the search's
|
||||
// reassert failed, so the search was silently dropped.
|
||||
// Gemini runs one reply's calls one after another: by the time "pan left"
|
||||
// runs, "fly to Xyzzyville" has already found nothing, so there is no flight
|
||||
// to wait on, and the pan moved the old view with ok: true.
|
||||
test('a motion run after its reply\'s fly-to found nothing is not run', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: async () => null,
|
||||
});
|
||||
const reply = { turn: 1 };
|
||||
const fly = await runner('fly_to_location', { query: 'Xyzzyville' }, { reply });
|
||||
assert.equal(fly.ok, false);
|
||||
const pan = await runner(
|
||||
'move_camera',
|
||||
{ motion: 'pan', direction: 'left' },
|
||||
{ reply },
|
||||
);
|
||||
assert.equal(pan.ok, false);
|
||||
assert.match(pan.error, /Not run: the fly-to in this reply found nothing/);
|
||||
assert.equal(getActiveCameraMotion(), null);
|
||||
// The same holds for OpenAI's reply identity.
|
||||
const group = 'response-1';
|
||||
await runner('fly_to_location', { query: 'Xyzzyville' }, { authorityGroup: group });
|
||||
const tilt = await runner(
|
||||
'move_camera',
|
||||
{ motion: 'tilt', pitchDeg: -45 },
|
||||
{ authorityGroup: group },
|
||||
);
|
||||
assert.equal(tilt.ok, false);
|
||||
assert.match(tilt.error, /found nothing/);
|
||||
});
|
||||
|
||||
test('a motion in a later reply runs after a fly-to that found nothing', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: async () => null,
|
||||
});
|
||||
await runner('fly_to_location', { query: 'Xyzzyville' }, { reply: { turn: 1 } });
|
||||
const pan = await runner(
|
||||
'move_camera',
|
||||
{ motion: 'pan', direction: 'left' },
|
||||
{ reply: { turn: 2 } },
|
||||
);
|
||||
assert.equal(pan.ok, true, pan.error);
|
||||
});
|
||||
|
||||
test('a motion runs at a flight of its reply that landed after another lookup found nothing', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: async () => null,
|
||||
});
|
||||
const reply = { turn: 1 };
|
||||
await runner('fly_to_location', { query: 'Xyzzyville' }, { reply });
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' }, { reply })).ok, true);
|
||||
flights[0].complete();
|
||||
const pan = await runner(
|
||||
'move_camera',
|
||||
{ motion: 'pan', direction: 'left' },
|
||||
{ reply },
|
||||
);
|
||||
assert.equal(pan.ok, true, pan.error);
|
||||
});
|
||||
|
||||
test('a motion queued behind a fly-to yields to a search started during the flight', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights, panelSearch, currentGeneration } =
|
||||
tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
const search = panelSearch();
|
||||
flights[0].complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /Not run: another navigation took the camera/);
|
||||
assert.equal(getActiveCameraMotion(), null);
|
||||
assert.equal(currentGeneration(), search, 'the search still owns navigation');
|
||||
});
|
||||
|
||||
test('a motion behind a geocoded fly-to yields to a search started while it flies', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, panelSearch } = tiltAfterFlightHarness();
|
||||
const searches = [];
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
searchNavigation: (_viewer, query, options) => new Promise((resolve) => {
|
||||
searches.push({ query, options, resolve });
|
||||
}),
|
||||
});
|
||||
const fly = runner('fly_to_location', { query: 'Place A' });
|
||||
const moved = runner('move_camera', { motion: 'orbit' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
searches[0].resolve({ label: 'Place A', navigationMode: 'city-overview' });
|
||||
assert.equal((await fly).ok, true);
|
||||
panelSearch();
|
||||
searches[0].options.onComplete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /another navigation took the camera/);
|
||||
assert.equal(getActiveCameraMotion(), null);
|
||||
});
|
||||
|
||||
test('a search before the fly-to does not drop the motion queued behind it', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager, flights, panelSearch } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
panelSearch();
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'tilt', pitchDeg: -45 });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
flights[0].complete();
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.motion, 'tilt');
|
||||
});
|
||||
|
||||
test('a fly-to that stops a running motion says so', async (t) => {
|
||||
t.after(() => interruptCameraMotion('test-cleanup'));
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
// The model sent the orbit first, so it ran at once.
|
||||
const orbit = await runner('move_camera', { motion: 'orbit', mode: 'continuous' });
|
||||
assert.equal(orbit.ok, true);
|
||||
const fly = await runner('fly_to_location', { locationId: 'austin' });
|
||||
assert.equal(fly.ok, true);
|
||||
assert.equal(fly.stoppedMotion, 'orbit');
|
||||
const again = await runner('fly_to_location', { locationId: 'austin' });
|
||||
assert.equal('stoppedMotion' in again, false);
|
||||
});
|
||||
|
||||
test('bad move_camera arguments are refused without waiting for a flight', async () => {
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
assert.equal((await runner('fly_to_location', { locationId: 'austin' })).ok, true);
|
||||
const moved = runner('move_camera', { motion: 'pan' });
|
||||
const movedDone = settledYet(moved);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
assert.equal(movedDone(), true, 'the refusal must not wait on the flight');
|
||||
const result = await moved;
|
||||
assert.equal(result.ok, false);
|
||||
assert.match(result.error, /needs a direction/);
|
||||
});
|
||||
|
||||
test('stop does not wait for a voice flight', async () => {
|
||||
const { viewer, styleManager } = tiltAfterFlightHarness();
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
});
|
||||
await runner('fly_to_location', { locationId: 'austin' });
|
||||
const result = await runner('move_camera', { motion: 'stop' });
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.motion, 'stop');
|
||||
});
|
||||
|
||||
test('nearest-aircraft voice action serializes layer enable, arrival, refresh, airborne query, and selection', async () => {
|
||||
globalThis.window = globalThis.window || {
|
||||
clearTimeout,
|
||||
|
||||
@@ -453,10 +453,12 @@ const layers = [
|
||||
export const VOICE_OFF_LAYERS = Object.freeze({
|
||||
'bhote-koshi-2026': 'scene-driven event layer (control_scene)',
|
||||
'bhote-koshi-locator': 'scene-driven event layer (control_scene)',
|
||||
// The Realtime prompt is at its 52,000-character budget; voice toggle and
|
||||
// The Realtime prompt is at its 55,500-character budget; voice toggle and
|
||||
// query for this layer wait until there is room.
|
||||
'drone-airspace':
|
||||
'informational airspace layer; no room in the prompt budget',
|
||||
'wildlife-sightings':
|
||||
'community observation layer; no room in the prompt budget',
|
||||
});
|
||||
|
||||
const TYPE_NAMES = Object.freeze({
|
||||
|
||||
@@ -1298,6 +1298,77 @@ test('undocking while a tray is open brings the panel back as its bar', async (t
|
||||
assert.equal($('#gev-chat-panel').dataset.placement, 'compact');
|
||||
});
|
||||
|
||||
test('opening chat or closing the voice panel clears a stale voice error', async (t) => {
|
||||
for (const leave of ['chat', 'close']) {
|
||||
const f = mounted(t, { view: true });
|
||||
await f.commands.session.start();
|
||||
f.commands.voicePanel.select('preview');
|
||||
f.instances[0].hooks.emit({
|
||||
type: 'state',
|
||||
state: 'error',
|
||||
detail: 'Lost',
|
||||
});
|
||||
await f.settle();
|
||||
assert.equal($('#gev-voice-control').dataset.status, 'error');
|
||||
assert.equal(f.commands.session.isActive(), false);
|
||||
if (leave === 'chat') $('#gev-chat-button').click();
|
||||
else $('#gev-voice-settings-close').click();
|
||||
await f.settle();
|
||||
assert.equal(f.commands.session.state, 'idle', leave);
|
||||
assert.notEqual($('#gev-voice-control').dataset.status, 'error', leave);
|
||||
}
|
||||
});
|
||||
|
||||
test('switching AI Provider from chat Settings keeps chat Settings on the new mount', async (t) => {
|
||||
const view = mountVoiceView(t);
|
||||
const host = createVoicePanelHost({ storage: null });
|
||||
const instances = [];
|
||||
const commands = createProviderCommands(
|
||||
{
|
||||
runner: async () => ({}),
|
||||
dataManager: { layers: new Map() },
|
||||
supportedProviders: ['openai', 'gemini'],
|
||||
},
|
||||
{
|
||||
bind: (options) =>
|
||||
bind({
|
||||
...options,
|
||||
panelHost: host,
|
||||
createControl: (control) =>
|
||||
createTestVoiceUi({ ...control, pinia: view.pinia }),
|
||||
}),
|
||||
factories: { openai: factory(instances), gemini: factory(instances) },
|
||||
storage: null,
|
||||
},
|
||||
);
|
||||
t.after(() => {
|
||||
commands.destroy();
|
||||
host.destroy();
|
||||
});
|
||||
await view.settle();
|
||||
$('#gev-chat-button').click();
|
||||
await view.settle();
|
||||
$('#gev-chat-panel').getBoundingClientRect = () => ({
|
||||
width: 320,
|
||||
height: 480,
|
||||
});
|
||||
$('#gev-voice-settings-button').click();
|
||||
await view.settle();
|
||||
const old = commands.ui;
|
||||
assert.equal(old.state.voicePanel.context, 'chat');
|
||||
old.emit('provider-change', 'gemini');
|
||||
await view.settle();
|
||||
const { ui } = commands;
|
||||
assert.notEqual(ui, old);
|
||||
assert.equal(ui.state.voicePanel.context, 'chat');
|
||||
assert.equal(ui.state.voicePanel.frameWidth, 320);
|
||||
assert.equal(ui.state.voicePanel.frameHeight, 480);
|
||||
assert.equal(ui.state.chat.backVisible, true);
|
||||
assert.equal(ui.state.root.assistantMode, 'chat');
|
||||
assert.equal($('#gev-chat-back').hidden, false);
|
||||
assert.equal(active(), 'gev-voice-provider');
|
||||
});
|
||||
|
||||
test('the voice panel close turns voice off', async (t) => {
|
||||
const f = mounted(t, { view: true });
|
||||
await f.commands.session.start();
|
||||
|
||||
@@ -309,7 +309,10 @@ test('markup: the chip sits under the user caption with a screen-reader separato
|
||||
assert.equal(pointer.hidden, true);
|
||||
const separator = pointer.querySelector('.gev-voice-card-sr');
|
||||
assert.equal(separator.textContent, ': ');
|
||||
assert.equal(separator.previousElementSibling.id, 'gev-voice-card-pointer-kind');
|
||||
assert.equal(
|
||||
separator.previousElementSibling.id,
|
||||
'gev-voice-card-pointer-kind',
|
||||
);
|
||||
});
|
||||
|
||||
test('deixis prompt lint: one short rule, and every sentinel it names exists in the schema', () => {
|
||||
@@ -347,15 +350,18 @@ test('deixis prompt lint: one short rule, and every sentinel it names exists in
|
||||
// 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, ~290 under. A new tool or rule has to fit
|
||||
// under this ceiling.
|
||||
// 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.
|
||||
const size = instructions.length + JSON.stringify(GEV_REALTIME_TOOLS).length;
|
||||
assert.ok(size <= 55_500, `prompt size ${size}`);
|
||||
});
|
||||
|
||||
|
||||
test('after-tool speech allows returned items to answer requested lists and rankings', () => {
|
||||
const rule = realtimeInstructions().split('\n').find(line => line.startsWith('AFTER TOOLS:'));
|
||||
const rule = realtimeInstructions()
|
||||
.split('\n')
|
||||
.find((line) => line.startsWith('AFTER TOOLS:'));
|
||||
assert.match(rule, /requested analyst list or ranking/);
|
||||
assert.match(rule, /returned items.*returned values/);
|
||||
assert.match(rule, /keep their order/);
|
||||
|
||||
@@ -64,6 +64,8 @@ export function createProviderCommands(options, { bind, factories, storage }) {
|
||||
const textOnly = Boolean(
|
||||
current.session.adapter.getStartOptions?.().textOnly,
|
||||
);
|
||||
// Settings opened from chat stay chat's Settings.
|
||||
const presentation = current.chatPresentation?.() ?? null;
|
||||
const generation = ++mountGeneration;
|
||||
voiceEnabled = false;
|
||||
current.session.destroy();
|
||||
@@ -80,7 +82,7 @@ export function createProviderCommands(options, { bind, factories, storage }) {
|
||||
} catch {
|
||||
/* Storage is optional. */
|
||||
}
|
||||
mount();
|
||||
mount(presentation);
|
||||
if (resume && !disposed && provider === next)
|
||||
void current.session.start({
|
||||
pushToTalk,
|
||||
@@ -142,7 +144,7 @@ export function createProviderCommands(options, { bind, factories, storage }) {
|
||||
return typeof value === 'function' ? value.bind(current) : value;
|
||||
},
|
||||
});
|
||||
function mount() {
|
||||
function mount(presentation = null) {
|
||||
voiceEnabled = false;
|
||||
const generation = ++mountGeneration;
|
||||
current = bind({
|
||||
@@ -158,6 +160,7 @@ export function createProviderCommands(options, { bind, factories, storage }) {
|
||||
handleSessionEvent(event);
|
||||
},
|
||||
createSession: factories[provider],
|
||||
presentation,
|
||||
});
|
||||
window.__gevVoiceCommands = facade;
|
||||
}
|
||||
|
||||
@@ -856,3 +856,18 @@ for (const action of ['stop', 'destroy']) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test('a provider switch hands chat Settings to the new mount', async (t) => {
|
||||
const f = compositionFixture(t);
|
||||
const first = f.facade.provider;
|
||||
const next = first === 'openai' ? 'gemini' : 'openai';
|
||||
// Without chat open there is nothing to carry.
|
||||
assert.equal(f.mounts[0].controls.chatPresentation(), null);
|
||||
const shown = { view: 'settings', frame: { width: 320, height: 480 } };
|
||||
f.mounts[0].controls.chatPresentation = () => shown;
|
||||
f.select(next);
|
||||
await settle();
|
||||
assert.equal(f.mounts.length, 2);
|
||||
assert.deepEqual(f.mounts[1].options.presentation, shown);
|
||||
assert.equal(f.facade.provider, next);
|
||||
});
|
||||
@@ -185,6 +185,10 @@ export function createVoiceSession({ createAdapter, runner, signal }) {
|
||||
};
|
||||
}
|
||||
|
||||
// Live, or left in error: stopping either returns the session to idle.
|
||||
export const isStoppable = (session) =>
|
||||
session.isActive() || session.state === 'error';
|
||||
|
||||
function abortError() {
|
||||
return new DOMException('Voice action cancelled', 'AbortError');
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { bindAssistantPanelLayout, bindLayoutDock } from './panelLayout.js';
|
||||
import { bindChatControl } from './chatControl.js';
|
||||
import { bindVoiceMiniPreview } from './voiceMiniPreview.js';
|
||||
import { createVoiceControl, voiceStatusLabel } from './control.js';
|
||||
import { createVoiceSession } from './session.js';
|
||||
import { createVoiceSession, isStoppable } from './session.js';
|
||||
import { VoiceCardControls } from './voiceCard.js';
|
||||
import { PointerReticle } from './pointerReticle.js';
|
||||
import { VOICE_PROVIDERS } from './providerCapabilities.js';
|
||||
@@ -40,6 +40,8 @@ export function createVoiceCommands({
|
||||
createReticle = createDefaultReticle,
|
||||
panelHost = null,
|
||||
nativePanelProvider = null,
|
||||
// Chat's Settings, carried across a provider switch.
|
||||
presentation = null,
|
||||
}) {
|
||||
if (resetExisting) window.__gevVoiceCommands?.stop?.({ removeUi: true });
|
||||
const ui = createControl(panelHost ? { panel: true } : {});
|
||||
@@ -225,6 +227,8 @@ export function createVoiceCommands({
|
||||
onOpen: () => panelMount?.panel.close(),
|
||||
})
|
||||
: null;
|
||||
chat?.restorePresentation(presentation);
|
||||
controls.chatPresentation = () => chat?.presentation() ?? null;
|
||||
function minimizeVoicePanel() {
|
||||
const panel = ui.element('voicePanel');
|
||||
const holdsFocus = panel?.contains?.(globalThis.document?.activeElement);
|
||||
@@ -284,7 +288,8 @@ export function createVoiceCommands({
|
||||
// The panel's close turns voice off, as chat's close ends the chat. A typed
|
||||
// session belongs to chat, which handles its own close.
|
||||
const offClose = ui.on('settings-close', () => {
|
||||
if (!session.isActive() || adapter.getStartOptions?.().textOnly) return;
|
||||
// A voice error the user closes is over too; stopping returns to idle.
|
||||
if (!isStoppable(session) || adapter.getStartOptions?.().textOnly) return;
|
||||
const ticket = panelMount?.stopTicket();
|
||||
session.stop();
|
||||
panelMount?.closeAfterStop(ticket);
|
||||
|
||||
Reference in new issue
Block a user