diff --git a/docs/APPLICATION.md b/docs/APPLICATION.md index 10673fd07..301ca53cd 100644 --- a/docs/APPLICATION.md +++ b/docs/APPLICATION.md @@ -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 }`; diff --git a/src/app/tools.js b/src/app/tools.js index 7709a3f85..beccc1c6f 100644 --- a/src/app/tools.js +++ b/src/app/tools.js @@ -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, diff --git a/src/stories/boot.js b/src/stories/boot.js index eb2a533b2..5d0c4957d 100644 --- a/src/stories/boot.js +++ b/src/stories/boot.js @@ -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 diff --git a/src/stories/boot.test.mjs b/src/stories/boot.test.mjs index 0ab000097..ec1a1eb53 100644 --- a/src/stories/boot.test.mjs +++ b/src/stories/boot.test.mjs @@ -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;