feat(messenger): add getRegisteredActionTypes accessor#9271
Open
sirtimid wants to merge 1 commit into
Open
Conversation
ad9e23f to
41944f4
Compare
Add a public, read-only `getRegisteredActionTypes()` method to the `Messenger` class that returns every action type the messenger can call directly — actions registered on it plus actions delegated into it. This gives consumers a way to discover a messenger's callable action surface (needed by an upcoming `mm daemon list` command in `@metamask/wallet-cli`). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
41944f4 to
c14f260
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Adds a public, read-only accessor
Messenger.getRegisteredActionTypes()that returns the action types a messenger cancall()directly — actions registered on it plus actions delegated into it from a child messenger. It returns[...this.#actions.keys()].There is no public way to enumerate a messenger's callable actions today.
Why
string[]and notAction['type'][]The first instinct is to type the return as the messenger's action-type union for nicer caller types. That's not safe here: it would make
Actionappear in a covariant (return) position — the first such member on the class. Every existingAction-dependent method (call,registerActionHandler) deliberately keepsActionbehind a bounded generic to avoid this. A covariantActionmember breaks assigning a messenger to a narrower-typed one (e.g. passing a controller's full messenger to a service typed against only a subset of its actions) — a pattern consumers rely on (@metamask/perps-controllerdoes exactly this and fails to compile with the union return). No union-derived return type avoids this; only a constant return type does.string[]is sufficient for the consumer below, which just lists/prints the types.Why
@metamask/wallet-cliis gaining anmm daemon listcommand to enumerate the actions on the wallet's root messenger (sibling to the existingmm daemon call <Controller>:<method>). That needs a public accessor on the messenger, which this PR adds. The command itself is a separate wallet-cli follow-up.Notes for reviewers
🤖 Generated with Claude Code
Note
Low Risk
Purely additive read-only introspection with no changes to registration, delegation, or call behavior.
Overview
Adds a read-only
Messenger.getRegisteredActionTypes()API that lists every action type the instance can invoke viacall()—handlers on that messenger plus actions delegated into it, and not actions delegated away.The implementation snapshots keys from the internal
#actionsmap (same sourcegetAction/calluse), so unregistering or revoking delegation updates the list. Tests cover empty messengers, register/unregister, and delegated-in actions; the unreleased changelog documents the method for tooling such as wallet CLI action listing.Reviewed by Cursor Bugbot for commit c14f260. Bugbot is set up for automated code reviews on this repo. Configure here.