@openclaw/msteams 2026.5.2 → 2026.5.3-beta.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 (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,215 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import type { OpenClawConfig } from "../runtime-api.js";
3
- import { getChannelInfoMSTeams, listChannelsMSTeams } from "./graph-teams.js";
4
-
5
- const mockState = vi.hoisted(() => ({
6
- resolveGraphToken: vi.fn(),
7
- fetchGraphJson: vi.fn(),
8
- }));
9
-
10
- vi.mock("./graph.js", async (importOriginal) => {
11
- const actual = await importOriginal<typeof import("./graph.js")>();
12
- return {
13
- ...actual,
14
- resolveGraphToken: mockState.resolveGraphToken,
15
- fetchGraphJson: mockState.fetchGraphJson,
16
- };
17
- });
18
-
19
- const TOKEN = "test-graph-token";
20
-
21
- describe("listChannelsMSTeams", () => {
22
- beforeEach(() => {
23
- mockState.resolveGraphToken.mockReset().mockResolvedValue(TOKEN);
24
- mockState.fetchGraphJson.mockReset();
25
- });
26
-
27
- it("returns channels with all fields mapped", async () => {
28
- mockState.fetchGraphJson.mockResolvedValue({
29
- value: [
30
- {
31
- id: "ch-1",
32
- displayName: "General",
33
- description: "The default channel",
34
- membershipType: "standard",
35
- },
36
- {
37
- id: "ch-2",
38
- displayName: "Engineering",
39
- description: "Engineering discussions",
40
- membershipType: "private",
41
- },
42
- ],
43
- });
44
-
45
- const result = await listChannelsMSTeams({
46
- cfg: {} as OpenClawConfig,
47
- teamId: "team-abc",
48
- });
49
-
50
- expect(result.channels).toEqual([
51
- {
52
- id: "ch-1",
53
- displayName: "General",
54
- description: "The default channel",
55
- membershipType: "standard",
56
- },
57
- {
58
- id: "ch-2",
59
- displayName: "Engineering",
60
- description: "Engineering discussions",
61
- membershipType: "private",
62
- },
63
- ]);
64
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
65
- token: TOKEN,
66
- path: `/teams/${encodeURIComponent("team-abc")}/channels?$select=id,displayName,description,membershipType`,
67
- });
68
- });
69
-
70
- it("returns empty array when team has no channels", async () => {
71
- mockState.fetchGraphJson.mockResolvedValue({ value: [] });
72
-
73
- const result = await listChannelsMSTeams({
74
- cfg: {} as OpenClawConfig,
75
- teamId: "team-empty",
76
- });
77
-
78
- expect(result.channels).toEqual([]);
79
- });
80
-
81
- it("returns empty array when value is undefined", async () => {
82
- mockState.fetchGraphJson.mockResolvedValue({});
83
-
84
- const result = await listChannelsMSTeams({
85
- cfg: {} as OpenClawConfig,
86
- teamId: "team-no-value",
87
- });
88
-
89
- expect(result.channels).toEqual([]);
90
- });
91
-
92
- it("follows @odata.nextLink across multiple pages", async () => {
93
- mockState.fetchGraphJson
94
- .mockResolvedValueOnce({
95
- value: [
96
- { id: "ch-1", displayName: "General", description: null, membershipType: "standard" },
97
- ],
98
- "@odata.nextLink":
99
- "https://graph.microsoft.com/v1.0/teams/team-paged/channels?$select=id,displayName,description,membershipType&$skip=1",
100
- })
101
- .mockResolvedValueOnce({
102
- value: [
103
- { id: "ch-2", displayName: "Random", description: "Fun", membershipType: "standard" },
104
- ],
105
- "@odata.nextLink":
106
- "https://graph.microsoft.com/v1.0/teams/team-paged/channels?$select=id,displayName,description,membershipType&$skip=2",
107
- })
108
- .mockResolvedValueOnce({
109
- value: [
110
- { id: "ch-3", displayName: "Private", description: null, membershipType: "private" },
111
- ],
112
- });
113
-
114
- const result = await listChannelsMSTeams({
115
- cfg: {} as OpenClawConfig,
116
- teamId: "team-paged",
117
- });
118
-
119
- expect(result.channels).toHaveLength(3);
120
- expect(result.channels.map((ch) => ch.id)).toEqual(["ch-1", "ch-2", "ch-3"]);
121
- expect(result.truncated).toBe(false);
122
- expect(mockState.fetchGraphJson).toHaveBeenCalledTimes(3);
123
-
124
- // Second call should use the relative path stripped from the nextLink
125
- const secondCallPath = mockState.fetchGraphJson.mock.calls[1]?.[0]?.path;
126
- expect(secondCallPath).toBe(
127
- "/teams/team-paged/channels?$select=id,displayName,description,membershipType&$skip=1",
128
- );
129
- });
130
-
131
- it("stops after 10 pages to avoid runaway pagination", async () => {
132
- for (let i = 0; i < 11; i++) {
133
- mockState.fetchGraphJson.mockResolvedValueOnce({
134
- value: [
135
- {
136
- id: `ch-${i}`,
137
- displayName: `Channel ${i}`,
138
- description: null,
139
- membershipType: "standard",
140
- },
141
- ],
142
- "@odata.nextLink": `https://graph.microsoft.com/v1.0/teams/team-huge/channels?$skip=${i + 1}`,
143
- });
144
- }
145
-
146
- const result = await listChannelsMSTeams({
147
- cfg: {} as OpenClawConfig,
148
- teamId: "team-huge",
149
- });
150
-
151
- // Should stop at 10 pages even though more nextLinks are available
152
- expect(result.channels).toHaveLength(10);
153
- expect(mockState.fetchGraphJson).toHaveBeenCalledTimes(10);
154
- expect(result.truncated).toBe(true);
155
- });
156
- });
157
-
158
- describe("getChannelInfoMSTeams", () => {
159
- beforeEach(() => {
160
- mockState.resolveGraphToken.mockReset().mockResolvedValue(TOKEN);
161
- mockState.fetchGraphJson.mockReset();
162
- });
163
-
164
- it("returns channel with all fields", async () => {
165
- mockState.fetchGraphJson.mockResolvedValue({
166
- id: "ch-1",
167
- displayName: "General",
168
- description: "The default channel",
169
- membershipType: "standard",
170
- webUrl: "https://teams.microsoft.com/l/channel/ch-1/General",
171
- createdDateTime: "2026-01-15T09:00:00Z",
172
- });
173
-
174
- const result = await getChannelInfoMSTeams({
175
- cfg: {} as OpenClawConfig,
176
- teamId: "team-abc",
177
- channelId: "ch-1",
178
- });
179
-
180
- expect(result.channel).toEqual({
181
- id: "ch-1",
182
- displayName: "General",
183
- description: "The default channel",
184
- membershipType: "standard",
185
- webUrl: "https://teams.microsoft.com/l/channel/ch-1/General",
186
- createdDateTime: "2026-01-15T09:00:00Z",
187
- });
188
- expect(mockState.fetchGraphJson).toHaveBeenCalledWith({
189
- token: TOKEN,
190
- path: `/teams/${encodeURIComponent("team-abc")}/channels/${encodeURIComponent("ch-1")}?$select=id,displayName,description,membershipType,webUrl,createdDateTime`,
191
- });
192
- });
193
-
194
- it("handles missing optional fields gracefully", async () => {
195
- mockState.fetchGraphJson.mockResolvedValue({
196
- id: "ch-2",
197
- displayName: "Private Channel",
198
- });
199
-
200
- const result = await getChannelInfoMSTeams({
201
- cfg: {} as OpenClawConfig,
202
- teamId: "team-abc",
203
- channelId: "ch-2",
204
- });
205
-
206
- expect(result.channel).toEqual({
207
- id: "ch-2",
208
- displayName: "Private Channel",
209
- description: undefined,
210
- membershipType: undefined,
211
- webUrl: undefined,
212
- createdDateTime: undefined,
213
- });
214
- });
215
- });
@@ -1,114 +0,0 @@
1
- import type { OpenClawConfig } from "../runtime-api.js";
2
- import { type GraphResponse, fetchGraphJson, resolveGraphToken } from "./graph.js";
3
-
4
- // ---------------------------------------------------------------------------
5
- // Types
6
- // ---------------------------------------------------------------------------
7
-
8
- type GraphTeamsChannel = {
9
- id?: string;
10
- displayName?: string;
11
- description?: string;
12
- membershipType?: string;
13
- webUrl?: string;
14
- createdDateTime?: string;
15
- };
16
-
17
- type ListChannelsMSTeamsParams = {
18
- cfg: OpenClawConfig;
19
- teamId: string;
20
- };
21
-
22
- type ListChannelsMSTeamsResult = {
23
- channels: Array<{
24
- id: string | undefined;
25
- displayName: string | undefined;
26
- description: string | undefined;
27
- membershipType: string | undefined;
28
- }>;
29
- truncated?: boolean;
30
- };
31
-
32
- type GetChannelInfoMSTeamsParams = {
33
- cfg: OpenClawConfig;
34
- teamId: string;
35
- channelId: string;
36
- };
37
-
38
- type GetChannelInfoMSTeamsResult = {
39
- channel: {
40
- id: string | undefined;
41
- displayName: string | undefined;
42
- description: string | undefined;
43
- membershipType: string | undefined;
44
- webUrl: string | undefined;
45
- createdDateTime: string | undefined;
46
- };
47
- };
48
-
49
- // ---------------------------------------------------------------------------
50
- // List channels for a team
51
- // ---------------------------------------------------------------------------
52
-
53
- /**
54
- * List channels in a team via Graph API.
55
- * Returns id, displayName, description, and membershipType for each channel.
56
- * Follows @odata.nextLink for paginated results (up to 10 pages).
57
- */
58
- export async function listChannelsMSTeams(
59
- params: ListChannelsMSTeamsParams,
60
- ): Promise<ListChannelsMSTeamsResult> {
61
- const token = await resolveGraphToken(params.cfg);
62
- const firstPath = `/teams/${encodeURIComponent(params.teamId)}/channels?$select=id,displayName,description,membershipType`;
63
- const collected: GraphTeamsChannel[] = [];
64
- let nextPath: string | undefined = firstPath;
65
- const MAX_PAGES = 10;
66
- let page = 0;
67
- while (nextPath && page < MAX_PAGES) {
68
- type PagedChannelResponse = GraphResponse<GraphTeamsChannel> & {
69
- "@odata.nextLink"?: string;
70
- };
71
- const res: PagedChannelResponse = await fetchGraphJson<PagedChannelResponse>({
72
- token,
73
- path: nextPath,
74
- });
75
- collected.push(...(res.value ?? []));
76
- const nextLink: string | undefined = res["@odata.nextLink"];
77
- // Strip the Graph API root so fetchGraphJson receives a relative path
78
- nextPath = nextLink ? nextLink.replace("https://graph.microsoft.com/v1.0", "") : undefined;
79
- page++;
80
- }
81
- const channels = collected.map((ch) => ({
82
- id: ch.id,
83
- displayName: ch.displayName,
84
- description: ch.description,
85
- membershipType: ch.membershipType,
86
- }));
87
- return { channels, truncated: !!nextPath };
88
- }
89
-
90
- // ---------------------------------------------------------------------------
91
- // Get channel info
92
- // ---------------------------------------------------------------------------
93
-
94
- /**
95
- * Get detailed information about a single channel in a team via Graph API.
96
- * Returns id, displayName, description, membershipType, webUrl, and createdDateTime.
97
- */
98
- export async function getChannelInfoMSTeams(
99
- params: GetChannelInfoMSTeamsParams,
100
- ): Promise<GetChannelInfoMSTeamsResult> {
101
- const token = await resolveGraphToken(params.cfg);
102
- const path = `/teams/${encodeURIComponent(params.teamId)}/channels/${encodeURIComponent(params.channelId)}?$select=id,displayName,description,membershipType,webUrl,createdDateTime`;
103
- const ch = await fetchGraphJson<GraphTeamsChannel>({ token, path });
104
- return {
105
- channel: {
106
- id: ch.id,
107
- displayName: ch.displayName,
108
- description: ch.description,
109
- membershipType: ch.membershipType,
110
- webUrl: ch.webUrl,
111
- createdDateTime: ch.createdDateTime,
112
- },
113
- };
114
- }
@@ -1,246 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import {
3
- _teamGroupIdCacheForTest,
4
- fetchChannelMessage,
5
- fetchThreadReplies,
6
- formatThreadContext,
7
- resolveTeamGroupId,
8
- stripHtmlFromTeamsMessage,
9
- } from "./graph-thread.js";
10
- import { fetchGraphJson } from "./graph.js";
11
-
12
- vi.mock("./graph.js", () => ({
13
- fetchGraphJson: vi.fn(),
14
- }));
15
-
16
- describe("stripHtmlFromTeamsMessage", () => {
17
- it("preserves @mention display names from <at> tags", () => {
18
- expect(stripHtmlFromTeamsMessage("<at>Alice</at> hello")).toBe("@Alice hello");
19
- });
20
-
21
- it("strips other HTML tags", () => {
22
- expect(stripHtmlFromTeamsMessage("<p>Hello <b>world</b></p>")).toBe("Hello world");
23
- });
24
-
25
- it("decodes common HTML entities", () => {
26
- expect(stripHtmlFromTeamsMessage("&amp; &lt;b&gt; &quot;x&quot; &#39;y&#39; &nbsp;z")).toBe(
27
- "& <b> \"x\" 'y' z",
28
- );
29
- });
30
-
31
- it("normalizes multiple whitespace to single space", () => {
32
- expect(stripHtmlFromTeamsMessage("hello world")).toBe("hello world");
33
- });
34
-
35
- it("handles <at> tags with attributes", () => {
36
- expect(stripHtmlFromTeamsMessage('<at id="123">Bob</at> please review')).toBe(
37
- "@Bob please review",
38
- );
39
- });
40
-
41
- it("returns empty string for empty input", () => {
42
- expect(stripHtmlFromTeamsMessage("")).toBe("");
43
- });
44
- });
45
-
46
- describe("resolveTeamGroupId", () => {
47
- beforeEach(() => {
48
- vi.mocked(fetchGraphJson).mockReset();
49
- _teamGroupIdCacheForTest.clear();
50
- });
51
-
52
- it("fetches team id from Graph and caches it", async () => {
53
- vi.mocked(fetchGraphJson).mockResolvedValueOnce({ id: "group-guid-1" } as never);
54
-
55
- const result = await resolveTeamGroupId("tok", "team-123");
56
- expect(result).toBe("group-guid-1");
57
- expect(fetchGraphJson).toHaveBeenCalledWith({
58
- token: "tok",
59
- path: "/teams/team-123?$select=id",
60
- });
61
- });
62
-
63
- it("returns cached value without calling Graph again", async () => {
64
- vi.mocked(fetchGraphJson).mockResolvedValueOnce({ id: "group-guid-2" } as never);
65
-
66
- await resolveTeamGroupId("tok", "team-456");
67
- await resolveTeamGroupId("tok", "team-456");
68
-
69
- expect(fetchGraphJson).toHaveBeenCalledTimes(1);
70
- });
71
-
72
- it("falls back to conversationTeamId when Graph returns no id", async () => {
73
- vi.mocked(fetchGraphJson).mockResolvedValueOnce({} as never);
74
-
75
- const result = await resolveTeamGroupId("tok", "team-fallback");
76
- expect(result).toBe("team-fallback");
77
- });
78
- });
79
-
80
- describe("fetchChannelMessage", () => {
81
- beforeEach(() => {
82
- vi.mocked(fetchGraphJson).mockReset();
83
- });
84
-
85
- it("fetches the parent message with correct path", async () => {
86
- const mockMsg = { id: "msg-1", body: { content: "hello", contentType: "text" } };
87
- vi.mocked(fetchGraphJson).mockResolvedValueOnce(mockMsg as never);
88
-
89
- const result = await fetchChannelMessage("tok", "group-1", "channel-1", "msg-1");
90
-
91
- expect(result).toEqual(mockMsg);
92
- expect(fetchGraphJson).toHaveBeenCalledWith({
93
- token: "tok",
94
- path: "/teams/group-1/channels/channel-1/messages/msg-1?$select=id,from,body,createdDateTime",
95
- });
96
- });
97
-
98
- it("returns undefined on fetch error", async () => {
99
- vi.mocked(fetchGraphJson).mockRejectedValueOnce(new Error("forbidden") as never);
100
-
101
- const result = await fetchChannelMessage("tok", "group-1", "channel-1", "msg-1");
102
- expect(result).toBeUndefined();
103
- });
104
-
105
- it("URL-encodes group, channel, and message IDs", async () => {
106
- vi.mocked(fetchGraphJson).mockResolvedValueOnce({} as never);
107
-
108
- await fetchChannelMessage("tok", "g/1", "c/2", "m/3");
109
-
110
- expect(fetchGraphJson).toHaveBeenCalledWith({
111
- token: "tok",
112
- path: "/teams/g%2F1/channels/c%2F2/messages/m%2F3?$select=id,from,body,createdDateTime",
113
- });
114
- });
115
- });
116
-
117
- describe("fetchThreadReplies", () => {
118
- beforeEach(() => {
119
- vi.mocked(fetchGraphJson).mockReset();
120
- });
121
-
122
- it("fetches replies with correct path and default limit", async () => {
123
- vi.mocked(fetchGraphJson).mockResolvedValueOnce({
124
- value: [{ id: "reply-1" }, { id: "reply-2" }],
125
- } as never);
126
-
127
- const result = await fetchThreadReplies("tok", "group-1", "channel-1", "msg-1");
128
-
129
- expect(result).toHaveLength(2);
130
- expect(fetchGraphJson).toHaveBeenCalledWith({
131
- token: "tok",
132
- path: "/teams/group-1/channels/channel-1/messages/msg-1/replies?$top=50&$select=id,from,body,createdDateTime",
133
- });
134
- });
135
-
136
- it("clamps limit to 50 maximum", async () => {
137
- vi.mocked(fetchGraphJson).mockResolvedValueOnce({ value: [] } as never);
138
-
139
- await fetchThreadReplies("tok", "g", "c", "m", 200);
140
-
141
- const path = vi.mocked(fetchGraphJson).mock.calls[0]?.[0]?.path ?? "";
142
- expect(path).toContain("$top=50");
143
- });
144
-
145
- it("clamps limit to 1 minimum", async () => {
146
- vi.mocked(fetchGraphJson).mockResolvedValueOnce({ value: [] } as never);
147
-
148
- await fetchThreadReplies("tok", "g", "c", "m", 0);
149
-
150
- const path = vi.mocked(fetchGraphJson).mock.calls[0]?.[0]?.path ?? "";
151
- expect(path).toContain("$top=1");
152
- });
153
-
154
- it("returns empty array when value is missing", async () => {
155
- vi.mocked(fetchGraphJson).mockResolvedValueOnce({} as never);
156
-
157
- const result = await fetchThreadReplies("tok", "g", "c", "m");
158
- expect(result).toEqual([]);
159
- });
160
- });
161
-
162
- describe("formatThreadContext", () => {
163
- it("formats messages as sender: content lines", () => {
164
- const messages = [
165
- {
166
- id: "m1",
167
- from: { user: { displayName: "Alice" } },
168
- body: { content: "Hello!", contentType: "text" },
169
- },
170
- {
171
- id: "m2",
172
- from: { user: { displayName: "Bob" } },
173
- body: { content: "World!", contentType: "text" },
174
- },
175
- ];
176
- expect(formatThreadContext(messages)).toBe("Alice: Hello!\nBob: World!");
177
- });
178
-
179
- it("skips the current message by id", () => {
180
- const messages = [
181
- {
182
- id: "m1",
183
- from: { user: { displayName: "Alice" } },
184
- body: { content: "Hello!", contentType: "text" },
185
- },
186
- {
187
- id: "m2",
188
- from: { user: { displayName: "Bob" } },
189
- body: { content: "Current", contentType: "text" },
190
- },
191
- ];
192
- expect(formatThreadContext(messages, "m2")).toBe("Alice: Hello!");
193
- });
194
-
195
- it("strips HTML from html contentType messages", () => {
196
- const messages = [
197
- {
198
- id: "m1",
199
- from: { user: { displayName: "Carol" } },
200
- body: { content: "<p>Hello <b>world</b></p>", contentType: "html" },
201
- },
202
- ];
203
- expect(formatThreadContext(messages)).toBe("Carol: Hello world");
204
- });
205
-
206
- it("uses application displayName when user is absent", () => {
207
- const messages = [
208
- {
209
- id: "m1",
210
- from: { application: { displayName: "BotApp" } },
211
- body: { content: "automated msg", contentType: "text" },
212
- },
213
- ];
214
- expect(formatThreadContext(messages)).toBe("BotApp: automated msg");
215
- });
216
-
217
- it("skips messages with empty content", () => {
218
- const messages = [
219
- {
220
- id: "m1",
221
- from: { user: { displayName: "Alice" } },
222
- body: { content: "", contentType: "text" },
223
- },
224
- {
225
- id: "m2",
226
- from: { user: { displayName: "Bob" } },
227
- body: { content: "actual content", contentType: "text" },
228
- },
229
- ];
230
- expect(formatThreadContext(messages)).toBe("Bob: actual content");
231
- });
232
-
233
- it("falls back to 'unknown' sender when from is missing", () => {
234
- const messages = [
235
- {
236
- id: "m1",
237
- body: { content: "orphan msg", contentType: "text" },
238
- },
239
- ];
240
- expect(formatThreadContext(messages)).toBe("unknown: orphan msg");
241
- });
242
-
243
- it("returns empty string for empty messages array", () => {
244
- expect(formatThreadContext([])).toBe("");
245
- });
246
- });