@kodelyth/msteams 2026.5.39 → 2026.5.42
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.
- package/api.ts +3 -0
- package/channel-config-api.ts +1 -0
- package/channel-plugin-api.ts +2 -0
- package/config-api.ts +4 -0
- package/contract-api.ts +4 -0
- package/dist/api.js +3 -0
- package/dist/channel-BvTXHuGs.js +1161 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-NssGKZm5.js +650 -0
- package/dist/config-schema-Btk-XCOd.js +43 -0
- package/dist/contract-api.js +2 -0
- package/dist/graph-users-D-gKCguI.js +1411 -0
- package/dist/index.js +22 -0
- package/dist/oauth-BUxlphX3.js +114 -0
- package/dist/oauth.token-ebId9946.js +116 -0
- package/dist/probe-Cj2KsAGF.js +2190 -0
- package/dist/runtime-api-BL4DOWXD.js +28 -0
- package/dist/runtime-api.js +2 -0
- package/dist/secret-contract-Bo7kdUrT.js +35 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/setup-plugin-api.js +64 -0
- package/dist/setup-surface-COTQDcTQ.js +531 -0
- package/dist/src-tvpsGYPV.js +4226 -0
- package/dist/test-api.js +2 -0
- package/index.ts +20 -0
- package/klaw.plugin.json +2 -726
- package/package.json +4 -4
- package/runtime-api.ts +66 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +13 -0
- package/setup-plugin-api.ts +3 -0
- package/src/ai-entity.ts +7 -0
- package/src/approval-auth.ts +44 -0
- package/src/attachments/bot-framework.test.ts +506 -0
- package/src/attachments/bot-framework.ts +348 -0
- package/src/attachments/download.ts +328 -0
- package/src/attachments/graph.test.ts +441 -0
- package/src/attachments/graph.ts +489 -0
- package/src/attachments/html.ts +122 -0
- package/src/attachments/payload.ts +14 -0
- package/src/attachments/remote-media.test.ts +187 -0
- package/src/attachments/remote-media.ts +86 -0
- package/src/attachments/shared.test.ts +547 -0
- package/src/attachments/shared.ts +655 -0
- package/src/attachments/types.ts +47 -0
- package/src/attachments.graph.test.ts +414 -0
- package/src/attachments.helpers.test.ts +245 -0
- package/src/attachments.test-helpers.ts +17 -0
- package/src/attachments.test.ts +754 -0
- package/src/attachments.ts +18 -0
- package/src/block-streaming-config.test.ts +61 -0
- package/src/channel-api.ts +1 -0
- package/src/channel.actions.test.ts +797 -0
- package/src/channel.directory.test.ts +176 -0
- package/src/channel.message-adapter.test.ts +227 -0
- package/src/channel.runtime.ts +56 -0
- package/src/channel.setup.ts +77 -0
- package/src/channel.test.ts +136 -0
- package/src/channel.ts +1176 -0
- package/src/config-schema.ts +6 -0
- package/src/config-ui-hints.ts +40 -0
- package/src/conversation-store-fs.test.ts +81 -0
- package/src/conversation-store-fs.ts +149 -0
- package/src/conversation-store-helpers.test.ts +202 -0
- package/src/conversation-store-helpers.ts +105 -0
- package/src/conversation-store-memory.ts +51 -0
- package/src/conversation-store.shared.test.ts +260 -0
- package/src/conversation-store.ts +71 -0
- package/src/directory-live.test.ts +156 -0
- package/src/directory-live.ts +111 -0
- package/src/doctor.ts +27 -0
- package/src/errors.test.ts +154 -0
- package/src/errors.ts +270 -0
- package/src/feedback-reflection-prompt.ts +117 -0
- package/src/feedback-reflection-store.ts +113 -0
- package/src/feedback-reflection.test.ts +237 -0
- package/src/feedback-reflection.ts +268 -0
- package/src/file-consent-helpers.test.ts +328 -0
- package/src/file-consent-helpers.ts +115 -0
- package/src/file-consent-invoke.ts +150 -0
- package/src/file-consent.test.ts +378 -0
- package/src/file-consent.ts +223 -0
- package/src/graph-chat.ts +36 -0
- package/src/graph-group-management.test.ts +332 -0
- package/src/graph-group-management.ts +168 -0
- package/src/graph-members.test.ts +89 -0
- package/src/graph-members.ts +48 -0
- package/src/graph-messages.actions.test.ts +253 -0
- package/src/graph-messages.read.test.ts +391 -0
- package/src/graph-messages.search.test.ts +227 -0
- package/src/graph-messages.test-helpers.ts +50 -0
- package/src/graph-messages.ts +534 -0
- package/src/graph-teams.test.ts +222 -0
- package/src/graph-teams.ts +114 -0
- package/src/graph-thread.test.ts +252 -0
- package/src/graph-thread.ts +146 -0
- package/src/graph-upload.test.ts +253 -0
- package/src/graph-upload.ts +531 -0
- package/src/graph-users.ts +29 -0
- package/src/graph.test.ts +540 -0
- package/src/graph.ts +308 -0
- package/src/inbound.test.ts +221 -0
- package/src/inbound.ts +148 -0
- package/src/index.ts +4 -0
- package/src/media-helpers.test.ts +220 -0
- package/src/media-helpers.ts +105 -0
- package/src/mentions.test.ts +254 -0
- package/src/mentions.ts +114 -0
- package/src/messenger.test.ts +961 -0
- package/src/messenger.ts +608 -0
- package/src/monitor-handler/access.ts +136 -0
- package/src/monitor-handler/inbound-media.test.ts +314 -0
- package/src/monitor-handler/inbound-media.ts +180 -0
- package/src/monitor-handler/message-handler-mock-support.test-support.ts +28 -0
- package/src/monitor-handler/message-handler.authz.test.ts +739 -0
- package/src/monitor-handler/message-handler.dm-media.test.ts +54 -0
- package/src/monitor-handler/message-handler.test-support.ts +99 -0
- package/src/monitor-handler/message-handler.thread-parent.test.ts +225 -0
- package/src/monitor-handler/message-handler.thread-session.test.ts +132 -0
- package/src/monitor-handler/message-handler.ts +1003 -0
- package/src/monitor-handler/reaction-handler.test.ts +325 -0
- package/src/monitor-handler/reaction-handler.ts +122 -0
- package/src/monitor-handler/thread-session.ts +30 -0
- package/src/monitor-handler.adaptive-card.test.ts +158 -0
- package/src/monitor-handler.feedback-authz.test.ts +357 -0
- package/src/monitor-handler.file-consent.test.ts +443 -0
- package/src/monitor-handler.sso.test.ts +576 -0
- package/src/monitor-handler.test-helpers.ts +181 -0
- package/src/monitor-handler.ts +538 -0
- package/src/monitor-handler.types.ts +27 -0
- package/src/monitor-types.ts +6 -0
- package/src/monitor.lifecycle.test.ts +457 -0
- package/src/monitor.test.ts +119 -0
- package/src/monitor.ts +476 -0
- package/src/oauth.flow.ts +77 -0
- package/src/oauth.shared.ts +37 -0
- package/src/oauth.test.ts +350 -0
- package/src/oauth.token.ts +162 -0
- package/src/oauth.ts +130 -0
- package/src/outbound.test.ts +400 -0
- package/src/outbound.ts +198 -0
- package/src/pending-uploads-fs.test.ts +261 -0
- package/src/pending-uploads-fs.ts +235 -0
- package/src/pending-uploads.test.ts +186 -0
- package/src/pending-uploads.ts +121 -0
- package/src/policy.test.ts +156 -0
- package/src/policy.ts +245 -0
- package/src/polls-store-memory.ts +32 -0
- package/src/polls.test.ts +169 -0
- package/src/polls.ts +312 -0
- package/src/presentation.ts +93 -0
- package/src/probe.test.ts +79 -0
- package/src/probe.ts +132 -0
- package/src/reply-dispatcher.test.ts +543 -0
- package/src/reply-dispatcher.ts +523 -0
- package/src/reply-stream-controller.test.ts +424 -0
- package/src/reply-stream-controller.ts +334 -0
- package/src/resolve-allowlist.test.ts +253 -0
- package/src/resolve-allowlist.ts +309 -0
- package/src/revoked-context.ts +17 -0
- package/src/runtime.ts +12 -0
- package/src/sdk-types.ts +59 -0
- package/src/sdk.test.ts +727 -0
- package/src/sdk.ts +916 -0
- package/src/secret-contract.ts +49 -0
- package/src/secret-input.ts +7 -0
- package/src/send-context.test.ts +93 -0
- package/src/send-context.ts +269 -0
- package/src/send.test.ts +588 -0
- package/src/send.ts +697 -0
- package/src/sent-message-cache.test.ts +106 -0
- package/src/sent-message-cache.ts +174 -0
- package/src/session-route.ts +40 -0
- package/src/setup-core.ts +162 -0
- package/src/setup-surface.test.ts +175 -0
- package/src/setup-surface.ts +319 -0
- package/src/sso-token-store.test.ts +74 -0
- package/src/sso-token-store.ts +166 -0
- package/src/sso.ts +300 -0
- package/src/storage.ts +25 -0
- package/src/store-fs.ts +42 -0
- package/src/streaming-message.test.ts +323 -0
- package/src/streaming-message.ts +327 -0
- package/src/test-runtime.ts +16 -0
- package/src/thread-parent-context.test.ts +224 -0
- package/src/thread-parent-context.ts +159 -0
- package/src/token-response.ts +11 -0
- package/src/token.test.ts +268 -0
- package/src/token.ts +194 -0
- package/src/user-agent.test.ts +121 -0
- package/src/user-agent.ts +53 -0
- package/src/webhook-timeouts.ts +27 -0
- package/src/welcome-card.test.ts +104 -0
- package/src/welcome-card.ts +57 -0
- package/test-api.ts +1 -0
- package/tsconfig.json +16 -0
- package/api.js +0 -7
- package/channel-config-api.js +0 -7
- package/channel-plugin-api.js +0 -7
- package/contract-api.js +0 -7
- package/index.js +0 -7
- package/runtime-api.js +0 -7
- package/secret-contract-api.js +0 -7
- package/setup-entry.js +0 -7
- package/setup-plugin-api.js +0 -7
- package/test-api.js +0 -7
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const streamInstances = vi.hoisted(
|
|
4
|
+
() =>
|
|
5
|
+
[] as Array<{
|
|
6
|
+
hasContent: boolean;
|
|
7
|
+
isFinalized: boolean;
|
|
8
|
+
isFailed: boolean;
|
|
9
|
+
streamedLength: number;
|
|
10
|
+
messageId?: string;
|
|
11
|
+
previewStreamId?: string;
|
|
12
|
+
sendInformativeUpdate: ReturnType<typeof vi.fn>;
|
|
13
|
+
update: ReturnType<typeof vi.fn>;
|
|
14
|
+
replaceInformativeWithFinal: ReturnType<typeof vi.fn>;
|
|
15
|
+
finalize: ReturnType<typeof vi.fn>;
|
|
16
|
+
}>,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
vi.mock("./streaming-message.js", () => ({
|
|
20
|
+
TeamsHttpStream: class {
|
|
21
|
+
hasContent = false;
|
|
22
|
+
isFinalized = false;
|
|
23
|
+
isFailed = false;
|
|
24
|
+
streamedLength = 0;
|
|
25
|
+
messageId: string | undefined;
|
|
26
|
+
previewStreamId = "preview-stream";
|
|
27
|
+
sendInformativeUpdate = vi.fn(async () => {});
|
|
28
|
+
update = vi.fn(function (
|
|
29
|
+
this: { hasContent: boolean; isFailed: boolean; streamedLength: number },
|
|
30
|
+
payloadText?: string,
|
|
31
|
+
) {
|
|
32
|
+
if ((payloadText?.length ?? 0) > 4000) {
|
|
33
|
+
this.hasContent = false;
|
|
34
|
+
this.isFailed = true;
|
|
35
|
+
this.streamedLength = 0;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.hasContent = true;
|
|
39
|
+
this.streamedLength = payloadText?.length ?? 0;
|
|
40
|
+
});
|
|
41
|
+
replaceInformativeWithFinal = vi.fn(async function (
|
|
42
|
+
this: {
|
|
43
|
+
hasContent: boolean;
|
|
44
|
+
isFailed: boolean;
|
|
45
|
+
isFinalized: boolean;
|
|
46
|
+
streamedLength: number;
|
|
47
|
+
messageId?: string;
|
|
48
|
+
update: (payloadText?: string) => void;
|
|
49
|
+
},
|
|
50
|
+
payloadText: string,
|
|
51
|
+
) {
|
|
52
|
+
this.update(payloadText);
|
|
53
|
+
if (this.isFailed) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
this.isFinalized = true;
|
|
57
|
+
this.messageId = "final-message";
|
|
58
|
+
return this.hasContent;
|
|
59
|
+
});
|
|
60
|
+
finalize = vi.fn(async function (this: { isFinalized: boolean; messageId?: string }) {
|
|
61
|
+
this.isFinalized = true;
|
|
62
|
+
this.messageId = "final-message";
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
constructor() {
|
|
66
|
+
streamInstances.push(this as never);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
import { createTeamsReplyStreamController } from "./reply-stream-controller.js";
|
|
72
|
+
|
|
73
|
+
describe("createTeamsReplyStreamController", () => {
|
|
74
|
+
function createController() {
|
|
75
|
+
streamInstances.length = 0;
|
|
76
|
+
return createTeamsReplyStreamController({
|
|
77
|
+
conversationType: "personal",
|
|
78
|
+
context: { sendActivity: vi.fn(async () => ({ id: "a" })) } as never,
|
|
79
|
+
feedbackLoopEnabled: false,
|
|
80
|
+
log: { debug: vi.fn() } as never,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
it("suppresses fallback for first text segment that was streamed", async () => {
|
|
85
|
+
const ctrl = createController();
|
|
86
|
+
ctrl.onPartialReply({ text: "Hello world" });
|
|
87
|
+
|
|
88
|
+
const result = await ctrl.preparePayload({ text: "Hello world" });
|
|
89
|
+
expect(result).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("when stream fails after partial delivery, fallback sends only remaining text", async () => {
|
|
93
|
+
const ctrl = createController();
|
|
94
|
+
const fullText = "a".repeat(4000) + "b".repeat(200);
|
|
95
|
+
|
|
96
|
+
ctrl.onPartialReply({ text: fullText });
|
|
97
|
+
streamInstances[0].hasContent = false;
|
|
98
|
+
streamInstances[0].isFailed = true;
|
|
99
|
+
streamInstances[0].isFinalized = true;
|
|
100
|
+
streamInstances[0].streamedLength = 4000;
|
|
101
|
+
|
|
102
|
+
const result = await ctrl.preparePayload({ text: fullText });
|
|
103
|
+
expect(result).toEqual({ text: "b".repeat(200) });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("when stream fails before sending content, fallback sends full text", async () => {
|
|
107
|
+
const ctrl = createController();
|
|
108
|
+
const fullText = "Failure at first chunk";
|
|
109
|
+
|
|
110
|
+
ctrl.onPartialReply({ text: fullText });
|
|
111
|
+
streamInstances[0].hasContent = false;
|
|
112
|
+
streamInstances[0].isFailed = true;
|
|
113
|
+
streamInstances[0].isFinalized = true;
|
|
114
|
+
streamInstances[0].streamedLength = 0;
|
|
115
|
+
|
|
116
|
+
const result = await ctrl.preparePayload({ text: fullText });
|
|
117
|
+
expect(result).toEqual({ text: fullText });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("allows fallback delivery for second text segment after tool calls", async () => {
|
|
121
|
+
const ctrl = createController();
|
|
122
|
+
|
|
123
|
+
// First text segment: streaming tokens arrive
|
|
124
|
+
ctrl.onPartialReply({ text: "First segment" });
|
|
125
|
+
|
|
126
|
+
// First segment complete: preparePayload suppresses (stream handled it)
|
|
127
|
+
const result1 = await ctrl.preparePayload({ text: "First segment" });
|
|
128
|
+
expect(result1).toBeUndefined();
|
|
129
|
+
|
|
130
|
+
// Tool calls happen... then second text segment arrives via deliver()
|
|
131
|
+
// preparePayload should allow fallback delivery for this segment
|
|
132
|
+
const result2 = await ctrl.preparePayload({ text: "Second segment after tools" });
|
|
133
|
+
expect(result2).toEqual({ text: "Second segment after tools" });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("finalizes the stream when suppressing first segment", async () => {
|
|
137
|
+
const ctrl = createController();
|
|
138
|
+
ctrl.onPartialReply({ text: "Streamed text" });
|
|
139
|
+
|
|
140
|
+
await ctrl.preparePayload({ text: "Streamed text" });
|
|
141
|
+
await ctrl.finalize();
|
|
142
|
+
|
|
143
|
+
expect(streamInstances[0]?.finalize).toHaveBeenCalled();
|
|
144
|
+
expect(ctrl.liveState().phase).toBe("finalized");
|
|
145
|
+
expect(ctrl.liveState().receipt?.primaryPlatformMessageId).toBe("final-message");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("uses fallback even when onPartialReply fires after stream finalized", async () => {
|
|
149
|
+
const ctrl = createController();
|
|
150
|
+
|
|
151
|
+
// First text segment: streaming tokens arrive
|
|
152
|
+
ctrl.onPartialReply({ text: "First segment" });
|
|
153
|
+
|
|
154
|
+
// First segment complete: preparePayload suppresses and finalizes stream
|
|
155
|
+
const result1 = await ctrl.preparePayload({ text: "First segment" });
|
|
156
|
+
expect(result1).toBeUndefined();
|
|
157
|
+
expect(streamInstances[0]?.isFinalized).toBe(true);
|
|
158
|
+
|
|
159
|
+
// Post-tool partial replies fire again (stream.update is a no-op since finalized)
|
|
160
|
+
ctrl.onPartialReply({ text: "Second segment" });
|
|
161
|
+
|
|
162
|
+
// Must still use fallback because stream is finalized and can't deliver
|
|
163
|
+
const result2 = await ctrl.preparePayload({ text: "Second segment" });
|
|
164
|
+
expect(result2).toEqual({ text: "Second segment" });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("delivers all segments across 3+ tool call rounds", async () => {
|
|
168
|
+
const ctrl = createController();
|
|
169
|
+
|
|
170
|
+
// Round 1: text → tool
|
|
171
|
+
ctrl.onPartialReply({ text: "Segment 1" });
|
|
172
|
+
await expect(ctrl.preparePayload({ text: "Segment 1" })).resolves.toBeUndefined();
|
|
173
|
+
|
|
174
|
+
// Round 2: text → tool
|
|
175
|
+
ctrl.onPartialReply({ text: "Segment 2" });
|
|
176
|
+
const r2 = await ctrl.preparePayload({ text: "Segment 2" });
|
|
177
|
+
expect(r2).toEqual({ text: "Segment 2" });
|
|
178
|
+
|
|
179
|
+
// Round 3: final text
|
|
180
|
+
ctrl.onPartialReply({ text: "Segment 3" });
|
|
181
|
+
const r3 = await ctrl.preparePayload({ text: "Segment 3" });
|
|
182
|
+
expect(r3).toEqual({ text: "Segment 3" });
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("passes media+text payload through fully after stream finalized", async () => {
|
|
186
|
+
const ctrl = createController();
|
|
187
|
+
|
|
188
|
+
// First segment streamed and finalized
|
|
189
|
+
ctrl.onPartialReply({ text: "Streamed text" });
|
|
190
|
+
await ctrl.preparePayload({ text: "Streamed text" });
|
|
191
|
+
|
|
192
|
+
// Second segment has both text and media — should pass through fully
|
|
193
|
+
const result = await ctrl.preparePayload({
|
|
194
|
+
text: "Post-tool text with image",
|
|
195
|
+
mediaUrl: "https://example.com/tool-output.png",
|
|
196
|
+
});
|
|
197
|
+
expect(result).toEqual({
|
|
198
|
+
text: "Post-tool text with image",
|
|
199
|
+
mediaUrl: "https://example.com/tool-output.png",
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("still strips text from media payloads when stream handled text", async () => {
|
|
204
|
+
const ctrl = createController();
|
|
205
|
+
ctrl.onPartialReply({ text: "Some text" });
|
|
206
|
+
|
|
207
|
+
const result = await ctrl.preparePayload({
|
|
208
|
+
text: "Some text",
|
|
209
|
+
mediaUrl: "https://example.com/image.png",
|
|
210
|
+
});
|
|
211
|
+
expect(result).toEqual({
|
|
212
|
+
text: undefined,
|
|
213
|
+
mediaUrl: "https://example.com/image.png",
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("falls back to normal delivery when progress final streaming fails", async () => {
|
|
218
|
+
streamInstances.length = 0;
|
|
219
|
+
const ctrl = createTeamsReplyStreamController({
|
|
220
|
+
conversationType: "personal",
|
|
221
|
+
context: { sendActivity: vi.fn(async () => ({ id: "a" })) } as never,
|
|
222
|
+
feedbackLoopEnabled: false,
|
|
223
|
+
log: { debug: vi.fn() } as never,
|
|
224
|
+
msteamsConfig: { streaming: { mode: "progress" } } as never,
|
|
225
|
+
});
|
|
226
|
+
await ctrl.noteProgressWork({ toolName: "exec" });
|
|
227
|
+
await ctrl.noteProgressWork();
|
|
228
|
+
const fullText = "x".repeat(4200);
|
|
229
|
+
|
|
230
|
+
const result = await ctrl.preparePayload({ text: fullText });
|
|
231
|
+
|
|
232
|
+
expect(result).toEqual({ text: fullText });
|
|
233
|
+
expect(streamInstances[0]?.replaceInformativeWithFinal).toHaveBeenCalledWith(fullText);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("records lifecycle receipt when progress final streaming succeeds", async () => {
|
|
237
|
+
streamInstances.length = 0;
|
|
238
|
+
const ctrl = createTeamsReplyStreamController({
|
|
239
|
+
conversationType: "personal",
|
|
240
|
+
context: { sendActivity: vi.fn(async () => ({ id: "a" })) } as never,
|
|
241
|
+
feedbackLoopEnabled: false,
|
|
242
|
+
log: { debug: vi.fn() } as never,
|
|
243
|
+
msteamsConfig: { streaming: { mode: "progress" } } as never,
|
|
244
|
+
});
|
|
245
|
+
await ctrl.noteProgressWork({ toolName: "exec" });
|
|
246
|
+
await ctrl.noteProgressWork();
|
|
247
|
+
|
|
248
|
+
await expect(ctrl.preparePayload({ text: "complete final answer" })).resolves.toBeUndefined();
|
|
249
|
+
|
|
250
|
+
expect(ctrl.liveState().phase).toBe("finalized");
|
|
251
|
+
expect(ctrl.liveState().receipt?.primaryPlatformMessageId).toBe("final-message");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("falls back with full text when progress final send fails after streaming text", async () => {
|
|
255
|
+
streamInstances.length = 0;
|
|
256
|
+
const ctrl = createTeamsReplyStreamController({
|
|
257
|
+
conversationType: "personal",
|
|
258
|
+
context: { sendActivity: vi.fn(async () => ({ id: "a" })) } as never,
|
|
259
|
+
feedbackLoopEnabled: false,
|
|
260
|
+
log: { debug: vi.fn() } as never,
|
|
261
|
+
msteamsConfig: { streaming: { mode: "progress" } } as never,
|
|
262
|
+
});
|
|
263
|
+
await ctrl.onReplyStart();
|
|
264
|
+
streamInstances[0].replaceInformativeWithFinal.mockImplementationOnce(
|
|
265
|
+
async function (this: {
|
|
266
|
+
hasContent: boolean;
|
|
267
|
+
isFailed: boolean;
|
|
268
|
+
isFinalized: boolean;
|
|
269
|
+
streamedLength: number;
|
|
270
|
+
}) {
|
|
271
|
+
this.hasContent = true;
|
|
272
|
+
this.isFailed = true;
|
|
273
|
+
this.isFinalized = true;
|
|
274
|
+
this.streamedLength = 12;
|
|
275
|
+
return false;
|
|
276
|
+
},
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const result = await ctrl.preparePayload({ text: "complete final answer" });
|
|
280
|
+
|
|
281
|
+
expect(result).toEqual({ text: "complete final answer" });
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("honors disabled Teams progress labels", async () => {
|
|
285
|
+
streamInstances.length = 0;
|
|
286
|
+
const ctrl = createTeamsReplyStreamController({
|
|
287
|
+
conversationType: "personal",
|
|
288
|
+
context: { sendActivity: vi.fn(async () => ({ id: "a" })) } as never,
|
|
289
|
+
feedbackLoopEnabled: false,
|
|
290
|
+
log: { debug: vi.fn() } as never,
|
|
291
|
+
msteamsConfig: { streaming: { mode: "progress", progress: { label: false } } } as never,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
await ctrl.onReplyStart();
|
|
295
|
+
|
|
296
|
+
expect(streamInstances).toHaveLength(1);
|
|
297
|
+
expect(streamInstances[0]?.sendInformativeUpdate).not.toHaveBeenCalled();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("streams compact Teams progress lines when tool progress is enabled", async () => {
|
|
301
|
+
streamInstances.length = 0;
|
|
302
|
+
const ctrl = createTeamsReplyStreamController({
|
|
303
|
+
conversationType: "personal",
|
|
304
|
+
context: { sendActivity: vi.fn(async () => ({ id: "a" })) } as never,
|
|
305
|
+
feedbackLoopEnabled: false,
|
|
306
|
+
log: { debug: vi.fn() } as never,
|
|
307
|
+
msteamsConfig: {
|
|
308
|
+
streaming: {
|
|
309
|
+
mode: "progress",
|
|
310
|
+
progress: {
|
|
311
|
+
label: "Working",
|
|
312
|
+
maxLines: 3,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
} as never,
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
await ctrl.pushProgressLine("tool: search");
|
|
319
|
+
await ctrl.pushProgressLine("tool: exec");
|
|
320
|
+
|
|
321
|
+
expect(ctrl.shouldSuppressDefaultToolProgressMessages()).toBe(true);
|
|
322
|
+
expect(ctrl.shouldStreamPreviewToolProgress()).toBe(true);
|
|
323
|
+
expect(streamInstances[0]?.sendInformativeUpdate).toHaveBeenLastCalledWith(
|
|
324
|
+
"Working\n- tool: search\n- tool: exec",
|
|
325
|
+
);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("suppresses Teams default progress messages without stream lines when tool progress is disabled", async () => {
|
|
329
|
+
streamInstances.length = 0;
|
|
330
|
+
const ctrl = createTeamsReplyStreamController({
|
|
331
|
+
conversationType: "personal",
|
|
332
|
+
context: { sendActivity: vi.fn(async () => ({ id: "a" })) } as never,
|
|
333
|
+
feedbackLoopEnabled: false,
|
|
334
|
+
log: { debug: vi.fn() } as never,
|
|
335
|
+
msteamsConfig: {
|
|
336
|
+
streaming: {
|
|
337
|
+
mode: "progress",
|
|
338
|
+
progress: {
|
|
339
|
+
toolProgress: false,
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
} as never,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
await ctrl.pushProgressLine("tool: search");
|
|
346
|
+
|
|
347
|
+
expect(ctrl.shouldSuppressDefaultToolProgressMessages()).toBe(true);
|
|
348
|
+
expect(ctrl.shouldStreamPreviewToolProgress()).toBe(false);
|
|
349
|
+
expect(streamInstances[0]?.sendInformativeUpdate).not.toHaveBeenCalled();
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("does not start native streaming for Teams block mode", async () => {
|
|
353
|
+
streamInstances.length = 0;
|
|
354
|
+
const ctrl = createTeamsReplyStreamController({
|
|
355
|
+
conversationType: "personal",
|
|
356
|
+
context: { sendActivity: vi.fn(async () => ({ id: "a" })) } as never,
|
|
357
|
+
feedbackLoopEnabled: false,
|
|
358
|
+
log: { debug: vi.fn() } as never,
|
|
359
|
+
msteamsConfig: { streaming: { mode: "block" } } as never,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
await ctrl.onReplyStart();
|
|
363
|
+
ctrl.onPartialReply({ text: "block partial" });
|
|
364
|
+
|
|
365
|
+
expect(streamInstances).toHaveLength(0);
|
|
366
|
+
await expect(ctrl.preparePayload({ text: "block final" })).resolves.toEqual({
|
|
367
|
+
text: "block final",
|
|
368
|
+
});
|
|
369
|
+
expect(ctrl.hasStream()).toBe(false);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
describe("isStreamActive", () => {
|
|
373
|
+
it("returns false before any tokens arrive so typing keepalive can warm up", () => {
|
|
374
|
+
const ctrl = createController();
|
|
375
|
+
expect(ctrl.isStreamActive()).toBe(false);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("returns false after the informative update but before tokens arrive", async () => {
|
|
379
|
+
const ctrl = createController();
|
|
380
|
+
await ctrl.onReplyStart();
|
|
381
|
+
expect(ctrl.isStreamActive()).toBe(false);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("returns true while the stream is actively receiving tokens", () => {
|
|
385
|
+
const ctrl = createController();
|
|
386
|
+
ctrl.onPartialReply({ text: "Streaming tokens" });
|
|
387
|
+
expect(ctrl.isStreamActive()).toBe(true);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it("returns false after the stream is finalized between tool rounds", async () => {
|
|
391
|
+
const ctrl = createController();
|
|
392
|
+
|
|
393
|
+
ctrl.onPartialReply({ text: "First segment" });
|
|
394
|
+
expect(ctrl.isStreamActive()).toBe(true);
|
|
395
|
+
|
|
396
|
+
// First segment complete: stream is finalized so the typing keepalive
|
|
397
|
+
// can resume during the tool chain that follows.
|
|
398
|
+
await ctrl.preparePayload({ text: "First segment" });
|
|
399
|
+
expect(ctrl.isStreamActive()).toBe(false);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it("returns false when the stream has failed", () => {
|
|
403
|
+
const ctrl = createController();
|
|
404
|
+
|
|
405
|
+
ctrl.onPartialReply({ text: "First segment" });
|
|
406
|
+
expect(ctrl.isStreamActive()).toBe(true);
|
|
407
|
+
|
|
408
|
+
streamInstances[0].isFailed = true;
|
|
409
|
+
expect(ctrl.isStreamActive()).toBe(false);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it("returns false when conversationType is not personal", () => {
|
|
413
|
+
streamInstances.length = 0;
|
|
414
|
+
const ctrl = createTeamsReplyStreamController({
|
|
415
|
+
conversationType: "channel",
|
|
416
|
+
context: { sendActivity: vi.fn() } as never,
|
|
417
|
+
feedbackLoopEnabled: false,
|
|
418
|
+
log: { debug: vi.fn() } as never,
|
|
419
|
+
});
|
|
420
|
+
ctrl.onPartialReply({ text: "anything" });
|
|
421
|
+
expect(ctrl.isStreamActive()).toBe(false);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
});
|