@openclaw/msteams 2026.1.29

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 (61) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/index.ts +18 -0
  3. package/openclaw.plugin.json +11 -0
  4. package/package.json +36 -0
  5. package/src/attachments/download.ts +206 -0
  6. package/src/attachments/graph.ts +319 -0
  7. package/src/attachments/html.ts +76 -0
  8. package/src/attachments/payload.ts +22 -0
  9. package/src/attachments/shared.ts +235 -0
  10. package/src/attachments/types.ts +37 -0
  11. package/src/attachments.test.ts +424 -0
  12. package/src/attachments.ts +18 -0
  13. package/src/channel.directory.test.ts +46 -0
  14. package/src/channel.ts +436 -0
  15. package/src/conversation-store-fs.test.ts +89 -0
  16. package/src/conversation-store-fs.ts +155 -0
  17. package/src/conversation-store-memory.ts +45 -0
  18. package/src/conversation-store.ts +41 -0
  19. package/src/directory-live.ts +179 -0
  20. package/src/errors.test.ts +46 -0
  21. package/src/errors.ts +158 -0
  22. package/src/file-consent-helpers.test.ts +234 -0
  23. package/src/file-consent-helpers.ts +73 -0
  24. package/src/file-consent.ts +122 -0
  25. package/src/graph-chat.ts +52 -0
  26. package/src/graph-upload.ts +445 -0
  27. package/src/inbound.test.ts +67 -0
  28. package/src/inbound.ts +38 -0
  29. package/src/index.ts +4 -0
  30. package/src/media-helpers.test.ts +186 -0
  31. package/src/media-helpers.ts +77 -0
  32. package/src/messenger.test.ts +245 -0
  33. package/src/messenger.ts +460 -0
  34. package/src/monitor-handler/inbound-media.ts +123 -0
  35. package/src/monitor-handler/message-handler.ts +629 -0
  36. package/src/monitor-handler.ts +166 -0
  37. package/src/monitor-types.ts +5 -0
  38. package/src/monitor.ts +290 -0
  39. package/src/onboarding.ts +432 -0
  40. package/src/outbound.ts +47 -0
  41. package/src/pending-uploads.ts +87 -0
  42. package/src/policy.test.ts +210 -0
  43. package/src/policy.ts +247 -0
  44. package/src/polls-store-memory.ts +30 -0
  45. package/src/polls-store.test.ts +40 -0
  46. package/src/polls.test.ts +73 -0
  47. package/src/polls.ts +300 -0
  48. package/src/probe.test.ts +57 -0
  49. package/src/probe.ts +99 -0
  50. package/src/reply-dispatcher.ts +128 -0
  51. package/src/resolve-allowlist.ts +277 -0
  52. package/src/runtime.ts +14 -0
  53. package/src/sdk-types.ts +19 -0
  54. package/src/sdk.ts +33 -0
  55. package/src/send-context.ts +156 -0
  56. package/src/send.ts +489 -0
  57. package/src/sent-message-cache.test.ts +16 -0
  58. package/src/sent-message-cache.ts +41 -0
  59. package/src/storage.ts +22 -0
  60. package/src/store-fs.ts +80 -0
  61. package/src/token.ts +19 -0
