@openclaw/msteams 2026.5.2 → 2026.5.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/api.js +3 -0
  2. package/dist/channel-D7hdreTh.js +984 -0
  3. package/dist/channel-config-api.js +2 -0
  4. package/dist/channel-plugin-api.js +2 -0
  5. package/dist/channel.runtime-BC1ruIfN.js +573 -0
  6. package/dist/config-schema-B8QezH6t.js +15 -0
  7. package/dist/contract-api.js +2 -0
  8. package/dist/graph-users-9uQJepqr.js +1354 -0
  9. package/dist/index.js +22 -0
  10. package/dist/oauth-BWJyilR1.js +114 -0
  11. package/dist/oauth.token-xxpoLWy5.js +115 -0
  12. package/dist/policy-DTnU2GR7.js +142 -0
  13. package/dist/probe-D_H8yFps.js +2194 -0
  14. package/dist/resolve-allowlist-D41JSziq.js +219 -0
  15. package/dist/runtime-api-DV1iVMn1.js +28 -0
  16. package/dist/runtime-api.js +2 -0
  17. package/dist/secret-contract-BuoEXmPS.js +35 -0
  18. package/dist/secret-contract-api.js +2 -0
  19. package/dist/setup-entry.js +15 -0
  20. package/dist/setup-plugin-api.js +64 -0
  21. package/dist/setup-surface-BLkFQYIQ.js +313 -0
  22. package/dist/src-CFp1QpFd.js +4064 -0
  23. package/dist/test-api.js +2 -0
  24. package/package.json +14 -6
  25. package/api.ts +0 -3
  26. package/channel-config-api.ts +0 -1
  27. package/channel-plugin-api.ts +0 -2
  28. package/config-api.ts +0 -4
  29. package/contract-api.ts +0 -4
  30. package/index.ts +0 -20
  31. package/runtime-api.ts +0 -73
  32. package/secret-contract-api.ts +0 -5
  33. package/setup-entry.ts +0 -13
  34. package/setup-plugin-api.ts +0 -3
  35. package/src/ai-entity.ts +0 -7
  36. package/src/approval-auth.ts +0 -44
  37. package/src/attachments/bot-framework.test.ts +0 -461
  38. package/src/attachments/bot-framework.ts +0 -362
  39. package/src/attachments/download.ts +0 -311
  40. package/src/attachments/graph.test.ts +0 -416
  41. package/src/attachments/graph.ts +0 -484
  42. package/src/attachments/html.ts +0 -122
  43. package/src/attachments/payload.ts +0 -14
  44. package/src/attachments/remote-media.test.ts +0 -137
  45. package/src/attachments/remote-media.ts +0 -112
  46. package/src/attachments/shared.test.ts +0 -530
  47. package/src/attachments/shared.ts +0 -626
  48. package/src/attachments/types.ts +0 -47
  49. package/src/attachments.graph.test.ts +0 -342
  50. package/src/attachments.helpers.test.ts +0 -246
  51. package/src/attachments.test-helpers.ts +0 -17
  52. package/src/attachments.test.ts +0 -687
  53. package/src/attachments.ts +0 -18
  54. package/src/block-streaming-config.test.ts +0 -61
  55. package/src/channel-api.ts +0 -1
  56. package/src/channel.actions.test.ts +0 -742
  57. package/src/channel.directory.test.ts +0 -200
  58. package/src/channel.runtime.ts +0 -56
  59. package/src/channel.setup.ts +0 -77
  60. package/src/channel.test.ts +0 -128
  61. package/src/channel.ts +0 -1136
  62. package/src/config-schema.ts +0 -6
  63. package/src/config-ui-hints.ts +0 -12
  64. package/src/conversation-store-fs.test.ts +0 -74
  65. package/src/conversation-store-fs.ts +0 -149
  66. package/src/conversation-store-helpers.test.ts +0 -202
  67. package/src/conversation-store-helpers.ts +0 -105
  68. package/src/conversation-store-memory.ts +0 -51
  69. package/src/conversation-store.shared.test.ts +0 -225
  70. package/src/conversation-store.ts +0 -71
  71. package/src/directory-live.test.ts +0 -156
  72. package/src/directory-live.ts +0 -111
  73. package/src/doctor.ts +0 -27
  74. package/src/errors.test.ts +0 -133
  75. package/src/errors.ts +0 -246
  76. package/src/feedback-reflection-prompt.ts +0 -117
  77. package/src/feedback-reflection-store.ts +0 -114
  78. package/src/feedback-reflection.test.ts +0 -237
  79. package/src/feedback-reflection.ts +0 -283
  80. package/src/file-consent-helpers.test.ts +0 -326
  81. package/src/file-consent-helpers.ts +0 -126
  82. package/src/file-consent-invoke.ts +0 -150
  83. package/src/file-consent.test.ts +0 -363
  84. package/src/file-consent.ts +0 -287
  85. package/src/graph-chat.ts +0 -55
  86. package/src/graph-group-management.test.ts +0 -318
  87. package/src/graph-group-management.ts +0 -168
  88. package/src/graph-members.test.ts +0 -89
  89. package/src/graph-members.ts +0 -48
  90. package/src/graph-messages.actions.test.ts +0 -243
  91. package/src/graph-messages.read.test.ts +0 -391
  92. package/src/graph-messages.search.test.ts +0 -213
  93. package/src/graph-messages.test-helpers.ts +0 -50
  94. package/src/graph-messages.ts +0 -534
  95. package/src/graph-teams.test.ts +0 -215
  96. package/src/graph-teams.ts +0 -114
  97. package/src/graph-thread.test.ts +0 -246
  98. package/src/graph-thread.ts +0 -146
  99. package/src/graph-upload.test.ts +0 -258
  100. package/src/graph-upload.ts +0 -531
  101. package/src/graph-users.ts +0 -29
  102. package/src/graph.test.ts +0 -516
  103. package/src/graph.ts +0 -293
  104. package/src/inbound.test.ts +0 -221
  105. package/src/inbound.ts +0 -148
  106. package/src/index.ts +0 -4
  107. package/src/media-helpers.test.ts +0 -202
  108. package/src/media-helpers.ts +0 -105
  109. package/src/mentions.test.ts +0 -244
  110. package/src/mentions.ts +0 -114
  111. package/src/messenger.test.ts +0 -865
  112. package/src/messenger.ts +0 -605
  113. package/src/monitor-handler/access.ts +0 -125
  114. package/src/monitor-handler/inbound-media.test.ts +0 -289
  115. package/src/monitor-handler/inbound-media.ts +0 -180
  116. package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
  117. package/src/monitor-handler/message-handler.authz.test.ts +0 -669
  118. package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
  119. package/src/monitor-handler/message-handler.test-support.ts +0 -100
  120. package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
  121. package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
  122. package/src/monitor-handler/message-handler.ts +0 -1000
  123. package/src/monitor-handler/reaction-handler.test.ts +0 -267
  124. package/src/monitor-handler/reaction-handler.ts +0 -210
  125. package/src/monitor-handler/thread-session.ts +0 -17
  126. package/src/monitor-handler.adaptive-card.test.ts +0 -162
  127. package/src/monitor-handler.feedback-authz.test.ts +0 -314
  128. package/src/monitor-handler.file-consent.test.ts +0 -423
  129. package/src/monitor-handler.sso.test.ts +0 -563
  130. package/src/monitor-handler.test-helpers.ts +0 -180
  131. package/src/monitor-handler.ts +0 -534
  132. package/src/monitor-handler.types.ts +0 -27
  133. package/src/monitor-types.ts +0 -6
  134. package/src/monitor.lifecycle.test.ts +0 -278
  135. package/src/monitor.test.ts +0 -119
  136. package/src/monitor.ts +0 -442
  137. package/src/oauth.flow.ts +0 -77
  138. package/src/oauth.shared.ts +0 -37
  139. package/src/oauth.test.ts +0 -305
  140. package/src/oauth.token.ts +0 -158
  141. package/src/oauth.ts +0 -130
  142. package/src/outbound.test.ts +0 -130
  143. package/src/outbound.ts +0 -71
  144. package/src/pending-uploads-fs.test.ts +0 -246
  145. package/src/pending-uploads-fs.ts +0 -235
  146. package/src/pending-uploads.test.ts +0 -173
  147. package/src/pending-uploads.ts +0 -121
  148. package/src/policy.test.ts +0 -240
  149. package/src/policy.ts +0 -262
  150. package/src/polls-store-memory.ts +0 -32
  151. package/src/polls.test.ts +0 -160
  152. package/src/polls.ts +0 -323
  153. package/src/presentation.ts +0 -68
  154. package/src/probe.test.ts +0 -77
  155. package/src/probe.ts +0 -132
  156. package/src/reply-dispatcher.test.ts +0 -437
  157. package/src/reply-dispatcher.ts +0 -346
  158. package/src/reply-stream-controller.test.ts +0 -235
  159. package/src/reply-stream-controller.ts +0 -147
  160. package/src/resolve-allowlist.test.ts +0 -250
  161. package/src/resolve-allowlist.ts +0 -309
  162. package/src/revoked-context.ts +0 -17
  163. package/src/runtime.ts +0 -9
  164. package/src/sdk-types.ts +0 -59
  165. package/src/sdk.test.ts +0 -666
  166. package/src/sdk.ts +0 -884
  167. package/src/secret-contract.ts +0 -49
  168. package/src/secret-input.ts +0 -7
  169. package/src/send-context.ts +0 -231
  170. package/src/send.test.ts +0 -493
  171. package/src/send.ts +0 -637
  172. package/src/sent-message-cache.test.ts +0 -15
  173. package/src/sent-message-cache.ts +0 -56
  174. package/src/session-route.ts +0 -40
  175. package/src/setup-core.ts +0 -160
  176. package/src/setup-surface.test.ts +0 -202
  177. package/src/setup-surface.ts +0 -320
  178. package/src/sso-token-store.test.ts +0 -72
  179. package/src/sso-token-store.ts +0 -166
  180. package/src/sso.ts +0 -300
  181. package/src/storage.ts +0 -25
  182. package/src/store-fs.ts +0 -44
  183. package/src/streaming-message.test.ts +0 -262
  184. package/src/streaming-message.ts +0 -297
  185. package/src/test-runtime.ts +0 -16
  186. package/src/thread-parent-context.test.ts +0 -224
  187. package/src/thread-parent-context.ts +0 -159
  188. package/src/token-response.ts +0 -11
  189. package/src/token.test.ts +0 -259
  190. package/src/token.ts +0 -195
  191. package/src/user-agent.test.ts +0 -86
  192. package/src/user-agent.ts +0 -53
  193. package/src/webhook-timeouts.ts +0 -27
  194. package/src/welcome-card.test.ts +0 -81
  195. package/src/welcome-card.ts +0 -57
  196. package/test-api.ts +0 -1
  197. package/tsconfig.json +0 -16
