@kodelyth/msteams 2026.5.42 → 2026.6.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/klaw.plugin.json +726 -2
- package/package.json +16 -4
- 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 -66
- 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 -506
- package/src/attachments/bot-framework.ts +0 -348
- package/src/attachments/download.ts +0 -328
- package/src/attachments/graph.test.ts +0 -441
- package/src/attachments/graph.ts +0 -489
- package/src/attachments/html.ts +0 -122
- package/src/attachments/payload.ts +0 -14
- package/src/attachments/remote-media.test.ts +0 -187
- package/src/attachments/remote-media.ts +0 -86
- package/src/attachments/shared.test.ts +0 -547
- package/src/attachments/shared.ts +0 -655
- package/src/attachments/types.ts +0 -47
- package/src/attachments.graph.test.ts +0 -414
- package/src/attachments.helpers.test.ts +0 -245
- package/src/attachments.test-helpers.ts +0 -17
- package/src/attachments.test.ts +0 -754
- 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 -797
- package/src/channel.directory.test.ts +0 -176
- package/src/channel.message-adapter.test.ts +0 -227
- package/src/channel.runtime.ts +0 -56
- package/src/channel.setup.ts +0 -77
- package/src/channel.test.ts +0 -136
- package/src/channel.ts +0 -1176
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -40
- package/src/conversation-store-fs.test.ts +0 -81
- 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 -260
- 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 -154
- package/src/errors.ts +0 -270
- package/src/feedback-reflection-prompt.ts +0 -117
- package/src/feedback-reflection-store.ts +0 -113
- package/src/feedback-reflection.test.ts +0 -237
- package/src/feedback-reflection.ts +0 -268
- package/src/file-consent-helpers.test.ts +0 -328
- package/src/file-consent-helpers.ts +0 -115
- package/src/file-consent-invoke.ts +0 -150
- package/src/file-consent.test.ts +0 -378
- package/src/file-consent.ts +0 -223
- package/src/graph-chat.ts +0 -36
- package/src/graph-group-management.test.ts +0 -332
- 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 -253
- package/src/graph-messages.read.test.ts +0 -391
- package/src/graph-messages.search.test.ts +0 -227
- package/src/graph-messages.test-helpers.ts +0 -50
- package/src/graph-messages.ts +0 -534
- package/src/graph-teams.test.ts +0 -222
- package/src/graph-teams.ts +0 -114
- package/src/graph-thread.test.ts +0 -252
- package/src/graph-thread.ts +0 -146
- package/src/graph-upload.test.ts +0 -253
- package/src/graph-upload.ts +0 -531
- package/src/graph-users.ts +0 -29
- package/src/graph.test.ts +0 -540
- package/src/graph.ts +0 -308
- 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 -220
- package/src/media-helpers.ts +0 -105
- package/src/mentions.test.ts +0 -254
- package/src/mentions.ts +0 -114
- package/src/messenger.test.ts +0 -961
- package/src/messenger.ts +0 -608
- package/src/monitor-handler/access.ts +0 -136
- package/src/monitor-handler/inbound-media.test.ts +0 -314
- 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 -739
- package/src/monitor-handler/message-handler.dm-media.test.ts +0 -54
- package/src/monitor-handler/message-handler.test-support.ts +0 -99
- package/src/monitor-handler/message-handler.thread-parent.test.ts +0 -225
- package/src/monitor-handler/message-handler.thread-session.test.ts +0 -132
- package/src/monitor-handler/message-handler.ts +0 -1003
- package/src/monitor-handler/reaction-handler.test.ts +0 -325
- package/src/monitor-handler/reaction-handler.ts +0 -122
- package/src/monitor-handler/thread-session.ts +0 -30
- package/src/monitor-handler.adaptive-card.test.ts +0 -158
- package/src/monitor-handler.feedback-authz.test.ts +0 -357
- package/src/monitor-handler.file-consent.test.ts +0 -443
- package/src/monitor-handler.sso.test.ts +0 -576
- package/src/monitor-handler.test-helpers.ts +0 -181
- package/src/monitor-handler.ts +0 -538
- package/src/monitor-handler.types.ts +0 -27
- package/src/monitor-types.ts +0 -6
- package/src/monitor.lifecycle.test.ts +0 -457
- package/src/monitor.test.ts +0 -119
- package/src/monitor.ts +0 -476
- package/src/oauth.flow.ts +0 -77
- package/src/oauth.shared.ts +0 -37
- package/src/oauth.test.ts +0 -350
- package/src/oauth.token.ts +0 -162
- package/src/oauth.ts +0 -130
- package/src/outbound.test.ts +0 -400
- package/src/outbound.ts +0 -198
- package/src/pending-uploads-fs.test.ts +0 -261
- package/src/pending-uploads-fs.ts +0 -235
- package/src/pending-uploads.test.ts +0 -186
- package/src/pending-uploads.ts +0 -121
- package/src/policy.test.ts +0 -156
- package/src/policy.ts +0 -245
- package/src/polls-store-memory.ts +0 -32
- package/src/polls.test.ts +0 -169
- package/src/polls.ts +0 -312
- package/src/presentation.ts +0 -93
- package/src/probe.test.ts +0 -79
- package/src/probe.ts +0 -132
- package/src/reply-dispatcher.test.ts +0 -543
- package/src/reply-dispatcher.ts +0 -523
- package/src/reply-stream-controller.test.ts +0 -424
- package/src/reply-stream-controller.ts +0 -334
- package/src/resolve-allowlist.test.ts +0 -253
- package/src/resolve-allowlist.ts +0 -309
- package/src/revoked-context.ts +0 -17
- package/src/runtime.ts +0 -12
- package/src/sdk-types.ts +0 -59
- package/src/sdk.test.ts +0 -727
- package/src/sdk.ts +0 -916
- package/src/secret-contract.ts +0 -49
- package/src/secret-input.ts +0 -7
- package/src/send-context.test.ts +0 -93
- package/src/send-context.ts +0 -269
- package/src/send.test.ts +0 -588
- package/src/send.ts +0 -697
- package/src/sent-message-cache.test.ts +0 -106
- package/src/sent-message-cache.ts +0 -174
- package/src/session-route.ts +0 -40
- package/src/setup-core.ts +0 -162
- package/src/setup-surface.test.ts +0 -175
- package/src/setup-surface.ts +0 -319
- package/src/sso-token-store.test.ts +0 -74
- 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 -42
- package/src/streaming-message.test.ts +0 -323
- package/src/streaming-message.ts +0 -327
- 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 -268
- package/src/token.ts +0 -194
- package/src/user-agent.test.ts +0 -121
- package/src/user-agent.ts +0 -53
- package/src/webhook-timeouts.ts +0 -27
- package/src/welcome-card.test.ts +0 -104
- package/src/welcome-card.ts +0 -57
- package/test-api.ts +0 -1
- package/tsconfig.json +0 -16
package/src/pending-uploads.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In-memory storage for files awaiting user consent in the FileConsentCard flow.
|
|
3
|
-
*
|
|
4
|
-
* When sending large files (>=4MB) in personal chats, Teams requires user consent
|
|
5
|
-
* before upload. This module stores the file data temporarily until the user
|
|
6
|
-
* accepts or declines, or until the TTL expires.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import crypto from "node:crypto";
|
|
10
|
-
|
|
11
|
-
export interface PendingUpload {
|
|
12
|
-
id: string;
|
|
13
|
-
buffer: Buffer;
|
|
14
|
-
filename: string;
|
|
15
|
-
contentType?: string;
|
|
16
|
-
conversationId: string;
|
|
17
|
-
/** Activity ID of the original FileConsentCard, used to replace it after upload */
|
|
18
|
-
consentCardActivityId?: string;
|
|
19
|
-
createdAt: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const pendingUploads = new Map<string, PendingUpload>();
|
|
23
|
-
/** Timer handles keyed by upload ID, cleared on explicit removal to prevent ghost cleanup */
|
|
24
|
-
const pendingUploadTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
25
|
-
|
|
26
|
-
/** TTL for pending uploads: 5 minutes */
|
|
27
|
-
const PENDING_UPLOAD_TTL_MS = 5 * 60 * 1000;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Store a file pending user consent.
|
|
31
|
-
* Returns the upload ID to include in the FileConsentCard context.
|
|
32
|
-
*/
|
|
33
|
-
export function storePendingUpload(upload: Omit<PendingUpload, "id" | "createdAt">): string {
|
|
34
|
-
const id = crypto.randomUUID();
|
|
35
|
-
const entry: PendingUpload = {
|
|
36
|
-
...upload,
|
|
37
|
-
id,
|
|
38
|
-
createdAt: Date.now(),
|
|
39
|
-
};
|
|
40
|
-
pendingUploads.set(id, entry);
|
|
41
|
-
|
|
42
|
-
// Auto-cleanup after TTL; timer ref stored so removePendingUpload can cancel it
|
|
43
|
-
const timer = setTimeout(() => {
|
|
44
|
-
pendingUploads.delete(id);
|
|
45
|
-
pendingUploadTimers.delete(id);
|
|
46
|
-
}, PENDING_UPLOAD_TTL_MS);
|
|
47
|
-
pendingUploadTimers.set(id, timer);
|
|
48
|
-
|
|
49
|
-
return id;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Retrieve a pending upload by ID.
|
|
54
|
-
* Returns undefined if not found or expired.
|
|
55
|
-
*/
|
|
56
|
-
export function getPendingUpload(id?: string): PendingUpload | undefined {
|
|
57
|
-
if (!id) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
const entry = pendingUploads.get(id);
|
|
61
|
-
if (!entry) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Check if expired (in case timeout hasn't fired yet)
|
|
66
|
-
if (Date.now() - entry.createdAt > PENDING_UPLOAD_TTL_MS) {
|
|
67
|
-
pendingUploads.delete(id);
|
|
68
|
-
const timer = pendingUploadTimers.get(id);
|
|
69
|
-
if (timer !== undefined) {
|
|
70
|
-
clearTimeout(timer);
|
|
71
|
-
pendingUploadTimers.delete(id);
|
|
72
|
-
}
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return entry;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Remove a pending upload (after successful upload or user decline).
|
|
81
|
-
* Also clears the TTL timer to prevent ghost Map deletions.
|
|
82
|
-
*/
|
|
83
|
-
export function removePendingUpload(id?: string): void {
|
|
84
|
-
if (id) {
|
|
85
|
-
pendingUploads.delete(id);
|
|
86
|
-
const timer = pendingUploadTimers.get(id);
|
|
87
|
-
if (timer !== undefined) {
|
|
88
|
-
clearTimeout(timer);
|
|
89
|
-
pendingUploadTimers.delete(id);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Set the consent card activity ID on an existing pending upload.
|
|
96
|
-
* Called after the FileConsentCard is sent and we know its activity ID.
|
|
97
|
-
*/
|
|
98
|
-
export function setPendingUploadActivityId(uploadId: string, activityId: string): void {
|
|
99
|
-
const entry = pendingUploads.get(uploadId);
|
|
100
|
-
if (entry) {
|
|
101
|
-
entry.consentCardActivityId = activityId;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Get the count of pending uploads (for monitoring/debugging).
|
|
107
|
-
*/
|
|
108
|
-
export function getPendingUploadCount(): number {
|
|
109
|
-
return pendingUploads.size;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Clear all pending uploads (for testing).
|
|
114
|
-
*/
|
|
115
|
-
export function clearPendingUploads(): void {
|
|
116
|
-
for (const timer of pendingUploadTimers.values()) {
|
|
117
|
-
clearTimeout(timer);
|
|
118
|
-
}
|
|
119
|
-
pendingUploadTimers.clear();
|
|
120
|
-
pendingUploads.clear();
|
|
121
|
-
}
|
package/src/policy.test.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import type { MSTeamsConfig } from "../runtime-api.js";
|
|
3
|
-
import { resolveMSTeamsReplyPolicy, resolveMSTeamsRouteConfig } from "./policy.js";
|
|
4
|
-
|
|
5
|
-
function resolveNamedTeamRouteConfig(allowNameMatching = false) {
|
|
6
|
-
const cfg: MSTeamsConfig = {
|
|
7
|
-
teams: {
|
|
8
|
-
"My Team": {
|
|
9
|
-
requireMention: true,
|
|
10
|
-
channels: {
|
|
11
|
-
"General Chat": { requireMention: false },
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return resolveMSTeamsRouteConfig({
|
|
18
|
-
cfg,
|
|
19
|
-
teamName: "My Team",
|
|
20
|
-
channelName: "General Chat",
|
|
21
|
-
conversationId: "ignored",
|
|
22
|
-
allowNameMatching,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe("msteams policy", () => {
|
|
27
|
-
describe("resolveMSTeamsRouteConfig", () => {
|
|
28
|
-
it("returns team and channel config when present", () => {
|
|
29
|
-
const cfg: MSTeamsConfig = {
|
|
30
|
-
teams: {
|
|
31
|
-
team123: {
|
|
32
|
-
requireMention: false,
|
|
33
|
-
channels: {
|
|
34
|
-
chan456: { requireMention: true },
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const res = resolveMSTeamsRouteConfig({
|
|
41
|
-
cfg,
|
|
42
|
-
teamId: "team123",
|
|
43
|
-
conversationId: "chan456",
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
if (!res.teamConfig || !res.channelConfig) {
|
|
47
|
-
throw new Error("expected matched team and channel config");
|
|
48
|
-
}
|
|
49
|
-
expect(res.teamConfig.requireMention).toBe(false);
|
|
50
|
-
expect(res.channelConfig.requireMention).toBe(true);
|
|
51
|
-
expect(res.allowlistConfigured).toBe(true);
|
|
52
|
-
expect(res.allowed).toBe(true);
|
|
53
|
-
expect(res.channelMatchKey).toBe("chan456");
|
|
54
|
-
expect(res.channelMatchSource).toBe("direct");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("returns undefined configs when teamId is missing", () => {
|
|
58
|
-
const cfg: MSTeamsConfig = {
|
|
59
|
-
teams: { team123: { requireMention: false } },
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const res = resolveMSTeamsRouteConfig({
|
|
63
|
-
cfg,
|
|
64
|
-
teamId: undefined,
|
|
65
|
-
conversationId: "chan",
|
|
66
|
-
});
|
|
67
|
-
expect(res.teamConfig).toBeUndefined();
|
|
68
|
-
expect(res.channelConfig).toBeUndefined();
|
|
69
|
-
expect(res.allowlistConfigured).toBe(true);
|
|
70
|
-
expect(res.allowed).toBe(false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("blocks team and channel name matches by default", () => {
|
|
74
|
-
const res = resolveNamedTeamRouteConfig();
|
|
75
|
-
|
|
76
|
-
expect(res.teamConfig).toBeUndefined();
|
|
77
|
-
expect(res.channelConfig).toBeUndefined();
|
|
78
|
-
expect(res.allowed).toBe(false);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("matches team and channel by name when dangerous name matching is enabled", () => {
|
|
82
|
-
const res = resolveNamedTeamRouteConfig(true);
|
|
83
|
-
|
|
84
|
-
if (!res.teamConfig || !res.channelConfig) {
|
|
85
|
-
throw new Error("expected matched named team and channel config");
|
|
86
|
-
}
|
|
87
|
-
expect(res.teamConfig.requireMention).toBe(true);
|
|
88
|
-
expect(res.channelConfig.requireMention).toBe(false);
|
|
89
|
-
expect(res.allowed).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe("resolveMSTeamsReplyPolicy", () => {
|
|
94
|
-
it("forces thread replies for direct messages", () => {
|
|
95
|
-
const policy = resolveMSTeamsReplyPolicy({
|
|
96
|
-
isDirectMessage: true,
|
|
97
|
-
globalConfig: { replyStyle: "top-level", requireMention: false },
|
|
98
|
-
});
|
|
99
|
-
expect(policy).toEqual({ requireMention: false, replyStyle: "thread" });
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("defaults to requireMention=true and replyStyle=thread", () => {
|
|
103
|
-
const policy = resolveMSTeamsReplyPolicy({
|
|
104
|
-
isDirectMessage: false,
|
|
105
|
-
globalConfig: {},
|
|
106
|
-
});
|
|
107
|
-
expect(policy).toEqual({ requireMention: true, replyStyle: "thread" });
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("defaults replyStyle to top-level when requireMention=false", () => {
|
|
111
|
-
const policy = resolveMSTeamsReplyPolicy({
|
|
112
|
-
isDirectMessage: false,
|
|
113
|
-
globalConfig: { requireMention: false },
|
|
114
|
-
});
|
|
115
|
-
expect(policy).toEqual({
|
|
116
|
-
requireMention: false,
|
|
117
|
-
replyStyle: "top-level",
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("prefers channel overrides over team and global defaults", () => {
|
|
122
|
-
const policy = resolveMSTeamsReplyPolicy({
|
|
123
|
-
isDirectMessage: false,
|
|
124
|
-
globalConfig: { requireMention: true },
|
|
125
|
-
teamConfig: { requireMention: true },
|
|
126
|
-
channelConfig: { requireMention: false },
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// requireMention from channel -> false, and replyStyle defaults from requireMention -> top-level
|
|
130
|
-
expect(policy).toEqual({
|
|
131
|
-
requireMention: false,
|
|
132
|
-
replyStyle: "top-level",
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("inherits team mention settings when channel config is missing", () => {
|
|
137
|
-
const policy = resolveMSTeamsReplyPolicy({
|
|
138
|
-
isDirectMessage: false,
|
|
139
|
-
globalConfig: { requireMention: true },
|
|
140
|
-
teamConfig: { requireMention: false },
|
|
141
|
-
});
|
|
142
|
-
expect(policy).toEqual({
|
|
143
|
-
requireMention: false,
|
|
144
|
-
replyStyle: "top-level",
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("uses explicit replyStyle even when requireMention defaults would differ", () => {
|
|
149
|
-
const policy = resolveMSTeamsReplyPolicy({
|
|
150
|
-
isDirectMessage: false,
|
|
151
|
-
globalConfig: { requireMention: false, replyStyle: "thread" },
|
|
152
|
-
});
|
|
153
|
-
expect(policy).toEqual({ requireMention: false, replyStyle: "thread" });
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
});
|
package/src/policy.ts
DELETED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AllowlistMatch,
|
|
3
|
-
ChannelGroupContext,
|
|
4
|
-
GroupToolPolicyConfig,
|
|
5
|
-
MSTeamsChannelConfig,
|
|
6
|
-
MSTeamsConfig,
|
|
7
|
-
MSTeamsReplyStyle,
|
|
8
|
-
MSTeamsTeamConfig,
|
|
9
|
-
} from "../runtime-api.js";
|
|
10
|
-
import {
|
|
11
|
-
buildChannelKeyCandidates,
|
|
12
|
-
normalizeChannelSlug,
|
|
13
|
-
resolveAllowlistMatchSimple,
|
|
14
|
-
resolveToolsBySender,
|
|
15
|
-
resolveChannelEntryMatchWithFallback,
|
|
16
|
-
resolveNestedAllowlistDecision,
|
|
17
|
-
isDangerousNameMatchingEnabled,
|
|
18
|
-
} from "../runtime-api.js";
|
|
19
|
-
|
|
20
|
-
type MSTeamsResolvedRouteConfig = {
|
|
21
|
-
teamConfig?: MSTeamsTeamConfig;
|
|
22
|
-
channelConfig?: MSTeamsChannelConfig;
|
|
23
|
-
allowlistConfigured: boolean;
|
|
24
|
-
allowed: boolean;
|
|
25
|
-
teamKey?: string;
|
|
26
|
-
channelKey?: string;
|
|
27
|
-
channelMatchKey?: string;
|
|
28
|
-
channelMatchSource?: "direct" | "wildcard";
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export function resolveMSTeamsRouteConfig(params: {
|
|
32
|
-
cfg?: MSTeamsConfig;
|
|
33
|
-
teamId?: string | null | undefined;
|
|
34
|
-
teamName?: string | null | undefined;
|
|
35
|
-
conversationId?: string | null | undefined;
|
|
36
|
-
channelName?: string | null | undefined;
|
|
37
|
-
allowNameMatching?: boolean;
|
|
38
|
-
}): MSTeamsResolvedRouteConfig {
|
|
39
|
-
const teamId = params.teamId?.trim();
|
|
40
|
-
const teamName = params.teamName?.trim();
|
|
41
|
-
const conversationId = params.conversationId?.trim();
|
|
42
|
-
const channelName = params.channelName?.trim();
|
|
43
|
-
const teams = params.cfg?.teams ?? {};
|
|
44
|
-
const allowlistConfigured = Object.keys(teams).length > 0;
|
|
45
|
-
const teamCandidates = buildChannelKeyCandidates(
|
|
46
|
-
teamId,
|
|
47
|
-
params.allowNameMatching ? teamName : undefined,
|
|
48
|
-
params.allowNameMatching && teamName ? normalizeChannelSlug(teamName) : undefined,
|
|
49
|
-
);
|
|
50
|
-
const teamMatch = resolveChannelEntryMatchWithFallback({
|
|
51
|
-
entries: teams,
|
|
52
|
-
keys: teamCandidates,
|
|
53
|
-
wildcardKey: "*",
|
|
54
|
-
normalizeKey: normalizeChannelSlug,
|
|
55
|
-
});
|
|
56
|
-
const teamConfig = teamMatch.entry;
|
|
57
|
-
const channels = teamConfig?.channels ?? {};
|
|
58
|
-
const channelAllowlistConfigured = Object.keys(channels).length > 0;
|
|
59
|
-
const channelCandidates = buildChannelKeyCandidates(
|
|
60
|
-
conversationId,
|
|
61
|
-
params.allowNameMatching ? channelName : undefined,
|
|
62
|
-
params.allowNameMatching && channelName ? normalizeChannelSlug(channelName) : undefined,
|
|
63
|
-
);
|
|
64
|
-
const channelMatch = resolveChannelEntryMatchWithFallback({
|
|
65
|
-
entries: channels,
|
|
66
|
-
keys: channelCandidates,
|
|
67
|
-
wildcardKey: "*",
|
|
68
|
-
normalizeKey: normalizeChannelSlug,
|
|
69
|
-
});
|
|
70
|
-
const channelConfig = channelMatch.entry;
|
|
71
|
-
|
|
72
|
-
const allowed = resolveNestedAllowlistDecision({
|
|
73
|
-
outerConfigured: allowlistConfigured,
|
|
74
|
-
outerMatched: Boolean(teamConfig),
|
|
75
|
-
innerConfigured: channelAllowlistConfigured,
|
|
76
|
-
innerMatched: Boolean(channelConfig),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
teamConfig,
|
|
81
|
-
channelConfig,
|
|
82
|
-
allowlistConfigured,
|
|
83
|
-
allowed,
|
|
84
|
-
teamKey: teamMatch.matchKey ?? teamMatch.key,
|
|
85
|
-
channelKey: channelMatch.matchKey ?? channelMatch.key,
|
|
86
|
-
channelMatchKey: channelMatch.matchKey,
|
|
87
|
-
channelMatchSource:
|
|
88
|
-
channelMatch.matchSource === "direct" || channelMatch.matchSource === "wildcard"
|
|
89
|
-
? channelMatch.matchSource
|
|
90
|
-
: undefined,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function resolveMSTeamsGroupToolPolicy(
|
|
95
|
-
params: ChannelGroupContext,
|
|
96
|
-
): GroupToolPolicyConfig | undefined {
|
|
97
|
-
const cfg = params.cfg.channels?.msteams;
|
|
98
|
-
if (!cfg) {
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
const groupId = params.groupId?.trim();
|
|
102
|
-
const groupChannel = params.groupChannel?.trim();
|
|
103
|
-
const groupSpace = params.groupSpace?.trim();
|
|
104
|
-
const allowNameMatching = isDangerousNameMatchingEnabled(cfg);
|
|
105
|
-
|
|
106
|
-
const resolved = resolveMSTeamsRouteConfig({
|
|
107
|
-
cfg,
|
|
108
|
-
teamId: groupSpace,
|
|
109
|
-
teamName: groupSpace,
|
|
110
|
-
conversationId: groupId,
|
|
111
|
-
channelName: groupChannel,
|
|
112
|
-
allowNameMatching,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
if (resolved.channelConfig) {
|
|
116
|
-
const senderPolicy = resolveToolsBySender({
|
|
117
|
-
toolsBySender: resolved.channelConfig.toolsBySender,
|
|
118
|
-
senderId: params.senderId,
|
|
119
|
-
senderName: params.senderName,
|
|
120
|
-
senderUsername: params.senderUsername,
|
|
121
|
-
senderE164: params.senderE164,
|
|
122
|
-
});
|
|
123
|
-
if (senderPolicy) {
|
|
124
|
-
return senderPolicy;
|
|
125
|
-
}
|
|
126
|
-
if (resolved.channelConfig.tools) {
|
|
127
|
-
return resolved.channelConfig.tools;
|
|
128
|
-
}
|
|
129
|
-
const teamSenderPolicy = resolveToolsBySender({
|
|
130
|
-
toolsBySender: resolved.teamConfig?.toolsBySender,
|
|
131
|
-
senderId: params.senderId,
|
|
132
|
-
senderName: params.senderName,
|
|
133
|
-
senderUsername: params.senderUsername,
|
|
134
|
-
senderE164: params.senderE164,
|
|
135
|
-
});
|
|
136
|
-
if (teamSenderPolicy) {
|
|
137
|
-
return teamSenderPolicy;
|
|
138
|
-
}
|
|
139
|
-
return resolved.teamConfig?.tools;
|
|
140
|
-
}
|
|
141
|
-
if (resolved.teamConfig) {
|
|
142
|
-
const teamSenderPolicy = resolveToolsBySender({
|
|
143
|
-
toolsBySender: resolved.teamConfig.toolsBySender,
|
|
144
|
-
senderId: params.senderId,
|
|
145
|
-
senderName: params.senderName,
|
|
146
|
-
senderUsername: params.senderUsername,
|
|
147
|
-
senderE164: params.senderE164,
|
|
148
|
-
});
|
|
149
|
-
if (teamSenderPolicy) {
|
|
150
|
-
return teamSenderPolicy;
|
|
151
|
-
}
|
|
152
|
-
if (resolved.teamConfig.tools) {
|
|
153
|
-
return resolved.teamConfig.tools;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (!groupId) {
|
|
158
|
-
return undefined;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const channelCandidates = buildChannelKeyCandidates(
|
|
162
|
-
groupId,
|
|
163
|
-
allowNameMatching ? groupChannel : undefined,
|
|
164
|
-
allowNameMatching && groupChannel ? normalizeChannelSlug(groupChannel) : undefined,
|
|
165
|
-
);
|
|
166
|
-
for (const teamConfig of Object.values(cfg.teams ?? {})) {
|
|
167
|
-
const match = resolveChannelEntryMatchWithFallback({
|
|
168
|
-
entries: teamConfig?.channels ?? {},
|
|
169
|
-
keys: channelCandidates,
|
|
170
|
-
wildcardKey: "*",
|
|
171
|
-
normalizeKey: normalizeChannelSlug,
|
|
172
|
-
});
|
|
173
|
-
if (match.entry) {
|
|
174
|
-
const senderPolicy = resolveToolsBySender({
|
|
175
|
-
toolsBySender: match.entry.toolsBySender,
|
|
176
|
-
senderId: params.senderId,
|
|
177
|
-
senderName: params.senderName,
|
|
178
|
-
senderUsername: params.senderUsername,
|
|
179
|
-
senderE164: params.senderE164,
|
|
180
|
-
});
|
|
181
|
-
if (senderPolicy) {
|
|
182
|
-
return senderPolicy;
|
|
183
|
-
}
|
|
184
|
-
if (match.entry.tools) {
|
|
185
|
-
return match.entry.tools;
|
|
186
|
-
}
|
|
187
|
-
const teamSenderPolicy = resolveToolsBySender({
|
|
188
|
-
toolsBySender: teamConfig?.toolsBySender,
|
|
189
|
-
senderId: params.senderId,
|
|
190
|
-
senderName: params.senderName,
|
|
191
|
-
senderUsername: params.senderUsername,
|
|
192
|
-
senderE164: params.senderE164,
|
|
193
|
-
});
|
|
194
|
-
if (teamSenderPolicy) {
|
|
195
|
-
return teamSenderPolicy;
|
|
196
|
-
}
|
|
197
|
-
return teamConfig?.tools;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return undefined;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
type MSTeamsReplyPolicy = {
|
|
205
|
-
requireMention: boolean;
|
|
206
|
-
replyStyle: MSTeamsReplyStyle;
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
type MSTeamsAllowlistMatch = AllowlistMatch<"wildcard" | "id" | "name">;
|
|
210
|
-
|
|
211
|
-
export function resolveMSTeamsAllowlistMatch(params: {
|
|
212
|
-
allowFrom: Array<string | number>;
|
|
213
|
-
senderId: string;
|
|
214
|
-
senderName?: string | null;
|
|
215
|
-
allowNameMatching?: boolean;
|
|
216
|
-
}): MSTeamsAllowlistMatch {
|
|
217
|
-
return resolveAllowlistMatchSimple(params);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
export function resolveMSTeamsReplyPolicy(params: {
|
|
221
|
-
isDirectMessage: boolean;
|
|
222
|
-
globalConfig?: MSTeamsConfig;
|
|
223
|
-
teamConfig?: MSTeamsTeamConfig;
|
|
224
|
-
channelConfig?: MSTeamsChannelConfig;
|
|
225
|
-
}): MSTeamsReplyPolicy {
|
|
226
|
-
if (params.isDirectMessage) {
|
|
227
|
-
return { requireMention: false, replyStyle: "thread" };
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const requireMention =
|
|
231
|
-
params.channelConfig?.requireMention ??
|
|
232
|
-
params.teamConfig?.requireMention ??
|
|
233
|
-
params.globalConfig?.requireMention ??
|
|
234
|
-
true;
|
|
235
|
-
|
|
236
|
-
const explicitReplyStyle =
|
|
237
|
-
params.channelConfig?.replyStyle ??
|
|
238
|
-
params.teamConfig?.replyStyle ??
|
|
239
|
-
params.globalConfig?.replyStyle;
|
|
240
|
-
|
|
241
|
-
const replyStyle: MSTeamsReplyStyle =
|
|
242
|
-
explicitReplyStyle ?? (requireMention ? "thread" : "top-level");
|
|
243
|
-
|
|
244
|
-
return { requireMention, replyStyle };
|
|
245
|
-
}
|
|
@@ -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
|
-
}
|