Commit 17aa41a
authored
* feat(teams): migrate native streaming to the SDK IStreamer + unwind transitional divergences (#93 PR 3/4)
Replace the hand-rolled Bot Framework streaming wire format with the
Teams SDK's native streamer (microsoft-teams-apps IStreamer / HttpStream),
mirroring upstream adapter-teams@chat@4.30.0 index.ts (streamViaEmit DM
path). Atomically unwind the two transitional public-type divergences
this enables.
Streaming flow (DMs):
- _handle_message_activity captures an IStreamer for DMs via
app.activity_sender.create_stream(ref), registers it in _active_streams,
and awaits a processing_done gate (wrapped wait_until shim) so the
streamer stays alive while the handler streams.
- stream() -> _stream_via_emit calls stream.emit(text) per chunk; it NEVER
calls close(). The handler's finally calls stream.close() once (the
lifecycle-owner role the SDK App's process_activity plays upstream;
our bridge owns dispatch via server.on_request).
- Cancellation is detected two ways: stream.canceled (checked before each
emit) and catching StreamCancelledError (other exceptions re-raise).
- The first chunk's server-assigned id is captured via on_chunk and
awaited only when text was emitted and the stream was not canceled.
- Group / channel / proactive threads fall back to a single buffered
post_message (SDK-backed from PR 2).
Removed: _TeamsStreamSession, _stream_via_emit's hand-rolled wire format,
_emit_streaming_activity, _close_stream_session, _teams_send, the 1500ms
emit throttle, the clock/sleep injectables, and the
native_stream_min_emit_interval_ms config field.
Divergence unwinds (must land together — touching one without the other
corrupts recorded message history):
- types.py: removed the RawMessage.text override field (RawMessage is now
{id, thread_id, raw}, matching upstream packages/chat/src/types.ts).
- thread.py: _handle_stream now seeds StreamOptions.update_interval_ms
with the thread default (upstream parity, vercel/chat#340) and records
the local accumulator (no adapter-side text override).
Throttle parity: the SDK HttpStream owns the Bot Framework streaming wire
format (streamType/streamSequence/streamId), a 500ms inter-flush throttle,
and 429 retry/backoff — verified against microsoft-teams-apps==2.0.13
http_stream.py (see docs/UPSTREAM_SYNC.md). A live Teams check is flagged
for reviewers/maintainer.
Tests: rewrote tests/test_teams_native_streaming.py to mock ctx.stream as
a StreamerProtocol double; added history-fidelity tests proving the
SentMessage->Message recording path and update_interval_ms seeding after
the unwind.
* docs(teams): clarify close-on-raw-cancel intent + pin SDK version in throttle note
Review fast-follow for PR 3 (native streaming): the finally-block comment
now distinguishes SDK-detected cancel (HttpStream.close no-ops, _canceled
set) from a raw asyncio.CancelledError (close flushes a final activity for
the accumulated text — intentional, and the except-Exception wrapper does
not catch CancelledError so cancellation still propagates). Also pins the
throttle-parity note to the installed microsoft-teams-apps==2.0.13.4 so a
future SDK bump that changes the 0.5s cadence is caught against the cited
baseline. No logic change.
1 parent a9f0c80 commit 17aa41a
11 files changed
Lines changed: 985 additions & 2397 deletions
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | 75 | | |
87 | 76 | | |
88 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
690 | 690 | | |
691 | 691 | | |
692 | 692 | | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
710 | 702 | | |
711 | 703 | | |
712 | 704 | | |
| |||
744 | 736 | | |
745 | 737 | | |
746 | 738 | | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
759 | 746 | | |
760 | 747 | | |
761 | | - | |
| 748 | + | |
762 | 749 | | |
763 | 750 | | |
764 | 751 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
855 | 855 | | |
856 | 856 | | |
857 | 857 | | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | | - | |
878 | 858 | | |
879 | 859 | | |
880 | 860 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
983 | 983 | | |
984 | 984 | | |
985 | 985 | | |
986 | | - | |
| 986 | + | |
987 | 987 | | |
988 | 988 | | |
989 | 989 | | |
990 | 990 | | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
1012 | | - | |
1013 | | - | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | 991 | | |
1028 | 992 | | |
1029 | 993 | | |
| |||
1244 | 1208 | | |
1245 | 1209 | | |
1246 | 1210 | | |
| 1211 | + | |
| 1212 | + | |
1247 | 1213 | | |
1248 | 1214 | | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
| 1215 | + | |
1257 | 1216 | | |
1258 | 1217 | | |
1259 | 1218 | | |
| |||
1267 | 1226 | | |
1268 | 1227 | | |
1269 | 1228 | | |
1270 | | - | |
| 1229 | + | |
1271 | 1230 | | |
1272 | 1231 | | |
1273 | | - | |
| 1232 | + | |
1274 | 1233 | | |
1275 | 1234 | | |
1276 | 1235 | | |
1277 | | - | |
| 1236 | + | |
1278 | 1237 | | |
1279 | 1238 | | |
1280 | 1239 | | |
| |||
1290 | 1249 | | |
1291 | 1250 | | |
1292 | 1251 | | |
1293 | | - | |
| 1252 | + | |
1294 | 1253 | | |
1295 | 1254 | | |
1296 | 1255 | | |
1297 | | - | |
| 1256 | + | |
1298 | 1257 | | |
1299 | 1258 | | |
1300 | 1259 | | |
| |||
1309 | 1268 | | |
1310 | 1269 | | |
1311 | 1270 | | |
1312 | | - | |
| 1271 | + | |
1313 | 1272 | | |
1314 | 1273 | | |
1315 | 1274 | | |
| |||
1368 | 1327 | | |
1369 | 1328 | | |
1370 | 1329 | | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
1374 | | - | |
1375 | | - | |
1376 | | - | |
1377 | | - | |
1378 | | - | |
1379 | | - | |
1380 | | - | |
1381 | | - | |
1382 | | - | |
1383 | | - | |
1384 | | - | |
1385 | | - | |
1386 | | - | |
1387 | | - | |
1388 | | - | |
1389 | | - | |
1390 | | - | |
1391 | | - | |
1392 | | - | |
1393 | | - | |
1394 | | - | |
1395 | | - | |
1396 | | - | |
1397 | | - | |
1398 | | - | |
1399 | | - | |
1400 | | - | |
1401 | | - | |
1402 | 1330 | | |
1403 | 1331 | | |
1404 | 1332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
739 | | - | |
740 | | - | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
741 | 743 | | |
742 | 744 | | |
743 | | - | |
| 745 | + | |
744 | 746 | | |
745 | 747 | | |
746 | 748 | | |
| |||
755 | 757 | | |
756 | 758 | | |
757 | 759 | | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
763 | 766 | | |
764 | 767 | | |
765 | 768 | | |
766 | 769 | | |
767 | 770 | | |
768 | | - | |
| 771 | + | |
769 | 772 | | |
770 | 773 | | |
771 | 774 | | |
| |||
782 | 785 | | |
783 | 786 | | |
784 | 787 | | |
785 | | - | |
| 788 | + | |
0 commit comments