Skip to content

feat(adapter-teams): native streaming for DMs via emit#416

Merged
dancer merged 4 commits into
vercel:mainfrom
heyitsaamir:feat/teams-native-streaming
Apr 29, 2026
Merged

feat(adapter-teams): native streaming for DMs via emit#416
dancer merged 4 commits into
vercel:mainfrom
heyitsaamir:feat/teams-native-streaming

Conversation

@heyitsaamir
Copy link
Copy Markdown
Contributor

Summary

  • Use Teams SDK's ctx.stream.emit() for DM streaming instead of manual post+edit
  • Proper streaming UI in Teams (typing indicators with streamType: 'streaming' channelData)
  • Group chats accumulate and post as single message (no post+edit flicker)
  • Handles cancellation (stream.canceled + StreamCancelledError)

How it works

  • handleMessageActivity captures ctx.stream for DMs and blocks the handler via a deferred promise wired through waitUntil — this keeps the Teams SDK from auto-closing the stream before processing completes
  • streamViaEmit() sends incremental text deltas via stream.emit(), framework auto-closes with streamType: 'final'
  • Falls back to accumulate-and-post for group chats where no IStreamer is available

Also adds missing @slack/socket-mode dep to adapter-slack.

Test plan

  • pnpm --filter @chat-adapter/teams build passes
  • pnpm --filter @chat-adapter/teams test — 148 tests pass
  • Manual: DM bot in Teams — response streams with native typing UI
  • Manual: Group chat — response posts as single message (no flicker)

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 23, 2026

@heyitsaamir is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@heyitsaamir heyitsaamir force-pushed the feat/teams-native-streaming branch 2 times, most recently from 4fbde61 to 68dfc05 Compare April 23, 2026 22:24
@bensabic bensabic force-pushed the feat/teams-native-streaming branch from b2f63cc to df792e2 Compare April 29, 2026 08:58
@bensabic bensabic requested a review from a team as a code owner April 29, 2026 08:58
heyitsaamir and others added 4 commits April 29, 2026 16:01
Use ctx.stream.emit() from the Teams SDK for DM streaming instead of
manual post+edit. This sends proper typing activities with streamType
channelData, giving the native streaming UI in Teams.

- Capture IStreamer from activity context in handleMessageActivity
- Block handler with deferred promise so stream stays alive during processing
- streamViaEmit() for DMs: uses stream.emit() with incremental text deltas
- Group chats: accumulate full response and post as single message (no flicker)
- Handle StreamCancelledError and stream.canceled for graceful cancellation

Co-Authored-By: Claude <noreply@anthropic.com>
Group chats now accumulate streamed chunks and post as a single message
instead of post+edit, so assertions should check sentActivities not
updatedActivities.
@dancer dancer force-pushed the feat/teams-native-streaming branch from df792e2 to 151becb Compare April 29, 2026 15:02
@dancer dancer merged commit ed46bae into vercel:main Apr 29, 2026
7 of 8 checks passed
patrick-chinchill added a commit to Chinchill-AI/chat-sdk-python that referenced this pull request May 28, 2026
Ports vercel/chat#416 — native Teams streaming for DMs via emit.

DM threads now use the Bot Framework streaming protocol (typing activities with channelData.streamType=streaming + streamSequence, then a final message activity with streamType=final) instead of Thread._fallback_stream. Group chats accumulate and post a single message, matching upstream's flicker-free behavior.

- Wire format: streamId omitted on first chunk, present on both channelData and streaminfo entity for subsequent and final activities
- Throttle: configurable native_stream_min_emit_interval_ms (default 1500ms), honors StreamOptions.update_interval_ms
- End-of-stream flush ensures buffered text is confirmed-accepted before close
- Send-failure mid-stream cancels session and re-raises (keeps Thread.stream history consistent with delivered chunks)
- Migration to microsoft-teams-apps SDK tracked as issue #93 (out of scope for 4.27.0)
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.

3 participants