@openclaw/msteams 2026.5.2 → 2026.5.3-beta.1

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 (197) hide show
  1. package/dist/api.js +3 -0
  2. package/dist/channel-D7hdreTh.js +984 -0
  3. package/dist/channel-config-api.js +2 -0
  4. package/dist/channel-plugin-api.js +2 -0
  5. package/dist/channel.runtime-BC1ruIfN.js +573 -0
  6. package/dist/config-schema-B8QezH6t.js +15 -0
  7. package/dist/contract-api.js +2 -0
  8. package/dist/graph-users-9uQJepqr.js +1354 -0
  9. package/dist/index.js +22 -0
  10. package/dist/oauth-BWJyilR1.js +114 -0
  11. package/dist/oauth.token-xxpoLWy5.js +115 -0
  12. package/dist/policy-DTnU2GR7.js +142 -0
  13. package/dist/probe-D_H8yFps.js +2194 -0
  14. package/dist/resolve-allowlist-D41JSziq.js +219 -0
  15. package/dist/runtime-api-DV1iVMn1.js +28 -0
  16. package/dist/runtime-api.js +2 -0
  17. package/dist/secret-contract-BuoEXmPS.js +35 -0
  18. package/dist/secret-contract-api.js +2 -0
  19. package/dist/setup-entry.js +15 -0
  20. package/dist/setup-plugin-api.js +64 -0
  21. package/dist/setup-surface-BLkFQYIQ.js +313 -0
  22. package/dist/src-CFp1QpFd.js +4064 -0
  23. package/dist/test-api.js +2 -0
  24. package/package.json +14 -6
  25. package/api.ts +0 -3
  26. package/channel-config-api.ts +0 -1
  27. package/channel-plugin-api.ts +0 -2
  28. package/config-api.ts +0 -4
  29. package/contract-api.ts +0 -4
  30. package/index.ts +0 -20
  31. package/runtime-api.ts +0 -73
  32. package/secret-contract-api.ts +0 -5
  33. package/setup-entry.ts +0 -13
  34. package/setup-plugin-api.ts +0 -3
  35. package/src/ai-entity.ts +0 -7
  36. package/src/approval-auth.ts +0 -44
  37. package/src/attachments/bot-framework.test.ts +0 -461
  38. package/src/attachments/bot-framework.ts +0 -362
  39. package/src/attachments/download.ts +0 -311
  40. package/src/attachments/graph.test.ts +0 -416
  41. package/src/attachments/graph.ts +0 -484
  42. package/src/attachments/html.ts +0 -122
  43. package/src/attachments/payload.ts +0 -14
  44. package/src/attachments/remote-media.test.ts +0 -137
  45. package/src/attachments/remote-media.ts +0 -112
  46. package/src/attachments/shared.test.ts +0 -530
  47. package/src/attachments/shared.ts +0 -626
  48. package/src/attachments/types.ts +0 -47
  49. package/src/attachments.graph.test.ts +0 -342
  50. package/src/attachments.helpers.test.ts +0 -246
  51. package/src/attachments.test-helpers.ts +0 -17
  52. package/src/attachments.test.ts +0 -687
  53. package/src/attachments.ts +0 -18
  54. package/src/block-streaming-config.test.ts +0 -61
  55. package/src/channel-api.ts +0 -1
  56. package/src/channel.actions.test.ts +0 -742
  57. package/src/channel.directory.test.ts +0 -200
  58. package/src/channel.runtime.ts +0 -56
  59. package/src/channel.setup.ts +0 -77
  60. package/src/channel.test.ts +0 -128
  61. package/src/channel.ts +0 -1136
  62. package/src/config-schema.ts +0 -6
  63. package/src/config-ui-hints.ts +0 -12
  64. package/src/conversation-store-fs.test.ts +0 -74
  65. package/src/conversation-store-fs.ts +0 -149
  66. package/src/conversation-store-helpers.test.ts +0 -202
  67. package/src/conversation-store-helpers.ts +0 -105
  68. package/src/conversation-store-memory.ts +0 -51
  69. package/src/conversation-store.shared.test.ts +0 -225
  70. package/src/conversation-store.ts +0 -71
  71. package/src/directory-live.test.ts +0 -156
  72. package/src/directory-live.ts +0 -111
  73. package/src/doctor.ts +0 -27
  74. package/src/errors.test.ts +0 -133
  75. package/src/errors.ts +0 -246
  76. package/src/feedback-reflection-prompt.ts +0 -117
  77. package/src/feedback-reflection-store.ts +0 -114
  78. package/src/feedback-reflection.test.ts +0 -237
  79. package/src/feedback-reflection.ts +0 -283
  80. package/src/file-consent-helpers.test.ts +0 -326
  81. package/src/file-consent-helpers.ts +0 -126
  82. package/src/file-consent-invoke.ts +0 -150
  83. package/src/file-consent.test.ts +0 -363
  84. package/src/file-consent.ts +0 -287
  85. package/src/graph-chat.ts +0 -55
  86. package/src/graph-group-management.test.ts +0 -318
  87. package/src/graph-group-management.ts +0 -168
  88. package/src/graph-members.test.ts +0 -89
  89. package/src/graph-members.ts +0 -48
  90. package/src/graph-messages.actions.test.ts +0 -243
  91. package/src/graph-messages.read.test.ts +0 -391
  92. package/src/graph-messages.search.test.ts +0 -213
  93. package/src/graph-messages.test-helpers.ts +0 -50
  94. package/src/graph-messages.ts +0 -534
  95. package/src/graph-teams.test.ts +0 -215
  96. package/src/graph-teams.ts +0 -114
  97. package/src/graph-thread.test.ts +0 -246
  98. package/src/graph-thread.ts +0 -146
  99. package/src/graph-upload.test.ts +0 -258
  100. package/src/graph-upload.ts +0 -531
  101. package/src/graph-users.ts +0 -29
  102. package/src/graph.test.ts +0 -516
  103. package/src/graph.ts +0 -293
  104. package/src/inbound.test.ts +0 -221
  105. package/src/inbound.ts +0 -148
  106. package/src/index.ts +0 -4
  107. package/src/media-helpers.test.ts +0 -202
  108. package/src/media-helpers.ts +0 -105
  109. package/src/mentions.test.ts +0 -244
  110. package/src/mentions.ts +0 -114
  111. package/src/messenger.test.ts +0 -865
  112. package/src/messenger.ts +0 -605
  113. package/src/monitor-handler/access.ts +0 -125
  114. package/src/monitor-handler/inbound-media.test.ts +0 -289
  115. package/src/monitor-handler/inbound-media.ts +0 -180
  116. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  117. package/src/monitor-handler/message-handler.authz.test.ts +0 -669
  118. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  119. package/src/monitor-handler/message-handler.test-support.ts +0 -100
  120. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
  121. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
  122. package/src/monitor-handler/message-handler.ts +0 -1000
  123. package/src/monitor-handler/reaction-handler.test.ts +0 -267
  124. package/src/monitor-handler/reaction-handler.ts +0 -210
  125. package/src/monitor-handler/thread-session.ts +0 -17
  126. package/src/monitor-handler.adaptive-card.test.ts +0 -162
  127. package/src/monitor-handler.feedback-authz.test.ts +0 -314
  128. package/src/monitor-handler.file-consent.test.ts +0 -423
  129. package/src/monitor-handler.sso.test.ts +0 -563
  130. package/src/monitor-handler.test-helpers.ts +0 -180
  131. package/src/monitor-handler.ts +0 -534
  132. package/src/monitor-handler.types.ts +0 -27
  133. package/src/monitor-types.ts +0 -6
  134. package/src/monitor.lifecycle.test.ts +0 -278
  135. package/src/monitor.test.ts +0 -119
  136. package/src/monitor.ts +0 -442
  137. package/src/oauth.flow.ts +0 -77
  138. package/src/oauth.shared.ts +0 -37
  139. package/src/oauth.test.ts +0 -305
  140. package/src/oauth.token.ts +0 -158
  141. package/src/oauth.ts +0 -130
  142. package/src/outbound.test.ts +0 -130
  143. package/src/outbound.ts +0 -71
  144. package/src/pending-uploads-fs.test.ts +0 -246
  145. package/src/pending-uploads-fs.ts +0 -235
  146. package/src/pending-uploads.test.ts +0 -173
  147. package/src/pending-uploads.ts +0 -121
  148. package/src/policy.test.ts +0 -240
  149. package/src/policy.ts +0 -262
  150. package/src/polls-store-memory.ts +0 -32
  151. package/src/polls.test.ts +0 -160
  152. package/src/polls.ts +0 -323
  153. package/src/presentation.ts +0 -68
  154. package/src/probe.test.ts +0 -77
  155. package/src/probe.ts +0 -132
  156. package/src/reply-dispatcher.test.ts +0 -437
  157. package/src/reply-dispatcher.ts +0 -346
  158. package/src/reply-stream-controller.test.ts +0 -235
  159. package/src/reply-stream-controller.ts +0 -147
  160. package/src/resolve-allowlist.test.ts +0 -250
  161. package/src/resolve-allowlist.ts +0 -309
  162. package/src/revoked-context.ts +0 -17
  163. package/src/runtime.ts +0 -9
  164. package/src/sdk-types.ts +0 -59
  165. package/src/sdk.test.ts +0 -666
  166. package/src/sdk.ts +0 -884
  167. package/src/secret-contract.ts +0 -49
  168. package/src/secret-input.ts +0 -7
  169. package/src/send-context.ts +0 -231
  170. package/src/send.test.ts +0 -493
  171. package/src/send.ts +0 -637
  172. package/src/sent-message-cache.test.ts +0 -15
  173. package/src/sent-message-cache.ts +0 -56
  174. package/src/session-route.ts +0 -40
  175. package/src/setup-core.ts +0 -160
  176. package/src/setup-surface.test.ts +0 -202
  177. package/src/setup-surface.ts +0 -320
  178. package/src/sso-token-store.test.ts +0 -72
  179. package/src/sso-token-store.ts +0 -166
  180. package/src/sso.ts +0 -300
  181. package/src/storage.ts +0 -25
  182. package/src/store-fs.ts +0 -44
  183. package/src/streaming-message.test.ts +0 -262
  184. package/src/streaming-message.ts +0 -297
  185. package/src/test-runtime.ts +0 -16
  186. package/src/thread-parent-context.test.ts +0 -224
  187. package/src/thread-parent-context.ts +0 -159
  188. package/src/token-response.ts +0 -11
  189. package/src/token.test.ts +0 -259
  190. package/src/token.ts +0 -195
  191. package/src/user-agent.test.ts +0 -86
  192. package/src/user-agent.ts +0 -53
  193. package/src/webhook-timeouts.ts +0 -27
  194. package/src/welcome-card.test.ts +0 -81
  195. package/src/welcome-card.ts +0 -57
  196. package/test-api.ts +0 -1
  197. package/tsconfig.json +0 -16
