startProviderResponse function
Future<StreamedResponse>
startProviderResponse(
- AssistantMessageEventStream eventStream,
- ProviderStreamState state,
- Client httpClient,
- Request request,
- CancelToken? cancelToken,
- FutureOr<
void> onResponse()?,
Sends request (via sendProviderRequest), runs the adapter's
onResponse hook, and pushes the StartEvent with the initial snapshot.
Shared by the adapters: pi fires start right after the response headers
arrive, before the body stream is consumed.
Implementation
Future<http.StreamedResponse> startProviderResponse(
AssistantMessageEventStream eventStream,
ProviderStreamState state,
http.Client httpClient,
http.Request request,
CancelToken? cancelToken,
FutureOr<void> Function(int statusCode, Map<String, String> headers, Model)?
onResponse,
) async {
// Issue #1554: the model's request-scoped watchdog windows (a roles
// chain entry's `connectTimeoutMs`/`streamIdleTimeoutMs`) ride the send
// — the top precedence layer, above the URL-keyed tuning table. The
// scope label cites THE LEG THAT RAN (review round 1): an idle-only
// override never names its scope on a connect-stall note, and vice
// versa — a leg that ran the global default keeps the bare text.
final response = await sendProviderRequest(
httpClient,
request,
cancelToken,
connectTimeout: state.model.connectTimeout,
timeoutSource: state.model.connectTimeout == null
? null
: state.model.timeoutScopeLabel,
);
await onResponse?.call(response.statusCode, response.headers, state.model);
eventStream.push(StartEvent(partial: state.snapshot()));
return response;
}