Merge pull request #1776 from bilawalsidhu/stories/open-stories-option

Voice: an app can supply what open_stories does
This commit is contained in:
Sameh Khamis authored and GitHub committed 2026-11-16 16:54:12 -08:00
commit 65480f2604
4 files changed
+76 -9

No files matched your search

+4 -1
View File
@@ -284,7 +284,10 @@ rejects delayed responses; a new start requests a fresh secret. Secret expiry
limits connection creation and does not describe the connected session lifetime.
`createStandaloneApplication({ voice })` passes these construction options to
the controls. An incompatible protocol needs a separate controller adapter;
the controls. An app can supply `voice.openStories({ isCurrent })` for what the
`open_stories` action does, spoken or typed; it answers true when it opened,
`'already-open'`, or false. Without it the action opens the Stories page.
An incompatible protocol needs a separate controller adapter;
changing an endpoint alone does not translate protocol messages. No alternate
model is bundled by this extraction. The Node Realtime provider accepts
`realtime: { endpoint, models: { standard, mini }, resolveApiKey, fetchImpl }`;
+11 -7
View File
@@ -1,5 +1,9 @@
import { onFollowChanged } from '../data/followed.js';
import { bootStories, stopVoiceForStories } from '../stories/boot.js';
import {
bootStories,
stopVoiceForStories,
storiesOpener,
} from '../stories/boot.js';
import { t } from '../i18n/index.js';
import { useStoriesStore } from '../ui/stores/stories.js';
import { SceneDirector } from '../scenes/director.js';
@@ -309,12 +313,12 @@ export function createApplicationTools({
voiceCommands = initGevVoiceCommands({
...voice,
canStartVoice: () => !isStoriesOpen(),
openStories: storiesStore.available
? ({ isCurrent }) =>
storiesStore.mode === 'closed'
? stories.open({ isCurrent })
: 'already-open'
: null,
// An app may supply what open_stories does; the Stories page by default.
openStories: storiesOpener({
openStories: voice?.openStories,
store: storiesStore,
stories,
}),
floorServices: operations.surface.groundFloor,
annotationResolver: operations.annotationResolver,
searchNavigation: operations.searchAndFlyTo,
+17
View File
@@ -12,6 +12,23 @@ export function stopVoiceForStories(session) {
return wasActive;
}
/**
* What the `open_stories` action does, spoken or typed: the app's own
* `openStories` when it supplies one, else open the Stories page (none
* where Stories is not offered). It is called with `{ isCurrent }` and
* answers true when it opened, 'already-open', or false.
* @param {{openStories?: Function|null,
* store: {available: boolean, mode: string},
* stories: {open: (options: {isCurrent: () => boolean}) => unknown}}} options
* @returns {Function|null}
*/
export function storiesOpener({ openStories, store, stories }) {
if (typeof openStories === 'function') return openStories;
if (!store.available) return null;
return ({ isCurrent }) =>
store.mode === 'closed' ? stories.open({ isCurrent }) : 'already-open';
}
/**
* Stories, loaded on first use. The controller, the story catalog, the
* screens and their styles are separate chunks, fetched when the person
+44 -1
View File
@@ -34,7 +34,8 @@ globalThis.HTMLCanvasElement.prototype.getContext = (kind) =>
globalThis.requestAnimationFrame = () => 0;
globalThis.cancelAnimationFrame = () => {};
const { bootStories, stopVoiceForStories } = await import('./boot.js');
const { bootStories, stopVoiceForStories, storiesOpener } =
await import('./boot.js');
const { useStoriesStore } = await import('../ui/stores/stories.js');
const { bindRenderer } = await import('../render/rendererOf.js');
@@ -76,6 +77,48 @@ const director = {
styleManager: { runImmediateNavigation: () => true },
};
test('open_stories runs the app’s own openStories when it supplies one', async () => {
const calls = [];
const opened = [];
const own = async (options) => {
calls.push(options);
return true;
};
const open = storiesOpener({
openStories: own,
store: { available: true, mode: 'closed' },
stories: { open: (options) => opened.push(options) },
});
assert.equal(open, own);
const isCurrent = () => true;
assert.equal(await open({ isCurrent }), true);
assert.deepEqual(calls, [{ isCurrent }]);
assert.deepEqual(opened, [], 'the Stories page is not opened');
});
test('open_stories opens the Stories page by default', () => {
const opened = [];
const store = { available: true, mode: 'closed' };
const stories = {
open: (options) => {
opened.push(options);
return true;
},
};
const open = storiesOpener({ store, stories });
const isCurrent = () => true;
assert.equal(open({ isCurrent }), true);
assert.deepEqual(opened, [{ isCurrent }]);
store.mode = 'explore';
assert.equal(open({ isCurrent }), 'already-open');
assert.equal(opened.length, 1);
// Where Stories is not offered, there is nothing to open.
assert.equal(
storiesOpener({ store: { available: false, mode: 'closed' }, stories }),
null,
);
});
test('entering Stories stops microphone sessions and preserves typed chat', () => {
let textOnly = false;
let active = true;