package/src/polls.ts ADDED
@@ -0,0 +1,300 @@
1
+ import crypto from "node:crypto";
2
+
3
+ import { resolveMSTeamsStorePath } from "./storage.js";
4
+ import { readJsonFile, withFileLock, writeJsonFile } from "./store-fs.js";
5
+
6
+ export type MSTeamsPollVote = {
7
+ pollId: string;
8
+ selections: string[];
9
+ };
10
+
11
+ export type MSTeamsPoll = {
12
+ id: string;
13
+ question: string;
14
+ options: string[];
15
+ maxSelections: number;
16
+ createdAt: string;
17
+ updatedAt?: string;
18
+ conversationId?: string;
19
+ messageId?: string;
20
+ votes: Record<string, string[]>;
21
+ };
22
+
23
+ export type MSTeamsPollStore = {
24
+ createPoll: (poll: MSTeamsPoll) => Promise<void>;
25
+ getPoll: (pollId: string) => Promise<MSTeamsPoll | null>;
26
+ recordVote: (params: {
27
+ pollId: string;
28
+ voterId: string;
29
+ selections: string[];
30
+ }) => Promise<MSTeamsPoll | null>;
31
+ };
32
+
33
+ export type MSTeamsPollCard = {
34
+ pollId: string;
35
+ question: string;
36
+ options: string[];
37
+ maxSelections: number;
38
+ card: Record<string, unknown>;
39
+ fallbackText: string;
40
+ };
41
+
42
+ type PollStoreData = {
43
+ version: 1;
44
+ polls: Record<string, MSTeamsPoll>;
45
+ };
46
+
47
+ const STORE_FILENAME = "msteams-polls.json";
48
+ const MAX_POLLS = 1000;
49
+ const POLL_TTL_MS = 30 * 24 * 60 * 60 * 1000;
50
+ function isRecord(value: unknown): value is Record<string, unknown> {
51
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
52
+ }
53
+
54
+ function normalizeChoiceValue(value: unknown): string | null {
55
+ if (typeof value === "string") {
56
+ const trimmed = value.trim();
57
+ return trimmed ? trimmed : null;
58
+ }
59
+ if (typeof value === "number" && Number.isFinite(value)) {
60
+ return String(value);
61
+ }
62
+ return null;
63
+ }
64
+
65
+ function extractSelections(value: unknown): string[] {
66
+ if (Array.isArray(value)) {
67
+ return value.map(normalizeChoiceValue).filter((entry): entry is string => Boolean(entry));
68
+ }
69
+ const normalized = normalizeChoiceValue(value);
70
+ if (!normalized) return [];
71
+ if (normalized.includes(",")) {
72
+ return normalized
73
+ .split(",")
74
+ .map((entry) => entry.trim())
75
+ .filter(Boolean);
76
+ }
77
+ return [normalized];
78
+ }
79
+
80
+ function readNestedValue(value: unknown, keys: Array<string | number>): unknown {
81
+ let current: unknown = value;
82
+ for (const key of keys) {
83
+ if (!isRecord(current)) return undefined;
84
+ current = current[key as keyof typeof current];
85
+ }
86
+ return current;
87
+ }
88
+
89
+ function readNestedString(value: unknown, keys: Array<string | number>): string | undefined {
90
+ const found = readNestedValue(value, keys);
91
+ return typeof found === "string" && found.trim() ? found.trim() : undefined;
92
+ }
93
+
94
+ export function extractMSTeamsPollVote(
95
+ activity: { value?: unknown } | undefined,
96
+ ): MSTeamsPollVote | null {
97
+ const value = activity?.value;
98
+ if (!value || !isRecord(value)) return null;
99
+ const pollId =
100
+ readNestedString(value, ["openclawPollId"]) ??
101
+ readNestedString(value, ["pollId"]) ??
102
+ readNestedString(value, ["openclaw", "pollId"]) ??
103
+ readNestedString(value, ["openclaw", "poll", "id"]) ??
104
+ readNestedString(value, ["data", "openclawPollId"]) ??
105
+ readNestedString(value, ["data", "pollId"]) ??
106
+ readNestedString(value, ["data", "openclaw", "pollId"]);
107
+ if (!pollId) return null;
108
+
109
+ const directSelections = extractSelections(value.choices);
110
+ const nestedSelections = extractSelections(readNestedValue(value, ["choices"]));
111
+ const dataSelections = extractSelections(readNestedValue(value, ["data", "choices"]));
112
+ const selections =
113
+ directSelections.length > 0
114
+ ? directSelections
115
+ : nestedSelections.length > 0
116
+ ? nestedSelections
117
+ : dataSelections;
118
+
119
+ if (selections.length === 0) return null;
120
+
121
+ return {
122
+ pollId,
123
+ selections,
124
+ };
125
+ }
126
+
127
+ export function buildMSTeamsPollCard(params: {
128
+ question: string;
129
+ options: string[];
130
+ maxSelections?: number;
131
+ pollId?: string;
132
+ }): MSTeamsPollCard {
133
+ const pollId = params.pollId ?? crypto.randomUUID();
134
+ const maxSelections =
135
+ typeof params.maxSelections === "number" && params.maxSelections > 1
136
+ ? Math.floor(params.maxSelections)
137
+ : 1;
138
+ const cappedMaxSelections = Math.min(Math.max(1, maxSelections), params.options.length);
139
+ const choices = params.options.map((option, index) => ({
140
+ title: option,
141
+ value: String(index),
142
+ }));
143
+ const hint =
144
+ cappedMaxSelections > 1
145
+ ? `Select up to ${cappedMaxSelections} option${cappedMaxSelections === 1 ? "" : "s"}.`
146
+ : "Select one option.";
147
+
148
+ const card = {
149
+ type: "AdaptiveCard",
150
+ version: "1.5",
151
+ body: [
152
+ {
153
+ type: "TextBlock",
154
+ text: params.question,
155
+ wrap: true,
156
+ weight: "Bolder",
157
+ size: "Medium",
158
+ },
159
+ {
160
+ type: "Input.ChoiceSet",
161
+ id: "choices",
162
+ isMultiSelect: cappedMaxSelections > 1,
163
+ style: "expanded",
164
+ choices,
165
+ },
166
+ {
167
+ type: "TextBlock",
168
+ text: hint,
169
+ wrap: true,
170
+ isSubtle: true,
171
+ spacing: "Small",
172
+ },
173
+ ],
174
+ actions: [
175
+ {
176
+ type: "Action.Submit",
177
+ title: "Vote",
178
+ data: {
179
+ openclawPollId: pollId,
180
+ pollId,
181
+ },
182
+ msteams: {
183
+ type: "messageBack",
184
+ text: "openclaw poll vote",
185
+ displayText: "Vote recorded",
186
+ value: { openclawPollId: pollId, pollId },
187
+ },
188
+ },
189
+ ],
190
+ };
191
+
192
+ const fallbackLines = [
193
+ `Poll: ${params.question}`,
194
+ ...params.options.map((option, index) => `${index + 1}. ${option}`),
195
+ ];
196
+
197
+ return {
198
+ pollId,
199
+ question: params.question,
200
+ options: params.options,
201
+ maxSelections: cappedMaxSelections,
202
+ card,
203
+ fallbackText: fallbackLines.join("\n"),
204
+ };
205
+ }
206
+
207
+ export type MSTeamsPollStoreFsOptions = {
208
+ env?: NodeJS.ProcessEnv;
209
+ homedir?: () => string;
210
+ stateDir?: string;
211
+ storePath?: string;
212
+ };
213
+
214
+ function parseTimestamp(value?: string): number | null {
215
+ if (!value) return null;
216
+ const parsed = Date.parse(value);
217
+ return Number.isFinite(parsed) ? parsed : null;
218
+ }
219
+
220
+ function pruneExpired(polls: Record<string, MSTeamsPoll>) {
221
+ const cutoff = Date.now() - POLL_TTL_MS;
222
+ const entries = Object.entries(polls).filter(([, poll]) => {
223
+ const ts = parseTimestamp(poll.updatedAt ?? poll.createdAt) ?? 0;
224
+ return ts >= cutoff;
225
+ });
226
+ return Object.fromEntries(entries);
227
+ }
228
+
229
+ function pruneToLimit(polls: Record<string, MSTeamsPoll>) {
230
+ const entries = Object.entries(polls);
231
+ if (entries.length <= MAX_POLLS) return polls;
232
+ entries.sort((a, b) => {
233
+ const aTs = parseTimestamp(a[1].updatedAt ?? a[1].createdAt) ?? 0;
234
+ const bTs = parseTimestamp(b[1].updatedAt ?? b[1].createdAt) ?? 0;
235
+ return aTs - bTs;
236
+ });
237
+ const keep = entries.slice(entries.length - MAX_POLLS);
238
+ return Object.fromEntries(keep);
239
+ }
240
+
241
+ export function normalizeMSTeamsPollSelections(poll: MSTeamsPoll, selections: string[]) {
242
+ const maxSelections = Math.max(1, poll.maxSelections);
243
+ const mapped = selections
244
+ .map((entry) => Number.parseInt(entry, 10))
245
+ .filter((value) => Number.isFinite(value))
246
+ .filter((value) => value >= 0 && value < poll.options.length)
247
+ .map((value) => String(value));
248
+ const limited = maxSelections > 1 ? mapped.slice(0, maxSelections) : mapped.slice(0, 1);
249
+ return Array.from(new Set(limited));
250
+ }
251
+
252
+ export function createMSTeamsPollStoreFs(params?: MSTeamsPollStoreFsOptions): MSTeamsPollStore {
253
+ const filePath = resolveMSTeamsStorePath({
254
+ filename: STORE_FILENAME,
255
+ env: params?.env,
256
+ homedir: params?.homedir,
257
+ stateDir: params?.stateDir,
258
+ storePath: params?.storePath,
259
+ });
260
+ const empty: PollStoreData = { version: 1, polls: {} };
261
+
262
+ const readStore = async (): Promise<PollStoreData> => {
263
+ const { value } = await readJsonFile<PollStoreData>(filePath, empty);
264
+ const pruned = pruneToLimit(pruneExpired(value.polls ?? {}));
265
+ return { version: 1, polls: pruned };
266
+ };
267
+
268
+ const writeStore = async (data: PollStoreData) => {
269
+ await writeJsonFile(filePath, data);
270
+ };
271
+
272
+ const createPoll = async (poll: MSTeamsPoll) => {
273
+ await withFileLock(filePath, empty, async () => {
274
+ const data = await readStore();
275
+ data.polls[poll.id] = poll;
276
+ await writeStore({ version: 1, polls: pruneToLimit(data.polls) });
277
+ });
278
+ };
279
+
280
+ const getPoll = async (pollId: string) =>
281
+ await withFileLock(filePath, empty, async () => {
282
+ const data = await readStore();
283
+ return data.polls[pollId] ?? null;
284
+ });
285
+
286
+ const recordVote = async (params: { pollId: string; voterId: string; selections: string[] }) =>
287
+ await withFileLock(filePath, empty, async () => {
288
+ const data = await readStore();
289
+ const poll = data.polls[params.pollId];
290
+ if (!poll) return null;
291
+ const normalized = normalizeMSTeamsPollSelections(poll, params.selections);
292
+ poll.votes[params.voterId] = normalized;
293
+ poll.updatedAt = new Date().toISOString();
294
+ data.polls[poll.id] = poll;
295
+ await writeStore({ version: 1, polls: pruneToLimit(data.polls) });
296
+ return poll;
297
+ });
298
+
299
+ return { createPoll, getPoll, recordVote };
300
+ }
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+
3
+ import type { MSTeamsConfig } from "openclaw/plugin-sdk";
4
+
5
+ const hostMockState = vi.hoisted(() => ({
6
+ tokenError: null as Error | null,
7
+ }));
8
+
9
+ vi.mock("@microsoft/agents-hosting", () => ({
10
+ getAuthConfigWithDefaults: (cfg: unknown) => cfg,
11
+ MsalTokenProvider: class {
12
+ async getAccessToken() {
13
+ if (hostMockState.tokenError) throw hostMockState.tokenError;
14
+ return "token";
15
+ }
16
+ },
17
+ }));
18
+
19
+ import { probeMSTeams } from "./probe.js";
20
+
21
+ describe("msteams probe", () => {
22
+ it("returns an error when credentials are missing", async () => {
23
+ const cfg = { enabled: true } as unknown as MSTeamsConfig;
24
+ await expect(probeMSTeams(cfg)).resolves.toMatchObject({
25
+ ok: false,
26
+ });
27
+ });
28
+
29
+ it("validates credentials by acquiring a token", async () => {
30
+ hostMockState.tokenError = null;
31
+ const cfg = {
32
+ enabled: true,
33
+ appId: "app",
34
+ appPassword: "pw",
35
+ tenantId: "tenant",
36
+ } as unknown as MSTeamsConfig;
37
+ await expect(probeMSTeams(cfg)).resolves.toMatchObject({
38
+ ok: true,
39
+ appId: "app",
40
+ });
41
+ });
42
+
43
+ it("returns a helpful error when token acquisition fails", async () => {
44
+ hostMockState.tokenError = new Error("bad creds");
45
+ const cfg = {
46
+ enabled: true,
47
+ appId: "app",
48
+ appPassword: "pw",
49
+ tenantId: "tenant",
50
+ } as unknown as MSTeamsConfig;
51
+ await expect(probeMSTeams(cfg)).resolves.toMatchObject({
52
+ ok: false,
53
+ appId: "app",
54
+ error: "bad creds",
55
+ });
56
+ });
57
+ });
package/src/probe.ts ADDED
@@ -0,0 +1,99 @@
1
+ import type { MSTeamsConfig } from "openclaw/plugin-sdk";
2
+ import { formatUnknownError } from "./errors.js";
3
+ import { loadMSTeamsSdkWithAuth } from "./sdk.js";
4
+ import { resolveMSTeamsCredentials } from "./token.js";
5
+
6
+ export type ProbeMSTeamsResult = {
7
+ ok: boolean;
8
+ error?: string;
9
+ appId?: string;
10
+ graph?: {
11
+ ok: boolean;
12
+ error?: string;
13
+ roles?: string[];
14
+ scopes?: string[];
15
+ };
16
+ };
17
+
18
+ function readAccessToken(value: unknown): string | null {
19
+ if (typeof value === "string") return value;
20
+ if (value && typeof value === "object") {
21
+ const token =
22
+ (value as { accessToken?: unknown }).accessToken ??
23
+ (value as { token?: unknown }).token;
24
+ return typeof token === "string" ? token : null;
25
+ }
26
+ return null;
27
+ }
28
+
29
+ function decodeJwtPayload(token: string): Record<string, unknown> | null {
30
+ const parts = token.split(".");
31
+ if (parts.length < 2) return null;
32
+ const payload = parts[1] ?? "";
33
+ const padded = payload.padEnd(payload.length + ((4 - (payload.length % 4)) % 4), "=");
34
+ const normalized = padded.replace(/-/g, "+").replace(/_/g, "/");
35
+ try {
36
+ const decoded = Buffer.from(normalized, "base64").toString("utf8");
37
+ const parsed = JSON.parse(decoded) as Record<string, unknown>;
38
+ return parsed && typeof parsed === "object" ? parsed : null;
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+
44
+ function readStringArray(value: unknown): string[] | undefined {
45
+ if (!Array.isArray(value)) return undefined;
46
+ const out = value.map((entry) => String(entry).trim()).filter(Boolean);
47
+ return out.length > 0 ? out : undefined;
48
+ }
49
+
50
+ function readScopes(value: unknown): string[] | undefined {
51
+ if (typeof value !== "string") return undefined;
52
+ const out = value.split(/\s+/).map((entry) => entry.trim()).filter(Boolean);
53
+ return out.length > 0 ? out : undefined;
54
+ }
55
+
56
+ export async function probeMSTeams(cfg?: MSTeamsConfig): Promise<ProbeMSTeamsResult> {
57
+ const creds = resolveMSTeamsCredentials(cfg);
58
+ if (!creds) {
59
+ return {
60
+ ok: false,
61
+ error: "missing credentials (appId, appPassword, tenantId)",
62
+ };
63
+ }
64
+
65
+ try {
66
+ const { sdk, authConfig } = await loadMSTeamsSdkWithAuth(creds);
67
+ const tokenProvider = new sdk.MsalTokenProvider(authConfig);
68
+ await tokenProvider.getAccessToken("https://api.botframework.com");
69
+ let graph:
70
+ | {
71
+ ok: boolean;
72
+ error?: string;
73
+ roles?: string[];
74
+ scopes?: string[];
75
+ }
76
+ | undefined;
77
+ try {
78
+ const graphToken = await tokenProvider.getAccessToken(
79
+ "https://graph.microsoft.com",
80
+ );
81
+ const accessToken = readAccessToken(graphToken);
82
+ const payload = accessToken ? decodeJwtPayload(accessToken) : null;
83
+ graph = {
84
+ ok: true,
85
+ roles: readStringArray(payload?.roles),
86
+ scopes: readScopes(payload?.scp),
87
+ };
88
+ } catch (err) {
89
+ graph = { ok: false, error: formatUnknownError(err) };
90
+ }
91
+ return { ok: true, appId: creds.appId, ...(graph ? { graph } : {}) };
92
+ } catch (err) {
93
+ return {
94
+ ok: false,
95
+ appId: creds.appId,
96
+ error: formatUnknownError(err),
97
+ };
98
+ }
99
+ }
@@ -0,0 +1,128 @@
1
+ import {
2
+ createReplyPrefixContext,
3
+ createTypingCallbacks,
4
+ logTypingFailure,
5
+ resolveChannelMediaMaxBytes,
6
+ type OpenClawConfig,
7
+ type MSTeamsReplyStyle,
8
+ type RuntimeEnv,
9
+ } from "openclaw/plugin-sdk";
10
+ import type { MSTeamsAccessTokenProvider } from "./attachments/types.js";
11
+ import type { StoredConversationReference } from "./conversation-store.js";
12
+ import {
13
+ classifyMSTeamsSendError,
14
+ formatMSTeamsSendErrorHint,
15
+ formatUnknownError,
16
+ } from "./errors.js";
17
+ import {
18
+ type MSTeamsAdapter,
19
+ renderReplyPayloadsToMessages,
20
+ sendMSTeamsMessages,
21
+ } from "./messenger.js";
22
+ import type { MSTeamsMonitorLogger } from "./monitor-types.js";
23
+ import type { MSTeamsTurnContext } from "./sdk-types.js";
24
+ import { getMSTeamsRuntime } from "./runtime.js";
25
+
26
+ export function createMSTeamsReplyDispatcher(params: {
27
+ cfg: OpenClawConfig;
28
+ agentId: string;
29
+ runtime: RuntimeEnv;
30
+ log: MSTeamsMonitorLogger;
31
+ adapter: MSTeamsAdapter;
32
+ appId: string;
33
+ conversationRef: StoredConversationReference;
34
+ context: MSTeamsTurnContext;
35
+ replyStyle: MSTeamsReplyStyle;
36
+ textLimit: number;
37
+ onSentMessageIds?: (ids: string[]) => void;
38
+ /** Token provider for OneDrive/SharePoint uploads in group chats/channels */
39
+ tokenProvider?: MSTeamsAccessTokenProvider;
40
+ /** SharePoint site ID for file uploads in group chats/channels */
41
+ sharePointSiteId?: string;
42
+ }) {
43
+ const core = getMSTeamsRuntime();
44
+ const sendTypingIndicator = async () => {
45
+ await params.context.sendActivity({ type: "typing" });
46
+ };
47
+ const typingCallbacks = createTypingCallbacks({
48
+ start: sendTypingIndicator,
49
+ onStartError: (err) => {
50
+ logTypingFailure({
51
+ log: (message) => params.log.debug(message),
52
+ channel: "msteams",
53
+ action: "start",
54
+ error: err,
55
+ });
56
+ },
57
+ });
58
+ const prefixContext = createReplyPrefixContext({
59
+ cfg: params.cfg,
60
+ agentId: params.agentId,
61
+ });
62
+ const chunkMode = core.channel.text.resolveChunkMode(params.cfg, "msteams");
63
+
64
+ const { dispatcher, replyOptions, markDispatchIdle } =
65
+ core.channel.reply.createReplyDispatcherWithTyping({
66
+ responsePrefix: prefixContext.responsePrefix,
67
+ responsePrefixContextProvider: prefixContext.responsePrefixContextProvider,
68
+ humanDelay: core.channel.reply.resolveHumanDelayConfig(params.cfg, params.agentId),
69
+ deliver: async (payload) => {
70
+ const tableMode = core.channel.text.resolveMarkdownTableMode({
71
+ cfg: params.cfg,
72
+ channel: "msteams",
73
+ });
74
+ const messages = renderReplyPayloadsToMessages([payload], {
75
+ textChunkLimit: params.textLimit,
76
+ chunkText: true,
77
+ mediaMode: "split",
78
+ tableMode,
79
+ chunkMode,
80
+ });
81
+ const mediaMaxBytes = resolveChannelMediaMaxBytes({
82
+ cfg: params.cfg,
83
+ resolveChannelLimitMb: ({ cfg }) => cfg.channels?.msteams?.mediaMaxMb,
84
+ });
85
+ const ids = await sendMSTeamsMessages({
86
+ replyStyle: params.replyStyle,
87
+ adapter: params.adapter,
88
+ appId: params.appId,
89
+ conversationRef: params.conversationRef,
90
+ context: params.context,
91
+ messages,
92
+ // Enable default retry/backoff for throttling/transient failures.
93
+ retry: {},
94
+ onRetry: (event) => {
95
+ params.log.debug("retrying send", {
96
+ replyStyle: params.replyStyle,
97
+ ...event,
98
+ });
99
+ },
100
+ tokenProvider: params.tokenProvider,
101
+ sharePointSiteId: params.sharePointSiteId,
102
+ mediaMaxBytes,
103
+ });
104
+ if (ids.length > 0) params.onSentMessageIds?.(ids);
105
+ },
106
+ onError: (err, info) => {
107
+ const errMsg = formatUnknownError(err);
108
+ const classification = classifyMSTeamsSendError(err);
109
+ const hint = formatMSTeamsSendErrorHint(classification);
110
+ params.runtime.error?.(
111
+ `msteams ${info.kind} reply failed: ${errMsg}${hint ? ` (${hint})` : ""}`,
112
+ );
113
+ params.log.error("reply failed", {
114
+ kind: info.kind,
115
+ error: errMsg,
116
+ classification,
117
+ hint,
118
+ });
119
+ },
120
+ onReplyStart: typingCallbacks.onReplyStart,
121
+ });
122
+
123
+ return {
124
+ dispatcher,
125
+ replyOptions: { ...replyOptions, onModelSelected: prefixContext.onModelSelected },
126
+ markDispatchIdle,
127
+ };
128
+ }