ModelRolesResolver class final
Builds per-role fallback chains from configuration and secrets.
Constructors
-
ModelRolesResolver({required ModelRolesConfig config, required Map<
String, String> secrets, String? cwd, String? homeDir, void onNotice(FallbackNotice notice)?, DateTime now()?, double jitterFraction()?, Future<bool> sleeper(Duration delay, CancelToken? cancelToken)?, StreamFunction streamFactory(String kind, String apiKey)?}) -
Creates a resolver over
configand a snapshot ofsecrets(name → value).cwd/homeDirfeed path-override matching;now/jitterFraction/sleeperare injectable for deterministic tests and forwarded to every chain wrapper.streamFactorybuilds the per-key provider adapter (defaults to providerStreamFunction; tests inject fakes).
Properties
- config ↔ ModelRolesConfig
-
The active configuration (replaced by setDefaultChain).
getter/setter pair
- cwd → String?
-
The working directory used for path-override matching.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- homeDir → String?
-
Home directory for
~override patterns.final - jitterFraction → double Function()?
-
Jitter source forwarded to chain wrappers (tests inject determinism).
final
- onNotice ↔ void Function(FallbackNotice notice)?
-
Receives every chain wrapper's FallbackNotice. Mutable so hosts can
attach rendering after construction; wrappers forward to the current
value.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
skippedEntries
→ Map<
String, List< String> > -
Chain entries skipped during the last chainFor per role, as
provider/modelId (reason)— resolution must not degrade silently.final -
sleeper
→ Future<
bool> Function(Duration delay, CancelToken? cancelToken)? -
Sleep implementation forwarded to chain wrappers (tests inject fakes).
final
Methods
-
applyToAgent(
Agent agent, {String role = defaultModelRole}) → void -
Points
agentatrole's model and fallback stream for subsequent runs (the agent's role for a run; hosts usedefaultfor user turns). -
chainFor(
String role) → List< ChainEntry> ? -
Resolves
role's chain for cwd and builds the entries (models from the provider catalog, key rings from the secrets snapshot). -
describeRoles(
) → String -
Renders the roles overview for
/model: each configured role with its chain, the active entry marked (*), cooling-down entries annotated, and skipped entries listed. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolveRole(
String role) → ({Model model, StreamFunction stream})? -
Resolves
roleto its current model and stream function, ornullwhen the role (and the inheriteddefault) is unconfigured. -
setDefaultChain(
List< ModelRef> chain) → void -
Replaces the
defaultrole's chain (runtime/model <id>switch); the new chain takes effect on the next run. -
streamForRole(
String role) → FallbackStreamFunction -
The cached FallbackStreamFunction for
role(entry cooldowns and chain position persist across runs — session state). -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromSecretsStore(
ModelRolesConfig config, SecretsStore store, {String? cwd, String? homeDir, void onNotice(FallbackNotice notice)?, DateTime now()?, double jitterFraction()?, Future< bool> sleeper(Duration delay, CancelToken? cancelToken)?, StreamFunction streamFactory(String kind, String apiKey)?}) → Future<ModelRolesResolver> - Builds a resolver from a SecretsStore (reads the bulk snapshot once).