@kodelyth/msteams 2026.5.42 → 2026.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/klaw.plugin.json +726 -2
  2. package/package.json +18 -6
  3. package/api.ts +0 -3
  4. package/channel-config-api.ts +0 -1
  5. package/channel-plugin-api.ts +0 -2
  6. package/config-api.ts +0 -4
  7. package/contract-api.ts +0 -4
  8. package/index.ts +0 -20
  9. package/runtime-api.ts +0 -66
  10. package/secret-contract-api.ts +0 -5
  11. package/setup-entry.ts +0 -13
  12. package/setup-plugin-api.ts +0 -3
  13. package/src/ai-entity.ts +0 -7
  14. package/src/approval-auth.ts +0 -44
  15. package/src/attachments/bot-framework.test.ts +0 -506
  16. package/src/attachments/bot-framework.ts +0 -348
  17. package/src/attachments/download.ts +0 -328
  18. package/src/attachments/graph.test.ts +0 -441
  19. package/src/attachments/graph.ts +0 -489
  20. package/src/attachments/html.ts +0 -122
  21. package/src/attachments/payload.ts +0 -14
  22. package/src/attachments/remote-media.test.ts +0 -187
  23. package/src/attachments/remote-media.ts +0 -86
  24. package/src/attachments/shared.test.ts +0 -547
  25. package/src/attachments/shared.ts +0 -655
  26. package/src/attachments/types.ts +0 -47
  27. package/src/attachments.graph.test.ts +0 -414
  28. package/src/attachments.helpers.test.ts +0 -245
  29. package/src/attachments.test-helpers.ts +0 -17
  30. package/src/attachments.test.ts +0 -754
  31. package/src/attachments.ts +0 -18
  32. package/src/block-streaming-config.test.ts +0 -61
  33. package/src/channel-api.ts +0 -1
  34. package/src/channel.actions.test.ts +0 -797
  35. package/src/channel.directory.test.ts +0 -176
  36. package/src/channel.message-adapter.test.ts +0 -227
  37. package/src/channel.runtime.ts +0 -56
  38. package/src/channel.setup.ts +0 -77
  39. package/src/channel.test.ts +0 -136
  40. package/src/channel.ts +0 -1176
  41. package/src/config-schema.ts +0 -6
  42. package/src/config-ui-hints.ts +0 -40
  43. package/src/conversation-store-fs.test.ts +0 -81
  44. package/src/conversation-store-fs.ts +0 -149
  45. package/src/conversation-store-helpers.test.ts +0 -202
  46. package/src/conversation-store-helpers.ts +0 -105
  47. package/src/conversation-store-memory.ts +0 -51
  48. package/src/conversation-store.shared.test.ts +0 -260
  49. package/src/conversation-store.ts +0 -71
  50. package/src/directory-live.test.ts +0 -156
  51. package/src/directory-live.ts +0 -111
  52. package/src/doctor.ts +0 -27
  53. package/src/errors.test.ts +0 -154
  54. package/src/errors.ts +0 -270
  55. package/src/feedback-reflection-prompt.ts +0 -117
  56. package/src/feedback-reflection-store.ts +0 -113
  57. package/src/feedback-reflection.test.ts +0 -237
  58. package/src/feedback-reflection.ts +0 -268
  59. package/src/file-consent-helpers.test.ts +0 -328
  60. package/src/file-consent-helpers.ts +0 -115
  61. package/src/file-consent-invoke.ts +0 -150
  62. package/src/file-consent.test.ts +0 -378
  63. package/src/file-consent.ts +0 -223
  64. package/src/graph-chat.ts +0 -36
  65. package/src/graph-group-management.test.ts +0 -332
  66. package/src/graph-group-management.ts +0 -168
  67. package/src/graph-members.test.ts +0 -89
  68. package/src/graph-members.ts +0 -48
  69. package/src/graph-messages.actions.test.ts +0 -253
  70. package/src/graph-messages.read.test.ts +0 -391
  71. package/src/graph-messages.search.test.ts +0 -227
  72. package/src/graph-messages.test-helpers.ts +0 -50
  73. package/src/graph-messages.ts +0 -534
  74. package/src/graph-teams.test.ts +0 -222
  75. package/src/graph-teams.ts +0 -114
  76. package/src/graph-thread.test.ts +0 -252
  77. package/src/graph-thread.ts +0 -146
  78. package/src/graph-upload.test.ts +0 -253
  79. package/src/graph-upload.ts +0 -531
  80. package/src/graph-users.ts +0 -29
  81. package/src/graph.test.ts +0 -540
  82. package/src/graph.ts +0 -308
  83. package/src/inbound.test.ts +0 -221
  84. package/src/inbound.ts +0 -148
  85. package/src/index.ts +0 -4
  86. package/src/media-helpers.test.ts +0 -220
  87. package/src/media-helpers.ts +0 -105
  88. package/src/mentions.test.ts +0 -254
  89. package/src/mentions.ts +0 -114
  90. package/src/messenger.test.ts +0 -961
  91. package/src/messenger.ts +0 -608
  92. package/src/monitor-handler/access.ts +0 -136
  93. package/src/monitor-handler/inbound-media.test.ts +0 -314
  94. package/src/monitor-handler/inbound-media.ts +0 -180
  95. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  96. package/src/monitor-handler/message-handler.authz.test.ts +0 -739
  97. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  98. package/src/monitor-handler/message-handler.test-support.ts +0 -99
  99. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -225
  100. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -132
  101. package/src/monitor-handler/message-handler.ts +0 -1003
  102. package/src/monitor-handler/reaction-handler.test.ts +0 -325
  103. package/src/monitor-handler/reaction-handler.ts +0 -122
  104. package/src/monitor-handler/thread-session.ts +0 -30
  105. package/src/monitor-handler.adaptive-card.test.ts +0 -158
  106. package/src/monitor-handler.feedback-authz.test.ts +0 -357
  107. package/src/monitor-handler.file-consent.test.ts +0 -443
  108. package/src/monitor-handler.sso.test.ts +0 -576
  109. package/src/monitor-handler.test-helpers.ts +0 -181
  110. package/src/monitor-handler.ts +0 -538
  111. package/src/monitor-handler.types.ts +0 -27
  112. package/src/monitor-types.ts +0 -6
  113. package/src/monitor.lifecycle.test.ts +0 -457
  114. package/src/monitor.test.ts +0 -119
  115. package/src/monitor.ts +0 -476
  116. package/src/oauth.flow.ts +0 -77
  117. package/src/oauth.shared.ts +0 -37
  118. package/src/oauth.test.ts +0 -350
  119. package/src/oauth.token.ts +0 -162
  120. package/src/oauth.ts +0 -130
  121. package/src/outbound.test.ts +0 -400
  122. package/src/outbound.ts +0 -198
  123. package/src/pending-uploads-fs.test.ts +0 -261
  124. package/src/pending-uploads-fs.ts +0 -235
  125. package/src/pending-uploads.test.ts +0 -186
  126. package/src/pending-uploads.ts +0 -121
  127. package/src/policy.test.ts +0 -156
  128. package/src/policy.ts +0 -245
  129. package/src/polls-store-memory.ts +0 -32
  130. package/src/polls.test.ts +0 -169
  131. package/src/polls.ts +0 -312
  132. package/src/presentation.ts +0 -93
  133. package/src/probe.test.ts +0 -79
  134. package/src/probe.ts +0 -132
  135. package/src/reply-dispatcher.test.ts +0 -543
  136. package/src/reply-dispatcher.ts +0 -523
  137. package/src/reply-stream-controller.test.ts +0 -424
  138. package/src/reply-stream-controller.ts +0 -334
  139. package/src/resolve-allowlist.test.ts +0 -253
  140. package/src/resolve-allowlist.ts +0 -309
  141. package/src/revoked-context.ts +0 -17
  142. package/src/runtime.ts +0 -12
  143. package/src/sdk-types.ts +0 -59
  144. package/src/sdk.test.ts +0 -727
  145. package/src/sdk.ts +0 -916
  146. package/src/secret-contract.ts +0 -49
  147. package/src/secret-input.ts +0 -7
  148. package/src/send-context.test.ts +0 -93
  149. package/src/send-context.ts +0 -269
  150. package/src/send.test.ts +0 -588
  151. package/src/send.ts +0 -697
  152. package/src/sent-message-cache.test.ts +0 -106
  153. package/src/sent-message-cache.ts +0 -174
  154. package/src/session-route.ts +0 -40
  155. package/src/setup-core.ts +0 -162
  156. package/src/setup-surface.test.ts +0 -175
  157. package/src/setup-surface.ts +0 -319
  158. package/src/sso-token-store.test.ts +0 -74
  159. package/src/sso-token-store.ts +0 -166
  160. package/src/sso.ts +0 -300
  161. package/src/storage.ts +0 -25
  162. package/src/store-fs.ts +0 -42
  163. package/src/streaming-message.test.ts +0 -323
  164. package/src/streaming-message.ts +0 -327
  165. package/src/test-runtime.ts +0 -16
  166. package/src/thread-parent-context.test.ts +0 -224
  167. package/src/thread-parent-context.ts +0 -159
  168. package/src/token-response.ts +0 -11
  169. package/src/token.test.ts +0 -268
  170. package/src/token.ts +0 -194
  171. package/src/user-agent.test.ts +0 -121
  172. package/src/user-agent.ts +0 -53
  173. package/src/webhook-timeouts.ts +0 -27
  174. package/src/welcome-card.test.ts +0 -104
  175. package/src/welcome-card.ts +0 -57
  176. package/test-api.ts +0 -1
  177. package/tsconfig.json +0 -16
