Skip to content

fix: correct V2 SDK API to use receive() instead of stream()#501

Closed
Copilot wants to merge 2 commits into
upgrade/agent-sdk-ts-v2from
copilot/sub-pr-500
Closed

fix: correct V2 SDK API to use receive() instead of stream()#501
Copilot wants to merge 2 commits into
upgrade/agent-sdk-ts-v2from
copilot/sub-pr-500

Conversation

Copilot AI commented Dec 31, 2025

Copy link
Copy Markdown
Contributor

The V2 Agent SDK implementation was calling sdkSession.stream() instead of the documented sdkSession.receive() method, causing a mismatch with the official API specification.

Changes

  • SDKAgent.ts (lines 129, 176): Changed stream()receive() for AsyncGenerator message iteration
  • Comments: Updated to reflect correct V2 "receive" terminology

API Alignment

The Session interface per official V2 docs:

interface Session {
  send(message: string): Promise<void>;
  receive(): AsyncGenerator<SDKMessage>;  // Not stream()
  close(): void;
}

Before:

await sdkSession.send(initPrompt);
for await (const message of sdkSession.stream()) {  // ❌ Incorrect
  await this.handleSDKMessage(message, session, worker);
}

After:

await sdkSession.send(initPrompt);
for await (const message of sdkSession.receive()) {  // ✅ Correct
  await this.handleSDKMessage(message, session, worker);
}

All other V2 API usage (unstable_v2_createSession, unstable_v2_resumeSession, unstable_v2_prompt, await using cleanup) was already correct.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: thedotmack <683968+thedotmack@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate to Agent SDK V2 with code quality improvements fix: correct V2 SDK API to use receive() instead of stream() Dec 31, 2025
Copilot AI requested a review from thedotmack December 31, 2025 03:03
@thedotmack

Copy link
Copy Markdown
Owner

@copilot Lol how bad was it? Its such a simple easy implementation lol

Copilot AI commented Dec 31, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Lol how bad was it? Its such a simple easy implementation lol

Not bad at all! Just one method name wrong in 2 places (stream() vs receive()). Everything else - session creation, resuming, send pattern, cleanup - was already correct. Clean 2-line fix.

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.

2 participants