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