package/src/probe.ts DELETED
@@ -1,132 +0,0 @@
1
- import {
2
- normalizeStringEntries,
3
- type BaseProbeResult,
4
- type MSTeamsConfig,
5
- } from "../runtime-api.js";
6
- import { formatUnknownError } from "./errors.js";
7
- import { createMSTeamsTokenProvider, loadMSTeamsSdkWithAuth } from "./sdk.js";
8
- import { readAccessToken } from "./token-response.js";
9
- import { loadDelegatedTokens, resolveMSTeamsCredentials } from "./token.js";
10
-
11
- export type ProbeMSTeamsResult = BaseProbeResult<string> & {
12
- appId?: string;
13
- graph?: {
14
- ok: boolean;
15
- error?: string;
16
- roles?: string[];
17
- scopes?: string[];
18
- };
19
- delegatedAuth?: {
20
- ok: boolean;
21
- error?: string;
22
- scopes?: string[];
23
- userPrincipalName?: string;
24
- };
25
- };
26
-
27
- function decodeJwtPayload(token: string): Record<string, unknown> | null {
28
- const parts = token.split(".");
29
- if (parts.length < 2) {
30
- return null;
31
- }
32
- const payload = parts[1] ?? "";
33
- const padded = payload.padEnd(payload.length + ((4 - (payload.length % 4)) % 4), "=");
34
- const normalized = padded.replace(/-/g, "+").replace(/_/g, "/");
35
- try {
36
- const decoded = Buffer.from(normalized, "base64").toString("utf8");
37
- const parsed = JSON.parse(decoded) as Record<string, unknown>;
38
- return parsed && typeof parsed === "object" ? parsed : null;
39
- } catch {
40
- return null;
41
- }
42
- }
43
-
44
- function readStringArray(value: unknown): string[] | undefined {
45
- if (!Array.isArray(value)) {
46
- return undefined;
47
- }
48
- const out = normalizeStringEntries(value);
49
- return out.length > 0 ? out : undefined;
50
- }
51
-
52
- function readScopes(value: unknown): string[] | undefined {
53
- if (typeof value !== "string") {
54
- return undefined;
55
- }
56
- const out = value
57
- .split(/\s+/)
58
- .map((entry) => entry.trim())
59
- .filter(Boolean);
60
- return out.length > 0 ? out : undefined;
61
- }
62
-
63
- export async function probeMSTeams(cfg?: MSTeamsConfig): Promise<ProbeMSTeamsResult> {
64
- const creds = resolveMSTeamsCredentials(cfg);
65
- if (!creds) {
66
- return {
67
- ok: false,
68
- error: "missing credentials (appId, appPassword, tenantId)",
69
- };
70
- }
71
-
72
- try {
73
- const { app } = await loadMSTeamsSdkWithAuth(creds);
74
- const tokenProvider = createMSTeamsTokenProvider(app);
75
- const botTokenValue = await tokenProvider.getAccessToken("https://api.botframework.com");
76
- if (!botTokenValue) {
77
- throw new Error("Failed to acquire bot token");
78
- }
79
-
80
- let graph:
81
- | {
82
- ok: boolean;
83
- error?: string;
84
- roles?: string[];
85
- scopes?: string[];
86
- }
87
- | undefined;
88
- try {
89
- const graphTokenValue = await tokenProvider.getAccessToken("https://graph.microsoft.com");
90
- const accessToken = readAccessToken(graphTokenValue);
91
- const payload = accessToken ? decodeJwtPayload(accessToken) : null;
92
- graph = {
93
- ok: true,
94
- roles: readStringArray(payload?.roles),
95
- scopes: readScopes(payload?.scp),
96
- };
97
- } catch (err) {
98
- graph = { ok: false, error: formatUnknownError(err) };
99
- }
100
- let delegatedAuth: ProbeMSTeamsResult["delegatedAuth"];
101
- if (cfg?.delegatedAuth?.enabled) {
102
- try {
103
- const tokens = loadDelegatedTokens();
104
- if (tokens) {
105
- const isExpired = tokens.expiresAt <= Date.now();
106
- delegatedAuth = {
107
- ok: !isExpired,
108
- scopes: tokens.scopes,
109
- userPrincipalName: tokens.userPrincipalName,
110
- ...(isExpired ? { error: "token expired (will auto-refresh on next use)" } : {}),
111
- };
112
- } else {
113
- delegatedAuth = { ok: false, error: "no delegated tokens found (run setup wizard)" };
114
- }
115
- } catch {
116
- delegatedAuth = { ok: false, error: "failed to load delegated tokens" };
117
- }
118
- }
119
- return {
120
- ok: true,
121
- appId: creds.appId,
122
- ...(graph ? { graph } : {}),
123
- ...(delegatedAuth ? { delegatedAuth } : {}),
124
- };
125
- } catch (err) {
126
- return {
127
- ok: false,
128
- appId: creds.appId,
129
- error: formatUnknownError(err),
130
- };
131
- }
132
- }
@@ -1,543 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- const createChannelMessageReplyPipelineMock = vi.hoisted(() => vi.fn());
4
- const createReplyDispatcherWithTypingMock = vi.hoisted(() => vi.fn());
5
- const getMSTeamsRuntimeMock = vi.hoisted(() => vi.fn());
6
- const enqueueSystemEventMock = vi.hoisted(() => vi.fn());
7
- const renderReplyPayloadsToMessagesMock = vi.hoisted(() => vi.fn(() => []));
8
- const sendMSTeamsMessagesMock = vi.hoisted(() => vi.fn(async () => []));
9
- const streamInstances = vi.hoisted(
10
- () =>
11
- [] as Array<{
12
- hasContent: boolean;
13
- isFinalized: boolean;
14
- isFailed: boolean;
15
- streamedLength: number;
16
- sendInformativeUpdate: ReturnType<typeof vi.fn>;
17
- update: ReturnType<typeof vi.fn>;
18
- finalize: ReturnType<typeof vi.fn>;
19
- }>,
20
- );
21
-
22
- vi.mock("../runtime-api.js", () => ({
23
- createChannelMessageReplyPipeline: createChannelMessageReplyPipelineMock,
24
- logTypingFailure: vi.fn(),
25
- resolveChannelMediaMaxBytes: vi.fn(() => 8 * 1024 * 1024),
26
- }));
27
-
28
- vi.mock("./runtime.js", () => ({
29
- getMSTeamsRuntime: getMSTeamsRuntimeMock,
30
- }));
31
-
32
- vi.mock("./messenger.js", () => ({
33
- buildConversationReference: vi.fn((ref) => ref),
34
- renderReplyPayloadsToMessages: renderReplyPayloadsToMessagesMock,
35
- sendMSTeamsMessages: sendMSTeamsMessagesMock,
36
- }));
37
-
38
- vi.mock("./errors.js", () => ({
39
- classifyMSTeamsSendError: vi.fn(() => ({})),
40
- formatMSTeamsSendErrorHint: vi.fn(() => undefined),
41
- formatUnknownError: vi.fn((err) => String(err)),
42
- }));
43
-
44
- vi.mock("./revoked-context.js", () => ({
45
- withRevokedProxyFallback: async ({ run }: { run: () => Promise<unknown> }) => await run(),
46
- }));
47
-
48
- vi.mock("./streaming-message.js", () => ({
49
- TeamsHttpStream: class {
50
- hasContent = false;
51
- isFinalized = false;
52
- isFailed = false;
53
- streamedLength = 0;
54
- sendInformativeUpdate = vi.fn(async () => {});
55
- update = vi.fn();
56
- finalize = vi.fn(async function (this: { isFinalized: boolean }) {
57
- this.isFinalized = true;
58
- });
59
-
60
- constructor() {
61
- streamInstances.push(this);
62
- }
63
- },
64
- }));
65
-
66
- import { createMSTeamsReplyDispatcher, pickInformativeStatusText } from "./reply-dispatcher.js";
67
-
68
- describe("createMSTeamsReplyDispatcher", () => {
69
- let typingCallbacks: {
70
- onReplyStart: ReturnType<typeof vi.fn>;
71
- onIdle: ReturnType<typeof vi.fn>;
72
- onCleanup: ReturnType<typeof vi.fn>;
73
- };
74
-
75
- beforeEach(() => {
76
- vi.clearAllMocks();
77
- streamInstances.length = 0;
78
-
79
- typingCallbacks = {
80
- onReplyStart: vi.fn(async () => {}),
81
- onIdle: vi.fn(),
82
- onCleanup: vi.fn(),
83
- };
84
-
85
- createChannelMessageReplyPipelineMock.mockReturnValue({
86
- onModelSelected: vi.fn(),
87
- typingCallbacks,
88
- });
89
-
90
- createReplyDispatcherWithTypingMock.mockImplementation((options) => ({
91
- dispatcher: {},
92
- replyOptions: {},
93
- markDispatchIdle: vi.fn(),
94
- _options: options,
95
- }));
96
-
97
- getMSTeamsRuntimeMock.mockReturnValue({
98
- system: {
99
- enqueueSystemEvent: enqueueSystemEventMock,
100
- },
101
- channel: {
102
- text: {
103
- resolveChunkMode: vi.fn(() => "length"),
104
- resolveMarkdownTableMode: vi.fn(() => "code"),
105
- },
106
- reply: {
107
- createReplyDispatcherWithTyping: createReplyDispatcherWithTypingMock,
108
- resolveHumanDelayConfig: vi.fn(() => undefined),
109
- },
110
- },
111
- });
112
- });
113
-
114
- let lastCreatedDispatcher: ReturnType<typeof createMSTeamsReplyDispatcher> | undefined;
115
- let lastContextSendActivity: ReturnType<typeof vi.fn> | undefined;
116
-
117
- function createDispatcher(
118
- conversationType: string = "personal",
119
- msteamsConfig: Record<string, unknown> = {},
120
- extraParams: { onSentMessageIds?: (ids: string[]) => void } = {},
121
- ) {
122
- const contextSendActivity = vi.fn(async () => ({ id: "activity-1" }));
123
- lastContextSendActivity = contextSendActivity;
124
- const dispatcher = createMSTeamsReplyDispatcher({
125
- cfg: { channels: { msteams: msteamsConfig } } as never,
126
- agentId: "agent",
127
- sessionKey: "agent:main:main",
128
- runtime: { error: vi.fn() } as never,
129
- log: { debug: vi.fn(), error: vi.fn(), warn: vi.fn() } as never,
130
- adapter: {
131
- continueConversation: vi.fn(),
132
- process: vi.fn(),
133
- updateActivity: vi.fn(),
134
- deleteActivity: vi.fn(),
135
- } as never,
136
- appId: "app",
137
- conversationRef: {
138
- conversation: { id: "conv", conversationType },
139
- user: { id: "user" },
140
- agent: { id: "bot" },
141
- channelId: "msteams",
142
- serviceUrl: "https://service.example.com",
143
- } as never,
144
- context: {
145
- sendActivity: contextSendActivity,
146
- } as never,
147
- replyStyle: "thread",
148
- textLimit: 4000,
149
- ...extraParams,
150
- });
151
- lastCreatedDispatcher = dispatcher;
152
- return dispatcher;
153
- }
154
-
155
- function getContextSendActivity(): ReturnType<typeof vi.fn> {
156
- if (!lastContextSendActivity) {
157
- throw new Error("createDispatcher must be called first");
158
- }
159
- return lastContextSendActivity;
160
- }
161
-
162
- type DispatcherOptions = {
163
- onReplyStart?: () => Promise<void> | void;
164
- deliver: (payload: { text: string }) => Promise<void> | void;
165
- };
166
-
167
- type PipelineArgs = {
168
- typing?: {
169
- keepaliveIntervalMs?: number;
170
- maxDurationMs?: number;
171
- start?: () => Promise<void>;
172
- };
173
- };
174
-
175
- function dispatcherOptions(): DispatcherOptions {
176
- const [call] = createReplyDispatcherWithTypingMock.mock.calls;
177
- if (!call) {
178
- throw new Error("expected reply dispatcher factory call");
179
- }
180
- return call[0] as DispatcherOptions;
181
- }
182
-
183
- function pipelineArgs(): PipelineArgs {
184
- const [call] = createChannelMessageReplyPipelineMock.mock.calls;
185
- if (!call) {
186
- throw new Error("expected reply pipeline factory call");
187
- }
188
- return call[0] as PipelineArgs;
189
- }
190
-
191
- function pipelineTypingStart(): () => Promise<void> {
192
- const sendTyping = pipelineArgs().typing?.start;
193
- if (typeof sendTyping !== "function") {
194
- throw new Error("expected typing start callback");
195
- }
196
- return sendTyping;
197
- }
198
-
199
- function firstSystemEventCall(): [string, unknown] {
200
- const [call] = enqueueSystemEventMock.mock.calls;
201
- if (!call) {
202
- throw new Error("expected system event call");
203
- }
204
- return call as [string, unknown];
205
- }
206
-
207
- async function triggerPartialReply(text: string): Promise<void> {
208
- if (!lastCreatedDispatcher) {
209
- throw new Error("createDispatcher must be called first");
210
- }
211
- lastCreatedDispatcher.replyOptions.onPartialReply?.({ text });
212
- }
213
-
214
- it("sends an informative status update once work expands in personal chats", async () => {
215
- const dispatcher = createDispatcher("personal", { streaming: { mode: "progress" } });
216
- const options = dispatcherOptions();
217
-
218
- await options.onReplyStart?.();
219
- await dispatcher.replyOptions.onToolStart?.({ name: "exec" });
220
- await dispatcher.replyOptions.onItemEvent?.({ progressText: "done" });
221
-
222
- expect(streamInstances).toHaveLength(1);
223
- expect(streamInstances[0]?.sendInformativeUpdate).toHaveBeenCalledTimes(1);
224
- });
225
-
226
- it("starts the typing keepalive in personal chats so the TurnContext survives long tool chains", async () => {
227
- createDispatcher("personal");
228
- const options = dispatcherOptions();
229
-
230
- await options.onReplyStart?.();
231
-
232
- // In addition to the streaming card's informative update, the typing
233
- // keepalive is now started on personal chats so Bot Framework proxies
234
- // stay alive during long tool chains (#59731).
235
- expect(typingCallbacks.onReplyStart).toHaveBeenCalledTimes(1);
236
- });
237
-
238
- it("skips the typing keepalive in personal chats when typingIndicator=false", async () => {
239
- createDispatcher("personal", { typingIndicator: false });
240
- const options = dispatcherOptions();
241
-
242
- await options.onReplyStart?.();
243
-
244
- expect(streamInstances[0]?.sendInformativeUpdate).not.toHaveBeenCalled();
245
- expect(typingCallbacks.onReplyStart).not.toHaveBeenCalled();
246
- });
247
-
248
- it("passes a longer keepalive TTL so the loop survives long tool chains", () => {
249
- createDispatcher("personal");
250
-
251
- const args = pipelineArgs();
252
- expect(args.typing?.keepaliveIntervalMs).toBeGreaterThan(3_000);
253
- expect(args.typing?.keepaliveIntervalMs).toBeLessThanOrEqual(10_000);
254
- // Issue #59731 reports 60s+ tool chains — the default 60s TTL is too
255
- // tight so the dispatcher passes its own generous ceiling.
256
- expect(args.typing?.maxDurationMs).toBeGreaterThanOrEqual(300_000);
257
- });
258
-
259
- it("allows typing keepalive sends before any stream tokens arrive", async () => {
260
- createDispatcher("personal");
261
- const sendTyping = pipelineTypingStart();
262
-
263
- // No onPartialReply has been called yet, so the stream is not active.
264
- // The typing keepalive should be allowed to warm the TurnContext.
265
- const contextSendActivity = getContextSendActivity();
266
- contextSendActivity.mockClear();
267
- await sendTyping();
268
- expect(contextSendActivity).toHaveBeenCalledWith({ type: "typing" });
269
- });
270
-
271
- it("suppresses typing keepalive sends while the stream card is actively chunking", async () => {
272
- createDispatcher("personal");
273
- const sendTyping = pipelineTypingStart();
274
-
275
- // Simulate the stream actively receiving a partial chunk. While the
276
- // stream card is live we do not want a plain "..." typing indicator
277
- // layered on top of it.
278
- await triggerPartialReply("streaming content");
279
-
280
- const contextSendActivity = getContextSendActivity();
281
- contextSendActivity.mockClear();
282
- await sendTyping();
283
- expect(contextSendActivity).not.toHaveBeenCalled();
284
- });
285
-
286
- it("resumes typing keepalive sends once the stream finalizes between tool rounds", async () => {
287
- createDispatcher("personal");
288
- const sendTyping = pipelineTypingStart();
289
-
290
- // First segment: tokens flow, stream is active, typing is gated off.
291
- await triggerPartialReply("first segment tokens");
292
- const stream = streamInstances[0];
293
- if (!stream) {
294
- throw new Error("expected a Teams stream instance to be created");
295
- }
296
- const contextSendActivity = getContextSendActivity();
297
- contextSendActivity.mockClear();
298
- await sendTyping();
299
- expect(contextSendActivity).not.toHaveBeenCalled();
300
-
301
- // First segment complete: the stream is finalized ahead of the tool
302
- // chain. Mirror what preparePayload does by flipping the mocked stream's
303
- // finalized flag. The controller's isStreamActive check reads this via
304
- // the real stream controller wired into the dispatcher.
305
- stream.isFinalized = true;
306
-
307
- // During the tool chain the loop should be allowed to fire again so
308
- // the Bot Framework proxy stays warm. See #59731.
309
- contextSendActivity.mockClear();
310
- await sendTyping();
311
- expect(contextSendActivity).toHaveBeenCalledWith({ type: "typing" });
312
- });
313
-
314
- it("fires native typing in group chats (no stream) because the gate never applies", async () => {
315
- createDispatcher("groupchat");
316
- const sendTyping = pipelineTypingStart();
317
-
318
- // In group chats we don't create a stream, so isStreamActive() always
319
- // returns false and the typing indicator still fires normally.
320
- const contextSendActivity = getContextSendActivity();
321
- contextSendActivity.mockClear();
322
- await sendTyping();
323
- expect(contextSendActivity).toHaveBeenCalledWith({ type: "typing" });
324
- });
325
-
326
- it("is a no-op for channel conversations (typing unsupported)", async () => {
327
- createDispatcher("channel");
328
- const sendTyping = pipelineTypingStart();
329
-
330
- const contextSendActivity = getContextSendActivity();
331
- contextSendActivity.mockClear();
332
- await sendTyping();
333
- // Teams channel conversations do not support the typing activity at
334
- // all, so the start callback is a no-op regardless of stream state.
335
- expect(contextSendActivity).not.toHaveBeenCalled();
336
- });
337
-
338
- it("sends native typing indicator for channel conversations by default", async () => {
339
- createDispatcher("channel");
340
- const options = dispatcherOptions();
341
-
342
- await options.onReplyStart?.();
343
-
344
- expect(streamInstances).toHaveLength(0);
345
- expect(typingCallbacks.onReplyStart).toHaveBeenCalledTimes(1);
346
- });
347
-
348
- it("skips native typing indicator when typingIndicator=false", async () => {
349
- createDispatcher("channel", { typingIndicator: false });
350
- const options = dispatcherOptions();
351
-
352
- await options.onReplyStart?.();
353
-
354
- expect(typingCallbacks.onReplyStart).not.toHaveBeenCalled();
355
- });
356
-
357
- it("delays the informative status update until work expands", async () => {
358
- const dispatcher = createDispatcher("personal", { streaming: { mode: "progress" } });
359
-
360
- await dispatcher.replyOptions.onToolStart?.({ name: "exec" });
361
- expect(streamInstances[0]?.sendInformativeUpdate).not.toHaveBeenCalled();
362
-
363
- await dispatcher.replyOptions.onItemEvent?.({ progressText: "done" });
364
- await dispatcher.replyOptions.onPatchSummary?.({ phase: "end", summary: "patched" });
365
-
366
- expect(streamInstances[0]?.sendInformativeUpdate).toHaveBeenCalledTimes(2);
367
- });
368
-
369
- it("forwards partial replies into the Teams stream", () => {
370
- const dispatcher = createDispatcher("personal");
371
-
372
- dispatcher.replyOptions.onPartialReply?.({ text: "partial response" });
373
-
374
- expect(streamInstances[0]?.update).toHaveBeenCalledWith("partial response");
375
- });
376
-
377
- it("surfaces Teams progress tool lines through native stream updates", async () => {
378
- const dispatcher = createDispatcher("personal", {
379
- streaming: {
380
- mode: "progress",
381
- progress: {
382
- label: "Working",
383
- },
384
- },
385
- });
386
-
387
- expect(dispatcher.replyOptions.suppressDefaultToolProgressMessages).toBe(true);
388
- await dispatcher.replyOptions.onToolStart?.({ name: "web_search" });
389
- expect(streamInstances[0]?.sendInformativeUpdate).not.toHaveBeenCalled();
390
-
391
- await dispatcher.replyOptions.onToolStart?.({ name: "exec" });
392
-
393
- expect(streamInstances[0]?.sendInformativeUpdate).toHaveBeenCalledWith(
394
- "Working\n🔎 Web Search\n🛠️ Exec",
395
- );
396
- });
397
-
398
- it("suppresses standalone Teams progress messages when progress tool lines are disabled", async () => {
399
- const dispatcher = createDispatcher("personal", {
400
- streaming: {
401
- mode: "progress",
402
- progress: {
403
- toolProgress: false,
404
- },
405
- },
406
- });
407
-
408
- expect(dispatcher.replyOptions.suppressDefaultToolProgressMessages).toBe(true);
409
- await dispatcher.replyOptions.onToolStart?.({ name: "web_search" });
410
- expect(streamInstances[0]?.sendInformativeUpdate).not.toHaveBeenCalled();
411
-
412
- await dispatcher.replyOptions.onToolStart?.({ name: "exec" });
413
-
414
- expect(streamInstances[0]?.sendInformativeUpdate).toHaveBeenCalledWith(
415
- pickInformativeStatusText({ seed: "default:conv" }),
416
- );
417
- });
418
-
419
- it("does not create a stream for channel conversations", () => {
420
- createDispatcher("channel");
421
-
422
- expect(streamInstances).toHaveLength(0);
423
- });
424
-
425
- it("sets disableBlockStreaming=false when blockStreaming=true", () => {
426
- const dispatcher = createDispatcher("personal", { blockStreaming: true });
427
-
428
- expect(dispatcher.replyOptions.disableBlockStreaming).toBe(false);
429
- });
430
-
431
- it("maps streaming.mode=block to block delivery without native Teams streaming", async () => {
432
- renderReplyPayloadsToMessagesMock.mockReturnValue([{ content: "hello" }] as never);
433
- sendMSTeamsMessagesMock.mockResolvedValue(["id-1"] as never);
434
-
435
- const dispatcher = createDispatcher("personal", { streaming: { mode: "block" } });
436
- const options = dispatcherOptions();
437
-
438
- await options.deliver({ text: "block content" });
439
-
440
- expect(streamInstances).toHaveLength(0);
441
- expect(dispatcher.replyOptions.onPartialReply).toBeUndefined();
442
- expect(dispatcher.replyOptions.disableBlockStreaming).toBe(false);
443
- expect(sendMSTeamsMessagesMock).toHaveBeenCalledTimes(1);
444
- });
445
-
446
- it("sets disableBlockStreaming=true when blockStreaming=false", () => {
447
- const dispatcher = createDispatcher("personal", { blockStreaming: false });
448
-
449
- expect(dispatcher.replyOptions.disableBlockStreaming).toBe(true);
450
- });
451
-
452
- it("leaves disableBlockStreaming undefined when blockStreaming is not set", () => {
453
- const dispatcher = createDispatcher("personal", {});
454
-
455
- expect(dispatcher.replyOptions.disableBlockStreaming).toBeUndefined();
456
- });
457
-
458
- it("flushes messages immediately on deliver when blockStreaming is enabled", async () => {
459
- renderReplyPayloadsToMessagesMock.mockReturnValue([{ content: "hello" }] as never);
460
- sendMSTeamsMessagesMock.mockResolvedValue(["id-1"] as never);
461
-
462
- createDispatcher("personal", { blockStreaming: true });
463
- const options = dispatcherOptions();
464
-
465
- // Call deliver — with blockStreaming enabled it should flush immediately
466
- await options.deliver({ text: "block content" });
467
-
468
- expect(sendMSTeamsMessagesMock).toHaveBeenCalledTimes(1);
469
- });
470
-
471
- it("does not flush messages on deliver when blockStreaming is disabled", async () => {
472
- renderReplyPayloadsToMessagesMock.mockReturnValue([{ content: "hello" }] as never);
473
-
474
- createDispatcher("personal", { blockStreaming: false });
475
- const options = dispatcherOptions();
476
-
477
- await options.deliver({ text: "block content" });
478
-
479
- expect(sendMSTeamsMessagesMock).not.toHaveBeenCalled();
480
- });
481
-
482
- it("queues a system event when some queued Teams messages fail to send", async () => {
483
- const onSentMessageIds = vi.fn();
484
- renderReplyPayloadsToMessagesMock.mockReturnValue([
485
- { content: "one" },
486
- { content: "two" },
487
- ] as never);
488
- sendMSTeamsMessagesMock
489
- .mockRejectedValueOnce(Object.assign(new Error("gateway timeout"), { statusCode: 502 }))
490
- .mockResolvedValueOnce(["id-1"] as never)
491
- .mockRejectedValueOnce(Object.assign(new Error("gateway timeout"), { statusCode: 502 }));
492
-
493
- const dispatcher = createDispatcher(
494
- "personal",
495
- { blockStreaming: false },
496
- { onSentMessageIds },
497
- );
498
- const options = dispatcherOptions();
499
-
500
- await options.deliver({ text: "block content" });
501
- await dispatcher.markDispatchIdle();
502
-
503
- expect(onSentMessageIds).toHaveBeenCalledWith(["id-1"]);
504
- expect(enqueueSystemEventMock).toHaveBeenCalledTimes(1);
505
- const [message, context] = firstSystemEventCall();
506
- expect(message).toContain("Microsoft Teams delivery failed");
507
- expect(message).toContain("1 of 2 message blocks were not delivered");
508
- expect(message).toContain("The user may not have received the full reply");
509
- expect(message).toContain("Error: Error: gateway timeout.");
510
- expect(context).toEqual({
511
- sessionKey: "agent:main:main",
512
- contextKey: "msteams:delivery-failure:conv",
513
- });
514
- });
515
-
516
- it("does not queue a delivery-failure system event when Teams send succeeds", async () => {
517
- renderReplyPayloadsToMessagesMock.mockReturnValue([{ content: "hello" }] as never);
518
- sendMSTeamsMessagesMock.mockResolvedValue(["id-1"] as never);
519
-
520
- const dispatcher = createDispatcher("personal", { blockStreaming: false });
521
- const options = dispatcherOptions();
522
-
523
- await options.deliver({ text: "block content" });
524
- await dispatcher.markDispatchIdle();
525
-
526
- expect(enqueueSystemEventMock).not.toHaveBeenCalled();
527
- });
528
- });
529
-
530
- describe("pickInformativeStatusText", () => {
531
- it("selects a deterministic status line for a fixed random source", () => {
532
- expect(pickInformativeStatusText(() => 0)).toBe("Thinking...");
533
- expect(pickInformativeStatusText(() => 0.99)).toBe("Surfacing...");
534
- });
535
-
536
- it("honors disabled progress labels", () => {
537
- expect(
538
- pickInformativeStatusText({
539
- config: { streaming: { progress: { label: false } } } as never,
540
- }),
541
- ).toBeUndefined();
542
- });
543
- });