routeInteraction method
Route a user interaction captured on a rendered tree back to the agent
(FR-004). If the action is confirm-tier, it is intercepted by the
PolicyGate (FR-006) and only delivered after approval.
Returns the action that was actually delivered (or null if denied).
Implementation
Future<SemanticAction?> routeInteraction(SemanticAction action) async {
// Stamp the action with the view id so the agent knows which view to
// update. Fall back to the active (most-recently-rendered active) view
// rather than the chronologically-last-rendered one, which would
// mis-attribute an interaction to a different, still-live view in a
// multi-view mission.
final stamped = action.viewId == null
? action.copyWith(viewId: activeView?.viewId)
: action;
// Gate confirm-tier actions (FR-006).
final approved = await policyGate.intercept(stamped);
if (approved == null) {
// Denied — emit a policy event and drop the action (FR-006 acceptance 2).
channel.emitPolicy(stamped, approved: false);
return null;
}
channel.emitPolicy(approved, approved: true);
channel.emitInteraction(approved);
actionRouter.deliver(approved);
return approved;
}