From 75b02e142a3904b3d12e79659f8e6f60f1982d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 20 Nov 2026 16:47:07 +0100 Subject: [PATCH 1/5] refactor(contracts): bind only the interactor families an owner implements Each family declares its catalog rows beside its binders, and the adapters take the rows to walk. The TV runtime and Vega pass their own families, so they no longer evaluate keyboard, clipboard, alert, settings, orientation and app-event binders. The unavailable-facts hub states every operation by name instead of calling each family's facts builder, which every owner evaluated whether or not it implements the family. Co-Authored-By: Claude Fable 5.2 --- packages/contracts/package.json | 4 + packages/contracts/src/alert-runtime.ts | 27 +- packages/contracts/src/app-event-runtime.ts | 6 + packages/contracts/src/back-runtime.ts | 6 + packages/contracts/src/clipboard-runtime.ts | 17 +- .../src/interactor-operation-binding.ts | 74 +++++ .../src/interactor-operation-catalog.test.ts | 13 +- .../src/interactor-operation-catalog.ts | 270 ++---------------- packages/contracts/src/keyboard-runtime.ts | 22 +- .../src/local-interactor-operation-set.ts | 13 +- packages/contracts/src/orientation-runtime.ts | 9 +- .../src/platform-runtime-unavailable.ts | 139 +++++---- packages/contracts/src/settings-runtime.ts | 9 +- .../contracts/src/system-button-runtime.ts | 84 +++++- packages/contracts/src/tv-remote-runtime.ts | 8 +- .../platform-apple/src/navigation/runtime.ts | 4 +- packages/platform-apple/src/system/runtime.ts | 4 +- packages/platform-vega/src/runtime.test.ts | 7 + packages/platform-vega/src/runtime.ts | 29 +- .../provider-limrun/src/app-log-runtime.ts | 4 +- .../src/interaction-operations.test.ts | 5 +- .../provider-revyl/src/platform-runtime.ts | 4 +- .../src/platform-runtime.ts | 4 +- packages/tv-cdp/src/runtime.test.ts | 16 ++ packages/tv-cdp/src/runtime.ts | 19 +- src/core/interactors-app-events.test.ts | 4 +- .../provider-device-runtime.fixtures.ts | 4 +- 27 files changed, 466 insertions(+), 339 deletions(-) diff --git a/packages/contracts/package.json b/packages/contracts/package.json index db7fb2abb2..9edd902c43 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -276,6 +276,10 @@ "types": "./src/ios-target-activation.ts", "default": "./src/ios-target-activation.ts" }, + "./interactor-operation-binding": { + "types": "./src/interactor-operation-binding.ts", + "default": "./src/interactor-operation-binding.ts" + }, "./interactor-operation-catalog": { "types": "./src/interactor-operation-catalog.ts", "default": "./src/interactor-operation-catalog.ts" diff --git a/packages/contracts/src/alert-runtime.ts b/packages/contracts/src/alert-runtime.ts index c0e69cc660..a12cbbd1ee 100644 --- a/packages/contracts/src/alert-runtime.ts +++ b/packages/contracts/src/alert-runtime.ts @@ -1,3 +1,4 @@ +import type { InteractorOperationDefinition } from './interactor-operation-binding.ts'; import type { AlertInteractorOptions, Interactor, RunnerContext } from './interactor-types.ts'; import type { RuntimeOperationFact } from './platform-runtime.ts'; import type { SessionSurface } from './session-surface.ts'; @@ -109,7 +110,7 @@ function alertInteractorOptions( type AlertLeg = 'readAlert' | 'awaitAlert' | 'acceptAlert' | 'dismissAlert'; /** How a fail-closed refusal names each leg to the caller, matching the command that asked for it. */ -export const ALERT_LEG_LABELS = { +const ALERT_LEG_LABELS = { readAlert: 'alert get', awaitAlert: 'alert wait', acceptAlert: 'alert accept', @@ -132,3 +133,27 @@ export function bindAlertLeg( }, }) as Readonly Promise>>>; } + +/** The family's rows for the interactor-operation adapters: one fact, one bind call. */ +export const ALERT_INTERACTOR_OPERATIONS = [ + { + operation: 'readAlert', + label: ALERT_LEG_LABELS.readAlert, + bind: (signal, resolve) => bindAlertLeg('readAlert', signal, resolve), + }, + { + operation: 'awaitAlert', + label: ALERT_LEG_LABELS.awaitAlert, + bind: (signal, resolve) => bindAlertLeg('awaitAlert', signal, resolve), + }, + { + operation: 'acceptAlert', + label: ALERT_LEG_LABELS.acceptAlert, + bind: (signal, resolve) => bindAlertLeg('acceptAlert', signal, resolve), + }, + { + operation: 'dismissAlert', + label: ALERT_LEG_LABELS.dismissAlert, + bind: (signal, resolve) => bindAlertLeg('dismissAlert', signal, resolve), + }, +] as const satisfies readonly InteractorOperationDefinition[]; diff --git a/packages/contracts/src/app-event-runtime.ts b/packages/contracts/src/app-event-runtime.ts index 20b4d2a6dd..04f5695585 100644 --- a/packages/contracts/src/app-event-runtime.ts +++ b/packages/contracts/src/app-event-runtime.ts @@ -1,3 +1,4 @@ +import type { InteractorOperationDefinition } from './interactor-operation-binding.ts'; import type { Interactor, RunnerContext } from './interactor-types.ts'; import type { RuntimeOperationFact } from './platform-runtime.ts'; import type { SnapshotRuntimeExecution } from './snapshot-runtime.ts'; @@ -55,3 +56,8 @@ export function bindAppEvent( }, }); } + +/** The family's rows for the interactor-operation adapters: one fact, one bind call. */ +export const APP_EVENT_INTERACTOR_OPERATIONS = [ + { operation: 'triggerAppEvent', label: 'trigger-app-event', bind: bindAppEvent }, +] as const satisfies readonly InteractorOperationDefinition[]; diff --git a/packages/contracts/src/back-runtime.ts b/packages/contracts/src/back-runtime.ts index 04a5a6e472..583ad4e984 100644 --- a/packages/contracts/src/back-runtime.ts +++ b/packages/contracts/src/back-runtime.ts @@ -1,3 +1,4 @@ +import type { InteractorOperationDefinition } from './interactor-operation-binding.ts'; import type { BackMode, Interactor, RunnerContext } from './interactor-types.ts'; import type { RuntimeOperationFact } from './platform-runtime.ts'; import type { SnapshotRuntimeExecution } from './snapshot-runtime.ts'; @@ -52,3 +53,8 @@ export function bindBack( }, }); } + +/** The family's rows for the interactor-operation adapters: one fact, one bind call. */ +export const BACK_INTERACTOR_OPERATIONS = [ + { operation: 'back', label: 'back', bind: bindBack }, +] as const satisfies readonly InteractorOperationDefinition[]; diff --git a/packages/contracts/src/clipboard-runtime.ts b/packages/contracts/src/clipboard-runtime.ts index 2b73e37834..bbd730bdf9 100644 --- a/packages/contracts/src/clipboard-runtime.ts +++ b/packages/contracts/src/clipboard-runtime.ts @@ -1,3 +1,4 @@ +import type { InteractorOperationDefinition } from './interactor-operation-binding.ts'; import type { Interactor, RunnerContext } from './interactor-types.ts'; import type { RuntimeOperationFact, RuntimeOperationUnavailability } from './platform-runtime.ts'; import type { SnapshotRuntimeExecution } from './snapshot-runtime.ts'; @@ -70,7 +71,7 @@ export function clipboardRuntimeOperationFacts( } /** How a fail-closed refusal names each clipboard half to the caller. */ -export const CLIPBOARD_LEG_LABELS = { +const CLIPBOARD_LEG_LABELS = { readClipboard: 'clipboard read', writeClipboard: 'clipboard write', } as const; @@ -131,3 +132,17 @@ export function bindClipboardWrite( }, }); } + +/** The family's rows for the interactor-operation adapters: one fact, one bind call. */ +export const CLIPBOARD_INTERACTOR_OPERATIONS = [ + { + operation: 'readClipboard', + label: CLIPBOARD_LEG_LABELS.readClipboard, + bind: bindClipboardRead, + }, + { + operation: 'writeClipboard', + label: CLIPBOARD_LEG_LABELS.writeClipboard, + bind: bindClipboardWrite, + }, +] as const satisfies readonly InteractorOperationDefinition[]; diff --git a/packages/contracts/src/interactor-operation-binding.ts b/packages/contracts/src/interactor-operation-binding.ts index ebcd26c3ad..1640772628 100644 --- a/packages/contracts/src/interactor-operation-binding.ts +++ b/packages/contracts/src/interactor-operation-binding.ts @@ -61,3 +61,77 @@ export function providerInteractorSource( ); }; } + +/** + * How a family turns one resolved interactor into one of its own typed operations. Every row + * shares this shape, which is what lets one adapter drive all of them: the family owns what the + * operation *does* and declares its rows beside its binders, and the adapters below own only which + * interactor a row reaches and how a refusal reads. + */ +export type InteractorOperationDefinition = Readonly<{ + /** The facts key that admits it, and the operations key it binds. */ + operation: keyof Operations; + /** How a provider fail-closed refusal names this operation to the caller. */ + label: string; + bind: ( + signal: AbortSignal, + resolveInteractor: (runner: RunnerContext) => Promise, + ) => Partial; +}>; + +/** + * `operations` is the rows of every family the owner implements, so an owner evaluates only those + * families. `facts[operation]` alone still decides whether a row binds: `facts` is an owner's full + * `RuntimeFacts.operations` (extra keys are ignored) or a narrower standalone map, and a key it + * never defines is never bindable. + */ +type AdmittedInteractorOperationParams = Readonly<{ + device: DeviceInfo; + signal: AbortSignal; + resolveInteractor: Resolver; + operations: readonly InteractorOperationDefinition[]; + facts: Readonly>>>; +}>; + +/** + * Walks the rows once, binding each operation the facts admitted through whichever interactor + * source the caller's entry point supplies. The source is the only thing that differs between a + * local owner and a provider. + */ +function bindAdmittedInteractorOperations( + params: AdmittedInteractorOperationParams, + source: ( + definition: InteractorOperationDefinition, + ) => (runner: RunnerContext) => Promise, +): Partial { + const bound: Partial = {}; + for (const definition of params.operations) { + if (!params.facts[definition.operation]?.available) continue; + Object.assign(bound, definition.bind(params.signal, source(definition))); + } + return bound; +} + +/** + * Binds whichever local operations the owner's own facts admitted. The owner keeps full + * authority — its facts alone decide what binds — this only removes the once-per-operation + * ternary that read them. + */ +export function bindAdmittedLocalInteractorOperations( + params: AdmittedInteractorOperationParams, +): Partial { + return bindAdmittedInteractorOperations(params, () => localInteractorSource(params)); +} + +/** + * Binds whichever provider operations the owner's own facts admitted, failing closed when the + * exact owner no longer exposes its interactor. Each refusal names the operation the caller asked + * for, which is what the per-operation `label` carries. + */ +export function bindAdmittedProviderInteractorOperations( + params: AdmittedInteractorOperationParams, +): Partial { + return bindAdmittedInteractorOperations(params, (definition) => + providerInteractorSource({ ...params, operation: definition.label }), + ); +} diff --git a/packages/contracts/src/interactor-operation-catalog.test.ts b/packages/contracts/src/interactor-operation-catalog.test.ts index f0f5e530b7..1e5bc2d741 100644 --- a/packages/contracts/src/interactor-operation-catalog.test.ts +++ b/packages/contracts/src/interactor-operation-catalog.test.ts @@ -2,7 +2,8 @@ import { expect, test, vi } from 'vitest'; import { bindAdmittedLocalInteractorOperations, bindAdmittedProviderInteractorOperations, -} from './interactor-operation-catalog.ts'; +} from './interactor-operation-binding.ts'; +import { INTERACTOR_OPERATIONS } from './interactor-operation-catalog.ts'; import type { Interactor } from './interactor-types.ts'; const device = { @@ -18,6 +19,7 @@ const unavailable = { available: false, reason: 'unsupported-device-kind' } as c test('skips an operation the facts refused', () => { const operations = bindAdmittedLocalInteractorOperations({ + operations: INTERACTOR_OPERATIONS, device, signal: new AbortController().signal, resolveInteractor: vi.fn(), @@ -28,8 +30,9 @@ test('skips an operation the facts refused', () => { expect(operations.home).toBeUndefined(); }); -// The facts a caller passes are the ONLY source of truth for what binds — there is no separate, -// caller-maintained operation list that could drift from them. +// Among the rows a caller supplies, its facts are the ONLY source of truth for what binds. An owner +// that supplies fewer families than the catalog pins, in its own runtime test, that its facts +// admit no operation outside them. test('binds every one of the seven navigation operations when every fact admits it', async () => { const back = vi.fn(async () => undefined); const home = vi.fn(async () => undefined); @@ -52,6 +55,7 @@ test('binds every one of the seven navigation operations when every fact admits ); const operations = bindAdmittedLocalInteractorOperations({ + operations: INTERACTOR_OPERATIONS, device, signal: new AbortController().signal, resolveInteractor, @@ -93,6 +97,7 @@ test('binds every one of the seven navigation operations when every fact admits test('treats an operation missing from a partial facts map as unavailable', () => { const operations = bindAdmittedLocalInteractorOperations({ + operations: INTERACTOR_OPERATIONS, device, signal: new AbortController().signal, resolveInteractor: vi.fn(), @@ -108,6 +113,7 @@ test('a provider binding drives its own resolved interactor for every admitted o const resolveInteractor = vi.fn(() => ({ tvRemote }) as unknown as Interactor); const operations = bindAdmittedProviderInteractorOperations({ + operations: INTERACTOR_OPERATIONS, device, signal: new AbortController().signal, resolveInteractor, @@ -123,6 +129,7 @@ test('a provider binding drives its own resolved interactor for every admitted o test('a provider binding fails closed when its exact owner exposes no interactor', async () => { const operations = bindAdmittedProviderInteractorOperations({ + operations: INTERACTOR_OPERATIONS, device, signal: new AbortController().signal, resolveInteractor: () => undefined, diff --git a/packages/contracts/src/interactor-operation-catalog.ts b/packages/contracts/src/interactor-operation-catalog.ts index 4a91eb3a40..5e18b67007 100644 --- a/packages/contracts/src/interactor-operation-catalog.ts +++ b/packages/contracts/src/interactor-operation-catalog.ts @@ -1,247 +1,37 @@ -import type { DeviceInfo } from '@agent-device/kernel/device'; -import { ALERT_LEG_LABELS, bindAlertLeg } from './alert-runtime.ts'; -import { bindAppEvent } from './app-event-runtime.ts'; -import { bindBack } from './back-runtime.ts'; -import { - CLIPBOARD_LEG_LABELS, - bindClipboardRead, - bindClipboardWrite, -} from './clipboard-runtime.ts'; -import { KEYBOARD_ACTION_LABELS, bindKeyboardAction } from './keyboard-runtime.ts'; -import { bindOrientation, bindOrientationUnlock } from './orientation-runtime.ts'; -import { bindReadSetting, bindSetSetting } from './settings-runtime.ts'; -import { TV_REMOTE_LABEL, bindTvRemote } from './tv-remote-runtime.ts'; -import { - localInteractorSource, - providerInteractorSource, - type LocalInteractorOperationResolver, - type ProviderInteractorOperationResolver, -} from './interactor-operation-binding.ts'; -import type { Interactor, RunnerContext } from './interactor-types.ts'; +import { ALERT_INTERACTOR_OPERATIONS } from './alert-runtime.ts'; +import { APP_EVENT_INTERACTOR_OPERATIONS } from './app-event-runtime.ts'; +import { BACK_INTERACTOR_OPERATIONS } from './back-runtime.ts'; +import { CLIPBOARD_INTERACTOR_OPERATIONS } from './clipboard-runtime.ts'; +import type { InteractorOperationDefinition } from './interactor-operation-binding.ts'; +import { KEYBOARD_INTERACTOR_OPERATIONS } from './keyboard-runtime.ts'; +import { ORIENTATION_INTERACTOR_OPERATIONS } from './orientation-runtime.ts'; import type { PlatformRuntimeOperations } from './platform-runtime-operations.ts'; -import type { RuntimeOperationFact } from './platform-runtime.ts'; -import { bindSystemButton, SYSTEM_BUTTON_LABELS } from './system-button-runtime.ts'; - -/** - * How a facet turns one resolved interactor into its own typed operations. Every catalog member - * shares this shape, which is what lets one adapter drive all of them: the facet owns what the - * operation *does*, and this module owns only which interactor it reaches and how a refusal reads. - */ -type InteractorOperationBinder = ( - signal: AbortSignal, - resolveInteractor: (runner: RunnerContext) => Promise, -) => Partial; - -type InteractorOperationDefinition = Readonly<{ - /** The facts key that admits it, and the operations key it binds. */ - operation: keyof PlatformRuntimeOperations; - /** How a provider fail-closed refusal names this operation to the caller. */ - label: string; - bind: InteractorOperationBinder; -}>; +import { SETTINGS_INTERACTOR_OPERATIONS } from './settings-runtime.ts'; +import { SYSTEM_BUTTON_INTERACTOR_OPERATIONS } from './system-button-runtime.ts'; +import { TV_REMOTE_INTERACTOR_OPERATIONS } from './tv-remote-runtime.ts'; /** * Every operation whose whole binding is "one fact, one bind call, no owner mechanics in between" * — the navigation/keyboard leaves and the system-surface leaves that joined them in Wave 6. * - * One row per operation, declared once. It used to take three parallel declarations — a name - * tuple, a local binder map, and a provider binder map — plus a mirrored - * `bindLocal…Interactor`/`bindProvider…Interactor` pair in each facet whose only difference was - * which interactor source to use and which label to name in a refusal. Both of those now live - * here, in the two adapters below, so adding an operation is adding one row. - * - * Not caller-supplied: `facts[operation]` alone decides whether an operation binds, so a row whose - * key the caller's facts never define is simply never available — which is how an owner with a - * narrower, dedicated facts object (Limrun's keyboard-less navigation facts) opts a subset out. - */ -export const INTERACTOR_OPERATIONS = [ - { operation: 'back', label: 'back', bind: bindBack }, - { - operation: 'home', - label: SYSTEM_BUTTON_LABELS.home, - bind: (signal, resolve) => bindSystemButton('home', signal, resolve), - }, - { operation: 'setOrientation', label: 'orientation', bind: bindOrientation }, - { operation: 'unlockOrientation', label: 'orientation auto', bind: bindOrientationUnlock }, - { operation: 'tvRemote', label: TV_REMOTE_LABEL, bind: bindTvRemote }, - { - operation: 'keyboardStatus', - label: KEYBOARD_ACTION_LABELS.keyboardStatus, - bind: (signal, resolve) => bindKeyboardAction('keyboardStatus', signal, resolve), - }, - { - operation: 'keyboardDismiss', - label: KEYBOARD_ACTION_LABELS.keyboardDismiss, - bind: (signal, resolve) => bindKeyboardAction('keyboardDismiss', signal, resolve), - }, - { - operation: 'keyboardEnter', - label: KEYBOARD_ACTION_LABELS.keyboardEnter, - bind: (signal, resolve) => bindKeyboardAction('keyboardEnter', signal, resolve), - }, - { - operation: 'readClipboard', - label: CLIPBOARD_LEG_LABELS.readClipboard, - bind: bindClipboardRead, - }, - { - operation: 'writeClipboard', - label: CLIPBOARD_LEG_LABELS.writeClipboard, - bind: bindClipboardWrite, - }, - { - operation: 'appSwitcher', - label: SYSTEM_BUTTON_LABELS.appSwitcher, - bind: (signal, resolve) => bindSystemButton('appSwitcher', signal, resolve), - }, - { - operation: 'actionButton', - label: SYSTEM_BUTTON_LABELS.actionButton, - bind: (signal, resolve) => bindSystemButton('actionButton', signal, resolve), - }, - { - operation: 'shake', - label: SYSTEM_BUTTON_LABELS.shake, - bind: (signal, resolve) => bindSystemButton('shake', signal, resolve), - }, - { - operation: 'volumeUp', - label: SYSTEM_BUTTON_LABELS.volumeUp, - bind: (signal, resolve) => bindSystemButton('volumeUp', signal, resolve), - }, - { - operation: 'volumeDown', - label: SYSTEM_BUTTON_LABELS.volumeDown, - bind: (signal, resolve) => bindSystemButton('volumeDown', signal, resolve), - }, - { - operation: 'power', - label: SYSTEM_BUTTON_LABELS.power, - bind: (signal, resolve) => bindSystemButton('power', signal, resolve), - }, - { - operation: 'mute', - label: SYSTEM_BUTTON_LABELS.mute, - bind: (signal, resolve) => bindSystemButton('mute', signal, resolve), - }, - { - operation: 'sleep', - label: SYSTEM_BUTTON_LABELS.sleep, - bind: (signal, resolve) => bindSystemButton('sleep', signal, resolve), - }, - { - operation: 'wake', - label: SYSTEM_BUTTON_LABELS.wake, - bind: (signal, resolve) => bindSystemButton('wake', signal, resolve), - }, - { - operation: 'mediaPlayPause', - label: SYSTEM_BUTTON_LABELS.mediaPlayPause, - bind: (signal, resolve) => bindSystemButton('mediaPlayPause', signal, resolve), - }, - { - operation: 'mediaNext', - label: SYSTEM_BUTTON_LABELS.mediaNext, - bind: (signal, resolve) => bindSystemButton('mediaNext', signal, resolve), - }, - { - operation: 'mediaPrevious', - label: SYSTEM_BUTTON_LABELS.mediaPrevious, - bind: (signal, resolve) => bindSystemButton('mediaPrevious', signal, resolve), - }, - { - operation: 'mediaRewind', - label: SYSTEM_BUTTON_LABELS.mediaRewind, - bind: (signal, resolve) => bindSystemButton('mediaRewind', signal, resolve), - }, - { - operation: 'mediaFastForward', - label: SYSTEM_BUTTON_LABELS.mediaFastForward, - bind: (signal, resolve) => bindSystemButton('mediaFastForward', signal, resolve), - }, - { operation: 'triggerAppEvent', label: 'trigger-app-event', bind: bindAppEvent }, - { operation: 'setSetting', label: 'settings', bind: bindSetSetting }, - { operation: 'readSetting', label: 'settings read', bind: bindReadSetting }, - { - operation: 'readAlert', - label: ALERT_LEG_LABELS.readAlert, - bind: (signal, resolve) => bindAlertLeg('readAlert', signal, resolve), - }, - { - operation: 'awaitAlert', - label: ALERT_LEG_LABELS.awaitAlert, - bind: (signal, resolve) => bindAlertLeg('awaitAlert', signal, resolve), - }, - { - operation: 'acceptAlert', - label: ALERT_LEG_LABELS.acceptAlert, - bind: (signal, resolve) => bindAlertLeg('acceptAlert', signal, resolve), - }, - { - operation: 'dismissAlert', - label: ALERT_LEG_LABELS.dismissAlert, - bind: (signal, resolve) => bindAlertLeg('dismissAlert', signal, resolve), - }, -] as const satisfies readonly InteractorOperationDefinition[]; - -export type CatalogInteractorOperation = (typeof INTERACTOR_OPERATIONS)[number]['operation']; - -/** - * The operation-facts slice every caller already holds: an owner's full `RuntimeFacts.operations` - * (narrows structurally — extra keys are ignored), or, for an owner whose navigation facts are - * assembled standalone (see `platform-apple/src/navigation/runtime.ts`), that flat map directly — which may cover only the subset of - * operations the owner admits at all, so a missing key here is simply never bindable. - */ -type CatalogOperationFacts = Readonly< - Partial> ->; - -type CatalogBindParams = Readonly<{ - device: DeviceInfo; - signal: AbortSignal; - resolveInteractor: Resolver; - facts: CatalogOperationFacts; -}>; - -/** - * Walks the catalog once, binding each operation the facts admitted through whichever interactor - * source the caller's entry point supplies. The source is the only thing that differs between a - * local owner and a provider. - */ -function bindAdmittedInteractorOperations( - params: CatalogBindParams, - source: ( - definition: InteractorOperationDefinition, - ) => (runner: RunnerContext) => Promise, -): Partial { - const bound: Partial = {}; - for (const definition of INTERACTOR_OPERATIONS) { - if (!params.facts[definition.operation]?.available) continue; - Object.assign(bound, definition.bind(params.signal, source(definition))); - } - return bound; -} - -/** - * Binds whichever local operations the owner's own facts admitted. The owner keeps full - * authority — its facts alone decide what binds — this only removes the once-per-operation - * ternary that read them. - */ -export function bindAdmittedLocalInteractorOperations( - params: CatalogBindParams, -): Partial { - return bindAdmittedInteractorOperations(params, () => localInteractorSource(params)); -} - -/** - * Binds whichever provider operations the owner's own facts admitted, failing closed when the - * exact owner no longer exposes its interactor. Each refusal names the operation the caller asked - * for, which is what the per-operation `label` carries. + * Each family declares its own rows beside its binders, and this is all of them, for an owner that + * implements every family. An owner that implements a few passes those families' rows to the + * adapters in `interactor-operation-binding.ts` instead, and so never evaluates the rest. */ -export function bindAdmittedProviderInteractorOperations( - params: CatalogBindParams, -): Partial { - return bindAdmittedInteractorOperations(params, (definition) => - providerInteractorSource({ ...params, operation: definition.label }), - ); -} +const ALL_FAMILY_OPERATIONS = [ + ...BACK_INTERACTOR_OPERATIONS, + ...SYSTEM_BUTTON_INTERACTOR_OPERATIONS, + ...ORIENTATION_INTERACTOR_OPERATIONS, + ...TV_REMOTE_INTERACTOR_OPERATIONS, + ...KEYBOARD_INTERACTOR_OPERATIONS, + ...CLIPBOARD_INTERACTOR_OPERATIONS, + ...APP_EVENT_INTERACTOR_OPERATIONS, + ...SETTINGS_INTERACTOR_OPERATIONS, + ...ALERT_INTERACTOR_OPERATIONS, +] as const satisfies readonly InteractorOperationDefinition[]; + +export type CatalogInteractorOperation = (typeof ALL_FAMILY_OPERATIONS)[number]['operation']; + +export const INTERACTOR_OPERATIONS: readonly InteractorOperationDefinition< + Pick +>[] = ALL_FAMILY_OPERATIONS; diff --git a/packages/contracts/src/keyboard-runtime.ts b/packages/contracts/src/keyboard-runtime.ts index 51f82375d4..075355b9b7 100644 --- a/packages/contracts/src/keyboard-runtime.ts +++ b/packages/contracts/src/keyboard-runtime.ts @@ -1,3 +1,4 @@ +import type { InteractorOperationDefinition } from './interactor-operation-binding.ts'; import type { Interactor, KeyboardDismissResult, @@ -92,7 +93,7 @@ async function resolveKeyboardInteractor( }); } -export const KEYBOARD_ACTION_LABELS = { +const KEYBOARD_ACTION_LABELS = { keyboardStatus: 'keyboard status', keyboardDismiss: 'keyboard dismiss', keyboardEnter: 'keyboard enter', @@ -119,3 +120,22 @@ export function bindKeyboardAction( }; return Object.freeze({ [key]: action }) as Pick; } + +/** The family's rows for the interactor-operation adapters: one fact, one bind call. */ +export const KEYBOARD_INTERACTOR_OPERATIONS = [ + { + operation: 'keyboardStatus', + label: KEYBOARD_ACTION_LABELS.keyboardStatus, + bind: (signal, resolve) => bindKeyboardAction('keyboardStatus', signal, resolve), + }, + { + operation: 'keyboardDismiss', + label: KEYBOARD_ACTION_LABELS.keyboardDismiss, + bind: (signal, resolve) => bindKeyboardAction('keyboardDismiss', signal, resolve), + }, + { + operation: 'keyboardEnter', + label: KEYBOARD_ACTION_LABELS.keyboardEnter, + bind: (signal, resolve) => bindKeyboardAction('keyboardEnter', signal, resolve), + }, +] as const satisfies readonly InteractorOperationDefinition[]; diff --git a/packages/contracts/src/local-interactor-operation-set.ts b/packages/contracts/src/local-interactor-operation-set.ts index e90552079f..65c2cbeb67 100644 --- a/packages/contracts/src/local-interactor-operation-set.ts +++ b/packages/contracts/src/local-interactor-operation-set.ts @@ -2,8 +2,11 @@ import type { DeviceInfo } from '@agent-device/kernel/device'; import { bindElementTextRuntime } from './element-text-runtime.ts'; import { bindLocalFocusInteractor } from './focus-runtime.ts'; import { bindLocalGestureInteractor } from './gesture-runtime.ts'; -import { bindAdmittedLocalInteractorOperations } from './interactor-operation-catalog.ts'; -import type { LocalInteractorOperationResolver } from './interactor-operation-binding.ts'; +import { + bindAdmittedLocalInteractorOperations, + type LocalInteractorOperationResolver, +} from './interactor-operation-binding.ts'; +import { INTERACTOR_OPERATIONS } from './interactor-operation-catalog.ts'; import type { PlatformRuntimeOperations } from './platform-runtime-operations.ts'; import { whenAdmitted, type RuntimeFacts } from './platform-runtime.ts'; import { bindLocalScreenshotInteractor } from './screenshot-runtime.ts'; @@ -48,6 +51,10 @@ export function bindLocalInteractorOperationSet( ...(facts.typeText.available ? bindLocalTypeTextInteractor(resolver) : {}), ...(facts.readTextAtPoint.available ? bindElementTextRuntime(resolver) : {}), ...whenAdmitted(facts.tapPoint, () => bindLocalTouchInteractor({ ...resolver, facts, pause })), - ...bindAdmittedLocalInteractorOperations({ ...resolver, facts }), + ...bindAdmittedLocalInteractorOperations({ + ...resolver, + operations: INTERACTOR_OPERATIONS, + facts, + }), }; } diff --git a/packages/contracts/src/orientation-runtime.ts b/packages/contracts/src/orientation-runtime.ts index 09d74680fb..d5d3ec72ab 100644 --- a/packages/contracts/src/orientation-runtime.ts +++ b/packages/contracts/src/orientation-runtime.ts @@ -1,4 +1,5 @@ import type { DeviceRotation } from './device-rotation.ts'; +import type { InteractorOperationDefinition } from './interactor-operation-binding.ts'; import type { Interactor, RunnerContext } from './interactor-types.ts'; import type { RuntimeOperationFact } from './platform-runtime.ts'; import type { SnapshotRuntimeExecution } from './snapshot-runtime.ts'; @@ -68,7 +69,7 @@ export function bindOrientation( }); } -export function bindOrientationUnlock( +function bindOrientationUnlock( signal: AbortSignal, resolveInteractor: (runner: RunnerContext) => Promise, ): Pick { @@ -87,3 +88,9 @@ export function bindOrientationUnlock( }, }); } + +/** The family's rows for the interactor-operation adapters: one fact, one bind call. */ +export const ORIENTATION_INTERACTOR_OPERATIONS = [ + { operation: 'setOrientation', label: 'orientation', bind: bindOrientation }, + { operation: 'unlockOrientation', label: 'orientation auto', bind: bindOrientationUnlock }, +] as const satisfies readonly InteractorOperationDefinition[]; diff --git a/packages/contracts/src/platform-runtime-unavailable.ts b/packages/contracts/src/platform-runtime-unavailable.ts index ea88a270b4..1e2a149979 100644 --- a/packages/contracts/src/platform-runtime-unavailable.ts +++ b/packages/contracts/src/platform-runtime-unavailable.ts @@ -11,26 +11,6 @@ import type { RuntimeOwnerRef, RuntimeProviderMode, } from './platform-runtime.ts'; -import { screenshotRuntimeOperationFacts } from './screenshot-runtime.ts'; -import { snapshotRuntimeOperationFacts } from './snapshot-runtime.ts'; -import { selectorObservationRuntimeOperationFacts } from './selector-observation-runtime.ts'; -import { viewportRuntimeOperationFacts } from './viewport-runtime.ts'; -import { focusRuntimeOperationFacts } from './focus-runtime.ts'; -import { gestureRuntimeOperationFacts } from './gesture-runtime.ts'; -import { scrollRuntimeOperationFacts } from './scroll-runtime.ts'; -import { typeTextRuntimeOperationFacts } from './type-text-runtime.ts'; -import { elementTextRuntimeOperationFacts } from './element-text-runtime.ts'; -import { backRuntimeOperationFacts } from './back-runtime.ts'; -import { orientationRuntimeOperationFacts } from './orientation-runtime.ts'; -import { tvRemoteRuntimeOperationFacts } from './tv-remote-runtime.ts'; -import { keyboardRuntimeOperationFacts } from './keyboard-runtime.ts'; -import { clipboardRuntimeOperationFacts } from './clipboard-runtime.ts'; -import { systemButtonRuntimeOperationFacts } from './system-button-runtime.ts'; -import { appEventRuntimeOperationFacts } from './app-event-runtime.ts'; -import { alertRuntimeOperationFacts } from './alert-runtime.ts'; -import { audioProbeRuntimeOperationFacts } from './audio-probe-runtime.ts'; -import { perfRuntimeOperationFacts } from './perf-runtime.ts'; -import { touchRuntimeOperationFacts } from './touch-runtime.ts'; /** * A runtime-contract helper for provider ownership gaps. It never assigns lifecycle semantics: @@ -38,6 +18,10 @@ import { touchRuntimeOperationFacts } from './touch-runtime.ts'; * * A family is one cell where all of its operations share one reason, and one cell per operation * only where the reasons genuinely differ per operation. + * + * Every operation is stated here by name, never through its family's facts builder: each owner + * builds on this value, so a family this module evaluated would be one every owner evaluates, + * whether or not it implements that family. `RuntimeFacts` refuses a value that omits an operation. */ export type UnavailablePlatformRuntimeFacts = Readonly<{ appLog: RuntimeOperationUnavailability; @@ -210,65 +194,78 @@ export function createUnavailablePlatformRuntimeFacts( screenRecordingStart: frozen.screenRecording, screenRecordingReattach: frozen.screenRecording, screenRecordingCleanup: frozen.screenRecording, - ...screenshotRuntimeOperationFacts({ capture: frozen.screenshot }), - ...snapshotRuntimeOperationFacts({ - capture: frozen.snapshot, - customActions: frozen.snapshot, - withoutActiveApp: frozen.snapshot, - }), + captureScreenshot: frozen.screenshot, + captureSnapshot: frozen.snapshot, + captureSnapshotWithCustomActions: frozen.snapshot, + captureSnapshotWithoutActiveApp: frozen.snapshot, // The preferred text reading starts unavailable for every family, on the same sentinel as // capture: an owner that has a native reading declares it explicitly, and one that does not // sends every text wait to the canonical tree. The live selector read starts unavailable for // the same reason: an owner without it refuses on its bulk-tree verdict unchanged. - ...selectorObservationRuntimeOperationFacts({ - findText: frozen.snapshot, - querySelector: frozen.snapshot, - }), - ...viewportRuntimeOperationFacts({ setViewport: frozen.viewport }), - ...focusRuntimeOperationFacts({ focus: frozen.focus }), - ...gestureRuntimeOperationFacts({ unsupported: frozen.gesture }), - ...scrollRuntimeOperationFacts({ scroll: frozen.scroll }), - ...typeTextRuntimeOperationFacts({ type: frozen.typeText }), - ...touchRuntimeOperationFacts({ - unsupported: frozen.touch, - tap: frozen.touch, - longPress: frozen.touch, - fill: frozen.touch, - }), - ...elementTextRuntimeOperationFacts({ readTextAtPoint: frozen.elementText }), - ...backRuntimeOperationFacts({ back: frozen.back }), - ...orientationRuntimeOperationFacts({ - orientation: frozen.orientation, - unlock: frozen.orientation, - }), - // Stated directly rather than through `foldRuntimeOperationFacts`, so this hub does not - // evaluate the fold contract for owners that never pose a hinge (eager-closure budgets). + findText: frozen.snapshot, + querySelector: frozen.snapshot, + setViewport: frozen.viewport, + focusPoint: frozen.focus, + performGesturePlan: frozen.gesture, + performDirectionalFlingPlan: frozen.gesture, + performMultiTouchGesturePlan: frozen.gesture, + performTargetAuthoredDrag: frozen.gesture, + gestureViewport: frozen.gesture, + scrollDirection: frozen.scroll, + typeText: frozen.typeText, + tapPoint: frozen.touch, + tapRef: frozen.touch, + longPressPoint: frozen.touch, + hoverPoint: frozen.touch, + hoverRef: frozen.touch, + fillPoint: frozen.touch, + fillRef: frozen.touch, + tapElementSelector: frozen.touch, + readTextAtPoint: frozen.elementText, + back: frozen.back, + setOrientation: frozen.orientation, + unlockOrientation: frozen.orientation, setFoldPose: frozen.fold, sendTelephonyEvent: frozen.telephony, - ...tvRemoteRuntimeOperationFacts({ tvRemote: frozen.tvRemote }), - ...keyboardRuntimeOperationFacts({ unsupported: frozen.keyboard }), - ...clipboardRuntimeOperationFacts({ unsupported: frozen.clipboard }), - ...systemButtonRuntimeOperationFacts({ unsupported: frozen.systemButton }), - ...appEventRuntimeOperationFacts({ triggerAppEvent: frozen.triggerAppEvent }), + tvRemote: frozen.tvRemote, + keyboardStatus: frozen.keyboard, + keyboardDismiss: frozen.keyboard, + keyboardEnter: frozen.keyboard, + readClipboard: frozen.clipboard, + writeClipboard: frozen.clipboard, + home: frozen.systemButton, + appSwitcher: frozen.systemButton, + actionButton: frozen.systemButton, + shake: frozen.systemButton, + volumeUp: frozen.systemButton, + volumeDown: frozen.systemButton, + power: frozen.systemButton, + mute: frozen.systemButton, + sleep: frozen.systemButton, + wake: frozen.systemButton, + mediaPlayPause: frozen.systemButton, + mediaNext: frozen.systemButton, + mediaPrevious: frozen.systemButton, + mediaRewind: frozen.systemButton, + mediaFastForward: frozen.systemButton, + triggerAppEvent: frozen.triggerAppEvent, setSetting: frozen.settings, readSetting: frozen.settings, - ...alertRuntimeOperationFacts({ - read: frozen.readAlert, - wait: frozen.awaitAlert, - accept: frozen.acceptAlert, - dismiss: frozen.dismissAlert, - }), - ...audioProbeRuntimeOperationFacts({ - capture: frozen.audioProbeCapture, - query: frozen.audioProbeQuery, - }), - ...perfRuntimeOperationFacts({ - frames: frozen.perf, - memorySample: frozen.perf, - memorySnapshot: frozen.perf, - nativeCapture: frozen.perf, - profileReport: frozen.perf, - }), + readAlert: frozen.readAlert, + awaitAlert: frozen.awaitAlert, + acceptAlert: frozen.acceptAlert, + dismissAlert: frozen.dismissAlert, + audioProbeStart: frozen.audioProbeCapture, + audioProbeReattach: frozen.audioProbeCapture, + audioProbeCleanup: frozen.audioProbeCapture, + audioProbeQuery: frozen.audioProbeQuery, + perfFrames: frozen.perf, + perfMemorySample: frozen.perf, + perfMemorySnapshot: frozen.perf, + perfNativeCaptureStart: frozen.perf, + perfNativeCaptureReattach: frozen.perf, + perfNativeCaptureCleanup: frozen.perf, + perfProfileReport: frozen.perf, ensureReady: frozen.readiness, bootTarget: frozen.readiness, bootTargetHeadless: frozen.readiness, diff --git a/packages/contracts/src/settings-runtime.ts b/packages/contracts/src/settings-runtime.ts index 6dd1103ff7..eed581b2b6 100644 --- a/packages/contracts/src/settings-runtime.ts +++ b/packages/contracts/src/settings-runtime.ts @@ -1,3 +1,4 @@ +import type { InteractorOperationDefinition } from './interactor-operation-binding.ts'; import type { Interactor, RunnerContext } from './interactor-types.ts'; import type { RuntimeOperationFact, RuntimeOperationUnavailability } from './platform-runtime.ts'; import type { ReadSettingResult, SettingOptions } from './settings.ts'; @@ -125,7 +126,7 @@ export function bindSetSetting( * fact is refused at admission rather than resolving an absent method into an empty answer — the * same guard every optional-member binder takes. */ -export function bindReadSetting( +function bindReadSetting( signal: AbortSignal, resolveInteractor: (runner: RunnerContext) => Promise, ): Pick { @@ -140,3 +141,9 @@ export function bindReadSetting( }, }); } + +/** The family's rows for the interactor-operation adapters: one fact, one bind call. */ +export const SETTINGS_INTERACTOR_OPERATIONS = [ + { operation: 'setSetting', label: 'settings', bind: bindSetSetting }, + { operation: 'readSetting', label: 'settings read', bind: bindReadSetting }, +] as const satisfies readonly InteractorOperationDefinition[]; diff --git a/packages/contracts/src/system-button-runtime.ts b/packages/contracts/src/system-button-runtime.ts index 3a53ea3075..985e371040 100644 --- a/packages/contracts/src/system-button-runtime.ts +++ b/packages/contracts/src/system-button-runtime.ts @@ -1,5 +1,8 @@ import type { HARDWARE_BUTTON_NAME_LABELS, HardwareButton } from './device-rotation.ts'; -import { requireInteractorMethod } from './interactor-operation-binding.ts'; +import { + requireInteractorMethod, + type InteractorOperationDefinition, +} from './interactor-operation-binding.ts'; import type { Interactor, RunnerContext } from './interactor-types.ts'; import type { RuntimeOperationFact, RuntimeOperationUnavailability } from './platform-runtime.ts'; import type { SnapshotRuntimeExecution } from './snapshot-runtime.ts'; @@ -210,3 +213,82 @@ export function bindSystemButton