@@ -1,11 +0,0 @@
1
- export function readAccessToken(value: unknown): string | null {
2
- if (typeof value === "string") {
3
- return value;
4
- }
5
- if (value && typeof value === "object") {
6
- const token =
7
- (value as { accessToken?: unknown }).accessToken ?? (value as { token?: unknown }).token;
8
- return typeof token === "string" ? token : null;
9
- }
10
- return null;
11
- }
package/src/token.test.ts DELETED
@@ -1,259 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
- import { readAccessToken } from "./token-response.js";
3
- import { hasConfiguredMSTeamsCredentials, resolveMSTeamsCredentials } from "./token.js";
4
-
5
- vi.mock("./secret-input.js", () => ({
6
- normalizeSecretInputString: (v: unknown) =>
7
- typeof v === "string" && v.trim() ? v.trim() : undefined,
8
- normalizeResolvedSecretInputString: (opts: { value: unknown; path: string }) =>
9
- typeof opts.value === "string" && opts.value.trim() ? opts.value.trim() : undefined,
10
- hasConfiguredSecretInput: (v: unknown) => typeof v === "string" && v.trim().length > 0,
11
- }));
12
-
13
- const ENV_KEYS = [
14
- "MSTEAMS_APP_ID",
15
- "MSTEAMS_APP_PASSWORD",
16
- "MSTEAMS_TENANT_ID",
17
- "MSTEAMS_AUTH_TYPE",
18
- "MSTEAMS_CERTIFICATE_PATH",
19
- "MSTEAMS_CERTIFICATE_THUMBPRINT",
20
- "MSTEAMS_USE_MANAGED_IDENTITY",
21
- "MSTEAMS_MANAGED_IDENTITY_CLIENT_ID",
22
- ] as const;
23
-
24
- let savedEnv: Record<string, string | undefined> = {};
25
-
26
- function saveAndClearEnv() {
27
- savedEnv = {};
28
- for (const key of ENV_KEYS) {
29
- savedEnv[key] = process.env[key];
30
- delete process.env[key];
31
- }
32
- }
33
-
34
- function restoreEnv() {
35
- for (const key of ENV_KEYS) {
36
- if (savedEnv[key] !== undefined) {
37
- process.env[key] = savedEnv[key];
38
- } else {
39
- delete process.env[key];
40
- }
41
- }
42
- }
43
-
44
- describe("token – secret credentials", () => {
45
- beforeEach(saveAndClearEnv);
46
- afterEach(restoreEnv);
47
-
48
- it("returns true when appId + appPassword + tenantId are provided in config", () => {
49
- const cfg = { appId: "app-id", appPassword: "app-pw", tenantId: "tenant-id" } as any;
50
- expect(hasConfiguredMSTeamsCredentials(cfg)).toBe(true);
51
- });
52
-
53
- it("returns false when appPassword is missing", () => {
54
- const cfg = { appId: "app-id", tenantId: "tenant-id" } as any;
55
- expect(hasConfiguredMSTeamsCredentials(cfg)).toBe(false);
56
- });
57
-
58
- it("returns false when no config is given and no env vars set", () => {
59
- expect(hasConfiguredMSTeamsCredentials(undefined)).toBe(false);
60
- });
61
-
62
- it("resolves secret credentials from config", () => {
63
- const cfg = { appId: "app-id", appPassword: "app-pw", tenantId: "tenant-id" } as any;
64
- const result = resolveMSTeamsCredentials(cfg);
65
- expect(result).toEqual({
66
- type: "secret",
67
- appId: "app-id",
68
- appPassword: "app-pw",
69
- tenantId: "tenant-id",
70
- });
71
- });
72
-
73
- it("resolves secret credentials from env vars", () => {
74
- process.env.MSTEAMS_APP_ID = "env-app-id";
75
- process.env.MSTEAMS_APP_PASSWORD = "env-app-pw";
76
- process.env.MSTEAMS_TENANT_ID = "env-tenant-id";
77
- const result = resolveMSTeamsCredentials(undefined);
78
- expect(result).toEqual({
79
- type: "secret",
80
- appId: "env-app-id",
81
- appPassword: "env-app-pw",
82
- tenantId: "env-tenant-id",
83
- });
84
- });
85
-
86
- it("returns undefined when appPassword is missing", () => {
87
- const cfg = { appId: "app-id", tenantId: "tenant-id" } as any;
88
- expect(resolveMSTeamsCredentials(cfg)).toBeUndefined();
89
- });
90
- });
91
-
92
- describe("token – federated credentials (certificate)", () => {
93
- beforeEach(saveAndClearEnv);
94
- afterEach(restoreEnv);
95
-
96
- it("hasConfigured returns true when certificate path is provided", () => {
97
- const cfg = {
98
- appId: "app-id",
99
- tenantId: "tenant-id",
100
- authType: "federated",
101
- certificatePath: "/cert.pem",
102
- } as any;
103
- expect(hasConfiguredMSTeamsCredentials(cfg)).toBe(true);
104
- });
105
-
106
- it("hasConfigured returns false when neither cert nor MI is provided", () => {
107
- const cfg = { appId: "app-id", tenantId: "tenant-id", authType: "federated" } as any;
108
- expect(hasConfiguredMSTeamsCredentials(cfg)).toBe(false);
109
- });
110
-
111
- it("resolves federated credentials with certificate from config", () => {
112
- const cfg = {
113
- appId: "app-id",
114
- tenantId: "tenant-id",
115
- authType: "federated",
116
- certificatePath: "/cert.pem",
117
- certificateThumbprint: "AABBCCDD",
118
- } as any;
119
- const result = resolveMSTeamsCredentials(cfg);
120
- expect(result).toEqual({
121
- type: "federated",
122
- appId: "app-id",
123
- tenantId: "tenant-id",
124
- certificatePath: "/cert.pem",
125
- certificateThumbprint: "AABBCCDD",
126
- useManagedIdentity: undefined,
127
- managedIdentityClientId: undefined,
128
- });
129
- });
130
-
131
- it("resolves federated credentials from env vars", () => {
132
- process.env.MSTEAMS_AUTH_TYPE = "federated";
133
- process.env.MSTEAMS_APP_ID = "env-app-id";
134
- process.env.MSTEAMS_TENANT_ID = "env-tenant-id";
135
- process.env.MSTEAMS_CERTIFICATE_PATH = "/env/cert.pem";
136
- process.env.MSTEAMS_CERTIFICATE_THUMBPRINT = "EEFF0011";
137
- const result = resolveMSTeamsCredentials(undefined);
138
- expect(result).toEqual({
139
- type: "federated",
140
- appId: "env-app-id",
141
- tenantId: "env-tenant-id",
142
- certificatePath: "/env/cert.pem",
143
- certificateThumbprint: "EEFF0011",
144
- useManagedIdentity: undefined,
145
- managedIdentityClientId: undefined,
146
- });
147
- });
148
- });
149
-
150
- describe("token – federated credentials (managed identity)", () => {
151
- beforeEach(saveAndClearEnv);
152
- afterEach(restoreEnv);
153
-
154
- it("resolves managed identity from config", () => {
155
- const cfg = {
156
- appId: "app-id",
157
- tenantId: "tenant-id",
158
- authType: "federated",
159
- useManagedIdentity: true,
160
- managedIdentityClientId: "mi-client-id",
161
- } as any;
162
- const result = resolveMSTeamsCredentials(cfg);
163
- expect(result).toEqual({
164
- type: "federated",
165
- appId: "app-id",
166
- tenantId: "tenant-id",
167
- certificatePath: undefined,
168
- certificateThumbprint: undefined,
169
- useManagedIdentity: true,
170
- managedIdentityClientId: "mi-client-id",
171
- });
172
- });
173
-
174
- it("resolves system-assigned managed identity (no clientId)", () => {
175
- const cfg = {
176
- appId: "app-id",
177
- tenantId: "tenant-id",
178
- authType: "federated",
179
- useManagedIdentity: true,
180
- } as any;
181
- const result = resolveMSTeamsCredentials(cfg);
182
- expect(result).toEqual({
183
- type: "federated",
184
- appId: "app-id",
185
- tenantId: "tenant-id",
186
- certificatePath: undefined,
187
- certificateThumbprint: undefined,
188
- useManagedIdentity: true,
189
- managedIdentityClientId: undefined,
190
- });
191
- });
192
-
193
- it("hasConfigured returns true for managed identity via env", () => {
194
- process.env.MSTEAMS_AUTH_TYPE = "federated";
195
- process.env.MSTEAMS_APP_ID = "env-app-id";
196
- process.env.MSTEAMS_TENANT_ID = "env-tenant-id";
197
- process.env.MSTEAMS_USE_MANAGED_IDENTITY = "true";
198
- expect(hasConfiguredMSTeamsCredentials(undefined)).toBe(true);
199
- });
200
-
201
- it("config useManagedIdentity=false overrides env MSTEAMS_USE_MANAGED_IDENTITY=true", () => {
202
- process.env.MSTEAMS_USE_MANAGED_IDENTITY = "true";
203
- const cfg = {
204
- appId: "app-id",
205
- tenantId: "tenant-id",
206
- authType: "federated",
207
- certificatePath: "/cert.pem",
208
- useManagedIdentity: false,
209
- } as any;
210
- const result = resolveMSTeamsCredentials(cfg);
211
- expect(result).toBeDefined();
212
- expect(result!.type).toBe("federated");
213
- expect((result as any).useManagedIdentity).toBeUndefined();
214
- expect((result as any).certificatePath).toBe("/cert.pem");
215
- });
216
- });
217
-
218
- describe("token – backward compatibility", () => {
219
- beforeEach(saveAndClearEnv);
220
- afterEach(restoreEnv);
221
-
222
- it("defaults to secret when authType is absent", () => {
223
- const cfg = { appId: "app-id", appPassword: "pw", tenantId: "tenant-id" } as any;
224
- const result = resolveMSTeamsCredentials(cfg);
225
- expect(result).toBeDefined();
226
- expect(result!.type).toBe("secret");
227
- });
228
-
229
- it("explicit authType=secret behaves same as absent", () => {
230
- const cfg = {
231
- appId: "app-id",
232
- appPassword: "pw",
233
- tenantId: "tenant-id",
234
- authType: "secret",
235
- } as any;
236
- const result = resolveMSTeamsCredentials(cfg);
237
- expect(result).toEqual({
238
- type: "secret",
239
- appId: "app-id",
240
- appPassword: "pw",
241
- tenantId: "tenant-id",
242
- });
243
- });
244
- });
245
-
246
- describe("readAccessToken", () => {
247
- it("reads string and object token forms", () => {
248
- expect(readAccessToken("abc")).toBe("abc");
249
- expect(readAccessToken({ accessToken: "access-token" })).toBe("access-token");
250
- expect(readAccessToken({ token: "fallback-token" })).toBe("fallback-token");
251
- });
252
-
253
- it("returns null for unsupported token payloads", () => {
254
- expect(readAccessToken({ accessToken: 123 })).toBeNull();
255
- expect(readAccessToken({ token: false })).toBeNull();
256
- expect(readAccessToken(null)).toBeNull();
257
- expect(readAccessToken(undefined)).toBeNull();
258
- });
259
- });
package/src/token.ts DELETED
@@ -1,195 +0,0 @@
1
- import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
2
- import { dirname } from "node:path";
3
- import type { MSTeamsConfig } from "../runtime-api.js";
4
- import type { MSTeamsDelegatedTokens } from "./oauth.shared.js";
5
- import { refreshMSTeamsDelegatedTokens } from "./oauth.token.js";
6
- import {
7
- hasConfiguredSecretInput,
8
- normalizeResolvedSecretInputString,
9
- normalizeSecretInputString,
10
- } from "./secret-input.js";
11
- import { resolveMSTeamsStorePath } from "./storage.js";
12
-
13
- // ── Credential types ───────────────────────────────────────────────────────
14
-
15
- export type MSTeamsSecretCredentials = {
16
- type: "secret";
17
- appId: string;
18
- appPassword: string;
19
- tenantId: string;
20
- };
21
-
22
- export type MSTeamsFederatedCredentials = {
23
- type: "federated";
24
- appId: string;
25
- tenantId: string;
26
- certificatePath?: string;
27
- certificateThumbprint?: string;
28
- useManagedIdentity?: boolean;
29
- managedIdentityClientId?: string;
30
- };
31
-
32
- export type MSTeamsCredentials = MSTeamsSecretCredentials | MSTeamsFederatedCredentials;
33
-
34
- // ── Helpers ────────────────────────────────────────────────────────────────
35
-
36
- function resolveAuthType(cfg?: MSTeamsConfig): "secret" | "federated" {
37
- const fromCfg = cfg?.authType;
38
- if (fromCfg === "secret" || fromCfg === "federated") {
39
- return fromCfg;
40
- }
41
-
42
- const fromEnv = process.env.MSTEAMS_AUTH_TYPE;
43
- if (fromEnv === "federated") {
44
- return "federated";
45
- }
46
-
47
- return "secret";
48
- }
49
-
50
- // ── hasConfiguredMSTeamsCredentials ────────────────────────────────────────
51
-
52
- export function hasConfiguredMSTeamsCredentials(cfg?: MSTeamsConfig): boolean {
53
- const authType = resolveAuthType(cfg);
54
-
55
- const hasAppId = Boolean(
56
- normalizeSecretInputString(cfg?.appId) ||
57
- normalizeSecretInputString(process.env.MSTEAMS_APP_ID),
58
- );
59
- const hasTenantId = Boolean(
60
- normalizeSecretInputString(cfg?.tenantId) ||
61
- normalizeSecretInputString(process.env.MSTEAMS_TENANT_ID),
62
- );
63
-
64
- if (authType === "federated") {
65
- const hasCert = Boolean(cfg?.certificatePath || process.env.MSTEAMS_CERTIFICATE_PATH);
66
- const hasManagedIdentity =
67
- cfg?.useManagedIdentity ?? process.env.MSTEAMS_USE_MANAGED_IDENTITY === "true";
68
-
69
- return hasAppId && hasTenantId && (hasCert || hasManagedIdentity);
70
- }
71
-
72
- // "secret" (default) — original logic
73
- return Boolean(
74
- normalizeSecretInputString(cfg?.appId) &&
75
- hasConfiguredSecretInput(cfg?.appPassword) &&
76
- normalizeSecretInputString(cfg?.tenantId),
77
- );
78
- }
79
-
80
- // ── resolveMSTeamsCredentials ─────────────────────────────────────────────
81
-
82
- export function resolveMSTeamsCredentials(cfg?: MSTeamsConfig): MSTeamsCredentials | undefined {
83
- const authType = resolveAuthType(cfg);
84
-
85
- const appId =
86
- normalizeSecretInputString(cfg?.appId) ||
87
- normalizeSecretInputString(process.env.MSTEAMS_APP_ID);
88
-
89
- const tenantId =
90
- normalizeSecretInputString(cfg?.tenantId) ||
91
- normalizeSecretInputString(process.env.MSTEAMS_TENANT_ID);
92
-
93
- if (!appId || !tenantId) {
94
- return undefined;
95
- }
96
-
97
- if (authType === "federated") {
98
- const certificatePath =
99
- cfg?.certificatePath || process.env.MSTEAMS_CERTIFICATE_PATH || undefined;
100
-
101
- const certificateThumbprint =
102
- cfg?.certificateThumbprint || process.env.MSTEAMS_CERTIFICATE_THUMBPRINT || undefined;
103
-
104
- const useManagedIdentity =
105
- cfg?.useManagedIdentity ?? process.env.MSTEAMS_USE_MANAGED_IDENTITY === "true";
106
-
107
- const managedIdentityClientId =
108
- cfg?.managedIdentityClientId || process.env.MSTEAMS_MANAGED_IDENTITY_CLIENT_ID || undefined;
109
-
110
- // At least one federated mechanism must be configured.
111
- if (!certificatePath && !useManagedIdentity) {
112
- return undefined;
113
- }
114
-
115
- return {
116
- type: "federated",
117
- appId,
118
- tenantId,
119
- certificatePath,
120
- certificateThumbprint,
121
- useManagedIdentity: useManagedIdentity || undefined,
122
- managedIdentityClientId,
123
- };
124
- }
125
-
126
- // "secret" (default) — original logic
127
- const appPassword =
128
- normalizeResolvedSecretInputString({
129
- value: cfg?.appPassword,
130
- path: "channels.msteams.appPassword",
131
- }) || normalizeSecretInputString(process.env.MSTEAMS_APP_PASSWORD);
132
-
133
- if (!appPassword) {
134
- return undefined;
135
- }
136
-
137
- return { type: "secret", appId, appPassword, tenantId };
138
- }
139
-
140
- // ---------------------------------------------------------------------------
141
- // Delegated token storage / resolution
142
- // ---------------------------------------------------------------------------
143
-
144
- const DELEGATED_TOKEN_FILENAME = "msteams-delegated.json";
145
-
146
- function resolveDelegatedTokenPath(): string {
147
- return resolveMSTeamsStorePath({ filename: DELEGATED_TOKEN_FILENAME });
148
- }
149
-
150
- export function loadDelegatedTokens(): MSTeamsDelegatedTokens | undefined {
151
- try {
152
- const content = readFileSync(resolveDelegatedTokenPath(), "utf8");
153
- return JSON.parse(content) as MSTeamsDelegatedTokens;
154
- } catch {
155
- return undefined;
156
- }
157
- }
158
-
159
- export function saveDelegatedTokens(tokens: MSTeamsDelegatedTokens): void {
160
- const tokenPath = resolveDelegatedTokenPath();
161
- const dir = dirname(tokenPath);
162
- mkdirSync(dir, { recursive: true });
163
- writeFileSync(tokenPath, JSON.stringify(tokens, null, 2), "utf8");
164
- }
165
-
166
- export async function resolveDelegatedAccessToken(params: {
167
- tenantId: string;
168
- clientId: string;
169
- clientSecret: string;
170
- }): Promise<string | undefined> {
171
- const tokens = loadDelegatedTokens();
172
- if (!tokens) {
173
- return undefined;
174
- }
175
-
176
- // Token still valid (5-min buffer already baked into expiresAt)
177
- if (tokens.expiresAt > Date.now()) {
178
- return tokens.accessToken;
179
- }
180
-
181
- // Attempt refresh
182
- try {
183
- const refreshed = await refreshMSTeamsDelegatedTokens({
184
- tenantId: params.tenantId,
185
- clientId: params.clientId,
186
- clientSecret: params.clientSecret,
187
- refreshToken: tokens.refreshToken,
188
- scopes: tokens.scopes,
189
- });
190
- saveDelegatedTokens(refreshed);
191
- return refreshed.accessToken;
192
- } catch {
193
- return undefined;
194
- }
195
- }
@@ -1,86 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
-
3
- // Mock the runtime before importing buildUserAgent
4
- const mockRuntime = {
5
- version: "2026.3.19",
6
- };
7
-
8
- vi.mock("./runtime.js", () => ({
9
- getMSTeamsRuntime: vi.fn(() => mockRuntime),
10
- }));
11
-
12
- import { fetchGraphJson } from "./graph.js";
13
- import { getMSTeamsRuntime } from "./runtime.js";
14
- import { buildUserAgent, ensureUserAgentHeader, resetUserAgentCache } from "./user-agent.js";
15
-
16
- describe("buildUserAgent", () => {
17
- beforeEach(() => {
18
- resetUserAgentCache();
19
- vi.mocked(getMSTeamsRuntime).mockReturnValue(mockRuntime as never);
20
- });
21
-
22
- afterEach(() => {
23
- vi.restoreAllMocks();
24
- });
25
-
26
- it("returns teams.ts[apps]/<sdk> OpenClaw/<version> format", () => {
27
- const ua = buildUserAgent();
28
- expect(ua).toMatch(/^teams\.ts\[apps\]\/.+ OpenClaw\/2026\.3\.19$/);
29
- });
30
-
31
- it("reflects the runtime version", () => {
32
- vi.mocked(getMSTeamsRuntime).mockReturnValue({ version: "1.2.3" } as never);
33
- const ua = buildUserAgent();
34
- expect(ua).toMatch(/OpenClaw\/1\.2\.3$/);
35
- });
36
-
37
- it("returns OpenClaw/unknown when runtime is not initialized", () => {
38
- vi.mocked(getMSTeamsRuntime).mockImplementation(() => {
39
- throw new Error("MSTeams runtime not initialized");
40
- });
41
- const ua = buildUserAgent();
42
- expect(ua).toMatch(/OpenClaw\/unknown$/);
43
- // SDK version should still be present
44
- expect(ua).toMatch(/^teams\.ts\[apps\]\//);
45
- });
46
-
47
- it("sends the generated User-Agent in Graph requests by default", async () => {
48
- const mockFetch = vi.fn().mockResolvedValueOnce({
49
- ok: true,
50
- json: async () => ({ value: [] }),
51
- });
52
- vi.stubGlobal("fetch", mockFetch);
53
-
54
- await fetchGraphJson({ token: "test-token", path: "/groups" });
55
-
56
- expect(mockFetch).toHaveBeenCalledOnce();
57
- const [, init] = mockFetch.mock.calls[0];
58
- expect(init.headers["User-Agent"]).toMatch(/^teams\.ts\[apps\]\/.+ OpenClaw\/2026\.3\.19$/);
59
- expect(init.headers).toHaveProperty("Authorization", "Bearer test-token");
60
- });
61
-
62
- it("lets caller headers override the default Graph User-Agent", async () => {
63
- const mockFetch = vi.fn().mockResolvedValueOnce({
64
- ok: true,
65
- json: async () => ({ value: [] }),
66
- });
67
- vi.stubGlobal("fetch", mockFetch);
68
-
69
- await fetchGraphJson({
70
- token: "test-token",
71
- path: "/groups",
72
- headers: { "User-Agent": "custom-agent/1.0" },
73
- });
74
-
75
- const [, init] = mockFetch.mock.calls[0];
76
- expect(init.headers["User-Agent"]).toBe("custom-agent/1.0");
77
- });
78
-
79
- it("adds the generated User-Agent to Headers instances without overwriting callers", () => {
80
- const generated = ensureUserAgentHeader();
81
- expect(generated.get("User-Agent")).toMatch(/^teams\.ts\[apps\]\/.+ OpenClaw\/2026\.3\.19$/);
82
-
83
- const custom = ensureUserAgentHeader({ "User-Agent": "custom-agent/2.0" });
84
- expect(custom.get("User-Agent")).toBe("custom-agent/2.0");
85
- });
86
- });
package/src/user-agent.ts DELETED
@@ -1,53 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import { getMSTeamsRuntime } from "./runtime.js";
3
-
4
- let cachedUserAgent: string | undefined;
5
-
6
- function resolveTeamsSdkVersion(): string {
7
- try {
8
- const require = createRequire(import.meta.url);
9
- const pkg = require("@microsoft/teams.apps/package.json") as { version?: string };
10
- return pkg.version ?? "unknown";
11
- } catch {
12
- return "unknown";
13
- }
14
- }
15
-
16
- function resolveOpenClawVersion(): string {
17
- try {
18
- return getMSTeamsRuntime().version;
19
- } catch {
20
- return "unknown";
21
- }
22
- }
23
-
24
- /**
25
- * Build a combined User-Agent string that preserves the Teams SDK identity
26
- * and appends the OpenClaw version.
27
- *
28
- * Format: "teams.ts[apps]/<sdk-version> OpenClaw/<openclaw-version>"
29
- * Example: "teams.ts[apps]/2.0.5 OpenClaw/2026.3.22"
30
- *
31
- * This lets the Teams backend track SDK usage while also identifying the
32
- * host application.
33
- */
34
- /** Reset the cached User-Agent (for testing). */
35
- export function resetUserAgentCache(): void {
36
- cachedUserAgent = undefined;
37
- }
38
-
39
- export function buildUserAgent(): string {
40
- if (cachedUserAgent) {
41
- return cachedUserAgent;
42
- }
43
- cachedUserAgent = `teams.ts[apps]/${resolveTeamsSdkVersion()} OpenClaw/${resolveOpenClawVersion()}`;
44
- return cachedUserAgent;
45
- }
46
-
47
- export function ensureUserAgentHeader(headers?: HeadersInit): Headers {
48
- const nextHeaders = new Headers(headers);
49
- if (!nextHeaders.has("User-Agent")) {
50
- nextHeaders.set("User-Agent", buildUserAgent());
51
- }
52
- return nextHeaders;
53
- }
@@ -1,27 +0,0 @@
1
- import type { Server } from "node:http";
2
-
3
- const MSTEAMS_WEBHOOK_INACTIVITY_TIMEOUT_MS = 30_000;
4
- const MSTEAMS_WEBHOOK_REQUEST_TIMEOUT_MS = 30_000;
5
- const MSTEAMS_WEBHOOK_HEADERS_TIMEOUT_MS = 15_000;
6
-
7
- type ApplyMSTeamsWebhookTimeoutsOpts = {
8
- inactivityTimeoutMs?: number;
9
- requestTimeoutMs?: number;
10
- headersTimeoutMs?: number;
11
- };
12
-
13
- export function applyMSTeamsWebhookTimeouts(
14
- httpServer: Server,
15
- opts?: ApplyMSTeamsWebhookTimeoutsOpts,
16
- ): void {
17
- const inactivityTimeoutMs = opts?.inactivityTimeoutMs ?? MSTEAMS_WEBHOOK_INACTIVITY_TIMEOUT_MS;
18
- const requestTimeoutMs = opts?.requestTimeoutMs ?? MSTEAMS_WEBHOOK_REQUEST_TIMEOUT_MS;
19
- const headersTimeoutMs = Math.min(
20
- opts?.headersTimeoutMs ?? MSTEAMS_WEBHOOK_HEADERS_TIMEOUT_MS,
21
- requestTimeoutMs,
22
- );
23
-
24
- httpServer.setTimeout(inactivityTimeoutMs);
25
- httpServer.requestTimeout = requestTimeoutMs;
26
- httpServer.headersTimeout = headersTimeoutMs;
27
- }