@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
@@ -1,797 +0,0 @@
1
- import type { KlawConfig } from "klaw/plugin-sdk/config-contracts";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
- import { msteamsPlugin } from "./channel.js";
4
-
5
- const {
6
- editMessageMSTeamsMock,
7
- deleteMessageMSTeamsMock,
8
- getChannelInfoMSTeamsMock,
9
- getMemberInfoMSTeamsMock,
10
- getMessageMSTeamsMock,
11
- listChannelsMSTeamsMock,
12
- listReactionsMSTeamsMock,
13
- pinMessageMSTeamsMock,
14
- reactMessageMSTeamsMock,
15
- searchMessagesMSTeamsMock,
16
- sendAdaptiveCardMSTeamsMock,
17
- sendMessageMSTeamsMock,
18
- unpinMessageMSTeamsMock,
19
- } = vi.hoisted(() => ({
20
- editMessageMSTeamsMock: vi.fn(),
21
- deleteMessageMSTeamsMock: vi.fn(),
22
- getChannelInfoMSTeamsMock: vi.fn(),
23
- getMemberInfoMSTeamsMock: vi.fn(),
24
- getMessageMSTeamsMock: vi.fn(),
25
- listChannelsMSTeamsMock: vi.fn(),
26
- listReactionsMSTeamsMock: vi.fn(),
27
- pinMessageMSTeamsMock: vi.fn(),
28
- reactMessageMSTeamsMock: vi.fn(),
29
- searchMessagesMSTeamsMock: vi.fn(),
30
- sendAdaptiveCardMSTeamsMock: vi.fn(),
31
- sendMessageMSTeamsMock: vi.fn(),
32
- unpinMessageMSTeamsMock: vi.fn(),
33
- }));
34
-
35
- vi.mock("./channel.runtime.js", () => ({
36
- msTeamsChannelRuntime: {
37
- editMessageMSTeams: editMessageMSTeamsMock,
38
- deleteMessageMSTeams: deleteMessageMSTeamsMock,
39
- getChannelInfoMSTeams: getChannelInfoMSTeamsMock,
40
- getMemberInfoMSTeams: getMemberInfoMSTeamsMock,
41
- getMessageMSTeams: getMessageMSTeamsMock,
42
- listChannelsMSTeams: listChannelsMSTeamsMock,
43
- listReactionsMSTeams: listReactionsMSTeamsMock,
44
- pinMessageMSTeams: pinMessageMSTeamsMock,
45
- reactMessageMSTeams: reactMessageMSTeamsMock,
46
- searchMessagesMSTeams: searchMessagesMSTeamsMock,
47
- sendAdaptiveCardMSTeams: sendAdaptiveCardMSTeamsMock,
48
- sendMessageMSTeams: sendMessageMSTeamsMock,
49
- unpinMessageMSTeams: unpinMessageMSTeamsMock,
50
- },
51
- }));
52
-
53
- const actionMocks = [
54
- editMessageMSTeamsMock,
55
- deleteMessageMSTeamsMock,
56
- getChannelInfoMSTeamsMock,
57
- getMemberInfoMSTeamsMock,
58
- getMessageMSTeamsMock,
59
- listChannelsMSTeamsMock,
60
- listReactionsMSTeamsMock,
61
- pinMessageMSTeamsMock,
62
- reactMessageMSTeamsMock,
63
- searchMessagesMSTeamsMock,
64
- sendAdaptiveCardMSTeamsMock,
65
- sendMessageMSTeamsMock,
66
- unpinMessageMSTeamsMock,
67
- ];
68
- const currentChannelId = "conversation:19:ctx@thread.tacv2";
69
- const reactChannelId = "conversation:19:react@thread.tacv2";
70
- const targetChannelId = "conversation:19:target@thread.tacv2";
71
- const editedConversationId = "19:edited@thread.tacv2";
72
- const editedMessageId = "msg-edit-1";
73
- const readMessage = { id: "msg-1", text: "hello" };
74
- const reactionType = "like";
75
- const updatedText = "updated text";
76
- const reactionTypes = ["like", "heart", "laugh", "surprised", "sad", "angry"];
77
- const deleteMissingTargetError = "Delete requires a target (to) and messageId.";
78
- const reactionsMissingTargetError = "Reactions requires a target (to) and messageId.";
79
- const presentationSendMissingTargetError = "Card send requires a target (to).";
80
- const reactMissingEmojiError =
81
- "React requires an emoji (reaction type). Valid types: like, heart, laugh, surprised, sad, angry.";
82
- const reactMissingEmojiDetail = "React requires an emoji (reaction type).";
83
- const searchMissingQueryError = "Search requires a target (to) and query.";
84
-
85
- function padded(value: string) {
86
- return ` ${value} `;
87
- }
88
-
89
- function msteamsActionDetails(action: string, details?: Record<string, unknown>) {
90
- return {
91
- channel: "msteams",
92
- action,
93
- ...details,
94
- };
95
- }
96
-
97
- function okMSTeamsActionDetails(action: string, details?: Record<string, unknown>) {
98
- return msteamsActionDetails(action, { ok: true, ...details });
99
- }
100
-
101
- function requireMSTeamsHandleAction() {
102
- const handleAction = msteamsPlugin.actions?.handleAction;
103
- if (!handleAction) {
104
- throw new Error("msteams actions.handleAction unavailable");
105
- }
106
- return handleAction;
107
- }
108
-
109
- async function runAction(params: {
110
- action: string;
111
- cfg?: Record<string, unknown>;
112
- params?: Record<string, unknown>;
113
- toolContext?: Record<string, unknown>;
114
- mediaLocalRoots?: readonly string[];
115
- mediaReadFile?: (filePath: string) => Promise<Buffer>;
116
- }) {
117
- const handleAction = requireMSTeamsHandleAction();
118
- return await handleAction({
119
- channel: "msteams",
120
- action: params.action,
121
- cfg: params.cfg ?? {},
122
- params: params.params ?? {},
123
- mediaLocalRoots: params.mediaLocalRoots,
124
- mediaReadFile: params.mediaReadFile,
125
- toolContext: params.toolContext,
126
- } as Parameters<ReturnType<typeof requireMSTeamsHandleAction>>[0]);
127
- }
128
-
129
- async function expectActionError(
130
- params: Parameters<typeof runAction>[0],
131
- expectedMessage: string,
132
- expectedDetails?: Record<string, unknown>,
133
- ) {
134
- await expect(runAction(params)).resolves.toEqual({
135
- isError: true,
136
- content: [{ type: "text", text: expectedMessage }],
137
- details: expectedDetails ?? { error: expectedMessage },
138
- });
139
- }
140
-
141
- async function expectActionParamError(
142
- action: Parameters<typeof runAction>[0]["action"],
143
- params: Record<string, unknown>,
144
- expectedMessage: string,
145
- expectedDetails?: Record<string, unknown>,
146
- ) {
147
- await expectActionError({ action, params }, expectedMessage, expectedDetails);
148
- }
149
-
150
- function expectActionSuccess(
151
- result: Awaited<ReturnType<typeof runAction>>,
152
- details: Record<string, unknown>,
153
- contentDetails: Record<string, unknown> = details,
154
- ) {
155
- expect(result).toEqual({
156
- content: [
157
- {
158
- type: "text",
159
- text: JSON.stringify(contentDetails),
160
- },
161
- ],
162
- details,
163
- });
164
- }
165
-
166
- function expectActionRuntimeCall(
167
- mockFn: ReturnType<typeof vi.fn>,
168
- params: Record<string, unknown>,
169
- ) {
170
- expect(mockFn).toHaveBeenCalledWith({
171
- cfg: {},
172
- ...params,
173
- });
174
- }
175
-
176
- async function expectSuccessfulAction(params: {
177
- mockFn: ReturnType<typeof vi.fn>;
178
- mockResult: unknown;
179
- action: Parameters<typeof runAction>[0]["action"];
180
- actionParams?: Parameters<typeof runAction>[0]["params"];
181
- toolContext?: Parameters<typeof runAction>[0]["toolContext"];
182
- mediaLocalRoots?: Parameters<typeof runAction>[0]["mediaLocalRoots"];
183
- mediaReadFile?: Parameters<typeof runAction>[0]["mediaReadFile"];
184
- runtimeParams: Record<string, unknown>;
185
- details: Record<string, unknown>;
186
- contentDetails?: Record<string, unknown>;
187
- }) {
188
- params.mockFn.mockResolvedValue(params.mockResult);
189
- const result = await runAction({
190
- action: params.action,
191
- params: params.actionParams,
192
- mediaLocalRoots: params.mediaLocalRoots,
193
- mediaReadFile: params.mediaReadFile,
194
- toolContext: params.toolContext,
195
- });
196
- expectActionRuntimeCall(params.mockFn, params.runtimeParams);
197
- expectActionSuccess(result, params.details, params.contentDetails);
198
- }
199
-
200
- describe("msteamsPlugin message actions", () => {
201
- beforeEach(() => {
202
- for (const mockFn of actionMocks) {
203
- mockFn.mockReset();
204
- }
205
- });
206
-
207
- it("falls back to toolContext.currentChannelId for read actions", async () => {
208
- await expectSuccessfulAction({
209
- mockFn: getMessageMSTeamsMock,
210
- mockResult: readMessage,
211
- action: "read",
212
- actionParams: {
213
- messageId: padded("msg-1"),
214
- },
215
- toolContext: {
216
- currentChannelId: padded(currentChannelId),
217
- },
218
- runtimeParams: {
219
- to: currentChannelId,
220
- messageId: "msg-1",
221
- },
222
- details: okMSTeamsActionDetails("read", {
223
- message: readMessage,
224
- }),
225
- contentDetails: {
226
- ok: true,
227
- channel: "msteams",
228
- action: "read",
229
- message: readMessage,
230
- },
231
- });
232
- });
233
-
234
- it("advertises upload-file in the message tool surface", () => {
235
- expect(
236
- msteamsPlugin.actions?.describeMessageTool?.({
237
- cfg: {
238
- channels: {
239
- msteams: {
240
- appId: "app-id",
241
- appPassword: "secret",
242
- tenantId: "tenant-id",
243
- },
244
- },
245
- } as KlawConfig,
246
- })?.actions,
247
- ).toContain("upload-file");
248
- });
249
-
250
- it("routes upload-file through sendMessageMSTeams with filename override", async () => {
251
- const mediaReadFile = vi.fn(async () => Buffer.from("pdf"));
252
- await expectSuccessfulAction({
253
- mockFn: sendMessageMSTeamsMock,
254
- mockResult: {
255
- messageId: "msg-upload-1",
256
- conversationId: "conv-upload-1",
257
- },
258
- action: "upload-file",
259
- actionParams: {
260
- target: padded(targetChannelId),
261
- path: " /tmp/report.pdf ",
262
- message: "Quarterly report",
263
- filename: "Q1-report.pdf",
264
- },
265
- mediaLocalRoots: ["/tmp"],
266
- mediaReadFile,
267
- runtimeParams: {
268
- to: targetChannelId,
269
- text: "Quarterly report",
270
- mediaUrl: " /tmp/report.pdf ",
271
- filename: "Q1-report.pdf",
272
- mediaLocalRoots: ["/tmp"],
273
- mediaReadFile,
274
- },
275
- details: {
276
- ok: true,
277
- channel: "msteams",
278
- messageId: "msg-upload-1",
279
- },
280
- contentDetails: {
281
- ok: true,
282
- channel: "msteams",
283
- action: "upload-file",
284
- messageId: "msg-upload-1",
285
- conversationId: "conv-upload-1",
286
- },
287
- });
288
- });
289
-
290
- it("routes member-info through the Teams runtime", async () => {
291
- await expectSuccessfulAction({
292
- mockFn: getMemberInfoMSTeamsMock,
293
- mockResult: { member: { id: "user-1" } },
294
- action: "member-info",
295
- actionParams: { userId: " user-1 " },
296
- runtimeParams: { userId: "user-1" },
297
- details: okMSTeamsActionDetails("member-info", {
298
- member: { id: "user-1" },
299
- }),
300
- contentDetails: {
301
- ok: true,
302
- channel: "msteams",
303
- action: "member-info",
304
- member: { id: "user-1" },
305
- },
306
- });
307
- });
308
-
309
- it("routes channel-list through the Teams runtime", async () => {
310
- await expectSuccessfulAction({
311
- mockFn: listChannelsMSTeamsMock,
312
- mockResult: { channels: [{ id: "channel-1" }] },
313
- action: "channel-list",
314
- actionParams: { teamId: " team-1 " },
315
- runtimeParams: { teamId: "team-1" },
316
- details: okMSTeamsActionDetails("channel-list", {
317
- channels: [{ id: "channel-1" }],
318
- }),
319
- contentDetails: {
320
- ok: true,
321
- channel: "msteams",
322
- action: "channel-list",
323
- channels: [{ id: "channel-1" }],
324
- },
325
- });
326
- });
327
-
328
- it("routes channel-info through the Teams runtime", async () => {
329
- await expectSuccessfulAction({
330
- mockFn: getChannelInfoMSTeamsMock,
331
- mockResult: { channel: { id: "channel-1" } },
332
- action: "channel-info",
333
- actionParams: {
334
- teamId: " team-1 ",
335
- channelId: " channel-1 ",
336
- },
337
- runtimeParams: {
338
- teamId: "team-1",
339
- channelId: "channel-1",
340
- },
341
- details: okMSTeamsActionDetails("channel-info", {
342
- channelInfo: { id: "channel-1" },
343
- }),
344
- contentDetails: {
345
- ok: true,
346
- channel: "msteams",
347
- action: "channel-info",
348
- channelInfo: { id: "channel-1" },
349
- },
350
- });
351
- });
352
-
353
- it("accepts target as an alias for pin actions", async () => {
354
- await expectSuccessfulAction({
355
- mockFn: pinMessageMSTeamsMock,
356
- mockResult: { ok: true, pinnedMessageId: "pin-1" },
357
- action: "pin",
358
- actionParams: {
359
- target: padded(targetChannelId),
360
- messageId: padded("msg-2"),
361
- },
362
- runtimeParams: {
363
- to: targetChannelId,
364
- messageId: "msg-2",
365
- },
366
- details: okMSTeamsActionDetails("pin", {
367
- pinnedMessageId: "pin-1",
368
- }),
369
- });
370
- });
371
-
372
- it("falls back from content to message fields for edit actions", async () => {
373
- await expectSuccessfulAction({
374
- mockFn: editMessageMSTeamsMock,
375
- mockResult: { conversationId: editedConversationId },
376
- action: "edit",
377
- actionParams: {
378
- to: targetChannelId,
379
- messageId: editedMessageId,
380
- content: updatedText,
381
- },
382
- runtimeParams: {
383
- to: targetChannelId,
384
- activityId: editedMessageId,
385
- text: updatedText,
386
- },
387
- details: {
388
- ok: true,
389
- channel: "msteams",
390
- },
391
- contentDetails: {
392
- ok: true,
393
- channel: "msteams",
394
- conversationId: editedConversationId,
395
- },
396
- });
397
- });
398
-
399
- it("falls back from pinnedMessageId to messageId for unpin actions", async () => {
400
- await expectSuccessfulAction({
401
- mockFn: unpinMessageMSTeamsMock,
402
- mockResult: { ok: true },
403
- action: "unpin",
404
- actionParams: {
405
- target: padded(targetChannelId),
406
- messageId: padded("pin-2"),
407
- },
408
- runtimeParams: {
409
- to: targetChannelId,
410
- pinnedMessageId: "pin-2",
411
- },
412
- details: okMSTeamsActionDetails("unpin"),
413
- });
414
- });
415
-
416
- it("uses explicit pinnedMessageId over messageId for unpin actions", async () => {
417
- await expectSuccessfulAction({
418
- mockFn: unpinMessageMSTeamsMock,
419
- mockResult: { ok: true },
420
- action: "unpin",
421
- actionParams: {
422
- target: padded(targetChannelId),
423
- pinnedMessageId: padded("pinned-resource-99"),
424
- messageId: padded("msg-99"),
425
- },
426
- runtimeParams: {
427
- to: targetChannelId,
428
- pinnedMessageId: "pinned-resource-99",
429
- },
430
- details: okMSTeamsActionDetails("unpin"),
431
- });
432
- });
433
-
434
- it("returns an error when unpin is called without pinnedMessageId or messageId", async () => {
435
- await expectActionParamError(
436
- "unpin",
437
- { target: targetChannelId },
438
- "Unpin requires a target (to) and pinnedMessageId.",
439
- );
440
- });
441
-
442
- it("exposes pinnedMessageId in the tool schema", () => {
443
- const discovery = msteamsPlugin.actions?.describeMessageTool?.({
444
- cfg: {
445
- channels: {
446
- msteams: {
447
- appId: "app-id",
448
- appPassword: "secret",
449
- tenantId: "tenant-id",
450
- },
451
- },
452
- } as KlawConfig,
453
- });
454
- const schema = discovery?.schema;
455
- if (!schema) {
456
- throw new Error("expected msteams message tool schema");
457
- }
458
- const properties = Array.isArray(schema)
459
- ? schema[0]?.properties
460
- : (schema as { properties: Record<string, unknown> })?.properties;
461
- expect(properties).toHaveProperty("pinnedMessageId");
462
- });
463
-
464
- it("reuses currentChannelId fallback for react actions", async () => {
465
- await expectSuccessfulAction({
466
- mockFn: reactMessageMSTeamsMock,
467
- mockResult: { ok: true },
468
- action: "react",
469
- actionParams: {
470
- messageId: padded("msg-3"),
471
- emoji: padded(reactionType),
472
- },
473
- toolContext: {
474
- currentChannelId: padded(reactChannelId),
475
- },
476
- runtimeParams: {
477
- to: reactChannelId,
478
- messageId: "msg-3",
479
- reactionType,
480
- },
481
- details: okMSTeamsActionDetails("react", {
482
- reactionType,
483
- }),
484
- contentDetails: {
485
- channel: "msteams",
486
- action: "react",
487
- reactionType,
488
- ok: true,
489
- },
490
- });
491
- });
492
-
493
- it("shares the missing target and messageId validation across actions", async () => {
494
- await expectActionParamError("delete", {}, deleteMissingTargetError);
495
-
496
- await expectActionParamError("reactions", { to: targetChannelId }, reactionsMissingTargetError);
497
- });
498
-
499
- it("keeps presentation-card target validation shared", async () => {
500
- await expectActionParamError(
501
- "send",
502
- { presentation: { blocks: [{ type: "text", text: "hello" }] } },
503
- presentationSendMissingTargetError,
504
- );
505
- });
506
-
507
- it("preserves message text when sending presentation cards", async () => {
508
- await expectSuccessfulAction({
509
- mockFn: sendAdaptiveCardMSTeamsMock,
510
- mockResult: {
511
- messageId: "msg-card-1",
512
- conversationId: "conv-card-1",
513
- },
514
- action: "send",
515
- actionParams: {
516
- to: targetChannelId,
517
- message: "Deploy finished",
518
- presentation: {
519
- blocks: [
520
- {
521
- type: "buttons",
522
- buttons: [{ label: "Open", value: "open" }],
523
- },
524
- ],
525
- },
526
- },
527
- runtimeParams: {
528
- to: targetChannelId,
529
- card: {
530
- type: "AdaptiveCard",
531
- version: "1.4",
532
- body: [{ type: "TextBlock", text: "Deploy finished", wrap: true }],
533
- actions: [
534
- { type: "Action.Submit", title: "Open", data: { value: "open", label: "Open" } },
535
- ],
536
- },
537
- },
538
- details: {
539
- ok: true,
540
- channel: "msteams",
541
- messageId: "msg-card-1",
542
- },
543
- contentDetails: {
544
- ok: true,
545
- channel: "msteams",
546
- messageId: "msg-card-1",
547
- conversationId: "conv-card-1",
548
- },
549
- });
550
- });
551
-
552
- it("downgrades select blocks when sending presentation cards", async () => {
553
- await expectSuccessfulAction({
554
- mockFn: sendAdaptiveCardMSTeamsMock,
555
- mockResult: {
556
- messageId: "msg-card-select-1",
557
- conversationId: "conv-card-select-1",
558
- },
559
- action: "send",
560
- actionParams: {
561
- to: targetChannelId,
562
- presentation: {
563
- blocks: [
564
- {
565
- type: "select",
566
- placeholder: "Pick a lane",
567
- options: [
568
- { label: "Canary", value: "canary" },
569
- { label: "Stable", value: "stable" },
570
- ],
571
- },
572
- ],
573
- },
574
- },
575
- runtimeParams: {
576
- to: targetChannelId,
577
- card: {
578
- type: "AdaptiveCard",
579
- version: "1.4",
580
- body: [
581
- {
582
- type: "TextBlock",
583
- text: "Pick a lane:\n- Canary\n- Stable",
584
- wrap: true,
585
- isSubtle: true,
586
- size: "Small",
587
- },
588
- ],
589
- },
590
- },
591
- details: {
592
- ok: true,
593
- channel: "msteams",
594
- messageId: "msg-card-select-1",
595
- },
596
- contentDetails: {
597
- ok: true,
598
- channel: "msteams",
599
- messageId: "msg-card-select-1",
600
- conversationId: "conv-card-select-1",
601
- },
602
- });
603
- });
604
-
605
- it("reports the allowed reaction types when emoji is missing", async () => {
606
- await expectActionParamError(
607
- "react",
608
- {
609
- to: targetChannelId,
610
- messageId: "msg-4",
611
- },
612
- reactMissingEmojiError,
613
- {
614
- error: reactMissingEmojiDetail,
615
- validTypes: reactionTypes,
616
- },
617
- );
618
- });
619
-
620
- it("requires a non-empty search query after trimming", async () => {
621
- await expectActionParamError(
622
- "search",
623
- {
624
- to: targetChannelId,
625
- query: " ",
626
- },
627
- searchMissingQueryError,
628
- );
629
- });
630
-
631
- it("routes channel fallback targets via teamId/channelId for react actions", async () => {
632
- // When an action is invoked in a Teams channel context and `target` is
633
- // omitted, the action handler falls back to `toolContext.currentChannelId`.
634
- // For channel turns, buildToolContext populates that field with the
635
- // compound `teamId/channelId` form (see buildToolContext below), so the
636
- // runtime call must receive that compound form — NOT a bare
637
- // `conversation:<id>` — so Graph API routes through
638
- // `/teams/{teamId}/channels/{channelId}` rather than `/chats/{id}`.
639
- const teamChannelTarget = "team-1/19:channel-abc@thread.tacv2";
640
- await expectSuccessfulAction({
641
- mockFn: reactMessageMSTeamsMock,
642
- mockResult: { ok: true },
643
- action: "react",
644
- actionParams: {
645
- messageId: "msg-channel-react",
646
- emoji: reactionType,
647
- },
648
- toolContext: {
649
- currentChannelId: "conversation:19:channel-abc@thread.tacv2",
650
- currentGraphChannelId: teamChannelTarget,
651
- },
652
- runtimeParams: {
653
- to: teamChannelTarget,
654
- messageId: "msg-channel-react",
655
- reactionType,
656
- },
657
- details: okMSTeamsActionDetails("react", {
658
- reactionType,
659
- }),
660
- contentDetails: {
661
- channel: "msteams",
662
- action: "react",
663
- reactionType,
664
- ok: true,
665
- },
666
- });
667
- });
668
-
669
- it("preserves explicit teamId/channelId target over toolContext fallback", async () => {
670
- // Even in a channel context with a compound currentChannelId, an
671
- // explicit `target` param must take precedence.
672
- const teamChannelTarget = "team-2/19:channel-def@thread.tacv2";
673
- const explicitTarget = "team-explicit/19:other@thread.tacv2";
674
- await expectSuccessfulAction({
675
- mockFn: reactMessageMSTeamsMock,
676
- mockResult: { ok: true },
677
- action: "react",
678
- actionParams: {
679
- target: explicitTarget,
680
- messageId: "msg-explicit",
681
- emoji: reactionType,
682
- },
683
- toolContext: {
684
- currentChannelId: teamChannelTarget,
685
- currentGraphChannelId: teamChannelTarget,
686
- },
687
- runtimeParams: {
688
- to: explicitTarget,
689
- messageId: "msg-explicit",
690
- reactionType,
691
- },
692
- details: okMSTeamsActionDetails("react", {
693
- reactionType,
694
- }),
695
- contentDetails: {
696
- channel: "msteams",
697
- action: "react",
698
- reactionType,
699
- ok: true,
700
- },
701
- });
702
- });
703
-
704
- it("keeps chat conversation fallback targets as-is for DM react actions", async () => {
705
- // DM/group-chat turns continue to set currentChannelId to a
706
- // `conversation:<id>` string (no `teamId/` prefix), which the runtime
707
- // will resolve through `/chats/{id}`.
708
- const dmFallback = "conversation:19:chat-dm@thread.skype";
709
- await expectSuccessfulAction({
710
- mockFn: reactMessageMSTeamsMock,
711
- mockResult: { ok: true },
712
- action: "react",
713
- actionParams: {
714
- messageId: "msg-dm-react",
715
- emoji: reactionType,
716
- },
717
- toolContext: {
718
- currentChannelId: dmFallback,
719
- },
720
- runtimeParams: {
721
- to: dmFallback,
722
- messageId: "msg-dm-react",
723
- reactionType,
724
- },
725
- details: okMSTeamsActionDetails("react", {
726
- reactionType,
727
- }),
728
- contentDetails: {
729
- channel: "msteams",
730
- action: "react",
731
- reactionType,
732
- ok: true,
733
- },
734
- });
735
- });
736
- });
737
-
738
- describe("msteamsPlugin.threading.buildToolContext", () => {
739
- function callBuildToolContext(context: {
740
- To?: string;
741
- NativeChannelId?: string;
742
- ReplyToId?: string;
743
- }) {
744
- const build = msteamsPlugin.threading?.buildToolContext;
745
- if (!build) {
746
- throw new Error("msteams threading.buildToolContext unavailable");
747
- }
748
- return build({
749
- cfg: {} as KlawConfig,
750
- accountId: undefined,
751
- context,
752
- });
753
- }
754
-
755
- it("uses NativeChannelId for channel turns so actions route via teamId/channelId", () => {
756
- // Teams channel inbound messages carry the compound `teamId/channelId`
757
- // on NativeChannelId. buildToolContext must prefer it over the bare
758
- // `conversation:<id>` in To so action fallbacks route via
759
- // `/teams/{teamId}/channels/{channelId}`.
760
- const result = callBuildToolContext({
761
- To: "conversation:19:channel-abc@thread.tacv2",
762
- NativeChannelId: "team-1/19:channel-abc@thread.tacv2",
763
- ReplyToId: "reply-1",
764
- });
765
- expect(result?.currentChannelId).toBe("conversation:19:channel-abc@thread.tacv2");
766
- expect(result?.currentGraphChannelId).toBe("team-1/19:channel-abc@thread.tacv2");
767
- expect(result?.currentThreadTs).toBe("reply-1");
768
- });
769
-
770
- it("falls back to To for DM turns (no NativeChannelId)", () => {
771
- const result = callBuildToolContext({
772
- To: "user:aad-user-1",
773
- });
774
- expect(result?.currentChannelId).toBe("user:aad-user-1");
775
- expect(result?.currentGraphChannelId).toBeUndefined();
776
- });
777
-
778
- it("falls back to To for group chat turns (no NativeChannelId)", () => {
779
- const result = callBuildToolContext({
780
- To: "conversation:19:groupchat@thread.v2",
781
- });
782
- expect(result?.currentChannelId).toBe("conversation:19:groupchat@thread.v2");
783
- expect(result?.currentGraphChannelId).toBeUndefined();
784
- });
785
-
786
- it("ignores NativeChannelId that does not encode a teamId/channelId pair", () => {
787
- // Safety: only compound forms (with "/") should preempt the To fallback.
788
- // A bare native id without a team prefix must not accidentally route
789
- // through channel Graph paths.
790
- const result = callBuildToolContext({
791
- To: "conversation:19:chat@thread.v2",
792
- NativeChannelId: "19:chat@thread.v2",
793
- });
794
- expect(result?.currentChannelId).toBe("conversation:19:chat@thread.v2");
795
- expect(result?.currentGraphChannelId).toBeUndefined();
796
- });
797
- });