@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
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";
2
+ //#region extensions/msteams/index.ts
3
+ var msteams_default = defineBundledChannelEntry({
4
+ id: "msteams",
5
+ name: "Microsoft Teams",
6
+ description: "Microsoft Teams channel plugin (Bot Framework)",
7
+ importMetaUrl: import.meta.url,
8
+ plugin: {
9
+ specifier: "./channel-plugin-api.js",
10
+ exportName: "msteamsPlugin"
11
+ },
12
+ secrets: {
13
+ specifier: "./secret-contract-api.js",
14
+ exportName: "channelSecrets"
15
+ },
16
+ runtime: {
17
+ specifier: "./runtime-api.js",
18
+ exportName: "setMSTeamsRuntime"
19
+ }
20
+ });
21
+ //#endregion
22
+ export { msteams_default as default };
@@ -0,0 +1,114 @@
1
+ import { a as MSTEAMS_OAUTH_CALLBACK_PORT, i as MSTEAMS_OAUTH_CALLBACK_PATH, o as MSTEAMS_OAUTH_REDIRECT_URI, r as MSTEAMS_DEFAULT_DELEGATED_SCOPES, s as buildMSTeamsAuthEndpoint, t as exchangeMSTeamsCodeForTokens } from "./oauth.token-xxpoLWy5.js";
2
+ import { generateHexPkceVerifierChallenge } from "openclaw/plugin-sdk/provider-auth";
3
+ import { generateOAuthState, parseOAuthCallbackInput, waitForLocalOAuthCallback } from "openclaw/plugin-sdk/provider-auth-runtime";
4
+ import { isWSL2Sync } from "openclaw/plugin-sdk/runtime-env";
5
+ //#region extensions/msteams/src/oauth.flow.ts
6
+ function shouldUseManualOAuthFlow(isRemote) {
7
+ return isRemote || isWSL2Sync();
8
+ }
9
+ function generatePkce() {
10
+ return generateHexPkceVerifierChallenge();
11
+ }
12
+ function buildMSTeamsAuthUrl(params) {
13
+ const scopes = params.scopes ?? MSTEAMS_DEFAULT_DELEGATED_SCOPES;
14
+ return `${buildMSTeamsAuthEndpoint(params.tenantId)}?${new URLSearchParams({
15
+ client_id: params.clientId,
16
+ response_type: "code",
17
+ redirect_uri: MSTEAMS_OAUTH_REDIRECT_URI,
18
+ scope: scopes.join(" "),
19
+ code_challenge: params.challenge,
20
+ code_challenge_method: "S256",
21
+ state: params.state,
22
+ prompt: "consent"
23
+ }).toString()}`;
24
+ }
25
+ function parseCallbackInput(input, _expectedState) {
26
+ return parseOAuthCallbackInput(input, {
27
+ missingState: "Missing 'state' parameter in URL. Paste the full redirect URL.",
28
+ invalidInput: "Paste the full redirect URL (including code and state parameters), not just the authorization code."
29
+ });
30
+ }
31
+ async function waitForLocalCallback(params) {
32
+ return await waitForLocalOAuthCallback({
33
+ expectedState: params.expectedState,
34
+ timeoutMs: params.timeoutMs,
35
+ port: MSTEAMS_OAUTH_CALLBACK_PORT,
36
+ callbackPath: MSTEAMS_OAUTH_CALLBACK_PATH,
37
+ redirectUri: MSTEAMS_OAUTH_REDIRECT_URI,
38
+ successTitle: "MSTeams Delegated OAuth complete",
39
+ progressMessage: `Waiting for OAuth callback on ${MSTEAMS_OAUTH_REDIRECT_URI}...`,
40
+ onProgress: params.onProgress
41
+ });
42
+ }
43
+ //#endregion
44
+ //#region extensions/msteams/src/oauth.ts
45
+ async function loginMSTeamsDelegated(ctx, params) {
46
+ const scopes = params.scopes ?? MSTEAMS_DEFAULT_DELEGATED_SCOPES;
47
+ const needsManual = shouldUseManualOAuthFlow(ctx.isRemote);
48
+ await ctx.note(needsManual ? [
49
+ "You are running in a remote/VPS environment.",
50
+ "A URL will be shown for you to open in your LOCAL browser.",
51
+ "After signing in, copy the redirect URL and paste it back here."
52
+ ].join("\n") : [
53
+ "Browser will open for Microsoft authentication.",
54
+ `Sign in to grant delegated permissions for MSTeams.`,
55
+ `The callback will be captured automatically on localhost:${MSTEAMS_OAUTH_CALLBACK_PORT}.`
56
+ ].join("\n"), "MSTeams Delegated OAuth");
57
+ const { verifier, challenge } = generatePkce();
58
+ const state = generateOAuthState();
59
+ const authUrl = buildMSTeamsAuthUrl({
60
+ tenantId: params.tenantId,
61
+ clientId: params.clientId,
62
+ challenge,
63
+ state,
64
+ scopes
65
+ });
66
+ if (needsManual) return manualFlow(ctx, authUrl, state, verifier, params);
67
+ ctx.progress.update("Complete sign-in in browser...");
68
+ try {
69
+ await ctx.openUrl(authUrl);
70
+ } catch {
71
+ ctx.log(`\nOpen this URL in your browser:\n\n${authUrl}\n`);
72
+ }
73
+ try {
74
+ const { code } = await waitForLocalCallback({
75
+ expectedState: state,
76
+ timeoutMs: 300 * 1e3,
77
+ onProgress: (msg) => ctx.progress.update(msg)
78
+ });
79
+ ctx.progress.update("Exchanging authorization code for tokens...");
80
+ return await exchangeMSTeamsCodeForTokens({
81
+ tenantId: params.tenantId,
82
+ clientId: params.clientId,
83
+ clientSecret: params.clientSecret,
84
+ code,
85
+ verifier,
86
+ scopes
87
+ });
88
+ } catch (err) {
89
+ if (err instanceof Error && (err.message.includes("EADDRINUSE") || err.message.includes("port") || err.message.includes("listen"))) {
90
+ ctx.progress.update("Local callback server failed. Switching to manual mode...");
91
+ return manualFlow(ctx, authUrl, state, verifier, params, err);
92
+ }
93
+ throw err;
94
+ }
95
+ }
96
+ async function manualFlow(ctx, authUrl, state, verifier, params, cause) {
97
+ ctx.progress.update("OAuth URL ready");
98
+ ctx.log(`\nOpen this URL in your LOCAL browser:\n\n${authUrl}\n`);
99
+ ctx.progress.update("Waiting for you to paste the callback URL...");
100
+ const parsed = parseCallbackInput(await ctx.prompt("Paste the redirect URL here: "), state);
101
+ if ("error" in parsed) throw new Error(parsed.error, cause ? { cause } : void 0);
102
+ if (parsed.state !== state) throw new Error("OAuth state mismatch - please try again", cause ? { cause } : void 0);
103
+ ctx.progress.update("Exchanging authorization code for tokens...");
104
+ return exchangeMSTeamsCodeForTokens({
105
+ tenantId: params.tenantId,
106
+ clientId: params.clientId,
107
+ clientSecret: params.clientSecret,
108
+ code: parsed.code,
109
+ verifier,
110
+ scopes: params.scopes
111
+ });
112
+ }
113
+ //#endregion
114
+ export { loginMSTeamsDelegated };
@@ -0,0 +1,115 @@
1
+ import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
2
+ //#region extensions/msteams/src/oauth.shared.ts
3
+ const MSTEAMS_OAUTH_REDIRECT_URI = "http://localhost:8086/oauth2callback";
4
+ const MSTEAMS_OAUTH_CALLBACK_PORT = 8086;
5
+ const MSTEAMS_OAUTH_CALLBACK_PATH = "/oauth2callback";
6
+ const MSTEAMS_DEFAULT_TOKEN_FETCH_TIMEOUT_MS = 1e4;
7
+ const MSTEAMS_DEFAULT_DELEGATED_SCOPES = [
8
+ "ChatMessage.Send",
9
+ "ChannelMessage.Send",
10
+ "Chat.ReadWrite",
11
+ "offline_access"
12
+ ];
13
+ function buildMSTeamsAuthEndpoint(tenantId) {
14
+ return `https://login.microsoftonline.com/${encodeURIComponent(tenantId)}/oauth2/v2.0/authorize`;
15
+ }
16
+ function buildMSTeamsTokenEndpoint(tenantId) {
17
+ return `https://login.microsoftonline.com/${encodeURIComponent(tenantId)}/oauth2/v2.0/token`;
18
+ }
19
+ //#endregion
20
+ //#region extensions/msteams/src/oauth.token.ts
21
+ /** Five-minute buffer subtracted from token expiry to avoid edge-case clock drift. */
22
+ const EXPIRY_BUFFER_MS = 300 * 1e3;
23
+ function createMSTeamsTokenBody(params) {
24
+ const body = new URLSearchParams({
25
+ client_id: params.clientId,
26
+ client_secret: params.clientSecret,
27
+ grant_type: params.grantType,
28
+ scope: [...params.scopes].join(" ")
29
+ });
30
+ for (const [key, value] of Object.entries(params.values ?? {})) body.set(key, value);
31
+ return body;
32
+ }
33
+ async function fetchMSTeamsTokens(params) {
34
+ const currentFetch = globalThis.fetch;
35
+ const { response, release } = await fetchWithSsrFGuard({
36
+ url: params.tokenUrl,
37
+ fetchImpl: async (input, guardedInit) => await currentFetch(input, guardedInit),
38
+ init: {
39
+ method: "POST",
40
+ headers: {
41
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
42
+ Accept: "application/json"
43
+ },
44
+ body: params.body,
45
+ signal: AbortSignal.timeout(MSTEAMS_DEFAULT_TOKEN_FETCH_TIMEOUT_MS)
46
+ },
47
+ auditContext: params.auditContext
48
+ });
49
+ try {
50
+ if (!response.ok) {
51
+ const errorText = await response.text();
52
+ throw new Error(`MSTeams ${params.failureLabel} failed (${response.status}): ${errorText}`);
53
+ }
54
+ return await response.json();
55
+ } finally {
56
+ await release();
57
+ }
58
+ }
59
+ async function requestMSTeamsDelegatedTokens(params) {
60
+ const scopes = params.scopes ?? MSTEAMS_DEFAULT_DELEGATED_SCOPES;
61
+ const body = createMSTeamsTokenBody({
62
+ clientId: params.clientId,
63
+ clientSecret: params.clientSecret,
64
+ grantType: params.grantType,
65
+ scopes,
66
+ values: params.values
67
+ });
68
+ const data = await fetchMSTeamsTokens({
69
+ tokenUrl: buildMSTeamsTokenEndpoint(params.tenantId),
70
+ body,
71
+ auditContext: params.auditContext,
72
+ failureLabel: params.failureLabel
73
+ });
74
+ return {
75
+ accessToken: data.access_token,
76
+ refreshToken: params.resolveRefreshToken(data),
77
+ expiresAt: Date.now() + data.expires_in * 1e3 - EXPIRY_BUFFER_MS,
78
+ scopes: data.scope ? data.scope.split(" ") : [...scopes]
79
+ };
80
+ }
81
+ async function exchangeMSTeamsCodeForTokens(params) {
82
+ return await requestMSTeamsDelegatedTokens({
83
+ tenantId: params.tenantId,
84
+ clientId: params.clientId,
85
+ clientSecret: params.clientSecret,
86
+ grantType: "authorization_code",
87
+ scopes: params.scopes,
88
+ values: {
89
+ code: params.code,
90
+ redirect_uri: MSTEAMS_OAUTH_REDIRECT_URI,
91
+ code_verifier: params.verifier
92
+ },
93
+ auditContext: "msteams-oauth-token-exchange",
94
+ failureLabel: "token exchange",
95
+ resolveRefreshToken: (data) => {
96
+ if (!data.refresh_token) throw new Error("No refresh token received from Azure AD. Please try again.");
97
+ return data.refresh_token;
98
+ }
99
+ });
100
+ }
101
+ async function refreshMSTeamsDelegatedTokens(params) {
102
+ return await requestMSTeamsDelegatedTokens({
103
+ tenantId: params.tenantId,
104
+ clientId: params.clientId,
105
+ clientSecret: params.clientSecret,
106
+ grantType: "refresh_token",
107
+ scopes: params.scopes,
108
+ values: { refresh_token: params.refreshToken },
109
+ auditContext: "msteams-oauth-token-refresh",
110
+ failureLabel: "token refresh",
111
+ resolveRefreshToken: (data) => data.refresh_token ?? params.refreshToken
112
+ });
113
+ }
114
+ //#endregion
115
+ export { MSTEAMS_OAUTH_CALLBACK_PORT as a, MSTEAMS_OAUTH_CALLBACK_PATH as i, refreshMSTeamsDelegatedTokens as n, MSTEAMS_OAUTH_REDIRECT_URI as o, MSTEAMS_DEFAULT_DELEGATED_SCOPES as r, buildMSTeamsAuthEndpoint as s, exchangeMSTeamsCodeForTokens as t };
@@ -0,0 +1,142 @@
1
+ import { C as normalizeChannelSlug, D as resolveChannelEntryMatchWithFallback, E as resolveAllowlistMatchSimple, M as resolveNestedAllowlistDecision, P as resolveToolsBySender, i as buildChannelKeyCandidates, p as evaluateSenderGroupAccessForPolicy, v as isDangerousNameMatchingEnabled } from "./runtime-api-DV1iVMn1.js";
2
+ //#region extensions/msteams/src/policy.ts
3
+ function resolveMSTeamsRouteConfig(params) {
4
+ const teamId = params.teamId?.trim();
5
+ const teamName = params.teamName?.trim();
6
+ const conversationId = params.conversationId?.trim();
7
+ const channelName = params.channelName?.trim();
8
+ const teams = params.cfg?.teams ?? {};
9
+ const allowlistConfigured = Object.keys(teams).length > 0;
10
+ const teamMatch = resolveChannelEntryMatchWithFallback({
11
+ entries: teams,
12
+ keys: buildChannelKeyCandidates(teamId, params.allowNameMatching ? teamName : void 0, params.allowNameMatching && teamName ? normalizeChannelSlug(teamName) : void 0),
13
+ wildcardKey: "*",
14
+ normalizeKey: normalizeChannelSlug
15
+ });
16
+ const teamConfig = teamMatch.entry;
17
+ const channels = teamConfig?.channels ?? {};
18
+ const channelAllowlistConfigured = Object.keys(channels).length > 0;
19
+ const channelMatch = resolveChannelEntryMatchWithFallback({
20
+ entries: channels,
21
+ keys: buildChannelKeyCandidates(conversationId, params.allowNameMatching ? channelName : void 0, params.allowNameMatching && channelName ? normalizeChannelSlug(channelName) : void 0),
22
+ wildcardKey: "*",
23
+ normalizeKey: normalizeChannelSlug
24
+ });
25
+ const channelConfig = channelMatch.entry;
26
+ return {
27
+ teamConfig,
28
+ channelConfig,
29
+ allowlistConfigured,
30
+ allowed: resolveNestedAllowlistDecision({
31
+ outerConfigured: allowlistConfigured,
32
+ outerMatched: Boolean(teamConfig),
33
+ innerConfigured: channelAllowlistConfigured,
34
+ innerMatched: Boolean(channelConfig)
35
+ }),
36
+ teamKey: teamMatch.matchKey ?? teamMatch.key,
37
+ channelKey: channelMatch.matchKey ?? channelMatch.key,
38
+ channelMatchKey: channelMatch.matchKey,
39
+ channelMatchSource: channelMatch.matchSource === "direct" || channelMatch.matchSource === "wildcard" ? channelMatch.matchSource : void 0
40
+ };
41
+ }
42
+ function resolveMSTeamsGroupToolPolicy(params) {
43
+ const cfg = params.cfg.channels?.msteams;
44
+ if (!cfg) return;
45
+ const groupId = params.groupId?.trim();
46
+ const groupChannel = params.groupChannel?.trim();
47
+ const groupSpace = params.groupSpace?.trim();
48
+ const allowNameMatching = isDangerousNameMatchingEnabled(cfg);
49
+ const resolved = resolveMSTeamsRouteConfig({
50
+ cfg,
51
+ teamId: groupSpace,
52
+ teamName: groupSpace,
53
+ conversationId: groupId,
54
+ channelName: groupChannel,
55
+ allowNameMatching
56
+ });
57
+ if (resolved.channelConfig) {
58
+ const senderPolicy = resolveToolsBySender({
59
+ toolsBySender: resolved.channelConfig.toolsBySender,
60
+ senderId: params.senderId,
61
+ senderName: params.senderName,
62
+ senderUsername: params.senderUsername,
63
+ senderE164: params.senderE164
64
+ });
65
+ if (senderPolicy) return senderPolicy;
66
+ if (resolved.channelConfig.tools) return resolved.channelConfig.tools;
67
+ const teamSenderPolicy = resolveToolsBySender({
68
+ toolsBySender: resolved.teamConfig?.toolsBySender,
69
+ senderId: params.senderId,
70
+ senderName: params.senderName,
71
+ senderUsername: params.senderUsername,
72
+ senderE164: params.senderE164
73
+ });
74
+ if (teamSenderPolicy) return teamSenderPolicy;
75
+ return resolved.teamConfig?.tools;
76
+ }
77
+ if (resolved.teamConfig) {
78
+ const teamSenderPolicy = resolveToolsBySender({
79
+ toolsBySender: resolved.teamConfig.toolsBySender,
80
+ senderId: params.senderId,
81
+ senderName: params.senderName,
82
+ senderUsername: params.senderUsername,
83
+ senderE164: params.senderE164
84
+ });
85
+ if (teamSenderPolicy) return teamSenderPolicy;
86
+ if (resolved.teamConfig.tools) return resolved.teamConfig.tools;
87
+ }
88
+ if (!groupId) return;
89
+ const channelCandidates = buildChannelKeyCandidates(groupId, allowNameMatching ? groupChannel : void 0, allowNameMatching && groupChannel ? normalizeChannelSlug(groupChannel) : void 0);
90
+ for (const teamConfig of Object.values(cfg.teams ?? {})) {
91
+ const match = resolveChannelEntryMatchWithFallback({
92
+ entries: teamConfig?.channels ?? {},
93
+ keys: channelCandidates,
94
+ wildcardKey: "*",
95
+ normalizeKey: normalizeChannelSlug
96
+ });
97
+ if (match.entry) {
98
+ const senderPolicy = resolveToolsBySender({
99
+ toolsBySender: match.entry.toolsBySender,
100
+ senderId: params.senderId,
101
+ senderName: params.senderName,
102
+ senderUsername: params.senderUsername,
103
+ senderE164: params.senderE164
104
+ });
105
+ if (senderPolicy) return senderPolicy;
106
+ if (match.entry.tools) return match.entry.tools;
107
+ const teamSenderPolicy = resolveToolsBySender({
108
+ toolsBySender: teamConfig?.toolsBySender,
109
+ senderId: params.senderId,
110
+ senderName: params.senderName,
111
+ senderUsername: params.senderUsername,
112
+ senderE164: params.senderE164
113
+ });
114
+ if (teamSenderPolicy) return teamSenderPolicy;
115
+ return teamConfig?.tools;
116
+ }
117
+ }
118
+ }
119
+ function resolveMSTeamsAllowlistMatch(params) {
120
+ return resolveAllowlistMatchSimple(params);
121
+ }
122
+ function resolveMSTeamsReplyPolicy(params) {
123
+ if (params.isDirectMessage) return {
124
+ requireMention: false,
125
+ replyStyle: "thread"
126
+ };
127
+ const requireMention = params.channelConfig?.requireMention ?? params.teamConfig?.requireMention ?? params.globalConfig?.requireMention ?? true;
128
+ return {
129
+ requireMention,
130
+ replyStyle: params.channelConfig?.replyStyle ?? params.teamConfig?.replyStyle ?? params.globalConfig?.replyStyle ?? (requireMention ? "thread" : "top-level")
131
+ };
132
+ }
133
+ function isMSTeamsGroupAllowed(params) {
134
+ return evaluateSenderGroupAccessForPolicy({
135
+ groupPolicy: params.groupPolicy,
136
+ groupAllowFrom: params.allowFrom.map((entry) => String(entry)),
137
+ senderId: params.senderId,
138
+ isSenderAllowed: () => resolveMSTeamsAllowlistMatch(params).allowed
139
+ }).allowed;
140
+ }
141
+ //#endregion
142
+ export { resolveMSTeamsRouteConfig as a, resolveMSTeamsReplyPolicy as i, resolveMSTeamsAllowlistMatch as n, resolveMSTeamsGroupToolPolicy as r, isMSTeamsGroupAllowed as t };