ai.stream.from_spec

One-turn streaming over a spec: render the spec's prompt exactly as the default runner's first turn would, require a streaming-capable client, and return the typed partial stream. The compiler-private `Fn@stream` entry calls this function with the `Out$stream` partial schema; host stream helpers reach that companion through the normal bridge.

Reference version

Signature

function ai.stream.from_spec<TStream, TFinal, __effect_param_0>(
spec: ai.FunctionSpec<TFinal>,
client: ai.stream.StreamingClient | null = …,
on_event: ((ai.events.Event) -> void throws __effect_param_0) | null = …
) -> ai.stream.Stream<TStream, TFinal> throws baml.errors.InvalidArgument | baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

One-turn streaming over a spec: render the spec's prompt exactly as the default runner's first turn would, require a streaming-capable client, and return the typed partial stream. The compiler-private Fn@stream entry calls this function with the Out$stream partial schema; host stream helpers reach that companion through the normal bridge.

Streaming does not run the tool loop yet: a spec with a non-empty toolbox is rejected. The client override is typed as the capability, so passing a non-streaming client fails at the call site; the spec's DEFAULT client is only checked at runtime (ai.errors.StreamingUnsupported when it cannot stream).

Source:<builtin>/ai/ns_stream/stream.bamlbytes 2346626698