ai.clients.resolve
Resolve a `Selector` to the client to call, at CALL time.
Signature
Resolve a Selector to the client to call, at CALL time.
- a
ai.Clientis returned unchanged (identity); - a string is the
"provider/model"shorthand, constructed throughproviders— the runtime twin of the compiler's literal-client:lowering. An unknown prefix throwsai.errors.InvalidRequestlisting the valid ones; - a
baml.env.Refis read now and its value takes the string path. An UNSET variable is a typedai.errors.InvalidRequestnaming it — not a panic, so acatch_allat the call boundary can still fall back.
Write it as ai.clients.resolve(selector): the call is compiler-assisted.
Only the compiler knows every provider (each provider package depends on
this one, so this package cannot name them), so at every call site it
appends providers — constructing the client for a prefix and model, or
null for a prefix it does not know — and prefixes, the prefixes it
knows, both synthesized from the one provider table the literal
client "provider/model" lowering reads.
This is what makes client: env.MODEL.get() ?? "openai/gpt-4o-mini" work:
nothing about the selection is decided until the call happens.
Source:<builtin>/ai/ns_clients/clients.bamlbytes 2079–3045