#include "third_party/blink/renderer/modules/ai/model_execution_responder.h"
#include <optional>
#include "base/functional/callback_forward.h"
#include "base/metrics/histogram_functions.h"
#include "third_party/blink/public/mojom/ai/model_streaming_responder.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/abort_signal.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/streams/readable_stream.h"
#include "third_party/blink/renderer/core/streams/readable_stream_default_controller_with_script_scope.h"
#include "third_party/blink/renderer/core/streams/underlying_source_base.h"
#include "third_party/blink/renderer/modules/ai/exception_helpers.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/context_lifecycle_observer.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/heap/self_keep_alive.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
namespace {
class Responder final : public GarbageCollected<Responder>,
public mojom::blink::ModelStreamingResponder,
public ContextLifecycleObserver { … };
class StreamingResponder final
: public UnderlyingSourceBase,
public blink::mojom::blink::ModelStreamingResponder { … };
}
std::tuple<ScriptPromise<IDLString>,
mojo::PendingRemote<blink::mojom::blink::ModelStreamingResponder>>
CreateModelExecutionResponder(
ScriptState* script_state,
AbortSignal* signal,
scoped_refptr<base::SequencedTaskRunner> task_runner,
AIMetrics::AISessionType session_type,
base::OnceCallback<void(std::optional<uint64_t> current_tokens)>
complete_callback) { … }
std::tuple<ReadableStream*,
mojo::PendingRemote<blink::mojom::blink::ModelStreamingResponder>>
CreateModelExecutionStreamingResponder(
ScriptState* script_state,
AbortSignal* signal,
scoped_refptr<base::SequencedTaskRunner> task_runner,
AIMetrics::AISessionType session_type,
base::OnceCallback<void(std::optional<uint64_t> current_tokens)>
complete_callback) { … }
}