@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.
- package/dist/api.js +3 -0
- package/dist/channel-D7hdreTh.js +984 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-BC1ruIfN.js +573 -0
- package/dist/config-schema-B8QezH6t.js +15 -0
- package/dist/contract-api.js +2 -0
- package/dist/graph-users-9uQJepqr.js +1354 -0
- package/dist/index.js +22 -0
- package/dist/oauth-BWJyilR1.js +114 -0
- package/dist/oauth.token-xxpoLWy5.js +115 -0
- package/dist/policy-DTnU2GR7.js +142 -0
- package/dist/probe-D_H8yFps.js +2194 -0
- package/dist/resolve-allowlist-D41JSziq.js +219 -0
- package/dist/runtime-api-DV1iVMn1.js +28 -0
- package/dist/runtime-api.js +2 -0
- package/dist/secret-contract-BuoEXmPS.js +35 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/setup-plugin-api.js +64 -0
- package/dist/setup-surface-BLkFQYIQ.js +313 -0
- package/dist/src-CFp1QpFd.js +4064 -0
- package/dist/test-api.js +2 -0
- package/package.json +14 -6
- package/api.ts +0 -3
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -2
- package/config-api.ts +0 -4
- package/contract-api.ts +0 -4
- package/index.ts +0 -20
- package/runtime-api.ts +0 -73
- package/secret-contract-api.ts +0 -5
- package/setup-entry.ts +0 -13
- package/setup-plugin-api.ts +0 -3
- package/src/ai-entity.ts +0 -7
- package/src/approval-auth.ts +0 -44
- package/src/attachments/bot-framework.test.ts +0 -461
- package/src/attachments/bot-framework.ts +0 -362
- package/src/attachments/download.ts +0 -311
- package/src/attachments/graph.test.ts +0 -416
- package/src/attachments/graph.ts +0 -484
- package/src/attachments/html.ts +0 -122
- package/src/attachments/payload.ts +0 -14
- package/src/attachments/remote-media.test.ts +0 -137
- package/src/attachments/remote-media.ts +0 -112
- package/src/attachments/shared.test.ts +0 -530
- package/src/attachments/shared.ts +0 -626
- package/src/attachments/types.ts +0 -47
- package/src/attachments.graph.test.ts +0 -342
- package/src/attachments.helpers.test.ts +0 -246
- package/src/attachments.test-helpers.ts +0 -17
- package/src/attachments.test.ts +0 -687
- package/src/attachments.ts +0 -18
- package/src/block-streaming-config.test.ts +0 -61
- package/src/channel-api.ts +0 -1
- package/src/channel.actions.test.ts +0 -742
- package/src/channel.directory.test.ts +0 -200
- package/src/channel.runtime.ts +0 -56
- package/src/channel.setup.ts +0 -77
- package/src/channel.test.ts +0 -128
- package/src/channel.ts +0 -1136
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -12
- package/src/conversation-store-fs.test.ts +0 -74
- package/src/conversation-store-fs.ts +0 -149
- package/src/conversation-store-helpers.test.ts +0 -202
- package/src/conversation-store-helpers.ts +0 -105
- package/src/conversation-store-memory.ts +0 -51
- package/src/conversation-store.shared.test.ts +0 -225
- package/src/conversation-store.ts +0 -71
- package/src/directory-live.test.ts +0 -156
- package/src/directory-live.ts +0 -111
- package/src/doctor.ts +0 -27
- package/src/errors.test.ts +0 -133
- package/src/errors.ts +0 -246
- package/src/feedback-reflection-prompt.ts +0 -117
- package/src/feedback-reflection-store.ts +0 -114
- package/src/feedback-reflection.test.ts +0 -237
- package/src/feedback-reflection.ts +0 -283
- package/src/file-consent-helpers.test.ts +0 -326
- package/src/file-consent-helpers.ts +0 -126
- package/src/file-consent-invoke.ts +0 -150
- package/src/file-consent.test.ts +0 -363
- package/src/file-consent.ts +0 -287
- package/src/graph-chat.ts +0 -55
- package/src/graph-group-management.test.ts +0 -318
- package/src/graph-group-management.ts +0 -168
- package/src/graph-members.test.ts +0 -89
- package/src/graph-members.ts +0 -48
- package/src/graph-messages.actions.test.ts +0 -243
- package/src/graph-messages.read.test.ts +0 -391
- package/src/graph-messages.search.test.ts +0 -213
- package/src/graph-messages.test-helpers.ts +0 -50
- package/src/graph-messages.ts +0 -534
- package/src/graph-teams.test.ts +0 -215
- package/src/graph-teams.ts +0 -114
- package/src/graph-thread.test.ts +0 -246
- package/src/graph-thread.ts +0 -146
- package/src/graph-upload.test.ts +0 -258
- package/src/graph-upload.ts +0 -531
- package/src/graph-users.ts +0 -29
- package/src/graph.test.ts +0 -516
- package/src/graph.ts +0 -293
- package/src/inbound.test.ts +0 -221
- package/src/inbound.ts +0 -148
- package/src/index.ts +0 -4
- package/src/media-helpers.test.ts +0 -202
- package/src/media-helpers.ts +0 -105
- package/src/mentions.test.ts +0 -244
- package/src/mentions.ts +0 -114
- package/src/messenger.test.ts +0 -865
- package/src/messenger.ts +0 -605
- package/src/monitor-handler/access.ts +0 -125
- package/src/monitor-handler/inbound-media.test.ts +0 -289
- package/src/monitor-handler/inbound-media.ts +0 -180
- package/src/monitor-handler/message-handler-mock-support.test-support.ts +0 -28
- package/src/monitor-handler/message-handler.authz.test.ts +0 -669
- package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
- package/src/monitor-handler/message-handler.test-support.ts +0 -100
- package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -223
- package/src/monitor-handler/message-handler.thread-session.test.ts +0 -77
- package/src/monitor-handler/message-handler.ts +0 -1000
- package/src/monitor-handler/reaction-handler.test.ts +0 -267
- package/src/monitor-handler/reaction-handler.ts +0 -210
- package/src/monitor-handler/thread-session.ts +0 -17
- package/src/monitor-handler.adaptive-card.test.ts +0 -162
- package/src/monitor-handler.feedback-authz.test.ts +0 -314
- package/src/monitor-handler.file-consent.test.ts +0 -423
- package/src/monitor-handler.sso.test.ts +0 -563
- package/src/monitor-handler.test-helpers.ts +0 -180
- package/src/monitor-handler.ts +0 -534
- package/src/monitor-handler.types.ts +0 -27
- package/src/monitor-types.ts +0 -6
- package/src/monitor.lifecycle.test.ts +0 -278
- package/src/monitor.test.ts +0 -119
- package/src/monitor.ts +0 -442
- package/src/oauth.flow.ts +0 -77
- package/src/oauth.shared.ts +0 -37
- package/src/oauth.test.ts +0 -305
- package/src/oauth.token.ts +0 -158
- package/src/oauth.ts +0 -130
- package/src/outbound.test.ts +0 -130
- package/src/outbound.ts +0 -71
- package/src/pending-uploads-fs.test.ts +0 -246
- package/src/pending-uploads-fs.ts +0 -235
- package/src/pending-uploads.test.ts +0 -173
- package/src/pending-uploads.ts +0 -121
- package/src/policy.test.ts +0 -240
- package/src/policy.ts +0 -262
- package/src/polls-store-memory.ts +0 -32
- package/src/polls.test.ts +0 -160
- package/src/polls.ts +0 -323
- package/src/presentation.ts +0 -68
- package/src/probe.test.ts +0 -77
- package/src/probe.ts +0 -132
- package/src/reply-dispatcher.test.ts +0 -437
- package/src/reply-dispatcher.ts +0 -346
- package/src/reply-stream-controller.test.ts +0 -235
- package/src/reply-stream-controller.ts +0 -147
- package/src/resolve-allowlist.test.ts +0 -250
- package/src/resolve-allowlist.ts +0 -309
- package/src/revoked-context.ts +0 -17
- package/src/runtime.ts +0 -9
- package/src/sdk-types.ts +0 -59
- package/src/sdk.test.ts +0 -666
- package/src/sdk.ts +0 -884
- package/src/secret-contract.ts +0 -49
- package/src/secret-input.ts +0 -7
- package/src/send-context.ts +0 -231
- package/src/send.test.ts +0 -493
- package/src/send.ts +0 -637
- package/src/sent-message-cache.test.ts +0 -15
- package/src/sent-message-cache.ts +0 -56
- package/src/session-route.ts +0 -40
- package/src/setup-core.ts +0 -160
- package/src/setup-surface.test.ts +0 -202
- package/src/setup-surface.ts +0 -320
- package/src/sso-token-store.test.ts +0 -72
- package/src/sso-token-store.ts +0 -166
- package/src/sso.ts +0 -300
- package/src/storage.ts +0 -25
- package/src/store-fs.ts +0 -44
- package/src/streaming-message.test.ts +0 -262
- package/src/streaming-message.ts +0 -297
- package/src/test-runtime.ts +0 -16
- package/src/thread-parent-context.test.ts +0 -224
- package/src/thread-parent-context.ts +0 -159
- package/src/token-response.ts +0 -11
- package/src/token.test.ts +0 -259
- package/src/token.ts +0 -195
- package/src/user-agent.test.ts +0 -86
- package/src/user-agent.ts +0 -53
- package/src/webhook-timeouts.ts +0 -27
- package/src/welcome-card.test.ts +0 -81
- package/src/welcome-card.ts +0 -57
- package/test-api.ts +0 -1
- package/tsconfig.json +0 -16
package/src/channel.ts
DELETED
|
@@ -1,1136 +0,0 @@
|
|
|
1
|
-
import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
|
|
2
|
-
import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from";
|
|
3
|
-
import { createTopLevelChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
|
|
4
|
-
import type {
|
|
5
|
-
ChannelMessageActionAdapter,
|
|
6
|
-
ChannelMessageToolDiscovery,
|
|
7
|
-
} from "openclaw/plugin-sdk/channel-contract";
|
|
8
|
-
import { createChatChannelPlugin } from "openclaw/plugin-sdk/channel-core";
|
|
9
|
-
import { createPairingPrefixStripper } from "openclaw/plugin-sdk/channel-pairing";
|
|
10
|
-
import {
|
|
11
|
-
createAllowlistProviderGroupPolicyWarningCollector,
|
|
12
|
-
projectConfigWarningCollector,
|
|
13
|
-
} from "openclaw/plugin-sdk/channel-policy";
|
|
14
|
-
import {
|
|
15
|
-
createChannelDirectoryAdapter,
|
|
16
|
-
createRuntimeDirectoryLiveAdapter,
|
|
17
|
-
listDirectoryEntriesFromSources,
|
|
18
|
-
} from "openclaw/plugin-sdk/directory-runtime";
|
|
19
|
-
import { normalizeMessagePresentation } from "openclaw/plugin-sdk/interactive-runtime";
|
|
20
|
-
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
|
|
21
|
-
import { createRuntimeOutboundDelegates } from "openclaw/plugin-sdk/outbound-runtime";
|
|
22
|
-
import { createComputedAccountStatusAdapter } from "openclaw/plugin-sdk/status-helpers";
|
|
23
|
-
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
|
24
|
-
import { Type } from "typebox";
|
|
25
|
-
import type { ChannelMessageActionName, ChannelPlugin, OpenClawConfig } from "../runtime-api.js";
|
|
26
|
-
import {
|
|
27
|
-
buildProbeChannelStatusSummary,
|
|
28
|
-
chunkTextForOutbound,
|
|
29
|
-
createDefaultChannelRuntimeState,
|
|
30
|
-
DEFAULT_ACCOUNT_ID,
|
|
31
|
-
PAIRING_APPROVED_MESSAGE,
|
|
32
|
-
} from "../runtime-api.js";
|
|
33
|
-
import { msTeamsApprovalAuth } from "./approval-auth.js";
|
|
34
|
-
import { MSTeamsChannelConfigSchema } from "./config-schema.js";
|
|
35
|
-
import { collectMSTeamsMutableAllowlistWarnings } from "./doctor.js";
|
|
36
|
-
import { resolveMSTeamsGroupToolPolicy } from "./policy.js";
|
|
37
|
-
import { buildMSTeamsPresentationCard } from "./presentation.js";
|
|
38
|
-
import type { ProbeMSTeamsResult } from "./probe.js";
|
|
39
|
-
import {
|
|
40
|
-
normalizeMSTeamsMessagingTarget,
|
|
41
|
-
normalizeMSTeamsUserInput,
|
|
42
|
-
looksLikeMSTeamsTargetId,
|
|
43
|
-
parseMSTeamsConversationId,
|
|
44
|
-
parseMSTeamsTeamChannelInput,
|
|
45
|
-
resolveMSTeamsChannelAllowlist,
|
|
46
|
-
resolveMSTeamsUserAllowlist,
|
|
47
|
-
} from "./resolve-allowlist.js";
|
|
48
|
-
import { resolveMSTeamsOutboundSessionRoute } from "./session-route.js";
|
|
49
|
-
import { msteamsSetupAdapter } from "./setup-core.js";
|
|
50
|
-
import { msteamsSetupWizard } from "./setup-surface.js";
|
|
51
|
-
import { resolveMSTeamsCredentials } from "./token.js";
|
|
52
|
-
|
|
53
|
-
type ResolvedMSTeamsAccount = {
|
|
54
|
-
accountId: string;
|
|
55
|
-
enabled: boolean;
|
|
56
|
-
configured: boolean;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const meta = {
|
|
60
|
-
id: "msteams",
|
|
61
|
-
label: "Microsoft Teams",
|
|
62
|
-
selectionLabel: "Microsoft Teams (Bot Framework)",
|
|
63
|
-
docsPath: "/channels/msteams",
|
|
64
|
-
docsLabel: "msteams",
|
|
65
|
-
blurb: "Teams SDK; enterprise support.",
|
|
66
|
-
aliases: ["teams"],
|
|
67
|
-
order: 60,
|
|
68
|
-
} as const;
|
|
69
|
-
|
|
70
|
-
const TEAMS_GRAPH_PERMISSION_HINTS: Record<string, string> = {
|
|
71
|
-
"ChannelMessage.Read.All": "channel history",
|
|
72
|
-
"Chat.Read.All": "chat history",
|
|
73
|
-
"Channel.ReadBasic.All": "channel list",
|
|
74
|
-
"Team.ReadBasic.All": "team list",
|
|
75
|
-
"TeamsActivity.Read.All": "teams activity",
|
|
76
|
-
"Sites.Read.All": "files (SharePoint)",
|
|
77
|
-
"Files.Read.All": "files (OneDrive)",
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const collectMSTeamsSecurityWarnings = createAllowlistProviderGroupPolicyWarningCollector<{
|
|
81
|
-
cfg: OpenClawConfig;
|
|
82
|
-
}>({
|
|
83
|
-
providerConfigPresent: (cfg) => cfg.channels?.msteams !== undefined,
|
|
84
|
-
resolveGroupPolicy: ({ cfg }) => cfg.channels?.msteams?.groupPolicy,
|
|
85
|
-
collect: ({ groupPolicy }) =>
|
|
86
|
-
groupPolicy === "open"
|
|
87
|
-
? [
|
|
88
|
-
'- MS Teams groups: groupPolicy="open" allows any member to trigger (mention-gated). Set channels.msteams.groupPolicy="allowlist" + channels.msteams.groupAllowFrom to restrict senders.',
|
|
89
|
-
]
|
|
90
|
-
: [],
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const loadMSTeamsChannelRuntime = createLazyRuntimeNamedExport(
|
|
94
|
-
() => import("./channel.runtime.js"),
|
|
95
|
-
"msTeamsChannelRuntime",
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const resolveMSTeamsChannelConfig = (cfg: OpenClawConfig) => ({
|
|
99
|
-
allowFrom: cfg.channels?.msteams?.allowFrom,
|
|
100
|
-
defaultTo: cfg.channels?.msteams?.defaultTo,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const msteamsConfigAdapter = createTopLevelChannelConfigAdapter<
|
|
104
|
-
ResolvedMSTeamsAccount,
|
|
105
|
-
{
|
|
106
|
-
allowFrom?: Array<string | number>;
|
|
107
|
-
defaultTo?: string;
|
|
108
|
-
}
|
|
109
|
-
>({
|
|
110
|
-
sectionKey: "msteams",
|
|
111
|
-
resolveAccount: (cfg) => ({
|
|
112
|
-
accountId: DEFAULT_ACCOUNT_ID,
|
|
113
|
-
enabled: cfg.channels?.msteams?.enabled !== false,
|
|
114
|
-
configured: Boolean(resolveMSTeamsCredentials(cfg.channels?.msteams)),
|
|
115
|
-
}),
|
|
116
|
-
resolveAccessorAccount: ({ cfg }) => resolveMSTeamsChannelConfig(cfg),
|
|
117
|
-
resolveAllowFrom: (account) => account.allowFrom,
|
|
118
|
-
formatAllowFrom: (allowFrom) => formatAllowFromLowercase({ allowFrom }),
|
|
119
|
-
resolveDefaultTo: (account) => account.defaultTo,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
function jsonActionResult(data: Record<string, unknown>) {
|
|
123
|
-
const text = JSON.stringify(data);
|
|
124
|
-
return {
|
|
125
|
-
content: [{ type: "text" as const, text }],
|
|
126
|
-
details: data,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function jsonMSTeamsActionResult(action: string, data: Record<string, unknown> = {}) {
|
|
131
|
-
return jsonActionResult({ channel: "msteams", action, ...data });
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function jsonMSTeamsOkActionResult(action: string, data: Record<string, unknown> = {}) {
|
|
135
|
-
return jsonActionResult({ ok: true, channel: "msteams", action, ...data });
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function jsonMSTeamsConversationResult(conversationId: string | undefined) {
|
|
139
|
-
return jsonActionResultWithDetails(
|
|
140
|
-
{
|
|
141
|
-
ok: true,
|
|
142
|
-
channel: "msteams",
|
|
143
|
-
conversationId,
|
|
144
|
-
},
|
|
145
|
-
{ ok: true, channel: "msteams" },
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function jsonActionResultWithDetails(
|
|
150
|
-
contentData: Record<string, unknown>,
|
|
151
|
-
details: Record<string, unknown>,
|
|
152
|
-
) {
|
|
153
|
-
return {
|
|
154
|
-
content: [{ type: "text" as const, text: JSON.stringify(contentData) }],
|
|
155
|
-
details,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const MSTEAMS_REACTION_TYPES = ["like", "heart", "laugh", "surprised", "sad", "angry"] as const;
|
|
160
|
-
|
|
161
|
-
function actionError(message: string) {
|
|
162
|
-
return {
|
|
163
|
-
isError: true as const,
|
|
164
|
-
content: [{ type: "text" as const, text: message }],
|
|
165
|
-
details: { error: message },
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function resolveActionTarget(
|
|
170
|
-
params: Record<string, unknown>,
|
|
171
|
-
currentChannelId?: string | null,
|
|
172
|
-
): string {
|
|
173
|
-
return typeof params.to === "string"
|
|
174
|
-
? params.to.trim()
|
|
175
|
-
: typeof params.target === "string"
|
|
176
|
-
? params.target.trim()
|
|
177
|
-
: (currentChannelId?.trim() ?? "");
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function resolveGraphActionTarget(
|
|
181
|
-
params: Record<string, unknown>,
|
|
182
|
-
currentChannelId?: string | null,
|
|
183
|
-
currentGraphChannelId?: string | null,
|
|
184
|
-
): string {
|
|
185
|
-
return resolveActionTarget(params, currentGraphChannelId ?? currentChannelId);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function resolveActionMessageId(params: Record<string, unknown>): string {
|
|
189
|
-
return normalizeOptionalString(params.messageId) ?? "";
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function resolveActionPinnedMessageId(params: Record<string, unknown>): string {
|
|
193
|
-
return typeof params.pinnedMessageId === "string"
|
|
194
|
-
? params.pinnedMessageId.trim()
|
|
195
|
-
: typeof params.messageId === "string"
|
|
196
|
-
? params.messageId.trim()
|
|
197
|
-
: "";
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function resolveActionQuery(params: Record<string, unknown>): string {
|
|
201
|
-
return normalizeOptionalString(params.query) ?? "";
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function resolveActionContent(params: Record<string, unknown>): string {
|
|
205
|
-
return typeof params.text === "string"
|
|
206
|
-
? params.text
|
|
207
|
-
: typeof params.content === "string"
|
|
208
|
-
? params.content
|
|
209
|
-
: typeof params.message === "string"
|
|
210
|
-
? params.message
|
|
211
|
-
: "";
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function readOptionalTrimmedString(
|
|
215
|
-
params: Record<string, unknown>,
|
|
216
|
-
key: string,
|
|
217
|
-
): string | undefined {
|
|
218
|
-
return typeof params[key] === "string" ? params[key].trim() || undefined : undefined;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function resolveActionUploadFilePath(params: Record<string, unknown>): string | undefined {
|
|
222
|
-
for (const key of ["filePath", "path", "media"] as const) {
|
|
223
|
-
if (typeof params[key] === "string") {
|
|
224
|
-
const value = params[key];
|
|
225
|
-
if (value.trim()) {
|
|
226
|
-
return value;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return undefined;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function resolveRequiredActionTarget(params: {
|
|
234
|
-
actionLabel: string;
|
|
235
|
-
toolParams: Record<string, unknown>;
|
|
236
|
-
currentChannelId?: string | null;
|
|
237
|
-
currentGraphChannelId?: string | null;
|
|
238
|
-
graphOnly?: boolean;
|
|
239
|
-
}): string | ReturnType<typeof actionError> {
|
|
240
|
-
const to = params.graphOnly
|
|
241
|
-
? resolveGraphActionTarget(
|
|
242
|
-
params.toolParams,
|
|
243
|
-
params.currentChannelId,
|
|
244
|
-
params.currentGraphChannelId,
|
|
245
|
-
)
|
|
246
|
-
: resolveActionTarget(params.toolParams, params.currentChannelId);
|
|
247
|
-
if (!to) {
|
|
248
|
-
return actionError(`${params.actionLabel} requires a target (to).`);
|
|
249
|
-
}
|
|
250
|
-
return to;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function resolveRequiredActionMessageTarget(params: {
|
|
254
|
-
actionLabel: string;
|
|
255
|
-
toolParams: Record<string, unknown>;
|
|
256
|
-
currentChannelId?: string | null;
|
|
257
|
-
currentGraphChannelId?: string | null;
|
|
258
|
-
graphOnly?: boolean;
|
|
259
|
-
}): { to: string; messageId: string } | ReturnType<typeof actionError> {
|
|
260
|
-
const to = params.graphOnly
|
|
261
|
-
? resolveGraphActionTarget(
|
|
262
|
-
params.toolParams,
|
|
263
|
-
params.currentChannelId,
|
|
264
|
-
params.currentGraphChannelId,
|
|
265
|
-
)
|
|
266
|
-
: resolveActionTarget(params.toolParams, params.currentChannelId);
|
|
267
|
-
const messageId = resolveActionMessageId(params.toolParams);
|
|
268
|
-
if (!to || !messageId) {
|
|
269
|
-
return actionError(`${params.actionLabel} requires a target (to) and messageId.`);
|
|
270
|
-
}
|
|
271
|
-
return { to, messageId };
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function resolveRequiredActionPinnedMessageTarget(params: {
|
|
275
|
-
actionLabel: string;
|
|
276
|
-
toolParams: Record<string, unknown>;
|
|
277
|
-
currentChannelId?: string | null;
|
|
278
|
-
currentGraphChannelId?: string | null;
|
|
279
|
-
graphOnly?: boolean;
|
|
280
|
-
}): { to: string; pinnedMessageId: string } | ReturnType<typeof actionError> {
|
|
281
|
-
const to = params.graphOnly
|
|
282
|
-
? resolveGraphActionTarget(
|
|
283
|
-
params.toolParams,
|
|
284
|
-
params.currentChannelId,
|
|
285
|
-
params.currentGraphChannelId,
|
|
286
|
-
)
|
|
287
|
-
: resolveActionTarget(params.toolParams, params.currentChannelId);
|
|
288
|
-
const pinnedMessageId = resolveActionPinnedMessageId(params.toolParams);
|
|
289
|
-
if (!to || !pinnedMessageId) {
|
|
290
|
-
return actionError(`${params.actionLabel} requires a target (to) and pinnedMessageId.`);
|
|
291
|
-
}
|
|
292
|
-
return { to, pinnedMessageId };
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
async function runWithRequiredActionTarget<T>(params: {
|
|
296
|
-
actionLabel: string;
|
|
297
|
-
toolParams: Record<string, unknown>;
|
|
298
|
-
currentChannelId?: string | null;
|
|
299
|
-
currentGraphChannelId?: string | null;
|
|
300
|
-
graphOnly?: boolean;
|
|
301
|
-
run: (to: string) => Promise<T>;
|
|
302
|
-
}): Promise<T | ReturnType<typeof actionError>> {
|
|
303
|
-
const to = resolveRequiredActionTarget({
|
|
304
|
-
actionLabel: params.actionLabel,
|
|
305
|
-
toolParams: params.toolParams,
|
|
306
|
-
currentChannelId: params.currentChannelId,
|
|
307
|
-
currentGraphChannelId: params.currentGraphChannelId,
|
|
308
|
-
graphOnly: params.graphOnly,
|
|
309
|
-
});
|
|
310
|
-
if (typeof to !== "string") {
|
|
311
|
-
return to;
|
|
312
|
-
}
|
|
313
|
-
return await params.run(to);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
async function runWithRequiredActionMessageTarget<T>(params: {
|
|
317
|
-
actionLabel: string;
|
|
318
|
-
toolParams: Record<string, unknown>;
|
|
319
|
-
currentChannelId?: string | null;
|
|
320
|
-
currentGraphChannelId?: string | null;
|
|
321
|
-
graphOnly?: boolean;
|
|
322
|
-
run: (target: { to: string; messageId: string }) => Promise<T>;
|
|
323
|
-
}): Promise<T | ReturnType<typeof actionError>> {
|
|
324
|
-
const target = resolveRequiredActionMessageTarget({
|
|
325
|
-
actionLabel: params.actionLabel,
|
|
326
|
-
toolParams: params.toolParams,
|
|
327
|
-
currentChannelId: params.currentChannelId,
|
|
328
|
-
currentGraphChannelId: params.currentGraphChannelId,
|
|
329
|
-
graphOnly: params.graphOnly,
|
|
330
|
-
});
|
|
331
|
-
if ("isError" in target) {
|
|
332
|
-
return target;
|
|
333
|
-
}
|
|
334
|
-
return await params.run(target);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
async function runWithRequiredActionPinnedMessageTarget<T>(params: {
|
|
338
|
-
actionLabel: string;
|
|
339
|
-
toolParams: Record<string, unknown>;
|
|
340
|
-
currentChannelId?: string | null;
|
|
341
|
-
currentGraphChannelId?: string | null;
|
|
342
|
-
graphOnly?: boolean;
|
|
343
|
-
run: (target: { to: string; pinnedMessageId: string }) => Promise<T>;
|
|
344
|
-
}): Promise<T | ReturnType<typeof actionError>> {
|
|
345
|
-
const target = resolveRequiredActionPinnedMessageTarget({
|
|
346
|
-
actionLabel: params.actionLabel,
|
|
347
|
-
toolParams: params.toolParams,
|
|
348
|
-
currentChannelId: params.currentChannelId,
|
|
349
|
-
currentGraphChannelId: params.currentGraphChannelId,
|
|
350
|
-
graphOnly: params.graphOnly,
|
|
351
|
-
});
|
|
352
|
-
if ("isError" in target) {
|
|
353
|
-
return target;
|
|
354
|
-
}
|
|
355
|
-
return await params.run(target);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function describeMSTeamsMessageTool({
|
|
359
|
-
cfg,
|
|
360
|
-
}: Parameters<
|
|
361
|
-
NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>
|
|
362
|
-
>[0]): ChannelMessageToolDiscovery {
|
|
363
|
-
const enabled =
|
|
364
|
-
cfg.channels?.msteams?.enabled !== false &&
|
|
365
|
-
Boolean(resolveMSTeamsCredentials(cfg.channels?.msteams));
|
|
366
|
-
return {
|
|
367
|
-
actions: enabled
|
|
368
|
-
? ([
|
|
369
|
-
"upload-file",
|
|
370
|
-
"poll",
|
|
371
|
-
"edit",
|
|
372
|
-
"delete",
|
|
373
|
-
"pin",
|
|
374
|
-
"unpin",
|
|
375
|
-
"list-pins",
|
|
376
|
-
"read",
|
|
377
|
-
"react",
|
|
378
|
-
"reactions",
|
|
379
|
-
"search",
|
|
380
|
-
"member-info",
|
|
381
|
-
"channel-list",
|
|
382
|
-
"channel-info",
|
|
383
|
-
"addParticipant",
|
|
384
|
-
"removeParticipant",
|
|
385
|
-
"renameGroup",
|
|
386
|
-
] satisfies ChannelMessageActionName[])
|
|
387
|
-
: [],
|
|
388
|
-
capabilities: enabled ? ["presentation"] : [],
|
|
389
|
-
schema: enabled
|
|
390
|
-
? {
|
|
391
|
-
actions: ["unpin"],
|
|
392
|
-
properties: {
|
|
393
|
-
pinnedMessageId: Type.Optional(
|
|
394
|
-
Type.String({
|
|
395
|
-
description:
|
|
396
|
-
"Pinned message resource ID for unpin (from pin or list-pins, not the chat message ID).",
|
|
397
|
-
}),
|
|
398
|
-
),
|
|
399
|
-
},
|
|
400
|
-
}
|
|
401
|
-
: null,
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsResult> =
|
|
406
|
-
createChatChannelPlugin({
|
|
407
|
-
base: {
|
|
408
|
-
id: "msteams",
|
|
409
|
-
meta: {
|
|
410
|
-
...meta,
|
|
411
|
-
aliases: [...meta.aliases],
|
|
412
|
-
},
|
|
413
|
-
setupWizard: msteamsSetupWizard,
|
|
414
|
-
capabilities: {
|
|
415
|
-
chatTypes: ["direct", "channel", "thread"],
|
|
416
|
-
polls: true,
|
|
417
|
-
threads: true,
|
|
418
|
-
media: true,
|
|
419
|
-
},
|
|
420
|
-
streaming: {
|
|
421
|
-
blockStreamingCoalesceDefaults: { minChars: 1500, idleMs: 1000 },
|
|
422
|
-
},
|
|
423
|
-
agentPrompt: {
|
|
424
|
-
messageToolHints: () => [
|
|
425
|
-
"- Adaptive Cards supported. Use `action=send` with `card={type,version,body}` to send rich cards.",
|
|
426
|
-
"- MSTeams targeting: omit `target` to reply to the current conversation (auto-inferred). Explicit targets: `user:ID` or `user:Display Name` (requires Graph API) for DMs, `conversation:19:...@thread.tacv2` for groups/channels. Prefer IDs over display names for speed.",
|
|
427
|
-
],
|
|
428
|
-
},
|
|
429
|
-
groups: {
|
|
430
|
-
resolveToolPolicy: resolveMSTeamsGroupToolPolicy,
|
|
431
|
-
},
|
|
432
|
-
reload: { configPrefixes: ["channels.msteams"] },
|
|
433
|
-
configSchema: MSTeamsChannelConfigSchema,
|
|
434
|
-
config: {
|
|
435
|
-
...msteamsConfigAdapter,
|
|
436
|
-
isConfigured: (_account, cfg) => Boolean(resolveMSTeamsCredentials(cfg.channels?.msteams)),
|
|
437
|
-
describeAccount: (account) =>
|
|
438
|
-
describeAccountSnapshot({
|
|
439
|
-
account,
|
|
440
|
-
configured: account.configured,
|
|
441
|
-
}),
|
|
442
|
-
},
|
|
443
|
-
approvalCapability: msTeamsApprovalAuth,
|
|
444
|
-
doctor: {
|
|
445
|
-
dmAllowFromMode: "topOnly",
|
|
446
|
-
groupModel: "hybrid",
|
|
447
|
-
groupAllowFromFallbackToAllowFrom: false,
|
|
448
|
-
warnOnEmptyGroupSenderAllowlist: true,
|
|
449
|
-
collectMutableAllowlistWarnings: collectMSTeamsMutableAllowlistWarnings,
|
|
450
|
-
},
|
|
451
|
-
setup: msteamsSetupAdapter,
|
|
452
|
-
messaging: {
|
|
453
|
-
targetPrefixes: ["msteams", "teams"],
|
|
454
|
-
normalizeTarget: normalizeMSTeamsMessagingTarget,
|
|
455
|
-
resolveOutboundSessionRoute: (params) => resolveMSTeamsOutboundSessionRoute(params),
|
|
456
|
-
targetResolver: {
|
|
457
|
-
looksLikeId: (raw) => looksLikeMSTeamsTargetId(raw),
|
|
458
|
-
hint: "<conversationId|user:ID|conversation:ID>",
|
|
459
|
-
},
|
|
460
|
-
},
|
|
461
|
-
directory: createChannelDirectoryAdapter({
|
|
462
|
-
self: async ({ cfg }) => {
|
|
463
|
-
const creds = resolveMSTeamsCredentials(cfg.channels?.msteams);
|
|
464
|
-
if (!creds) {
|
|
465
|
-
return null;
|
|
466
|
-
}
|
|
467
|
-
return { kind: "user" as const, id: creds.appId, name: creds.appId };
|
|
468
|
-
},
|
|
469
|
-
listPeers: async ({ cfg, query, limit }) =>
|
|
470
|
-
listDirectoryEntriesFromSources({
|
|
471
|
-
kind: "user",
|
|
472
|
-
sources: [
|
|
473
|
-
cfg.channels?.msteams?.allowFrom ?? [],
|
|
474
|
-
Object.keys(cfg.channels?.msteams?.dms ?? {}),
|
|
475
|
-
],
|
|
476
|
-
query,
|
|
477
|
-
limit,
|
|
478
|
-
normalizeId: (raw) => {
|
|
479
|
-
const normalized = normalizeMSTeamsMessagingTarget(raw) ?? raw;
|
|
480
|
-
const lowered = normalized.toLowerCase();
|
|
481
|
-
if (lowered.startsWith("user:") || lowered.startsWith("conversation:")) {
|
|
482
|
-
return normalized;
|
|
483
|
-
}
|
|
484
|
-
return `user:${normalized}`;
|
|
485
|
-
},
|
|
486
|
-
}),
|
|
487
|
-
listGroups: async ({ cfg, query, limit }) =>
|
|
488
|
-
listDirectoryEntriesFromSources({
|
|
489
|
-
kind: "group",
|
|
490
|
-
sources: [
|
|
491
|
-
Object.values(cfg.channels?.msteams?.teams ?? {}).flatMap((team) =>
|
|
492
|
-
Object.keys(team.channels ?? {}),
|
|
493
|
-
),
|
|
494
|
-
],
|
|
495
|
-
query,
|
|
496
|
-
limit,
|
|
497
|
-
normalizeId: (raw) => `conversation:${raw.replace(/^conversation:/i, "").trim()}`,
|
|
498
|
-
}),
|
|
499
|
-
...createRuntimeDirectoryLiveAdapter({
|
|
500
|
-
getRuntime: loadMSTeamsChannelRuntime,
|
|
501
|
-
listPeersLive: (runtime) => runtime.listMSTeamsDirectoryPeersLive,
|
|
502
|
-
listGroupsLive: (runtime) => runtime.listMSTeamsDirectoryGroupsLive,
|
|
503
|
-
}),
|
|
504
|
-
}),
|
|
505
|
-
resolver: {
|
|
506
|
-
resolveTargets: async ({ cfg, inputs, kind, runtime }) => {
|
|
507
|
-
const results = inputs.map((input) => ({
|
|
508
|
-
input,
|
|
509
|
-
resolved: false,
|
|
510
|
-
id: undefined as string | undefined,
|
|
511
|
-
name: undefined as string | undefined,
|
|
512
|
-
note: undefined as string | undefined,
|
|
513
|
-
}));
|
|
514
|
-
type ResolveTargetResultEntry = (typeof results)[number];
|
|
515
|
-
type PendingTargetEntry = { input: string; query: string; index: number };
|
|
516
|
-
|
|
517
|
-
const stripPrefix = (value: string) => normalizeMSTeamsUserInput(value);
|
|
518
|
-
const markPendingLookupFailed = (pending: PendingTargetEntry[]) => {
|
|
519
|
-
pending.forEach(({ index }) => {
|
|
520
|
-
const entry = results[index];
|
|
521
|
-
if (entry) {
|
|
522
|
-
entry.note = "lookup failed";
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
};
|
|
526
|
-
const resolvePending = async <T>(
|
|
527
|
-
pending: PendingTargetEntry[],
|
|
528
|
-
resolveEntries: (entries: string[]) => Promise<T[]>,
|
|
529
|
-
applyResolvedEntry: (target: ResolveTargetResultEntry, entry: T) => void,
|
|
530
|
-
) => {
|
|
531
|
-
if (pending.length === 0) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
try {
|
|
535
|
-
const resolved = await resolveEntries(pending.map((entry) => entry.query));
|
|
536
|
-
resolved.forEach((entry, idx) => {
|
|
537
|
-
const target = results[pending[idx]?.index ?? -1];
|
|
538
|
-
if (!target) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
applyResolvedEntry(target, entry);
|
|
542
|
-
});
|
|
543
|
-
} catch (err) {
|
|
544
|
-
runtime.error?.(`msteams resolve failed: ${String(err)}`);
|
|
545
|
-
markPendingLookupFailed(pending);
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
if (kind === "user") {
|
|
550
|
-
const pending: PendingTargetEntry[] = [];
|
|
551
|
-
results.forEach((entry, index) => {
|
|
552
|
-
const trimmed = entry.input.trim();
|
|
553
|
-
if (!trimmed) {
|
|
554
|
-
entry.note = "empty input";
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
const cleaned = stripPrefix(trimmed);
|
|
558
|
-
if (/^[0-9a-fA-F-]{16,}$/.test(cleaned) || cleaned.includes("@")) {
|
|
559
|
-
entry.resolved = true;
|
|
560
|
-
entry.id = cleaned;
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
pending.push({ input: entry.input, query: cleaned, index });
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
await resolvePending(
|
|
567
|
-
pending,
|
|
568
|
-
(entries) => resolveMSTeamsUserAllowlist({ cfg, entries }),
|
|
569
|
-
(target, entry) => {
|
|
570
|
-
target.resolved = entry.resolved;
|
|
571
|
-
target.id = entry.id;
|
|
572
|
-
target.name = entry.name;
|
|
573
|
-
target.note = entry.note;
|
|
574
|
-
},
|
|
575
|
-
);
|
|
576
|
-
|
|
577
|
-
return results;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
const pending: PendingTargetEntry[] = [];
|
|
581
|
-
results.forEach((entry, index) => {
|
|
582
|
-
const trimmed = entry.input.trim();
|
|
583
|
-
if (!trimmed) {
|
|
584
|
-
entry.note = "empty input";
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
const conversationId = parseMSTeamsConversationId(trimmed);
|
|
588
|
-
if (conversationId !== null) {
|
|
589
|
-
entry.resolved = Boolean(conversationId);
|
|
590
|
-
entry.id = conversationId || undefined;
|
|
591
|
-
entry.note = conversationId ? "conversation id" : "empty conversation id";
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
const parsed = parseMSTeamsTeamChannelInput(trimmed);
|
|
595
|
-
if (!parsed.team) {
|
|
596
|
-
entry.note = "missing team";
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
const query = parsed.channel ? `${parsed.team}/${parsed.channel}` : parsed.team;
|
|
600
|
-
pending.push({ input: entry.input, query, index });
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
await resolvePending(
|
|
604
|
-
pending,
|
|
605
|
-
(entries) => resolveMSTeamsChannelAllowlist({ cfg, entries }),
|
|
606
|
-
(target, entry) => {
|
|
607
|
-
if (!entry.resolved || !entry.teamId) {
|
|
608
|
-
target.resolved = false;
|
|
609
|
-
target.note = entry.note;
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
target.resolved = true;
|
|
613
|
-
if (entry.channelId) {
|
|
614
|
-
target.id = `${entry.teamId}/${entry.channelId}`;
|
|
615
|
-
target.name =
|
|
616
|
-
entry.channelName && entry.teamName
|
|
617
|
-
? `${entry.teamName}/${entry.channelName}`
|
|
618
|
-
: (entry.channelName ?? entry.teamName);
|
|
619
|
-
} else {
|
|
620
|
-
target.id = entry.teamId;
|
|
621
|
-
target.name = entry.teamName;
|
|
622
|
-
target.note = "team id";
|
|
623
|
-
}
|
|
624
|
-
if (entry.note) {
|
|
625
|
-
target.note = entry.note;
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
);
|
|
629
|
-
|
|
630
|
-
return results;
|
|
631
|
-
},
|
|
632
|
-
},
|
|
633
|
-
actions: {
|
|
634
|
-
describeMessageTool: describeMSTeamsMessageTool,
|
|
635
|
-
handleAction: async (ctx) => {
|
|
636
|
-
const presentation =
|
|
637
|
-
ctx.action === "send"
|
|
638
|
-
? normalizeMessagePresentation(ctx.params.presentation)
|
|
639
|
-
: undefined;
|
|
640
|
-
if (ctx.action === "send" && presentation) {
|
|
641
|
-
const card = buildMSTeamsPresentationCard({
|
|
642
|
-
presentation,
|
|
643
|
-
text: resolveActionContent(ctx.params),
|
|
644
|
-
});
|
|
645
|
-
return await runWithRequiredActionTarget({
|
|
646
|
-
actionLabel: "Card send",
|
|
647
|
-
toolParams: ctx.params,
|
|
648
|
-
run: async (to) => {
|
|
649
|
-
const { sendAdaptiveCardMSTeams } = await loadMSTeamsChannelRuntime();
|
|
650
|
-
const result = await sendAdaptiveCardMSTeams({
|
|
651
|
-
cfg: ctx.cfg,
|
|
652
|
-
to,
|
|
653
|
-
card,
|
|
654
|
-
});
|
|
655
|
-
return jsonActionResultWithDetails(
|
|
656
|
-
{
|
|
657
|
-
ok: true,
|
|
658
|
-
channel: "msteams",
|
|
659
|
-
messageId: result.messageId,
|
|
660
|
-
conversationId: result.conversationId,
|
|
661
|
-
},
|
|
662
|
-
{ ok: true, channel: "msteams", messageId: result.messageId },
|
|
663
|
-
);
|
|
664
|
-
},
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
if (ctx.action === "upload-file") {
|
|
668
|
-
const mediaUrl = resolveActionUploadFilePath(ctx.params);
|
|
669
|
-
if (!mediaUrl) {
|
|
670
|
-
return actionError("Upload-file requires media, filePath, or path.");
|
|
671
|
-
}
|
|
672
|
-
return await runWithRequiredActionTarget({
|
|
673
|
-
actionLabel: "Upload-file",
|
|
674
|
-
toolParams: ctx.params,
|
|
675
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
676
|
-
run: async (to) => {
|
|
677
|
-
const { sendMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
678
|
-
const result = await sendMessageMSTeams({
|
|
679
|
-
cfg: ctx.cfg,
|
|
680
|
-
to,
|
|
681
|
-
text: resolveActionContent(ctx.params),
|
|
682
|
-
mediaUrl,
|
|
683
|
-
filename:
|
|
684
|
-
readOptionalTrimmedString(ctx.params, "filename") ??
|
|
685
|
-
readOptionalTrimmedString(ctx.params, "title"),
|
|
686
|
-
mediaLocalRoots: ctx.mediaLocalRoots,
|
|
687
|
-
mediaReadFile: ctx.mediaReadFile,
|
|
688
|
-
});
|
|
689
|
-
return jsonActionResultWithDetails(
|
|
690
|
-
{
|
|
691
|
-
ok: true,
|
|
692
|
-
channel: "msteams",
|
|
693
|
-
action: "upload-file",
|
|
694
|
-
messageId: result.messageId,
|
|
695
|
-
conversationId: result.conversationId,
|
|
696
|
-
...(result.pendingUploadId ? { pendingUploadId: result.pendingUploadId } : {}),
|
|
697
|
-
},
|
|
698
|
-
{
|
|
699
|
-
ok: true,
|
|
700
|
-
channel: "msteams",
|
|
701
|
-
messageId: result.messageId,
|
|
702
|
-
...(result.pendingUploadId ? { pendingUploadId: result.pendingUploadId } : {}),
|
|
703
|
-
},
|
|
704
|
-
);
|
|
705
|
-
},
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
if (ctx.action === "edit") {
|
|
709
|
-
const content = resolveActionContent(ctx.params);
|
|
710
|
-
if (!content) {
|
|
711
|
-
return actionError("Edit requires content.");
|
|
712
|
-
}
|
|
713
|
-
return await runWithRequiredActionMessageTarget({
|
|
714
|
-
actionLabel: "Edit",
|
|
715
|
-
toolParams: ctx.params,
|
|
716
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
717
|
-
run: async (target) => {
|
|
718
|
-
const { editMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
719
|
-
const result = await editMessageMSTeams({
|
|
720
|
-
cfg: ctx.cfg,
|
|
721
|
-
to: target.to,
|
|
722
|
-
activityId: target.messageId,
|
|
723
|
-
text: content,
|
|
724
|
-
});
|
|
725
|
-
return jsonMSTeamsConversationResult(result.conversationId);
|
|
726
|
-
},
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
if (ctx.action === "delete") {
|
|
731
|
-
return await runWithRequiredActionMessageTarget({
|
|
732
|
-
actionLabel: "Delete",
|
|
733
|
-
toolParams: ctx.params,
|
|
734
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
735
|
-
run: async (target) => {
|
|
736
|
-
const { deleteMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
737
|
-
const result = await deleteMessageMSTeams({
|
|
738
|
-
cfg: ctx.cfg,
|
|
739
|
-
to: target.to,
|
|
740
|
-
activityId: target.messageId,
|
|
741
|
-
});
|
|
742
|
-
return jsonMSTeamsConversationResult(result.conversationId);
|
|
743
|
-
},
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
if (ctx.action === "read") {
|
|
748
|
-
return await runWithRequiredActionMessageTarget({
|
|
749
|
-
actionLabel: "Read",
|
|
750
|
-
toolParams: ctx.params,
|
|
751
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
752
|
-
currentGraphChannelId: ctx.toolContext?.currentGraphChannelId,
|
|
753
|
-
graphOnly: true,
|
|
754
|
-
run: async (target) => {
|
|
755
|
-
const { getMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
756
|
-
const message = await getMessageMSTeams({
|
|
757
|
-
cfg: ctx.cfg,
|
|
758
|
-
to: target.to,
|
|
759
|
-
messageId: target.messageId,
|
|
760
|
-
});
|
|
761
|
-
return jsonMSTeamsOkActionResult("read", { message });
|
|
762
|
-
},
|
|
763
|
-
});
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
if (ctx.action === "pin") {
|
|
767
|
-
return await runWithRequiredActionMessageTarget({
|
|
768
|
-
actionLabel: "Pin",
|
|
769
|
-
toolParams: ctx.params,
|
|
770
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
771
|
-
currentGraphChannelId: ctx.toolContext?.currentGraphChannelId,
|
|
772
|
-
graphOnly: true,
|
|
773
|
-
run: async (target) => {
|
|
774
|
-
const { pinMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
775
|
-
const result = await pinMessageMSTeams({
|
|
776
|
-
cfg: ctx.cfg,
|
|
777
|
-
to: target.to,
|
|
778
|
-
messageId: target.messageId,
|
|
779
|
-
});
|
|
780
|
-
return jsonMSTeamsActionResult("pin", result);
|
|
781
|
-
},
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
if (ctx.action === "unpin") {
|
|
786
|
-
return await runWithRequiredActionPinnedMessageTarget({
|
|
787
|
-
actionLabel: "Unpin",
|
|
788
|
-
toolParams: ctx.params,
|
|
789
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
790
|
-
currentGraphChannelId: ctx.toolContext?.currentGraphChannelId,
|
|
791
|
-
graphOnly: true,
|
|
792
|
-
run: async (target) => {
|
|
793
|
-
const { unpinMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
794
|
-
const result = await unpinMessageMSTeams({
|
|
795
|
-
cfg: ctx.cfg,
|
|
796
|
-
to: target.to,
|
|
797
|
-
pinnedMessageId: target.pinnedMessageId,
|
|
798
|
-
});
|
|
799
|
-
return jsonMSTeamsActionResult("unpin", result);
|
|
800
|
-
},
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
if (ctx.action === "list-pins") {
|
|
805
|
-
return await runWithRequiredActionTarget({
|
|
806
|
-
actionLabel: "List-pins",
|
|
807
|
-
toolParams: ctx.params,
|
|
808
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
809
|
-
currentGraphChannelId: ctx.toolContext?.currentGraphChannelId,
|
|
810
|
-
graphOnly: true,
|
|
811
|
-
run: async (to) => {
|
|
812
|
-
const { listPinsMSTeams } = await loadMSTeamsChannelRuntime();
|
|
813
|
-
const result = await listPinsMSTeams({ cfg: ctx.cfg, to });
|
|
814
|
-
return jsonMSTeamsOkActionResult("list-pins", result);
|
|
815
|
-
},
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
if (ctx.action === "react") {
|
|
820
|
-
return await runWithRequiredActionMessageTarget({
|
|
821
|
-
actionLabel: "React",
|
|
822
|
-
toolParams: ctx.params,
|
|
823
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
824
|
-
currentGraphChannelId: ctx.toolContext?.currentGraphChannelId,
|
|
825
|
-
graphOnly: true,
|
|
826
|
-
run: async (target) => {
|
|
827
|
-
const emoji = typeof ctx.params.emoji === "string" ? ctx.params.emoji.trim() : "";
|
|
828
|
-
const remove = typeof ctx.params.remove === "boolean" ? ctx.params.remove : false;
|
|
829
|
-
if (!emoji) {
|
|
830
|
-
return {
|
|
831
|
-
isError: true,
|
|
832
|
-
content: [
|
|
833
|
-
{
|
|
834
|
-
type: "text" as const,
|
|
835
|
-
text: `React requires an emoji (reaction type). Valid types: ${MSTEAMS_REACTION_TYPES.join(", ")}.`,
|
|
836
|
-
},
|
|
837
|
-
],
|
|
838
|
-
details: {
|
|
839
|
-
error: "React requires an emoji (reaction type).",
|
|
840
|
-
validTypes: [...MSTEAMS_REACTION_TYPES],
|
|
841
|
-
},
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
if (remove) {
|
|
845
|
-
const { unreactMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
846
|
-
const result = await unreactMessageMSTeams({
|
|
847
|
-
cfg: ctx.cfg,
|
|
848
|
-
to: target.to,
|
|
849
|
-
messageId: target.messageId,
|
|
850
|
-
reactionType: emoji,
|
|
851
|
-
});
|
|
852
|
-
return jsonMSTeamsActionResult("react", {
|
|
853
|
-
removed: true,
|
|
854
|
-
reactionType: emoji,
|
|
855
|
-
...result,
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
const { reactMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
859
|
-
const result = await reactMessageMSTeams({
|
|
860
|
-
cfg: ctx.cfg,
|
|
861
|
-
to: target.to,
|
|
862
|
-
messageId: target.messageId,
|
|
863
|
-
reactionType: emoji,
|
|
864
|
-
});
|
|
865
|
-
return jsonMSTeamsActionResult("react", {
|
|
866
|
-
reactionType: emoji,
|
|
867
|
-
...result,
|
|
868
|
-
});
|
|
869
|
-
},
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
if (ctx.action === "reactions") {
|
|
874
|
-
return await runWithRequiredActionMessageTarget({
|
|
875
|
-
actionLabel: "Reactions",
|
|
876
|
-
toolParams: ctx.params,
|
|
877
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
878
|
-
currentGraphChannelId: ctx.toolContext?.currentGraphChannelId,
|
|
879
|
-
graphOnly: true,
|
|
880
|
-
run: async (target) => {
|
|
881
|
-
const { listReactionsMSTeams } = await loadMSTeamsChannelRuntime();
|
|
882
|
-
const result = await listReactionsMSTeams({
|
|
883
|
-
cfg: ctx.cfg,
|
|
884
|
-
to: target.to,
|
|
885
|
-
messageId: target.messageId,
|
|
886
|
-
});
|
|
887
|
-
return jsonMSTeamsOkActionResult("reactions", result);
|
|
888
|
-
},
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
if (ctx.action === "search") {
|
|
893
|
-
return await runWithRequiredActionTarget({
|
|
894
|
-
actionLabel: "Search",
|
|
895
|
-
toolParams: ctx.params,
|
|
896
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
897
|
-
currentGraphChannelId: ctx.toolContext?.currentGraphChannelId,
|
|
898
|
-
graphOnly: true,
|
|
899
|
-
run: async (to) => {
|
|
900
|
-
const query = resolveActionQuery(ctx.params);
|
|
901
|
-
if (!query) {
|
|
902
|
-
return actionError("Search requires a target (to) and query.");
|
|
903
|
-
}
|
|
904
|
-
const limit = typeof ctx.params.limit === "number" ? ctx.params.limit : undefined;
|
|
905
|
-
const from =
|
|
906
|
-
typeof ctx.params.from === "string" ? ctx.params.from.trim() : undefined;
|
|
907
|
-
const { searchMessagesMSTeams } = await loadMSTeamsChannelRuntime();
|
|
908
|
-
const result = await searchMessagesMSTeams({
|
|
909
|
-
cfg: ctx.cfg,
|
|
910
|
-
to,
|
|
911
|
-
query,
|
|
912
|
-
from: from || undefined,
|
|
913
|
-
limit,
|
|
914
|
-
});
|
|
915
|
-
return jsonMSTeamsOkActionResult("search", result);
|
|
916
|
-
},
|
|
917
|
-
});
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
if (ctx.action === "member-info") {
|
|
921
|
-
const userId = normalizeOptionalString(ctx.params.userId) ?? "";
|
|
922
|
-
if (!userId) {
|
|
923
|
-
return actionError("member-info requires a userId.");
|
|
924
|
-
}
|
|
925
|
-
const { getMemberInfoMSTeams } = await loadMSTeamsChannelRuntime();
|
|
926
|
-
const result = await getMemberInfoMSTeams({ cfg: ctx.cfg, userId });
|
|
927
|
-
return jsonMSTeamsOkActionResult("member-info", result);
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
if (ctx.action === "channel-list") {
|
|
931
|
-
const teamId = normalizeOptionalString(ctx.params.teamId) ?? "";
|
|
932
|
-
if (!teamId) {
|
|
933
|
-
return actionError("channel-list requires a teamId.");
|
|
934
|
-
}
|
|
935
|
-
const { listChannelsMSTeams } = await loadMSTeamsChannelRuntime();
|
|
936
|
-
const result = await listChannelsMSTeams({ cfg: ctx.cfg, teamId });
|
|
937
|
-
return jsonMSTeamsOkActionResult("channel-list", result);
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
if (ctx.action === "channel-info") {
|
|
941
|
-
const teamId = normalizeOptionalString(ctx.params.teamId) ?? "";
|
|
942
|
-
const channelId = normalizeOptionalString(ctx.params.channelId) ?? "";
|
|
943
|
-
if (!teamId || !channelId) {
|
|
944
|
-
return actionError("channel-info requires teamId and channelId.");
|
|
945
|
-
}
|
|
946
|
-
const { getChannelInfoMSTeams } = await loadMSTeamsChannelRuntime();
|
|
947
|
-
const result = await getChannelInfoMSTeams({
|
|
948
|
-
cfg: ctx.cfg,
|
|
949
|
-
teamId,
|
|
950
|
-
channelId,
|
|
951
|
-
});
|
|
952
|
-
return jsonMSTeamsOkActionResult("channel-info", {
|
|
953
|
-
channelInfo: result.channel,
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
if (ctx.action === "addParticipant") {
|
|
958
|
-
const userId = typeof ctx.params.userId === "string" ? ctx.params.userId.trim() : "";
|
|
959
|
-
if (!userId) {
|
|
960
|
-
return actionError("addParticipant requires a userId.");
|
|
961
|
-
}
|
|
962
|
-
return await runWithRequiredActionTarget({
|
|
963
|
-
actionLabel: "addParticipant",
|
|
964
|
-
toolParams: ctx.params,
|
|
965
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
966
|
-
run: async (to) => {
|
|
967
|
-
const role = readOptionalTrimmedString(ctx.params, "role");
|
|
968
|
-
const { addParticipantMSTeams } = await loadMSTeamsChannelRuntime();
|
|
969
|
-
const result = await addParticipantMSTeams({
|
|
970
|
-
cfg: ctx.cfg,
|
|
971
|
-
to,
|
|
972
|
-
userId,
|
|
973
|
-
role,
|
|
974
|
-
});
|
|
975
|
-
return jsonMSTeamsOkActionResult("addParticipant", result);
|
|
976
|
-
},
|
|
977
|
-
});
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
if (ctx.action === "removeParticipant") {
|
|
981
|
-
const userId = typeof ctx.params.userId === "string" ? ctx.params.userId.trim() : "";
|
|
982
|
-
if (!userId) {
|
|
983
|
-
return actionError("removeParticipant requires a userId.");
|
|
984
|
-
}
|
|
985
|
-
return await runWithRequiredActionTarget({
|
|
986
|
-
actionLabel: "removeParticipant",
|
|
987
|
-
toolParams: ctx.params,
|
|
988
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
989
|
-
run: async (to) => {
|
|
990
|
-
const { removeParticipantMSTeams } = await loadMSTeamsChannelRuntime();
|
|
991
|
-
const result = await removeParticipantMSTeams({
|
|
992
|
-
cfg: ctx.cfg,
|
|
993
|
-
to,
|
|
994
|
-
userId,
|
|
995
|
-
});
|
|
996
|
-
return jsonMSTeamsOkActionResult("removeParticipant", result);
|
|
997
|
-
},
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
if (ctx.action === "renameGroup") {
|
|
1002
|
-
const name = typeof ctx.params.name === "string" ? ctx.params.name.trim() : "";
|
|
1003
|
-
if (!name) {
|
|
1004
|
-
return actionError("renameGroup requires a name.");
|
|
1005
|
-
}
|
|
1006
|
-
return await runWithRequiredActionTarget({
|
|
1007
|
-
actionLabel: "renameGroup",
|
|
1008
|
-
toolParams: ctx.params,
|
|
1009
|
-
currentChannelId: ctx.toolContext?.currentChannelId,
|
|
1010
|
-
run: async (to) => {
|
|
1011
|
-
const { renameGroupMSTeams } = await loadMSTeamsChannelRuntime();
|
|
1012
|
-
const result = await renameGroupMSTeams({
|
|
1013
|
-
cfg: ctx.cfg,
|
|
1014
|
-
to,
|
|
1015
|
-
name,
|
|
1016
|
-
});
|
|
1017
|
-
return jsonMSTeamsOkActionResult("renameGroup", result);
|
|
1018
|
-
},
|
|
1019
|
-
});
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
// Return null to fall through to default handler
|
|
1023
|
-
return null as never;
|
|
1024
|
-
},
|
|
1025
|
-
},
|
|
1026
|
-
status: createComputedAccountStatusAdapter<ResolvedMSTeamsAccount, ProbeMSTeamsResult>({
|
|
1027
|
-
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID, { port: null }),
|
|
1028
|
-
buildChannelSummary: ({ snapshot }) =>
|
|
1029
|
-
buildProbeChannelStatusSummary(snapshot, {
|
|
1030
|
-
port: snapshot.port ?? null,
|
|
1031
|
-
}),
|
|
1032
|
-
probeAccount: async ({ cfg }) =>
|
|
1033
|
-
await (await loadMSTeamsChannelRuntime()).probeMSTeams(cfg.channels?.msteams),
|
|
1034
|
-
formatCapabilitiesProbe: ({ probe }) => {
|
|
1035
|
-
const teamsProbe = probe;
|
|
1036
|
-
const lines: Array<{ text: string; tone?: "error" }> = [];
|
|
1037
|
-
const appId = typeof teamsProbe?.appId === "string" ? teamsProbe.appId.trim() : "";
|
|
1038
|
-
if (appId) {
|
|
1039
|
-
lines.push({ text: `App: ${appId}` });
|
|
1040
|
-
}
|
|
1041
|
-
const graph = teamsProbe?.graph;
|
|
1042
|
-
if (graph) {
|
|
1043
|
-
const roles = Array.isArray(graph.roles)
|
|
1044
|
-
? graph.roles.map((role) => role.trim()).filter(Boolean)
|
|
1045
|
-
: [];
|
|
1046
|
-
const scopes = Array.isArray(graph.scopes)
|
|
1047
|
-
? graph.scopes.map((scope) => scope.trim()).filter(Boolean)
|
|
1048
|
-
: [];
|
|
1049
|
-
const formatPermission = (permission: string) => {
|
|
1050
|
-
const hint = TEAMS_GRAPH_PERMISSION_HINTS[permission];
|
|
1051
|
-
return hint ? `${permission} (${hint})` : permission;
|
|
1052
|
-
};
|
|
1053
|
-
if (!graph.ok) {
|
|
1054
|
-
lines.push({ text: `Graph: ${graph.error ?? "failed"}`, tone: "error" });
|
|
1055
|
-
} else if (roles.length > 0 || scopes.length > 0) {
|
|
1056
|
-
if (roles.length > 0) {
|
|
1057
|
-
lines.push({ text: `Graph roles: ${roles.map(formatPermission).join(", ")}` });
|
|
1058
|
-
}
|
|
1059
|
-
if (scopes.length > 0) {
|
|
1060
|
-
lines.push({ text: `Graph scopes: ${scopes.map(formatPermission).join(", ")}` });
|
|
1061
|
-
}
|
|
1062
|
-
} else if (graph.ok) {
|
|
1063
|
-
lines.push({ text: "Graph: ok" });
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
return lines;
|
|
1067
|
-
},
|
|
1068
|
-
resolveAccountSnapshot: ({ account, runtime }) => ({
|
|
1069
|
-
accountId: account.accountId,
|
|
1070
|
-
enabled: account.enabled,
|
|
1071
|
-
configured: account.configured,
|
|
1072
|
-
extra: {
|
|
1073
|
-
port: runtime?.port ?? null,
|
|
1074
|
-
},
|
|
1075
|
-
}),
|
|
1076
|
-
}),
|
|
1077
|
-
gateway: {
|
|
1078
|
-
startAccount: async (ctx) => {
|
|
1079
|
-
const { monitorMSTeamsProvider } = await import("./index.js");
|
|
1080
|
-
const port = ctx.cfg.channels?.msteams?.webhook?.port ?? 3978;
|
|
1081
|
-
ctx.setStatus({ accountId: ctx.accountId, port });
|
|
1082
|
-
ctx.log?.info(`starting provider (port ${port})`);
|
|
1083
|
-
return monitorMSTeamsProvider({
|
|
1084
|
-
cfg: ctx.cfg,
|
|
1085
|
-
runtime: ctx.runtime,
|
|
1086
|
-
abortSignal: ctx.abortSignal,
|
|
1087
|
-
});
|
|
1088
|
-
},
|
|
1089
|
-
},
|
|
1090
|
-
},
|
|
1091
|
-
security: {
|
|
1092
|
-
collectWarnings: projectConfigWarningCollector<{ cfg: OpenClawConfig }>(
|
|
1093
|
-
collectMSTeamsSecurityWarnings,
|
|
1094
|
-
),
|
|
1095
|
-
},
|
|
1096
|
-
pairing: {
|
|
1097
|
-
text: {
|
|
1098
|
-
idLabel: "msteamsUserId",
|
|
1099
|
-
message: PAIRING_APPROVED_MESSAGE,
|
|
1100
|
-
normalizeAllowEntry: createPairingPrefixStripper(/^(msteams|user):/i),
|
|
1101
|
-
notify: async ({ cfg, id, message }) => {
|
|
1102
|
-
const { sendMessageMSTeams } = await loadMSTeamsChannelRuntime();
|
|
1103
|
-
await sendMessageMSTeams({
|
|
1104
|
-
cfg,
|
|
1105
|
-
to: id,
|
|
1106
|
-
text: message,
|
|
1107
|
-
});
|
|
1108
|
-
},
|
|
1109
|
-
},
|
|
1110
|
-
},
|
|
1111
|
-
threading: {
|
|
1112
|
-
buildToolContext: ({ context, hasRepliedRef }) => {
|
|
1113
|
-
const nativeChannelId = context.NativeChannelId?.trim();
|
|
1114
|
-
const hasChannelRoute = Boolean(nativeChannelId && nativeChannelId.includes("/"));
|
|
1115
|
-
return {
|
|
1116
|
-
currentChannelId: normalizeOptionalString(context.To),
|
|
1117
|
-
currentGraphChannelId: hasChannelRoute ? nativeChannelId : undefined,
|
|
1118
|
-
currentThreadTs: context.ReplyToId,
|
|
1119
|
-
hasRepliedRef,
|
|
1120
|
-
};
|
|
1121
|
-
},
|
|
1122
|
-
},
|
|
1123
|
-
outbound: {
|
|
1124
|
-
deliveryMode: "direct",
|
|
1125
|
-
chunker: chunkTextForOutbound,
|
|
1126
|
-
chunkerMode: "markdown",
|
|
1127
|
-
textChunkLimit: 4000,
|
|
1128
|
-
pollMaxOptions: 12,
|
|
1129
|
-
...createRuntimeOutboundDelegates({
|
|
1130
|
-
getRuntime: loadMSTeamsChannelRuntime,
|
|
1131
|
-
sendText: { resolve: (runtime) => runtime.msteamsOutbound.sendText },
|
|
1132
|
-
sendMedia: { resolve: (runtime) => runtime.msteamsOutbound.sendMedia },
|
|
1133
|
-
sendPoll: { resolve: (runtime) => runtime.msteamsOutbound.sendPoll },
|
|
1134
|
-
}),
|
|
1135
|
-
},
|
|
1136
|
-
});
|