@@ -1,125 +0,0 @@
1
- import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
2
- import {
3
- DEFAULT_ACCOUNT_ID,
4
- createChannelPairingController,
5
- evaluateSenderGroupAccessForPolicy,
6
- isDangerousNameMatchingEnabled,
7
- readStoreAllowFromForDmPolicy,
8
- resolveDefaultGroupPolicy,
9
- resolveDmGroupAccessWithLists,
10
- resolveEffectiveAllowFromLists,
11
- resolveSenderScopedGroupPolicy,
12
- type OpenClawConfig,
13
- } from "../../runtime-api.js";
14
- import { normalizeMSTeamsConversationId } from "../inbound.js";
15
- import { resolveMSTeamsAllowlistMatch, resolveMSTeamsRouteConfig } from "../policy.js";
16
- import { getMSTeamsRuntime } from "../runtime.js";
17
- import type { MSTeamsTurnContext } from "../sdk-types.js";
18
-
19
- export async function resolveMSTeamsSenderAccess(params: {
20
- cfg: OpenClawConfig;
21
- activity: MSTeamsTurnContext["activity"];
22
- }) {
23
- const activity = params.activity;
24
- const msteamsCfg = params.cfg.channels?.msteams;
25
- const conversationId = normalizeMSTeamsConversationId(activity.conversation?.id ?? "unknown");
26
- const convType = normalizeOptionalLowercaseString(activity.conversation?.conversationType);
27
- const isDirectMessage = convType === "personal" || (!convType && !activity.conversation?.isGroup);
28
- const senderId = activity.from?.aadObjectId ?? activity.from?.id ?? "unknown";
29
- const senderName = activity.from?.name ?? activity.from?.id ?? senderId;
30
-
31
- const core = getMSTeamsRuntime();
32
- const pairing = createChannelPairingController({
33
- core,
34
- channel: "msteams",
35
- accountId: DEFAULT_ACCOUNT_ID,
36
- });
37
- const dmPolicy = msteamsCfg?.dmPolicy ?? "pairing";
38
- const storedAllowFrom = await readStoreAllowFromForDmPolicy({
39
- provider: "msteams",
40
- accountId: pairing.accountId,
41
- dmPolicy,
42
- readStore: pairing.readStoreForDmPolicy,
43
- });
44
- const configuredDmAllowFrom = msteamsCfg?.allowFrom ?? [];
45
- const groupAllowFrom = msteamsCfg?.groupAllowFrom;
46
- const resolvedAllowFromLists = resolveEffectiveAllowFromLists({
47
- allowFrom: configuredDmAllowFrom,
48
- groupAllowFrom,
49
- storeAllowFrom: storedAllowFrom,
50
- dmPolicy,
51
- });
52
- const defaultGroupPolicy = resolveDefaultGroupPolicy(params.cfg);
53
- const groupPolicy =
54
- !isDirectMessage && msteamsCfg
55
- ? (msteamsCfg.groupPolicy ?? defaultGroupPolicy ?? "allowlist")
56
- : "disabled";
57
- const effectiveGroupAllowFrom = resolvedAllowFromLists.effectiveGroupAllowFrom;
58
- const allowNameMatching = isDangerousNameMatchingEnabled(msteamsCfg);
59
- const channelGate = resolveMSTeamsRouteConfig({
60
- cfg: msteamsCfg,
61
- teamId: activity.channelData?.team?.id,
62
- teamName: activity.channelData?.team?.name,
63
- conversationId,
64
- channelName: activity.channelData?.channel?.name,
65
- allowNameMatching,
66
- });
67
-
68
- // When a route-level (team/channel) allowlist is configured but the sender allowlist is
69
- // empty, resolveSenderScopedGroupPolicy would otherwise downgrade the policy to "open",
70
- // allowing any sender. To close this bypass (GHSA-g7cr-9h7q-4qxq), treat an empty sender
71
- // allowlist as deny-all whenever the route allowlist is active.
72
- const senderGroupPolicy =
73
- channelGate.allowlistConfigured && effectiveGroupAllowFrom.length === 0
74
- ? groupPolicy
75
- : resolveSenderScopedGroupPolicy({
76
- groupPolicy,
77
- groupAllowFrom: effectiveGroupAllowFrom,
78
- });
79
- const access = resolveDmGroupAccessWithLists({
80
- isGroup: !isDirectMessage,
81
- dmPolicy,
82
- groupPolicy: senderGroupPolicy,
83
- allowFrom: configuredDmAllowFrom,
84
- groupAllowFrom,
85
- storeAllowFrom: storedAllowFrom,
86
- groupAllowFromFallbackToAllowFrom: false,
87
- isSenderAllowed: (allowFrom) =>
88
- resolveMSTeamsAllowlistMatch({
89
- allowFrom,
90
- senderId,
91
- senderName,
92
- allowNameMatching,
93
- }).allowed,
94
- });
95
- const senderGroupAccess = evaluateSenderGroupAccessForPolicy({
96
- groupPolicy,
97
- groupAllowFrom: effectiveGroupAllowFrom,
98
- senderId,
99
- isSenderAllowed: (_senderId, allowFrom) =>
100
- resolveMSTeamsAllowlistMatch({
101
- allowFrom,
102
- senderId,
103
- senderName,
104
- allowNameMatching,
105
- }).allowed,
106
- });
107
-
108
- return {
109
- msteamsCfg,
110
- pairing,
111
- isDirectMessage,
112
- conversationId,
113
- senderId,
114
- senderName,
115
- dmPolicy,
116
- channelGate,
117
- access,
118
- senderGroupAccess,
119
- configuredDmAllowFrom,
120
- effectiveDmAllowFrom: access.effectiveAllowFrom,
121
- effectiveGroupAllowFrom,
122
- allowNameMatching,
123
- groupPolicy,
124
- };
125
- }
@@ -1,289 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
-
3
- vi.mock("../attachments.js", () => ({
4
- downloadMSTeamsAttachments: vi.fn(async () => []),
5
- downloadMSTeamsGraphMedia: vi.fn(async () => ({ media: [] })),
6
- downloadMSTeamsBotFrameworkAttachments: vi.fn(async () => ({ media: [], attachmentCount: 0 })),
7
- buildMSTeamsGraphMessageUrls: vi.fn(() => [
8
- "https://graph.microsoft.com/v1.0/chats/c/messages/m",
9
- ]),
10
- extractMSTeamsHtmlAttachmentIds: vi.fn(() => ["att-0", "att-1"]),
11
- isBotFrameworkPersonalChatId: vi.fn((id: string | null | undefined) => {
12
- if (typeof id !== "string") {
13
- return false;
14
- }
15
- return id.startsWith("a:") || id.startsWith("8:orgid:");
16
- }),
17
- }));
18
-
19
- import {
20
- buildMSTeamsGraphMessageUrls,
21
- downloadMSTeamsAttachments,
22
- downloadMSTeamsBotFrameworkAttachments,
23
- downloadMSTeamsGraphMedia,
24
- extractMSTeamsHtmlAttachmentIds,
25
- } from "../attachments.js";
26
- import { resolveMSTeamsInboundMedia } from "./inbound-media.js";
27
-
28
- const baseParams = {
29
- maxBytes: 1024 * 1024,
30
- tokenProvider: { getAccessToken: vi.fn(async () => "token") },
31
- conversationType: "personal",
32
- conversationId: "19:user_bot@unq.gbl.spaces",
33
- activity: { id: "msg-1", replyToId: undefined, channelData: {} },
34
- log: { debug: vi.fn() },
35
- };
36
-
37
- describe("resolveMSTeamsInboundMedia graph fallback trigger", () => {
38
- it("triggers Graph fallback when HTML contains <attachment> tags", async () => {
39
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
40
- vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce(["att-0"]);
41
- vi.mocked(downloadMSTeamsGraphMedia).mockResolvedValue({
42
- media: [{ path: "/tmp/img.png", contentType: "image/png", placeholder: "[image]" }],
43
- });
44
-
45
- await resolveMSTeamsInboundMedia({
46
- ...baseParams,
47
- attachments: [
48
- {
49
- contentType: "text/html",
50
- content: '<div>A file <attachment id="att-0"></attachment></div>',
51
- },
52
- ],
53
- });
54
-
55
- expect(buildMSTeamsGraphMessageUrls).toHaveBeenCalled();
56
- expect(downloadMSTeamsGraphMedia).toHaveBeenCalled();
57
- });
58
-
59
- it("does NOT trigger Graph fallback for mention-only HTML (no <attachment> tags)", async () => {
60
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
61
- // Mention cards include `<at>` markers but no `<attachment id="...">`,
62
- // so the extractor returns an empty ID list. The fallback must skip.
63
- vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce([]);
64
- vi.mocked(downloadMSTeamsGraphMedia).mockClear();
65
- vi.mocked(buildMSTeamsGraphMessageUrls).mockClear();
66
-
67
- await resolveMSTeamsInboundMedia({
68
- ...baseParams,
69
- attachments: [
70
- {
71
- contentType: "text/html",
72
- content: '<div><at id="0">Bot</at> hello there</div>',
73
- },
74
- ],
75
- });
76
-
77
- expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
78
- expect(buildMSTeamsGraphMessageUrls).not.toHaveBeenCalled();
79
- });
80
-
81
- it("does NOT trigger Graph fallback when no attachments are text/html", async () => {
82
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
83
- // No HTML attachments at all → extractor returns [].
84
- vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce([]);
85
- vi.mocked(downloadMSTeamsGraphMedia).mockClear();
86
- vi.mocked(buildMSTeamsGraphMessageUrls).mockClear();
87
-
88
- await resolveMSTeamsInboundMedia({
89
- ...baseParams,
90
- attachments: [
91
- { contentType: "image/png", contentUrl: "https://example.com/img.png" },
92
- { contentType: "application/pdf", contentUrl: "https://example.com/doc.pdf" },
93
- ],
94
- });
95
-
96
- expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
97
- });
98
-
99
- it("does NOT trigger Graph fallback when direct download succeeds", async () => {
100
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([
101
- { path: "/tmp/img.png", contentType: "image/png", placeholder: "[image]" },
102
- ]);
103
- vi.mocked(downloadMSTeamsGraphMedia).mockClear();
104
-
105
- await resolveMSTeamsInboundMedia({
106
- ...baseParams,
107
- attachments: [
108
- {
109
- contentType: "text/html",
110
- content: '<div><attachment id="att-0"></attachment></div>',
111
- },
112
- ],
113
- });
114
-
115
- expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
116
- });
117
-
118
- it("forwards log through to downloadMSTeamsGraphMedia for diagnostics", async () => {
119
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
120
- vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce(["att-0"]);
121
- vi.mocked(downloadMSTeamsGraphMedia).mockClear();
122
- vi.mocked(downloadMSTeamsGraphMedia).mockResolvedValue({ media: [] });
123
- const log = { debug: vi.fn() };
124
-
125
- await resolveMSTeamsInboundMedia({
126
- ...baseParams,
127
- log,
128
- attachments: [
129
- {
130
- contentType: "text/html",
131
- content: '<div><attachment id="att-0"></attachment></div>',
132
- },
133
- ],
134
- });
135
-
136
- const call = vi.mocked(downloadMSTeamsGraphMedia).mock.calls[0]?.[0];
137
- // The monitor handler's logger is forwarded so graph.ts can report
138
- // message fetch failures instead of swallowing them (#51749).
139
- expect(call?.logger).toBe(log);
140
- expect(log.debug).toHaveBeenCalledWith(
141
- "graph media fetch empty",
142
- expect.objectContaining({ attachmentIdCount: 1 }),
143
- );
144
- });
145
- });
146
-
147
- describe("resolveMSTeamsInboundMedia bot framework DM routing", () => {
148
- const dmParams = {
149
- ...baseParams,
150
- conversationType: "personal",
151
- conversationId: "a:1dRsHCobZ1AxURzY05Dc",
152
- serviceUrl: "https://smba.trafficmanager.net/amer/",
153
- };
154
-
155
- it("routes 'a:' conversation IDs through the Bot Framework attachment endpoint", async () => {
156
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
157
- vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
158
- vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockResolvedValue({
159
- media: [
160
- {
161
- path: "/tmp/report.pdf",
162
- contentType: "application/pdf",
163
- placeholder: "<media:document>",
164
- },
165
- ],
166
- attachmentCount: 1,
167
- });
168
- vi.mocked(downloadMSTeamsGraphMedia).mockClear();
169
-
170
- const mediaList = await resolveMSTeamsInboundMedia({
171
- ...dmParams,
172
- attachments: [
173
- {
174
- contentType: "text/html",
175
- content: '<div>A file <attachment id="att-0"></attachment></div>',
176
- },
177
- ],
178
- });
179
-
180
- expect(downloadMSTeamsBotFrameworkAttachments).toHaveBeenCalledTimes(1);
181
- const call = vi.mocked(downloadMSTeamsBotFrameworkAttachments).mock.calls[0]?.[0];
182
- expect(call?.serviceUrl).toBe(dmParams.serviceUrl);
183
- expect(call?.attachmentIds).toEqual(["att-0", "att-1"]);
184
- expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
185
- expect(mediaList).toHaveLength(1);
186
- expect(mediaList[0].path).toBe("/tmp/report.pdf");
187
- });
188
-
189
- it("skips the Graph fallback entirely for 'a:' conversation IDs", async () => {
190
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
191
- vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
192
- vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockResolvedValue({
193
- media: [],
194
- attachmentCount: 1,
195
- });
196
- vi.mocked(downloadMSTeamsGraphMedia).mockClear();
197
- vi.mocked(buildMSTeamsGraphMessageUrls).mockClear();
198
-
199
- await resolveMSTeamsInboundMedia({
200
- ...dmParams,
201
- attachments: [
202
- {
203
- contentType: "text/html",
204
- content: '<div><attachment id="att-0"></attachment></div>',
205
- },
206
- ],
207
- });
208
-
209
- expect(downloadMSTeamsBotFrameworkAttachments).toHaveBeenCalled();
210
- expect(buildMSTeamsGraphMessageUrls).not.toHaveBeenCalled();
211
- expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
212
- });
213
-
214
- it("does NOT call the Bot Framework endpoint for Graph-compatible '19:' IDs", async () => {
215
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
216
- vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
217
- vi.mocked(downloadMSTeamsGraphMedia).mockResolvedValue({ media: [] });
218
-
219
- await resolveMSTeamsInboundMedia({
220
- ...baseParams,
221
- conversationId: "19:abc@thread.tacv2",
222
- serviceUrl: "https://smba.trafficmanager.net/amer/",
223
- attachments: [
224
- {
225
- contentType: "text/html",
226
- content: '<div><attachment id="att-0"></attachment></div>',
227
- },
228
- ],
229
- });
230
-
231
- expect(downloadMSTeamsBotFrameworkAttachments).not.toHaveBeenCalled();
232
- expect(downloadMSTeamsGraphMedia).toHaveBeenCalled();
233
- });
234
-
235
- it("skips BF DM attachment fetch entirely when HTML has no <attachment> tags", async () => {
236
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
237
- vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
238
- vi.mocked(downloadMSTeamsGraphMedia).mockClear();
239
- // Mention-only HTML (no `<attachment id="...">` tag) → extractor
240
- // returns []. The fallback skips both the Bot Framework and Graph
241
- // paths so we do not emit spurious 404 diagnostics (#58617).
242
- vi.mocked(extractMSTeamsHtmlAttachmentIds).mockReturnValueOnce([]);
243
-
244
- await resolveMSTeamsInboundMedia({
245
- ...dmParams,
246
- attachments: [
247
- {
248
- contentType: "text/html",
249
- content: '<div><at id="0">Bot</at> hello</div>',
250
- },
251
- ],
252
- });
253
-
254
- expect(downloadMSTeamsBotFrameworkAttachments).not.toHaveBeenCalled();
255
- expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
256
- });
257
-
258
- it("logs when serviceUrl is missing for a BF DM with HTML content", async () => {
259
- vi.mocked(downloadMSTeamsAttachments).mockResolvedValue([]);
260
- vi.mocked(downloadMSTeamsBotFrameworkAttachments).mockClear();
261
- vi.mocked(downloadMSTeamsGraphMedia).mockClear();
262
- vi.mocked(buildMSTeamsGraphMessageUrls).mockClear();
263
- const log = { debug: vi.fn() };
264
-
265
- await resolveMSTeamsInboundMedia({
266
- ...baseParams,
267
- log,
268
- conversationType: "personal",
269
- conversationId: "a:bf-dm-id",
270
- attachments: [
271
- {
272
- contentType: "text/html",
273
- content: '<div><attachment id="att-0"></attachment></div>',
274
- },
275
- ],
276
- });
277
-
278
- expect(downloadMSTeamsBotFrameworkAttachments).not.toHaveBeenCalled();
279
- // Graph fallback is also skipped because the ID is 'a:'
280
- expect(downloadMSTeamsGraphMedia).not.toHaveBeenCalled();
281
- expect(log.debug).toHaveBeenCalledWith(
282
- "bot framework attachment skipped (missing serviceUrl)",
283
- expect.objectContaining({
284
- conversationType: "personal",
285
- conversationId: "a:bf-dm-id",
286
- }),
287
- );
288
- });
289
- });
@@ -1,180 +0,0 @@
1
- import {
2
- buildMSTeamsGraphMessageUrls,
3
- downloadMSTeamsAttachments,
4
- downloadMSTeamsBotFrameworkAttachments,
5
- downloadMSTeamsGraphMedia,
6
- extractMSTeamsHtmlAttachmentIds,
7
- isBotFrameworkPersonalChatId,
8
- type MSTeamsAccessTokenProvider,
9
- type MSTeamsAttachmentLike,
10
- type MSTeamsHtmlAttachmentSummary,
11
- type MSTeamsInboundMedia,
12
- } from "../attachments.js";
13
- import type { MSTeamsTurnContext } from "../sdk-types.js";
14
-
15
- type MSTeamsLogger = {
16
- debug?: (message: string, meta?: Record<string, unknown>) => void;
17
- warn?: (message: string, meta?: Record<string, unknown>) => void;
18
- error?: (message: string, meta?: Record<string, unknown>) => void;
19
- };
20
-
21
- export async function resolveMSTeamsInboundMedia(params: {
22
- attachments: MSTeamsAttachmentLike[];
23
- htmlSummary?: MSTeamsHtmlAttachmentSummary;
24
- maxBytes: number;
25
- allowHosts?: string[];
26
- authAllowHosts?: string[];
27
- tokenProvider: MSTeamsAccessTokenProvider;
28
- conversationType: string;
29
- conversationId: string;
30
- conversationMessageId?: string;
31
- serviceUrl?: string;
32
- activity: Pick<MSTeamsTurnContext["activity"], "id" | "replyToId" | "channelData">;
33
- log: MSTeamsLogger;
34
- /** When true, embeds original filename in stored path for later extraction. */
35
- preserveFilenames?: boolean;
36
- }): Promise<MSTeamsInboundMedia[]> {
37
- const {
38
- attachments,
39
- htmlSummary,
40
- maxBytes,
41
- tokenProvider,
42
- allowHosts,
43
- conversationType,
44
- conversationId,
45
- conversationMessageId,
46
- serviceUrl,
47
- activity,
48
- log,
49
- preserveFilenames,
50
- } = params;
51
-
52
- let mediaList = await downloadMSTeamsAttachments({
53
- attachments,
54
- maxBytes,
55
- tokenProvider,
56
- allowHosts,
57
- authAllowHosts: params.authAllowHosts,
58
- preserveFilenames,
59
- logger: log,
60
- });
61
-
62
- if (mediaList.length === 0) {
63
- // Gate the Graph/Bot Framework media fallback on the presence of real
64
- // `<attachment id="...">` tags inside any `text/html` attachment. Teams
65
- // delivers @mention cards and other chrome as `text/html` attachments
66
- // too, so keying off contentType alone produces spurious 404 diagnostics
67
- // for every mention-only message and masks real file attachments (#58617).
68
- const attachmentIds = extractMSTeamsHtmlAttachmentIds(attachments);
69
- const hasHtmlFileAttachment = attachmentIds.length > 0;
70
-
71
- // Personal DMs with the bot use Bot Framework conversation IDs (`a:...`
72
- // or `8:orgid:...`) which Graph's `/chats/{id}` endpoint rejects with
73
- // "Invalid ThreadId". Fetch media via the Bot Framework v3 attachments
74
- // endpoint instead, which speaks the same identifier space.
75
- if (hasHtmlFileAttachment && isBotFrameworkPersonalChatId(conversationId)) {
76
- if (!serviceUrl) {
77
- log.debug?.("bot framework attachment skipped (missing serviceUrl)", {
78
- conversationType,
79
- conversationId,
80
- });
81
- } else {
82
- const bfMedia = await downloadMSTeamsBotFrameworkAttachments({
83
- serviceUrl,
84
- attachmentIds,
85
- tokenProvider,
86
- maxBytes,
87
- allowHosts,
88
- authAllowHosts: params.authAllowHosts,
89
- preserveFilenames,
90
- });
91
- if (bfMedia.media.length > 0) {
92
- mediaList = bfMedia.media;
93
- } else {
94
- log.debug?.("bot framework attachments fetch empty", {
95
- conversationType,
96
- attachmentCount: bfMedia.attachmentCount ?? attachmentIds.length,
97
- });
98
- }
99
- }
100
- }
101
-
102
- if (
103
- hasHtmlFileAttachment &&
104
- mediaList.length === 0 &&
105
- !isBotFrameworkPersonalChatId(conversationId)
106
- ) {
107
- const messageUrls = buildMSTeamsGraphMessageUrls({
108
- conversationType,
109
- conversationId,
110
- messageId: activity.id ?? undefined,
111
- replyToId: activity.replyToId ?? undefined,
112
- conversationMessageId,
113
- channelData: activity.channelData,
114
- });
115
- if (messageUrls.length === 0) {
116
- log.debug?.("graph message url unavailable", {
117
- conversationType,
118
- hasChannelData: Boolean(activity.channelData),
119
- messageId: activity.id ?? undefined,
120
- replyToId: activity.replyToId ?? undefined,
121
- });
122
- } else {
123
- const attempts: Array<{
124
- url: string;
125
- hostedStatus?: number;
126
- attachmentStatus?: number;
127
- hostedCount?: number;
128
- attachmentCount?: number;
129
- tokenError?: boolean;
130
- }> = [];
131
- for (const messageUrl of messageUrls) {
132
- const graphMedia = await downloadMSTeamsGraphMedia({
133
- messageUrl,
134
- tokenProvider,
135
- maxBytes,
136
- allowHosts,
137
- authAllowHosts: params.authAllowHosts,
138
- preserveFilenames,
139
- log,
140
- logger: log,
141
- });
142
- attempts.push({
143
- url: messageUrl,
144
- hostedStatus: graphMedia.hostedStatus,
145
- attachmentStatus: graphMedia.attachmentStatus,
146
- hostedCount: graphMedia.hostedCount,
147
- attachmentCount: graphMedia.attachmentCount,
148
- tokenError: graphMedia.tokenError,
149
- });
150
- if (graphMedia.media.length > 0) {
151
- mediaList = graphMedia.media;
152
- break;
153
- }
154
- if (graphMedia.tokenError) {
155
- break;
156
- }
157
- }
158
- if (mediaList.length === 0) {
159
- log.debug?.("graph media fetch empty", {
160
- attempts,
161
- attachmentIdCount: attachmentIds.length,
162
- });
163
- }
164
- }
165
- }
166
- }
167
-
168
- if (mediaList.length > 0) {
169
- log.debug?.("downloaded attachments", { count: mediaList.length });
170
- } else if (htmlSummary?.imgTags) {
171
- log.debug?.("inline images detected but none downloaded", {
172
- imgTags: htmlSummary.imgTags,
173
- srcHosts: htmlSummary.srcHosts,
174
- dataImages: htmlSummary.dataImages,
175
- cidImages: htmlSummary.cidImages,
176
- });
177
- }
178
-
179
- return mediaList;
180
- }
@@ -1,28 +0,0 @@
1
- import { vi } from "vitest";
2
-
3
- const runtimeApiMockState = vi.hoisted(() => ({
4
- dispatchReplyFromConfigWithSettledDispatcher: vi.fn(async (params: { ctxPayload: unknown }) => ({
5
- queuedFinal: false,
6
- counts: {},
7
- capturedCtxPayload: params.ctxPayload,
8
- })),
9
- }));
10
-
11
- export function getRuntimeApiMockState() {
12
- return runtimeApiMockState;
13
- }
14
-
15
- vi.mock("openclaw/plugin-sdk/inbound-reply-dispatch", () => {
16
- return {
17
- dispatchReplyFromConfigWithSettledDispatcher:
18
- runtimeApiMockState.dispatchReplyFromConfigWithSettledDispatcher,
19
- };
20
- });
21
-
22
- vi.mock("../reply-dispatcher.js", () => ({
23
- createMSTeamsReplyDispatcher: () => ({
24
- dispatcher: {},
25
- replyOptions: {},
26
- markDispatchIdle: vi.fn(),
27
- }),
28
- }));