PluginsHooksExamples
Why Role Resolution Must Stay Unique
Use a role-resolution scenario to show why resolve cannot allow several plugins to answer at once
Why Role Resolution Must Stay Unique
Scenario
The host wants to answer one question:
- what is this user's final role
So it calls:
const role = await agent.plugins.resolve<{ userId: string }, string>(
"auth.resolve_role",
{ userId: "owner" },
);Why two resolvers would be a problem
If two plugins can both answer:
- plugin A says
admin - plugin B says
member
then the host has to add another layer of arbitration.
But the whole point of resolve is to avoid that extra arbitration layer.
Its design means:
- this point must decide its single authority ahead of time
That is why the implementation behaves this way
- duplicate registration for the same resolve point: throw
- no resolver registered: throw
- resolver plugin disabled: throw
All three rules protect the same invariant:
- the final answer must stay unambiguous
If you really want several participants
Then you probably should not use resolve for that part.
A healthier structure is often:
- first use
pipelineto collect and enrich context - then let one
resolvepoint produce the final answer