@chrischall/microsoft-teams-mcp 0.4.0 → 0.5.0
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +330 -32
- package/dist/bundle.js +2062 -457
- package/dist/chatsvc.js +35 -7
- package/dist/index.js +10 -1
- package/dist/model.js +119 -15
- package/dist/substrate-auth.js +104 -0
- package/dist/substrate-token-cache.js +64 -0
- package/dist/substrate.js +319 -0
- package/dist/tools/changes.js +241 -0
- package/dist/tools/channels.js +5 -3
- package/dist/tools/chat-search.js +65 -0
- package/dist/tools/chat.js +89 -14
- package/dist/tools/confirm.js +50 -7
- package/dist/tools/conversation.js +326 -102
- package/dist/tools/cursor.js +43 -0
- package/dist/tools/format.js +135 -0
- package/dist/tools/healthcheck.js +7 -2
- package/dist/tools/listing.js +74 -10
- package/dist/tools/markread.js +246 -0
- package/dist/tools/roots.js +73 -0
- package/dist/tools/search.js +426 -0
- package/dist/tools/timezone.js +38 -0
- package/dist/tools/unread.js +140 -39
- package/dist/version.js +1 -1
- package/mint.yaml +13 -1
- package/package.json +1 -1
- package/server.json +10 -3
- package/skills/teams-fpx/SKILL.md +6 -3
package/dist/bundle.js
CHANGED
|
@@ -326,8 +326,8 @@ function defineLazy(object2, key, getter) {
|
|
|
326
326
|
configurable: true
|
|
327
327
|
});
|
|
328
328
|
}
|
|
329
|
-
function objectClone(
|
|
330
|
-
return Object.create(Object.getPrototypeOf(
|
|
329
|
+
function objectClone(obj2) {
|
|
330
|
+
return Object.create(Object.getPrototypeOf(obj2), Object.getOwnPropertyDescriptors(obj2));
|
|
331
331
|
}
|
|
332
332
|
function assignProp(target, prop, value) {
|
|
333
333
|
Object.defineProperty(target, prop, {
|
|
@@ -398,10 +398,10 @@ function mergeDefs(...defs) {
|
|
|
398
398
|
function cloneDef(schema) {
|
|
399
399
|
return mergeDefs(schema._zod.def);
|
|
400
400
|
}
|
|
401
|
-
function getElementAtPath(
|
|
401
|
+
function getElementAtPath(obj2, path) {
|
|
402
402
|
if (!path)
|
|
403
|
-
return
|
|
404
|
-
return path.reduce((acc, key) => acc?.[key],
|
|
403
|
+
return obj2;
|
|
404
|
+
return path.reduce((acc, key) => acc?.[key], obj2);
|
|
405
405
|
}
|
|
406
406
|
function promiseAllObject(promisesObj) {
|
|
407
407
|
const keys = Object.keys(promisesObj);
|
|
@@ -416,14 +416,14 @@ function promiseAllObject(promisesObj) {
|
|
|
416
416
|
}
|
|
417
417
|
function randomString(length = 10) {
|
|
418
418
|
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
419
|
-
let
|
|
419
|
+
let str3 = "";
|
|
420
420
|
for (let i = 0; i < length; i++) {
|
|
421
|
-
|
|
421
|
+
str3 += chars[Math.floor(Math.random() * chars.length)];
|
|
422
422
|
}
|
|
423
|
-
return
|
|
423
|
+
return str3;
|
|
424
424
|
}
|
|
425
|
-
function esc(
|
|
426
|
-
return JSON.stringify(
|
|
425
|
+
function esc(str3) {
|
|
426
|
+
return JSON.stringify(str3);
|
|
427
427
|
}
|
|
428
428
|
function slugify(input2) {
|
|
429
429
|
return input2.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -467,8 +467,8 @@ function numKeys(data) {
|
|
|
467
467
|
}
|
|
468
468
|
return keyCount;
|
|
469
469
|
}
|
|
470
|
-
function escapeRegex(
|
|
471
|
-
return
|
|
470
|
+
function escapeRegex(str3) {
|
|
471
|
+
return str3.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
472
472
|
}
|
|
473
473
|
function clone(inst, def, params) {
|
|
474
474
|
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
@@ -710,13 +710,13 @@ function getSizableOrigin(input2) {
|
|
|
710
710
|
return "file";
|
|
711
711
|
return "unknown";
|
|
712
712
|
}
|
|
713
|
-
function codePointLength(
|
|
714
|
-
const units =
|
|
715
|
-
if (!highSurrogate.test(
|
|
713
|
+
function codePointLength(str3) {
|
|
714
|
+
const units = str3.length;
|
|
715
|
+
if (!highSurrogate.test(str3))
|
|
716
716
|
return units;
|
|
717
717
|
let count = units;
|
|
718
718
|
for (let i = 0; i < units - 1; i++) {
|
|
719
|
-
if ((
|
|
719
|
+
if ((str3.charCodeAt(i) & 64512) === 55296 && (str3.charCodeAt(i + 1) & 64512) === 56320) {
|
|
720
720
|
count--;
|
|
721
721
|
i++;
|
|
722
722
|
}
|
|
@@ -743,9 +743,9 @@ function parsedType(data) {
|
|
|
743
743
|
if (Array.isArray(data)) {
|
|
744
744
|
return "array";
|
|
745
745
|
}
|
|
746
|
-
const
|
|
747
|
-
if (
|
|
748
|
-
return
|
|
746
|
+
const obj2 = data;
|
|
747
|
+
if (obj2 && Object.getPrototypeOf(obj2) !== Object.prototype && "constructor" in obj2 && obj2.constructor) {
|
|
748
|
+
return obj2.constructor.name;
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
751
|
}
|
|
@@ -763,8 +763,8 @@ function issue(...args) {
|
|
|
763
763
|
}
|
|
764
764
|
return { ...iss };
|
|
765
765
|
}
|
|
766
|
-
function cleanEnum(
|
|
767
|
-
return Object.entries(
|
|
766
|
+
function cleanEnum(obj2) {
|
|
767
|
+
return Object.entries(obj2).filter(([k, _]) => {
|
|
768
768
|
return Number.isNaN(Number.parseInt(k, 10));
|
|
769
769
|
}).map((el) => el[1]);
|
|
770
770
|
}
|
|
@@ -1161,15 +1161,15 @@ function _getMessage() {
|
|
|
1161
1161
|
function _setMessage(value) {
|
|
1162
1162
|
this._zod.message = value;
|
|
1163
1163
|
}
|
|
1164
|
-
function node(
|
|
1165
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
1164
|
+
function node(obj2, key, make) {
|
|
1165
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key)) {
|
|
1166
1166
|
if (key === "__proto__") {
|
|
1167
|
-
Object.defineProperty(
|
|
1167
|
+
Object.defineProperty(obj2, key, { value: make(), writable: true, enumerable: true, configurable: true });
|
|
1168
1168
|
} else {
|
|
1169
|
-
|
|
1169
|
+
obj2[key] = make();
|
|
1170
1170
|
}
|
|
1171
1171
|
}
|
|
1172
|
-
return
|
|
1172
|
+
return obj2[key];
|
|
1173
1173
|
}
|
|
1174
1174
|
function flattenError(error62, mapper = (issue2) => issue2.message) {
|
|
1175
1175
|
const fieldErrors = {};
|
|
@@ -24258,12 +24258,12 @@ function isZodV4Schema(v) {
|
|
|
24258
24258
|
function looksLikeZodV3(v) {
|
|
24259
24259
|
return typeof v === "object" && v !== null && !("_zod" in v) && "_def" in v && typeof v._def?.typeName === "string";
|
|
24260
24260
|
}
|
|
24261
|
-
function isZodRawShape(
|
|
24262
|
-
if (typeof
|
|
24263
|
-
if (isStandardSchema(
|
|
24264
|
-
const proto = Object.getPrototypeOf(
|
|
24261
|
+
function isZodRawShape(obj2) {
|
|
24262
|
+
if (typeof obj2 !== "object" || obj2 === null) return false;
|
|
24263
|
+
if (isStandardSchema(obj2)) return false;
|
|
24264
|
+
const proto = Object.getPrototypeOf(obj2);
|
|
24265
24265
|
if (proto !== Object.prototype && proto !== null) return false;
|
|
24266
|
-
return Object.values(
|
|
24266
|
+
return Object.values(obj2).every((v) => isZodV4Schema(v));
|
|
24267
24267
|
}
|
|
24268
24268
|
function normalizeRawShapeSchema(schema) {
|
|
24269
24269
|
if (schema === void 0) return void 0;
|
|
@@ -25515,8 +25515,8 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25515
25515
|
if (notification.params.requestId === void 0) return;
|
|
25516
25516
|
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
25517
25517
|
}
|
|
25518
|
-
_setupTimeout(
|
|
25519
|
-
this._timeoutInfo.set(
|
|
25518
|
+
_setupTimeout(messageId2, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
25519
|
+
this._timeoutInfo.set(messageId2, {
|
|
25520
25520
|
timeoutId: setTimeout(onTimeout, timeout),
|
|
25521
25521
|
startTime: Date.now(),
|
|
25522
25522
|
timeout,
|
|
@@ -25525,12 +25525,12 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25525
25525
|
onTimeout
|
|
25526
25526
|
});
|
|
25527
25527
|
}
|
|
25528
|
-
_resetTimeout(
|
|
25529
|
-
const info = this._timeoutInfo.get(
|
|
25528
|
+
_resetTimeout(messageId2) {
|
|
25529
|
+
const info = this._timeoutInfo.get(messageId2);
|
|
25530
25530
|
if (!info) return false;
|
|
25531
25531
|
const totalElapsed = Date.now() - info.startTime;
|
|
25532
25532
|
if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
|
|
25533
|
-
this._timeoutInfo.delete(
|
|
25533
|
+
this._timeoutInfo.delete(messageId2);
|
|
25534
25534
|
throw new SdkError(SdkErrorCode.RequestTimeout, "Maximum total timeout exceeded", {
|
|
25535
25535
|
maxTotalTimeout: info.maxTotalTimeout,
|
|
25536
25536
|
totalElapsed
|
|
@@ -25540,11 +25540,11 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25540
25540
|
info.timeoutId = setTimeout(info.onTimeout, info.timeout);
|
|
25541
25541
|
return true;
|
|
25542
25542
|
}
|
|
25543
|
-
_cleanupTimeout(
|
|
25544
|
-
const info = this._timeoutInfo.get(
|
|
25543
|
+
_cleanupTimeout(messageId2) {
|
|
25544
|
+
const info = this._timeoutInfo.get(messageId2);
|
|
25545
25545
|
if (info) {
|
|
25546
25546
|
clearTimeout(info.timeoutId);
|
|
25547
|
-
this._timeoutInfo.delete(
|
|
25547
|
+
this._timeoutInfo.delete(messageId2);
|
|
25548
25548
|
}
|
|
25549
25549
|
}
|
|
25550
25550
|
/**
|
|
@@ -25743,20 +25743,20 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25743
25743
|
}
|
|
25744
25744
|
_onprogress(notification) {
|
|
25745
25745
|
const { progressToken, ...params } = notification.params;
|
|
25746
|
-
const
|
|
25747
|
-
const handler = this._progressHandlers.get(
|
|
25746
|
+
const messageId2 = Number(progressToken);
|
|
25747
|
+
const handler = this._progressHandlers.get(messageId2);
|
|
25748
25748
|
if (!handler) {
|
|
25749
25749
|
this._onerror(/* @__PURE__ */ new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`));
|
|
25750
25750
|
return;
|
|
25751
25751
|
}
|
|
25752
|
-
const responseHandler = this._responseHandlers.get(
|
|
25753
|
-
const timeoutInfo = this._timeoutInfo.get(
|
|
25752
|
+
const responseHandler = this._responseHandlers.get(messageId2);
|
|
25753
|
+
const timeoutInfo = this._timeoutInfo.get(messageId2);
|
|
25754
25754
|
if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) try {
|
|
25755
|
-
this._resetTimeout(
|
|
25755
|
+
this._resetTimeout(messageId2);
|
|
25756
25756
|
} catch (error62) {
|
|
25757
|
-
this._responseHandlers.delete(
|
|
25758
|
-
this._progressHandlers.delete(
|
|
25759
|
-
this._cleanupTimeout(
|
|
25757
|
+
this._responseHandlers.delete(messageId2);
|
|
25758
|
+
this._progressHandlers.delete(messageId2);
|
|
25759
|
+
this._cleanupTimeout(messageId2);
|
|
25760
25760
|
responseHandler(error62);
|
|
25761
25761
|
return;
|
|
25762
25762
|
}
|
|
@@ -25769,15 +25769,15 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25769
25769
|
* else.
|
|
25770
25770
|
*/
|
|
25771
25771
|
_onresponse(response) {
|
|
25772
|
-
const
|
|
25773
|
-
const handler = this._responseHandlers.get(
|
|
25772
|
+
const messageId2 = Number(response.id);
|
|
25773
|
+
const handler = this._responseHandlers.get(messageId2);
|
|
25774
25774
|
if (handler === void 0) {
|
|
25775
25775
|
this._onerror(/* @__PURE__ */ new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
|
|
25776
25776
|
return;
|
|
25777
25777
|
}
|
|
25778
|
-
this._responseHandlers.delete(
|
|
25779
|
-
this._cleanupTimeout(
|
|
25780
|
-
this._progressHandlers.delete(
|
|
25778
|
+
this._responseHandlers.delete(messageId2);
|
|
25779
|
+
this._cleanupTimeout(messageId2);
|
|
25780
|
+
this._progressHandlers.delete(messageId2);
|
|
25781
25781
|
if (isJSONRPCResultResponse(response)) handler(response);
|
|
25782
25782
|
else handler(ProtocolError.fromError(response.error.code, response.error.message, response.error.data));
|
|
25783
25783
|
}
|
|
@@ -25892,20 +25892,20 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25892
25892
|
throw reason instanceof SdkError ? reason : new SdkError(SdkErrorCode.RequestTimeout, String(reason));
|
|
25893
25893
|
}
|
|
25894
25894
|
const requestAbort = codec2.era === MODERN_WIRE_REVISION && this._transport.hasPerRequestStream === true ? new AbortController() : void 0;
|
|
25895
|
-
const
|
|
25896
|
-
cleanupMessageId =
|
|
25895
|
+
const messageId2 = this._requestMessageId++;
|
|
25896
|
+
cleanupMessageId = messageId2;
|
|
25897
25897
|
const jsonrpcRequest = {
|
|
25898
25898
|
...request,
|
|
25899
25899
|
jsonrpc: "2.0",
|
|
25900
|
-
id:
|
|
25900
|
+
id: messageId2
|
|
25901
25901
|
};
|
|
25902
25902
|
if (options?.onprogress) {
|
|
25903
|
-
this._progressHandlers.set(
|
|
25903
|
+
this._progressHandlers.set(messageId2, options.onprogress);
|
|
25904
25904
|
jsonrpcRequest.params = {
|
|
25905
25905
|
...request.params,
|
|
25906
25906
|
_meta: {
|
|
25907
25907
|
...request.params?._meta,
|
|
25908
|
-
progressToken:
|
|
25908
|
+
progressToken: messageId2
|
|
25909
25909
|
}
|
|
25910
25910
|
};
|
|
25911
25911
|
}
|
|
@@ -25913,13 +25913,13 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25913
25913
|
let responseReceived = false;
|
|
25914
25914
|
const cancel = (reason) => {
|
|
25915
25915
|
if (responseReceived) return;
|
|
25916
|
-
this._progressHandlers.delete(
|
|
25916
|
+
this._progressHandlers.delete(messageId2);
|
|
25917
25917
|
if (requestAbort === void 0) {
|
|
25918
25918
|
if (request.method !== "initialize") this._transport?.send(this._envelopeOutbound({
|
|
25919
25919
|
jsonrpc: "2.0",
|
|
25920
25920
|
method: "notifications/cancelled",
|
|
25921
25921
|
params: {
|
|
25922
|
-
requestId:
|
|
25922
|
+
requestId: messageId2,
|
|
25923
25923
|
reason: String(reason)
|
|
25924
25924
|
}
|
|
25925
25925
|
}), {
|
|
@@ -25930,7 +25930,7 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25930
25930
|
} else requestAbort.abort();
|
|
25931
25931
|
reject(reason instanceof SdkError ? reason : new SdkError(SdkErrorCode.RequestTimeout, String(reason)));
|
|
25932
25932
|
};
|
|
25933
|
-
this._responseHandlers.set(
|
|
25933
|
+
this._responseHandlers.set(messageId2, (response) => {
|
|
25934
25934
|
if (options?.signal?.aborted) return;
|
|
25935
25935
|
responseReceived = true;
|
|
25936
25936
|
if (response instanceof Error) return reject(response);
|
|
@@ -25966,7 +25966,7 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25966
25966
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
25967
25967
|
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
25968
25968
|
const timeoutHandler = () => cancel(new SdkError(SdkErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
25969
|
-
this._setupTimeout(
|
|
25969
|
+
this._setupTimeout(messageId2, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
25970
25970
|
this._transport.send(outbound, {
|
|
25971
25971
|
relatedRequestId,
|
|
25972
25972
|
resumptionToken,
|
|
@@ -25974,7 +25974,7 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
25974
25974
|
headers,
|
|
25975
25975
|
requestSignal: requestAbort?.signal
|
|
25976
25976
|
}).catch((error62) => {
|
|
25977
|
-
this._progressHandlers.delete(
|
|
25977
|
+
this._progressHandlers.delete(messageId2);
|
|
25978
25978
|
reject(error62);
|
|
25979
25979
|
});
|
|
25980
25980
|
}).finally(() => {
|
|
@@ -26118,7 +26118,7 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
26118
26118
|
var index = header.indexOf(";");
|
|
26119
26119
|
var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
|
|
26120
26120
|
if (!TYPE_REGEXP.test(type)) throw new TypeError("invalid media type");
|
|
26121
|
-
var
|
|
26121
|
+
var obj2 = new ContentType(type.toLowerCase());
|
|
26122
26122
|
if (index !== -1) {
|
|
26123
26123
|
var key;
|
|
26124
26124
|
var match;
|
|
@@ -26133,16 +26133,16 @@ var init_src_Cqbh3MYc = __esm({
|
|
|
26133
26133
|
value = value.slice(1, -1);
|
|
26134
26134
|
if (value.indexOf("\\") !== -1) value = value.replace(QESC_REGEXP, "$1");
|
|
26135
26135
|
}
|
|
26136
|
-
|
|
26136
|
+
obj2.parameters[key] = value;
|
|
26137
26137
|
}
|
|
26138
26138
|
if (index !== header.length) throw new TypeError("invalid parameter format");
|
|
26139
26139
|
}
|
|
26140
|
-
return
|
|
26140
|
+
return obj2;
|
|
26141
26141
|
}
|
|
26142
|
-
function getcontenttype(
|
|
26142
|
+
function getcontenttype(obj2) {
|
|
26143
26143
|
var header;
|
|
26144
|
-
if (typeof
|
|
26145
|
-
else if (typeof
|
|
26144
|
+
if (typeof obj2.getHeader === "function") header = obj2.getHeader("content-type");
|
|
26145
|
+
else if (typeof obj2.headers === "object") header = obj2.headers && obj2.headers["content-type"];
|
|
26146
26146
|
if (typeof header !== "string") throw new TypeError("content-type header is missing from object");
|
|
26147
26147
|
return header;
|
|
26148
26148
|
}
|
|
@@ -26267,7 +26267,7 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
26267
26267
|
}
|
|
26268
26268
|
exports._ = _;
|
|
26269
26269
|
const plus = new _Code("+");
|
|
26270
|
-
function
|
|
26270
|
+
function str3(strs, ...args) {
|
|
26271
26271
|
const expr = [safeStringify(strs[0])];
|
|
26272
26272
|
let i = 0;
|
|
26273
26273
|
while (i < args.length) {
|
|
@@ -26278,7 +26278,7 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
26278
26278
|
optimize(expr);
|
|
26279
26279
|
return new _Code(expr);
|
|
26280
26280
|
}
|
|
26281
|
-
exports.str =
|
|
26281
|
+
exports.str = str3;
|
|
26282
26282
|
function addCodeArg(code2, arg) {
|
|
26283
26283
|
if (arg instanceof _Code) code2.push(...arg._items);
|
|
26284
26284
|
else if (arg instanceof Name) code2.push(arg);
|
|
@@ -26311,7 +26311,7 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
26311
26311
|
if (typeof b == "string" && b[0] === '"' && !(a instanceof Name)) return `"${a}${b.slice(1)}`;
|
|
26312
26312
|
}
|
|
26313
26313
|
function strConcat(c1, c2) {
|
|
26314
|
-
return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 :
|
|
26314
|
+
return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str3`${c1}${c2}`;
|
|
26315
26315
|
}
|
|
26316
26316
|
exports.strConcat = strConcat;
|
|
26317
26317
|
function interpolate(x) {
|
|
@@ -26992,10 +26992,10 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
26992
26992
|
}
|
|
26993
26993
|
return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
|
|
26994
26994
|
}
|
|
26995
|
-
forIn(nameOrPrefix,
|
|
26996
|
-
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${
|
|
26995
|
+
forIn(nameOrPrefix, obj2, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
|
|
26996
|
+
if (this.opts.ownProperties) return this.forOf(nameOrPrefix, (0, code_1._)`Object.keys(${obj2})`, forBody);
|
|
26997
26997
|
const name = this._scope.toName(nameOrPrefix);
|
|
26998
|
-
return this._for(new ForIter("in", varKind, name,
|
|
26998
|
+
return this._for(new ForIter("in", varKind, name, obj2), () => forBody(name));
|
|
26999
26999
|
}
|
|
27000
27000
|
endFor() {
|
|
27001
27001
|
return this._endBlockNode(For);
|
|
@@ -27190,21 +27190,21 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
27190
27190
|
return (0, codegen_1._)`${topSchemaRef}${schemaPath}${(0, codegen_1.getProperty)(keyword)}`;
|
|
27191
27191
|
}
|
|
27192
27192
|
exports.schemaRefOrVal = schemaRefOrVal;
|
|
27193
|
-
function unescapeFragment(
|
|
27194
|
-
return unescapeJsonPointer(decodeURIComponent(
|
|
27193
|
+
function unescapeFragment(str3) {
|
|
27194
|
+
return unescapeJsonPointer(decodeURIComponent(str3));
|
|
27195
27195
|
}
|
|
27196
27196
|
exports.unescapeFragment = unescapeFragment;
|
|
27197
|
-
function escapeFragment(
|
|
27198
|
-
return encodeURIComponent(escapeJsonPointer(
|
|
27197
|
+
function escapeFragment(str3) {
|
|
27198
|
+
return encodeURIComponent(escapeJsonPointer(str3));
|
|
27199
27199
|
}
|
|
27200
27200
|
exports.escapeFragment = escapeFragment;
|
|
27201
|
-
function escapeJsonPointer(
|
|
27202
|
-
if (typeof
|
|
27203
|
-
return
|
|
27201
|
+
function escapeJsonPointer(str3) {
|
|
27202
|
+
if (typeof str3 == "number") return `${str3}`;
|
|
27203
|
+
return str3.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
27204
27204
|
}
|
|
27205
27205
|
exports.escapeJsonPointer = escapeJsonPointer;
|
|
27206
|
-
function unescapeJsonPointer(
|
|
27207
|
-
return
|
|
27206
|
+
function unescapeJsonPointer(str3) {
|
|
27207
|
+
return str3.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
27208
27208
|
}
|
|
27209
27209
|
exports.unescapeJsonPointer = unescapeJsonPointer;
|
|
27210
27210
|
function eachItem(xs, f) {
|
|
@@ -28090,8 +28090,8 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
28090
28090
|
post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
28091
28091
|
}
|
|
28092
28092
|
}
|
|
28093
|
-
function escapeJsonPtr(
|
|
28094
|
-
return
|
|
28093
|
+
function escapeJsonPtr(str3) {
|
|
28094
|
+
return str3.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
28095
28095
|
}
|
|
28096
28096
|
}));
|
|
28097
28097
|
require_resolve = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -28523,9 +28523,9 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
28523
28523
|
ok(cond) {
|
|
28524
28524
|
if (!this.allErrors) this.gen.if(cond);
|
|
28525
28525
|
}
|
|
28526
|
-
setParams(
|
|
28527
|
-
if (assign) Object.assign(this.params,
|
|
28528
|
-
else this.params =
|
|
28526
|
+
setParams(obj2, assign) {
|
|
28527
|
+
if (assign) Object.assign(this.params, obj2);
|
|
28528
|
+
else this.params = obj2;
|
|
28529
28529
|
}
|
|
28530
28530
|
block$data(valid, codeBlock, $dataValid = codegen_1.nil) {
|
|
28531
28531
|
this.gen.block(() => {
|
|
@@ -28983,9 +28983,9 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
28983
28983
|
isIPV6: false
|
|
28984
28984
|
};
|
|
28985
28985
|
}
|
|
28986
|
-
function findToken(
|
|
28986
|
+
function findToken(str3, token) {
|
|
28987
28987
|
let ind = 0;
|
|
28988
|
-
for (let i = 0; i <
|
|
28988
|
+
for (let i = 0; i < str3.length; i++) if (str3[i] === token) ind++;
|
|
28989
28989
|
return ind;
|
|
28990
28990
|
}
|
|
28991
28991
|
function removeDotSegments(path) {
|
|
@@ -29500,7 +29500,7 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
29500
29500
|
const util_1 = require_util();
|
|
29501
29501
|
const $dataRefSchema = require_data();
|
|
29502
29502
|
const uri_1 = require_uri();
|
|
29503
|
-
const defaultRegExp = (
|
|
29503
|
+
const defaultRegExp = (str3, flags) => new RegExp(str3, flags);
|
|
29504
29504
|
defaultRegExp.code = "new RegExp";
|
|
29505
29505
|
const META_IGNORE_OPTIONS = [
|
|
29506
29506
|
"removeAdditional",
|
|
@@ -30206,16 +30206,16 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
30206
30206
|
}));
|
|
30207
30207
|
require_ucs2length = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
30208
30208
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30209
|
-
function ucs2length(
|
|
30210
|
-
const len =
|
|
30209
|
+
function ucs2length(str3) {
|
|
30210
|
+
const len = str3.length;
|
|
30211
30211
|
let length = 0;
|
|
30212
30212
|
let pos = 0;
|
|
30213
30213
|
let value;
|
|
30214
30214
|
while (pos < len) {
|
|
30215
30215
|
length++;
|
|
30216
|
-
value =
|
|
30216
|
+
value = str3.charCodeAt(pos++);
|
|
30217
30217
|
if (value >= 55296 && value <= 56319 && pos < len) {
|
|
30218
|
-
value =
|
|
30218
|
+
value = str3.charCodeAt(pos);
|
|
30219
30219
|
if ((value & 64512) === 56320) pos++;
|
|
30220
30220
|
}
|
|
30221
30221
|
}
|
|
@@ -32926,8 +32926,8 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
32926
32926
|
30,
|
|
32927
32927
|
31
|
|
32928
32928
|
];
|
|
32929
|
-
function date5(
|
|
32930
|
-
const matches = DATE.exec(
|
|
32929
|
+
function date5(str3) {
|
|
32930
|
+
const matches = DATE.exec(str3);
|
|
32931
32931
|
if (!matches) return false;
|
|
32932
32932
|
const year = +matches[1];
|
|
32933
32933
|
const month = +matches[2];
|
|
@@ -32942,8 +32942,8 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
32942
32942
|
}
|
|
32943
32943
|
const TIME = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;
|
|
32944
32944
|
function getTime(strictTimeZone) {
|
|
32945
|
-
return function time3(
|
|
32946
|
-
const matches = TIME.exec(
|
|
32945
|
+
return function time3(str3) {
|
|
32946
|
+
const matches = TIME.exec(str3);
|
|
32947
32947
|
if (!matches) return false;
|
|
32948
32948
|
const hr = +matches[1];
|
|
32949
32949
|
const min = +matches[2];
|
|
@@ -32980,8 +32980,8 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
32980
32980
|
const DATE_TIME_SEPARATOR = /t|\s/i;
|
|
32981
32981
|
function getDateTime(strictTimeZone) {
|
|
32982
32982
|
const time3 = getTime(strictTimeZone);
|
|
32983
|
-
return function date_time(
|
|
32984
|
-
const dateTime =
|
|
32983
|
+
return function date_time(str3) {
|
|
32984
|
+
const dateTime = str3.split(DATE_TIME_SEPARATOR);
|
|
32985
32985
|
return dateTime.length === 2 && date5(dateTime[0]) && time3(dateTime[1]);
|
|
32986
32986
|
};
|
|
32987
32987
|
}
|
|
@@ -33002,13 +33002,13 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
33002
33002
|
}
|
|
33003
33003
|
const NOT_URI_FRAGMENT = /\/|:/;
|
|
33004
33004
|
const URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
33005
|
-
function uri(
|
|
33006
|
-
return NOT_URI_FRAGMENT.test(
|
|
33005
|
+
function uri(str3) {
|
|
33006
|
+
return NOT_URI_FRAGMENT.test(str3) && URI.test(str3);
|
|
33007
33007
|
}
|
|
33008
33008
|
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
|
|
33009
|
-
function byte(
|
|
33009
|
+
function byte(str3) {
|
|
33010
33010
|
BYTE.lastIndex = 0;
|
|
33011
|
-
return BYTE.test(
|
|
33011
|
+
return BYTE.test(str3);
|
|
33012
33012
|
}
|
|
33013
33013
|
const MIN_INT32 = -(2 ** 31);
|
|
33014
33014
|
const MAX_INT32 = 2 ** 31 - 1;
|
|
@@ -33022,10 +33022,10 @@ var init_ajvProvider_CEoC_sr = __esm({
|
|
|
33022
33022
|
return true;
|
|
33023
33023
|
}
|
|
33024
33024
|
const Z_ANCHOR = /[^\\]\\Z/;
|
|
33025
|
-
function regex(
|
|
33026
|
-
if (Z_ANCHOR.test(
|
|
33025
|
+
function regex(str3) {
|
|
33026
|
+
if (Z_ANCHOR.test(str3)) return false;
|
|
33027
33027
|
try {
|
|
33028
|
-
new RegExp(
|
|
33028
|
+
new RegExp(str3);
|
|
33029
33029
|
return true;
|
|
33030
33030
|
} catch (e) {
|
|
33031
33031
|
return false;
|
|
@@ -35373,9 +35373,9 @@ function redactSecrets(text) {
|
|
|
35373
35373
|
return text.replace(BEARER_RE, "$1[REDACTED]").replace(BASIC_AUTH_RE, "$1[REDACTED]").replace(SET_COOKIE_RE, "$1$2=[REDACTED]").replace(COOKIE_HEADER_RE, (_m, prefix, pairs) => `${prefix}${pairs.replace(/=[^;,\s]*/g, "=[REDACTED]")}`).replace(API_KEY_RE, "[REDACTED]").replace(GOOGLE_OAUTH_TOKEN_RE, "[REDACTED]").replace(HEADER_SECRET_RE, "$1[REDACTED]").replace(QUERY_SECRET_RE, "$1[REDACTED]").replace(OAUTH_CODE_RE, "$1[REDACTED]").replace(FORM_PASSWORD_RE, "$1[REDACTED]").replace(AWS_SIGV4_RE, "$1[REDACTED]").replace(JSON_COOKIE_DQ_RE, redactJsonCookie('"')).replace(JSON_COOKIE_SQ_RE, redactJsonCookie("'")).replace(JSON_SECRET_DQ_RE, "$1[REDACTED]$2").replace(JSON_SECRET_SQ_RE, "$1[REDACTED]$2").replace(JSON_SECRET_NUM_RE, "$1[REDACTED]").replace(JWT_RE, "[REDACTED]");
|
|
35374
35374
|
}
|
|
35375
35375
|
function truncateErrorMessage(text, max = DEFAULT_ERROR_MESSAGE_MAX) {
|
|
35376
|
-
const
|
|
35376
|
+
const str3 = text === null || text === void 0 ? "" : String(text);
|
|
35377
35377
|
const cap = Math.max(ERROR_REDACTION_INPUT_MAX, max);
|
|
35378
|
-
const redacted = redactSecrets(
|
|
35378
|
+
const redacted = redactSecrets(str3.length > cap ? str3.slice(0, cap) : str3);
|
|
35379
35379
|
if (redacted.length <= max)
|
|
35380
35380
|
return redacted;
|
|
35381
35381
|
return `${redacted.slice(0, max)}\u2026 [truncated]`;
|
|
@@ -37080,7 +37080,7 @@ var init_version = __esm({
|
|
|
37080
37080
|
"src/version.ts"() {
|
|
37081
37081
|
"use strict";
|
|
37082
37082
|
PACKAGE_NAME = "microsoft-teams-mcp";
|
|
37083
|
-
VERSION = "0.
|
|
37083
|
+
VERSION = "0.5.0";
|
|
37084
37084
|
}
|
|
37085
37085
|
});
|
|
37086
37086
|
|
|
@@ -37662,8 +37662,8 @@ function assertBase64(x, label) {
|
|
|
37662
37662
|
function base64ByteLength(s) {
|
|
37663
37663
|
if (s.length % 4 !== 0)
|
|
37664
37664
|
return null;
|
|
37665
|
-
const
|
|
37666
|
-
return s.length / 4 * 3 -
|
|
37665
|
+
const pad2 = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0;
|
|
37666
|
+
return s.length / 4 * 3 - pad2;
|
|
37667
37667
|
}
|
|
37668
37668
|
function assertBase64Bytes(x, label, bytes) {
|
|
37669
37669
|
assertBase64(x, label);
|
|
@@ -47591,6 +47591,73 @@ var init_sharepoint_auth = __esm({
|
|
|
47591
47591
|
}
|
|
47592
47592
|
});
|
|
47593
47593
|
|
|
47594
|
+
// src/substrate-auth.ts
|
|
47595
|
+
var substrate_auth_exports = {};
|
|
47596
|
+
__export(substrate_auth_exports, {
|
|
47597
|
+
SUBSTRATE_CAPTURE_DECL: () => SUBSTRATE_CAPTURE_DECL,
|
|
47598
|
+
SUBSTRATE_TRUST_DOMAINS: () => SUBSTRATE_TRUST_DOMAINS,
|
|
47599
|
+
captureSubstrateTokenViaFetchproxy: () => captureSubstrateTokenViaFetchproxy
|
|
47600
|
+
});
|
|
47601
|
+
async function captureSubstrateTokenViaFetchproxy(env = process.env) {
|
|
47602
|
+
const windowMs = captureWindowMs(env);
|
|
47603
|
+
const transport = createFetchproxyTransport({
|
|
47604
|
+
// Same verb set as the other two captures (`capture_request_header` beside
|
|
47605
|
+
// the always-on `fetch`); only the trusted domain differs.
|
|
47606
|
+
...createBootstrapOpts({
|
|
47607
|
+
domains: [...SUBSTRATE_TRUST_DOMAINS],
|
|
47608
|
+
bootstrap: { captureHeaders: [{ ...SUBSTRATE_CAPTURE_DECL }] }
|
|
47609
|
+
}),
|
|
47610
|
+
port: getWsPort(),
|
|
47611
|
+
fetchTimeoutMs: bridgeDeadlineMs(windowMs),
|
|
47612
|
+
captureWindowMs: windowMs,
|
|
47613
|
+
serverName: PACKAGE_NAME,
|
|
47614
|
+
version: VERSION
|
|
47615
|
+
});
|
|
47616
|
+
try {
|
|
47617
|
+
await transport.start();
|
|
47618
|
+
try {
|
|
47619
|
+
const raw = await transport.server.captureRequestHeader({ ...SUBSTRATE_CAPTURE_DECL, timeoutMs: windowMs });
|
|
47620
|
+
if (typeof raw !== "string") {
|
|
47621
|
+
throw new Error(`${SUBSTRATE_CAPTURE_DECL.host}: capture returned no header`);
|
|
47622
|
+
}
|
|
47623
|
+
const token = stripBearer(raw);
|
|
47624
|
+
if (token.length < MIN_TOKEN_LENGTH3) {
|
|
47625
|
+
throw new Error(
|
|
47626
|
+
`${SUBSTRATE_CAPTURE_DECL.host}: authorization header was present but too short to be a token (${token.length} chars)`
|
|
47627
|
+
);
|
|
47628
|
+
}
|
|
47629
|
+
return token;
|
|
47630
|
+
} catch (e) {
|
|
47631
|
+
const detail = e.message;
|
|
47632
|
+
throw new Error(
|
|
47633
|
+
`could not capture a Substrate search token from the browser (${detail}). In a signed-in teams.cloud.microsoft tab, type anything into the search box at the top and press Enter \u2014 that is what makes Teams call substrate.office.com, where the token is read from \u2014 then retry. A "not in declared set" error means the ContextMint Bridge pairing does not trust substrate.office.com yet: re-pair microsoft-teams-mcp once.`
|
|
47634
|
+
);
|
|
47635
|
+
}
|
|
47636
|
+
} finally {
|
|
47637
|
+
try {
|
|
47638
|
+
await transport.close();
|
|
47639
|
+
} catch {
|
|
47640
|
+
}
|
|
47641
|
+
}
|
|
47642
|
+
}
|
|
47643
|
+
var SUBSTRATE_CAPTURE_DECL, SUBSTRATE_TRUST_DOMAINS, MIN_TOKEN_LENGTH3;
|
|
47644
|
+
var init_substrate_auth = __esm({
|
|
47645
|
+
"src/substrate-auth.ts"() {
|
|
47646
|
+
"use strict";
|
|
47647
|
+
init_fetchproxy();
|
|
47648
|
+
init_capture_window();
|
|
47649
|
+
init_auth_fetchproxy();
|
|
47650
|
+
init_version();
|
|
47651
|
+
SUBSTRATE_CAPTURE_DECL = {
|
|
47652
|
+
host: "substrate.office.com",
|
|
47653
|
+
path: "/searchservice/*",
|
|
47654
|
+
headerName: "authorization"
|
|
47655
|
+
};
|
|
47656
|
+
SUBSTRATE_TRUST_DOMAINS = [SUBSTRATE_CAPTURE_DECL.host];
|
|
47657
|
+
MIN_TOKEN_LENGTH3 = 100;
|
|
47658
|
+
}
|
|
47659
|
+
});
|
|
47660
|
+
|
|
47594
47661
|
// src/index.ts
|
|
47595
47662
|
init_dist2();
|
|
47596
47663
|
init_version();
|
|
@@ -48286,6 +48353,16 @@ function newestActivityMs(c) {
|
|
|
48286
48353
|
const signals = [lastArrival, lastImReceivedMs(c)].filter((n) => n !== void 0 && Number.isFinite(n) && n > 0);
|
|
48287
48354
|
return signals.length === 0 ? void 0 : Math.max(...signals);
|
|
48288
48355
|
}
|
|
48356
|
+
function epochMs(raw) {
|
|
48357
|
+
const ms = typeof raw === "number" ? raw : typeof raw === "string" && /^\s*\d+\s*$/.test(raw) ? Number(raw) : NaN;
|
|
48358
|
+
return Number.isFinite(ms) && ms > 0 ? ms : void 0;
|
|
48359
|
+
}
|
|
48360
|
+
function lastChangeMs(c) {
|
|
48361
|
+
const signals = [newestActivityMs(c), epochMs(c.lastUpdatedMessageId), epochMs(c.lastUpdatedMessageVersion)].filter(
|
|
48362
|
+
(n) => n !== void 0
|
|
48363
|
+
);
|
|
48364
|
+
return signals.length === 0 ? void 0 : Math.max(...signals);
|
|
48365
|
+
}
|
|
48289
48366
|
function isUnreadCandidate(c, meMri) {
|
|
48290
48367
|
const horizon = readHorizon(c);
|
|
48291
48368
|
const last = c.lastMessage;
|
|
@@ -48312,6 +48389,10 @@ function flag(c, name) {
|
|
|
48312
48389
|
const v = c.properties?.[name];
|
|
48313
48390
|
return v === true || typeof v === "string" && v.trim().toLowerCase() === "true";
|
|
48314
48391
|
}
|
|
48392
|
+
function flagOff(c, name) {
|
|
48393
|
+
const v = c.properties?.[name];
|
|
48394
|
+
return v === false || typeof v === "string" && v.trim().toLowerCase() === "false";
|
|
48395
|
+
}
|
|
48315
48396
|
function isHiddenChannel(c) {
|
|
48316
48397
|
return c.memberProperties?.interest === "NotInterested";
|
|
48317
48398
|
}
|
|
@@ -48352,6 +48433,7 @@ function conversationSummary(c, meMri, all = []) {
|
|
|
48352
48433
|
unread,
|
|
48353
48434
|
unread_confirmed: false,
|
|
48354
48435
|
...hidden ? { hidden: true } : {},
|
|
48436
|
+
...flagOff(c, "alerts") ? { muted: true } : {},
|
|
48355
48437
|
...flag(c, "favorite") ? { favorite: true } : {},
|
|
48356
48438
|
...flag(c, "ispinned") ? { pinned: true } : {},
|
|
48357
48439
|
...lastActivity !== void 0 ? { lastActivity } : {},
|
|
@@ -48387,6 +48469,12 @@ function attr(tag, name) {
|
|
|
48387
48469
|
return m ? m[1] ?? m[2] : void 0;
|
|
48388
48470
|
}
|
|
48389
48471
|
var stripTags = (s) => s.replace(/<\/?[a-z!][^>]*>/gi, "");
|
|
48472
|
+
function tableRow(row) {
|
|
48473
|
+
const cells = [...row.matchAll(/<t[dh]\b[^>]*>([\s\S]*?)(?:<\/t[dh]\s*>|(?=<t[dh]\b)|$)/gi)].map(
|
|
48474
|
+
([, cell]) => cell.replace(/[\u0001\u0002]/g, "").replace(/<br\s*\/?>|<\/?(p|div|li|h[1-6])\b[^>]*>|\r?\n/gi, " ").trim()
|
|
48475
|
+
);
|
|
48476
|
+
return cells.length > 0 ? cells.join(" | ") : row;
|
|
48477
|
+
}
|
|
48390
48478
|
function htmlToText(html) {
|
|
48391
48479
|
let s = html.replace(/[\u0001\u0002]/g, "");
|
|
48392
48480
|
s = s.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/gi, "");
|
|
@@ -48406,6 +48494,9 @@ ${QUOTE_CLOSE}
|
|
|
48406
48494
|
if (label === "" || label === href) return href;
|
|
48407
48495
|
return `${inner} (${href})`;
|
|
48408
48496
|
});
|
|
48497
|
+
s = s.replace(/<tr\b[^>]*>([\s\S]*?)<\/tr\s*>/gi, (_whole, row) => `
|
|
48498
|
+
${tableRow(row)}
|
|
48499
|
+
`);
|
|
48409
48500
|
s = s.replace(/<br\s*\/?>/gi, "\n").replace(/<\/?(p|div|li|tr|h[1-6])\b[^>]*>/gi, "\n");
|
|
48410
48501
|
s = decodeEntities(stripTags(s));
|
|
48411
48502
|
const out = [];
|
|
@@ -48433,11 +48524,11 @@ function fileAttachments(raw) {
|
|
|
48433
48524
|
if (f === null || typeof f !== "object") continue;
|
|
48434
48525
|
const o = f;
|
|
48435
48526
|
const info = o.fileInfo && typeof o.fileInfo === "object" ? o.fileInfo : {};
|
|
48436
|
-
const
|
|
48437
|
-
const name =
|
|
48438
|
-
const type =
|
|
48439
|
-
const openUrl =
|
|
48440
|
-
const url2 =
|
|
48527
|
+
const str3 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
48528
|
+
const name = str3(o.fileName) ?? str3(o.title) ?? "(file)";
|
|
48529
|
+
const type = str3(o.fileType) ?? str3(o.type);
|
|
48530
|
+
const openUrl = str3(o.openUrl) ?? str3(info.shareUrl);
|
|
48531
|
+
const url2 = str3(o.objectUrl) ?? str3(info.fileUrl);
|
|
48441
48532
|
out.push({
|
|
48442
48533
|
name,
|
|
48443
48534
|
...type !== void 0 ? { type } : {},
|
|
@@ -48496,7 +48587,38 @@ function oldestFirst(messages) {
|
|
|
48496
48587
|
};
|
|
48497
48588
|
return messages.map((m, i) => ({ m, i, t: at(m) })).reverse().sort((a, b) => Number.isNaN(a.t) || Number.isNaN(b.t) ? 0 : a.t - b.t).map(({ m }) => m);
|
|
48498
48589
|
}
|
|
48499
|
-
function
|
|
48590
|
+
function isTimeZone(tz) {
|
|
48591
|
+
if (tz.trim() === "") return false;
|
|
48592
|
+
try {
|
|
48593
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
48594
|
+
return true;
|
|
48595
|
+
} catch {
|
|
48596
|
+
return false;
|
|
48597
|
+
}
|
|
48598
|
+
}
|
|
48599
|
+
var pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
48600
|
+
function localIsoTime(iso, timeZone) {
|
|
48601
|
+
const ms = Date.parse(iso);
|
|
48602
|
+
if (Number.isNaN(ms)) return void 0;
|
|
48603
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
48604
|
+
timeZone,
|
|
48605
|
+
hourCycle: "h23",
|
|
48606
|
+
year: "numeric",
|
|
48607
|
+
month: "2-digit",
|
|
48608
|
+
day: "2-digit",
|
|
48609
|
+
hour: "2-digit",
|
|
48610
|
+
minute: "2-digit",
|
|
48611
|
+
second: "2-digit"
|
|
48612
|
+
}).formatToParts(new Date(ms));
|
|
48613
|
+
const get = (type) => Number(parts.find((p) => p.type === type)?.value);
|
|
48614
|
+
const millis = (ms % 1e3 + 1e3) % 1e3;
|
|
48615
|
+
const wall = Date.UTC(get("year"), get("month") - 1, get("day"), get("hour"), get("minute"), get("second"), millis);
|
|
48616
|
+
const offsetMin = Math.round((wall - ms) / 6e4);
|
|
48617
|
+
const sign2 = offsetMin < 0 ? "-" : "+";
|
|
48618
|
+
const abs = Math.abs(offsetMin);
|
|
48619
|
+
return `${pad(get("year"), 4)}-${pad(get("month"))}-${pad(get("day"))}T${pad(get("hour"))}:${pad(get("minute"))}:${pad(get("second"))}.${pad(millis, 3)}${sign2}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
|
|
48620
|
+
}
|
|
48621
|
+
function normaliseMessage(m, meMri, opts = {}) {
|
|
48500
48622
|
const props = m.properties ?? {};
|
|
48501
48623
|
const mri = senderMri(m.from);
|
|
48502
48624
|
const arrival = Number(m.id);
|
|
@@ -48505,9 +48627,11 @@ function normaliseMessage(m, meMri) {
|
|
|
48505
48627
|
const root = /;messageid=(\d+)/.exec(m.conversationLink ?? "")?.[1];
|
|
48506
48628
|
const content = m.content ?? "";
|
|
48507
48629
|
const reactions = reactionsOf(props.emotions, meMri);
|
|
48630
|
+
const timeLocal = opts.timeZone !== void 0 ? localIsoTime(time3, opts.timeZone) : void 0;
|
|
48508
48631
|
return {
|
|
48509
48632
|
id: m.id,
|
|
48510
48633
|
time: time3,
|
|
48634
|
+
...timeLocal !== void 0 ? { time_local: timeLocal } : {},
|
|
48511
48635
|
sender: nonEmpty(m.imdisplayname) ?? mri ?? "unknown",
|
|
48512
48636
|
fromMe: mri !== void 0 && mri === meMri,
|
|
48513
48637
|
text: htmlToText(content),
|
|
@@ -48524,22 +48648,32 @@ function summariseAll(raw, meMri) {
|
|
|
48524
48648
|
if (!out.some((s) => s.id === SELF_CHAT)) out.push(conversationSummary({ id: SELF_CHAT }, meMri));
|
|
48525
48649
|
return out;
|
|
48526
48650
|
}
|
|
48527
|
-
function matchConversations(summaries, query) {
|
|
48651
|
+
function matchConversations(summaries, query, { messages = false } = {}) {
|
|
48528
48652
|
const exact = summaries.find((s) => s.id === query);
|
|
48529
|
-
if (exact) return [exact];
|
|
48653
|
+
if (exact) return [{ ...exact, match_reason: "id" }];
|
|
48530
48654
|
const q = query.trim().toLowerCase();
|
|
48531
48655
|
if (q === "") return [];
|
|
48532
48656
|
if (SELF_CHAT_ALIASES.has(q)) {
|
|
48533
48657
|
const self = summaries.find((s) => s.id === SELF_CHAT);
|
|
48534
|
-
if (self) return [self];
|
|
48658
|
+
if (self) return [{ ...self, match_reason: "title" }];
|
|
48535
48659
|
}
|
|
48536
|
-
return summaries.
|
|
48537
|
-
|
|
48538
|
-
|
|
48660
|
+
return summaries.flatMap((s) => {
|
|
48661
|
+
const reason = matchReason(s, q, messages);
|
|
48662
|
+
return reason === void 0 ? [] : [{ ...s, match_reason: reason }];
|
|
48663
|
+
});
|
|
48664
|
+
}
|
|
48665
|
+
function matchReason(s, q, messages) {
|
|
48666
|
+
if (hasRealTitle(s) && s.title.toLowerCase().includes(q)) return "title";
|
|
48667
|
+
if (s.team?.toLowerCase().includes(q)) return "team";
|
|
48668
|
+
if (s.participants?.some((p) => p.toLowerCase().includes(q))) return "participant";
|
|
48669
|
+
if (messages && s.lastMessagePreview !== void 0 && s.lastMessagePreview !== SYSTEM_EVENT_PREVIEW) {
|
|
48670
|
+
if (s.lastMessagePreview.toLowerCase().includes(q)) return "message";
|
|
48671
|
+
}
|
|
48672
|
+
return void 0;
|
|
48539
48673
|
}
|
|
48540
48674
|
function hasRealTitle(s) {
|
|
48541
48675
|
if (s.title === UNTITLED_GROUP_TITLE || s.title === UNTITLED_ONE_ON_ONE_TITLE) return false;
|
|
48542
|
-
return
|
|
48676
|
+
return s.participants === void 0;
|
|
48543
48677
|
}
|
|
48544
48678
|
|
|
48545
48679
|
// src/chatsvc.ts
|
|
@@ -48571,6 +48705,7 @@ function outcomeUnknown(method, e, hint) {
|
|
|
48571
48705
|
}
|
|
48572
48706
|
var SEND_OUTCOME_HINT = "The message may already have been posted \u2014 check the conversation (teams_read_conversation) before retrying; do not resend blindly.";
|
|
48573
48707
|
var REACTION_OUTCOME_HINT = "The reaction change may already have been applied \u2014 check the message (teams_read_conversation) before retrying.";
|
|
48708
|
+
var HORIZON_OUTCOME_HINT = "The read marker may already have moved \u2014 check the conversation (teams_read_conversation) before retrying; moving it again to the same message is harmless.";
|
|
48574
48709
|
function outcomeUnknownStatus(e) {
|
|
48575
48710
|
const status = e.cause?.status;
|
|
48576
48711
|
return typeof status === "number" ? status : void 0;
|
|
@@ -48726,12 +48861,16 @@ var ChatServiceClient = class {
|
|
|
48726
48861
|
return out;
|
|
48727
48862
|
}
|
|
48728
48863
|
/**
|
|
48729
|
-
* One message by id, or `undefined` when the service
|
|
48730
|
-
*
|
|
48864
|
+
* One message by id, or `undefined` when the service answers 404. Used to
|
|
48865
|
+
* quote a message (its sender and text go into the quote) and to fill in a
|
|
48866
|
+
* channel thread's root post when it is older than a read's window — a
|
|
48867
|
+
* channel root fetched by its id answers like any message (verified live
|
|
48868
|
+
* 2026-10-12). An id the channel does not hold was answered 403, not 404,
|
|
48869
|
+
* live, so that surfaces as an error.
|
|
48731
48870
|
*/
|
|
48732
|
-
async getMessage(conversationId,
|
|
48871
|
+
async getMessage(conversationId, messageId2) {
|
|
48733
48872
|
this.#requireConfigured();
|
|
48734
|
-
const url2 = `${this.#baseUrl}/users/ME/conversations/${encodeURIComponent(conversationId)}/messages/${encodeURIComponent(
|
|
48873
|
+
const url2 = `${this.#baseUrl}/users/ME/conversations/${encodeURIComponent(conversationId)}/messages/${encodeURIComponent(messageId2)}`;
|
|
48735
48874
|
const { status, body } = await this.#send(url2, "text");
|
|
48736
48875
|
if (status === 404) return void 0;
|
|
48737
48876
|
return this.#parseJson(status, body);
|
|
@@ -48769,19 +48908,39 @@ var ChatServiceClient = class {
|
|
|
48769
48908
|
* the tool reads the message back rather than reporting a plain failure for
|
|
48770
48909
|
* a change that may well be visible already.
|
|
48771
48910
|
*/
|
|
48772
|
-
async setReaction(conversationId,
|
|
48773
|
-
await this.#writeEmotions("PUT", conversationId,
|
|
48911
|
+
async setReaction(conversationId, messageId2, key, at = Date.now()) {
|
|
48912
|
+
await this.#writeEmotions("PUT", conversationId, messageId2, { key, value: at });
|
|
48774
48913
|
}
|
|
48775
48914
|
/** Withdraw the user's reaction: `DELETE` on the same property (unverified live — see the plan). */
|
|
48776
|
-
async removeReaction(conversationId,
|
|
48777
|
-
await this.#writeEmotions("DELETE", conversationId,
|
|
48915
|
+
async removeReaction(conversationId, messageId2, key) {
|
|
48916
|
+
await this.#writeEmotions("DELETE", conversationId, messageId2, { key });
|
|
48778
48917
|
}
|
|
48779
|
-
async #writeEmotions(method, conversationId,
|
|
48918
|
+
async #writeEmotions(method, conversationId, messageId2, emotions) {
|
|
48780
48919
|
this.#requireConfigured();
|
|
48781
|
-
const url2 = `${this.#baseUrl}/users/ME/conversations/${encodeURIComponent(conversationId)}/messages/${encodeURIComponent(
|
|
48920
|
+
const url2 = `${this.#baseUrl}/users/ME/conversations/${encodeURIComponent(conversationId)}/messages/${encodeURIComponent(messageId2)}/properties?name=emotions`;
|
|
48782
48921
|
const { status } = await this.#send(url2, "text", void 0, { method, body: { emotions }, hint: REACTION_OUTCOME_HINT });
|
|
48783
48922
|
this.#checkWriteStatus(method, status, REACTION_OUTCOME_HINT);
|
|
48784
48923
|
}
|
|
48924
|
+
/**
|
|
48925
|
+
* Move the user's read marker in a conversation to `messageId`:
|
|
48926
|
+
* `PUT …/conversations/{id}/properties?name=consumptionhorizon` with
|
|
48927
|
+
* `{ consumptionhorizon: "<id>;<client ms>;<id>" }` — the shape `readHorizon`
|
|
48928
|
+
* parses, its first segment the message's arrival ms (which is its id).
|
|
48929
|
+
* Teams clears the unread badge for everything up to it.
|
|
48930
|
+
*
|
|
48931
|
+
* Verified live 2026-10-12 on `48:notes`: 200, and the listing then carries
|
|
48932
|
+
* the new horizon. A move BACKWARDS is also answered 200 but ignored, so a
|
|
48933
|
+
* 200 does not prove the marker moved; never sending one is the caller's
|
|
48934
|
+
* rule (`teams_mark_read`), which reports it as a no-op instead. A lost
|
|
48935
|
+
* answer is a `WriteOutcomeUnknownError`, as for a reaction.
|
|
48936
|
+
*/
|
|
48937
|
+
async setConsumptionHorizon(conversationId, messageId2, at = Date.now()) {
|
|
48938
|
+
this.#requireConfigured();
|
|
48939
|
+
const url2 = `${this.#baseUrl}/users/ME/conversations/${encodeURIComponent(conversationId)}/properties?name=consumptionhorizon`;
|
|
48940
|
+
const body = { consumptionhorizon: `${messageId2};${at};${messageId2}` };
|
|
48941
|
+
const { status } = await this.#send(url2, "text", void 0, { method: "PUT", body, hint: HORIZON_OUTCOME_HINT });
|
|
48942
|
+
this.#checkWriteStatus("PUT", status, HORIZON_OUTCOME_HINT);
|
|
48943
|
+
}
|
|
48785
48944
|
/**
|
|
48786
48945
|
* Download an inline image (`<img src>` in a message body).
|
|
48787
48946
|
*
|
|
@@ -49259,8 +49418,274 @@ var SharePointClient = class {
|
|
|
49259
49418
|
}
|
|
49260
49419
|
};
|
|
49261
49420
|
|
|
49421
|
+
// src/substrate.ts
|
|
49422
|
+
init_dist2();
|
|
49423
|
+
|
|
49424
|
+
// src/substrate-token-cache.ts
|
|
49425
|
+
init_dist2();
|
|
49426
|
+
function substrateTokenCachePath(env = process.env) {
|
|
49427
|
+
return resolveStateFile({
|
|
49428
|
+
env,
|
|
49429
|
+
envVar: "TEAMS_SUBSTRATE_TOKEN_FILE",
|
|
49430
|
+
subdir: ".microsoft-teams-mcp",
|
|
49431
|
+
fileName: "substrate-token.json"
|
|
49432
|
+
});
|
|
49433
|
+
}
|
|
49434
|
+
function isToken3(raw) {
|
|
49435
|
+
if (raw === null || typeof raw !== "object") return false;
|
|
49436
|
+
const t = raw;
|
|
49437
|
+
return typeof t.accessToken === "string" && t.accessToken !== "" && typeof t.expiresAt === "number" && (t.refreshToken === void 0 || typeof t.refreshToken === "string");
|
|
49438
|
+
}
|
|
49439
|
+
function createSubstrateTokenCache(env = process.env) {
|
|
49440
|
+
if (!parseBoolEnv("TEAMS_TOKEN_CACHE", { env, default: true })) return null;
|
|
49441
|
+
if (parseBoolEnv("TEAMS_DISABLE_FETCHPROXY", { env })) return null;
|
|
49442
|
+
const file2 = createFileStatePersistence({
|
|
49443
|
+
filePath: substrateTokenCachePath(env),
|
|
49444
|
+
boundTo: "fetchproxy",
|
|
49445
|
+
validate: (raw) => isToken3(raw) ? raw : null
|
|
49446
|
+
});
|
|
49447
|
+
return {
|
|
49448
|
+
load: () => file2.load(),
|
|
49449
|
+
save(tokens) {
|
|
49450
|
+
try {
|
|
49451
|
+
file2.save(tokens);
|
|
49452
|
+
} catch (err) {
|
|
49453
|
+
reportCacheWriteFailure(err);
|
|
49454
|
+
}
|
|
49455
|
+
},
|
|
49456
|
+
clear() {
|
|
49457
|
+
try {
|
|
49458
|
+
file2.clear();
|
|
49459
|
+
} catch (err) {
|
|
49460
|
+
reportCacheWriteFailure(err);
|
|
49461
|
+
}
|
|
49462
|
+
}
|
|
49463
|
+
};
|
|
49464
|
+
}
|
|
49465
|
+
|
|
49466
|
+
// src/substrate.ts
|
|
49467
|
+
var SUBSTRATE_QUERY_URL = "https://substrate.office.com/searchservice/api/v2/query";
|
|
49468
|
+
var CAPTURE_RETRY_COOLDOWN_MS = 10 * 60 * 1e3;
|
|
49469
|
+
var UNKNOWN_TOKEN_TTL_MS3 = 10 * 60 * 1e3;
|
|
49470
|
+
var RECAPTURE_SENTINEL3 = "fetchproxy:recapture";
|
|
49471
|
+
var REQUEST_TIMEOUT_MS3 = 3e4;
|
|
49472
|
+
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
49473
|
+
function toBearerTokens3(accessToken) {
|
|
49474
|
+
let expiresAt;
|
|
49475
|
+
try {
|
|
49476
|
+
expiresAt = decodeJwtExp(accessToken) * 1e3;
|
|
49477
|
+
} catch {
|
|
49478
|
+
expiresAt = Date.now() + UNKNOWN_TOKEN_TTL_MS3;
|
|
49479
|
+
}
|
|
49480
|
+
return { accessToken, refreshToken: RECAPTURE_SENTINEL3, expiresAt };
|
|
49481
|
+
}
|
|
49482
|
+
async function captureSubstrateTokenLazily() {
|
|
49483
|
+
const mod = await Promise.resolve().then(() => (init_substrate_auth(), substrate_auth_exports));
|
|
49484
|
+
return mod.captureSubstrateTokenViaFetchproxy();
|
|
49485
|
+
}
|
|
49486
|
+
function sentBound(ms) {
|
|
49487
|
+
return new Date(Math.floor(ms / 1e3) * 1e3).toISOString().replace(/\.000Z$/, "Z");
|
|
49488
|
+
}
|
|
49489
|
+
function buildQueryString(req) {
|
|
49490
|
+
const filters = [];
|
|
49491
|
+
if (req.conversationId !== void 0) {
|
|
49492
|
+
if (/["\s]/.test(req.conversationId)) {
|
|
49493
|
+
throw new McpToolError("That conversation id cannot be expressed as a Substrate filter.", { kind: "unknown" });
|
|
49494
|
+
}
|
|
49495
|
+
filters.push(`ClientThreadId:"${req.conversationId}"`);
|
|
49496
|
+
}
|
|
49497
|
+
if (req.sentAfter !== void 0 && Number.isFinite(req.sentAfter)) filters.push(`sent>=${sentBound(req.sentAfter)}`);
|
|
49498
|
+
return filters.length === 0 ? req.query : [`(${req.query})`, ...filters].join(" ");
|
|
49499
|
+
}
|
|
49500
|
+
function buildQueryBody(req) {
|
|
49501
|
+
const cvid = crypto.randomUUID();
|
|
49502
|
+
return {
|
|
49503
|
+
entityRequests: [
|
|
49504
|
+
{
|
|
49505
|
+
entityType: "Message",
|
|
49506
|
+
contentSources: ["Teams"],
|
|
49507
|
+
query: { queryString: buildQueryString(req), displayQueryString: req.query },
|
|
49508
|
+
from: req.from,
|
|
49509
|
+
size: req.size,
|
|
49510
|
+
sort: [{ Field: "Time", SortDirection: "Desc" }]
|
|
49511
|
+
}
|
|
49512
|
+
],
|
|
49513
|
+
cvid,
|
|
49514
|
+
logicalId: cvid,
|
|
49515
|
+
scenario: {
|
|
49516
|
+
Name: "powerbar",
|
|
49517
|
+
Dimensions: [
|
|
49518
|
+
{ DimensionName: "QueryType", DimensionValue: "Messages" },
|
|
49519
|
+
{ DimensionName: "FormFactor", DimensionValue: "general.web.reactSearch" }
|
|
49520
|
+
]
|
|
49521
|
+
},
|
|
49522
|
+
QueryAlterationOptions: { EnableSuggestion: false, EnableAlteration: false }
|
|
49523
|
+
};
|
|
49524
|
+
}
|
|
49525
|
+
function obj(v) {
|
|
49526
|
+
return v !== null && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
49527
|
+
}
|
|
49528
|
+
function str(v) {
|
|
49529
|
+
return typeof v === "string" && v.trim() !== "" ? v : void 0;
|
|
49530
|
+
}
|
|
49531
|
+
function isoOf(v) {
|
|
49532
|
+
const s = str(v);
|
|
49533
|
+
if (s === void 0) return void 0;
|
|
49534
|
+
const ms = Date.parse(s);
|
|
49535
|
+
return Number.isFinite(ms) ? new Date(ms).toISOString() : void 0;
|
|
49536
|
+
}
|
|
49537
|
+
function mapResult(raw) {
|
|
49538
|
+
const r = obj(raw);
|
|
49539
|
+
const source = obj(r?.Source);
|
|
49540
|
+
if (r === void 0 || source === void 0) return void 0;
|
|
49541
|
+
const clientConv = str(source.ClientConversationId) ?? str(source.ClientThreadId);
|
|
49542
|
+
if (clientConv === void 0) return void 0;
|
|
49543
|
+
const [conversationId, ...params] = clientConv.split(";");
|
|
49544
|
+
if (str(conversationId) === void 0) return void 0;
|
|
49545
|
+
const root = params.map((p) => /^messageid=(.+)$/i.exec(p.trim())?.[1]).find((v) => v !== void 0);
|
|
49546
|
+
const messageId2 = str(source.InternetMessageId);
|
|
49547
|
+
const from = obj(obj(source.Sender)?.EmailAddress) ?? obj(obj(source.From)?.EmailAddress);
|
|
49548
|
+
const text = str(source.Preview) ?? str(r.HitHighlightedSummary) ?? "";
|
|
49549
|
+
const time3 = isoOf(source.DateTimeSent) ?? isoOf(source.DateTimeReceived) ?? isoOf(source.DateTimeCreated);
|
|
49550
|
+
const sender = str(from?.Name);
|
|
49551
|
+
const senderEmail = str(from?.Address);
|
|
49552
|
+
const subject = str(source.Subject);
|
|
49553
|
+
return {
|
|
49554
|
+
conversationId,
|
|
49555
|
+
...messageId2 !== void 0 ? { messageId: messageId2 } : {},
|
|
49556
|
+
...time3 !== void 0 ? { time: time3 } : {},
|
|
49557
|
+
...sender !== void 0 ? { sender } : {},
|
|
49558
|
+
...senderEmail !== void 0 ? { senderEmail } : {},
|
|
49559
|
+
text,
|
|
49560
|
+
...subject !== void 0 ? { subject } : {},
|
|
49561
|
+
...root !== void 0 && root !== messageId2 ? { replyTo: root } : {}
|
|
49562
|
+
};
|
|
49563
|
+
}
|
|
49564
|
+
function parseQueryResponse(body) {
|
|
49565
|
+
const sets = obj(body)?.EntitySets;
|
|
49566
|
+
const firstSet = Array.isArray(sets) ? obj(sets[0]) : void 0;
|
|
49567
|
+
const resultSets = firstSet?.ResultSets;
|
|
49568
|
+
const rs = Array.isArray(resultSets) ? obj(resultSets[0]) : void 0;
|
|
49569
|
+
if (rs === void 0) return { results: [], moreAvailable: false, unmapped: 0 };
|
|
49570
|
+
const raw = Array.isArray(rs.Results) ? rs.Results : [];
|
|
49571
|
+
const results = [];
|
|
49572
|
+
let unmapped = 0;
|
|
49573
|
+
for (const r of raw) {
|
|
49574
|
+
const m = mapResult(r);
|
|
49575
|
+
if (m === void 0) unmapped++;
|
|
49576
|
+
else results.push(m);
|
|
49577
|
+
}
|
|
49578
|
+
return {
|
|
49579
|
+
results,
|
|
49580
|
+
...typeof rs.Total === "number" ? { total: rs.Total } : {},
|
|
49581
|
+
moreAvailable: rs.MoreResultsAvailable === true,
|
|
49582
|
+
unmapped
|
|
49583
|
+
};
|
|
49584
|
+
}
|
|
49585
|
+
var SubstrateClient = class {
|
|
49586
|
+
#fetchImpl;
|
|
49587
|
+
#configError = null;
|
|
49588
|
+
#manager;
|
|
49589
|
+
/**
|
|
49590
|
+
* When the last capture failed, or a freshly captured token was still
|
|
49591
|
+
* refused (401), and how; cleared by a successful capture.
|
|
49592
|
+
*/
|
|
49593
|
+
#captureFailure = null;
|
|
49594
|
+
constructor(opts = {}) {
|
|
49595
|
+
const env = opts.env ?? process.env;
|
|
49596
|
+
const capture = opts.captureToken ?? captureSubstrateTokenLazily;
|
|
49597
|
+
this.#fetchImpl = opts.fetchImpl ?? ((input2, init) => fetch(input2, init));
|
|
49598
|
+
const recapture = async () => {
|
|
49599
|
+
try {
|
|
49600
|
+
const tokens = toBearerTokens3(await capture());
|
|
49601
|
+
this.#captureFailure = null;
|
|
49602
|
+
return tokens;
|
|
49603
|
+
} catch (error62) {
|
|
49604
|
+
this.#captureFailure = { at: Date.now(), error: error62 };
|
|
49605
|
+
throw error62;
|
|
49606
|
+
}
|
|
49607
|
+
};
|
|
49608
|
+
const persistence = createSubstrateTokenCache(env);
|
|
49609
|
+
this.#manager = new TokenManager({
|
|
49610
|
+
initial: recapture,
|
|
49611
|
+
refresh: recapture,
|
|
49612
|
+
...persistence ? { persistence } : {}
|
|
49613
|
+
});
|
|
49614
|
+
if (parseBoolEnv("TEAMS_DISABLE_FETCHPROXY", { env })) {
|
|
49615
|
+
this.#configError = new McpToolError("Substrate search is disabled (no token source).", {
|
|
49616
|
+
kind: "no_credential",
|
|
49617
|
+
hint: "Unset TEAMS_DISABLE_FETCHPROXY so a Substrate token can be captured from a signed-in Teams tab."
|
|
49618
|
+
});
|
|
49619
|
+
}
|
|
49620
|
+
}
|
|
49621
|
+
/** Whether a token could be obtained at all (the bridge is not disabled). */
|
|
49622
|
+
isConfigured() {
|
|
49623
|
+
return this.#configError === null;
|
|
49624
|
+
}
|
|
49625
|
+
async searchMessages(req, opts = {}) {
|
|
49626
|
+
if (this.#configError) throw this.#configError;
|
|
49627
|
+
const failed = this.#captureFailure;
|
|
49628
|
+
if (!opts.force && failed !== null && Date.now() - failed.at < CAPTURE_RETRY_COOLDOWN_MS) throw failed.error;
|
|
49629
|
+
let text = "";
|
|
49630
|
+
const res = await this.#manager.withAuth(async (token) => {
|
|
49631
|
+
const r = await fetchBounded(
|
|
49632
|
+
SUBSTRATE_QUERY_URL,
|
|
49633
|
+
{
|
|
49634
|
+
method: "POST",
|
|
49635
|
+
headers: {
|
|
49636
|
+
authorization: `Bearer ${token}`,
|
|
49637
|
+
"content-type": "application/json",
|
|
49638
|
+
accept: "application/json"
|
|
49639
|
+
},
|
|
49640
|
+
body: JSON.stringify(buildQueryBody(req)),
|
|
49641
|
+
redirect: "error"
|
|
49642
|
+
},
|
|
49643
|
+
{
|
|
49644
|
+
read: "text",
|
|
49645
|
+
maxBytes: MAX_RESPONSE_BYTES,
|
|
49646
|
+
service: "Substrate",
|
|
49647
|
+
timeoutMs: REQUEST_TIMEOUT_MS3,
|
|
49648
|
+
fetchImpl: this.#fetchImpl
|
|
49649
|
+
}
|
|
49650
|
+
);
|
|
49651
|
+
text = r.body;
|
|
49652
|
+
return r.res;
|
|
49653
|
+
});
|
|
49654
|
+
try {
|
|
49655
|
+
checkStatus(res.status);
|
|
49656
|
+
} catch (error62) {
|
|
49657
|
+
if (res.status === 401) this.#captureFailure = { at: Date.now(), error: error62 };
|
|
49658
|
+
throw error62;
|
|
49659
|
+
}
|
|
49660
|
+
try {
|
|
49661
|
+
return parseQueryResponse(JSON.parse(text));
|
|
49662
|
+
} catch {
|
|
49663
|
+
throw new McpToolError("Substrate returned a response that is not JSON.", { status: res.status, kind: "http" });
|
|
49664
|
+
}
|
|
49665
|
+
}
|
|
49666
|
+
};
|
|
49667
|
+
function checkStatus(status) {
|
|
49668
|
+
if (status >= 200 && status < 300) return;
|
|
49669
|
+
if (status === 401) {
|
|
49670
|
+
throw new McpToolError("Substrate rejected the search token (401) even after a fresh capture.", {
|
|
49671
|
+
status,
|
|
49672
|
+
kind: "credential_rejected",
|
|
49673
|
+
hint: "Run a search in a signed-in Teams tab to mint a fresh Substrate token, then retry."
|
|
49674
|
+
});
|
|
49675
|
+
}
|
|
49676
|
+
if (status === 429) {
|
|
49677
|
+
throw new McpToolError("Substrate is rate-limiting searches (429).", { status, kind: "http", hint: "Wait a minute before retrying." });
|
|
49678
|
+
}
|
|
49679
|
+
throw new McpToolError(`Substrate search returned HTTP ${status}.`, {
|
|
49680
|
+
status,
|
|
49681
|
+
kind: "http",
|
|
49682
|
+
...status >= 500 ? { hint: "A Substrate-side failure; retry shortly." } : {}
|
|
49683
|
+
});
|
|
49684
|
+
}
|
|
49685
|
+
|
|
49262
49686
|
// src/tools/chat.ts
|
|
49263
49687
|
init_dist2();
|
|
49688
|
+
init_zod();
|
|
49264
49689
|
|
|
49265
49690
|
// src/tools/errors.ts
|
|
49266
49691
|
init_dist2();
|
|
@@ -49332,6 +49757,44 @@ function makeLimitedStopAt(horizon, wanted, limit) {
|
|
|
49332
49757
|
};
|
|
49333
49758
|
}
|
|
49334
49759
|
|
|
49760
|
+
// src/tools/chat-search.ts
|
|
49761
|
+
init_dist2();
|
|
49762
|
+
var SEARCH_FETCH_MESSAGES = 50;
|
|
49763
|
+
var SEARCH_CONCURRENCY = 4;
|
|
49764
|
+
var SNIPPET_CHARS = 200;
|
|
49765
|
+
var SNIPPET_LEAD = 60;
|
|
49766
|
+
async function searchRecentMessages(chatsvc, me, ids, query) {
|
|
49767
|
+
const q = query.trim().toLowerCase();
|
|
49768
|
+
const hits = /* @__PURE__ */ new Map();
|
|
49769
|
+
let failed = 0;
|
|
49770
|
+
if (q === "") return { hits, failed };
|
|
49771
|
+
await mapWithConcurrency([...new Set(ids)], SEARCH_CONCURRENCY, async (id) => {
|
|
49772
|
+
let messages;
|
|
49773
|
+
try {
|
|
49774
|
+
messages = await chatsvc.getMessages(id, { max: SEARCH_FETCH_MESSAGES, pageSize: SEARCH_FETCH_MESSAGES });
|
|
49775
|
+
} catch {
|
|
49776
|
+
failed++;
|
|
49777
|
+
return;
|
|
49778
|
+
}
|
|
49779
|
+
for (const m of messages) {
|
|
49780
|
+
if (!isUserMessage(m)) continue;
|
|
49781
|
+
const n = normaliseMessage(m, me);
|
|
49782
|
+
if (n.deleted) continue;
|
|
49783
|
+
const at = n.text.toLowerCase().indexOf(q);
|
|
49784
|
+
if (at === -1) continue;
|
|
49785
|
+
hits.set(id, { id: n.id, time: n.time, sender: n.sender, text: snippet(n.text, at) });
|
|
49786
|
+
return;
|
|
49787
|
+
}
|
|
49788
|
+
});
|
|
49789
|
+
return { hits, failed };
|
|
49790
|
+
}
|
|
49791
|
+
function snippet(text, at) {
|
|
49792
|
+
if (text.length <= SNIPPET_CHARS) return text;
|
|
49793
|
+
const start = Math.max(0, Math.min(at - SNIPPET_LEAD, text.length - SNIPPET_CHARS));
|
|
49794
|
+
const end = start + SNIPPET_CHARS;
|
|
49795
|
+
return `${start > 0 ? "\u2026" : ""}${text.slice(start, end)}${end < text.length ? "\u2026" : ""}`;
|
|
49796
|
+
}
|
|
49797
|
+
|
|
49335
49798
|
// src/tools/listing.ts
|
|
49336
49799
|
init_zod();
|
|
49337
49800
|
|
|
@@ -49355,10 +49818,31 @@ function olderUnreadReport(olderSkipped, sinceDays) {
|
|
|
49355
49818
|
return {
|
|
49356
49819
|
older_unread_skipped: olderSkipped,
|
|
49357
49820
|
...olderSkipped > 0 ? {
|
|
49358
|
-
older_unread_hint: `${olderSkipped} conversation${olderSkipped === 1 ? "" : "s"} with unread activity older than ${days} days ${olderSkipped === 1 ? "was" : "were"} left out; pass a larger since_days (max ${MAX_SINCE_DAYS}) to include ${olderSkipped === 1 ? "it" : "them"}.`
|
|
49821
|
+
older_unread_hint: `${olderSkipped} conversation${olderSkipped === 1 ? "" : "s"} with unread activity older than ${days} days ${olderSkipped === 1 ? "was" : "were"} left out; pass a larger since_days (max ${MAX_SINCE_DAYS}) to include ${olderSkipped === 1 ? "it" : "them"}, or older_unread: true to list ${olderSkipped === 1 ? "it" : "them"}.`
|
|
49359
49822
|
} : {}
|
|
49360
49823
|
};
|
|
49361
49824
|
}
|
|
49825
|
+
function olderUnreadArg(scope = "") {
|
|
49826
|
+
return external_exports.boolean().optional().describe(
|
|
49827
|
+
`${scope}Also list the conversations since_days left out, as older_unread_conversations: id, kind, title, team (a channel's), lastActivity and, where its messages were read, unread_count. One never read (nothing at all happened inside the window) carries unread_count_known: false instead and is not read now \u2014 its news may be only system events. Default false.`
|
|
49828
|
+
);
|
|
49829
|
+
}
|
|
49830
|
+
function olderUnreadConversations(older, titled) {
|
|
49831
|
+
if (older.length === 0) return {};
|
|
49832
|
+
const rows = older.map(({ read }, i) => {
|
|
49833
|
+
const s = titled[i];
|
|
49834
|
+
return {
|
|
49835
|
+
id: s.id,
|
|
49836
|
+
kind: s.kind,
|
|
49837
|
+
title: s.title,
|
|
49838
|
+
...s.team !== void 0 ? { team: s.team } : {},
|
|
49839
|
+
...s.lastActivity !== void 0 ? { lastActivity: s.lastActivity } : {},
|
|
49840
|
+
...read === void 0 ? { unread_count_known: false } : { unread_count: read.messages.length, ...read.truncated ? { unread_count_exact: false } : {} }
|
|
49841
|
+
};
|
|
49842
|
+
});
|
|
49843
|
+
rows.sort((a, b) => (b.lastActivity ?? "").localeCompare(a.lastActivity ?? ""));
|
|
49844
|
+
return { older_unread_conversations: rows };
|
|
49845
|
+
}
|
|
49362
49846
|
function isUnreachable(err) {
|
|
49363
49847
|
const status = errorStatusOf(err);
|
|
49364
49848
|
return status === 404 || status === 403;
|
|
@@ -49381,25 +49865,27 @@ async function confirmUnreadCandidates(chatsvc, raw, me, candidates, opts) {
|
|
|
49381
49865
|
const conv = byId.get(summary.id) ?? { id: summary.id };
|
|
49382
49866
|
const newest = newestActivityMs(conv);
|
|
49383
49867
|
if (newest !== void 0 && newest < since) return { kind: "older" };
|
|
49384
|
-
const
|
|
49868
|
+
const cursors = opts.cursors ?? {};
|
|
49869
|
+
const cursor = Object.hasOwn(cursors, summary.id) ? Number(cursors[summary.id]) : 0;
|
|
49870
|
+
const horizon = Math.max(readHorizon(conv), Number.isFinite(cursor) ? cursor : 0);
|
|
49385
49871
|
try {
|
|
49386
49872
|
return { kind: "read", read: await readUnread(chatsvc, summary.id, horizon, me, opts) };
|
|
49387
49873
|
} catch (error62) {
|
|
49388
49874
|
return isUnreachable(error62) ? { kind: "unreachable" } : { kind: "failed", error: error62 };
|
|
49389
49875
|
}
|
|
49390
49876
|
});
|
|
49391
|
-
const outcome = { confirmed: [], skippedUnreachable: 0,
|
|
49877
|
+
const outcome = { confirmed: [], skippedUnreachable: 0, older: [], failed: [] };
|
|
49392
49878
|
let anyRead = false;
|
|
49393
49879
|
results.forEach((r, i) => {
|
|
49394
49880
|
const summary = candidates[i];
|
|
49395
|
-
if (r.kind === "older") outcome.
|
|
49881
|
+
if (r.kind === "older") outcome.older.push({ summary });
|
|
49396
49882
|
else if (r.kind === "unreachable") outcome.skippedUnreachable++;
|
|
49397
49883
|
else if (r.kind === "failed") outcome.failed.push({ summary, error: r.error });
|
|
49398
49884
|
else {
|
|
49399
49885
|
anyRead = true;
|
|
49400
49886
|
const newestUnread = r.read.messages[0];
|
|
49401
49887
|
if (newestUnread === void 0) return;
|
|
49402
|
-
if (Number(newestUnread.id) < since) outcome.
|
|
49888
|
+
if (Number(newestUnread.id) < since) outcome.older.push({ summary, read: r.read });
|
|
49403
49889
|
else outcome.confirmed.push({ summary, read: r.read });
|
|
49404
49890
|
}
|
|
49405
49891
|
});
|
|
@@ -49507,9 +49993,16 @@ async function enrichTitles(chatsvc, raw, me, rows) {
|
|
|
49507
49993
|
}
|
|
49508
49994
|
|
|
49509
49995
|
// src/tools/listing.ts
|
|
49996
|
+
function activeWithin(s, since, until) {
|
|
49997
|
+
if (since === void 0 && until === void 0) return true;
|
|
49998
|
+
const t = s.lastActivity === void 0 ? Number.NaN : Date.parse(s.lastActivity);
|
|
49999
|
+
if (Number.isNaN(t)) return false;
|
|
50000
|
+
return (since === void 0 || t >= since) && (until === void 0 || t <= until);
|
|
50001
|
+
}
|
|
49510
50002
|
var listSinceDaysArg = sinceDaysArg("With unread_only: ");
|
|
50003
|
+
var listOlderUnreadArg = olderUnreadArg("With unread_only: ");
|
|
49511
50004
|
var unreadOnlyArg = external_exports.boolean().optional().describe(
|
|
49512
|
-
"Only return conversations with a real message (not a call recording or other system event) the user has not read yet, each with its unread_count (default false). Exact: every candidate is confirmed by reading its messages past the read marker. Never marks anything read."
|
|
50005
|
+
"Only return conversations with a real message (not a call recording or other system event) the user has not read yet, each with its unread_count (default false). Exact: every candidate is confirmed by reading its messages past the read marker. Never marks anything read (teams_mark_read does)."
|
|
49513
50006
|
);
|
|
49514
50007
|
var UNREAD_HINT_DESCRIPTION = "Without unread_only, unread is only a hint from the listing (unread_confirmed: false): it can flag a conversation whose only news is a call recording or other system event. For an exact answer use unread_only (confirmed rows carry unread_confirmed: true and unread_count) or teams_get_unread.";
|
|
49515
50008
|
var CONFIRM_LIMIT = 50;
|
|
@@ -49523,6 +50016,7 @@ function isUnreadCandidateFor(s, includeHidden) {
|
|
|
49523
50016
|
function queryArg(what) {
|
|
49524
50017
|
return external_exports.string().min(1).optional().describe(`Case-insensitive substring of the ${what}, or an exact conversation id.`);
|
|
49525
50018
|
}
|
|
50019
|
+
var MATCH_REASON_DESCRIPTION = `With a query, each row carries match_reason \u2014 the first of "id" (exact id), "title", "team", "participant" (an untitled chat's participant) or "message" (what was said, not what the conversation is called) that applies.`;
|
|
49526
50020
|
var GROUP_TITLE_DESCRIPTION = 'A group chat with no topic is titled "Group chat: " and up to three of its recent senders other than the user, most recent first ("; " between names, "+N" for more), and carries every such recent sender as participants; it is "(untitled group chat)" when no one else wrote recently. A 1:1 is titled by the other person, who is its one participant; it is "(1:1 chat)" when they wrote nothing recently.';
|
|
49527
50021
|
function favoritesFirst(a, b) {
|
|
49528
50022
|
const rank = (s) => s.favorite ? 0 : s.pinned ? 1 : 2;
|
|
@@ -49531,10 +50025,23 @@ function favoritesFirst(a, b) {
|
|
|
49531
50025
|
var FAVORITES_DESCRIPTION = "Conversations the user marked a favorite or pinned in Teams carry favorite: true / pinned: true and, without unread_only, are listed first (favorites, then pinned); unread_only keeps its usual order.";
|
|
49532
50026
|
async function listSummaries(chatsvc, filter) {
|
|
49533
50027
|
const [raw, me] = await Promise.all([chatsvc.listConversations(), chatsvc.meMri()]);
|
|
49534
|
-
let rows = raw.map((c) => conversationSummary(c, me, raw)).filter((s) => filter.kinds.includes(s.kind));
|
|
50028
|
+
let rows = raw.map((c) => conversationSummary(c, me, raw)).filter((s) => filter.kinds.includes(s.kind) && activeWithin(s, filter.activeSince, filter.activeUntil));
|
|
49535
50029
|
if (filter.unread_only) rows = rows.filter((s) => isUnreadCandidateFor(s, filter.include_hidden));
|
|
49536
|
-
|
|
49537
|
-
if (
|
|
50030
|
+
let searched = {};
|
|
50031
|
+
if (filter.query !== void 0) {
|
|
50032
|
+
const titled = await enrichTitles(chatsvc, raw, me, rows);
|
|
50033
|
+
const matched = matchConversations(titled, filter.query, { messages: true });
|
|
50034
|
+
if (filter.searchMessages && !namesOne(matched, filter.query)) {
|
|
50035
|
+
const found = await searchUnmatched(chatsvc, me, titled, matched, filter.query);
|
|
50036
|
+
rows = found.rows;
|
|
50037
|
+
if (found.failed > 0) searched = { messages_not_searched: found.failed };
|
|
50038
|
+
} else {
|
|
50039
|
+
rows = matched;
|
|
50040
|
+
}
|
|
50041
|
+
}
|
|
50042
|
+
if (!filter.unread_only) {
|
|
50043
|
+
return { rows, ...searched, retitle: async (kept) => ({ rows: await enrichTitles(chatsvc, raw, me, kept) }) };
|
|
50044
|
+
}
|
|
49538
50045
|
const outcome = await confirmUnreadCandidates(chatsvc, raw, me, rows, {
|
|
49539
50046
|
limit: CONFIRM_LIMIT,
|
|
49540
50047
|
maxRaw: CONFIRM_MAX_RAW,
|
|
@@ -49554,6 +50061,8 @@ async function listSummaries(chatsvc, filter) {
|
|
|
49554
50061
|
return { rows: rows2, ...errs2 ? { errors: errs2 } : {} };
|
|
49555
50062
|
};
|
|
49556
50063
|
const errs = errors(failedSummaries);
|
|
50064
|
+
const listedOlder = filter.older_unread ? outcome.older : [];
|
|
50065
|
+
const olderTitled = await enrichTitles(chatsvc, raw, me, listedOlder.map((o) => o.summary));
|
|
49557
50066
|
return {
|
|
49558
50067
|
retitle,
|
|
49559
50068
|
rows: outcome.confirmed.map(({ summary, read }) => ({
|
|
@@ -49562,42 +50071,109 @@ async function listSummaries(chatsvc, filter) {
|
|
|
49562
50071
|
...read.truncated ? { unread_count_exact: false } : {}
|
|
49563
50072
|
})),
|
|
49564
50073
|
skipped_unreachable: outcome.skippedUnreachable,
|
|
49565
|
-
...olderUnreadReport(outcome.
|
|
49566
|
-
...
|
|
50074
|
+
...olderUnreadReport(outcome.older.length, filter.since_days),
|
|
50075
|
+
...olderUnreadConversations(listedOlder, olderTitled),
|
|
50076
|
+
...errs ? { errors: errs } : {},
|
|
50077
|
+
...searched
|
|
49567
50078
|
};
|
|
49568
50079
|
}
|
|
50080
|
+
function namesOne(matched, query) {
|
|
50081
|
+
if (matched.length !== 1) return false;
|
|
50082
|
+
const [m] = matched;
|
|
50083
|
+
return m.match_reason === "id" || m.id === SELF_CHAT && SELF_CHAT_ALIASES.has(query.trim().toLowerCase());
|
|
50084
|
+
}
|
|
50085
|
+
async function searchUnmatched(chatsvc, me, all, matched, query) {
|
|
50086
|
+
const byId = new Map(matched.map((m) => [m.id, m]));
|
|
50087
|
+
const rest = all.filter((s) => !byId.has(s.id));
|
|
50088
|
+
const { hits, failed } = await searchRecentMessages(chatsvc, me, rest.map((s) => s.id), query);
|
|
50089
|
+
const rows = all.flatMap((s) => {
|
|
50090
|
+
const named = byId.get(s.id);
|
|
50091
|
+
if (named !== void 0) return [named];
|
|
50092
|
+
const hit = hits.get(s.id);
|
|
50093
|
+
return hit !== void 0 ? [{ ...s, match_reason: "message", matched_message: hit }] : [];
|
|
50094
|
+
});
|
|
50095
|
+
return { rows, failed };
|
|
50096
|
+
}
|
|
49569
50097
|
|
|
49570
50098
|
// src/tools/chat.ts
|
|
49571
50099
|
var MAX_CHATS = 500;
|
|
49572
50100
|
function byLastActivityDesc(a, b) {
|
|
49573
50101
|
return (b.lastActivity ?? "").localeCompare(a.lastActivity ?? "");
|
|
49574
50102
|
}
|
|
50103
|
+
function byTitle(a, b) {
|
|
50104
|
+
return a.title.localeCompare(b.title, void 0, { sensitivity: "base" });
|
|
50105
|
+
}
|
|
50106
|
+
function activityBoundArg(name, side) {
|
|
50107
|
+
return external_exports.string().refine((s) => !Number.isNaN(Date.parse(s)), { message: `${name} must be an ISO 8601 date-time` }).optional().describe(
|
|
50108
|
+
`Only return chats whose last activity is ${side} this ISO 8601 date-time (e.g. 2026-09-21T09:00:00Z). A chat with no last activity is left out whenever since or until is given.`
|
|
50109
|
+
);
|
|
50110
|
+
}
|
|
50111
|
+
var SORTS = ["activity", "activity_only", "title"];
|
|
50112
|
+
var sortArg = external_exports.enum(SORTS).optional().describe(
|
|
50113
|
+
'Order of the result, and so which chats limit keeps: "activity" (default) \u2014 favorites, then pinned, then most recent activity (unread_only: most recent activity); "activity_only" \u2014 most recent activity first, ignoring favorites and pinned; "title" \u2014 alphabetical by title, case-insensitive (titles every untitled chat in the listing first, so it reads more).'
|
|
50114
|
+
);
|
|
50115
|
+
var searchMessagesArg = external_exports.boolean().optional().describe(
|
|
50116
|
+
`With query: also read the last ${SEARCH_FETCH_MESSAGES} messages of every chat no name or last-message preview matched, and return the chats where one of them contains the query (match_reason "message", with the newest such message as matched_message: id, time, sender, text). Reads one page per chat, four at a time, so it is slower on a large listing; narrow it with since / until or unread_only. Default false.`
|
|
50117
|
+
);
|
|
50118
|
+
function sortChats(rows, sort, unreadOnly) {
|
|
50119
|
+
rows.sort(byLastActivityDesc);
|
|
50120
|
+
if (sort === "title") rows.sort(byTitle);
|
|
50121
|
+
else if (sort === "activity" && !unreadOnly) rows.sort(favoritesFirst);
|
|
50122
|
+
}
|
|
49575
50123
|
function registerChatTools(server, { chatsvc }) {
|
|
49576
50124
|
server.registerTool(
|
|
49577
50125
|
"teams_list_chats",
|
|
49578
50126
|
{
|
|
49579
50127
|
title: "List Teams chats",
|
|
49580
|
-
description: "List every chat the signed-in user is in \u2014 1:1s, group chats and meeting chats, not just the ones visible in the Teams sidebar \u2014 favorites and pinned first, then most recent activity. Each has an id, kind (oneOnOne / group / meeting, or self for the user's own 48:notes self-chat), title, unread hint, last-activity time (ISO 8601), and a last-message preview and sender. " + GROUP_TITLE_DESCRIPTION + " query also matches those participant names. " + FAVORITES_DESCRIPTION + " Pass an id (or the title) to teams_read_conversation to read the messages. Use unread_only to find chats with messages the user has not read, exactly as Teams counts them: each candidate is confirmed by reading its messages past the read marker, so a call recording, transcript or other system event never makes a chat unread. By default unread_only keeps only chats whose newest unread message is from the last 14 days (since_days widens it); older ones are counted in older_unread_skipped,
|
|
50128
|
+
description: "List every chat the signed-in user is in \u2014 1:1s, group chats and meeting chats, not just the ones visible in the Teams sidebar \u2014 favorites and pinned first, then most recent activity. Each has an id, kind (oneOnOne / group / meeting, or self for the user's own 48:notes self-chat), title, unread hint, last-activity time (ISO 8601), and a last-message preview and sender. " + GROUP_TITLE_DESCRIPTION + " query also matches those participant names, and the last-message preview. " + MATCH_REASON_DESCRIPTION + " search_messages extends the match to each chat's recent messages. " + FAVORITES_DESCRIPTION + " Pass an id (or the title) to teams_read_conversation to read the messages. Use unread_only to find chats with messages the user has not read, exactly as Teams counts them: each candidate is confirmed by reading its messages past the read marker, so a call recording, transcript or other system event never makes a chat unread. By default unread_only keeps only chats whose newest unread message is from the last 14 days (since_days widens it); older ones are counted in older_unread_skipped, and older_unread: true lists them in older_unread_conversations (unread_count only for those already read). A chat the user muted in Teams carries muted: true. " + UNREAD_HINT_DESCRIPTION + " since / until (ISO 8601 date-times) keep chats whose last activity falls in that window; sort picks the order: activity (default, as above), activity_only (most recent first, ignoring favorites and pinned) or title (alphabetical, case-insensitive). Listing never marks anything read (teams_mark_read does). Channels are listed by teams_list_teams_and_channels instead." + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
49581
50129
|
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
49582
50130
|
inputSchema: {
|
|
49583
50131
|
unread_only: unreadOnlyArg,
|
|
49584
50132
|
since_days: listSinceDaysArg,
|
|
49585
|
-
|
|
49586
|
-
|
|
50133
|
+
older_unread: listOlderUnreadArg,
|
|
50134
|
+
query: queryArg("chat title, an untitled chat's participant names or the last-message preview"),
|
|
50135
|
+
search_messages: searchMessagesArg,
|
|
50136
|
+
since: activityBoundArg("since", "at or after"),
|
|
50137
|
+
until: activityBoundArg("until", "at or before"),
|
|
50138
|
+
sort: sortArg,
|
|
50139
|
+
limit: limitArg(MAX_CHATS, "chats", "the head of the sort order kept")
|
|
49587
50140
|
}
|
|
49588
50141
|
},
|
|
49589
|
-
async ({ unread_only, since_days, query, limit }) => {
|
|
50142
|
+
async ({ unread_only, since_days, older_unread, query, search_messages, since, until, sort = "activity", limit }) => {
|
|
50143
|
+
if (older_unread && !unread_only) {
|
|
50144
|
+
throw new McpToolError("older_unread lists what unread_only left out, so it needs unread_only.", {
|
|
50145
|
+
hint: "Pass unread_only: true with older_unread, or drop older_unread."
|
|
50146
|
+
});
|
|
50147
|
+
}
|
|
50148
|
+
if (search_messages && query === void 0) {
|
|
50149
|
+
throw new McpToolError("search_messages needs a query to search for.", {
|
|
50150
|
+
hint: "Pass the text to find as query, or drop search_messages."
|
|
50151
|
+
});
|
|
50152
|
+
}
|
|
50153
|
+
const activeSince = since !== void 0 ? Date.parse(since) : void 0;
|
|
50154
|
+
const activeUntil = until !== void 0 ? Date.parse(until) : void 0;
|
|
50155
|
+
if (activeSince !== void 0 && activeUntil !== void 0 && activeSince > activeUntil) {
|
|
50156
|
+
throw new McpToolError(`since (${since}) is after until (${until}).`, {
|
|
50157
|
+
hint: "Pass a since at or before until."
|
|
50158
|
+
});
|
|
50159
|
+
}
|
|
49590
50160
|
try {
|
|
49591
50161
|
const { rows, retitle, errors: _untitledErrors, ...unreadInfo } = await listSummaries(chatsvc, {
|
|
49592
50162
|
kinds: ["group", "meeting", "oneOnOne", "self"],
|
|
49593
50163
|
unread_only,
|
|
49594
50164
|
since_days,
|
|
49595
|
-
|
|
50165
|
+
older_unread,
|
|
50166
|
+
query,
|
|
50167
|
+
searchMessages: search_messages,
|
|
50168
|
+
activeSince,
|
|
50169
|
+
activeUntil
|
|
49596
50170
|
});
|
|
49597
|
-
|
|
49598
|
-
|
|
49599
|
-
|
|
49600
|
-
const
|
|
50171
|
+
const titledFirst = sort === "title" ? await retitle(rows) : void 0;
|
|
50172
|
+
const ordered = titledFirst?.rows ?? rows;
|
|
50173
|
+
sortChats(ordered, sort, unread_only);
|
|
50174
|
+
const which = sort === "title" || sort === "activity" && !unread_only ? "first" : "most recent";
|
|
50175
|
+
const { rows: kept, truncated } = trimRows(ordered, limit, "start", MAX_CHATS, which);
|
|
50176
|
+
const { rows: chats, errors } = titledFirst ? { rows: kept, errors: titledFirst.errors } : await retitle(kept);
|
|
49601
50177
|
return untrustedResult2({ chats, ...unreadInfo, ...errors ? { errors } : {}, ...truncated ? { truncated } : {} });
|
|
49602
50178
|
} catch (err) {
|
|
49603
50179
|
throw wrapApiError(err, "list chats");
|
|
@@ -49624,13 +50200,13 @@ function registerChannelTools(server, { chatsvc }) {
|
|
|
49624
50200
|
"teams_list_teams_and_channels",
|
|
49625
50201
|
{
|
|
49626
50202
|
title: "List Teams channels",
|
|
49627
|
-
description: "List every channel the signed-in user is in, across all their teams, sorted by team name then channel title. Each has an id, title, team (when Teams makes it determinable), unread hint, last-activity time (ISO 8601), and a last-message preview and sender. Channels the user has hidden in Teams are listed after the rest with hidden: true. Pass an id (or the channel name) to teams_read_conversation to read its posts and replies. Use unread_only for channels with real posts the user has not read, each confirmed by reading past the read marker (a channel that is gone or no longer readable is skipped and counted in skipped_unreachable); hidden channels are left out of it unless include_hidden is set, as Teams shows them no badge. By default unread_only keeps only channels whose newest unread post is from the last 14 days (since_days widens it); older ones are counted in older_unread_skipped, not listed. " + UNREAD_HINT_DESCRIPTION + " Listing never marks anything read. query matches the channel title or
|
|
50203
|
+
description: "List every channel the signed-in user is in, across all their teams, sorted by team name then channel title. Each has an id, title, team (when Teams makes it determinable), unread hint, last-activity time (ISO 8601), and a last-message preview and sender. Channels the user has hidden in Teams are listed after the rest with hidden: true. Pass an id (or the channel name) to teams_read_conversation to read its posts and replies. Use unread_only for channels with real posts the user has not read, each confirmed by reading past the read marker (a channel that is gone or no longer readable is skipped and counted in skipped_unreachable); hidden channels are left out of it unless include_hidden is set, as Teams shows them no badge. By default unread_only keeps only channels whose newest unread post is from the last 14 days (since_days widens it); older ones are counted in older_unread_skipped, not listed. " + UNREAD_HINT_DESCRIPTION + " Listing never marks anything read (teams_mark_read does). query matches the channel title, team name or last-message preview. " + MATCH_REASON_DESCRIPTION + " " + FAVORITES_DESCRIPTION + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
49628
50204
|
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
49629
50205
|
inputSchema: {
|
|
49630
50206
|
unread_only: unreadOnlyArg,
|
|
49631
50207
|
since_days: listSinceDaysArg,
|
|
49632
50208
|
include_hidden: includeHiddenArg,
|
|
49633
|
-
query: queryArg("channel title or
|
|
50209
|
+
query: queryArg("channel title, team name or last-message preview"),
|
|
49634
50210
|
limit: limitArg(MAX_CHANNELS, "channels", "favorites and pinned first, then by team and title, kept")
|
|
49635
50211
|
}
|
|
49636
50212
|
},
|
|
@@ -49657,21 +50233,62 @@ function registerChannelTools(server, { chatsvc }) {
|
|
|
49657
50233
|
// src/tools/conversation.ts
|
|
49658
50234
|
init_zod();
|
|
49659
50235
|
init_dist2();
|
|
49660
|
-
|
|
49661
|
-
|
|
49662
|
-
|
|
49663
|
-
|
|
49664
|
-
|
|
49665
|
-
|
|
49666
|
-
|
|
50236
|
+
|
|
50237
|
+
// src/tools/timezone.ts
|
|
50238
|
+
init_zod();
|
|
50239
|
+
init_dist2();
|
|
50240
|
+
var TIME_ZONE_ENV = "TEAMS_TIME_ZONE";
|
|
50241
|
+
var TIME_ZONE_DESCRIPTION = "tz (an IANA time zone, e.g. America/New_York; default TEAMS_TIME_ZONE) adds time_local \u2014 ISO 8601 with its offset \u2014 next to each message's UTC time.";
|
|
50242
|
+
var tzArg = external_exports.string().refine(isTimeZone, { message: "tz must be an IANA time zone such as America/New_York" }).optional().describe(
|
|
50243
|
+
`IANA time zone (e.g. America/New_York, Europe/London, UTC) to add each message's time_local in, ISO 8601 with its offset; time stays UTC. Defaults to ${TIME_ZONE_ENV} when set, else no time_local.`
|
|
50244
|
+
);
|
|
50245
|
+
function resolveTimeZone(tz, env = process.env) {
|
|
50246
|
+
if (tz !== void 0) return tz;
|
|
50247
|
+
const fromEnv = readEnvVar(TIME_ZONE_ENV, { env });
|
|
50248
|
+
if (fromEnv === void 0) return void 0;
|
|
50249
|
+
if (!isTimeZone(fromEnv)) {
|
|
50250
|
+
throw new McpToolError(`${TIME_ZONE_ENV} "${fromEnv}" is not an IANA time zone.`, {
|
|
50251
|
+
hint: `Set ${TIME_ZONE_ENV} to a name such as America/New_York, or unset it.`
|
|
50252
|
+
});
|
|
50253
|
+
}
|
|
50254
|
+
return fromEnv;
|
|
50255
|
+
}
|
|
50256
|
+
|
|
50257
|
+
// src/tools/cursor.ts
|
|
50258
|
+
init_zod();
|
|
50259
|
+
var messageId = external_exports.string().regex(/^\d+$/, {
|
|
50260
|
+
message: 'a message id is decimal digits, e.g. "1760000000000" \u2014 a teams_get_changes next_cursor is not one; pass its per-conversation after_message_id instead'
|
|
50261
|
+
});
|
|
50262
|
+
var afterMessageIdArg = messageId.optional().describe(
|
|
50263
|
+
"Only return messages newer than this message id (a previous teams_read_conversation next_cursor, a teams_get_changes row's after_message_id, or any message id); the read stops at the first message at or before it. Not teams_get_changes' next_cursor, which is a time token."
|
|
50264
|
+
);
|
|
50265
|
+
var cursorsArg = external_exports.record(external_exports.string(), messageId).optional().describe(
|
|
50266
|
+
"Per-conversation cursors, { conversationId: messageId } (a previous result's next_cursors): each conversation's read stops at the later of its read marker and its cursor, so only unread messages newer than the cursor come back, and a conversation with none past it is left out."
|
|
50267
|
+
);
|
|
50268
|
+
var CURSOR_NO_CACHE_DESCRIPTION = "fetched_at is when this call read Teams: the server holds no cache, so every call reads live (there is nothing to refresh). ";
|
|
50269
|
+
function newestId(messages) {
|
|
50270
|
+
let newest;
|
|
50271
|
+
for (const m of messages) if (newest === void 0 || Number(m.id) > Number(newest)) newest = m.id;
|
|
50272
|
+
return newest;
|
|
49667
50273
|
}
|
|
49668
|
-
|
|
50274
|
+
|
|
50275
|
+
// src/tools/format.ts
|
|
50276
|
+
init_zod();
|
|
50277
|
+
var READ_FORMATS = ["full", "compact", "summary"];
|
|
50278
|
+
var formatArg = external_exports.enum(READ_FORMATS).optional().describe(
|
|
50279
|
+
"How much to return (default full). full: every message field. compact: each message only id, time, time_local, sender, text (and subject when set) \u2014 no reactions, attachments or edited/deleted flags. summary: no messages, just per conversation its counts, newest message time and, for a channel, each thread's root id, subject, reply count and newest time."
|
|
50280
|
+
);
|
|
50281
|
+
var FORMAT_DESCRIPTION = 'format "compact" trims each message to id, time, sender and text, and the conversation to id, kind and title; format "summary" returns no messages, only message_count, newest_time and, for a channel, threads of { root_id, subject, reply_count, newest_time } \u2014 every format keeps the conversation id. ';
|
|
50282
|
+
var NO_ROOTS = /* @__PURE__ */ new Map();
|
|
50283
|
+
function groupThreads(messages, roots = NO_ROOTS) {
|
|
49669
50284
|
const byRoot = /* @__PURE__ */ new Map();
|
|
49670
50285
|
for (const m of messages) {
|
|
49671
50286
|
const rootId = m.replyTo ?? m.id;
|
|
49672
50287
|
let thread = byRoot.get(rootId);
|
|
49673
50288
|
if (thread === void 0) {
|
|
49674
|
-
|
|
50289
|
+
const outside = roots.get(rootId);
|
|
50290
|
+
const root = outside !== void 0 ? { ...outside, outside_window: true } : { id: rootId, missing: true };
|
|
50291
|
+
thread = { root, replies: [] };
|
|
49675
50292
|
byRoot.set(rootId, thread);
|
|
49676
50293
|
}
|
|
49677
50294
|
if (m.replyTo === void 0) thread.root = m;
|
|
@@ -49679,13 +50296,509 @@ function groupThreads(messages) {
|
|
|
49679
50296
|
}
|
|
49680
50297
|
return [...byRoot.values()];
|
|
49681
50298
|
}
|
|
50299
|
+
function compactMessage(m) {
|
|
50300
|
+
return {
|
|
50301
|
+
id: m.id,
|
|
50302
|
+
time: m.time,
|
|
50303
|
+
...m.time_local !== void 0 ? { time_local: m.time_local } : {},
|
|
50304
|
+
sender: m.sender,
|
|
50305
|
+
text: m.text,
|
|
50306
|
+
...m.subject !== void 0 ? { subject: m.subject } : {}
|
|
50307
|
+
};
|
|
50308
|
+
}
|
|
50309
|
+
var isMissing = (root) => "missing" in root;
|
|
50310
|
+
var isOutside = (root) => "outside_window" in root;
|
|
50311
|
+
function newestTime(messages) {
|
|
50312
|
+
const newest = messages.at(-1);
|
|
50313
|
+
if (newest === void 0) return {};
|
|
50314
|
+
return {
|
|
50315
|
+
newest_time: newest.time,
|
|
50316
|
+
...newest.time_local !== void 0 ? { newest_time_local: newest.time_local } : {}
|
|
50317
|
+
};
|
|
50318
|
+
}
|
|
50319
|
+
function summariseThread({ root, replies }) {
|
|
50320
|
+
const subject = isMissing(root) ? void 0 : root.subject;
|
|
50321
|
+
const inWindow = !isMissing(root) && !isOutside(root);
|
|
50322
|
+
return {
|
|
50323
|
+
root_id: root.id,
|
|
50324
|
+
...isMissing(root) ? { root_missing: true } : {},
|
|
50325
|
+
...isOutside(root) ? { root_outside_window: true } : {},
|
|
50326
|
+
...subject !== void 0 ? { subject } : {},
|
|
50327
|
+
reply_count: replies.length,
|
|
50328
|
+
// Replies are oldest first and newer than their root, so the last reply is the newest.
|
|
50329
|
+
...newestTime(inWindow ? [root, ...replies] : replies)
|
|
50330
|
+
};
|
|
50331
|
+
}
|
|
50332
|
+
function compactRoot(root) {
|
|
50333
|
+
if (isMissing(root)) return root;
|
|
50334
|
+
return { ...compactMessage(root), ...isOutside(root) ? { outside_window: true } : {} };
|
|
50335
|
+
}
|
|
50336
|
+
function formatConversation(summary, format) {
|
|
50337
|
+
if (format === "full") return summary;
|
|
50338
|
+
const { id, kind, title, team } = summary;
|
|
50339
|
+
return { id, kind, title, ...team !== void 0 ? { team } : {} };
|
|
50340
|
+
}
|
|
50341
|
+
function formatBody(kind, messages, format, roots = NO_ROOTS) {
|
|
50342
|
+
const channel = kind === "channel";
|
|
50343
|
+
if (format === "summary") {
|
|
50344
|
+
return {
|
|
50345
|
+
message_count: messages.length,
|
|
50346
|
+
...newestTime(messages),
|
|
50347
|
+
...channel ? { threads: groupThreads(messages, roots).map(summariseThread) } : {}
|
|
50348
|
+
};
|
|
50349
|
+
}
|
|
50350
|
+
if (format === "compact") {
|
|
50351
|
+
if (!channel) return { messages: messages.map(compactMessage) };
|
|
50352
|
+
return {
|
|
50353
|
+
threads: groupThreads(messages, roots).map(({ root, replies }) => ({
|
|
50354
|
+
root: compactRoot(root),
|
|
50355
|
+
replies: replies.map(compactMessage)
|
|
50356
|
+
}))
|
|
50357
|
+
};
|
|
50358
|
+
}
|
|
50359
|
+
return channel ? { threads: groupThreads(messages, roots) } : { messages: [...messages] };
|
|
50360
|
+
}
|
|
50361
|
+
|
|
50362
|
+
// src/tools/roots.ts
|
|
50363
|
+
init_dist2();
|
|
50364
|
+
var MAX_ROOT_FETCHES = 25;
|
|
50365
|
+
var ROOT_FETCH_CONCURRENCY = 5;
|
|
50366
|
+
function rootBudget() {
|
|
50367
|
+
return { remaining: MAX_ROOT_FETCHES };
|
|
50368
|
+
}
|
|
50369
|
+
function outsideRootIds(messages) {
|
|
50370
|
+
const held = new Set(messages.map((m) => m.id));
|
|
50371
|
+
const ids = /* @__PURE__ */ new Set();
|
|
50372
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
50373
|
+
const root = messages[i].replyTo;
|
|
50374
|
+
if (root !== void 0 && !held.has(root)) ids.add(root);
|
|
50375
|
+
}
|
|
50376
|
+
return [...ids];
|
|
50377
|
+
}
|
|
50378
|
+
async function fetchOutsideRoots(chatsvc, conversationId, messages, me, { budget, timeZone }) {
|
|
50379
|
+
const wanted = outsideRootIds(messages);
|
|
50380
|
+
const ids = wanted.slice(0, Math.max(0, budget.remaining));
|
|
50381
|
+
budget.remaining -= ids.length;
|
|
50382
|
+
const roots = /* @__PURE__ */ new Map();
|
|
50383
|
+
if (ids.length === 0) return roots;
|
|
50384
|
+
const fetched = await mapWithConcurrency(ids, ROOT_FETCH_CONCURRENCY, async (id) => {
|
|
50385
|
+
try {
|
|
50386
|
+
return await chatsvc.getMessage(conversationId, id);
|
|
50387
|
+
} catch {
|
|
50388
|
+
return void 0;
|
|
50389
|
+
}
|
|
50390
|
+
});
|
|
50391
|
+
fetched.forEach((raw, i) => {
|
|
50392
|
+
if (raw === void 0 || raw.id !== ids[i]) return;
|
|
50393
|
+
const root = normaliseMessage(raw, me, { timeZone });
|
|
50394
|
+
if (root.replyTo === void 0) roots.set(root.id, root);
|
|
50395
|
+
});
|
|
50396
|
+
return roots;
|
|
50397
|
+
}
|
|
50398
|
+
|
|
50399
|
+
// src/tools/markread.ts
|
|
50400
|
+
init_zod();
|
|
50401
|
+
init_dist2();
|
|
50402
|
+
|
|
50403
|
+
// src/compose.ts
|
|
50404
|
+
init_dist2();
|
|
50405
|
+
import { randomInt } from "node:crypto";
|
|
50406
|
+
var HTML_ESCAPES = {
|
|
50407
|
+
"&": "&",
|
|
50408
|
+
"<": "<",
|
|
50409
|
+
">": ">",
|
|
50410
|
+
'"': """,
|
|
50411
|
+
"'": "'"
|
|
50412
|
+
};
|
|
50413
|
+
function escapeHtml(s) {
|
|
50414
|
+
return s.replace(/[&<>"']/g, (c) => HTML_ESCAPES[c]);
|
|
50415
|
+
}
|
|
50416
|
+
var NAMED_EMOJI = {
|
|
50417
|
+
like: { title: "Like", char: "\u{1F44D}" },
|
|
50418
|
+
heart: { title: "Heart", char: "\u2764\uFE0F" },
|
|
50419
|
+
laugh: { title: "Laugh", char: "\u{1F606}" },
|
|
50420
|
+
surprised: { title: "Surprised", char: "\u{1F62E}" },
|
|
50421
|
+
sad: { title: "Sad", char: "\u{1F622}" },
|
|
50422
|
+
angry: { title: "Angry", char: "\u{1F621}" },
|
|
50423
|
+
smile: { title: "Smile", char: "\u{1F642}" },
|
|
50424
|
+
wink: { title: "Wink", char: "\u{1F609}" },
|
|
50425
|
+
cool: { title: "Cool", char: "\u{1F60E}" },
|
|
50426
|
+
hearteyes: { title: "Heart eyes", char: "\u{1F60D}" },
|
|
50427
|
+
fire: { title: "Fire", char: "\u{1F525}" },
|
|
50428
|
+
party: { title: "Party", char: "\u{1F389}" }
|
|
50429
|
+
};
|
|
50430
|
+
var UNICODE_KEY = /^([0-9a-f]{4,6}(?:-[0-9a-f]{4,6})*)_([a-z0-9]+)$/;
|
|
50431
|
+
function emojiSpan(key) {
|
|
50432
|
+
let title;
|
|
50433
|
+
let char;
|
|
50434
|
+
const named = NAMED_EMOJI[key];
|
|
50435
|
+
if (named !== void 0) {
|
|
50436
|
+
({ title, char } = named);
|
|
50437
|
+
} else {
|
|
50438
|
+
const m = UNICODE_KEY.exec(key);
|
|
50439
|
+
if (m === null) return void 0;
|
|
50440
|
+
const points = m[1].split("-").map((h) => parseInt(h, 16));
|
|
50441
|
+
if (points.some((p) => p > 1114111)) return void 0;
|
|
50442
|
+
char = String.fromCodePoint(...points);
|
|
50443
|
+
title = m[2];
|
|
50444
|
+
}
|
|
50445
|
+
const t = escapeHtml(title);
|
|
50446
|
+
return `<span contenteditable="false" title="${t}" type="(${key})" class="animated-emoticon-20-${key}" itemscope><img itemscope itemtype="http://schema.skype.com/Emoji" itemid="${key}" src="https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v2/assets/emoticons/${key}/default/20_f.png" title="${t}" alt="${escapeHtml(char)}" style="width:20px;height:20px;"></span>`;
|
|
50447
|
+
}
|
|
50448
|
+
function renderPlain(text) {
|
|
50449
|
+
let out = "";
|
|
50450
|
+
let at = 0;
|
|
50451
|
+
const shortcode = /:([a-z0-9_-]+):/g;
|
|
50452
|
+
for (let m = shortcode.exec(text); m !== null; m = shortcode.exec(text)) {
|
|
50453
|
+
const span = emojiSpan(m[1]);
|
|
50454
|
+
if (span === void 0) {
|
|
50455
|
+
shortcode.lastIndex = m.index + m[0].length - 1;
|
|
50456
|
+
continue;
|
|
50457
|
+
}
|
|
50458
|
+
out += escapeLines(text.slice(at, m.index)) + span;
|
|
50459
|
+
at = shortcode.lastIndex;
|
|
50460
|
+
}
|
|
50461
|
+
return out + escapeLines(text.slice(at));
|
|
50462
|
+
}
|
|
50463
|
+
var escapeLines = (s) => escapeHtml(s).replace(/\r?\n/g, "<br>");
|
|
50464
|
+
var isWordChar = (c) => c !== void 0 && /[\p{L}\p{N}_]/u.test(c);
|
|
50465
|
+
function locate(text, name, taken) {
|
|
50466
|
+
const free = (s, e) => taken.every(([ts, te]) => e <= ts || s >= te);
|
|
50467
|
+
const find = (needle, ci, wordStart) => {
|
|
50468
|
+
const hay = ci ? text.toLowerCase() : text;
|
|
50469
|
+
const n = ci ? needle.toLowerCase() : needle;
|
|
50470
|
+
for (let i = hay.indexOf(n); i >= 0; i = hay.indexOf(n, i + 1)) {
|
|
50471
|
+
const end = i + n.length;
|
|
50472
|
+
if (isWordChar(text[end]) || wordStart && isWordChar(text[i - 1])) continue;
|
|
50473
|
+
if (free(i, end)) return [i, end];
|
|
50474
|
+
}
|
|
50475
|
+
return void 0;
|
|
50476
|
+
};
|
|
50477
|
+
return find(`@${name}`, false, false) ?? find(`@${name}`, true, false) ?? find(name, true, true);
|
|
50478
|
+
}
|
|
50479
|
+
function renderMessageHtml(text, mentions) {
|
|
50480
|
+
const placed = [];
|
|
50481
|
+
for (const m of mentions) {
|
|
50482
|
+
const range = locate(
|
|
50483
|
+
text,
|
|
50484
|
+
m.text,
|
|
50485
|
+
placed.map((p) => [p.start, p.end])
|
|
50486
|
+
);
|
|
50487
|
+
if (range === void 0) {
|
|
50488
|
+
throw new McpToolError(`The mention "${m.text}" does not appear in the text.`, {
|
|
50489
|
+
hint: "name_in_text must be written in text (as @name or name) once per mention."
|
|
50490
|
+
});
|
|
50491
|
+
}
|
|
50492
|
+
placed.push({ start: range[0], end: range[1], mri: m.mri });
|
|
50493
|
+
}
|
|
50494
|
+
placed.sort((a, b) => a.start - b.start);
|
|
50495
|
+
let html = "";
|
|
50496
|
+
let at = 0;
|
|
50497
|
+
const out = [];
|
|
50498
|
+
placed.forEach((p, n) => {
|
|
50499
|
+
const shown = text.slice(p.start, p.end).replace(/^@/, "");
|
|
50500
|
+
html += renderPlain(text.slice(at, p.start));
|
|
50501
|
+
html += `<span itemscope itemtype="http://schema.skype.com/Mention" itemid="${n}">${escapeHtml(shown)}</span>`;
|
|
50502
|
+
out.push({ itemid: String(n), mri: p.mri, displayName: shown });
|
|
50503
|
+
at = p.end;
|
|
50504
|
+
});
|
|
50505
|
+
html += renderPlain(text.slice(at));
|
|
50506
|
+
return { html: `<p>${html}</p>`, mentions: out };
|
|
50507
|
+
}
|
|
50508
|
+
function mentionsProperty(mentions) {
|
|
50509
|
+
return JSON.stringify(
|
|
50510
|
+
mentions.map((m) => ({
|
|
50511
|
+
"@type": "http://schema.skype.com/Mention",
|
|
50512
|
+
itemid: m.itemid,
|
|
50513
|
+
mri: m.mri,
|
|
50514
|
+
mentionType: "person",
|
|
50515
|
+
displayName: m.displayName
|
|
50516
|
+
}))
|
|
50517
|
+
);
|
|
50518
|
+
}
|
|
50519
|
+
var QUOTE_PREVIEW_CHARS = 200;
|
|
50520
|
+
function clipText(s, max, ellipsis = "") {
|
|
50521
|
+
if (s.length <= max) return s;
|
|
50522
|
+
let end = Math.max(0, max - ellipsis.length);
|
|
50523
|
+
const last = s.charCodeAt(end - 1);
|
|
50524
|
+
if (last >= 55296 && last <= 56319) end -= 1;
|
|
50525
|
+
return s.slice(0, end) + ellipsis;
|
|
50526
|
+
}
|
|
50527
|
+
function quoteHtml(q) {
|
|
50528
|
+
const preview = clipText(q.text, QUOTE_PREVIEW_CHARS, "\u2026");
|
|
50529
|
+
const id = escapeHtml(q.id);
|
|
50530
|
+
return `<blockquote itemscope itemtype="http://schema.skype.com/Reply" itemid="${id}"><strong itemprop="mri" itemid="${escapeHtml(q.senderMri)}">${escapeHtml(q.senderName)}</strong><span itemprop="time" itemid="${id}"></span><p itemprop="preview">${escapeHtml(preview)}</p></blockquote>`;
|
|
50531
|
+
}
|
|
50532
|
+
function qtdMsgsProperty(q) {
|
|
50533
|
+
return JSON.stringify([{ messageId: q.id, sender: q.senderMri, time: Number(q.id) }]);
|
|
50534
|
+
}
|
|
50535
|
+
function newClientMessageId() {
|
|
50536
|
+
let id = String(randomInt(1, 10));
|
|
50537
|
+
for (let i = 0; i < 18; i++) id += String(randomInt(0, 10));
|
|
50538
|
+
return id;
|
|
50539
|
+
}
|
|
50540
|
+
function buildSendBody(i) {
|
|
50541
|
+
const time3 = i.now.toISOString();
|
|
50542
|
+
return {
|
|
50543
|
+
id: "-1",
|
|
50544
|
+
type: "Message",
|
|
50545
|
+
conversationid: i.conversationId,
|
|
50546
|
+
conversationLink: `blah/${i.conversationId}`,
|
|
50547
|
+
from: i.meMri,
|
|
50548
|
+
fromUserId: i.meMri,
|
|
50549
|
+
composetime: time3,
|
|
50550
|
+
originalarrivaltime: time3,
|
|
50551
|
+
content: i.content,
|
|
50552
|
+
messagetype: "RichText/Html",
|
|
50553
|
+
contenttype: "Text",
|
|
50554
|
+
imdisplayname: i.meName,
|
|
50555
|
+
clientmessageid: i.clientmessageid,
|
|
50556
|
+
callId: "",
|
|
50557
|
+
state: 0,
|
|
50558
|
+
version: "0",
|
|
50559
|
+
amsreferences: [],
|
|
50560
|
+
properties: {
|
|
50561
|
+
importance: "",
|
|
50562
|
+
subject: "",
|
|
50563
|
+
title: "",
|
|
50564
|
+
cards: "[]",
|
|
50565
|
+
links: "[]",
|
|
50566
|
+
mentions: i.mentions ?? "[]",
|
|
50567
|
+
onbehalfof: null,
|
|
50568
|
+
files: "[]",
|
|
50569
|
+
policyViolation: null,
|
|
50570
|
+
formatVariant: "TEAMS",
|
|
50571
|
+
...i.qtdMsgs !== void 0 ? { qtdMsgs: i.qtdMsgs } : {}
|
|
50572
|
+
},
|
|
50573
|
+
crossPostChannels: []
|
|
50574
|
+
};
|
|
50575
|
+
}
|
|
50576
|
+
|
|
50577
|
+
// src/tools/markread.ts
|
|
50578
|
+
var TOOL = "teams_mark_read";
|
|
50579
|
+
var NEWEST_PAGE = 50;
|
|
50580
|
+
var PREVIEW_CHARS2 = 200;
|
|
50581
|
+
var MARK_CONCURRENCY = 4;
|
|
50582
|
+
var markReadArg = external_exports.boolean().optional().describe(
|
|
50583
|
+
'After the read, also mark it read in Teams: move the read marker of each conversation returned up to the newest message returned (default false \u2014 the read leaves the unread badges alone). Never moves a marker backwards, and never past an unread message the caller did not receive: a conversation whose read was cut short is left as it was (marked_read: { skipped, hint }). Not allowed with format "summary", which returns no message text. A write, so it asks the user to confirm first, as teams_mark_read does.'
|
|
50584
|
+
);
|
|
50585
|
+
function assertMarkReadFormat(markRead, format) {
|
|
50586
|
+
if (markRead && format === "summary") {
|
|
50587
|
+
throw new McpToolError('mark_read cannot be combined with format "summary": a summary returns no messages, so nothing would have been read.', {
|
|
50588
|
+
hint: 'Read with format "full" or "compact" to mark what is returned, or use teams_mark_read to mark a conversation read deliberately.'
|
|
50589
|
+
});
|
|
50590
|
+
}
|
|
50591
|
+
}
|
|
50592
|
+
var MARK_READ_DESCRIPTION = `By default this does NOT mark anything read \u2014 the user's Teams unread badges are unaffected; pass mark_read: true (or use teams_mark_read) to clear them. mark_read never marks a message the caller did not receive: it is refused with format "summary" (compact is fine), and a conversation whose read was cut short, leaving unread messages older than those returned, keeps its marker and reports marked_read: { skipped: "truncated" (or "since"), hint }. `;
|
|
50593
|
+
function horizonPath(conversationId) {
|
|
50594
|
+
return `/users/ME/conversations/${encodeURIComponent(conversationId)}/properties?name=consumptionhorizon`;
|
|
50595
|
+
}
|
|
50596
|
+
function newestMessageId(messages) {
|
|
50597
|
+
let best;
|
|
50598
|
+
for (const m of messages) {
|
|
50599
|
+
const n = Number(m.id);
|
|
50600
|
+
if (Number.isFinite(n) && (best === void 0 || n > Number(best))) best = m.id;
|
|
50601
|
+
}
|
|
50602
|
+
return best;
|
|
50603
|
+
}
|
|
50604
|
+
function horizonMessageId(conv) {
|
|
50605
|
+
const h = readHorizon(conv);
|
|
50606
|
+
return h > 0 ? String(h) : null;
|
|
50607
|
+
}
|
|
50608
|
+
function advancesHorizon(conv, target) {
|
|
50609
|
+
if (target === void 0) return false;
|
|
50610
|
+
const n = Number(target);
|
|
50611
|
+
return Number.isFinite(n) && n > readHorizon(conv);
|
|
50612
|
+
}
|
|
50613
|
+
async function confirmMarks(ctx, opts) {
|
|
50614
|
+
const { plans } = opts;
|
|
50615
|
+
const many = plans.length > 1;
|
|
50616
|
+
return confirmWrite(ctx, {
|
|
50617
|
+
tool: opts.tool,
|
|
50618
|
+
action: "chat.mark_read",
|
|
50619
|
+
message: "Review and confirm marking these Teams messages read:",
|
|
50620
|
+
summary: many ? `Mark ${plans.length} conversations read up to their newest returned message` : `Mark a ${plans[0].summary.kind} ${JSON.stringify(plans[0].summary.title)} read up to message ${plans[0].target}`,
|
|
50621
|
+
account: opts.me,
|
|
50622
|
+
...many ? { payload: plans.map((p) => ({ conversation: p.summary.id, up_to_message_id: p.target })) } : { target: `${plans[0].summary.id}/${plans[0].target}`, request: { method: "PUT", path: horizonPath(plans[0].summary.id) } },
|
|
50623
|
+
preview: {
|
|
50624
|
+
conversations: untrustedField(
|
|
50625
|
+
plans.map((p) => ({
|
|
50626
|
+
id: p.summary.id,
|
|
50627
|
+
title: p.summary.title,
|
|
50628
|
+
kind: p.summary.kind,
|
|
50629
|
+
previous_horizon_message_id: p.previous,
|
|
50630
|
+
up_to_message_id: p.target
|
|
50631
|
+
}))
|
|
50632
|
+
),
|
|
50633
|
+
...opts.note !== void 0 ? { note: opts.note } : {}
|
|
50634
|
+
},
|
|
50635
|
+
confirmToken: opts.confirmToken
|
|
50636
|
+
});
|
|
50637
|
+
}
|
|
50638
|
+
function unconfirmedWhy(e) {
|
|
50639
|
+
const status = outcomeUnknownStatus(e);
|
|
50640
|
+
return e.timedOut ? "it did not answer in time" : status !== void 0 ? `it answered HTTP ${status}` : "the connection dropped";
|
|
50641
|
+
}
|
|
50642
|
+
async function applyMarks(chatsvc, plans) {
|
|
50643
|
+
const results = await mapWithConcurrency(plans, MARK_CONCURRENCY, async (p) => {
|
|
50644
|
+
try {
|
|
50645
|
+
await chatsvc.setConsumptionHorizon(p.summary.id, p.target);
|
|
50646
|
+
return { marked_read: true };
|
|
50647
|
+
} catch (e) {
|
|
50648
|
+
if (e instanceof WriteOutcomeUnknownError) {
|
|
50649
|
+
return {
|
|
50650
|
+
marked_read: false,
|
|
50651
|
+
mark_read_warning: `Teams did not confirm moving the read marker (${unconfirmedWhy(e)}); it may have moved \u2014 retrying is harmless.`
|
|
50652
|
+
};
|
|
50653
|
+
}
|
|
50654
|
+
return { marked_read: false, mark_read_warning: wrapApiError(e, "mark this conversation read").message };
|
|
50655
|
+
}
|
|
50656
|
+
});
|
|
50657
|
+
return new Map(plans.map((p, i) => [p.summary.id, results[i]]));
|
|
50658
|
+
}
|
|
50659
|
+
function registerMarkReadTools(server, { chatsvc }) {
|
|
50660
|
+
server.registerTool(
|
|
50661
|
+
TOOL,
|
|
50662
|
+
{
|
|
50663
|
+
title: "Mark a Teams conversation read",
|
|
50664
|
+
description: `Mark a chat or channel read in Teams, clearing its unread badge: moves the signed-in user's read marker up to up_to_message_id (from teams_read_conversation), or by default up to the newest message in the conversation. conversation is an id or name as for teams_read_conversation; "${SELF_CHAT}" (or "notes" / "self") is the user's own notes self-chat \u2014 use it to try this tool. The marker never moves backwards: when it is already at or past the target, nothing is written and status is "already_read". Returns the conversation, previous_horizon_message_id (null if it was never opened) and new_horizon_message_id; status "unknown" means Teams did not confirm the move \u2014 retrying is harmless. teams_read_conversation and teams_get_unread can do the same after a read with mark_read. ` + CONFIRM_FLOW_SENTENCE + " The preview shows the conversation, the message the marker moves to and where it was. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
50665
|
+
annotations: toolAnnotations({ readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
50666
|
+
inputSchema: {
|
|
50667
|
+
conversation: external_exports.string().min(1).describe(
|
|
50668
|
+
`The conversation id (or "${SELF_CHAT}" \u2014 also by the name "notes" or "self" \u2014 for the self-chat), or a case-insensitive substring of the chat title, channel name, team name or an untitled chat's participant names.`
|
|
50669
|
+
),
|
|
50670
|
+
up_to_message_id: external_exports.string().min(1).optional().describe(
|
|
50671
|
+
"Mark read up to and including this message, as teams_read_conversation lists it (default: the newest message in the conversation). Messages after it stay unread."
|
|
50672
|
+
),
|
|
50673
|
+
confirmToken: confirmTokenParam
|
|
50674
|
+
}
|
|
50675
|
+
},
|
|
50676
|
+
async ({ conversation, up_to_message_id, confirmToken }, ctx) => {
|
|
50677
|
+
try {
|
|
50678
|
+
const [raw, me] = await Promise.all([chatsvc.listConversations(), chatsvc.meMri()]);
|
|
50679
|
+
const summary = await resolveListed(chatsvc, raw, me, conversation, "mark read");
|
|
50680
|
+
const conv = raw.find((c) => c.id === summary.id) ?? { id: summary.id };
|
|
50681
|
+
const previous = horizonMessageId(conv);
|
|
50682
|
+
const page = await chatsvc.getMessages(summary.id, { max: NEWEST_PAGE, pageSize: NEWEST_PAGE });
|
|
50683
|
+
let target;
|
|
50684
|
+
if (up_to_message_id !== void 0) {
|
|
50685
|
+
target = await chatsvc.getMessage(summary.id, up_to_message_id);
|
|
50686
|
+
if (target === void 0) {
|
|
50687
|
+
throw new McpToolError(`There is no message ${up_to_message_id} in this conversation to mark read up to.`, {
|
|
50688
|
+
hint: "Take message ids from teams_read_conversation, or leave up_to_message_id out to mark it all read."
|
|
50689
|
+
});
|
|
50690
|
+
}
|
|
50691
|
+
} else {
|
|
50692
|
+
const newest = newestMessageId(page);
|
|
50693
|
+
target = page.find((m) => m.id === newest);
|
|
50694
|
+
}
|
|
50695
|
+
if (!advancesHorizon(conv, target?.id)) {
|
|
50696
|
+
return untrustedResult2({
|
|
50697
|
+
status: "already_read",
|
|
50698
|
+
conversation: summary,
|
|
50699
|
+
previous_horizon_message_id: previous,
|
|
50700
|
+
new_horizon_message_id: previous,
|
|
50701
|
+
hint: target === void 0 ? "The conversation has no messages, so there is nothing to mark read." : `The read marker is already at or past message ${target.id}; it never moves backwards, so nothing was changed.`
|
|
50702
|
+
});
|
|
50703
|
+
}
|
|
50704
|
+
const to = target.id;
|
|
50705
|
+
const gate = await confirmWrite(ctx, {
|
|
50706
|
+
tool: TOOL,
|
|
50707
|
+
action: "chat.mark_read",
|
|
50708
|
+
message: "Review and confirm marking this Teams conversation read:",
|
|
50709
|
+
// The title is someone else's text: JSON-quoted so it cannot break out of its quotes.
|
|
50710
|
+
summary: `Mark ${summary.kind} ${JSON.stringify(summary.title)} read up to message ${to}`,
|
|
50711
|
+
// The signed-in user, so an approval minted under one account never marks another's chats.
|
|
50712
|
+
account: me,
|
|
50713
|
+
target: `${summary.id}/${to}`,
|
|
50714
|
+
// The client time in the body is minted when the marker moves, so it is not bound.
|
|
50715
|
+
request: { method: "PUT", path: horizonPath(summary.id) },
|
|
50716
|
+
preview: {
|
|
50717
|
+
conversation: untrustedField({ id: summary.id, title: summary.title, kind: summary.kind }),
|
|
50718
|
+
up_to_message: untrustedField({
|
|
50719
|
+
id: to,
|
|
50720
|
+
sender: target.imdisplayname?.trim() || senderMri(target.from) || "unknown",
|
|
50721
|
+
preview: clipText(htmlToText(target.content ?? ""), PREVIEW_CHARS2)
|
|
50722
|
+
}),
|
|
50723
|
+
previous_horizon_message_id: previous
|
|
50724
|
+
},
|
|
50725
|
+
confirmToken
|
|
50726
|
+
});
|
|
50727
|
+
if (gate) return gate;
|
|
50728
|
+
const stillUnread = page.some((m) => isUnread(m, Number(to), me));
|
|
50729
|
+
const after = confirmedSummary(summary, stillUnread);
|
|
50730
|
+
try {
|
|
50731
|
+
await chatsvc.setConsumptionHorizon(summary.id, to);
|
|
50732
|
+
} catch (e) {
|
|
50733
|
+
if (!(e instanceof WriteOutcomeUnknownError)) throw e;
|
|
50734
|
+
return untrustedResult2({
|
|
50735
|
+
status: "unknown",
|
|
50736
|
+
conversation: summary,
|
|
50737
|
+
previous_horizon_message_id: previous,
|
|
50738
|
+
new_horizon_message_id: to,
|
|
50739
|
+
warning: `Teams did not confirm moving the read marker (${unconfirmedWhy(e)}); it may have moved. Retrying is harmless \u2014 moving it to the same message again is one move.`
|
|
50740
|
+
});
|
|
50741
|
+
}
|
|
50742
|
+
return untrustedResult2({
|
|
50743
|
+
status: "marked_read",
|
|
50744
|
+
conversation: after,
|
|
50745
|
+
previous_horizon_message_id: previous,
|
|
50746
|
+
new_horizon_message_id: to
|
|
50747
|
+
});
|
|
50748
|
+
} catch (err) {
|
|
50749
|
+
throw wrapApiError(err, "mark the conversation read");
|
|
50750
|
+
}
|
|
50751
|
+
}
|
|
50752
|
+
);
|
|
50753
|
+
}
|
|
50754
|
+
|
|
50755
|
+
// src/tools/conversation.ts
|
|
50756
|
+
var MAX_MESSAGES = 500;
|
|
50757
|
+
var MAX_RAW_MESSAGES = 4e3;
|
|
50758
|
+
var MAX_CANDIDATES = 10;
|
|
50759
|
+
function arrivalMs(m) {
|
|
50760
|
+
const n = Number(m.id);
|
|
50761
|
+
if (Number.isFinite(n) && n > 0) return n;
|
|
50762
|
+
return Date.parse(m.originalarrivaltime ?? m.composetime ?? "");
|
|
50763
|
+
}
|
|
49682
50764
|
function confirmUnread(summary, unreadCount, exact) {
|
|
49683
50765
|
if (unreadCount > 0) return confirmedSummary(summary, true);
|
|
49684
50766
|
return exact ? confirmedSummary(summary, false) : summary;
|
|
49685
50767
|
}
|
|
49686
50768
|
function describeCandidate(s) {
|
|
49687
50769
|
const where = s.team !== void 0 ? ` in ${s.team}` : "";
|
|
49688
|
-
|
|
50770
|
+
const how = s.match_reason !== void 0 ? `, matched by ${s.match_reason}` : "";
|
|
50771
|
+
return `"${s.title}"${where} (${s.kind}, id ${s.id}${how})`;
|
|
50772
|
+
}
|
|
50773
|
+
var AmbiguousConversationError = class extends McpToolError {
|
|
50774
|
+
constructor(query, matches, verb) {
|
|
50775
|
+
const named = matches.slice(0, MAX_CANDIDATES).map(describeCandidate).join("; ");
|
|
50776
|
+
const more = matches.length > MAX_CANDIDATES ? ` (first ${MAX_CANDIDATES} shown)` : "";
|
|
50777
|
+
super(`"${query}" matches ${matches.length} conversations${more}: ${named}.`, {
|
|
50778
|
+
hint: `Pass the id of the one to ${verb} as conversation.`
|
|
50779
|
+
});
|
|
50780
|
+
this.query = query;
|
|
50781
|
+
this.matches = matches;
|
|
50782
|
+
this.name = "AmbiguousConversationError";
|
|
50783
|
+
}
|
|
50784
|
+
query;
|
|
50785
|
+
matches;
|
|
50786
|
+
};
|
|
50787
|
+
function ambiguousResult(err) {
|
|
50788
|
+
return {
|
|
50789
|
+
ambiguous: true,
|
|
50790
|
+
query: err.query,
|
|
50791
|
+
match_count: err.matches.length,
|
|
50792
|
+
candidates: err.matches.slice(0, MAX_CANDIDATES).map((s) => ({
|
|
50793
|
+
id: s.id,
|
|
50794
|
+
title: s.title,
|
|
50795
|
+
kind: s.kind,
|
|
50796
|
+
...s.team !== void 0 ? { team: s.team } : {},
|
|
50797
|
+
...s.lastActivity !== void 0 ? { lastActivity: s.lastActivity } : {},
|
|
50798
|
+
...s.match_reason !== void 0 ? { match_reason: s.match_reason } : {}
|
|
50799
|
+
})),
|
|
50800
|
+
hint: "pass one id as conversation"
|
|
50801
|
+
};
|
|
49689
50802
|
}
|
|
49690
50803
|
function resolveConversation(summaries, conversation, verb) {
|
|
49691
50804
|
const matches = matchConversations(summaries, conversation);
|
|
@@ -49694,80 +50807,199 @@ function resolveConversation(summaries, conversation, verb) {
|
|
|
49694
50807
|
hint: "List them with teams_list_chats or teams_list_teams_and_channels and pass an id."
|
|
49695
50808
|
});
|
|
49696
50809
|
}
|
|
49697
|
-
if (matches.length > 1)
|
|
49698
|
-
const named = matches.slice(0, MAX_CANDIDATES).map(describeCandidate).join("; ");
|
|
49699
|
-
const more = matches.length > MAX_CANDIDATES ? ` (first ${MAX_CANDIDATES} shown)` : "";
|
|
49700
|
-
throw new McpToolError(`"${conversation}" matches ${matches.length} conversations${more}: ${named}.`, {
|
|
49701
|
-
hint: `Pass the id of the one to ${verb} as conversation.`
|
|
49702
|
-
});
|
|
49703
|
-
}
|
|
50810
|
+
if (matches.length > 1) throw new AmbiguousConversationError(conversation, matches, verb);
|
|
49704
50811
|
return matches[0];
|
|
49705
50812
|
}
|
|
49706
|
-
|
|
50813
|
+
function listedResolver(chatsvc, raw, me, verb) {
|
|
49707
50814
|
const summaries = summariseAll(raw, me);
|
|
49708
|
-
|
|
49709
|
-
|
|
49710
|
-
|
|
50815
|
+
let titled;
|
|
50816
|
+
return async (conversation) => {
|
|
50817
|
+
if (SELF_CHAT_ALIASES.has(conversation.trim().toLowerCase())) return resolveConversation(summaries, conversation, verb);
|
|
50818
|
+
const exact = summaries.find((s) => s.id === conversation);
|
|
50819
|
+
if (exact) return resolveConversation(await enrichTitles(chatsvc, raw, me, [exact]), conversation, verb);
|
|
50820
|
+
titled ??= enrichTitles(chatsvc, raw, me, summaries);
|
|
50821
|
+
return resolveConversation(await titled, conversation, verb);
|
|
50822
|
+
};
|
|
50823
|
+
}
|
|
50824
|
+
async function resolveListed(chatsvc, raw, me, conversation, verb) {
|
|
50825
|
+
return listedResolver(chatsvc, raw, me, verb)(conversation);
|
|
50826
|
+
}
|
|
50827
|
+
var MAX_CONVERSATIONS = 20;
|
|
50828
|
+
var READ_CONCURRENCY = 4;
|
|
50829
|
+
async function readOne(chatsvc, raw, me, summary, { unreadOnly, since, afterMessageId, limit, timeZone, format, roots }) {
|
|
50830
|
+
const conv = raw.find((c) => c.id === summary.id) ?? { id: summary.id };
|
|
50831
|
+
const horizon = readHorizon(conv);
|
|
50832
|
+
const cutoff = since !== void 0 ? Date.parse(since) : void 0;
|
|
50833
|
+
const cursor = afterMessageId !== void 0 ? Number(afterMessageId) : void 0;
|
|
50834
|
+
const wanted = (m) => isUserMessage(m) && (!unreadOnly || isUnread(m, horizon, me));
|
|
50835
|
+
const limited = makeLimitedStopAt(unreadOnly ? horizon : void 0, wanted, limit);
|
|
50836
|
+
let windowCut = false;
|
|
50837
|
+
let sinceCut = false;
|
|
50838
|
+
let capped = false;
|
|
50839
|
+
let lastSeen;
|
|
50840
|
+
const stopAt = (m) => {
|
|
50841
|
+
lastSeen = Number(m.id);
|
|
50842
|
+
const atHorizon = unreadOnly && Number(m.id) <= horizon;
|
|
50843
|
+
const at = arrivalMs(m);
|
|
50844
|
+
const atCursor = cursor !== void 0 && Number(m.id) <= cursor;
|
|
50845
|
+
const atSince = cutoff !== void 0 && Number.isFinite(at) && at < cutoff;
|
|
50846
|
+
if (!atHorizon && (atCursor || atSince)) {
|
|
50847
|
+
if (Number(m.id) > horizon) {
|
|
50848
|
+
windowCut = true;
|
|
50849
|
+
if (atSince && !atCursor) sinceCut = true;
|
|
50850
|
+
}
|
|
50851
|
+
return true;
|
|
50852
|
+
}
|
|
50853
|
+
return limited.stopAt(m);
|
|
50854
|
+
};
|
|
50855
|
+
const fetched = await chatsvc.getMessages(summary.id, {
|
|
50856
|
+
stopAt,
|
|
50857
|
+
max: MAX_RAW_MESSAGES,
|
|
50858
|
+
onCapped: () => capped = true
|
|
50859
|
+
});
|
|
50860
|
+
const returned = fetched.filter(wanted);
|
|
50861
|
+
const newest = newestId(returned);
|
|
50862
|
+
const next_cursor = newest ?? afterMessageId;
|
|
50863
|
+
const messages = oldestFirst(returned).map((m) => normaliseMessage(m, me, { timeZone }));
|
|
50864
|
+
const unread_count = fetched.filter((m) => wanted(m) && isUnread(m, horizon, me)).length;
|
|
50865
|
+
const outsideRoots = summary.kind === "channel" ? await fetchOutsideRoots(chatsvc, summary.id, messages, me, { budget: roots, timeZone }) : void 0;
|
|
50866
|
+
const truncated = limited.truncated || capped;
|
|
50867
|
+
const exact = !truncated && !windowCut;
|
|
50868
|
+
const limitCut = truncated && (lastSeen === void 0 || !(lastSeen <= horizon));
|
|
50869
|
+
const skip = limitCut ? {
|
|
50870
|
+
skipped: "truncated",
|
|
50871
|
+
hint: `The read marker was left where it was: the limit cut this read, so unread messages older than those returned were not returned. Read again with a larger limit (max ${MAX_MESSAGES}) to mark it read, or use teams_mark_read to mark it all read deliberately.`
|
|
50872
|
+
} : sinceCut ? {
|
|
50873
|
+
skipped: "since",
|
|
50874
|
+
hint: "The read marker was left where it was: the since cutoff left out unread messages older than those returned. Read again with an earlier since (or without it) to mark it read, or use teams_mark_read to mark it all read deliberately."
|
|
50875
|
+
} : void 0;
|
|
50876
|
+
const result = {
|
|
50877
|
+
conversation: formatConversation(confirmUnread(summary, unread_count, exact), format),
|
|
50878
|
+
unread_count,
|
|
50879
|
+
...exact ? {} : { unread_count_scope: "window" },
|
|
50880
|
+
...formatBody(summary.kind, messages, format, outsideRoots),
|
|
50881
|
+
...truncated ? {
|
|
50882
|
+
truncated: {
|
|
50883
|
+
returned: messages.length,
|
|
50884
|
+
hint: `Only the newest ${messages.length} messages were returned; pass a larger limit (max ${MAX_MESSAGES}) or a since time to read further back.`
|
|
50885
|
+
}
|
|
50886
|
+
} : {},
|
|
50887
|
+
...next_cursor !== void 0 ? { next_cursor } : {}
|
|
50888
|
+
};
|
|
50889
|
+
return { summary, conv, newest, ...skip !== void 0 ? { skip } : {}, result };
|
|
50890
|
+
}
|
|
50891
|
+
function readError(conversation, err, id) {
|
|
50892
|
+
const e = wrapApiError(err, "read this conversation");
|
|
50893
|
+
return {
|
|
50894
|
+
conversation,
|
|
50895
|
+
...id !== void 0 ? { id } : {},
|
|
50896
|
+
error: e.message,
|
|
50897
|
+
...e.hint !== void 0 ? { hint: e.hint } : {}
|
|
50898
|
+
};
|
|
50899
|
+
}
|
|
50900
|
+
async function readMany(chatsvc, raw, me, conversations, opts) {
|
|
50901
|
+
const resolve2 = listedResolver(chatsvc, raw, me, "read");
|
|
50902
|
+
const errors = [];
|
|
50903
|
+
const slots = [];
|
|
50904
|
+
const seen = /* @__PURE__ */ new Set();
|
|
50905
|
+
for (const asked of new Set(conversations)) {
|
|
50906
|
+
try {
|
|
50907
|
+
const summary = await resolve2(asked);
|
|
50908
|
+
if (seen.has(summary.id)) continue;
|
|
50909
|
+
seen.add(summary.id);
|
|
50910
|
+
slots.push({ asked, summary });
|
|
50911
|
+
} catch (err) {
|
|
50912
|
+
if (err instanceof AmbiguousConversationError) slots.push({ ambiguous: ambiguousResult(err) });
|
|
50913
|
+
else errors.push(readError(asked, err));
|
|
50914
|
+
}
|
|
50915
|
+
}
|
|
50916
|
+
const reads = await mapWithConcurrency(slots, READ_CONCURRENCY, async (slot) => {
|
|
50917
|
+
if ("ambiguous" in slot) return { ok: true, result: slot };
|
|
50918
|
+
try {
|
|
50919
|
+
return { ok: true, result: await readOne(chatsvc, raw, me, slot.summary, opts) };
|
|
50920
|
+
} catch (err) {
|
|
50921
|
+
return { ok: false, error: readError(slot.asked, err, slot.summary.id) };
|
|
50922
|
+
}
|
|
50923
|
+
});
|
|
50924
|
+
const results = [];
|
|
50925
|
+
for (const r of reads) {
|
|
50926
|
+
if (r.ok) results.push(r.result);
|
|
50927
|
+
else errors.push(r.error);
|
|
50928
|
+
}
|
|
50929
|
+
const order = new Map(conversations.map((c, i) => [c, i]));
|
|
50930
|
+
errors.sort((a, b) => (order.get(a.conversation) ?? 0) - (order.get(b.conversation) ?? 0));
|
|
50931
|
+
return { reads: results, errors };
|
|
49711
50932
|
}
|
|
49712
50933
|
function registerConversationTools(server, { chatsvc }) {
|
|
49713
50934
|
server.registerTool(
|
|
49714
50935
|
"teams_read_conversation",
|
|
49715
50936
|
{
|
|
49716
50937
|
title: "Read a Teams chat or channel",
|
|
49717
|
-
description: `Read the messages of any chat or channel the signed-in user is in, by id (from teams_list_chats / teams_list_teams_and_channels) or by name, without opening it in Teams. "48:notes" (or the name "notes" / "self") is the user's own notes self-chat. Messages come oldest first, each with id, time (ISO 8601), sender, fromMe, text, subject, edited/deleted flags and attachments; a channel is returned as threads, each root post with its replies
|
|
49718
|
-
|
|
50938
|
+
description: `Read the messages of any chat or channel the signed-in user is in, by id (from teams_list_chats / teams_list_teams_and_channels) or by name, without opening it in Teams. "48:notes" (or the name "notes" / "self") is the user's own notes self-chat. Messages come oldest first, each with id, time (UTC, ISO 8601), sender, fromMe, text (never truncated; table cells separated by " | "), subject, edited/deleted flags and attachments; a channel is returned as threads, each root post with its replies. A root older than the window is fetched and marked outside_window: true (it is context, not counted or cursored); up to ${MAX_ROOT_FETCHES} roots are fetched per call, and any beyond that or that cannot be fetched is { id, missing: true }. unread_only returns just the messages the user has not read; since stops at a time; limit keeps the newest (truncated says when more exist; unread_count_scope "window" says unread_count only covers what limit/since/after_message_id let through). after_message_id returns only messages newer than that id; next_cursor is the newest returned message id (or after_message_id when nothing is new) \u2014 pass it back as after_message_id to read only what arrived since. after_message_id takes message-id cursors only: to read what teams_get_changes counted, pass that row's after_message_id, never teams_get_changes' next_cursor (a time token for teams_get_changes). ` + CURSOR_NO_CACHE_DESCRIPTION + FORMAT_DESCRIPTION + `conversation may also be an array of up to ${MAX_CONVERSATIONS} ids/names: the result is then { conversations: [...], errors, fetched_at }, one single-read result per conversation (the other arguments apply to each); an ambiguous name takes its place among them as the same { ambiguous: true, ... } object a single read returns, and one that cannot be resolved or read is listed in errors while the rest still come back. ` + MARK_READ_DESCRIPTION + "With mark_read the read marker of each conversation read moves up to the newest message returned (never backwards; outside_window roots do not count) and its result says marked_read; one whose limit or since cut off unread messages older than those returned is not marked (marked_read: { skipped, hint }), while a limit that cut only already-read messages does not stop it; the user confirms first \u2014 a prompt where the client supports one, otherwise the first call returns only a preview and a confirmToken, and the repeat call with it reads and marks. " + CONFIRM_INJECTION_RULE + " Attachments are listed per message (images by ref, files by name) and fetched with teams_get_attachment. A name that matches several conversations is not an error: the result is {ambiguous: true, query, match_count, candidates (up to 10, each with id, title, kind, team, lastActivity and match_reason), hint} and no messages \u2014 read again with one candidate's id. " + TIME_ZONE_DESCRIPTION + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
50939
|
+
// A write only with mark_read, but a write: it moves the user's read marker (never backwards, so a repeat is a no-op).
|
|
50940
|
+
annotations: toolAnnotations({ readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
49719
50941
|
inputSchema: {
|
|
49720
|
-
conversation: external_exports.string().min(1).describe(
|
|
49721
|
-
`The conversation id ("48:notes", "notes" or "self" for the self-chat), or a case-insensitive substring of the chat title, channel name, team name or an untitled chat's participant names.`
|
|
50942
|
+
conversation: external_exports.union([external_exports.string().min(1), external_exports.array(external_exports.string().min(1)).min(1).max(MAX_CONVERSATIONS)]).describe(
|
|
50943
|
+
`The conversation id ("48:notes", "notes" or "self" for the self-chat), or a case-insensitive substring of the chat title, channel name, team name or an untitled chat's participant names; or an array of up to ${MAX_CONVERSATIONS} of them to read several at once.`
|
|
49722
50944
|
),
|
|
49723
|
-
unread_only: external_exports.boolean().optional().describe("Only return messages the user has not read yet (default false).
|
|
50945
|
+
unread_only: external_exports.boolean().optional().describe("Only return messages the user has not read yet (default false). Does not mark them read unless mark_read is set."),
|
|
49724
50946
|
since: sinceArg,
|
|
49725
|
-
|
|
50947
|
+
after_message_id: afterMessageIdArg,
|
|
50948
|
+
limit: limitArg(MAX_MESSAGES, "messages"),
|
|
50949
|
+
tz: tzArg,
|
|
50950
|
+
format: formatArg,
|
|
50951
|
+
mark_read: markReadArg,
|
|
50952
|
+
confirmToken: confirmTokenParam
|
|
49726
50953
|
}
|
|
49727
50954
|
},
|
|
49728
|
-
async ({ conversation, unread_only, since, limit }) => {
|
|
50955
|
+
async ({ conversation, unread_only, since, after_message_id, limit, tz, format, mark_read, confirmToken }, ctx) => {
|
|
49729
50956
|
try {
|
|
50957
|
+
assertMarkReadFormat(mark_read, format);
|
|
50958
|
+
const opts = {
|
|
50959
|
+
unreadOnly: unread_only ?? false,
|
|
50960
|
+
since,
|
|
50961
|
+
afterMessageId: after_message_id,
|
|
50962
|
+
limit: limit ?? DEFAULT_LIMIT,
|
|
50963
|
+
timeZone: resolveTimeZone(tz),
|
|
50964
|
+
format: format ?? "full",
|
|
50965
|
+
roots: rootBudget()
|
|
50966
|
+
};
|
|
50967
|
+
const fetched_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
49730
50968
|
const [raw, me] = await Promise.all([chatsvc.listConversations(), chatsvc.meMri()]);
|
|
49731
|
-
const
|
|
49732
|
-
|
|
49733
|
-
|
|
49734
|
-
const cutoff = since !== void 0 ? Date.parse(since) : void 0;
|
|
49735
|
-
const wanted = (m) => isUserMessage(m) && (!unread_only || isUnread(m, horizon, me));
|
|
49736
|
-
const limited = makeLimitedStopAt(unread_only ? horizon : void 0, wanted, limit ?? DEFAULT_LIMIT);
|
|
49737
|
-
let sinceCut = false;
|
|
49738
|
-
let capped = false;
|
|
49739
|
-
const stopAt = (m) => {
|
|
49740
|
-
const atHorizon = unread_only && Number(m.id) <= horizon;
|
|
49741
|
-
const at = arrivalMs(m);
|
|
49742
|
-
if (!atHorizon && cutoff !== void 0 && Number.isFinite(at) && at < cutoff) {
|
|
49743
|
-
if (Number(m.id) > horizon) sinceCut = true;
|
|
49744
|
-
return true;
|
|
49745
|
-
}
|
|
49746
|
-
return limited.stopAt(m);
|
|
50969
|
+
const many = Array.isArray(conversation) ? await readMany(chatsvc, raw, me, conversation, opts) : {
|
|
50970
|
+
reads: [await readOne(chatsvc, raw, me, await resolveListed(chatsvc, raw, me, conversation, "read"), opts)],
|
|
50971
|
+
errors: []
|
|
49747
50972
|
};
|
|
49748
|
-
|
|
49749
|
-
|
|
49750
|
-
|
|
49751
|
-
|
|
49752
|
-
|
|
49753
|
-
|
|
49754
|
-
|
|
49755
|
-
|
|
49756
|
-
|
|
49757
|
-
|
|
49758
|
-
|
|
49759
|
-
|
|
49760
|
-
|
|
49761
|
-
|
|
49762
|
-
|
|
49763
|
-
|
|
49764
|
-
|
|
49765
|
-
|
|
49766
|
-
|
|
49767
|
-
|
|
49768
|
-
|
|
49769
|
-
|
|
50973
|
+
let marks;
|
|
50974
|
+
if (mark_read) {
|
|
50975
|
+
const plans = [];
|
|
50976
|
+
for (const read of many.reads) {
|
|
50977
|
+
if ("ambiguous" in read) continue;
|
|
50978
|
+
const { summary, conv, newest, skip } = read;
|
|
50979
|
+
if (skip === void 0 && advancesHorizon(conv, newest)) plans.push({ summary, previous: horizonMessageId(conv), target: newest });
|
|
50980
|
+
}
|
|
50981
|
+
if (plans.length > 0) {
|
|
50982
|
+
const gate = await confirmMarks(ctx, { tool: "teams_read_conversation", me, plans, confirmToken });
|
|
50983
|
+
if (gate) return gate;
|
|
50984
|
+
}
|
|
50985
|
+
marks = await applyMarks(chatsvc, plans);
|
|
50986
|
+
}
|
|
50987
|
+
const results = many.reads.map(
|
|
50988
|
+
(read) => "ambiguous" in read ? read.ambiguous : {
|
|
50989
|
+
...read.result,
|
|
50990
|
+
...marks !== void 0 ? marks.get(read.summary.id) ?? (read.skip !== void 0 && advancesHorizon(read.conv, read.newest) ? { marked_read: read.skip } : { marked_read: false }) : {}
|
|
50991
|
+
}
|
|
50992
|
+
);
|
|
50993
|
+
if (Array.isArray(conversation)) {
|
|
50994
|
+
return untrustedResult2({
|
|
50995
|
+
conversations: results,
|
|
50996
|
+
...many.errors.length > 0 ? { errors: many.errors } : {},
|
|
50997
|
+
fetched_at
|
|
50998
|
+
});
|
|
50999
|
+
}
|
|
51000
|
+
return untrustedResult2({ ...results[0], fetched_at });
|
|
49770
51001
|
} catch (err) {
|
|
51002
|
+
if (err instanceof AmbiguousConversationError) return untrustedResult2(ambiguousResult(err));
|
|
49771
51003
|
throw wrapApiError(err, "read the conversation");
|
|
49772
51004
|
}
|
|
49773
51005
|
}
|
|
@@ -49779,15 +51011,20 @@ init_zod();
|
|
|
49779
51011
|
init_dist2();
|
|
49780
51012
|
var MAX_PER_CONVERSATION = 200;
|
|
49781
51013
|
var DEFAULT_PER_CONVERSATION = 50;
|
|
49782
|
-
var
|
|
51014
|
+
var MAX_CONVERSATIONS2 = 50;
|
|
49783
51015
|
var DEFAULT_CONVERSATIONS = 20;
|
|
49784
51016
|
var MAX_RAW_MESSAGES2 = 4e3;
|
|
51017
|
+
var ROOT_CONVERSATION_CONCURRENCY = 4;
|
|
49785
51018
|
var KIND_FILTERS = {
|
|
49786
51019
|
chat: ["group", "meeting", "oneOnOne"],
|
|
49787
51020
|
channel: ["channel"],
|
|
49788
51021
|
meeting: ["meeting"],
|
|
49789
51022
|
oneOnOne: ["oneOnOne"]
|
|
49790
51023
|
};
|
|
51024
|
+
var TRUNCATED_SKIP = {
|
|
51025
|
+
skipped: "truncated",
|
|
51026
|
+
hint: `The read marker was left where it was: per_conversation_limit cut this read, so unread messages older than those returned were not returned. Read again with a larger per_conversation_limit (max ${MAX_PER_CONVERSATION}) or with teams_read_conversation (unread_only) to mark it read, or use teams_mark_read to mark it all read deliberately.`
|
|
51027
|
+
};
|
|
49791
51028
|
function byLastActivityDesc2(a, b) {
|
|
49792
51029
|
return (b.lastActivity ?? "").localeCompare(a.lastActivity ?? "");
|
|
49793
51030
|
}
|
|
@@ -49796,31 +51033,62 @@ function registerUnreadTools(server, { chatsvc }) {
|
|
|
49796
51033
|
"teams_get_unread",
|
|
49797
51034
|
{
|
|
49798
51035
|
title: "Get unread Teams messages",
|
|
49799
|
-
description:
|
|
49800
|
-
|
|
51036
|
+
description: `Get every unread message across all the chats and channels the signed-in user is in (or those matching kinds / query), grouped by conversation, most recent activity first. Each conversation comes with its summary (id, kind, title, team) and only the messages the user has not read, oldest first; a channel's are grouped as threads under their root post. A root the user already read is fetched and marked outside_window: true (it is context, not unread or counted); up to ${MAX_ROOT_FETCHES} roots are fetched per call, and any beyond that or that cannot be fetched is { id, missing: true }. Exact, as in Teams: every conversation with activity past its read marker (or never opened) is read past the marker and kept only if it holds a real message from someone else, so a call recording, transcript or other system event never makes a conversation unread. Channels the user has hidden in Teams are left out (include_hidden adds them); one that is gone or no longer readable (404/403) is skipped and counted in skipped_unreachable. Only conversations whose newest unread message is from the last 14 days are returned by default (since_days widens or narrows it); older unread conversations \u2014 typically dormant channels \u2014 are not read past their marker and are counted in older_unread_skipped; older_unread: true also lists them in older_unread_conversations (id, kind, title, team, lastActivity, and unread_count only for those already read \u2014 unread_count_known: false otherwise). Chats the user muted in Teams (muted: true) are left out too and counted in muted_skipped, without being read; include_muted adds them. Unread conversations past max_conversations are listed by id, title and unread_count in more_unread_conversations; read one with teams_read_conversation. A conversation that could not be read is listed in errors and the rest still come back. total_unread covers every unread conversation found; total_unread_exact is false when a per-conversation limit truncated or a read failed. cursors ({ conversationId: messageId }) returns only unread messages newer than each conversation's cursor (one with none is left out, and total_unread counts only those). Each returned conversation carries next_cursor, its newest returned message id; next_cursors is the cursors passed in updated with every returned conversation's next_cursor (not those only in more_unread_conversations) \u2014 pass it back as cursors to get only what is new. ` + CURSOR_NO_CACHE_DESCRIPTION + FORMAT_DESCRIPTION + MARK_READ_DESCRIPTION + 'With mark_read each conversation returned with its messages (not more_unread_conversations) has its read marker moved up to its newest unread message returned (outside_window roots do not count) and carries marked_read (false with mark_read_warning when that move failed); one per_conversation_limit cut is not marked \u2014 marked_read: { skipped: "truncated", hint }; the user confirms first \u2014 a prompt where the client supports one, otherwise the first call returns only a preview and a confirmToken, and the repeat call with it reads and marks. ' + CONFIRM_INJECTION_RULE + " " + GROUP_TITLE_DESCRIPTION + " query also matches those participant names, and the last-message preview. " + MATCH_REASON_DESCRIPTION + "Message times are UTC (ISO 8601); " + TIME_ZONE_DESCRIPTION + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
51037
|
+
// A write only with mark_read, but a write: it moves the user's read markers (never backwards, so a repeat is a no-op).
|
|
51038
|
+
annotations: toolAnnotations({ readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
49801
51039
|
inputSchema: {
|
|
49802
51040
|
kinds: external_exports.array(external_exports.enum(Object.keys(KIND_FILTERS))).min(1).optional().describe(
|
|
49803
51041
|
"Only these kinds of conversation (default all): chat = every group, meeting and 1:1 chat; channel; meeting = meeting chats only; oneOnOne = 1:1 chats only."
|
|
49804
51042
|
),
|
|
49805
51043
|
query: external_exports.string().min(1).optional().describe(
|
|
49806
|
-
"Case-insensitive substring of the chat title, channel name, team name
|
|
51044
|
+
"Case-insensitive substring of the chat title, channel name, team name, an untitled chat's participant names or the last-message preview, or an exact conversation id."
|
|
49807
51045
|
),
|
|
49808
51046
|
include_hidden: includeHiddenArg,
|
|
51047
|
+
include_muted: external_exports.boolean().optional().describe(
|
|
51048
|
+
"Also return conversations the user has muted in Teams (default false: they are left out unread and counted in muted_skipped)."
|
|
51049
|
+
),
|
|
49809
51050
|
since_days: sinceDaysArg(),
|
|
51051
|
+
older_unread: olderUnreadArg(),
|
|
49810
51052
|
per_conversation_limit: external_exports.number().int().min(1).max(MAX_PER_CONVERSATION).optional().describe(
|
|
49811
51053
|
`Maximum unread messages per conversation, newest kept (default ${DEFAULT_PER_CONVERSATION}, max ${MAX_PER_CONVERSATION}).`
|
|
49812
51054
|
),
|
|
49813
|
-
max_conversations: external_exports.number().int().min(1).max(
|
|
49814
|
-
`Maximum unread conversations returned with their messages, most recent activity first (default ${DEFAULT_CONVERSATIONS}, max ${
|
|
49815
|
-
)
|
|
51055
|
+
max_conversations: external_exports.number().int().min(1).max(MAX_CONVERSATIONS2).optional().describe(
|
|
51056
|
+
`Maximum unread conversations returned with their messages, most recent activity first (default ${DEFAULT_CONVERSATIONS}, max ${MAX_CONVERSATIONS2}); the rest are listed in more_unread_conversations.`
|
|
51057
|
+
),
|
|
51058
|
+
cursors: cursorsArg,
|
|
51059
|
+
tz: tzArg,
|
|
51060
|
+
format: formatArg,
|
|
51061
|
+
mark_read: markReadArg,
|
|
51062
|
+
confirmToken: confirmTokenParam
|
|
49816
51063
|
}
|
|
49817
51064
|
},
|
|
49818
|
-
async ({
|
|
51065
|
+
async ({
|
|
51066
|
+
kinds,
|
|
51067
|
+
query,
|
|
51068
|
+
include_hidden,
|
|
51069
|
+
include_muted,
|
|
51070
|
+
since_days,
|
|
51071
|
+
older_unread,
|
|
51072
|
+
per_conversation_limit,
|
|
51073
|
+
max_conversations,
|
|
51074
|
+
cursors,
|
|
51075
|
+
tz,
|
|
51076
|
+
format,
|
|
51077
|
+
mark_read,
|
|
51078
|
+
confirmToken
|
|
51079
|
+
}, ctx) => {
|
|
49819
51080
|
try {
|
|
51081
|
+
assertMarkReadFormat(mark_read, format);
|
|
51082
|
+
const timeZone = resolveTimeZone(tz);
|
|
51083
|
+
const fetched_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
49820
51084
|
const [raw, me] = await Promise.all([chatsvc.listConversations(), chatsvc.meMri()]);
|
|
49821
51085
|
const allowed = new Set((kinds ?? ["chat", "channel"]).flatMap((k) => KIND_FILTERS[k]));
|
|
49822
51086
|
let candidates = raw.map((c) => conversationSummary(c, me, raw)).filter((s) => allowed.has(s.kind) && isUnreadCandidateFor(s, include_hidden));
|
|
49823
|
-
if (query !== void 0) candidates = matchConversations(await enrichTitles(chatsvc, raw, me, candidates), query
|
|
51087
|
+
if (query !== void 0) candidates = matchConversations(await enrichTitles(chatsvc, raw, me, candidates), query, {
|
|
51088
|
+
messages: true
|
|
51089
|
+
});
|
|
51090
|
+
const mutedSkipped = include_muted ? 0 : candidates.filter((s) => s.muted).length;
|
|
51091
|
+
if (!include_muted) candidates = candidates.filter((s) => !s.muted);
|
|
49824
51092
|
candidates.sort(byLastActivityDesc2);
|
|
49825
51093
|
const perLimit = per_conversation_limit ?? DEFAULT_PER_CONVERSATION;
|
|
49826
51094
|
const outcome = await confirmUnreadCandidates(
|
|
@@ -49828,39 +51096,73 @@ function registerUnreadTools(server, { chatsvc }) {
|
|
|
49828
51096
|
raw,
|
|
49829
51097
|
me,
|
|
49830
51098
|
candidates,
|
|
49831
|
-
{ limit: perLimit, maxRaw: MAX_RAW_MESSAGES2, since: sinceCutoff(since_days) }
|
|
51099
|
+
{ limit: perLimit, maxRaw: MAX_RAW_MESSAGES2, since: sinceCutoff(since_days), cursors }
|
|
49832
51100
|
);
|
|
49833
|
-
const { skippedUnreachable,
|
|
51101
|
+
const { skippedUnreachable, older } = outcome;
|
|
51102
|
+
const listedOlder = older_unread ? older : [];
|
|
49834
51103
|
const retitled = await enrichTitles(chatsvc, raw, me, [
|
|
49835
51104
|
...outcome.confirmed.map((c) => c.summary),
|
|
49836
|
-
...outcome.failed.map((f) => f.summary)
|
|
51105
|
+
...outcome.failed.map((f) => f.summary),
|
|
51106
|
+
...listedOlder.map((o) => o.summary)
|
|
49837
51107
|
]);
|
|
49838
51108
|
const confirmed = outcome.confirmed.map((c, i) => ({ ...c, summary: retitled[i] }));
|
|
49839
51109
|
const failed = outcome.failed.map((f, i) => ({ ...f, summary: retitled[outcome.confirmed.length + i] }));
|
|
51110
|
+
const olderTitled = retitled.slice(outcome.confirmed.length + outcome.failed.length);
|
|
49840
51111
|
const cap = max_conversations ?? DEFAULT_CONVERSATIONS;
|
|
49841
|
-
const
|
|
49842
|
-
|
|
49843
|
-
|
|
49844
|
-
|
|
49845
|
-
|
|
49846
|
-
|
|
49847
|
-
|
|
49848
|
-
|
|
49849
|
-
|
|
49850
|
-
|
|
49851
|
-
|
|
49852
|
-
|
|
49853
|
-
|
|
49854
|
-
|
|
49855
|
-
|
|
51112
|
+
const returned = confirmed.slice(0, cap);
|
|
51113
|
+
let marks;
|
|
51114
|
+
if (mark_read) {
|
|
51115
|
+
const byId = new Map(raw.map((c) => [c.id, c]));
|
|
51116
|
+
const plans = [];
|
|
51117
|
+
for (const { summary, read } of returned) {
|
|
51118
|
+
if (read.truncated) continue;
|
|
51119
|
+
const conv = byId.get(summary.id) ?? { id: summary.id };
|
|
51120
|
+
const target = newestId(read.messages);
|
|
51121
|
+
if (advancesHorizon(conv, target)) plans.push({ summary, previous: horizonMessageId(conv), target });
|
|
51122
|
+
}
|
|
51123
|
+
if (plans.length > 0) {
|
|
51124
|
+
const gate = await confirmMarks(ctx, { tool: "teams_get_unread", me, plans, confirmToken });
|
|
51125
|
+
if (gate) return gate;
|
|
51126
|
+
}
|
|
51127
|
+
marks = await applyMarks(chatsvc, plans);
|
|
51128
|
+
}
|
|
51129
|
+
const budget = rootBudget();
|
|
51130
|
+
const shown = returned.map(({ summary, read }) => ({
|
|
51131
|
+
summary,
|
|
51132
|
+
read,
|
|
51133
|
+
messages: oldestFirst(read.messages).map((m) => normaliseMessage(m, me, { timeZone }))
|
|
51134
|
+
}));
|
|
51135
|
+
const roots = await mapWithConcurrency(
|
|
51136
|
+
shown,
|
|
51137
|
+
ROOT_CONVERSATION_CONCURRENCY,
|
|
51138
|
+
({ summary, messages }) => summary.kind === "channel" ? fetchOutsideRoots(chatsvc, summary.id, messages, me, { budget, timeZone }) : Promise.resolve(void 0)
|
|
51139
|
+
);
|
|
51140
|
+
const conversations = shown.map(({ summary, read, messages }, i) => ({
|
|
51141
|
+
conversation: formatConversation(confirmedSummary(summary, true), format ?? "full"),
|
|
51142
|
+
unread_count: messages.length,
|
|
51143
|
+
...formatBody(summary.kind, messages, format ?? "full", roots[i]),
|
|
51144
|
+
// Every confirmed read holds at least one message, so there is always a newest.
|
|
51145
|
+
next_cursor: newestId(read.messages),
|
|
51146
|
+
...read.truncated ? {
|
|
51147
|
+
truncated: {
|
|
51148
|
+
returned: messages.length,
|
|
51149
|
+
hint: `Only the newest ${messages.length} unread messages were returned; pass a larger per_conversation_limit (max ${MAX_PER_CONVERSATION}) or read the conversation with teams_read_conversation (unread_only).`
|
|
51150
|
+
}
|
|
51151
|
+
} : {},
|
|
51152
|
+
...marks !== void 0 ? marks.get(summary.id) ?? { marked_read: read.truncated ? TRUNCATED_SKIP : false } : {}
|
|
51153
|
+
}));
|
|
49856
51154
|
const rest = confirmed.slice(cap);
|
|
51155
|
+
const next_cursors = { ...cursors };
|
|
51156
|
+
for (const c of conversations) next_cursors[c.conversation.id] = c.next_cursor;
|
|
49857
51157
|
const exact = failed.length === 0 && confirmed.every((c) => !c.read.truncated);
|
|
49858
51158
|
return untrustedResult2({
|
|
49859
51159
|
total_unread: confirmed.reduce((n, c) => n + c.read.messages.length, 0),
|
|
49860
51160
|
total_unread_exact: exact,
|
|
49861
51161
|
conversations,
|
|
49862
51162
|
skipped_unreachable: skippedUnreachable,
|
|
49863
|
-
|
|
51163
|
+
muted_skipped: mutedSkipped,
|
|
51164
|
+
...olderUnreadReport(older.length, since_days),
|
|
51165
|
+
...olderUnreadConversations(listedOlder, olderTitled),
|
|
49864
51166
|
...failed.length > 0 ? {
|
|
49865
51167
|
errors: failed.map((f) => ({
|
|
49866
51168
|
conversation: f.summary,
|
|
@@ -49873,7 +51175,9 @@ function registerUnreadTools(server, { chatsvc }) {
|
|
|
49873
51175
|
title: summary.title,
|
|
49874
51176
|
unread_count: read.messages.length
|
|
49875
51177
|
}))
|
|
49876
|
-
} : {}
|
|
51178
|
+
} : {},
|
|
51179
|
+
next_cursors,
|
|
51180
|
+
fetched_at
|
|
49877
51181
|
});
|
|
49878
51182
|
} catch (err) {
|
|
49879
51183
|
throw wrapApiError(err, "get unread messages");
|
|
@@ -49882,10 +51186,181 @@ function registerUnreadTools(server, { chatsvc }) {
|
|
|
49882
51186
|
);
|
|
49883
51187
|
}
|
|
49884
51188
|
|
|
51189
|
+
// src/tools/changes.ts
|
|
51190
|
+
init_zod();
|
|
51191
|
+
init_dist2();
|
|
51192
|
+
var MAX_CONVERSATIONS3 = 200;
|
|
51193
|
+
var DEFAULT_WINDOW_MS = 864e5;
|
|
51194
|
+
var MAX_RAW_MESSAGES3 = 1e3;
|
|
51195
|
+
var PAGE_SIZE = 50;
|
|
51196
|
+
var READ_CONCURRENCY2 = 4;
|
|
51197
|
+
function encodeChangesCursor(t) {
|
|
51198
|
+
return Buffer.from(JSON.stringify({ t }), "utf8").toString("base64url");
|
|
51199
|
+
}
|
|
51200
|
+
function badCursor(cursor) {
|
|
51201
|
+
return new McpToolError(`"${cursor}" is not a changes cursor.`, {
|
|
51202
|
+
hint: "Pass a previous result's next_cursor unchanged, or an ISO 8601 time such as 2026-10-12T09:00:00Z. A message id (digits) is not a changes cursor: pass it to teams_read_conversation as after_message_id."
|
|
51203
|
+
});
|
|
51204
|
+
}
|
|
51205
|
+
function decodeChangesCursor(cursor) {
|
|
51206
|
+
if (/^[A-Za-z0-9_-]+$/.test(cursor)) {
|
|
51207
|
+
let parsed;
|
|
51208
|
+
try {
|
|
51209
|
+
parsed = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
51210
|
+
} catch {
|
|
51211
|
+
parsed = void 0;
|
|
51212
|
+
}
|
|
51213
|
+
if (parsed !== void 0) {
|
|
51214
|
+
const t2 = parsed?.t;
|
|
51215
|
+
if (typeof t2 === "number" && Number.isFinite(t2) && t2 >= 0) return t2;
|
|
51216
|
+
throw badCursor(cursor);
|
|
51217
|
+
}
|
|
51218
|
+
}
|
|
51219
|
+
const t = /^\d{4}-\d{2}-\d{2}/.test(cursor) ? Date.parse(cursor) : NaN;
|
|
51220
|
+
if (Number.isNaN(t)) throw badCursor(cursor);
|
|
51221
|
+
return t;
|
|
51222
|
+
}
|
|
51223
|
+
function changedMs(m) {
|
|
51224
|
+
const v = Number(m.version);
|
|
51225
|
+
const id = Number(m.id);
|
|
51226
|
+
return Math.max(Number.isFinite(v) ? v : 0, Number.isFinite(id) ? id : 0);
|
|
51227
|
+
}
|
|
51228
|
+
async function readChanges(chatsvc, summary, t, me) {
|
|
51229
|
+
let capped = false;
|
|
51230
|
+
const fetched = await chatsvc.getMessages(summary.id, {
|
|
51231
|
+
stopAt: (m) => changedMs(m) <= t,
|
|
51232
|
+
max: MAX_RAW_MESSAGES3,
|
|
51233
|
+
pageSize: PAGE_SIZE,
|
|
51234
|
+
onCapped: () => capped = true
|
|
51235
|
+
});
|
|
51236
|
+
const arrived = fetched.filter((m) => Number(m.id) > t);
|
|
51237
|
+
const maxSeen = arrived.reduce((n, m) => Math.max(n, Number(m.id)), 0);
|
|
51238
|
+
const fresh = arrived.filter(isUserMessage).map((m) => normaliseMessage(m, me)).filter((m) => m.deleted !== true).sort((a, b) => Number(b.id) - Number(a.id));
|
|
51239
|
+
let threads;
|
|
51240
|
+
if (summary.kind === "channel") {
|
|
51241
|
+
const byRoot = /* @__PURE__ */ new Map();
|
|
51242
|
+
for (const m of fresh) {
|
|
51243
|
+
const rootId = m.replyTo ?? m.id;
|
|
51244
|
+
let thread = byRoot.get(rootId);
|
|
51245
|
+
if (thread === void 0) byRoot.set(rootId, thread = { root_id: rootId, new_root: false, new_reply_count: 0 });
|
|
51246
|
+
if (m.replyTo === void 0) thread.new_root = true;
|
|
51247
|
+
else thread.new_reply_count++;
|
|
51248
|
+
}
|
|
51249
|
+
threads = [...byRoot.values()];
|
|
51250
|
+
}
|
|
51251
|
+
return {
|
|
51252
|
+
count: fresh.length,
|
|
51253
|
+
fromOthers: fresh.filter((m) => !m.fromMe).length,
|
|
51254
|
+
newest: fresh.length > 0 ? Number(fresh[0].id) : 0,
|
|
51255
|
+
...fresh.length > 0 ? { newestTime: fresh[0].time } : {},
|
|
51256
|
+
maxSeen,
|
|
51257
|
+
...threads !== void 0 ? { threads } : {},
|
|
51258
|
+
truncated: capped
|
|
51259
|
+
};
|
|
51260
|
+
}
|
|
51261
|
+
function registerChangesTools(server, { chatsvc }) {
|
|
51262
|
+
server.registerTool(
|
|
51263
|
+
"teams_get_changes",
|
|
51264
|
+
{
|
|
51265
|
+
title: "Get Teams conversations with new messages",
|
|
51266
|
+
description: `List the chats and channels that got new messages since a cursor, most recent first \u2014 counts, not the messages: each with its summary (id, kind, title, team), new_message_count (real messages only \u2014 call recordings and other system events, and deleted messages, are not counted), new_from_others_count, newest_time and, for a channel, threads: one { root_id, new_root, new_reply_count } per thread the new messages landed in, including a thread whose root post is older than the cursor, and after_message_id: read the messages it counted with teams_read_conversation({ conversation: <its id>, after_message_id: <its after_message_id> }). Two cursor kinds, not interchangeable: this tool's cursor/next_cursor is a time token for teams_get_changes only and is not a message id; after_message_id is a message-id cursor (ids are arrival ms, so it is the cursor time as an id) for teams_read_conversation (or teams_get_unread cursors). Without cursor it looks back 24 hours. next_cursor is an opaque token \u2014 pass it back as cursor to get only what arrived since this call (cursor also takes a plain ISO 8601 time). It is at-least-once: a conversation can come back again but none is skipped; it stays at the input time when a read failed. Use the same kinds and include_hidden with a cursor as the call that returned it. Channels hidden in Teams are left out unless include_hidden (then every hidden channel is read, since Teams stops updating their listing); one that is gone or no longer readable (404/403) is skipped and counted in skipped_unreachable; one whose read failed is listed in errors. limit caps the conversations returned; the rest are named, with their new_message_count and after_message_id, in more_conversations, and total_new_messages counts them all. A conversation with more than ${MAX_RAW_MESSAGES3} new messages is marked truncated (its count is a lower bound). ` + CURSOR_NO_CACHE_DESCRIPTION + "This does NOT mark anything read \u2014 the user's Teams unread badges are unaffected. " + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
51267
|
+
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
51268
|
+
inputSchema: {
|
|
51269
|
+
cursor: external_exports.string().min(1).optional().describe(
|
|
51270
|
+
"A previous teams_get_changes result's next_cursor, or an ISO 8601 time (e.g. 2026-10-12T09:00:00Z): only messages that arrived after it count. Default: 24 hours ago. Not a message id, and not teams_read_conversation's next_cursor."
|
|
51271
|
+
),
|
|
51272
|
+
kinds: external_exports.array(external_exports.enum(Object.keys(KIND_FILTERS))).min(1).optional().describe(
|
|
51273
|
+
"Only these kinds of conversation (default all): chat = every group, meeting and 1:1 chat; channel; meeting = meeting chats only; oneOnOne = 1:1 chats only."
|
|
51274
|
+
),
|
|
51275
|
+
include_hidden: includeHiddenArg.describe(
|
|
51276
|
+
"Also include channels the user has hidden in Teams (default false: Teams shows them nowhere)."
|
|
51277
|
+
),
|
|
51278
|
+
limit: limitArg(MAX_CONVERSATIONS3, "conversations", "most recent activity first kept")
|
|
51279
|
+
}
|
|
51280
|
+
},
|
|
51281
|
+
async ({ cursor, kinds, include_hidden, limit }) => {
|
|
51282
|
+
try {
|
|
51283
|
+
const t = cursor !== void 0 ? decodeChangesCursor(cursor) : Date.now() - DEFAULT_WINDOW_MS;
|
|
51284
|
+
const fetched_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
51285
|
+
const [raw, me] = await Promise.all([chatsvc.listConversations(), chatsvc.meMri()]);
|
|
51286
|
+
const allowed = new Set((kinds ?? ["chat", "channel"]).flatMap((k) => KIND_FILTERS[k]));
|
|
51287
|
+
const lastChange = new Map(raw.map((c) => [c.id, lastChangeMs(c)]));
|
|
51288
|
+
const candidates = raw.map((c) => conversationSummary(c, me, raw)).filter((s) => allowed.has(s.kind)).filter((s) => s.hidden === true ? include_hidden === true : (lastChange.get(s.id) ?? 0) > t);
|
|
51289
|
+
const results = await mapWithConcurrency(candidates, READ_CONCURRENCY2, async (summary) => {
|
|
51290
|
+
try {
|
|
51291
|
+
return { kind: "read", read: await readChanges(chatsvc, summary, t, me) };
|
|
51292
|
+
} catch (error62) {
|
|
51293
|
+
return isUnreachable(error62) ? { kind: "unreachable" } : { kind: "failed", error: error62 };
|
|
51294
|
+
}
|
|
51295
|
+
});
|
|
51296
|
+
let skipped_unreachable = 0;
|
|
51297
|
+
let maxSeen = t;
|
|
51298
|
+
let anyRead = false;
|
|
51299
|
+
const changed = [];
|
|
51300
|
+
const failed = [];
|
|
51301
|
+
results.forEach((r, i) => {
|
|
51302
|
+
if (r.kind === "unreachable") skipped_unreachable++;
|
|
51303
|
+
else if (r.kind === "failed") failed.push({ summary: candidates[i], error: r.error });
|
|
51304
|
+
else {
|
|
51305
|
+
anyRead = true;
|
|
51306
|
+
maxSeen = Math.max(maxSeen, r.read.maxSeen);
|
|
51307
|
+
if (r.read.count > 0) changed.push({ summary: candidates[i], read: r.read });
|
|
51308
|
+
}
|
|
51309
|
+
});
|
|
51310
|
+
if (failed.length > 0 && !anyRead) throw failed[0].error;
|
|
51311
|
+
changed.sort((a, b) => b.read.newest - a.read.newest);
|
|
51312
|
+
const listed = Math.max(t, ...[...lastChange.values()].map((n) => n ?? 0));
|
|
51313
|
+
const next = failed.length > 0 ? t : Math.min(maxSeen, listed);
|
|
51314
|
+
const cap = limit ?? DEFAULT_LIMIT;
|
|
51315
|
+
const shown = changed.slice(0, cap);
|
|
51316
|
+
const rest = changed.slice(cap);
|
|
51317
|
+
const titled = await enrichTitles(chatsvc, raw, me, [
|
|
51318
|
+
...shown.map((c) => c.summary),
|
|
51319
|
+
...rest.map((c) => c.summary),
|
|
51320
|
+
...failed.map((f) => f.summary)
|
|
51321
|
+
]);
|
|
51322
|
+
const after_message_id = String(Math.floor(t));
|
|
51323
|
+
const conversations = shown.map(({ read }, i) => ({
|
|
51324
|
+
conversation: titled[i],
|
|
51325
|
+
new_message_count: read.count,
|
|
51326
|
+
new_from_others_count: read.fromOthers,
|
|
51327
|
+
...read.newestTime !== void 0 ? { newest_time: read.newestTime } : {},
|
|
51328
|
+
after_message_id,
|
|
51329
|
+
...read.threads !== void 0 ? { threads: read.threads } : {},
|
|
51330
|
+
...read.truncated ? { truncated: true } : {}
|
|
51331
|
+
}));
|
|
51332
|
+
const more = rest.map(({ read }, i) => ({
|
|
51333
|
+
id: titled[shown.length + i].id,
|
|
51334
|
+
title: titled[shown.length + i].title,
|
|
51335
|
+
new_message_count: read.count,
|
|
51336
|
+
after_message_id
|
|
51337
|
+
}));
|
|
51338
|
+
const errors = failed.map((f, i) => ({
|
|
51339
|
+
conversation: titled[changed.length + i],
|
|
51340
|
+
error: wrapApiError(f.error, "read this conversation").message
|
|
51341
|
+
}));
|
|
51342
|
+
return untrustedResult2({
|
|
51343
|
+
since: new Date(t).toISOString(),
|
|
51344
|
+
total_new_messages: changed.reduce((n, c) => n + c.read.count, 0),
|
|
51345
|
+
conversations,
|
|
51346
|
+
...more.length > 0 ? { more_conversations: more } : {},
|
|
51347
|
+
skipped_unreachable,
|
|
51348
|
+
...errors.length > 0 ? { errors } : {},
|
|
51349
|
+
next_cursor: next === t && cursor !== void 0 ? cursor : encodeChangesCursor(next),
|
|
51350
|
+
next_cursor_time: new Date(next).toISOString(),
|
|
51351
|
+
fetched_at
|
|
51352
|
+
});
|
|
51353
|
+
} catch (err) {
|
|
51354
|
+
throw wrapApiError(err, "get changed conversations");
|
|
51355
|
+
}
|
|
51356
|
+
}
|
|
51357
|
+
);
|
|
51358
|
+
}
|
|
51359
|
+
|
|
49885
51360
|
// src/tools/attachment.ts
|
|
49886
51361
|
init_zod();
|
|
49887
51362
|
init_dist2();
|
|
49888
|
-
var
|
|
51363
|
+
var MAX_RAW_MESSAGES4 = 4e3;
|
|
49889
51364
|
var MAX_FILE_BYTES = 25 * 1024 * 1024;
|
|
49890
51365
|
var FILE_HINT = "A shared file is downloaded from SharePoint and returned as its contents (an image as an image, anything else as an embedded resource). The first file from a given SharePoint host may need opening once in Teams to mint a short-lived token; a file your account cannot open comes back as metadata and its link.";
|
|
49891
51366
|
function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
@@ -49905,7 +51380,7 @@ function registerAttachmentTools(server, { chatsvc, sharepoint }) {
|
|
|
49905
51380
|
try {
|
|
49906
51381
|
const target = Number(message_id);
|
|
49907
51382
|
const stopAt = Number.isFinite(target) && target > 0 ? (m) => Number(m.id) < target : void 0;
|
|
49908
|
-
const fetched = await chatsvc.getMessages(conversation, { stopAt, max:
|
|
51383
|
+
const fetched = await chatsvc.getMessages(conversation, { stopAt, max: MAX_RAW_MESSAGES4 });
|
|
49909
51384
|
const raw = fetched.find((m) => m.id === message_id);
|
|
49910
51385
|
if (raw === void 0) {
|
|
49911
51386
|
throw new McpToolError(`Message ${message_id} was not found in conversation ${conversation}.`, {
|
|
@@ -50004,187 +51479,11 @@ function degradeHint(err, host) {
|
|
|
50004
51479
|
// src/tools/send.ts
|
|
50005
51480
|
init_zod();
|
|
50006
51481
|
init_dist2();
|
|
50007
|
-
|
|
50008
|
-
// src/compose.ts
|
|
50009
|
-
init_dist2();
|
|
50010
|
-
import { randomInt } from "node:crypto";
|
|
50011
|
-
var HTML_ESCAPES = {
|
|
50012
|
-
"&": "&",
|
|
50013
|
-
"<": "<",
|
|
50014
|
-
">": ">",
|
|
50015
|
-
'"': """,
|
|
50016
|
-
"'": "'"
|
|
50017
|
-
};
|
|
50018
|
-
function escapeHtml(s) {
|
|
50019
|
-
return s.replace(/[&<>"']/g, (c) => HTML_ESCAPES[c]);
|
|
50020
|
-
}
|
|
50021
|
-
var NAMED_EMOJI = {
|
|
50022
|
-
like: { title: "Like", char: "\u{1F44D}" },
|
|
50023
|
-
heart: { title: "Heart", char: "\u2764\uFE0F" },
|
|
50024
|
-
laugh: { title: "Laugh", char: "\u{1F606}" },
|
|
50025
|
-
surprised: { title: "Surprised", char: "\u{1F62E}" },
|
|
50026
|
-
sad: { title: "Sad", char: "\u{1F622}" },
|
|
50027
|
-
angry: { title: "Angry", char: "\u{1F621}" },
|
|
50028
|
-
smile: { title: "Smile", char: "\u{1F642}" },
|
|
50029
|
-
wink: { title: "Wink", char: "\u{1F609}" },
|
|
50030
|
-
cool: { title: "Cool", char: "\u{1F60E}" },
|
|
50031
|
-
hearteyes: { title: "Heart eyes", char: "\u{1F60D}" },
|
|
50032
|
-
fire: { title: "Fire", char: "\u{1F525}" },
|
|
50033
|
-
party: { title: "Party", char: "\u{1F389}" }
|
|
50034
|
-
};
|
|
50035
|
-
var UNICODE_KEY = /^([0-9a-f]{4,6}(?:-[0-9a-f]{4,6})*)_([a-z0-9]+)$/;
|
|
50036
|
-
function emojiSpan(key) {
|
|
50037
|
-
let title;
|
|
50038
|
-
let char;
|
|
50039
|
-
const named = NAMED_EMOJI[key];
|
|
50040
|
-
if (named !== void 0) {
|
|
50041
|
-
({ title, char } = named);
|
|
50042
|
-
} else {
|
|
50043
|
-
const m = UNICODE_KEY.exec(key);
|
|
50044
|
-
if (m === null) return void 0;
|
|
50045
|
-
const points = m[1].split("-").map((h) => parseInt(h, 16));
|
|
50046
|
-
if (points.some((p) => p > 1114111)) return void 0;
|
|
50047
|
-
char = String.fromCodePoint(...points);
|
|
50048
|
-
title = m[2];
|
|
50049
|
-
}
|
|
50050
|
-
const t = escapeHtml(title);
|
|
50051
|
-
return `<span contenteditable="false" title="${t}" type="(${key})" class="animated-emoticon-20-${key}" itemscope><img itemscope itemtype="http://schema.skype.com/Emoji" itemid="${key}" src="https://statics.teams.cdn.office.net/evergreen-assets/personal-expressions/v2/assets/emoticons/${key}/default/20_f.png" title="${t}" alt="${escapeHtml(char)}" style="width:20px;height:20px;"></span>`;
|
|
50052
|
-
}
|
|
50053
|
-
function renderPlain(text) {
|
|
50054
|
-
let out = "";
|
|
50055
|
-
let at = 0;
|
|
50056
|
-
const shortcode = /:([a-z0-9_-]+):/g;
|
|
50057
|
-
for (let m = shortcode.exec(text); m !== null; m = shortcode.exec(text)) {
|
|
50058
|
-
const span = emojiSpan(m[1]);
|
|
50059
|
-
if (span === void 0) {
|
|
50060
|
-
shortcode.lastIndex = m.index + m[0].length - 1;
|
|
50061
|
-
continue;
|
|
50062
|
-
}
|
|
50063
|
-
out += escapeLines(text.slice(at, m.index)) + span;
|
|
50064
|
-
at = shortcode.lastIndex;
|
|
50065
|
-
}
|
|
50066
|
-
return out + escapeLines(text.slice(at));
|
|
50067
|
-
}
|
|
50068
|
-
var escapeLines = (s) => escapeHtml(s).replace(/\r?\n/g, "<br>");
|
|
50069
|
-
var isWordChar = (c) => c !== void 0 && /[\p{L}\p{N}_]/u.test(c);
|
|
50070
|
-
function locate(text, name, taken) {
|
|
50071
|
-
const free = (s, e) => taken.every(([ts, te]) => e <= ts || s >= te);
|
|
50072
|
-
const find = (needle, ci, wordStart) => {
|
|
50073
|
-
const hay = ci ? text.toLowerCase() : text;
|
|
50074
|
-
const n = ci ? needle.toLowerCase() : needle;
|
|
50075
|
-
for (let i = hay.indexOf(n); i >= 0; i = hay.indexOf(n, i + 1)) {
|
|
50076
|
-
const end = i + n.length;
|
|
50077
|
-
if (isWordChar(text[end]) || wordStart && isWordChar(text[i - 1])) continue;
|
|
50078
|
-
if (free(i, end)) return [i, end];
|
|
50079
|
-
}
|
|
50080
|
-
return void 0;
|
|
50081
|
-
};
|
|
50082
|
-
return find(`@${name}`, false, false) ?? find(`@${name}`, true, false) ?? find(name, true, true);
|
|
50083
|
-
}
|
|
50084
|
-
function renderMessageHtml(text, mentions) {
|
|
50085
|
-
const placed = [];
|
|
50086
|
-
for (const m of mentions) {
|
|
50087
|
-
const range = locate(
|
|
50088
|
-
text,
|
|
50089
|
-
m.text,
|
|
50090
|
-
placed.map((p) => [p.start, p.end])
|
|
50091
|
-
);
|
|
50092
|
-
if (range === void 0) {
|
|
50093
|
-
throw new McpToolError(`The mention "${m.text}" does not appear in the text.`, {
|
|
50094
|
-
hint: "name_in_text must be written in text (as @name or name) once per mention."
|
|
50095
|
-
});
|
|
50096
|
-
}
|
|
50097
|
-
placed.push({ start: range[0], end: range[1], mri: m.mri });
|
|
50098
|
-
}
|
|
50099
|
-
placed.sort((a, b) => a.start - b.start);
|
|
50100
|
-
let html = "";
|
|
50101
|
-
let at = 0;
|
|
50102
|
-
const out = [];
|
|
50103
|
-
placed.forEach((p, n) => {
|
|
50104
|
-
const shown = text.slice(p.start, p.end).replace(/^@/, "");
|
|
50105
|
-
html += renderPlain(text.slice(at, p.start));
|
|
50106
|
-
html += `<span itemscope itemtype="http://schema.skype.com/Mention" itemid="${n}">${escapeHtml(shown)}</span>`;
|
|
50107
|
-
out.push({ itemid: String(n), mri: p.mri, displayName: shown });
|
|
50108
|
-
at = p.end;
|
|
50109
|
-
});
|
|
50110
|
-
html += renderPlain(text.slice(at));
|
|
50111
|
-
return { html: `<p>${html}</p>`, mentions: out };
|
|
50112
|
-
}
|
|
50113
|
-
function mentionsProperty(mentions) {
|
|
50114
|
-
return JSON.stringify(
|
|
50115
|
-
mentions.map((m) => ({
|
|
50116
|
-
"@type": "http://schema.skype.com/Mention",
|
|
50117
|
-
itemid: m.itemid,
|
|
50118
|
-
mri: m.mri,
|
|
50119
|
-
mentionType: "person",
|
|
50120
|
-
displayName: m.displayName
|
|
50121
|
-
}))
|
|
50122
|
-
);
|
|
50123
|
-
}
|
|
50124
|
-
var QUOTE_PREVIEW_CHARS = 200;
|
|
50125
|
-
function clipText(s, max, ellipsis = "") {
|
|
50126
|
-
if (s.length <= max) return s;
|
|
50127
|
-
let end = Math.max(0, max - ellipsis.length);
|
|
50128
|
-
const last = s.charCodeAt(end - 1);
|
|
50129
|
-
if (last >= 55296 && last <= 56319) end -= 1;
|
|
50130
|
-
return s.slice(0, end) + ellipsis;
|
|
50131
|
-
}
|
|
50132
|
-
function quoteHtml(q) {
|
|
50133
|
-
const preview = clipText(q.text, QUOTE_PREVIEW_CHARS, "\u2026");
|
|
50134
|
-
const id = escapeHtml(q.id);
|
|
50135
|
-
return `<blockquote itemscope itemtype="http://schema.skype.com/Reply" itemid="${id}"><strong itemprop="mri" itemid="${escapeHtml(q.senderMri)}">${escapeHtml(q.senderName)}</strong><span itemprop="time" itemid="${id}"></span><p itemprop="preview">${escapeHtml(preview)}</p></blockquote>`;
|
|
50136
|
-
}
|
|
50137
|
-
function qtdMsgsProperty(q) {
|
|
50138
|
-
return JSON.stringify([{ messageId: q.id, sender: q.senderMri, time: Number(q.id) }]);
|
|
50139
|
-
}
|
|
50140
|
-
function newClientMessageId() {
|
|
50141
|
-
let id = String(randomInt(1, 10));
|
|
50142
|
-
for (let i = 0; i < 18; i++) id += String(randomInt(0, 10));
|
|
50143
|
-
return id;
|
|
50144
|
-
}
|
|
50145
|
-
function buildSendBody(i) {
|
|
50146
|
-
const time3 = i.now.toISOString();
|
|
50147
|
-
return {
|
|
50148
|
-
id: "-1",
|
|
50149
|
-
type: "Message",
|
|
50150
|
-
conversationid: i.conversationId,
|
|
50151
|
-
conversationLink: `blah/${i.conversationId}`,
|
|
50152
|
-
from: i.meMri,
|
|
50153
|
-
fromUserId: i.meMri,
|
|
50154
|
-
composetime: time3,
|
|
50155
|
-
originalarrivaltime: time3,
|
|
50156
|
-
content: i.content,
|
|
50157
|
-
messagetype: "RichText/Html",
|
|
50158
|
-
contenttype: "Text",
|
|
50159
|
-
imdisplayname: i.meName,
|
|
50160
|
-
clientmessageid: i.clientmessageid,
|
|
50161
|
-
callId: "",
|
|
50162
|
-
state: 0,
|
|
50163
|
-
version: "0",
|
|
50164
|
-
amsreferences: [],
|
|
50165
|
-
properties: {
|
|
50166
|
-
importance: "",
|
|
50167
|
-
subject: "",
|
|
50168
|
-
title: "",
|
|
50169
|
-
cards: "[]",
|
|
50170
|
-
links: "[]",
|
|
50171
|
-
mentions: i.mentions ?? "[]",
|
|
50172
|
-
onbehalfof: null,
|
|
50173
|
-
files: "[]",
|
|
50174
|
-
policyViolation: null,
|
|
50175
|
-
formatVariant: "TEAMS",
|
|
50176
|
-
...i.qtdMsgs !== void 0 ? { qtdMsgs: i.qtdMsgs } : {}
|
|
50177
|
-
},
|
|
50178
|
-
crossPostChannels: []
|
|
50179
|
-
};
|
|
50180
|
-
}
|
|
50181
|
-
|
|
50182
|
-
// src/tools/send.ts
|
|
50183
|
-
var TOOL = "teams_send_message";
|
|
51482
|
+
var TOOL2 = "teams_send_message";
|
|
50184
51483
|
var RECENT_MESSAGES = 200;
|
|
50185
51484
|
var READBACK_MESSAGES = 50;
|
|
50186
51485
|
var MAX_CANDIDATES2 = 10;
|
|
50187
|
-
var
|
|
51486
|
+
var PREVIEW_CHARS3 = 200;
|
|
50188
51487
|
var MRI = /^\d+:\S+$/;
|
|
50189
51488
|
var mentionArg = external_exports.object({
|
|
50190
51489
|
name_in_text: external_exports.string().min(1).describe('How the person is named in text \u2014 its first "@name" (else "name") becomes the mention.'),
|
|
@@ -50277,7 +51576,7 @@ async function writeOrUnknown(run, conversation) {
|
|
|
50277
51576
|
}
|
|
50278
51577
|
function registerSendTools(server, { chatsvc }) {
|
|
50279
51578
|
server.registerTool(
|
|
50280
|
-
|
|
51579
|
+
TOOL2,
|
|
50281
51580
|
{
|
|
50282
51581
|
title: "Send a Teams message",
|
|
50283
51582
|
description: `Post a message as the signed-in user to any chat or channel, by id (from teams_list_chats / teams_list_teams_and_channels) or by name. text is plain text: it is escaped, newlines are kept, and :key: shortcodes (e.g. :smile:, :1f389_partypopper:) become Teams emoji. reply_to in a channel posts into that root post's thread; in a chat it quote-replies that message. quote quote-replies a message in any conversation. mentions @-mention people: name_in_text must appear in text, and person is an MRI or a display name matched among recent senders (ambiguous names are refused with the candidates). conversation "${SELF_CHAT}" (or "notes" / "self") is the user's own notes self-chat \u2014 use it to try this tool without anyone else seeing; other 48: system conversations are refused. Everyone in the conversation sees the post. The result says whether the post was found again by reading the conversation back (verified); status "unknown" means Teams did not confirm it \u2014 check the conversation before retrying. ` + CONFIRM_FLOW_SENTENCE + " The preview shows the conversation and exactly what would be posted. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
@@ -50324,7 +51623,7 @@ function registerSendTools(server, { chatsvc }) {
|
|
|
50324
51623
|
const { clientmessageid: _id, composetime: _c, originalarrivaltime: _o, ...bound } = draft;
|
|
50325
51624
|
const path = `/users/ME/conversations/${encodeURIComponent(postTo)}/messages`;
|
|
50326
51625
|
const gate = await confirmWrite(ctx, {
|
|
50327
|
-
tool:
|
|
51626
|
+
tool: TOOL2,
|
|
50328
51627
|
action: "chat.send_message",
|
|
50329
51628
|
message: "Review and confirm this Teams message before it is posted:",
|
|
50330
51629
|
// The title is someone else's text: JSON-quoted so it cannot break out of its quotes.
|
|
@@ -50349,7 +51648,7 @@ function registerSendTools(server, { chatsvc }) {
|
|
|
50349
51648
|
}))
|
|
50350
51649
|
)
|
|
50351
51650
|
} : {},
|
|
50352
|
-
...q ? { quoting: untrustedField({ id: q.id, sender: q.senderName, preview: clipText(q.text,
|
|
51651
|
+
...q ? { quoting: untrustedField({ id: q.id, sender: q.senderName, preview: clipText(q.text, PREVIEW_CHARS3) }) } : {},
|
|
50353
51652
|
note: "clientmessageid and the timestamps are filled in when the message is posted."
|
|
50354
51653
|
},
|
|
50355
51654
|
confirmToken
|
|
@@ -50396,7 +51695,7 @@ function registerSendTools(server, { chatsvc }) {
|
|
|
50396
51695
|
// src/tools/react.ts
|
|
50397
51696
|
init_zod();
|
|
50398
51697
|
init_dist2();
|
|
50399
|
-
var
|
|
51698
|
+
var TOOL3 = "teams_react";
|
|
50400
51699
|
var CHECKMARK_KEY = "2705_whiteheavycheckmark";
|
|
50401
51700
|
var ALIASES = {
|
|
50402
51701
|
thumbsup: "like",
|
|
@@ -50417,7 +51716,7 @@ var ALIASES = {
|
|
|
50417
51716
|
};
|
|
50418
51717
|
var RAW_KEY = /^[a-z0-9_]+$/;
|
|
50419
51718
|
var KEY_RULE = 'Unicode-style reaction keys are "<lowercase hex code point>_<the Unicode character name, lowercased, spaces and punctuation removed>" \u2014 e.g. \u{1F4AF} 1f4af_hundredpointssymbol, \u{1F440} 1f440_eyes, \u{1F62C} 1f62c_grimacingface. Teams also keeps short names for common ones: like, heart, laugh, surprised, sad, angry, yes, no, party, fire, smile, cool, wink, hearteyes, manshrug, fistbump, handsinair.';
|
|
50420
|
-
var
|
|
51719
|
+
var PREVIEW_CHARS4 = 200;
|
|
50421
51720
|
function reactionKey(input2) {
|
|
50422
51721
|
const s = input2.trim().replace(/️/g, "").replace(/^:(.+):$/, "$1").toLowerCase();
|
|
50423
51722
|
const alias = ALIASES[s];
|
|
@@ -50433,14 +51732,14 @@ function reactionKey(input2) {
|
|
|
50433
51732
|
hint: KEY_RULE
|
|
50434
51733
|
});
|
|
50435
51734
|
}
|
|
50436
|
-
async function hasMyReaction(chatsvc, conversationId,
|
|
50437
|
-
const m = await chatsvc.getMessage(conversationId,
|
|
51735
|
+
async function hasMyReaction(chatsvc, conversationId, messageId2, key, me) {
|
|
51736
|
+
const m = await chatsvc.getMessage(conversationId, messageId2);
|
|
50438
51737
|
if (m === void 0) return void 0;
|
|
50439
51738
|
return normaliseMessage(m, me).reactions?.some((r) => r.key === key && r.byMe) ?? false;
|
|
50440
51739
|
}
|
|
50441
51740
|
function registerReactTools(server, { chatsvc }) {
|
|
50442
51741
|
server.registerTool(
|
|
50443
|
-
|
|
51742
|
+
TOOL3,
|
|
50444
51743
|
{
|
|
50445
51744
|
title: "React to a Teams message",
|
|
50446
51745
|
description: `Add (or, with remove: true, withdraw) the signed-in user's reaction on a message in any chat or channel. conversation is an id or name as for teams_read_conversation; message_id comes from teams_read_conversation. reaction is an emoji or name \u2014 thumbsup/\u{1F44D}/like, heart/\u2764\uFE0F, laugh/\u{1F606}, surprised/\u{1F62E}, sad/\u{1F622}, angry/\u{1F621}, checkmark/\u2705 \u2014 or any raw Teams reaction key (e.g. fire, 1f389_partypopper); an emoji without a known key is refused with the rule for spelling its key. conversation "${SELF_CHAT}" (or "notes" / "self") is the user's own notes self-chat \u2014 use it to try this tool. Everyone in the conversation sees the reaction. The result says whether reading the message back showed the change (verified; null when the message was not found again); status "unknown" means Teams did not confirm the change and the read-back did not show it \u2014 check the message before retrying. ` + CONFIRM_FLOW_SENTENCE + " The preview shows the conversation, the message and the reaction. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
@@ -50470,7 +51769,7 @@ function registerReactTools(server, { chatsvc }) {
|
|
|
50470
51769
|
const method = remove ? "DELETE" : "PUT";
|
|
50471
51770
|
const path = `/users/ME/conversations/${encodeURIComponent(target.id)}/messages/${encodeURIComponent(message_id)}/properties?name=emotions`;
|
|
50472
51771
|
const gate = await confirmWrite(ctx, {
|
|
50473
|
-
tool:
|
|
51772
|
+
tool: TOOL3,
|
|
50474
51773
|
action: remove ? "chat.remove_reaction" : "chat.react",
|
|
50475
51774
|
message: `Review and confirm this Teams reaction before it is ${remove ? "removed" : "added"}:`,
|
|
50476
51775
|
// The title is someone else's text: JSON-quoted so it cannot break out of its quotes.
|
|
@@ -50487,7 +51786,7 @@ function registerReactTools(server, { chatsvc }) {
|
|
|
50487
51786
|
message: untrustedField({
|
|
50488
51787
|
id: m.id,
|
|
50489
51788
|
sender: m.imdisplayname?.trim() || senderMri(m.from) || "unknown",
|
|
50490
|
-
preview: clipText(htmlToText(m.content ?? ""),
|
|
51789
|
+
preview: clipText(htmlToText(m.content ?? ""), PREVIEW_CHARS4)
|
|
50491
51790
|
}),
|
|
50492
51791
|
reaction: key,
|
|
50493
51792
|
already_reacted: already
|
|
@@ -50584,13 +51883,13 @@ function activityOf(m) {
|
|
|
50584
51883
|
}
|
|
50585
51884
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
50586
51885
|
}
|
|
50587
|
-
function
|
|
51886
|
+
function str2(v) {
|
|
50588
51887
|
if (typeof v === "string") return v === "" ? void 0 : v;
|
|
50589
51888
|
if (typeof v === "number" && Number.isFinite(v)) return String(v);
|
|
50590
51889
|
return void 0;
|
|
50591
51890
|
}
|
|
50592
51891
|
function isoOrUndefined(v) {
|
|
50593
|
-
const s =
|
|
51892
|
+
const s = str2(v);
|
|
50594
51893
|
if (s === void 0) return void 0;
|
|
50595
51894
|
const ms = /^\d+$/.test(s) ? Number(s) : Date.parse(s);
|
|
50596
51895
|
return Number.isFinite(ms) ? new Date(ms).toISOString() : void 0;
|
|
@@ -50602,25 +51901,25 @@ function activityRow(m) {
|
|
|
50602
51901
|
if (m.properties?.deletetime) return void 0;
|
|
50603
51902
|
const a = activityOf(m);
|
|
50604
51903
|
if (a === void 0) return void 0;
|
|
50605
|
-
const type =
|
|
50606
|
-
const replyChain =
|
|
51904
|
+
const type = str2(a.activityType) ?? "";
|
|
51905
|
+
const replyChain = str2(a.sourceReplyChainId);
|
|
50607
51906
|
const isread = m.properties?.isread;
|
|
50608
51907
|
return {
|
|
50609
51908
|
id: m.id,
|
|
50610
51909
|
time: isoOrUndefined(a.activityTimestamp) ?? isoOrUndefined(m.originalarrivaltime),
|
|
50611
51910
|
kind: activityKind(type),
|
|
50612
51911
|
type,
|
|
50613
|
-
subtype:
|
|
51912
|
+
subtype: str2(a.activitySubtype) ?? "",
|
|
50614
51913
|
read: isread === true || isread === "true",
|
|
50615
|
-
from:
|
|
51914
|
+
from: str2(a.sourceUserImDisplayName),
|
|
50616
51915
|
where: {
|
|
50617
|
-
conversation_id:
|
|
50618
|
-
title:
|
|
50619
|
-
type:
|
|
51916
|
+
conversation_id: str2(a.sourceThreadId),
|
|
51917
|
+
title: str2(a.sourceThreadTopic),
|
|
51918
|
+
type: str2(a.sourceThreadType)
|
|
50620
51919
|
},
|
|
50621
|
-
message_id:
|
|
51920
|
+
message_id: str2(a.sourceMessageId),
|
|
50622
51921
|
...replyChain !== void 0 ? { reply_chain_id: replyChain } : {},
|
|
50623
|
-
preview: clip(htmlToText(
|
|
51922
|
+
preview: clip(htmlToText(str2(a.messagePreview) ?? ""))
|
|
50624
51923
|
};
|
|
50625
51924
|
}
|
|
50626
51925
|
var newestFirst = (a, b) => (b.time ?? "").localeCompare(a.time ?? "");
|
|
@@ -50672,12 +51971,314 @@ function registerActivityTools(server, { chatsvc }) {
|
|
|
50672
51971
|
);
|
|
50673
51972
|
}
|
|
50674
51973
|
|
|
51974
|
+
// src/tools/search.ts
|
|
51975
|
+
init_zod();
|
|
51976
|
+
init_dist2();
|
|
51977
|
+
var DEFAULT_LIMIT2 = 25;
|
|
51978
|
+
var MAX_LIMIT = 200;
|
|
51979
|
+
var DEFAULT_SINCE_DAYS2 = 30;
|
|
51980
|
+
var DAY_MS2 = 864e5;
|
|
51981
|
+
var DEFAULT_SCANNED_CONVERSATIONS = 100;
|
|
51982
|
+
var MAX_SCANNED_CONVERSATIONS = 500;
|
|
51983
|
+
var MAX_RAW_PER_CONVERSATION = 1e3;
|
|
51984
|
+
var SUBSTRATE_PAGE_SIZE = 50;
|
|
51985
|
+
var MAX_SUBSTRATE_PAGES = 10;
|
|
51986
|
+
var MODES2 = ["auto", "substrate", "scan"];
|
|
51987
|
+
function queryTerms(query) {
|
|
51988
|
+
const terms = [];
|
|
51989
|
+
for (const [, phrase, word] of query.toLowerCase().matchAll(/"([^"]*)"|(\S+)/g)) {
|
|
51990
|
+
const t = (phrase ?? word ?? "").replace(/"/g, "").trim();
|
|
51991
|
+
if (t !== "") terms.push(t);
|
|
51992
|
+
}
|
|
51993
|
+
return terms;
|
|
51994
|
+
}
|
|
51995
|
+
function matchesQuery(text, query) {
|
|
51996
|
+
const terms = queryTerms(query);
|
|
51997
|
+
if (terms.length === 0) return false;
|
|
51998
|
+
const haystack = text.toLowerCase();
|
|
51999
|
+
return terms.every((t) => haystack.includes(t));
|
|
52000
|
+
}
|
|
52001
|
+
function hitMessage(m) {
|
|
52002
|
+
const { attachments: _a3, reactions: _r, deleted: _d, ...rest } = m;
|
|
52003
|
+
return rest;
|
|
52004
|
+
}
|
|
52005
|
+
function hitConversation(s) {
|
|
52006
|
+
return { id: s.id, title: s.title, kind: s.kind, ...s.team !== void 0 ? { team: s.team } : {} };
|
|
52007
|
+
}
|
|
52008
|
+
function registerSearchTools(server, { chatsvc, substrate }) {
|
|
52009
|
+
server.registerTool(
|
|
52010
|
+
"teams_search_messages",
|
|
52011
|
+
{
|
|
52012
|
+
title: "Search Teams messages",
|
|
52013
|
+
description: `Find messages by text across the chats and channels the signed-in user is in. Hits come newest first, each with its conversation (id, title, kind, team) and the message (id, time ISO 8601, sender, fromMe (scan only), text, subject, replyTo for a channel reply); read a hit in context with teams_read_conversation. conversation narrows to one chat or channel (id or name); from keeps messages whose sender display name contains it; since (ISO 8601) sets how far back to look (default the last ${DEFAULT_SINCE_DAYS2} days); limit caps the hits (default ${DEFAULT_LIMIT2}, max ${MAX_LIMIT}; total_hits and truncated say when there were more). source says which path answered. mode "auto" (default) uses Teams' own search (Microsoft Substrate: matched the way the Teams search box matches \u2014 words ANDed with stemming, "quoted phrases", OR \u2014 and fast; conversation and since apply to it too; its text is a plain-text preview of up to ~255 characters, marked excerpt: true, and its hits carry no fromMe) and falls back to a scan, with fallback_reason, when Substrate is unavailable or fails \u2014 its token is captured from a Teams tab the first time, so a first search may need you to run any search in the Teams search box. mode "substrate" uses only Substrate (an error rather than a fallback); mode "scan" only scans. The SCAN requires every word of query to appear in the message text (any order, ignoring case; "quoted words" match as a phrase) and reads the ${DEFAULT_SCANNED_CONVERSATIONS} (max_conversations, up to ${MAX_SCANNED_CONVERSATIONS}) most recently active conversations with activity since the cutoff back to it (channels hidden in Teams are skipped unless named); scan reports what was read and what the bounds left out \u2014 a busy window can take a while, so narrow with conversation or since when you can. Deleted messages and system events never match. This does NOT mark anything read.` + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
52014
|
+
annotations: toolAnnotations({ readOnly: true, openWorld: true }),
|
|
52015
|
+
inputSchema: {
|
|
52016
|
+
query: external_exports.string().refine((s) => queryTerms(s).length > 0, { message: "query must contain a word to search for" }).describe(
|
|
52017
|
+
'Words to find in the message text, ignoring case. Substrate (the default) matches the way the Teams search box does (words ANDed with stemming, "quoted phrases", OR). The scan requires every word to appear verbatim, any order; words in double quotes match as one phrase.'
|
|
52018
|
+
),
|
|
52019
|
+
conversation: external_exports.string().min(1).optional().describe(
|
|
52020
|
+
`Search only this chat or channel: its id ("48:notes", "notes" or "self" for the self-chat), or a case-insensitive substring of its title, channel name, team name or an untitled chat's participant names (it must name exactly one).`
|
|
52021
|
+
),
|
|
52022
|
+
from: external_exports.string().min(1).optional().describe("Only messages whose sender's display name contains this, ignoring case."),
|
|
52023
|
+
since: external_exports.string().refine((s) => !Number.isNaN(Date.parse(s)), { message: "since must be an ISO 8601 date-time" }).optional().describe(
|
|
52024
|
+
`Only messages at or after this ISO 8601 date-time (default ${DEFAULT_SINCE_DAYS2} days ago). An older since makes a scan search further back and take longer.`
|
|
52025
|
+
),
|
|
52026
|
+
limit: external_exports.number().int().min(1).max(MAX_LIMIT).optional().describe(`Maximum hits to return, newest kept (default ${DEFAULT_LIMIT2}, max ${MAX_LIMIT}).`),
|
|
52027
|
+
max_conversations: external_exports.number().int().min(1).max(MAX_SCANNED_CONVERSATIONS).optional().describe(
|
|
52028
|
+
`Scan only: most conversations to read, most recently active first (default ${DEFAULT_SCANNED_CONVERSATIONS}, max ${MAX_SCANNED_CONVERSATIONS}). More finds hits in quieter conversations but takes longer (roughly 15s per 100).`
|
|
52029
|
+
),
|
|
52030
|
+
mode: external_exports.enum(MODES2).optional().describe(
|
|
52031
|
+
`"auto" (default): Teams' own search (Substrate), falling back to a scan when it is unavailable or fails. "substrate": Substrate only, failing instead of falling back. "scan": the client-side scan only.`
|
|
52032
|
+
)
|
|
52033
|
+
}
|
|
52034
|
+
},
|
|
52035
|
+
async ({ query, conversation, from, since, limit, max_conversations, mode }) => {
|
|
52036
|
+
try {
|
|
52037
|
+
const [raw, me] = await Promise.all([chatsvc.listConversations(), chatsvc.meMri()]);
|
|
52038
|
+
const cutoff = since !== void 0 ? Date.parse(since) : Date.now() - DEFAULT_SINCE_DAYS2 * DAY_MS2;
|
|
52039
|
+
const target = conversation !== void 0 ? await resolveListed(chatsvc, raw, me, conversation, "search") : void 0;
|
|
52040
|
+
const args = {
|
|
52041
|
+
query,
|
|
52042
|
+
...target !== void 0 ? { target } : {},
|
|
52043
|
+
...from !== void 0 ? { fromLc: from.trim().toLowerCase() } : {},
|
|
52044
|
+
cutoff,
|
|
52045
|
+
cap: limit ?? DEFAULT_LIMIT2
|
|
52046
|
+
};
|
|
52047
|
+
const m = mode ?? "auto";
|
|
52048
|
+
let fallbackReason;
|
|
52049
|
+
if (m !== "scan") {
|
|
52050
|
+
const unavailable = substrate === void 0 ? "Substrate search is not available in this server." : !substrate.isConfigured() ? "Substrate search is disabled: TEAMS_DISABLE_FETCHPROXY is set, and the browser bridge is its only token source." : void 0;
|
|
52051
|
+
if (unavailable !== void 0 || substrate === void 0) {
|
|
52052
|
+
const reason = unavailable ?? "Substrate search is not available in this server.";
|
|
52053
|
+
if (m === "substrate") {
|
|
52054
|
+
throw new McpToolError(reason, { kind: "no_credential", hint: 'Use mode "auto" or "scan" to search by scanning instead.' });
|
|
52055
|
+
}
|
|
52056
|
+
fallbackReason = reason;
|
|
52057
|
+
} else {
|
|
52058
|
+
try {
|
|
52059
|
+
return untrustedResult2({
|
|
52060
|
+
query,
|
|
52061
|
+
source: "substrate",
|
|
52062
|
+
...await substrateSearch(substrate, chatsvc, raw, me, args, m === "substrate")
|
|
52063
|
+
});
|
|
52064
|
+
} catch (err) {
|
|
52065
|
+
if (m === "substrate") throw err;
|
|
52066
|
+
fallbackReason = wrapApiError(err, "search with Substrate").message;
|
|
52067
|
+
}
|
|
52068
|
+
}
|
|
52069
|
+
}
|
|
52070
|
+
return untrustedResult2({
|
|
52071
|
+
query,
|
|
52072
|
+
source: "scan",
|
|
52073
|
+
...fallbackReason !== void 0 ? { fallback_reason: fallbackReason } : {},
|
|
52074
|
+
...await scanSearch(chatsvc, raw, me, args, max_conversations)
|
|
52075
|
+
});
|
|
52076
|
+
} catch (err) {
|
|
52077
|
+
throw wrapApiError(err, "search messages");
|
|
52078
|
+
}
|
|
52079
|
+
}
|
|
52080
|
+
);
|
|
52081
|
+
}
|
|
52082
|
+
function summaryFor(id, listed, raw, me) {
|
|
52083
|
+
const c = listed.get(id);
|
|
52084
|
+
if (c !== void 0) return conversationSummary(c, me, raw);
|
|
52085
|
+
return { id, kind: conversationKind({ id }), title: id, unread: false, unread_confirmed: false };
|
|
52086
|
+
}
|
|
52087
|
+
async function substrateSearch(substrate, chatsvc, raw, me, { query, target, fromLc, cutoff, cap }, force) {
|
|
52088
|
+
const found = [];
|
|
52089
|
+
let pages = 0;
|
|
52090
|
+
let resultsRead = 0;
|
|
52091
|
+
let filteredOut = 0;
|
|
52092
|
+
let unmapped = 0;
|
|
52093
|
+
let total;
|
|
52094
|
+
let more = false;
|
|
52095
|
+
for (let offset = 0; pages < MAX_SUBSTRATE_PAGES; offset += SUBSTRATE_PAGE_SIZE) {
|
|
52096
|
+
const page = await substrate.searchMessages(
|
|
52097
|
+
{
|
|
52098
|
+
query,
|
|
52099
|
+
from: offset,
|
|
52100
|
+
size: SUBSTRATE_PAGE_SIZE,
|
|
52101
|
+
// Both restrictions are verified server-side; the checks below stay as a backstop.
|
|
52102
|
+
...target !== void 0 ? { conversationId: target.id } : {},
|
|
52103
|
+
sentAfter: cutoff
|
|
52104
|
+
},
|
|
52105
|
+
force ? { force } : void 0
|
|
52106
|
+
);
|
|
52107
|
+
pages++;
|
|
52108
|
+
resultsRead += page.results.length;
|
|
52109
|
+
unmapped += page.unmapped;
|
|
52110
|
+
total ??= page.total;
|
|
52111
|
+
more = page.moreAvailable;
|
|
52112
|
+
let anyInWindow = false;
|
|
52113
|
+
for (const r of page.results) {
|
|
52114
|
+
const at = r.time !== void 0 ? Date.parse(r.time) : NaN;
|
|
52115
|
+
if (Number.isFinite(at) && at < cutoff) {
|
|
52116
|
+
filteredOut++;
|
|
52117
|
+
continue;
|
|
52118
|
+
}
|
|
52119
|
+
anyInWindow = true;
|
|
52120
|
+
if (target !== void 0 && r.conversationId !== target.id) filteredOut++;
|
|
52121
|
+
else if (fromLc !== void 0 && !(r.sender ?? "").toLowerCase().includes(fromLc)) filteredOut++;
|
|
52122
|
+
else found.push({ hit: r, at });
|
|
52123
|
+
}
|
|
52124
|
+
if (!more || page.results.length === 0 || found.length > cap || !anyInWindow) break;
|
|
52125
|
+
}
|
|
52126
|
+
found.sort((a, b) => (Number.isFinite(b.at) ? b.at : 0) - (Number.isFinite(a.at) ? a.at : 0));
|
|
52127
|
+
const kept = found.slice(0, cap);
|
|
52128
|
+
const listed = new Map(raw.map((c) => [c.id, c]));
|
|
52129
|
+
const summaries = [...new Map(kept.map(({ hit }) => [hit.conversationId, summaryFor(hit.conversationId, listed, raw, me)])).values()];
|
|
52130
|
+
const titled = new Map(
|
|
52131
|
+
(await enrichTitles(chatsvc, raw, me, summaries.filter((s) => listed.has(s.id)))).map((s) => [s.id, s])
|
|
52132
|
+
);
|
|
52133
|
+
const bySummary = new Map(summaries.map((s) => [s.id, titled.get(s.id) ?? s]));
|
|
52134
|
+
const hits = kept.map(({ hit }) => ({
|
|
52135
|
+
conversation: hitConversation(bySummary.get(hit.conversationId) ?? summaryFor(hit.conversationId, listed, raw, me)),
|
|
52136
|
+
message: {
|
|
52137
|
+
...hit.messageId !== void 0 ? { id: hit.messageId } : {},
|
|
52138
|
+
...hit.time !== void 0 ? { time: hit.time } : {},
|
|
52139
|
+
sender: hit.sender ?? "",
|
|
52140
|
+
// No fromMe: a Substrate hit names its sender by display name and SMTP address only.
|
|
52141
|
+
text: hit.text,
|
|
52142
|
+
excerpt: true,
|
|
52143
|
+
...hit.subject !== void 0 ? { subject: hit.subject } : {},
|
|
52144
|
+
...hit.replyTo !== void 0 ? { replyTo: hit.replyTo } : {}
|
|
52145
|
+
}
|
|
52146
|
+
}));
|
|
52147
|
+
const totalHits = more && filteredOut === 0 && total !== void 0 ? Math.max(total, found.length) : found.length;
|
|
52148
|
+
const sinceIso = new Date(cutoff).toISOString();
|
|
52149
|
+
const pageCapped = pages >= MAX_SUBSTRATE_PAGES && more && found.length <= cap;
|
|
52150
|
+
return {
|
|
52151
|
+
total_hits: totalHits,
|
|
52152
|
+
hits,
|
|
52153
|
+
...totalHits > kept.length ? {
|
|
52154
|
+
truncated: {
|
|
52155
|
+
total: totalHits,
|
|
52156
|
+
returned: kept.length,
|
|
52157
|
+
hint: `Only the newest ${kept.length} hits were returned; pass a larger limit (max ${MAX_LIMIT}) or narrow with conversation, from or since.`
|
|
52158
|
+
}
|
|
52159
|
+
} : {},
|
|
52160
|
+
substrate: {
|
|
52161
|
+
since: sinceIso,
|
|
52162
|
+
pages_read: pages,
|
|
52163
|
+
results_read: resultsRead,
|
|
52164
|
+
results_filtered_out: filteredOut,
|
|
52165
|
+
...unmapped > 0 ? { results_unmapped: unmapped } : {},
|
|
52166
|
+
more_available: more,
|
|
52167
|
+
...pageCapped ? {
|
|
52168
|
+
hint: `Read the first ${MAX_SUBSTRATE_PAGES * SUBSTRATE_PAGE_SIZE} Substrate results and stopped; narrow with conversation, from or a later since, or a more specific query.`
|
|
52169
|
+
} : {}
|
|
52170
|
+
}
|
|
52171
|
+
};
|
|
52172
|
+
}
|
|
52173
|
+
async function scanSearch(chatsvc, raw, me, { query, target, fromLc, cutoff, cap }, maxConversations) {
|
|
52174
|
+
let targets;
|
|
52175
|
+
let outsideWindow = 0;
|
|
52176
|
+
if (target !== void 0) {
|
|
52177
|
+
targets = [target];
|
|
52178
|
+
} else {
|
|
52179
|
+
const inWindow = [];
|
|
52180
|
+
for (const c of raw) {
|
|
52181
|
+
const summary = conversationSummary(c, me, raw);
|
|
52182
|
+
if (summary.hidden === true) continue;
|
|
52183
|
+
const newest = newestActivityMs(c);
|
|
52184
|
+
if (newest !== void 0 && newest < cutoff) outsideWindow++;
|
|
52185
|
+
else inWindow.push({ summary, newest: newest ?? 0 });
|
|
52186
|
+
}
|
|
52187
|
+
inWindow.sort((a, b) => b.newest - a.newest);
|
|
52188
|
+
targets = inWindow.map((c) => c.summary);
|
|
52189
|
+
}
|
|
52190
|
+
const maxScanned = maxConversations ?? DEFAULT_SCANNED_CONVERSATIONS;
|
|
52191
|
+
const scanned = targets.slice(0, maxScanned);
|
|
52192
|
+
const notScanned = targets.length - scanned.length;
|
|
52193
|
+
const reads = await mapWithConcurrency(scanned, CONFIRM_CONCURRENCY, async (summary) => {
|
|
52194
|
+
let capped = false;
|
|
52195
|
+
try {
|
|
52196
|
+
const fetched = await chatsvc.getMessages(summary.id, {
|
|
52197
|
+
stopAt: (m) => {
|
|
52198
|
+
const at = arrivalMs(m);
|
|
52199
|
+
return Number.isFinite(at) && at < cutoff;
|
|
52200
|
+
},
|
|
52201
|
+
max: MAX_RAW_PER_CONVERSATION,
|
|
52202
|
+
onCapped: () => capped = true
|
|
52203
|
+
});
|
|
52204
|
+
const hits2 = fetched.filter((m) => {
|
|
52205
|
+
if (!isUserMessage(m)) return false;
|
|
52206
|
+
const n = normaliseMessage(m, me);
|
|
52207
|
+
if (n.deleted) return false;
|
|
52208
|
+
if (fromLc !== void 0 && !n.sender.toLowerCase().includes(fromLc)) return false;
|
|
52209
|
+
return matchesQuery(n.subject !== void 0 ? `${n.subject}
|
|
52210
|
+
${n.text}` : n.text, query);
|
|
52211
|
+
});
|
|
52212
|
+
return { kind: "read", hits: hits2, seen: fetched.length, capped };
|
|
52213
|
+
} catch (error62) {
|
|
52214
|
+
return isUnreachable(error62) ? { kind: "unreachable" } : { kind: "failed", error: error62 };
|
|
52215
|
+
}
|
|
52216
|
+
});
|
|
52217
|
+
const found = [];
|
|
52218
|
+
const failed = [];
|
|
52219
|
+
const partial2 = [];
|
|
52220
|
+
let unreachable = 0;
|
|
52221
|
+
let messagesScanned = 0;
|
|
52222
|
+
let anyRead = false;
|
|
52223
|
+
reads.forEach((r, i) => {
|
|
52224
|
+
const summary = scanned[i];
|
|
52225
|
+
if (r.kind === "unreachable") unreachable++;
|
|
52226
|
+
else if (r.kind === "failed") failed.push({ summary, error: r.error });
|
|
52227
|
+
else {
|
|
52228
|
+
anyRead = true;
|
|
52229
|
+
messagesScanned += r.seen;
|
|
52230
|
+
if (r.capped) partial2.push(summary);
|
|
52231
|
+
for (const m of r.hits) found.push({ summary, message: normaliseMessage(m, me), at: arrivalMs(m) });
|
|
52232
|
+
}
|
|
52233
|
+
});
|
|
52234
|
+
if (failed.length > 0 && !anyRead) throw failed[0].error;
|
|
52235
|
+
found.sort((a, b) => (Number.isFinite(b.at) ? b.at : 0) - (Number.isFinite(a.at) ? a.at : 0));
|
|
52236
|
+
const kept = found.slice(0, cap);
|
|
52237
|
+
const named = [...new Map([...kept.map((h) => h.summary), ...partial2, ...failed.map((f) => f.summary)].map((s) => [s.id, s])).values()];
|
|
52238
|
+
const titled = new Map((await enrichTitles(chatsvc, raw, me, named)).map((s) => [s.id, s]));
|
|
52239
|
+
const final = (s) => titled.get(s.id) ?? s;
|
|
52240
|
+
const hits = kept.map((h) => ({ conversation: hitConversation(final(h.summary)), message: hitMessage(h.message) }));
|
|
52241
|
+
const sinceIso = new Date(cutoff).toISOString();
|
|
52242
|
+
const leftOut = notScanned > 0 || partial2.length > 0;
|
|
52243
|
+
return {
|
|
52244
|
+
total_hits: found.length,
|
|
52245
|
+
hits,
|
|
52246
|
+
...found.length > kept.length ? {
|
|
52247
|
+
truncated: {
|
|
52248
|
+
total: found.length,
|
|
52249
|
+
returned: kept.length,
|
|
52250
|
+
hint: `Only the newest ${kept.length} of ${found.length} hits were returned; pass a larger limit (max ${MAX_LIMIT}) or narrow with conversation, from or since.`
|
|
52251
|
+
}
|
|
52252
|
+
} : {},
|
|
52253
|
+
scan: {
|
|
52254
|
+
method: "client_scan",
|
|
52255
|
+
since: sinceIso,
|
|
52256
|
+
conversations_scanned: scanned.length,
|
|
52257
|
+
conversations_outside_window: outsideWindow,
|
|
52258
|
+
conversations_not_scanned: notScanned,
|
|
52259
|
+
messages_scanned: messagesScanned,
|
|
52260
|
+
skipped_unreachable: unreachable,
|
|
52261
|
+
...partial2.length > 0 ? { partially_scanned: partial2.map((s) => ({ id: s.id, title: final(s).title })) } : {},
|
|
52262
|
+
...leftOut ? {
|
|
52263
|
+
hint: (notScanned > 0 ? `${notScanned} less recently active conversation${notScanned === 1 ? " was" : "s were"} not scanned (max_conversations ${maxScanned}; up to ${MAX_SCANNED_CONVERSATIONS}). ` : "") + (partial2.length > 0 ? `${partial2.length} conversation${partial2.length === 1 ? " was" : "s were"} only read back ${MAX_RAW_PER_CONVERSATION} messages, short of ${sinceIso}. ` : "") + "Raise max_conversations, or narrow with conversation or a later since, to search everything in range."
|
|
52264
|
+
} : {}
|
|
52265
|
+
},
|
|
52266
|
+
...failed.length > 0 ? {
|
|
52267
|
+
errors: failed.map((f) => ({
|
|
52268
|
+
conversation: hitConversation(final(f.summary)),
|
|
52269
|
+
error: wrapApiError(f.error, "search this conversation").message
|
|
52270
|
+
}))
|
|
52271
|
+
} : {}
|
|
52272
|
+
};
|
|
52273
|
+
}
|
|
52274
|
+
|
|
50675
52275
|
// src/tools/healthcheck.ts
|
|
50676
52276
|
init_dist2();
|
|
50677
52277
|
init_healthcheck();
|
|
50678
52278
|
var HOST_LABEL = "teams.cloud.microsoft";
|
|
50679
52279
|
var TITLE = "Verify the Teams chat-service token and API end-to-end";
|
|
50680
52280
|
var SHAREPOINT_NOTE = "Shared-file download (teams_get_attachment) uses a separate SharePoint token, captured on demand per SharePoint host and short-lived (~53 min). None is held until you open a file, and this healthcheck neither mints nor requires one.";
|
|
52281
|
+
var SUBSTRATE_NOTE = "Search (teams_search_messages) uses a separate Microsoft Substrate token for substrate.office.com, captured on demand when you run a search in a Teams tab (the bridge pairing must trust substrate.office.com). Without one, search falls back to a scan of recent conversations; this healthcheck neither mints nor requires one.";
|
|
50681
52282
|
function registerHealthcheckTool(server, { chatsvc }) {
|
|
50682
52283
|
server.registerTool(
|
|
50683
52284
|
"teams_healthcheck",
|
|
@@ -50727,7 +52328,7 @@ function registerHealthcheckTool(server, { chatsvc }) {
|
|
|
50727
52328
|
...result.content,
|
|
50728
52329
|
{
|
|
50729
52330
|
type: "text",
|
|
50730
|
-
text: JSON.stringify({ chat_service: chatService, sharepoint: SHAREPOINT_NOTE }, null, 2)
|
|
52331
|
+
text: JSON.stringify({ chat_service: chatService, sharepoint: SHAREPOINT_NOTE, substrate: SUBSTRATE_NOTE }, null, 2)
|
|
50731
52332
|
}
|
|
50732
52333
|
]
|
|
50733
52334
|
};
|
|
@@ -50736,7 +52337,7 @@ function registerHealthcheckTool(server, { chatsvc }) {
|
|
|
50736
52337
|
content: [
|
|
50737
52338
|
{
|
|
50738
52339
|
type: "text",
|
|
50739
|
-
text: JSON.stringify({ ...body, chat_service: chatService, sharepoint: SHAREPOINT_NOTE }, null, 2)
|
|
52340
|
+
text: JSON.stringify({ ...body, chat_service: chatService, sharepoint: SHAREPOINT_NOTE, substrate: SUBSTRATE_NOTE }, null, 2)
|
|
50740
52341
|
}
|
|
50741
52342
|
]
|
|
50742
52343
|
};
|
|
@@ -50749,7 +52350,8 @@ var TOKEN_CAPTURE_HINT = "No Teams access token could be captured. Open a signed
|
|
|
50749
52350
|
loadDotenvSafely();
|
|
50750
52351
|
var deps = {
|
|
50751
52352
|
chatsvc: new ChatServiceClient(),
|
|
50752
|
-
sharepoint: new SharePointClient()
|
|
52353
|
+
sharepoint: new SharePointClient(),
|
|
52354
|
+
substrate: new SubstrateClient()
|
|
50753
52355
|
};
|
|
50754
52356
|
await runMcp({
|
|
50755
52357
|
name: "microsoft-teams-mcp",
|
|
@@ -50761,10 +52363,13 @@ await runMcp({
|
|
|
50761
52363
|
registerChannelTools,
|
|
50762
52364
|
registerConversationTools,
|
|
50763
52365
|
registerUnreadTools,
|
|
52366
|
+
registerChangesTools,
|
|
50764
52367
|
registerAttachmentTools,
|
|
50765
52368
|
registerSendTools,
|
|
50766
52369
|
registerReactTools,
|
|
52370
|
+
registerMarkReadTools,
|
|
50767
52371
|
registerActivityTools,
|
|
52372
|
+
registerSearchTools,
|
|
50768
52373
|
registerHealthcheckTool
|
|
50769
52374
|
]
|
|
50770
52375
|
});
|