Skip to content

feat(stream): document and publicly export readStream and toStream#1828

Open
toubatbrian wants to merge 1 commit into
1.5.0from
brian/export-stream-helpers
Open

feat(stream): document and publicly export readStream and toStream#1828
toubatbrian wants to merge 1 commit into
1.5.0from
brian/export-stream-helpers

Conversation

@toubatbrian

@toubatbrian toubatbrian commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add full TSDoc specs to readStream and toStream in agents/src/utils.ts, documenting their behavior including the abort (readStream) and cancel (toStream) semantics, type params, params, returns, and usage examples.
  • Surface both helpers through the curated stream namespace (agents/src/stream/index.ts) alongside mergeReadableStreams, MultiInputStream, createStreamChannel, etc., so they're cleanly importable and discoverable for user code (stream.readStream / stream.toStream, plus the existing top-level re-export).
  • Add a changeset (@livekit/agents patch).

readStream consumes a ReadableStream as an abortable async generator; toStream is its inverse, adapting any AsyncIterable into a ReadableStream.

Test plan

  • pnpm build:agents succeeds and the generated dist/utils.d.ts / dist/stream/index.d.ts include the documented, exported helpers.
  • pnpm --filter @livekit/agents lint reports only pre-existing warnings (none in the edited files).
  • pnpm exec prettier --check passes on the edited files.

Note: pnpm api:check fails on main independently of this change due to API Extractor not supporting the existing export * as ___ syntax in index.ts; this PR uses the supported export { ... } form.

@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5083033

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 35 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@toubatbrian toubatbrian changed the base branch from main to 1.5.0 June 18, 2026 21:49
Surface the readStream/toStream helpers under the `stream` namespace
alongside the other stream utilities, and add full TSDoc describing their
abort/cancel semantics so they are discoverable and supported for user code.

Co-authored-by: Cursor <cursoragent@cursor.com>
@toubatbrian toubatbrian force-pushed the brian/export-stream-helpers branch from b85c3d5 to 5083033 Compare June 18, 2026 21:51
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

private constructor({ id, tools, toolHandling }: AsyncToolsetCreateOptions) {
super({ id, tools });

P2 Badge Preserve AsyncToolset lifecycle hooks

Because AsyncToolsetCreateOptions extends ToolsetCreateOptions, callers can pass setup/aclose just like Toolset.create, but this constructor destructures only id, tools, and toolHandling and then calls the base constructor, so those hooks are discarded and super.aclose() later is a no-op. Any AsyncToolset that connects resources or publishes dynamic tools from setup never initializes or closes them; please forward/compose these hooks as the base factory does.


const sessionToolsets = this._tools.filter(
(tool): tool is ToolContextEntry<UserData> & { aclose: () => Promise<void> } =>
typeof (tool as { aclose?: unknown }).aclose === 'function',
);
await Promise.allSettled(sessionToolsets.map((toolset) => toolset.aclose()));

P2 Badge Close flattened session toolsets

When session-level tools contain a nested Toolset, setupToolsets() sets it up via new ToolContext(this.agentSession.tools).toolsets, which includes nested toolsets, but this close path only filters the top-level _tools array. In that nested-session-toolset case, the inner toolset's aclose() is never called, leaking resources/listeners; close the flattened ToolContext(...).toolsets list instead.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review

Comment thread agents/src/stream/index.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant