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 {
final response = await sendProviderRequest(httpClient, request, cancelToken);
await onResponse?.call(response.statusCode, response.headers, state.model);
eventStream.push(StartEvent(partial: state.snapshot()));
return response;
}