run method
The run: served from the request's session, where the transport's events are bounded by stallGap (see boundedAiRun) and streamed back here. A busy session refuses or queues (whenBusy). Cancelling the stream cancels the run. complete is derived from this.
The far end receives the request's WirePrompt.combined unchanged, and
the run's report carries the prompt's anchor hash, its body hash and its
template — the attribution a caller wrapping an anchor relies on.
Implementation
@override
Stream<LlmEvent> run(LlmRequest request) {
// a provider that reports no tool use never sees a tool
// declaration. Reaching here with one is a caller that skipped the
// capability check, and sending the prompt without the tools would run an
// agent that cannot act while appearing to.
if (request.toolBinding != null && !capabilities.canUseTools) {
throw UnsupportedError(
'This AI provider cannot use document tools; check '
'capabilities.canUseTools before binding them.',
);
}
if (!connectOnDemand && resume == null) {
final transport = selector.active;
if (transport == null) {
// Features are gated off, so reaching here is a caller bug rather
// than a runtime condition to recover from.
throw UnsupportedError(
'No AI transport is available; check isAvailable before completing.',
);
}
return _attempt(request, transport, resumeId: null);
}
return _prepared(request);
}