@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,147 +0,0 @@
1
- import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
2
- import type { ReplyPayload } from "../runtime-api.js";
3
- import { formatUnknownError } from "./errors.js";
4
- import type { MSTeamsMonitorLogger } from "./monitor-types.js";
5
- import type { MSTeamsTurnContext } from "./sdk-types.js";
6
- import { TeamsHttpStream } from "./streaming-message.js";
7
-
8
- // Local generic wrapper to defer union resolution. Works around a
9
- // single-file-mode limitation in the type-aware lint where imported
10
- // types resolved via extension runtime-api barrels are treated as
11
- // `error` (acting as `any`) and trip `no-redundant-type-constituents`
12
- // when combined with `undefined` in a union.
13
- type Maybe<T> = T | undefined;
14
-
15
- const INFORMATIVE_STATUS_TEXTS = [
16
- "Thinking...",
17
- "Working on that...",
18
- "Checking the details...",
19
- "Putting an answer together...",
20
- ];
21
-
22
- export function pickInformativeStatusText(random = Math.random): string {
23
- const index = Math.floor(random() * INFORMATIVE_STATUS_TEXTS.length);
24
- return INFORMATIVE_STATUS_TEXTS[index] ?? INFORMATIVE_STATUS_TEXTS[0];
25
- }
26
-
27
- export function createTeamsReplyStreamController(params: {
28
- conversationType?: string;
29
- context: MSTeamsTurnContext;
30
- feedbackLoopEnabled: boolean;
31
- log: MSTeamsMonitorLogger;
32
- random?: () => number;
33
- }) {
34
- const isPersonal = normalizeOptionalLowercaseString(params.conversationType) === "personal";
35
- const stream = isPersonal
36
- ? new TeamsHttpStream({
37
- sendActivity: (activity) => params.context.sendActivity(activity),
38
- feedbackLoopEnabled: params.feedbackLoopEnabled,
39
- onError: (err) => {
40
- params.log.debug?.(`stream error: ${formatUnknownError(err)}`);
41
- },
42
- })
43
- : undefined;
44
-
45
- let streamReceivedTokens = false;
46
- let informativeUpdateSent = false;
47
- let pendingFinalize: Promise<void> | undefined;
48
-
49
- return {
50
- async onReplyStart(): Promise<void> {
51
- if (!stream || informativeUpdateSent) {
52
- return;
53
- }
54
- informativeUpdateSent = true;
55
- await stream.sendInformativeUpdate(pickInformativeStatusText(params.random));
56
- },
57
-
58
- onPartialReply(payload: { text?: string }): void {
59
- if (!stream || !payload.text) {
60
- return;
61
- }
62
- streamReceivedTokens = true;
63
- stream.update(payload.text);
64
- },
65
-
66
- preparePayload(payload: ReplyPayload): Maybe<ReplyPayload> {
67
- if (!stream || !streamReceivedTokens) {
68
- return payload;
69
- }
70
-
71
- const hasMedia = Boolean(payload.mediaUrl || payload.mediaUrls?.length);
72
-
73
- // Stream failed after partial delivery (e.g. > 4000 chars). Send only
74
- // the unstreamed suffix via block delivery to avoid duplicate text.
75
- if (stream.isFailed) {
76
- streamReceivedTokens = false;
77
-
78
- if (!payload.text) {
79
- return payload;
80
- }
81
-
82
- const streamedLength = stream.streamedLength;
83
- if (streamedLength <= 0) {
84
- return payload;
85
- }
86
-
87
- const remainingText = payload.text.slice(streamedLength);
88
- if (!remainingText) {
89
- return hasMedia ? { ...payload, text: undefined } : undefined;
90
- }
91
-
92
- return { ...payload, text: remainingText };
93
- }
94
-
95
- if (!stream.hasContent || stream.isFinalized) {
96
- return payload;
97
- }
98
-
99
- // Stream handled this text segment. Finalize it and reset so any
100
- // subsequent text segments (after tool calls) use fallback delivery.
101
- // finalize() is idempotent; the later call in markDispatchIdle is a no-op.
102
- streamReceivedTokens = false;
103
- pendingFinalize = stream.finalize();
104
-
105
- if (!hasMedia) {
106
- return undefined;
107
- }
108
- return { ...payload, text: undefined };
109
- },
110
-
111
- async finalize(): Promise<void> {
112
- await pendingFinalize;
113
- await stream?.finalize();
114
- },
115
-
116
- hasStream(): boolean {
117
- return Boolean(stream);
118
- },
119
-
120
- /**
121
- * Whether the Teams streaming card is currently receiving LLM tokens.
122
- * Used to gate side-channel keepalive activity so we don't overlay plain
123
- * "typing" indicators on top of a live streaming card.
124
- *
125
- * Returns true only while the stream is actively chunking text into the
126
- * streaming card. The informative update (blue progress bar) is short
127
- * lived so we intentionally do not count it as "active"; this way the
128
- * typing keepalive can still fire during the informative window and
129
- * during tool chains between text segments.
130
- *
131
- * Returns false when:
132
- * - No stream exists (non-personal conversation).
133
- * - Stream has not yet received any text tokens.
134
- * - Stream has been finalized (e.g. after the first text segment, while
135
- * tools run before the next segment).
136
- */
137
- isStreamActive(): boolean {
138
- if (!stream) {
139
- return false;
140
- }
141
- if (stream.isFinalized || stream.isFailed) {
142
- return false;
143
- }
144
- return streamReceivedTokens;
145
- },
146
- };
147
- }
@@ -1,250 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- const {
4
- listTeamsByName,
5
- listChannelsForTeam,
6
- normalizeQuery,
7
- resolveGraphToken,
8
- searchGraphUsers,
9
- } = vi.hoisted(() => ({
10
- listTeamsByName: vi.fn(),
11
- listChannelsForTeam: vi.fn(),
12
- normalizeQuery: vi.fn((value: string) => value.trim().toLowerCase()),
13
- resolveGraphToken: vi.fn(async () => "graph-token"),
14
- searchGraphUsers: vi.fn(),
15
- }));
16
-
17
- vi.mock("./graph.js", () => ({
18
- listTeamsByName,
19
- listChannelsForTeam,
20
- normalizeQuery,
21
- resolveGraphToken,
22
- }));
23
-
24
- vi.mock("./graph-users.js", () => ({
25
- searchGraphUsers,
26
- }));
27
-
28
- import {
29
- looksLikeMSTeamsTargetId,
30
- resolveMSTeamsChannelAllowlist,
31
- resolveMSTeamsUserAllowlist,
32
- } from "./resolve-allowlist.js";
33
-
34
- beforeEach(() => {
35
- listTeamsByName.mockReset();
36
- listChannelsForTeam.mockReset();
37
- normalizeQuery.mockImplementation((value: string) => value.trim().toLowerCase());
38
- resolveGraphToken.mockReset().mockResolvedValue("graph-token");
39
- searchGraphUsers.mockReset();
40
- });
41
-
42
- describe("resolveMSTeamsUserAllowlist", () => {
43
- it("marks empty input unresolved", async () => {
44
- const [result] = await resolveMSTeamsUserAllowlist({ cfg: {}, entries: [" "] });
45
- expect(result).toEqual({ input: " ", resolved: false });
46
- });
47
-
48
- it("resolves first Graph user match", async () => {
49
- searchGraphUsers.mockResolvedValueOnce([
50
- { id: "user-1", displayName: "Alice One" },
51
- { id: "user-2", displayName: "Alice Two" },
52
- ]);
53
- const [result] = await resolveMSTeamsUserAllowlist({ cfg: {}, entries: ["alice"] });
54
- expect(result).toEqual({
55
- input: "alice",
56
- resolved: true,
57
- id: "user-1",
58
- name: "Alice One",
59
- note: "multiple matches; chose first",
60
- });
61
- });
62
- });
63
-
64
- describe("resolveMSTeamsChannelAllowlist", () => {
65
- it("keeps configured Teams conversation IDs resolved without Graph lookup", async () => {
66
- const [result] = await resolveMSTeamsChannelAllowlist({
67
- cfg: {},
68
- entries: ["19:team-general@thread.skype/19:roadmap@thread.skype"],
69
- });
70
-
71
- expect(result).toEqual({
72
- input: "19:team-general@thread.skype/19:roadmap@thread.skype",
73
- resolved: true,
74
- teamId: "19:team-general@thread.skype",
75
- teamName: "19:team-general@thread.skype",
76
- channelId: "19:roadmap@thread.skype",
77
- channelName: "19:roadmap@thread.skype",
78
- });
79
- expect(resolveGraphToken).not.toHaveBeenCalled();
80
- expect(listTeamsByName).not.toHaveBeenCalled();
81
- expect(listChannelsForTeam).not.toHaveBeenCalled();
82
- });
83
-
84
- it("normalizes conversation-prefixed configured channel IDs", async () => {
85
- const [result] = await resolveMSTeamsChannelAllowlist({
86
- cfg: {},
87
- entries: ["19:team-general@thread.tacv2/conversation:19:roadmap@thread.tacv2"],
88
- });
89
-
90
- expect(result).toMatchObject({
91
- resolved: true,
92
- teamId: "19:team-general@thread.tacv2",
93
- channelId: "19:roadmap@thread.tacv2",
94
- });
95
- expect(resolveGraphToken).not.toHaveBeenCalled();
96
- });
97
-
98
- it("resolves team/channel by team name + channel display name", async () => {
99
- // After the fix, listChannelsForTeam is called once and reused for both
100
- // General channel resolution and channel matching.
101
- listTeamsByName.mockResolvedValueOnce([{ id: "team-guid-1", displayName: "Product Team" }]);
102
- listChannelsForTeam.mockResolvedValueOnce([
103
- { id: "19:general-conv-id@thread.tacv2", displayName: "General" },
104
- { id: "19:roadmap-conv-id@thread.tacv2", displayName: "Roadmap" },
105
- ]);
106
-
107
- const [result] = await resolveMSTeamsChannelAllowlist({
108
- cfg: {},
109
- entries: ["Product Team/Roadmap"],
110
- });
111
-
112
- // teamId is now the General channel's conversation ID — not the Graph GUID —
113
- // because that's what Bot Framework sends as channelData.team.id at runtime.
114
- expect(result).toEqual({
115
- input: "Product Team/Roadmap",
116
- resolved: true,
117
- teamId: "19:general-conv-id@thread.tacv2",
118
- teamName: "Product Team",
119
- channelId: "19:roadmap-conv-id@thread.tacv2",
120
- channelName: "Roadmap",
121
- note: "multiple channels; chose first",
122
- });
123
- });
124
-
125
- it("uses General channel conversation ID as team key for team-only entry", async () => {
126
- // When no channel is specified we still resolve the General channel so the
127
- // stored key matches what Bot Framework sends as channelData.team.id.
128
- listTeamsByName.mockResolvedValueOnce([{ id: "guid-engineering", displayName: "Engineering" }]);
129
- listChannelsForTeam.mockResolvedValueOnce([
130
- { id: "19:eng-general@thread.tacv2", displayName: "General" },
131
- { id: "19:eng-standups@thread.tacv2", displayName: "Standups" },
132
- ]);
133
-
134
- const [result] = await resolveMSTeamsChannelAllowlist({
135
- cfg: {},
136
- entries: ["Engineering"],
137
- });
138
-
139
- expect(result).toEqual({
140
- input: "Engineering",
141
- resolved: true,
142
- teamId: "19:eng-general@thread.tacv2",
143
- teamName: "Engineering",
144
- });
145
- });
146
-
147
- it("falls back to Graph GUID when listChannelsForTeam throws", async () => {
148
- // Edge case: API call fails (rate limit, network error). We fall back to
149
- // the Graph GUID as the team key — the pre-fix behavior — so resolution
150
- // still succeeds instead of propagating the error.
151
- listTeamsByName.mockResolvedValueOnce([{ id: "guid-flaky", displayName: "Flaky Team" }]);
152
- listChannelsForTeam.mockRejectedValueOnce(new Error("429 Too Many Requests"));
153
-
154
- const [result] = await resolveMSTeamsChannelAllowlist({
155
- cfg: {},
156
- entries: ["Flaky Team"],
157
- });
158
-
159
- expect(result).toEqual({
160
- input: "Flaky Team",
161
- resolved: true,
162
- teamId: "guid-flaky",
163
- teamName: "Flaky Team",
164
- });
165
- });
166
-
167
- it("falls back to Graph GUID when General channel is not found", async () => {
168
- // Edge case: General channel was renamed or deleted. We fall back to the
169
- // Graph GUID so resolution still succeeds rather than silently breaking.
170
- listTeamsByName.mockResolvedValueOnce([{ id: "guid-ops", displayName: "Operations" }]);
171
- listChannelsForTeam.mockResolvedValueOnce([
172
- { id: "19:ops-announce@thread.tacv2", displayName: "Announcements" },
173
- { id: "19:ops-random@thread.tacv2", displayName: "Random" },
174
- ]);
175
-
176
- const [result] = await resolveMSTeamsChannelAllowlist({
177
- cfg: {},
178
- entries: ["Operations"],
179
- });
180
-
181
- expect(result).toEqual({
182
- input: "Operations",
183
- resolved: true,
184
- teamId: "guid-ops",
185
- teamName: "Operations",
186
- });
187
- });
188
- });
189
-
190
- describe("looksLikeMSTeamsTargetId", () => {
191
- // Regression suite for https://github.com/openclaw/openclaw/issues/58001:
192
- // cron announce delivery rejected valid Teams conversation ids because the
193
- // validator only matched the `conversation:`-prefixed and `@thread`-suffixed
194
- // forms. It must now accept every documented Bot Framework + Graph format.
195
- it.each([
196
- "conversation:19:abc@thread.tacv2",
197
- "conversation:a:1abc",
198
- "conversation:8:orgid:2d8c2d2c-1111-2222-3333-444444444444",
199
- ])("accepts conversation-prefixed ids (%s)", (raw) => {
200
- expect(looksLikeMSTeamsTargetId(raw)).toBe(true);
201
- });
202
-
203
- it.each(["19:AdviChannelId@thread.tacv2", "19:abc@thread.tacv2", "19:abc@thread.skype"])(
204
- "accepts bare channel/group conversation ids (%s)",
205
- (raw) => {
206
- expect(looksLikeMSTeamsTargetId(raw)).toBe(true);
207
- },
208
- );
209
-
210
- it("accepts the Graph 1:1 chat thread format", () => {
211
- expect(
212
- looksLikeMSTeamsTargetId(
213
- "19:40a1a0ed4ff24164a21955518990c197_2d8c2d2c11112222@unq.gbl.spaces",
214
- ),
215
- ).toBe(true);
216
- });
217
-
218
- it.each(["a:1abc123def", "a:1xyz-abc_def", "A:1UPPER"])(
219
- "accepts Bot Framework personal chat ids (%s)",
220
- (raw) => {
221
- expect(looksLikeMSTeamsTargetId(raw)).toBe(true);
222
- },
223
- );
224
-
225
- it.each(["8:orgid:2d8c2d2c-1111-2222-3333-444444444444", "8:orgid:user-object-id"])(
226
- "accepts Bot Framework org-scoped personal chat ids (%s)",
227
- (raw) => {
228
- expect(looksLikeMSTeamsTargetId(raw)).toBe(true);
229
- },
230
- );
231
-
232
- it("accepts Bot Framework user ids", () => {
233
- expect(looksLikeMSTeamsTargetId("29:1a2b3c4d5e6f")).toBe(true);
234
- });
235
-
236
- it("accepts user:<aad-object-id> ids", () => {
237
- expect(looksLikeMSTeamsTargetId("user:40a1a0ed-4ff2-4164-a219-55518990c197")).toBe(true);
238
- });
239
-
240
- it.each(["", " ", "user:John Smith", "Product Team/Roadmap", "Engineering", "hello"])(
241
- "rejects non-id inputs (%s)",
242
- (raw) => {
243
- expect(looksLikeMSTeamsTargetId(raw)).toBe(false);
244
- },
245
- );
246
-
247
- it("normalizes leading/trailing whitespace before classifying", () => {
248
- expect(looksLikeMSTeamsTargetId(" 19:abc@thread.tacv2 ")).toBe(true);
249
- });
250
- });
@@ -1,309 +0,0 @@
1
- import { mapAllowlistResolutionInputs } from "openclaw/plugin-sdk/allow-from";
2
- import {
3
- normalizeLowercaseStringOrEmpty,
4
- normalizeOptionalLowercaseString,
5
- } from "openclaw/plugin-sdk/text-runtime";
6
- import { searchGraphUsers } from "./graph-users.js";
7
- import {
8
- listChannelsForTeam,
9
- listTeamsByName,
10
- normalizeQuery,
11
- resolveGraphToken,
12
- } from "./graph.js";
13
-
14
- type MSTeamsChannelResolution = {
15
- input: string;
16
- resolved: boolean;
17
- teamId?: string;
18
- teamName?: string;
19
- channelId?: string;
20
- channelName?: string;
21
- note?: string;
22
- };
23
-
24
- type MSTeamsUserResolution = {
25
- input: string;
26
- resolved: boolean;
27
- id?: string;
28
- name?: string;
29
- note?: string;
30
- };
31
-
32
- function stripProviderPrefix(raw: string): string {
33
- return raw.replace(/^(msteams|teams):/i, "");
34
- }
35
-
36
- export function normalizeMSTeamsMessagingTarget(raw: string): string | undefined {
37
- let trimmed = raw.trim();
38
- if (!trimmed) {
39
- return undefined;
40
- }
41
- trimmed = stripProviderPrefix(trimmed).trim();
42
- if (/^conversation:/i.test(trimmed)) {
43
- const id = trimmed.slice("conversation:".length).trim();
44
- return id ? `conversation:${id}` : undefined;
45
- }
46
- if (/^user:/i.test(trimmed)) {
47
- const id = trimmed.slice("user:".length).trim();
48
- return id ? `user:${id}` : undefined;
49
- }
50
- return trimmed || undefined;
51
- }
52
-
53
- export function normalizeMSTeamsUserInput(raw: string): string {
54
- return stripProviderPrefix(raw)
55
- .replace(/^(user|conversation):/i, "")
56
- .trim();
57
- }
58
-
59
- export function parseMSTeamsConversationId(raw: string): string | null {
60
- const trimmed = stripProviderPrefix(raw).trim();
61
- if (!/^conversation:/i.test(trimmed)) {
62
- return null;
63
- }
64
- const id = trimmed.slice("conversation:".length).trim();
65
- return id;
66
- }
67
-
68
- /**
69
- * Detect whether a raw target string looks like a Microsoft Teams conversation
70
- * or user id that cron announce delivery and other explicit-target paths can
71
- * forward verbatim to the channel adapter.
72
- *
73
- * Accepts both prefixed and bare formats:
74
- * - `conversation:<id>` — explicit conversation prefix
75
- * - `user:<aad-guid>` — user id (16+ hex chars, UUID-like)
76
- * - `19:abc@thread.tacv2` / `19:abc@thread.skype` — channel / legacy group
77
- * - `19:{userId}_{appId}@unq.gbl.spaces` — Graph 1:1 chat thread format
78
- * - `a:1xxx` — Bot Framework personal (1:1) chat id
79
- * - `8:orgid:xxx` — Bot Framework org-scoped personal chat id
80
- * - `29:xxx` — Bot Framework user id
81
- *
82
- * Display-name user targets such as `user:John Smith` intentionally return
83
- * false so that the Graph API directory lookup still runs for them.
84
- */
85
- export function looksLikeMSTeamsTargetId(raw: string): boolean {
86
- const trimmed = raw.trim();
87
- if (!trimmed) {
88
- return false;
89
- }
90
- if (/^conversation:/i.test(trimmed)) {
91
- return true;
92
- }
93
- if (/^user:/i.test(trimmed)) {
94
- // Only treat as an id when the value after `user:` looks like a UUID;
95
- // display names must fall through to directory lookup.
96
- const id = trimmed.slice("user:".length).trim();
97
- return /^[0-9a-fA-F-]{16,}$/.test(id);
98
- }
99
- // Bare Bot Framework / Graph conversation id formats.
100
- // Channel / group ids always start with `19:` and include an `@thread.*`
101
- // suffix (`@thread.tacv2` or the legacy `@thread.skype`). Personal chat
102
- // ids come in three shapes: `a:1...` (Bot Framework), `8:orgid:...`
103
- // (org-scoped Bot Framework), and `19:{userId}_{appId}@unq.gbl.spaces`
104
- // (Graph API 1:1 chat thread). Bot Framework user ids use `29:...`.
105
- if (/^19:.+@thread\.(tacv2|skype)$/i.test(trimmed)) {
106
- return true;
107
- }
108
- if (/^19:.+@unq\.gbl\.spaces$/i.test(trimmed)) {
109
- return true;
110
- }
111
- if (/^a:1[A-Za-z0-9_-]+$/i.test(trimmed)) {
112
- return true;
113
- }
114
- if (/^8:orgid:[A-Za-z0-9-]+$/i.test(trimmed)) {
115
- return true;
116
- }
117
- if (/^29:[A-Za-z0-9_-]+$/i.test(trimmed)) {
118
- return true;
119
- }
120
- // Fallback: anything containing @thread is still treated as a conversation
121
- // id so the current matches for tenant-specific suffixes remain accepted.
122
- return /@thread\b/i.test(trimmed);
123
- }
124
-
125
- function normalizeMSTeamsTeamKey(raw: string): string | undefined {
126
- const trimmed = stripProviderPrefix(raw)
127
- .replace(/^team:/i, "")
128
- .trim();
129
- return trimmed || undefined;
130
- }
131
-
132
- function normalizeMSTeamsChannelKey(raw?: string | null): string | undefined {
133
- const trimmed = raw?.trim().replace(/^#/, "").trim() ?? "";
134
- return trimmed || undefined;
135
- }
136
-
137
- function normalizeMSTeamsConversationTargetId(raw: string): string {
138
- const trimmed = stripProviderPrefix(raw).trim();
139
- return parseMSTeamsConversationId(trimmed) ?? trimmed;
140
- }
141
-
142
- function looksLikeMSTeamsThreadConversationId(raw: string): boolean {
143
- const normalized = normalizeMSTeamsConversationTargetId(raw);
144
- return /^19:.+@thread\./i.test(normalized);
145
- }
146
-
147
- export function parseMSTeamsTeamChannelInput(raw: string): { team?: string; channel?: string } {
148
- const trimmed = stripProviderPrefix(raw).trim();
149
- if (!trimmed) {
150
- return {};
151
- }
152
- const parts = trimmed.split("/");
153
- const team = normalizeMSTeamsTeamKey(parts[0] ?? "");
154
- const channel =
155
- parts.length > 1 ? normalizeMSTeamsChannelKey(parts.slice(1).join("/")) : undefined;
156
- return {
157
- ...(team ? { team } : {}),
158
- ...(channel ? { channel } : {}),
159
- };
160
- }
161
-
162
- export function parseMSTeamsTeamEntry(
163
- raw: string,
164
- ): { teamKey: string; channelKey?: string } | null {
165
- const { team, channel } = parseMSTeamsTeamChannelInput(raw);
166
- if (!team) {
167
- return null;
168
- }
169
- return {
170
- teamKey: team,
171
- ...(channel ? { channelKey: channel } : {}),
172
- };
173
- }
174
-
175
- export async function resolveMSTeamsChannelAllowlist(params: {
176
- cfg: unknown;
177
- entries: string[];
178
- }): Promise<MSTeamsChannelResolution[]> {
179
- let tokenPromise: Promise<string> | undefined;
180
- const getToken = () => {
181
- tokenPromise ??= resolveGraphToken(params.cfg);
182
- return tokenPromise;
183
- };
184
- return await mapAllowlistResolutionInputs({
185
- inputs: params.entries,
186
- mapInput: async (input): Promise<MSTeamsChannelResolution> => {
187
- const { team, channel } = parseMSTeamsTeamChannelInput(input);
188
- if (!team) {
189
- return { input, resolved: false };
190
- }
191
- if (looksLikeMSTeamsThreadConversationId(team)) {
192
- const teamId = normalizeMSTeamsConversationTargetId(team);
193
- if (!channel) {
194
- return { input, resolved: true, teamId, teamName: teamId };
195
- }
196
- if (!looksLikeMSTeamsThreadConversationId(channel)) {
197
- return {
198
- input,
199
- resolved: false,
200
- teamId,
201
- teamName: teamId,
202
- note: "channel id required for conversation-id team",
203
- };
204
- }
205
- const channelId = normalizeMSTeamsConversationTargetId(channel);
206
- return {
207
- input,
208
- resolved: true,
209
- teamId,
210
- teamName: teamId,
211
- channelId,
212
- channelName: channelId,
213
- };
214
- }
215
- const token = await getToken();
216
- const teams = /^[0-9a-fA-F-]{16,}$/.test(team)
217
- ? [{ id: team, displayName: team }]
218
- : await listTeamsByName(token, team);
219
- if (teams.length === 0) {
220
- return { input, resolved: false, note: "team not found" };
221
- }
222
- const teamMatch = teams[0];
223
- const graphTeamId = teamMatch.id?.trim();
224
- const teamName = teamMatch.displayName?.trim() || team;
225
- if (!graphTeamId) {
226
- return { input, resolved: false, note: "team id missing" };
227
- }
228
- // Bot Framework sends the General channel's conversation ID as
229
- // channelData.team.id at runtime, NOT the Graph API group GUID.
230
- // Fetch channels upfront so we can resolve the correct key format for
231
- // runtime matching and reuse the list for channel lookups.
232
- let teamChannels: Awaited<ReturnType<typeof listChannelsForTeam>> = [];
233
- try {
234
- teamChannels = await listChannelsForTeam(token, graphTeamId);
235
- } catch {
236
- // API failure (rate limit, network error) — fall back to Graph GUID as team key
237
- }
238
- const generalChannel = teamChannels.find(
239
- (ch) => normalizeOptionalLowercaseString(ch.displayName) === "general",
240
- );
241
- // Use the General channel's conversation ID as the team key — this
242
- // matches what Bot Framework sends at runtime. Fall back to the Graph
243
- // GUID if the General channel isn't found (renamed or deleted).
244
- const teamId = generalChannel?.id?.trim() || graphTeamId;
245
- if (!channel) {
246
- return {
247
- input,
248
- resolved: true,
249
- teamId,
250
- teamName,
251
- note: teams.length > 1 ? "multiple teams; chose first" : undefined,
252
- };
253
- }
254
- // Reuse teamChannels — already fetched above
255
- const normalizedChannel = normalizeOptionalLowercaseString(channel);
256
- const channelMatch =
257
- teamChannels.find((item) => item.id === channel) ??
258
- teamChannels.find(
259
- (item) => normalizeOptionalLowercaseString(item.displayName) === normalizedChannel,
260
- ) ??
261
- teamChannels.find((item) =>
262
- normalizeLowercaseStringOrEmpty(item.displayName ?? "").includes(normalizedChannel ?? ""),
263
- );
264
- if (!channelMatch?.id) {
265
- return { input, resolved: false, note: "channel not found" };
266
- }
267
- return {
268
- input,
269
- resolved: true,
270
- teamId,
271
- teamName,
272
- channelId: channelMatch.id,
273
- channelName: channelMatch.displayName ?? channel,
274
- note: teamChannels.length > 1 ? "multiple channels; chose first" : undefined,
275
- };
276
- },
277
- });
278
- }
279
-
280
- export async function resolveMSTeamsUserAllowlist(params: {
281
- cfg: unknown;
282
- entries: string[];
283
- }): Promise<MSTeamsUserResolution[]> {
284
- const token = await resolveGraphToken(params.cfg);
285
- return await mapAllowlistResolutionInputs({
286
- inputs: params.entries,
287
- mapInput: async (input): Promise<MSTeamsUserResolution> => {
288
- const query = normalizeQuery(normalizeMSTeamsUserInput(input));
289
- if (!query) {
290
- return { input, resolved: false };
291
- }
292
- if (/^[0-9a-fA-F-]{16,}$/.test(query)) {
293
- return { input, resolved: true, id: query };
294
- }
295
- const users = await searchGraphUsers({ token, query, top: 10 });
296
- const match = users[0];
297
- if (!match?.id) {
298
- return { input, resolved: false };
299
- }
300
- return {
301
- input,
302
- resolved: true,
303
- id: match.id,
304
- name: match.displayName ?? undefined,
305
- note: users.length > 1 ? "multiple matches; chose first" : undefined,
306
- };
307
- },
308
- });
309
- }