@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/policy.ts
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AllowlistMatch,
|
|
3
|
-
ChannelGroupContext,
|
|
4
|
-
GroupPolicy,
|
|
5
|
-
GroupToolPolicyConfig,
|
|
6
|
-
MSTeamsChannelConfig,
|
|
7
|
-
MSTeamsConfig,
|
|
8
|
-
MSTeamsReplyStyle,
|
|
9
|
-
MSTeamsTeamConfig,
|
|
10
|
-
} from "../runtime-api.js";
|
|
11
|
-
import {
|
|
12
|
-
buildChannelKeyCandidates,
|
|
13
|
-
evaluateSenderGroupAccessForPolicy,
|
|
14
|
-
normalizeChannelSlug,
|
|
15
|
-
resolveAllowlistMatchSimple,
|
|
16
|
-
resolveToolsBySender,
|
|
17
|
-
resolveChannelEntryMatchWithFallback,
|
|
18
|
-
resolveNestedAllowlistDecision,
|
|
19
|
-
isDangerousNameMatchingEnabled,
|
|
20
|
-
} from "../runtime-api.js";
|
|
21
|
-
|
|
22
|
-
type MSTeamsResolvedRouteConfig = {
|
|
23
|
-
teamConfig?: MSTeamsTeamConfig;
|
|
24
|
-
channelConfig?: MSTeamsChannelConfig;
|
|
25
|
-
allowlistConfigured: boolean;
|
|
26
|
-
allowed: boolean;
|
|
27
|
-
teamKey?: string;
|
|
28
|
-
channelKey?: string;
|
|
29
|
-
channelMatchKey?: string;
|
|
30
|
-
channelMatchSource?: "direct" | "wildcard";
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export function resolveMSTeamsRouteConfig(params: {
|
|
34
|
-
cfg?: MSTeamsConfig;
|
|
35
|
-
teamId?: string | null | undefined;
|
|
36
|
-
teamName?: string | null | undefined;
|
|
37
|
-
conversationId?: string | null | undefined;
|
|
38
|
-
channelName?: string | null | undefined;
|
|
39
|
-
allowNameMatching?: boolean;
|
|
40
|
-
}): MSTeamsResolvedRouteConfig {
|
|
41
|
-
const teamId = params.teamId?.trim();
|
|
42
|
-
const teamName = params.teamName?.trim();
|
|
43
|
-
const conversationId = params.conversationId?.trim();
|
|
44
|
-
const channelName = params.channelName?.trim();
|
|
45
|
-
const teams = params.cfg?.teams ?? {};
|
|
46
|
-
const allowlistConfigured = Object.keys(teams).length > 0;
|
|
47
|
-
const teamCandidates = buildChannelKeyCandidates(
|
|
48
|
-
teamId,
|
|
49
|
-
params.allowNameMatching ? teamName : undefined,
|
|
50
|
-
params.allowNameMatching && teamName ? normalizeChannelSlug(teamName) : undefined,
|
|
51
|
-
);
|
|
52
|
-
const teamMatch = resolveChannelEntryMatchWithFallback({
|
|
53
|
-
entries: teams,
|
|
54
|
-
keys: teamCandidates,
|
|
55
|
-
wildcardKey: "*",
|
|
56
|
-
normalizeKey: normalizeChannelSlug,
|
|
57
|
-
});
|
|
58
|
-
const teamConfig = teamMatch.entry;
|
|
59
|
-
const channels = teamConfig?.channels ?? {};
|
|
60
|
-
const channelAllowlistConfigured = Object.keys(channels).length > 0;
|
|
61
|
-
const channelCandidates = buildChannelKeyCandidates(
|
|
62
|
-
conversationId,
|
|
63
|
-
params.allowNameMatching ? channelName : undefined,
|
|
64
|
-
params.allowNameMatching && channelName ? normalizeChannelSlug(channelName) : undefined,
|
|
65
|
-
);
|
|
66
|
-
const channelMatch = resolveChannelEntryMatchWithFallback({
|
|
67
|
-
entries: channels,
|
|
68
|
-
keys: channelCandidates,
|
|
69
|
-
wildcardKey: "*",
|
|
70
|
-
normalizeKey: normalizeChannelSlug,
|
|
71
|
-
});
|
|
72
|
-
const channelConfig = channelMatch.entry;
|
|
73
|
-
|
|
74
|
-
const allowed = resolveNestedAllowlistDecision({
|
|
75
|
-
outerConfigured: allowlistConfigured,
|
|
76
|
-
outerMatched: Boolean(teamConfig),
|
|
77
|
-
innerConfigured: channelAllowlistConfigured,
|
|
78
|
-
innerMatched: Boolean(channelConfig),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
teamConfig,
|
|
83
|
-
channelConfig,
|
|
84
|
-
allowlistConfigured,
|
|
85
|
-
allowed,
|
|
86
|
-
teamKey: teamMatch.matchKey ?? teamMatch.key,
|
|
87
|
-
channelKey: channelMatch.matchKey ?? channelMatch.key,
|
|
88
|
-
channelMatchKey: channelMatch.matchKey,
|
|
89
|
-
channelMatchSource:
|
|
90
|
-
channelMatch.matchSource === "direct" || channelMatch.matchSource === "wildcard"
|
|
91
|
-
? channelMatch.matchSource
|
|
92
|
-
: undefined,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function resolveMSTeamsGroupToolPolicy(
|
|
97
|
-
params: ChannelGroupContext,
|
|
98
|
-
): GroupToolPolicyConfig | undefined {
|
|
99
|
-
const cfg = params.cfg.channels?.msteams;
|
|
100
|
-
if (!cfg) {
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
const groupId = params.groupId?.trim();
|
|
104
|
-
const groupChannel = params.groupChannel?.trim();
|
|
105
|
-
const groupSpace = params.groupSpace?.trim();
|
|
106
|
-
const allowNameMatching = isDangerousNameMatchingEnabled(cfg);
|
|
107
|
-
|
|
108
|
-
const resolved = resolveMSTeamsRouteConfig({
|
|
109
|
-
cfg,
|
|
110
|
-
teamId: groupSpace,
|
|
111
|
-
teamName: groupSpace,
|
|
112
|
-
conversationId: groupId,
|
|
113
|
-
channelName: groupChannel,
|
|
114
|
-
allowNameMatching,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
if (resolved.channelConfig) {
|
|
118
|
-
const senderPolicy = resolveToolsBySender({
|
|
119
|
-
toolsBySender: resolved.channelConfig.toolsBySender,
|
|
120
|
-
senderId: params.senderId,
|
|
121
|
-
senderName: params.senderName,
|
|
122
|
-
senderUsername: params.senderUsername,
|
|
123
|
-
senderE164: params.senderE164,
|
|
124
|
-
});
|
|
125
|
-
if (senderPolicy) {
|
|
126
|
-
return senderPolicy;
|
|
127
|
-
}
|
|
128
|
-
if (resolved.channelConfig.tools) {
|
|
129
|
-
return resolved.channelConfig.tools;
|
|
130
|
-
}
|
|
131
|
-
const teamSenderPolicy = resolveToolsBySender({
|
|
132
|
-
toolsBySender: resolved.teamConfig?.toolsBySender,
|
|
133
|
-
senderId: params.senderId,
|
|
134
|
-
senderName: params.senderName,
|
|
135
|
-
senderUsername: params.senderUsername,
|
|
136
|
-
senderE164: params.senderE164,
|
|
137
|
-
});
|
|
138
|
-
if (teamSenderPolicy) {
|
|
139
|
-
return teamSenderPolicy;
|
|
140
|
-
}
|
|
141
|
-
return resolved.teamConfig?.tools;
|
|
142
|
-
}
|
|
143
|
-
if (resolved.teamConfig) {
|
|
144
|
-
const teamSenderPolicy = resolveToolsBySender({
|
|
145
|
-
toolsBySender: resolved.teamConfig.toolsBySender,
|
|
146
|
-
senderId: params.senderId,
|
|
147
|
-
senderName: params.senderName,
|
|
148
|
-
senderUsername: params.senderUsername,
|
|
149
|
-
senderE164: params.senderE164,
|
|
150
|
-
});
|
|
151
|
-
if (teamSenderPolicy) {
|
|
152
|
-
return teamSenderPolicy;
|
|
153
|
-
}
|
|
154
|
-
if (resolved.teamConfig.tools) {
|
|
155
|
-
return resolved.teamConfig.tools;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (!groupId) {
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const channelCandidates = buildChannelKeyCandidates(
|
|
164
|
-
groupId,
|
|
165
|
-
allowNameMatching ? groupChannel : undefined,
|
|
166
|
-
allowNameMatching && groupChannel ? normalizeChannelSlug(groupChannel) : undefined,
|
|
167
|
-
);
|
|
168
|
-
for (const teamConfig of Object.values(cfg.teams ?? {})) {
|
|
169
|
-
const match = resolveChannelEntryMatchWithFallback({
|
|
170
|
-
entries: teamConfig?.channels ?? {},
|
|
171
|
-
keys: channelCandidates,
|
|
172
|
-
wildcardKey: "*",
|
|
173
|
-
normalizeKey: normalizeChannelSlug,
|
|
174
|
-
});
|
|
175
|
-
if (match.entry) {
|
|
176
|
-
const senderPolicy = resolveToolsBySender({
|
|
177
|
-
toolsBySender: match.entry.toolsBySender,
|
|
178
|
-
senderId: params.senderId,
|
|
179
|
-
senderName: params.senderName,
|
|
180
|
-
senderUsername: params.senderUsername,
|
|
181
|
-
senderE164: params.senderE164,
|
|
182
|
-
});
|
|
183
|
-
if (senderPolicy) {
|
|
184
|
-
return senderPolicy;
|
|
185
|
-
}
|
|
186
|
-
if (match.entry.tools) {
|
|
187
|
-
return match.entry.tools;
|
|
188
|
-
}
|
|
189
|
-
const teamSenderPolicy = resolveToolsBySender({
|
|
190
|
-
toolsBySender: teamConfig?.toolsBySender,
|
|
191
|
-
senderId: params.senderId,
|
|
192
|
-
senderName: params.senderName,
|
|
193
|
-
senderUsername: params.senderUsername,
|
|
194
|
-
senderE164: params.senderE164,
|
|
195
|
-
});
|
|
196
|
-
if (teamSenderPolicy) {
|
|
197
|
-
return teamSenderPolicy;
|
|
198
|
-
}
|
|
199
|
-
return teamConfig?.tools;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return undefined;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
type MSTeamsReplyPolicy = {
|
|
207
|
-
requireMention: boolean;
|
|
208
|
-
replyStyle: MSTeamsReplyStyle;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
type MSTeamsAllowlistMatch = AllowlistMatch<"wildcard" | "id" | "name">;
|
|
212
|
-
|
|
213
|
-
export function resolveMSTeamsAllowlistMatch(params: {
|
|
214
|
-
allowFrom: Array<string | number>;
|
|
215
|
-
senderId: string;
|
|
216
|
-
senderName?: string | null;
|
|
217
|
-
allowNameMatching?: boolean;
|
|
218
|
-
}): MSTeamsAllowlistMatch {
|
|
219
|
-
return resolveAllowlistMatchSimple(params);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function resolveMSTeamsReplyPolicy(params: {
|
|
223
|
-
isDirectMessage: boolean;
|
|
224
|
-
globalConfig?: MSTeamsConfig;
|
|
225
|
-
teamConfig?: MSTeamsTeamConfig;
|
|
226
|
-
channelConfig?: MSTeamsChannelConfig;
|
|
227
|
-
}): MSTeamsReplyPolicy {
|
|
228
|
-
if (params.isDirectMessage) {
|
|
229
|
-
return { requireMention: false, replyStyle: "thread" };
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const requireMention =
|
|
233
|
-
params.channelConfig?.requireMention ??
|
|
234
|
-
params.teamConfig?.requireMention ??
|
|
235
|
-
params.globalConfig?.requireMention ??
|
|
236
|
-
true;
|
|
237
|
-
|
|
238
|
-
const explicitReplyStyle =
|
|
239
|
-
params.channelConfig?.replyStyle ??
|
|
240
|
-
params.teamConfig?.replyStyle ??
|
|
241
|
-
params.globalConfig?.replyStyle;
|
|
242
|
-
|
|
243
|
-
const replyStyle: MSTeamsReplyStyle =
|
|
244
|
-
explicitReplyStyle ?? (requireMention ? "thread" : "top-level");
|
|
245
|
-
|
|
246
|
-
return { requireMention, replyStyle };
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export function isMSTeamsGroupAllowed(params: {
|
|
250
|
-
groupPolicy: GroupPolicy;
|
|
251
|
-
allowFrom: Array<string | number>;
|
|
252
|
-
senderId: string;
|
|
253
|
-
senderName?: string | null;
|
|
254
|
-
allowNameMatching?: boolean;
|
|
255
|
-
}): boolean {
|
|
256
|
-
return evaluateSenderGroupAccessForPolicy({
|
|
257
|
-
groupPolicy: params.groupPolicy,
|
|
258
|
-
groupAllowFrom: params.allowFrom.map((entry) => String(entry)),
|
|
259
|
-
senderId: params.senderId,
|
|
260
|
-
isSenderAllowed: () => resolveMSTeamsAllowlistMatch(params).allowed,
|
|
261
|
-
}).allowed;
|
|
262
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type MSTeamsPoll,
|
|
3
|
-
type MSTeamsPollStore,
|
|
4
|
-
normalizeMSTeamsPollSelections,
|
|
5
|
-
} from "./polls.js";
|
|
6
|
-
|
|
7
|
-
export function createMSTeamsPollStoreMemory(initial: MSTeamsPoll[] = []): MSTeamsPollStore {
|
|
8
|
-
const polls = new Map<string, MSTeamsPoll>();
|
|
9
|
-
for (const poll of initial) {
|
|
10
|
-
polls.set(poll.id, { ...poll });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const createPoll = async (poll: MSTeamsPoll) => {
|
|
14
|
-
polls.set(poll.id, { ...poll });
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const getPoll = async (pollId: string) => polls.get(pollId) ?? null;
|
|
18
|
-
|
|
19
|
-
const recordVote = async (params: { pollId: string; voterId: string; selections: string[] }) => {
|
|
20
|
-
const poll = polls.get(params.pollId);
|
|
21
|
-
if (!poll) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
const normalized = normalizeMSTeamsPollSelections(poll, params.selections);
|
|
25
|
-
poll.votes[params.voterId] = normalized;
|
|
26
|
-
poll.updatedAt = new Date().toISOString();
|
|
27
|
-
polls.set(poll.id, poll);
|
|
28
|
-
return poll;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return { createPoll, getPoll, recordVote };
|
|
32
|
-
}
|
package/src/polls.test.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { createMSTeamsPollStoreMemory } from "./polls-store-memory.js";
|
|
6
|
-
import { buildMSTeamsPollCard, createMSTeamsPollStoreFs, extractMSTeamsPollVote } from "./polls.js";
|
|
7
|
-
import { setMSTeamsRuntime } from "./runtime.js";
|
|
8
|
-
import { msteamsRuntimeStub } from "./test-runtime.js";
|
|
9
|
-
|
|
10
|
-
describe("msteams polls", () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
setMSTeamsRuntime(msteamsRuntimeStub);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("builds poll cards with fallback text", () => {
|
|
16
|
-
const card = buildMSTeamsPollCard({
|
|
17
|
-
question: "Lunch?",
|
|
18
|
-
options: ["Pizza", "Sushi"],
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
expect(card.pollId).toMatch(
|
|
22
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
23
|
-
);
|
|
24
|
-
expect(card.fallbackText).toBe("Poll: Lunch?\n1. Pizza\n2. Sushi");
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("extracts poll votes from activity values", () => {
|
|
28
|
-
const vote = extractMSTeamsPollVote({
|
|
29
|
-
value: {
|
|
30
|
-
openclawPollId: "poll-1",
|
|
31
|
-
choices: "0,1",
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
expect(vote).toEqual({
|
|
36
|
-
pollId: "poll-1",
|
|
37
|
-
selections: ["0", "1"],
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("stores and records poll votes", async () => {
|
|
42
|
-
const home = await fs.promises.mkdtemp(path.join(os.tmpdir(), "openclaw-msteams-polls-"));
|
|
43
|
-
const store = createMSTeamsPollStoreFs({ homedir: () => home });
|
|
44
|
-
await store.createPoll({
|
|
45
|
-
id: "poll-2",
|
|
46
|
-
question: "Pick one",
|
|
47
|
-
options: ["A", "B"],
|
|
48
|
-
maxSelections: 1,
|
|
49
|
-
createdAt: new Date().toISOString(),
|
|
50
|
-
votes: {},
|
|
51
|
-
});
|
|
52
|
-
await store.recordVote({
|
|
53
|
-
pollId: "poll-2",
|
|
54
|
-
voterId: "user-1",
|
|
55
|
-
selections: ["0", "1"],
|
|
56
|
-
});
|
|
57
|
-
const stored = await store.getPoll("poll-2");
|
|
58
|
-
if (!stored) {
|
|
59
|
-
throw new Error("expected stored poll after recordVote");
|
|
60
|
-
}
|
|
61
|
-
expect(stored.votes["user-1"]).toEqual(["0"]);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const createFsStore = async () => {
|
|
66
|
-
const stateDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "openclaw-msteams-polls-"));
|
|
67
|
-
return createMSTeamsPollStoreFs({ stateDir });
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const createMemoryStore = () => createMSTeamsPollStoreMemory();
|
|
71
|
-
|
|
72
|
-
describe.each([
|
|
73
|
-
{ name: "memory", createStore: createMemoryStore },
|
|
74
|
-
{ name: "fs", createStore: createFsStore },
|
|
75
|
-
])("$name poll store", ({ createStore }) => {
|
|
76
|
-
it("stores polls and records normalized votes", async () => {
|
|
77
|
-
const store = await createStore();
|
|
78
|
-
await store.createPoll({
|
|
79
|
-
id: "poll-1",
|
|
80
|
-
question: "Lunch?",
|
|
81
|
-
options: ["Pizza", "Sushi"],
|
|
82
|
-
maxSelections: 1,
|
|
83
|
-
createdAt: new Date().toISOString(),
|
|
84
|
-
votes: {},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const poll = await store.recordVote({
|
|
88
|
-
pollId: "poll-1",
|
|
89
|
-
voterId: "user-1",
|
|
90
|
-
selections: ["0", "1"],
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (!poll) {
|
|
94
|
-
throw new Error("poll store did not return the updated poll");
|
|
95
|
-
}
|
|
96
|
-
expect(poll.votes["user-1"]).toEqual(["0"]);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("memory poll store", () => {
|
|
101
|
-
it("reads seeded polls back, updates timestamps, and returns null for missing polls", async () => {
|
|
102
|
-
const store = createMSTeamsPollStoreMemory([
|
|
103
|
-
{
|
|
104
|
-
id: "poll-1",
|
|
105
|
-
question: "Pick one",
|
|
106
|
-
options: ["A", "B"],
|
|
107
|
-
maxSelections: 1,
|
|
108
|
-
votes: {},
|
|
109
|
-
createdAt: "2026-03-22T00:00:00.000Z",
|
|
110
|
-
updatedAt: "2026-03-22T00:00:00.000Z",
|
|
111
|
-
},
|
|
112
|
-
]);
|
|
113
|
-
|
|
114
|
-
await expect(store.getPoll("poll-1")).resolves.toEqual(
|
|
115
|
-
expect.objectContaining({
|
|
116
|
-
id: "poll-1",
|
|
117
|
-
question: "Pick one",
|
|
118
|
-
}),
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const originalUpdatedAt = "2026-03-22T00:00:00.000Z";
|
|
122
|
-
const result = await store.recordVote({
|
|
123
|
-
pollId: "poll-1",
|
|
124
|
-
voterId: "user-1",
|
|
125
|
-
selections: ["1", "0", "missing"],
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
expect(result?.votes["user-1"]).toEqual(["1"]);
|
|
129
|
-
expect(result?.updatedAt).not.toBe(originalUpdatedAt);
|
|
130
|
-
|
|
131
|
-
await store.createPoll({
|
|
132
|
-
id: "poll-2",
|
|
133
|
-
question: "Pick many",
|
|
134
|
-
options: ["X", "Y"],
|
|
135
|
-
maxSelections: 2,
|
|
136
|
-
votes: {},
|
|
137
|
-
createdAt: "2026-03-22T00:00:00.000Z",
|
|
138
|
-
updatedAt: "2026-03-22T00:00:00.000Z",
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
await expect(
|
|
142
|
-
store.recordVote({
|
|
143
|
-
pollId: "poll-2",
|
|
144
|
-
voterId: "user-2",
|
|
145
|
-
selections: ["1", "0", "1"],
|
|
146
|
-
}),
|
|
147
|
-
).resolves.toEqual(
|
|
148
|
-
expect.objectContaining({
|
|
149
|
-
id: "poll-2",
|
|
150
|
-
votes: {
|
|
151
|
-
"user-2": ["1", "0"],
|
|
152
|
-
},
|
|
153
|
-
}),
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
await expect(
|
|
157
|
-
store.recordVote({ pollId: "missing", voterId: "nobody", selections: ["x"] }),
|
|
158
|
-
).resolves.toBeNull();
|
|
159
|
-
});
|
|
160
|
-
});
|