@chrischall/microsoft-teams-mcp 0.11.0 → 0.12.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 +55 -11
- package/dist/bundle.js +1200 -179
- package/dist/chatsvc.js +30 -0
- package/dist/compose.js +150 -51
- package/dist/index.js +4 -0
- package/dist/model.js +12 -91
- package/dist/rich.js +108 -0
- package/dist/tools/conversation.js +4 -1
- package/dist/tools/delete.js +72 -0
- package/dist/tools/edit.js +131 -0
- package/dist/tools/export-format.js +4 -1
- package/dist/tools/own-message.js +78 -0
- package/dist/tools/send.js +24 -8
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/server.json +3 -3
- package/skills/teams-fpx/SKILL.md +9 -7
package/dist/bundle.js
CHANGED
|
@@ -382,7 +382,7 @@ function putProp(target, key, value) {
|
|
|
382
382
|
else
|
|
383
383
|
target[key] = value;
|
|
384
384
|
}
|
|
385
|
-
function mirrorShape(target, source, keys,
|
|
385
|
+
function mirrorShape(target, source, keys, wrap2) {
|
|
386
386
|
const raw = sourceShape(source);
|
|
387
387
|
for (const key of keys) {
|
|
388
388
|
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
@@ -391,10 +391,10 @@ function mirrorShape(target, source, keys, wrap) {
|
|
|
391
391
|
if (desc.get) {
|
|
392
392
|
deferProp(target, key, () => {
|
|
393
393
|
const value = source._zod.def.shape[key];
|
|
394
|
-
return
|
|
394
|
+
return wrap2 ? wrap2(value, key) : value;
|
|
395
395
|
});
|
|
396
396
|
} else
|
|
397
|
-
putProp(target, key,
|
|
397
|
+
putProp(target, key, wrap2 ? wrap2(desc.value, key) : desc.value);
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
400
|
function mirrorProps(target, source) {
|
|
@@ -838,9 +838,9 @@ function hexToUint8Array(hex3) {
|
|
|
838
838
|
function uint8ArrayToHex(bytes) {
|
|
839
839
|
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
840
840
|
}
|
|
841
|
-
function members(proto,
|
|
842
|
-
for (const key in
|
|
843
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
841
|
+
function members(proto, table2) {
|
|
842
|
+
for (const key in table2) {
|
|
843
|
+
const desc = Object.getOwnPropertyDescriptor(table2, key);
|
|
844
844
|
if (desc.get)
|
|
845
845
|
Object.defineProperty(proto, key, { ...desc, enumerable: false });
|
|
846
846
|
else
|
|
@@ -855,10 +855,10 @@ function hide(inst, key, value) {
|
|
|
855
855
|
return own(inst, key, value, false);
|
|
856
856
|
}
|
|
857
857
|
// @__NO_SIDE_EFFECTS__
|
|
858
|
-
function derived(computes,
|
|
858
|
+
function derived(computes, table2) {
|
|
859
859
|
for (const key in computes) {
|
|
860
860
|
const compute = computes[key];
|
|
861
|
-
Object.defineProperty(
|
|
861
|
+
Object.defineProperty(table2, key, {
|
|
862
862
|
configurable: true,
|
|
863
863
|
enumerable: true,
|
|
864
864
|
get() {
|
|
@@ -869,7 +869,7 @@ function derived(computes, table) {
|
|
|
869
869
|
}
|
|
870
870
|
});
|
|
871
871
|
}
|
|
872
|
-
return
|
|
872
|
+
return table2;
|
|
873
873
|
}
|
|
874
874
|
function defineBound(proto, key, fn) {
|
|
875
875
|
Object.defineProperty(proto, key, {
|
|
@@ -16303,8 +16303,8 @@ var init_to_json_schema = __esm({
|
|
|
16303
16303
|
function aggregateChecks(schema) {
|
|
16304
16304
|
const agg = {};
|
|
16305
16305
|
const def = schema._zod.def;
|
|
16306
|
-
const
|
|
16307
|
-
for (const ch of
|
|
16306
|
+
const list2 = schema._zod.traits.has("$ZodCheck") ? [schema, ...def.checks ?? []] : def.checks ?? [];
|
|
16307
|
+
for (const ch of list2)
|
|
16308
16308
|
contributors[ch._zod.def.check]?.(agg, ch._zod.def);
|
|
16309
16309
|
const bag = schema._zod.bag;
|
|
16310
16310
|
if (bag.minimum !== void 0)
|
|
@@ -31196,7 +31196,7 @@ var init_ajvProvider_DyjnscPj = __esm({
|
|
|
31196
31196
|
const count = gen.let("count", 0);
|
|
31197
31197
|
validateItems(schValid, () => gen.if(schValid, () => checkLimits(count)));
|
|
31198
31198
|
}
|
|
31199
|
-
function validateItems(_valid,
|
|
31199
|
+
function validateItems(_valid, block2) {
|
|
31200
31200
|
gen.forRange("i", 0, len, (i) => {
|
|
31201
31201
|
cxt.subschema({
|
|
31202
31202
|
keyword: "contains",
|
|
@@ -31204,7 +31204,7 @@ var init_ajvProvider_DyjnscPj = __esm({
|
|
|
31204
31204
|
dataPropType: util_1.Type.Num,
|
|
31205
31205
|
compositeRule: true
|
|
31206
31206
|
}, _valid);
|
|
31207
|
-
|
|
31207
|
+
block2();
|
|
31208
31208
|
});
|
|
31209
31209
|
}
|
|
31210
31210
|
function checkLimits(count) {
|
|
@@ -33574,11 +33574,11 @@ var init_ajvProvider_DyjnscPj = __esm({
|
|
|
33574
33574
|
if (!f) throw new Error(`Unknown format "${name}"`);
|
|
33575
33575
|
return f;
|
|
33576
33576
|
};
|
|
33577
|
-
function addFormats2(ajv,
|
|
33577
|
+
function addFormats2(ajv, list2, fs, exportName) {
|
|
33578
33578
|
var _a3;
|
|
33579
33579
|
var _b;
|
|
33580
33580
|
(_a3 = (_b = ajv.opts.code).formats) !== null && _a3 !== void 0 || (_b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`);
|
|
33581
|
-
for (const f of
|
|
33581
|
+
for (const f of list2) ajv.addFormat(f, fs[f]);
|
|
33582
33582
|
}
|
|
33583
33583
|
module.exports = exports = formatsPlugin;
|
|
33584
33584
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -38523,7 +38523,7 @@ var init_version = __esm({
|
|
|
38523
38523
|
"src/version.ts"() {
|
|
38524
38524
|
"use strict";
|
|
38525
38525
|
PACKAGE_NAME = "microsoft-teams-mcp";
|
|
38526
|
-
VERSION = "0.
|
|
38526
|
+
VERSION = "0.12.0";
|
|
38527
38527
|
}
|
|
38528
38528
|
});
|
|
38529
38529
|
|
|
@@ -38894,13 +38894,13 @@ function capturedBearerTokens(accessToken, opts = {}) {
|
|
|
38894
38894
|
}
|
|
38895
38895
|
function createCapturedTokenManager(opts) {
|
|
38896
38896
|
const { direct } = opts;
|
|
38897
|
-
const
|
|
38897
|
+
const wrap2 = (token) => capturedBearerTokens(token, {
|
|
38898
38898
|
...opts.unknownTtlMs !== void 0 ? { unknownTtlMs: opts.unknownTtlMs } : {},
|
|
38899
38899
|
...opts.now !== void 0 ? { now: opts.now } : {}
|
|
38900
38900
|
});
|
|
38901
38901
|
const persistence = direct === void 0 ? opts.persistence ?? void 0 : void 0;
|
|
38902
38902
|
return new TokenManager({
|
|
38903
|
-
initial: async () =>
|
|
38903
|
+
initial: async () => wrap2(direct ?? await opts.capture()),
|
|
38904
38904
|
refresh: async () => {
|
|
38905
38905
|
if (direct !== void 0) {
|
|
38906
38906
|
throw opts.onDirectRejected ? opts.onDirectRejected() : new McpToolError("The directly supplied access token was rejected (401).", {
|
|
@@ -38909,7 +38909,7 @@ function createCapturedTokenManager(opts) {
|
|
|
38909
38909
|
hint: "A directly supplied token cannot be refreshed automatically. Replace it with a current one, or unset it to capture from a signed-in browser tab instead."
|
|
38910
38910
|
});
|
|
38911
38911
|
}
|
|
38912
|
-
return
|
|
38912
|
+
return wrap2(await opts.capture());
|
|
38913
38913
|
},
|
|
38914
38914
|
...persistence !== void 0 ? { persistence } : {},
|
|
38915
38915
|
// Never fatal: the token is in hand and re-capturable.
|
|
@@ -40403,14 +40403,14 @@ function assertAcceptsList(accepts) {
|
|
|
40403
40403
|
}
|
|
40404
40404
|
}
|
|
40405
40405
|
}
|
|
40406
|
-
function assertExtensionFeatures(
|
|
40406
|
+
function assertExtensionFeatures(list2) {
|
|
40407
40407
|
const label = "hello.features";
|
|
40408
|
-
if (!Array.isArray(
|
|
40408
|
+
if (!Array.isArray(list2))
|
|
40409
40409
|
throw new ProtocolError3(`${label}: expected array`);
|
|
40410
|
-
if (
|
|
40411
|
-
throw new ProtocolError3(`${label}: at most ${MAX_EXTENSION_FEATURES} entries, got ${
|
|
40410
|
+
if (list2.length > MAX_EXTENSION_FEATURES) {
|
|
40411
|
+
throw new ProtocolError3(`${label}: at most ${MAX_EXTENSION_FEATURES} entries, got ${list2.length}`);
|
|
40412
40412
|
}
|
|
40413
|
-
for (const f of
|
|
40413
|
+
for (const f of list2) {
|
|
40414
40414
|
if (typeof f !== "string") {
|
|
40415
40415
|
throw new ProtocolError3(`${label}: entry must be string, got ${typeof f}`);
|
|
40416
40416
|
}
|
|
@@ -40419,14 +40419,14 @@ function assertExtensionFeatures(list) {
|
|
|
40419
40419
|
}
|
|
40420
40420
|
}
|
|
40421
40421
|
}
|
|
40422
|
-
function assertUnavailableCapabilities(
|
|
40422
|
+
function assertUnavailableCapabilities(list2) {
|
|
40423
40423
|
const label = "hello.unavailableCapabilities";
|
|
40424
|
-
if (!Array.isArray(
|
|
40424
|
+
if (!Array.isArray(list2))
|
|
40425
40425
|
throw new ProtocolError3(`${label}: expected array`);
|
|
40426
|
-
if (
|
|
40427
|
-
throw new ProtocolError3(`${label}: at most ${MAX_UNAVAILABLE_CAPABILITIES} entries, got ${
|
|
40426
|
+
if (list2.length > MAX_UNAVAILABLE_CAPABILITIES) {
|
|
40427
|
+
throw new ProtocolError3(`${label}: at most ${MAX_UNAVAILABLE_CAPABILITIES} entries, got ${list2.length}`);
|
|
40428
40428
|
}
|
|
40429
|
-
for (const c of
|
|
40429
|
+
for (const c of list2) {
|
|
40430
40430
|
if (typeof c !== "string") {
|
|
40431
40431
|
throw new ProtocolError3(`${label}: entry must be string, got ${typeof c}`);
|
|
40432
40432
|
}
|
|
@@ -41401,13 +41401,13 @@ var require_buffer_util = __commonJS({
|
|
|
41401
41401
|
var { websocketMask, websocketUnmask } = __require("http");
|
|
41402
41402
|
var { EMPTY_BUFFER } = require_constants();
|
|
41403
41403
|
var FastBuffer = Buffer[Symbol.species];
|
|
41404
|
-
function concat(
|
|
41405
|
-
if (
|
|
41406
|
-
if (
|
|
41404
|
+
function concat(list2, totalLength) {
|
|
41405
|
+
if (list2.length === 0) return EMPTY_BUFFER;
|
|
41406
|
+
if (list2.length === 1) return list2[0];
|
|
41407
41407
|
const target = Buffer.allocUnsafe(totalLength);
|
|
41408
41408
|
let offset = 0;
|
|
41409
|
-
for (let i = 0; i <
|
|
41410
|
-
const buf =
|
|
41409
|
+
for (let i = 0; i < list2.length; i++) {
|
|
41410
|
+
const buf = list2[i];
|
|
41411
41411
|
target.set(buf, offset);
|
|
41412
41412
|
offset += buf.length;
|
|
41413
41413
|
}
|
|
@@ -43206,14 +43206,14 @@ var require_sender = __commonJS({
|
|
|
43206
43206
|
* @param {Function} [cb] Callback
|
|
43207
43207
|
* @private
|
|
43208
43208
|
*/
|
|
43209
|
-
sendFrame(
|
|
43210
|
-
if (
|
|
43209
|
+
sendFrame(list2, cb) {
|
|
43210
|
+
if (list2.length === 2) {
|
|
43211
43211
|
this._socket.cork();
|
|
43212
|
-
this._socket.write(
|
|
43213
|
-
this._socket.write(
|
|
43212
|
+
this._socket.write(list2[0]);
|
|
43213
|
+
this._socket.write(list2[1], cb);
|
|
43214
43214
|
this._socket.uncork();
|
|
43215
43215
|
} else {
|
|
43216
|
-
this._socket.write(
|
|
43216
|
+
this._socket.write(list2[0], cb);
|
|
43217
43217
|
}
|
|
43218
43218
|
}
|
|
43219
43219
|
};
|
|
@@ -48626,8 +48626,8 @@ var init_ws_server = __esm({
|
|
|
48626
48626
|
throw new Error("FetchproxyServer.captureRequestHeader: no captureHeaders declared on this server \u2014 declare at least one entry in FetchproxyServerOpts.captureHeaders, or pass {host, headerName} explicitly");
|
|
48627
48627
|
}
|
|
48628
48628
|
if (decls.length > 1) {
|
|
48629
|
-
const
|
|
48630
|
-
throw new Error(`FetchproxyServer.captureRequestHeader: multiple captureHeaders declared (${decls.length}: ${
|
|
48629
|
+
const list2 = decls.map((d) => `${JSON.stringify(d.host)}${JSON.stringify(normPath(d.path))}/${JSON.stringify(d.headerName)}`).join(", ");
|
|
48630
|
+
throw new Error(`FetchproxyServer.captureRequestHeader: multiple captureHeaders declared (${decls.length}: ${list2}); pass {host, headerName} to disambiguate`);
|
|
48631
48631
|
}
|
|
48632
48632
|
resolved = decls[0];
|
|
48633
48633
|
} else {
|
|
@@ -50096,22 +50096,22 @@ function captureHostFor(fileHost) {
|
|
|
50096
50096
|
return m ? `${m[1]}-my.sharepoint.com` : h;
|
|
50097
50097
|
}
|
|
50098
50098
|
async function captureSharePointTokenViaFetchproxy(hosts, env = process.env) {
|
|
50099
|
-
const
|
|
50100
|
-
const bad =
|
|
50101
|
-
if (
|
|
50099
|
+
const list2 = [...new Set((typeof hosts === "string" ? [hosts] : [...hosts]).map((h) => h.toLowerCase()))];
|
|
50100
|
+
const bad = list2.find((h) => !isSharePointHost(h));
|
|
50101
|
+
if (list2.length === 0 || bad !== void 0) {
|
|
50102
50102
|
throw new Error(
|
|
50103
50103
|
`refusing to capture a SharePoint token for ${JSON.stringify(bad ?? "")}: not a *.sharepoint.com host`
|
|
50104
50104
|
);
|
|
50105
50105
|
}
|
|
50106
|
-
const label =
|
|
50106
|
+
const label = list2.join(" or ");
|
|
50107
50107
|
let refused = false;
|
|
50108
|
-
const scoped = bridgeScopedTransport(env,
|
|
50108
|
+
const scoped = bridgeScopedTransport(env, list2);
|
|
50109
50109
|
let token;
|
|
50110
50110
|
try {
|
|
50111
50111
|
token = await captureBearerHeader({
|
|
50112
50112
|
// Any call the browser makes to one of these hosts. Concrete hosts, never
|
|
50113
50113
|
// a wildcard — see the module note.
|
|
50114
|
-
captures:
|
|
50114
|
+
captures: list2.map(sharePointCaptureDecl),
|
|
50115
50115
|
// The one bridge scope (`bridge-scope.ts`), with these hosts' captures
|
|
50116
50116
|
// added to the remembered ones so the hello asks for exactly what it is
|
|
50117
50117
|
// about to read.
|
|
@@ -50132,7 +50132,7 @@ async function captureSharePointTokenViaFetchproxy(hosts, env = process.env) {
|
|
|
50132
50132
|
cause: err
|
|
50133
50133
|
});
|
|
50134
50134
|
}
|
|
50135
|
-
for (const h of
|
|
50135
|
+
for (const h of list2) rememberSharePointHost(h, env);
|
|
50136
50136
|
return token;
|
|
50137
50137
|
}
|
|
50138
50138
|
function noteScopeRefusal(transport, onRefused) {
|
|
@@ -50246,6 +50246,758 @@ init_dist2();
|
|
|
50246
50246
|
init_session();
|
|
50247
50247
|
init_token_cache();
|
|
50248
50248
|
|
|
50249
|
+
// node_modules/@chrischall/mcp-utils/dist/rich/html.js
|
|
50250
|
+
var NAMED_ENTITIES = {
|
|
50251
|
+
amp: "&",
|
|
50252
|
+
lt: "<",
|
|
50253
|
+
gt: ">",
|
|
50254
|
+
quot: '"',
|
|
50255
|
+
apos: "'",
|
|
50256
|
+
nbsp: " "
|
|
50257
|
+
};
|
|
50258
|
+
function decodeEntities(s) {
|
|
50259
|
+
return s.replace(/&(?:#(\d{1,8})|#x([0-9a-f]{1,8})|([a-z]{1,10}));|&(amp|lt|gt|quot|nbsp)(?![a-z0-9=])/gi, (whole, dec2, hex3, name, legacy) => {
|
|
50260
|
+
if (legacy !== void 0)
|
|
50261
|
+
return NAMED_ENTITIES[legacy.toLowerCase()];
|
|
50262
|
+
if (name !== void 0)
|
|
50263
|
+
return NAMED_ENTITIES[name.toLowerCase()] ?? whole;
|
|
50264
|
+
const code2 = dec2 !== void 0 ? Number(dec2) : parseInt(hex3, 16);
|
|
50265
|
+
if (!Number.isFinite(code2) || code2 > 1114111)
|
|
50266
|
+
return whole;
|
|
50267
|
+
if (code2 < 32 && code2 !== 9 && code2 !== 10)
|
|
50268
|
+
return "";
|
|
50269
|
+
return String.fromCodePoint(code2);
|
|
50270
|
+
});
|
|
50271
|
+
}
|
|
50272
|
+
var HTML_ESCAPES = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
50273
|
+
function escapeHtml(s) {
|
|
50274
|
+
return s.replace(/[&<>"']/g, (c) => HTML_ESCAPES[c]);
|
|
50275
|
+
}
|
|
50276
|
+
function attr(attrs, name) {
|
|
50277
|
+
const m = new RegExp(`(?:^|\\s)${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'>]+))`, "i").exec(attrs);
|
|
50278
|
+
return m ? m[1] ?? m[2] ?? m[3] : void 0;
|
|
50279
|
+
}
|
|
50280
|
+
var INVISIBLE = /[\u200b\u200c\u2060\ufeff]/g;
|
|
50281
|
+
var visible = (s) => s.replace(INVISIBLE, "");
|
|
50282
|
+
var MAX_DEPTH = 200;
|
|
50283
|
+
var VOID = /* @__PURE__ */ new Set(["br", "img", "hr", "wbr", "input", "meta", "link", "col", "source", "area", "base", "embed", "param", "track"]);
|
|
50284
|
+
var DROPPED_WITH_CONTENT = "script|style|head|title|template|noscript|iframe|object|svg|math|xml";
|
|
50285
|
+
var BLOCK = /* @__PURE__ */ new Set(["p", "div", "ul", "ol", "pre", "blockquote", "table", "h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
50286
|
+
var TAG = /<(\/?)([a-z][a-z0-9]*)\b((?:[^<>"']|"[^"<]*"|'[^'<]*')*)>/gi;
|
|
50287
|
+
var HIDDEN_STYLE = /(?:^|[;\s])(?:display\s*:\s*none|visibility\s*:\s*hidden|mso-hide\s*:\s*all)\b/i;
|
|
50288
|
+
function isHidden(attrs) {
|
|
50289
|
+
const names = attrs.replace(/"[^"]*"|'[^']*'/g, '""');
|
|
50290
|
+
if (/(?:^|\s)hidden(?:\s|=|\/|$)/i.test(names))
|
|
50291
|
+
return true;
|
|
50292
|
+
const style = attr(attrs, "style");
|
|
50293
|
+
return style !== void 0 && HIDDEN_STYLE.test(decodeEntities(style));
|
|
50294
|
+
}
|
|
50295
|
+
function parseHtml(html, opts = {}) {
|
|
50296
|
+
const root = { tag: "#root", attrs: "", children: [] };
|
|
50297
|
+
const stack = [root];
|
|
50298
|
+
const top = () => stack[stack.length - 1];
|
|
50299
|
+
const src = html.replace(/[\u0001-\u0005]/g, "").replace(/<!--[\s\S]*?(?:-->|$)/g, "").replace(/<!\[CDATA\[[\s\S]*?(?:\]\]>|$)/g, "").replace(/<![^>]*>/g, "").replace(new RegExp(`<(${DROPPED_WITH_CONTENT})\\b[\\s\\S]*?(?:<\\/\\1\\s*>|$)`, "gi"), "");
|
|
50300
|
+
let at = 0;
|
|
50301
|
+
for (const m of src.matchAll(TAG)) {
|
|
50302
|
+
if (m.index > at)
|
|
50303
|
+
top().children.push(src.slice(at, m.index));
|
|
50304
|
+
at = m.index + m[0].length;
|
|
50305
|
+
const tag = m[2].toLowerCase();
|
|
50306
|
+
if (m[1] === "/") {
|
|
50307
|
+
let i = stack.length - 1;
|
|
50308
|
+
while (i > 0 && stack[i].tag !== tag)
|
|
50309
|
+
i--;
|
|
50310
|
+
if (i > 0)
|
|
50311
|
+
stack.length = i;
|
|
50312
|
+
continue;
|
|
50313
|
+
}
|
|
50314
|
+
if (tag === "li" && top().tag === "li" || BLOCK.has(tag) && top().tag === "p")
|
|
50315
|
+
stack.pop();
|
|
50316
|
+
if ((tag === "td" || tag === "th" || tag === "tr") && (top().tag === "td" || top().tag === "th"))
|
|
50317
|
+
stack.pop();
|
|
50318
|
+
if (tag === "tr" && top().tag === "tr")
|
|
50319
|
+
stack.pop();
|
|
50320
|
+
const attrs = m[3];
|
|
50321
|
+
const el = { tag, attrs, children: [] };
|
|
50322
|
+
const hidden = opts.keepHidden !== true && isHidden(attrs);
|
|
50323
|
+
if (!hidden)
|
|
50324
|
+
top().children.push(el);
|
|
50325
|
+
const opens = !VOID.has(tag) && !attrs.trimEnd().endsWith("/");
|
|
50326
|
+
if (opens && (hidden || stack.length <= MAX_DEPTH))
|
|
50327
|
+
stack.push(el);
|
|
50328
|
+
}
|
|
50329
|
+
if (at < src.length)
|
|
50330
|
+
top().children.push(src.slice(at));
|
|
50331
|
+
return root;
|
|
50332
|
+
}
|
|
50333
|
+
function safeHref(attrs) {
|
|
50334
|
+
const raw = attr(attrs, "href");
|
|
50335
|
+
if (raw === void 0)
|
|
50336
|
+
return void 0;
|
|
50337
|
+
const href = decodeEntities(raw).trim();
|
|
50338
|
+
return /^(https?:\/\/|mailto:)/i.test(href) ? href : void 0;
|
|
50339
|
+
}
|
|
50340
|
+
function defaultImageText(el) {
|
|
50341
|
+
const alt = decodeEntities(attr(el.attrs, "alt") ?? "").replace(/\s+/g, " ").trim();
|
|
50342
|
+
return alt === "" ? "" : `[${alt}]`;
|
|
50343
|
+
}
|
|
50344
|
+
var PLAIN_TAGS = /* @__PURE__ */ new Set([
|
|
50345
|
+
"p",
|
|
50346
|
+
"div",
|
|
50347
|
+
"br",
|
|
50348
|
+
"b",
|
|
50349
|
+
"strong",
|
|
50350
|
+
"i",
|
|
50351
|
+
"em",
|
|
50352
|
+
"u",
|
|
50353
|
+
"s",
|
|
50354
|
+
"strike",
|
|
50355
|
+
"del",
|
|
50356
|
+
"ul",
|
|
50357
|
+
"li",
|
|
50358
|
+
"code",
|
|
50359
|
+
"pre",
|
|
50360
|
+
"blockquote",
|
|
50361
|
+
"h1",
|
|
50362
|
+
"h2",
|
|
50363
|
+
"h3",
|
|
50364
|
+
"h4",
|
|
50365
|
+
"h5",
|
|
50366
|
+
"h6",
|
|
50367
|
+
"table",
|
|
50368
|
+
"thead",
|
|
50369
|
+
"tbody",
|
|
50370
|
+
"tr",
|
|
50371
|
+
"td",
|
|
50372
|
+
"th",
|
|
50373
|
+
"hr"
|
|
50374
|
+
]);
|
|
50375
|
+
function serialise(nodes, o, allow) {
|
|
50376
|
+
let out = "";
|
|
50377
|
+
for (const n of nodes) {
|
|
50378
|
+
if (typeof n === "string") {
|
|
50379
|
+
out += n.replace(/\r\n?/g, "\n").replace(/</g, "<").replace(/>/g, ">");
|
|
50380
|
+
continue;
|
|
50381
|
+
}
|
|
50382
|
+
const inner = n.tag === "img" ? "" : serialise(n.children, o, allow);
|
|
50383
|
+
const hooked = o.element?.(n, "html", inner);
|
|
50384
|
+
if (hooked !== void 0)
|
|
50385
|
+
out += hooked;
|
|
50386
|
+
else if (n.tag === "img")
|
|
50387
|
+
out += escapeHtml(defaultImageText(n));
|
|
50388
|
+
else if (allow !== void 0 && !allow.has(n.tag))
|
|
50389
|
+
out += outsideSubset(n, inner, o, allow);
|
|
50390
|
+
else if (n.tag === "br" || n.tag === "hr")
|
|
50391
|
+
out += `<${n.tag}>`;
|
|
50392
|
+
else if (PLAIN_TAGS.has(n.tag))
|
|
50393
|
+
out += `<${n.tag}>${inner}</${n.tag}>`;
|
|
50394
|
+
else if (n.tag === "ol") {
|
|
50395
|
+
const start = attr(n.attrs, "start");
|
|
50396
|
+
out += `<ol${start !== void 0 && /^\d{1,9}$/.test(start) ? ` start="${start}"` : ""}>${inner}</ol>`;
|
|
50397
|
+
} else if (n.tag === "a") {
|
|
50398
|
+
const href = safeHref(n.attrs);
|
|
50399
|
+
out += href !== void 0 ? `<a href="${escapeHtml(href)}">${inner}</a>` : inner;
|
|
50400
|
+
} else
|
|
50401
|
+
out += inner;
|
|
50402
|
+
}
|
|
50403
|
+
return out;
|
|
50404
|
+
}
|
|
50405
|
+
var EQUIVALENT = {
|
|
50406
|
+
b: ["strong"],
|
|
50407
|
+
strong: ["b"],
|
|
50408
|
+
i: ["em"],
|
|
50409
|
+
em: ["i"],
|
|
50410
|
+
s: ["strike", "del"],
|
|
50411
|
+
strike: ["s", "del"],
|
|
50412
|
+
del: ["s", "strike"]
|
|
50413
|
+
};
|
|
50414
|
+
var para = (inner, allow) => allow.has("p") ? `<p>${inner}</p>` : inner;
|
|
50415
|
+
var lineBreak = (allow) => allow.has("br") ? "<br>" : " ";
|
|
50416
|
+
function listLines(el, o, allow) {
|
|
50417
|
+
const ordered = el.tag === "ol";
|
|
50418
|
+
const startAttr = Number(attr(el.attrs, "start"));
|
|
50419
|
+
let n = ordered && Number.isInteger(startAttr) && startAttr >= 0 ? startAttr : 1;
|
|
50420
|
+
let out = "";
|
|
50421
|
+
let lines = [];
|
|
50422
|
+
const flush = () => {
|
|
50423
|
+
if (lines.length > 0)
|
|
50424
|
+
out += para(lines.join(lineBreak(allow)), allow);
|
|
50425
|
+
lines = [];
|
|
50426
|
+
};
|
|
50427
|
+
for (const li of el.children) {
|
|
50428
|
+
if (typeof li === "string" || li.tag !== "li")
|
|
50429
|
+
continue;
|
|
50430
|
+
const marker = ordered ? `${n++}. ` : "- ";
|
|
50431
|
+
const text = [];
|
|
50432
|
+
const nested = [];
|
|
50433
|
+
for (const c of li.children) {
|
|
50434
|
+
if (typeof c !== "string" && (c.tag === "ul" || c.tag === "ol"))
|
|
50435
|
+
nested.push(c);
|
|
50436
|
+
else
|
|
50437
|
+
text.push(c);
|
|
50438
|
+
}
|
|
50439
|
+
lines.push(marker + serialise(text, o, allow).trim());
|
|
50440
|
+
const blocks = nested.map((c) => serialise([c], o, allow)).join("");
|
|
50441
|
+
if (/^<(ul|ol|p)\b/.test(blocks)) {
|
|
50442
|
+
flush();
|
|
50443
|
+
out += blocks;
|
|
50444
|
+
} else if (blocks !== "")
|
|
50445
|
+
lines.push(blocks);
|
|
50446
|
+
}
|
|
50447
|
+
flush();
|
|
50448
|
+
return allow.has("p") ? out : out.replace(/<br>$/, "");
|
|
50449
|
+
}
|
|
50450
|
+
function outsideSubset(n, inner, o, allow) {
|
|
50451
|
+
const same = EQUIVALENT[n.tag]?.find((t) => allow.has(t));
|
|
50452
|
+
if (same !== void 0)
|
|
50453
|
+
return `<${same}>${inner}</${same}>`;
|
|
50454
|
+
switch (n.tag) {
|
|
50455
|
+
case "a": {
|
|
50456
|
+
const href = safeHref(n.attrs);
|
|
50457
|
+
if (href === void 0)
|
|
50458
|
+
return inner;
|
|
50459
|
+
const shown3 = escapeHtml(href);
|
|
50460
|
+
const label = inner.trim();
|
|
50461
|
+
return label === "" || label === shown3 || LOOKS_LIKE_ADDRESS.test(label) ? shown3 : `${inner} (${shown3})`;
|
|
50462
|
+
}
|
|
50463
|
+
case "ol":
|
|
50464
|
+
case "ul":
|
|
50465
|
+
return listLines(n, o, allow);
|
|
50466
|
+
case "li":
|
|
50467
|
+
return inner;
|
|
50468
|
+
case "pre":
|
|
50469
|
+
return para(inner.replace(/^\n+|\n+$/g, "").replace(/\n/g, lineBreak(allow)), allow);
|
|
50470
|
+
case "br":
|
|
50471
|
+
return " ";
|
|
50472
|
+
case "h1":
|
|
50473
|
+
case "h2":
|
|
50474
|
+
case "h3":
|
|
50475
|
+
case "h4":
|
|
50476
|
+
case "h5":
|
|
50477
|
+
case "h6": {
|
|
50478
|
+
const bold = ["b", "strong"].find((t) => allow.has(t));
|
|
50479
|
+
return para(bold === void 0 ? inner : `<${bold}>${inner}</${bold}>`, allow);
|
|
50480
|
+
}
|
|
50481
|
+
default:
|
|
50482
|
+
return inner;
|
|
50483
|
+
}
|
|
50484
|
+
}
|
|
50485
|
+
function sanitiseHtml(html, opts = {}) {
|
|
50486
|
+
const allow = opts.tags === void 0 ? void 0 : new Set([...opts.tags].map((t) => t.toLowerCase()));
|
|
50487
|
+
return serialise(parseHtml(html, opts).children, opts, allow);
|
|
50488
|
+
}
|
|
50489
|
+
var FORMATTING = /<(?!\/?(?:p|div|br)>)[a-z]/i;
|
|
50490
|
+
function walk(nodes, visit2) {
|
|
50491
|
+
for (const n of nodes) {
|
|
50492
|
+
if (typeof n === "string")
|
|
50493
|
+
continue;
|
|
50494
|
+
visit2(n);
|
|
50495
|
+
walk(n.children, visit2);
|
|
50496
|
+
}
|
|
50497
|
+
}
|
|
50498
|
+
function textOf(nodes, o) {
|
|
50499
|
+
return toText(nodes, o).replace(/[\u0001-\u0005]/g, " ").replace(/\s+/g, " ").trim();
|
|
50500
|
+
}
|
|
50501
|
+
function links(root, o) {
|
|
50502
|
+
const out = [];
|
|
50503
|
+
const seen = /* @__PURE__ */ new Set();
|
|
50504
|
+
walk(root.children, (el) => {
|
|
50505
|
+
if (el.tag !== "a")
|
|
50506
|
+
return;
|
|
50507
|
+
const href = safeHref(el.attrs);
|
|
50508
|
+
if (href === void 0)
|
|
50509
|
+
return;
|
|
50510
|
+
const text = textOf(el.children, o);
|
|
50511
|
+
const key = `${href}
|
|
50512
|
+
${text}`;
|
|
50513
|
+
if (seen.has(key))
|
|
50514
|
+
return;
|
|
50515
|
+
seen.add(key);
|
|
50516
|
+
out.push({ href, text });
|
|
50517
|
+
});
|
|
50518
|
+
return out;
|
|
50519
|
+
}
|
|
50520
|
+
function bodyStructure(html, opts = {}) {
|
|
50521
|
+
const root = parseHtml(html, opts);
|
|
50522
|
+
const sanitised = serialise(root.children, opts);
|
|
50523
|
+
return { ...FORMATTING.test(sanitised) ? { contentHtml: sanitised } : {}, links: links(root, { ...opts }) };
|
|
50524
|
+
}
|
|
50525
|
+
var QUOTE_OPEN = "";
|
|
50526
|
+
var QUOTE_CLOSE = "";
|
|
50527
|
+
var PARA = "";
|
|
50528
|
+
var BR = "";
|
|
50529
|
+
var MARKS = /[\u0004\u0005]/g;
|
|
50530
|
+
var paraBlock = (inner) => `
|
|
50531
|
+
${PARA}
|
|
50532
|
+
${inner}
|
|
50533
|
+
${PARA}
|
|
50534
|
+
`;
|
|
50535
|
+
var TEXT_BLOCK = /* @__PURE__ */ new Set(["p", "div", "h1", "h2", "h3", "h4", "h5", "h6", "table", "hr"]);
|
|
50536
|
+
var LOOKS_LIKE_ADDRESS = /^(https?:\/\/|www\.)/i;
|
|
50537
|
+
function linkText(el, label) {
|
|
50538
|
+
const url2 = safeHref(el.attrs);
|
|
50539
|
+
if (url2 === void 0)
|
|
50540
|
+
return label;
|
|
50541
|
+
const shown3 = label.trim();
|
|
50542
|
+
if (shown3 === "" || shown3 === url2 || LOOKS_LIKE_ADDRESS.test(shown3))
|
|
50543
|
+
return url2;
|
|
50544
|
+
return `${label} (${url2})`;
|
|
50545
|
+
}
|
|
50546
|
+
function rowText(tr, o) {
|
|
50547
|
+
const cells = tr.children.filter((n) => typeof n !== "string" && (n.tag === "td" || n.tag === "th"));
|
|
50548
|
+
if (cells.length === 0)
|
|
50549
|
+
return toText(tr.children, o);
|
|
50550
|
+
const raw = cells.map((c) => toText(c.children, o));
|
|
50551
|
+
const filled = raw.filter((t) => t.replace(/[\s\u0001-\u0005]+/g, "") !== "");
|
|
50552
|
+
if (filled.length === 1)
|
|
50553
|
+
return filled[0];
|
|
50554
|
+
const texts = raw.map((t) => t.replace(/[\n\u0001-\u0005]+/g, " ").trim());
|
|
50555
|
+
while (texts.length > 0 && texts[texts.length - 1] === "")
|
|
50556
|
+
texts.pop();
|
|
50557
|
+
return texts.join(" | ");
|
|
50558
|
+
}
|
|
50559
|
+
function toText(nodes, o) {
|
|
50560
|
+
const memo3 = o.textMemo ??= /* @__PURE__ */ new WeakMap();
|
|
50561
|
+
const hit = memo3.get(nodes);
|
|
50562
|
+
if (hit !== void 0)
|
|
50563
|
+
return hit;
|
|
50564
|
+
let out = "";
|
|
50565
|
+
for (const n of nodes) {
|
|
50566
|
+
if (typeof n === "string") {
|
|
50567
|
+
out += visible(decodeEntities(n));
|
|
50568
|
+
continue;
|
|
50569
|
+
}
|
|
50570
|
+
if (n.tag === "br") {
|
|
50571
|
+
out += `
|
|
50572
|
+
${BR}`;
|
|
50573
|
+
continue;
|
|
50574
|
+
}
|
|
50575
|
+
const code2 = n.tag === "code" || n.tag === "pre";
|
|
50576
|
+
const inner = n.tag === "img" ? "" : code2 ? codeText(n.children) : toText(n.children, o);
|
|
50577
|
+
const hooked = o.element?.(n, "text", inner);
|
|
50578
|
+
if (hooked !== void 0)
|
|
50579
|
+
out += hooked;
|
|
50580
|
+
else if (n.tag === "img")
|
|
50581
|
+
out += defaultImageText(n);
|
|
50582
|
+
else if (n.tag === "a")
|
|
50583
|
+
out += linkText(n, inner);
|
|
50584
|
+
else if (n.tag === "tr")
|
|
50585
|
+
out += `
|
|
50586
|
+
${rowText(n, o)}
|
|
50587
|
+
`;
|
|
50588
|
+
else if (n.tag === "blockquote")
|
|
50589
|
+
out += paraBlock(`${QUOTE_OPEN}
|
|
50590
|
+
${inner}
|
|
50591
|
+
${QUOTE_CLOSE}`);
|
|
50592
|
+
else if (n.tag === "ol" || n.tag === "ul") {
|
|
50593
|
+
const start = Number(attr(n.attrs, "start"));
|
|
50594
|
+
let i = n.tag === "ol" && Number.isInteger(start) && start >= 0 ? start : 1;
|
|
50595
|
+
let items = "";
|
|
50596
|
+
for (const c of n.children) {
|
|
50597
|
+
if (typeof c !== "string" && c.tag === "li") {
|
|
50598
|
+
const text = toText(c.children, o).replace(/^[\s\u0004\u0005]+|[\s\u0004\u0005]+$/g, "");
|
|
50599
|
+
items += `
|
|
50600
|
+
${n.tag === "ol" ? `${i++}. ` : "- "}${text}
|
|
50601
|
+
`;
|
|
50602
|
+
} else
|
|
50603
|
+
items += toText([c], o);
|
|
50604
|
+
}
|
|
50605
|
+
out += paraBlock(items);
|
|
50606
|
+
} else if (n.tag === "pre" || TEXT_BLOCK.has(n.tag))
|
|
50607
|
+
out += paraBlock(inner);
|
|
50608
|
+
else if (n.tag === "li")
|
|
50609
|
+
out += `
|
|
50610
|
+
${inner}
|
|
50611
|
+
`;
|
|
50612
|
+
else
|
|
50613
|
+
out += inner;
|
|
50614
|
+
}
|
|
50615
|
+
memo3.set(nodes, out);
|
|
50616
|
+
return out;
|
|
50617
|
+
}
|
|
50618
|
+
function htmlToText(html, opts = {}) {
|
|
50619
|
+
const out = [];
|
|
50620
|
+
const paragraphs = opts.paragraphs === true;
|
|
50621
|
+
let depth = 0;
|
|
50622
|
+
let lastDepth = 0;
|
|
50623
|
+
let pendingBreak = false;
|
|
50624
|
+
for (const raw of toText(parseHtml(html, opts).children, { ...opts }).split(/\r?\n/)) {
|
|
50625
|
+
const line = raw.replace(/[ \t\u00a0]+/g, " ").trim();
|
|
50626
|
+
if (line === QUOTE_OPEN)
|
|
50627
|
+
depth++;
|
|
50628
|
+
else if (line === QUOTE_CLOSE)
|
|
50629
|
+
depth = Math.max(0, depth - 1);
|
|
50630
|
+
else if (line === PARA || line === BR)
|
|
50631
|
+
pendingBreak = paragraphs && out.length > 0;
|
|
50632
|
+
else {
|
|
50633
|
+
const text = line.replace(MARKS, "").trim();
|
|
50634
|
+
if (text === "")
|
|
50635
|
+
continue;
|
|
50636
|
+
if (pendingBreak)
|
|
50637
|
+
out.push("> ".repeat(Math.min(depth, lastDepth)).trimEnd());
|
|
50638
|
+
pendingBreak = false;
|
|
50639
|
+
out.push(`${"> ".repeat(depth)}${text}`);
|
|
50640
|
+
lastDepth = depth;
|
|
50641
|
+
}
|
|
50642
|
+
}
|
|
50643
|
+
return out.join("\n");
|
|
50644
|
+
}
|
|
50645
|
+
var CODE_HOLE = "";
|
|
50646
|
+
var block = (s) => `
|
|
50647
|
+
|
|
50648
|
+
${s}
|
|
50649
|
+
|
|
50650
|
+
`;
|
|
50651
|
+
function wrap(marker, inner) {
|
|
50652
|
+
const m = /^(\s*)([\s\S]*?)(\s*)$/.exec(inner);
|
|
50653
|
+
return m[2] === "" ? inner : `${m[1]}${marker}${m[2]}${marker}${m[3]}`;
|
|
50654
|
+
}
|
|
50655
|
+
function codeText(nodes) {
|
|
50656
|
+
return nodes.map((n) => typeof n === "string" ? decodeEntities(n) : n.tag === "br" ? "\n" : codeText(n.children)).join("");
|
|
50657
|
+
}
|
|
50658
|
+
function inlineCode(text) {
|
|
50659
|
+
const longest = Math.max(0, ...[...text.matchAll(/`+/g)].map((m) => m[0].length));
|
|
50660
|
+
const fence = "`".repeat(longest + 1);
|
|
50661
|
+
const pad2 = text.startsWith("`") || text.endsWith("`") ? " " : "";
|
|
50662
|
+
return `${fence}${pad2}${text}${pad2}${fence}`;
|
|
50663
|
+
}
|
|
50664
|
+
var tidyInner = (s) => s.replace(/\n{3,}/g, "\n\n").trim();
|
|
50665
|
+
function list(el, codes, o) {
|
|
50666
|
+
const ordered = el.tag === "ol";
|
|
50667
|
+
const startAttr = Number(attr(el.attrs, "start"));
|
|
50668
|
+
const start = ordered && Number.isInteger(startAttr) && startAttr >= 0 ? startAttr : 1;
|
|
50669
|
+
const items = el.children.filter((n) => typeof n !== "string" && n.tag === "li");
|
|
50670
|
+
return items.map((li, i) => {
|
|
50671
|
+
const marker = ordered ? `${start + i}. ` : "- ";
|
|
50672
|
+
const lines = md(li.children, codes, o).replace(/\n{2,}/g, "\n").trim().split("\n");
|
|
50673
|
+
return lines.map((l, n) => n === 0 ? marker + l : l === "" ? "" : " ".repeat(marker.length) + l).join("\n");
|
|
50674
|
+
}).join("\n");
|
|
50675
|
+
}
|
|
50676
|
+
function rowsOf(el) {
|
|
50677
|
+
const out = [];
|
|
50678
|
+
for (const n of el.children) {
|
|
50679
|
+
if (typeof n === "string")
|
|
50680
|
+
continue;
|
|
50681
|
+
if (n.tag === "tr")
|
|
50682
|
+
out.push(n);
|
|
50683
|
+
else if (n.tag === "thead" || n.tag === "tbody" || n.tag === "tfoot")
|
|
50684
|
+
out.push(...rowsOf(n));
|
|
50685
|
+
}
|
|
50686
|
+
return out;
|
|
50687
|
+
}
|
|
50688
|
+
function table(el, codes, o) {
|
|
50689
|
+
const cellsOf = (tr) => tr.children.filter((n) => typeof n !== "string" && (n.tag === "td" || n.tag === "th")).map((c) => tidyInner(md(c.children, codes, o)));
|
|
50690
|
+
const raw = rowsOf(el).map(cellsOf).filter((cells) => cells.some((c) => c !== ""));
|
|
50691
|
+
if (raw.length === 0)
|
|
50692
|
+
return "";
|
|
50693
|
+
if (raw.every((cells) => cells.filter((c) => c !== "").length <= 1)) {
|
|
50694
|
+
return raw.map((cells) => cells.find((c) => c !== "") ?? "").join("\n\n");
|
|
50695
|
+
}
|
|
50696
|
+
if (raw.length === 1)
|
|
50697
|
+
return raw[0].filter((c) => c !== "").join(" ");
|
|
50698
|
+
const lines = raw.map((cells) => cells.map((c) => c.replace(/\s*\n\s*/g, " ").replace(/\|/g, "\\|")));
|
|
50699
|
+
const width = Math.max(...lines.map((cells) => cells.length));
|
|
50700
|
+
const row = (cells) => `| ${[...cells, ...Array(width - cells.length).fill("")].join(" | ")} |`;
|
|
50701
|
+
const sep2 = `| ${Array.from({ length: width }, () => "---").join(" | ")} |`;
|
|
50702
|
+
return [row(lines[0]), sep2, ...lines.slice(1).map(row)].join("\n");
|
|
50703
|
+
}
|
|
50704
|
+
function md(nodes, codes, o) {
|
|
50705
|
+
const memo3 = o.mdMemo ??= /* @__PURE__ */ new WeakMap();
|
|
50706
|
+
const hit = memo3.get(nodes);
|
|
50707
|
+
if (hit !== void 0)
|
|
50708
|
+
return hit;
|
|
50709
|
+
let out = "";
|
|
50710
|
+
for (const n of nodes) {
|
|
50711
|
+
if (typeof n === "string") {
|
|
50712
|
+
out += visible(decodeEntities(n)).replace(/[\s\u00a0]+/g, " ");
|
|
50713
|
+
continue;
|
|
50714
|
+
}
|
|
50715
|
+
const inner = () => md(n.children, codes, o);
|
|
50716
|
+
if (o.element !== void 0 && n.tag !== "br") {
|
|
50717
|
+
const hooked = o.element(n, "markdown", n.tag === "img" ? "" : inner());
|
|
50718
|
+
if (hooked !== void 0) {
|
|
50719
|
+
out += hooked;
|
|
50720
|
+
continue;
|
|
50721
|
+
}
|
|
50722
|
+
}
|
|
50723
|
+
switch (n.tag) {
|
|
50724
|
+
case "br":
|
|
50725
|
+
out += "\n";
|
|
50726
|
+
break;
|
|
50727
|
+
case "p":
|
|
50728
|
+
case "div":
|
|
50729
|
+
out += block(inner().trim());
|
|
50730
|
+
break;
|
|
50731
|
+
case "hr":
|
|
50732
|
+
out += block("---");
|
|
50733
|
+
break;
|
|
50734
|
+
case "h1":
|
|
50735
|
+
case "h2":
|
|
50736
|
+
case "h3":
|
|
50737
|
+
case "h4":
|
|
50738
|
+
case "h5":
|
|
50739
|
+
case "h6": {
|
|
50740
|
+
const text = inner().replace(/\s+/g, " ").trim();
|
|
50741
|
+
out += text === "" ? "" : block(`${"#".repeat(Number(n.tag[1]))} ${text}`);
|
|
50742
|
+
break;
|
|
50743
|
+
}
|
|
50744
|
+
case "b":
|
|
50745
|
+
case "strong":
|
|
50746
|
+
out += wrap("**", inner());
|
|
50747
|
+
break;
|
|
50748
|
+
case "i":
|
|
50749
|
+
case "em":
|
|
50750
|
+
out += wrap("_", inner());
|
|
50751
|
+
break;
|
|
50752
|
+
case "s":
|
|
50753
|
+
case "strike":
|
|
50754
|
+
case "del":
|
|
50755
|
+
out += wrap("~~", inner());
|
|
50756
|
+
break;
|
|
50757
|
+
case "code":
|
|
50758
|
+
out += inlineCode(codeText(n.children));
|
|
50759
|
+
break;
|
|
50760
|
+
case "pre": {
|
|
50761
|
+
codes.push("```\n" + codeText(n.children).replace(/\n+$/, "") + "\n```");
|
|
50762
|
+
out += block(`${CODE_HOLE}${codes.length - 1}${CODE_HOLE}`);
|
|
50763
|
+
break;
|
|
50764
|
+
}
|
|
50765
|
+
case "a": {
|
|
50766
|
+
const label = inner().trim().replace(/^\[([^\[\]]*)\]$/, "$1");
|
|
50767
|
+
const href = safeHref(n.attrs);
|
|
50768
|
+
if (href === void 0)
|
|
50769
|
+
out += label;
|
|
50770
|
+
else if (label === "" || label === href || LOOKS_LIKE_ADDRESS.test(label))
|
|
50771
|
+
out += href;
|
|
50772
|
+
else
|
|
50773
|
+
out += `[${label}](${href.replace(/[()\s]/g, (c) => encodeURIComponent(c))})`;
|
|
50774
|
+
break;
|
|
50775
|
+
}
|
|
50776
|
+
case "blockquote":
|
|
50777
|
+
out += block(tidyInner(inner()).split("\n").map((l) => l === "" ? ">" : `> ${l}`).join("\n"));
|
|
50778
|
+
break;
|
|
50779
|
+
case "ul":
|
|
50780
|
+
case "ol":
|
|
50781
|
+
out += block(list(n, codes, o));
|
|
50782
|
+
break;
|
|
50783
|
+
case "table":
|
|
50784
|
+
out += block(table(n, codes, o));
|
|
50785
|
+
break;
|
|
50786
|
+
case "img":
|
|
50787
|
+
out += defaultImageText(n);
|
|
50788
|
+
break;
|
|
50789
|
+
default:
|
|
50790
|
+
out += inner();
|
|
50791
|
+
}
|
|
50792
|
+
}
|
|
50793
|
+
memo3.set(nodes, out);
|
|
50794
|
+
return out;
|
|
50795
|
+
}
|
|
50796
|
+
function htmlToMarkdown(html, opts = {}) {
|
|
50797
|
+
const codes = [];
|
|
50798
|
+
const lines = md(parseHtml(html, opts).children, codes, { ...opts }).split("\n");
|
|
50799
|
+
const tidy = [];
|
|
50800
|
+
for (const raw of lines) {
|
|
50801
|
+
const line = raw.trimEnd();
|
|
50802
|
+
tidy.push(tidy.length === 0 || tidy[tidy.length - 1] === "" ? line.trimStart() : line);
|
|
50803
|
+
}
|
|
50804
|
+
return tidy.join("\n").replace(/\n{3,}/g, "\n\n").trim().replace(new RegExp(`${CODE_HOLE}(\\d+)${CODE_HOLE}`, "g"), (_w, i) => codes[Number(i)]);
|
|
50805
|
+
}
|
|
50806
|
+
|
|
50807
|
+
// node_modules/@chrischall/mcp-utils/dist/rich/markdown.js
|
|
50808
|
+
var HOLE_OPEN = "\uE000";
|
|
50809
|
+
var HOLE_CLOSE = "\uE001";
|
|
50810
|
+
var RESERVED2 = /[-]/g;
|
|
50811
|
+
var SAFE_HREF = /^(https?:\/\/|mailto:)/i;
|
|
50812
|
+
function renderInline(src, o) {
|
|
50813
|
+
const holes = [];
|
|
50814
|
+
const hole = (html) => `${HOLE_OPEN}${holes.push(html) - 1}${HOLE_CLOSE}`;
|
|
50815
|
+
const token = /(`+)([\s\S]*?[^`])\1(?!`)|\[([^\]\n]+)\]\(\s*([^\s()]+(?:\([^\s()]*\)[^\s()]*)*)\s*\)|\\([\\`*_{}[\]()#+\-.!~>|:])/g;
|
|
50816
|
+
let s = src.replace(token, (whole, _ticks, code2, label, href, escaped) => {
|
|
50817
|
+
if (code2 !== void 0)
|
|
50818
|
+
return hole(`<code>${escapeHtml(code2.replace(/^ (.*[^ ].*) $/s, "$1"))}</code>`);
|
|
50819
|
+
if (escaped !== void 0)
|
|
50820
|
+
return hole(escapeHtml(escaped));
|
|
50821
|
+
if (!SAFE_HREF.test(href))
|
|
50822
|
+
return whole;
|
|
50823
|
+
return hole(`<a href="${escapeHtml(href)}">${renderInline(label, o)}</a>`);
|
|
50824
|
+
});
|
|
50825
|
+
if (o.shortcode !== void 0) {
|
|
50826
|
+
const render2 = o.shortcode;
|
|
50827
|
+
s = s.replace(/:([a-z0-9_+-]+):/g, (whole, key) => {
|
|
50828
|
+
const html = render2(key);
|
|
50829
|
+
return html === void 0 ? whole : hole(html);
|
|
50830
|
+
});
|
|
50831
|
+
}
|
|
50832
|
+
s = escapeHtml(s).replace(/\*\*(?=\S)([\s\S]*?\S)\*\*/g, "<strong>$1</strong>").replace(/(^|[^\w])__(?=\S)([\s\S]*?\S)__(?!\w)/g, "$1<strong>$2</strong>").replace(/~~(?=\S)([\s\S]*?\S)~~/g, "<s>$1</s>").replace(/(^|[^\w*])\*(?=[^\s*])([\s\S]*?[^\s*])\*(?![\w*])/g, "$1<em>$2</em>").replace(/(^|[^\w])_(?=[^\s_])([\s\S]*?[^\s_])_(?!\w)/g, "$1<em>$2</em>").replace(/\n/g, "<br>");
|
|
50833
|
+
const fill = new RegExp(`${HOLE_OPEN}(\\d+)${HOLE_CLOSE}`, "g");
|
|
50834
|
+
return s.replace(fill, (_w, n) => holes[Number(n)]);
|
|
50835
|
+
}
|
|
50836
|
+
var LIST_ITEM = /^( *)([-*+]|\d{1,9}[.)])[ \t]+(.*)$/;
|
|
50837
|
+
var HEADING = /^ {0,3}(#{1,6})[ \t]+(.+?)[ \t]*#*[ \t]*$/;
|
|
50838
|
+
var QUOTE = /^ {0,3}> ?(.*)$/;
|
|
50839
|
+
function renderList(list2, o) {
|
|
50840
|
+
const tag = list2.ordered ? "ol" : "ul";
|
|
50841
|
+
const start = list2.ordered && list2.start !== 1 ? ` start="${list2.start}"` : "";
|
|
50842
|
+
const items = list2.items.map((i) => `<li>${renderInline(i.lines.join("\n"), o)}${i.children.map((c) => renderList(c, o)).join("")}</li>`);
|
|
50843
|
+
return `<${tag}${start}>${items.join("")}</${tag}>`;
|
|
50844
|
+
}
|
|
50845
|
+
function parseList(lines, from, o) {
|
|
50846
|
+
const roots = [];
|
|
50847
|
+
const stack = [];
|
|
50848
|
+
let i = from;
|
|
50849
|
+
for (; i < lines.length; i++) {
|
|
50850
|
+
const line = lines[i];
|
|
50851
|
+
const m = LIST_ITEM.exec(line);
|
|
50852
|
+
if (m === null) {
|
|
50853
|
+
const last = stack.at(-1)?.items.at(-1);
|
|
50854
|
+
if (line.trim() !== "" && /^\s/.test(line) && last !== void 0) {
|
|
50855
|
+
last.lines.push(line.trim());
|
|
50856
|
+
continue;
|
|
50857
|
+
}
|
|
50858
|
+
break;
|
|
50859
|
+
}
|
|
50860
|
+
const indent = m[1].length;
|
|
50861
|
+
const ordered = /\d/.test(m[2]);
|
|
50862
|
+
while (stack.length > 0 && indent < stack[stack.length - 1].indent)
|
|
50863
|
+
stack.pop();
|
|
50864
|
+
let top = stack.at(-1);
|
|
50865
|
+
if (top !== void 0 && indent >= top.indent + 2 && top.items.length > 0) {
|
|
50866
|
+
const nested = { indent, ordered, start: ordered ? Number.parseInt(m[2], 10) : 1, items: [] };
|
|
50867
|
+
top.items[top.items.length - 1].children.push(nested);
|
|
50868
|
+
stack.push(nested);
|
|
50869
|
+
top = nested;
|
|
50870
|
+
} else if (top === void 0 || top.ordered !== ordered) {
|
|
50871
|
+
const fresh = { indent, ordered, start: ordered ? Number.parseInt(m[2], 10) : 1, items: [] };
|
|
50872
|
+
if (top !== void 0 && stack.length > 1) {
|
|
50873
|
+
stack.pop();
|
|
50874
|
+
stack[stack.length - 1].items.at(-1).children.push(fresh);
|
|
50875
|
+
} else {
|
|
50876
|
+
roots.push(fresh);
|
|
50877
|
+
stack.length = 0;
|
|
50878
|
+
}
|
|
50879
|
+
stack.push(fresh);
|
|
50880
|
+
top = fresh;
|
|
50881
|
+
}
|
|
50882
|
+
top.items.push({ lines: [m[3]], children: [] });
|
|
50883
|
+
}
|
|
50884
|
+
return { html: roots.map((r) => renderList(r, o)).join(""), next: i };
|
|
50885
|
+
}
|
|
50886
|
+
function render(src, o, depth) {
|
|
50887
|
+
const lines = src.split("\n");
|
|
50888
|
+
const out = [];
|
|
50889
|
+
let para2 = [];
|
|
50890
|
+
const flush = () => {
|
|
50891
|
+
if (para2.length > 0)
|
|
50892
|
+
out.push(`<p>${renderInline(para2.join("\n"), o)}</p>`);
|
|
50893
|
+
para2 = [];
|
|
50894
|
+
};
|
|
50895
|
+
for (let i = 0; i < lines.length; ) {
|
|
50896
|
+
const line = lines[i];
|
|
50897
|
+
const fence = /^ {0,3}(`{3,}|~{3,})/.exec(line);
|
|
50898
|
+
if (fence !== null) {
|
|
50899
|
+
flush();
|
|
50900
|
+
const close = new RegExp(`^ {0,3}${fence[1][0] === "`" ? "`" : "~"}{${fence[1].length},}\\s*$`);
|
|
50901
|
+
const code2 = [];
|
|
50902
|
+
for (i++; i < lines.length && !close.test(lines[i]); i++)
|
|
50903
|
+
code2.push(lines[i]);
|
|
50904
|
+
i++;
|
|
50905
|
+
out.push(`<pre><code>${escapeHtml(code2.join("\n"))}</code></pre>`);
|
|
50906
|
+
continue;
|
|
50907
|
+
}
|
|
50908
|
+
if (LIST_ITEM.test(line)) {
|
|
50909
|
+
flush();
|
|
50910
|
+
const { html, next } = parseList(lines, i, o);
|
|
50911
|
+
out.push(html);
|
|
50912
|
+
i = next;
|
|
50913
|
+
continue;
|
|
50914
|
+
}
|
|
50915
|
+
const heading = o.headings === true ? HEADING.exec(line) : null;
|
|
50916
|
+
if (heading !== null) {
|
|
50917
|
+
flush();
|
|
50918
|
+
const level = heading[1].length;
|
|
50919
|
+
out.push(`<h${level}>${renderInline(heading[2], o)}</h${level}>`);
|
|
50920
|
+
i++;
|
|
50921
|
+
continue;
|
|
50922
|
+
}
|
|
50923
|
+
if (o.quotes === true && depth < 20 && QUOTE.test(line)) {
|
|
50924
|
+
flush();
|
|
50925
|
+
const quoted2 = [];
|
|
50926
|
+
for (; i < lines.length; i++) {
|
|
50927
|
+
const q = QUOTE.exec(lines[i]);
|
|
50928
|
+
if (q === null)
|
|
50929
|
+
break;
|
|
50930
|
+
quoted2.push(q[1]);
|
|
50931
|
+
}
|
|
50932
|
+
out.push(`<blockquote>${render(quoted2.join("\n"), o, depth + 1)}</blockquote>`);
|
|
50933
|
+
continue;
|
|
50934
|
+
}
|
|
50935
|
+
if (line.trim() === "")
|
|
50936
|
+
flush();
|
|
50937
|
+
else
|
|
50938
|
+
para2.push(line);
|
|
50939
|
+
i++;
|
|
50940
|
+
}
|
|
50941
|
+
flush();
|
|
50942
|
+
return out.join("");
|
|
50943
|
+
}
|
|
50944
|
+
function renderMarkdown(src, opts = {}) {
|
|
50945
|
+
return render(src.replace(/\r\n?/g, "\n").replace(RESERVED2, ""), opts, 0);
|
|
50946
|
+
}
|
|
50947
|
+
|
|
50948
|
+
// src/rich.ts
|
|
50949
|
+
var MENTION_TYPE = "http://schema.skype.com/Mention";
|
|
50950
|
+
var EMOJI_TYPE = /schema\.skype\.com\/Emoji/i;
|
|
50951
|
+
var TEAMS = {
|
|
50952
|
+
element: (el, output2, inner) => {
|
|
50953
|
+
if (el.tag === "img") {
|
|
50954
|
+
const alt = attr(el.attrs, "alt");
|
|
50955
|
+
const text = EMOJI_TYPE.test(attr(el.attrs, "itemtype") ?? "") && alt ? decodeEntities(alt) : "[image]";
|
|
50956
|
+
return output2 === "html" ? escapeHtml(text) : text;
|
|
50957
|
+
}
|
|
50958
|
+
if (el.tag === "span" && attr(el.attrs, "itemtype") === MENTION_TYPE) {
|
|
50959
|
+
if (output2 === "markdown") return `@${inner.trim()}`;
|
|
50960
|
+
if (output2 === "html") {
|
|
50961
|
+
const id = attr(el.attrs, "itemid");
|
|
50962
|
+
const itemid = id !== void 0 && /^\d+$/.test(id) ? ` itemid="${id}"` : "";
|
|
50963
|
+
return `<span itemtype="${MENTION_TYPE}"${itemid}>${inner}</span>`;
|
|
50964
|
+
}
|
|
50965
|
+
}
|
|
50966
|
+
return void 0;
|
|
50967
|
+
}
|
|
50968
|
+
};
|
|
50969
|
+
function sanitiseHtml2(html) {
|
|
50970
|
+
return sanitiseHtml(html, TEAMS);
|
|
50971
|
+
}
|
|
50972
|
+
function bodyStructure2(html) {
|
|
50973
|
+
return bodyStructure(html, TEAMS);
|
|
50974
|
+
}
|
|
50975
|
+
function htmlToText2(html) {
|
|
50976
|
+
return htmlToText(html, TEAMS);
|
|
50977
|
+
}
|
|
50978
|
+
function htmlToMarkdown2(html) {
|
|
50979
|
+
return htmlToMarkdown(html, TEAMS);
|
|
50980
|
+
}
|
|
50981
|
+
function mentionsOf(raw) {
|
|
50982
|
+
let parsed = raw;
|
|
50983
|
+
if (typeof raw === "string") {
|
|
50984
|
+
try {
|
|
50985
|
+
parsed = JSON.parse(raw);
|
|
50986
|
+
} catch {
|
|
50987
|
+
return [];
|
|
50988
|
+
}
|
|
50989
|
+
}
|
|
50990
|
+
if (!Array.isArray(parsed)) return [];
|
|
50991
|
+
const out = [];
|
|
50992
|
+
for (const e of parsed) {
|
|
50993
|
+
if (e === null || typeof e !== "object") continue;
|
|
50994
|
+
const { mri, displayName } = e;
|
|
50995
|
+
if (typeof mri !== "string" || mri === "") continue;
|
|
50996
|
+
out.push({ mri, displayName: typeof displayName === "string" ? displayName : "" });
|
|
50997
|
+
}
|
|
50998
|
+
return out;
|
|
50999
|
+
}
|
|
51000
|
+
|
|
50249
51001
|
// src/model.ts
|
|
50250
51002
|
var SELF_CHAT = "48:notes";
|
|
50251
51003
|
var SELF_CHAT_TITLE = "Notes (self-chat)";
|
|
@@ -50394,7 +51146,7 @@ function conversationSummary(c, meMri, all = []) {
|
|
|
50394
51146
|
if (teamThread !== void 0) team = teamName(teamThread);
|
|
50395
51147
|
}
|
|
50396
51148
|
const lastActivity = last ? toIso(last.originalarrivaltime) ?? toIso(last.composetime) : void 0;
|
|
50397
|
-
const preview = systemEvent ? SYSTEM_EVENT_PREVIEW : last?.content !== void 0 ?
|
|
51149
|
+
const preview = systemEvent ? SYSTEM_EVENT_PREVIEW : last?.content !== void 0 ? htmlToText2(last.content) : void 0;
|
|
50398
51150
|
const unread = isUnreadCandidate(c, meMri);
|
|
50399
51151
|
const hidden = kind === "channel" && isHiddenChannel(c);
|
|
50400
51152
|
return {
|
|
@@ -50417,70 +51169,6 @@ function conversationSummary(c, meMri, all = []) {
|
|
|
50417
51169
|
function truncate(s, max) {
|
|
50418
51170
|
return s.length <= max ? s : `${s.slice(0, max - 1)}\u2026`;
|
|
50419
51171
|
}
|
|
50420
|
-
var QUOTE_OPEN = "";
|
|
50421
|
-
var QUOTE_CLOSE = "";
|
|
50422
|
-
var NAMED_ENTITIES = {
|
|
50423
|
-
amp: "&",
|
|
50424
|
-
lt: "<",
|
|
50425
|
-
gt: ">",
|
|
50426
|
-
quot: '"',
|
|
50427
|
-
apos: "'",
|
|
50428
|
-
nbsp: " "
|
|
50429
|
-
};
|
|
50430
|
-
function decodeEntities(s) {
|
|
50431
|
-
return s.replace(/&(?:#(\d+)|#x([0-9a-f]+)|([a-z]+));/gi, (whole, dec2, hex3, name) => {
|
|
50432
|
-
if (name !== void 0) return NAMED_ENTITIES[name.toLowerCase()] ?? whole;
|
|
50433
|
-
const code2 = dec2 !== void 0 ? Number(dec2) : parseInt(hex3, 16);
|
|
50434
|
-
if (!Number.isFinite(code2) || code2 > 1114111) return whole;
|
|
50435
|
-
if (code2 < 32 && code2 !== 9 && code2 !== 10) return "";
|
|
50436
|
-
return String.fromCodePoint(code2);
|
|
50437
|
-
});
|
|
50438
|
-
}
|
|
50439
|
-
function attr(tag, name) {
|
|
50440
|
-
const m = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`, "i").exec(tag);
|
|
50441
|
-
return m ? m[1] ?? m[2] : void 0;
|
|
50442
|
-
}
|
|
50443
|
-
var stripTags = (s) => s.replace(/<\/?[a-z!][^>]*>/gi, "");
|
|
50444
|
-
function tableRow(row) {
|
|
50445
|
-
const cells = [...row.matchAll(/<t[dh]\b[^>]*>([\s\S]*?)(?:<\/t[dh]\s*>|(?=<t[dh]\b)|$)/gi)].map(
|
|
50446
|
-
([, cell]) => cell.replace(/[\u0001\u0002]/g, "").replace(/<br\s*\/?>|<\/?(p|div|li|h[1-6])\b[^>]*>|\r?\n/gi, " ").trim()
|
|
50447
|
-
);
|
|
50448
|
-
return cells.length > 0 ? cells.join(" | ") : row;
|
|
50449
|
-
}
|
|
50450
|
-
function htmlToText(html) {
|
|
50451
|
-
let s = html.replace(/[\u0001\u0002]/g, "");
|
|
50452
|
-
s = s.replace(/<(script|style)\b[\s\S]*?<\/\1\s*>/gi, "");
|
|
50453
|
-
s = s.replace(/<blockquote\b[^>]*>/gi, `
|
|
50454
|
-
${QUOTE_OPEN}
|
|
50455
|
-
`).replace(/<\/blockquote\s*>/gi, `
|
|
50456
|
-
${QUOTE_CLOSE}
|
|
50457
|
-
`);
|
|
50458
|
-
s = s.replace(/<img\b[^>]*>/gi, (tag) => {
|
|
50459
|
-
const alt = attr(tag, "alt");
|
|
50460
|
-
return /schema\.skype\.com\/Emoji/i.test(attr(tag, "itemtype") ?? "") && alt ? alt : "[image]";
|
|
50461
|
-
});
|
|
50462
|
-
s = s.replace(/<a\b([^>]*)>([\s\S]*?)<\/a\s*>/gi, (_whole, attrs, inner) => {
|
|
50463
|
-
const href = attr(` ${attrs}`, "href");
|
|
50464
|
-
const label = stripTags(inner).trim();
|
|
50465
|
-
if (!href) return inner;
|
|
50466
|
-
if (label === "" || label === href) return href;
|
|
50467
|
-
return `${inner} (${href})`;
|
|
50468
|
-
});
|
|
50469
|
-
s = s.replace(/<tr\b[^>]*>([\s\S]*?)<\/tr\s*>/gi, (_whole, row) => `
|
|
50470
|
-
${tableRow(row)}
|
|
50471
|
-
`);
|
|
50472
|
-
s = s.replace(/<br\s*\/?>/gi, "\n").replace(/<\/?(p|div|li|tr|h[1-6])\b[^>]*>/gi, "\n");
|
|
50473
|
-
s = decodeEntities(stripTags(s));
|
|
50474
|
-
const out = [];
|
|
50475
|
-
let depth = 0;
|
|
50476
|
-
for (const raw of s.split(/\r?\n/)) {
|
|
50477
|
-
const line = raw.replace(/[ \t ]+/g, " ").trim();
|
|
50478
|
-
if (line === QUOTE_OPEN) depth++;
|
|
50479
|
-
else if (line === QUOTE_CLOSE) depth = Math.max(0, depth - 1);
|
|
50480
|
-
else if (line !== "") out.push(`${"> ".repeat(depth)}${line}`);
|
|
50481
|
-
}
|
|
50482
|
-
return out.join("\n");
|
|
50483
|
-
}
|
|
50484
51172
|
function fileAttachments(raw) {
|
|
50485
51173
|
let parsed = raw;
|
|
50486
51174
|
if (typeof raw === "string") {
|
|
@@ -50605,17 +51293,23 @@ function normaliseMessage(m, meMri, opts = {}) {
|
|
|
50605
51293
|
const content = m.content ?? "";
|
|
50606
51294
|
const reactions = reactionsOf(props.emotions, meMri);
|
|
50607
51295
|
const timeLocal = opts.timeZone !== void 0 ? localIsoTime(time3, opts.timeZone) : void 0;
|
|
51296
|
+
const deleted = isDeleted(m);
|
|
51297
|
+
const { contentHtml, links: links2 } = deleted ? { links: [] } : bodyStructure2(content);
|
|
51298
|
+
const mentions = deleted ? [] : mentionsOf(props.mentions);
|
|
50608
51299
|
return {
|
|
50609
51300
|
id: m.id,
|
|
50610
51301
|
time: time3,
|
|
50611
51302
|
...timeLocal !== void 0 ? { time_local: timeLocal } : {},
|
|
50612
51303
|
sender: nonEmpty(m.imdisplayname) ?? mri ?? "unknown",
|
|
50613
51304
|
fromMe: mri !== void 0 && mri === meMri,
|
|
50614
|
-
text:
|
|
51305
|
+
text: htmlToText2(content),
|
|
51306
|
+
...contentHtml !== void 0 ? { content_html: contentHtml } : {},
|
|
51307
|
+
...mentions.length > 0 ? { mentions } : {},
|
|
51308
|
+
...links2.length > 0 ? { links: links2 } : {},
|
|
50615
51309
|
...subject !== void 0 ? { subject } : {},
|
|
50616
51310
|
...root !== void 0 && root !== m.id ? { replyTo: root } : {},
|
|
50617
51311
|
edited: props.edittime !== void 0 && props.edittime !== null && props.edittime !== "",
|
|
50618
|
-
...
|
|
51312
|
+
...deleted ? { deleted: true } : {},
|
|
50619
51313
|
attachments: { files: fileAttachments(props.files), images: imageAttachments(content) },
|
|
50620
51314
|
...reactions.length > 0 ? { reactions } : {}
|
|
50621
51315
|
};
|
|
@@ -50706,8 +51400,8 @@ var TIMING = /^(\d{1,2}:)?\d{2}:\d{2}\.\d{3}\s+-->\s+((?:\d{1,2}:)?\d{2}:\d{2}\.
|
|
|
50706
51400
|
function parseVtt(vtt) {
|
|
50707
51401
|
const blocks = vtt.replace(/^/, "").replace(/\r\n?/g, "\n").split(/\n{2,}/);
|
|
50708
51402
|
const cues = [];
|
|
50709
|
-
for (const
|
|
50710
|
-
const lines =
|
|
51403
|
+
for (const block2 of blocks) {
|
|
51404
|
+
const lines = block2.split("\n").filter((l) => l.trim() !== "");
|
|
50711
51405
|
const at = lines.findIndex((l) => TIMING.test(l.trim()));
|
|
50712
51406
|
if (at < 0) continue;
|
|
50713
51407
|
const timing = lines[at].trim();
|
|
@@ -50798,6 +51492,8 @@ function outcomeUnknown(method, e, hint) {
|
|
|
50798
51492
|
}
|
|
50799
51493
|
var SEND_OUTCOME_HINT = "The message may already have been posted \u2014 check the conversation (teams_list_messages) before retrying; do not resend blindly.";
|
|
50800
51494
|
var REACTION_OUTCOME_HINT = "The reaction change may already have been applied \u2014 check the message (teams_list_messages) before retrying.";
|
|
51495
|
+
var EDIT_OUTCOME_HINT = "The edit may already have been applied \u2014 read the message (teams_list_messages) before retrying.";
|
|
51496
|
+
var DELETE_OUTCOME_HINT = "The message may already have been deleted \u2014 read the conversation (teams_list_messages) before retrying.";
|
|
50801
51497
|
var THREAD_OUTCOME_HINT = "The change to the chat may already have been applied \u2014 check the chat (its name and members) before retrying.";
|
|
50802
51498
|
var CREATE_OUTCOME_HINT = "A chat may already have been created \u2014 check teams_list_conversations before retrying; a blind retry would create a second chat (and a chat cannot be deleted).";
|
|
50803
51499
|
var HORIZON_OUTCOME_HINT = "The read marker may already have moved \u2014 check the conversation (teams_list_messages) before retrying; moving it again to the same message is harmless.";
|
|
@@ -50985,6 +51681,32 @@ var ChatServiceClient = class {
|
|
|
50985
51681
|
const id = /\/messages\/([^/?#]+)\/?(?:[?#].*)?$/.exec(headers.get("location") ?? "")?.[1];
|
|
50986
51682
|
return id !== void 0 ? { id: decodeURIComponent(id) } : {};
|
|
50987
51683
|
}
|
|
51684
|
+
/**
|
|
51685
|
+
* Replace one of the user's own messages: `PUT …/messages/{id}` with the
|
|
51686
|
+
* new body (`teams_edit_message` builds it). An edit is idempotent, but a
|
|
51687
|
+
* request that was sent and got no usable answer is still a
|
|
51688
|
+
* `WriteOutcomeUnknownError`, so the tool reads the message back rather
|
|
51689
|
+
* than report a plain failure for a change that may have landed.
|
|
51690
|
+
*/
|
|
51691
|
+
async editMessage(conversationId, messageId2, body) {
|
|
51692
|
+
this.#requireConfigured();
|
|
51693
|
+
const url2 = `${this.#baseUrl}/users/ME/conversations/${encodeURIComponent(conversationId)}/messages/${encodeURIComponent(messageId2)}`;
|
|
51694
|
+
const { status } = await this.#send(url2, "text", void 0, { method: "PUT", body, hint: EDIT_OUTCOME_HINT });
|
|
51695
|
+
this.#checkWriteStatus("PUT", status, EDIT_OUTCOME_HINT);
|
|
51696
|
+
}
|
|
51697
|
+
/**
|
|
51698
|
+
* Delete one of the user's own messages: `DELETE …/messages/{id}`. Teams
|
|
51699
|
+
* keeps a deleted message in the conversation with `properties.deletetime`
|
|
51700
|
+
* set and no content. Deleting twice leaves it deleted, but a request that
|
|
51701
|
+
* was sent and got no usable answer is still a `WriteOutcomeUnknownError`,
|
|
51702
|
+
* so the tool reads the message back to settle it.
|
|
51703
|
+
*/
|
|
51704
|
+
async deleteMessage(conversationId, messageId2) {
|
|
51705
|
+
this.#requireConfigured();
|
|
51706
|
+
const url2 = `${this.#baseUrl}/users/ME/conversations/${encodeURIComponent(conversationId)}/messages/${encodeURIComponent(messageId2)}`;
|
|
51707
|
+
const { status } = await this.#send(url2, "text", void 0, { method: "DELETE", hint: DELETE_OUTCOME_HINT });
|
|
51708
|
+
this.#checkWriteStatus("DELETE", status, DELETE_OUTCOME_HINT);
|
|
51709
|
+
}
|
|
50988
51710
|
/**
|
|
50989
51711
|
* React to a message: `PUT …/messages/{id}/properties?name=emotions` with
|
|
50990
51712
|
* `{ emotions: { key, value: <epoch ms> } }` (captured live). Only the
|
|
@@ -52035,10 +52757,10 @@ function timespan(v) {
|
|
|
52035
52757
|
return m ? hms(Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3])) : void 0;
|
|
52036
52758
|
}
|
|
52037
52759
|
function parseCollabObject(body) {
|
|
52038
|
-
const
|
|
52039
|
-
if (!Array.isArray(
|
|
52760
|
+
const list2 = obj2(body)?.resources;
|
|
52761
|
+
if (!Array.isArray(list2)) return [];
|
|
52040
52762
|
const byId = /* @__PURE__ */ new Map();
|
|
52041
|
-
for (const raw of
|
|
52763
|
+
for (const raw of list2) {
|
|
52042
52764
|
const r = obj2(raw);
|
|
52043
52765
|
const id = str2(r?.id);
|
|
52044
52766
|
const type = str2(r?.type);
|
|
@@ -52068,36 +52790,36 @@ function summarizeRecap(resources) {
|
|
|
52068
52790
|
other: []
|
|
52069
52791
|
};
|
|
52070
52792
|
for (const r of resources) {
|
|
52071
|
-
const
|
|
52793
|
+
const md2 = r.metadata;
|
|
52072
52794
|
switch (r.type) {
|
|
52073
52795
|
case "Recording": {
|
|
52074
|
-
const started = ticksToIso(
|
|
52075
|
-
const ended = ticksToIso(
|
|
52796
|
+
const started = ticksToIso(md2.startTime);
|
|
52797
|
+
const ended = ticksToIso(md2.endTime);
|
|
52076
52798
|
const duration3 = started && ended ? hms((Date.parse(ended) - Date.parse(started)) / 1e3) : void 0;
|
|
52077
52799
|
out.recordings.push(compact({ started, ended, duration: duration3, url: httpsUrl(r.location) }));
|
|
52078
52800
|
break;
|
|
52079
52801
|
}
|
|
52080
52802
|
case "TranscriptV2":
|
|
52081
|
-
out.transcripts.push(compact({ started: ticksToIso(
|
|
52803
|
+
out.transcripts.push(compact({ started: ticksToIso(md2.startTime), duration: timespan(md2.duration), url: httpsUrl(md2.webUrl) }));
|
|
52082
52804
|
break;
|
|
52083
52805
|
case "transcript":
|
|
52084
|
-
out.transcripts.push(compact({ started: isoOf2(
|
|
52806
|
+
out.transcripts.push(compact({ started: isoOf2(md2.startTime), state: str2(md2.state) }));
|
|
52085
52807
|
break;
|
|
52086
52808
|
case "notes":
|
|
52087
52809
|
out.notes.push(compact({ url: httpsUrl(r.location), added: r.added }));
|
|
52088
52810
|
break;
|
|
52089
52811
|
case "AttendanceReport":
|
|
52090
|
-
out.attendance_reports.push(compact({ started: ticksToIso(
|
|
52812
|
+
out.attendance_reports.push(compact({ started: ticksToIso(md2.startTime), url: httpsUrl(md2.webUrl) ?? httpsUrl(r.location) }));
|
|
52091
52813
|
break;
|
|
52092
52814
|
case "MeetingChat":
|
|
52093
52815
|
case "MeetingStage":
|
|
52094
52816
|
out.files.push(
|
|
52095
52817
|
compact({
|
|
52096
|
-
name: str2(
|
|
52097
|
-
file_type: str2(
|
|
52098
|
-
app: str2(
|
|
52818
|
+
name: str2(md2.fileTitle),
|
|
52819
|
+
file_type: str2(md2.fileType),
|
|
52820
|
+
app: str2(md2.appTitle),
|
|
52099
52821
|
shared_in: r.type === "MeetingChat" ? "chat" : "meeting",
|
|
52100
|
-
url: httpsUrl(
|
|
52822
|
+
url: httpsUrl(md2.shareUrl) ?? httpsUrl(r.location),
|
|
52101
52823
|
added: r.added
|
|
52102
52824
|
})
|
|
52103
52825
|
);
|
|
@@ -53040,16 +53762,6 @@ init_dist2();
|
|
|
53040
53762
|
// src/compose.ts
|
|
53041
53763
|
init_dist2();
|
|
53042
53764
|
import { randomInt } from "node:crypto";
|
|
53043
|
-
var HTML_ESCAPES = {
|
|
53044
|
-
"&": "&",
|
|
53045
|
-
"<": "<",
|
|
53046
|
-
">": ">",
|
|
53047
|
-
'"': """,
|
|
53048
|
-
"'": "'"
|
|
53049
|
-
};
|
|
53050
|
-
function escapeHtml(s) {
|
|
53051
|
-
return s.replace(/[&<>"']/g, (c) => HTML_ESCAPES[c]);
|
|
53052
|
-
}
|
|
53053
53765
|
var NAMED_EMOJI = {
|
|
53054
53766
|
like: { title: "Like", char: "\u{1F44D}" },
|
|
53055
53767
|
heart: { title: "Heart", char: "\u2764\uFE0F" },
|
|
@@ -53064,30 +53776,83 @@ var NAMED_EMOJI = {
|
|
|
53064
53776
|
fire: { title: "Fire", char: "\u{1F525}" },
|
|
53065
53777
|
party: { title: "Party", char: "\u{1F389}" }
|
|
53066
53778
|
};
|
|
53779
|
+
var PLAIN_EMOJI = {
|
|
53780
|
+
rocket: "\u{1F680}",
|
|
53781
|
+
tada: "\u{1F389}",
|
|
53782
|
+
thumbsup: "\u{1F44D}",
|
|
53783
|
+
thumbsdown: "\u{1F44E}",
|
|
53784
|
+
clap: "\u{1F44F}",
|
|
53785
|
+
raised_hands: "\u{1F64C}",
|
|
53786
|
+
pray: "\u{1F64F}",
|
|
53787
|
+
muscle: "\u{1F4AA}",
|
|
53788
|
+
wave: "\u{1F44B}",
|
|
53789
|
+
eyes: "\u{1F440}",
|
|
53790
|
+
thinking: "\u{1F914}",
|
|
53791
|
+
joy: "\u{1F602}",
|
|
53792
|
+
sweat_smile: "\u{1F605}",
|
|
53793
|
+
grin: "\u{1F601}",
|
|
53794
|
+
slightly_smiling_face: "\u{1F642}",
|
|
53795
|
+
upside_down: "\u{1F643}",
|
|
53796
|
+
shrug: "\u{1F937}",
|
|
53797
|
+
facepalm: "\u{1F926}",
|
|
53798
|
+
white_check_mark: "\u2705",
|
|
53799
|
+
heavy_check_mark: "\u2714\uFE0F",
|
|
53800
|
+
x: "\u274C",
|
|
53801
|
+
warning: "\u26A0\uFE0F",
|
|
53802
|
+
bangbang: "\u203C\uFE0F",
|
|
53803
|
+
question: "\u2753",
|
|
53804
|
+
bulb: "\u{1F4A1}",
|
|
53805
|
+
star: "\u2B50",
|
|
53806
|
+
sparkles: "\u2728",
|
|
53807
|
+
zap: "\u26A1",
|
|
53808
|
+
boom: "\u{1F4A5}",
|
|
53809
|
+
"100": "\u{1F4AF}",
|
|
53810
|
+
robot: "\u{1F916}",
|
|
53811
|
+
brain: "\u{1F9E0}",
|
|
53812
|
+
coffee: "\u2615",
|
|
53813
|
+
chart_with_upwards_trend: "\u{1F4C8}",
|
|
53814
|
+
chart_with_downwards_trend: "\u{1F4C9}",
|
|
53815
|
+
memo: "\u{1F4DD}",
|
|
53816
|
+
calendar: "\u{1F4C5}",
|
|
53817
|
+
lock: "\u{1F512}",
|
|
53818
|
+
bug: "\u{1F41B}",
|
|
53819
|
+
wrench: "\u{1F527}",
|
|
53820
|
+
hammer: "\u{1F528}",
|
|
53821
|
+
package: "\u{1F4E6}",
|
|
53822
|
+
ship: "\u{1F6A2}",
|
|
53823
|
+
hourglass: "\u231B",
|
|
53824
|
+
stopwatch: "\u23F1\uFE0F",
|
|
53825
|
+
point_right: "\u{1F449}",
|
|
53826
|
+
point_up: "\u261D\uFE0F",
|
|
53827
|
+
ok_hand: "\u{1F44C}",
|
|
53828
|
+
crossed_fingers: "\u{1F91E}",
|
|
53829
|
+
see_no_evil: "\u{1F648}",
|
|
53830
|
+
skull: "\u{1F480}",
|
|
53831
|
+
partying_face: "\u{1F973}",
|
|
53832
|
+
exploding_head: "\u{1F92F}",
|
|
53833
|
+
mind_blown: "\u{1F92F}"
|
|
53834
|
+
};
|
|
53067
53835
|
var UNICODE_KEY = /^([0-9a-f]{4,6}(?:-[0-9a-f]{4,6})*)_([a-z0-9]+)$/;
|
|
53068
|
-
function
|
|
53069
|
-
let title;
|
|
53070
|
-
let char;
|
|
53836
|
+
function emojiHtml(key) {
|
|
53071
53837
|
const named = NAMED_EMOJI[key];
|
|
53072
53838
|
if (named !== void 0) {
|
|
53073
|
-
|
|
53074
|
-
|
|
53075
|
-
const m = UNICODE_KEY.exec(key);
|
|
53076
|
-
if (m === null) return void 0;
|
|
53077
|
-
const points = m[1].split("-").map((h) => parseInt(h, 16));
|
|
53078
|
-
if (points.some((p) => p > 1114111)) return void 0;
|
|
53079
|
-
char = String.fromCodePoint(...points);
|
|
53080
|
-
title = m[2];
|
|
53839
|
+
const t = escapeHtml(named.title);
|
|
53840
|
+
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(named.char)}" style="width:20px;height:20px;"></span>`;
|
|
53081
53841
|
}
|
|
53082
|
-
const
|
|
53083
|
-
|
|
53842
|
+
const plain = Object.hasOwn(PLAIN_EMOJI, key) ? PLAIN_EMOJI[key] : void 0;
|
|
53843
|
+
if (plain !== void 0) return plain;
|
|
53844
|
+
const m = UNICODE_KEY.exec(key);
|
|
53845
|
+
if (m === null) return void 0;
|
|
53846
|
+
const points = m[1].split("-").map((h) => parseInt(h, 16));
|
|
53847
|
+
if (points.some((p) => p > 1114111)) return void 0;
|
|
53848
|
+
return escapeHtml(String.fromCodePoint(...points));
|
|
53084
53849
|
}
|
|
53085
53850
|
function renderPlain(text) {
|
|
53086
53851
|
let out = "";
|
|
53087
53852
|
let at = 0;
|
|
53088
53853
|
const shortcode = /:([a-z0-9_-]+):/g;
|
|
53089
53854
|
for (let m = shortcode.exec(text); m !== null; m = shortcode.exec(text)) {
|
|
53090
|
-
const span =
|
|
53855
|
+
const span = emojiHtml(m[1]);
|
|
53091
53856
|
if (span === void 0) {
|
|
53092
53857
|
shortcode.lastIndex = m.index + m[0].length - 1;
|
|
53093
53858
|
continue;
|
|
@@ -53113,7 +53878,8 @@ function locate(text, name, taken) {
|
|
|
53113
53878
|
};
|
|
53114
53879
|
return find(`@${name}`, false, false) ?? find(`@${name}`, true, false) ?? find(name, true, true);
|
|
53115
53880
|
}
|
|
53116
|
-
|
|
53881
|
+
var MESSAGE_FORMATS = ["text", "markdown"];
|
|
53882
|
+
function placeMentions(text, mentions) {
|
|
53117
53883
|
const placed = [];
|
|
53118
53884
|
for (const m of mentions) {
|
|
53119
53885
|
const range = locate(
|
|
@@ -53128,15 +53894,39 @@ function renderMessageHtml(text, mentions) {
|
|
|
53128
53894
|
}
|
|
53129
53895
|
placed.push({ start: range[0], end: range[1], mri: m.mri });
|
|
53130
53896
|
}
|
|
53131
|
-
placed.sort((a, b) => a.start - b.start);
|
|
53897
|
+
return placed.sort((a, b) => a.start - b.start);
|
|
53898
|
+
}
|
|
53899
|
+
var mentionSpan = (n, shown3) => `<span itemscope itemtype="http://schema.skype.com/Mention" itemid="${n}">${escapeHtml(shown3)}</span>`;
|
|
53900
|
+
var MENTION_OPEN = "\uE010";
|
|
53901
|
+
var MENTION_CLOSE = "\uE011";
|
|
53902
|
+
var PLACEHOLDER_CHARS = /[\ue010-\ue01f]/g;
|
|
53903
|
+
function renderMessageHtml(text, mentions, format = "text") {
|
|
53904
|
+
const placed = placeMentions(text, mentions);
|
|
53905
|
+
const out = placed.map((p, n) => ({
|
|
53906
|
+
itemid: String(n),
|
|
53907
|
+
mri: p.mri,
|
|
53908
|
+
displayName: text.slice(p.start, p.end).replace(/^@/, "")
|
|
53909
|
+
}));
|
|
53910
|
+
if (format === "markdown") {
|
|
53911
|
+
let src = "";
|
|
53912
|
+
let at2 = 0;
|
|
53913
|
+
const clean = (s) => s.replace(PLACEHOLDER_CHARS, "");
|
|
53914
|
+
placed.forEach((p, n) => {
|
|
53915
|
+
src += clean(text.slice(at2, p.start)) + `${MENTION_OPEN}${n}${MENTION_CLOSE}`;
|
|
53916
|
+
at2 = p.end;
|
|
53917
|
+
});
|
|
53918
|
+
src += clean(text.slice(at2));
|
|
53919
|
+
const html2 = renderMarkdown(src, { shortcode: emojiHtml }).replace(
|
|
53920
|
+
new RegExp(`${MENTION_OPEN}(\\d+)${MENTION_CLOSE}`, "g"),
|
|
53921
|
+
(_w, n) => mentionSpan(Number(n), out[Number(n)].displayName)
|
|
53922
|
+
);
|
|
53923
|
+
return { html: html2, mentions: out };
|
|
53924
|
+
}
|
|
53132
53925
|
let html = "";
|
|
53133
53926
|
let at = 0;
|
|
53134
|
-
const out = [];
|
|
53135
53927
|
placed.forEach((p, n) => {
|
|
53136
|
-
const shown3 = text.slice(p.start, p.end).replace(/^@/, "");
|
|
53137
53928
|
html += renderPlain(text.slice(at, p.start));
|
|
53138
|
-
html +=
|
|
53139
|
-
out.push({ itemid: String(n), mri: p.mri, displayName: shown3 });
|
|
53929
|
+
html += mentionSpan(n, out[n].displayName);
|
|
53140
53930
|
at = p.end;
|
|
53141
53931
|
});
|
|
53142
53932
|
html += renderPlain(text.slice(at));
|
|
@@ -53362,7 +54152,7 @@ function registerMarkReadTools(server, { chatsvc }) {
|
|
|
53362
54152
|
up_to_message: untrustedField({
|
|
53363
54153
|
id: to,
|
|
53364
54154
|
sender: target.imdisplayname?.trim() || senderMri(target.from) || "unknown",
|
|
53365
|
-
preview: clipText(
|
|
54155
|
+
preview: clipText(htmlToText2(target.content ?? ""), PREVIEW_CHARS2)
|
|
53366
54156
|
}),
|
|
53367
54157
|
previous_horizon_message_id: previous
|
|
53368
54158
|
},
|
|
@@ -53609,7 +54399,7 @@ function registerConversationTools(server, { chatsvc }) {
|
|
|
53609
54399
|
"teams_list_messages",
|
|
53610
54400
|
{
|
|
53611
54401
|
title: "Read a Teams chat or channel",
|
|
53612
|
-
description: `Read the messages of any chat or channel the signed-in user is in, by id (from teams_list_conversations / teams_list_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_list_changed_conversations counted, pass that row's after_message_id, never teams_list_changed_conversations' next_cursor (a time token for teams_list_changed_conversations). ` + 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 (the argument as passed and, once it resolved, its id, title, kind, team and participants) while the rest still come back. ` + FROM_DESCRIPTION + "With from, limit keeps the OLDEST messages, unread_only pages only unread ones, and since, after_message_id and mark_read cannot be used; the result carries from_time, has_more, next_from and next_from_time in place of unread_count and next_cursor. " + 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,
|
|
54402
|
+
description: `Read the messages of any chat or channel the signed-in user is in, by id (from teams_list_conversations / teams_list_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 " | "; lists numbered or bulleted), subject, edited/deleted flags and attachments; a formatted message also carries content_html (its body as sanitised HTML: bold, lists, links, code, quotes, mentions), mentions ([{mri, displayName}], who was @mentioned) and links ([{href, text}]), each absent when there is none; 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_list_changed_conversations counted, pass that row's after_message_id, never teams_list_changed_conversations' next_cursor (a time token for teams_list_changed_conversations). ` + 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 (the argument as passed and, once it resolved, its id, title, kind, team and participants) while the rest still come back. ` + FROM_DESCRIPTION + "With from, limit keeps the OLDEST messages, unread_only pages only unread ones, and since, after_message_id and mark_read cannot be used; the result carries from_time, has_more, next_from and next_from_time in place of unread_count and next_cursor. " + 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,
|
|
53613
54403
|
// 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).
|
|
53614
54404
|
annotations: toolAnnotations({ readOnly: false, destructive: false, idempotent: true, openWorld: true }),
|
|
53615
54405
|
_meta: workMeta("lookup", { aliases: ["messages", "chat history", "read the chat", "thread"] }),
|
|
@@ -54362,14 +55152,14 @@ import { basename as basename2, dirname as dirname6, join as join11 } from "node
|
|
|
54362
55152
|
// node_modules/@chrischall/mcp-utils/dist/export/zip.js
|
|
54363
55153
|
import { deflateRawSync } from "node:zlib";
|
|
54364
55154
|
var CRC_TABLE = (() => {
|
|
54365
|
-
const
|
|
55155
|
+
const table2 = new Uint32Array(256);
|
|
54366
55156
|
for (let n = 0; n < 256; n++) {
|
|
54367
55157
|
let c = n;
|
|
54368
55158
|
for (let k = 0; k < 8; k++)
|
|
54369
55159
|
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
54370
|
-
|
|
55160
|
+
table2[n] = c >>> 0;
|
|
54371
55161
|
}
|
|
54372
|
-
return
|
|
55162
|
+
return table2;
|
|
54373
55163
|
})();
|
|
54374
55164
|
function crc32(bytes) {
|
|
54375
55165
|
let crc = 4294967295;
|
|
@@ -54723,15 +55513,15 @@ function openDiskSink(dir, exportId, part) {
|
|
|
54723
55513
|
if (finished)
|
|
54724
55514
|
throw badInput2("This export part is already finished.");
|
|
54725
55515
|
finished = true;
|
|
54726
|
-
const
|
|
55516
|
+
const list2 = [...files.values()];
|
|
54727
55517
|
return {
|
|
54728
55518
|
mode: "disk",
|
|
54729
55519
|
exportId,
|
|
54730
55520
|
part,
|
|
54731
55521
|
location: dir,
|
|
54732
55522
|
dir,
|
|
54733
|
-
bytes:
|
|
54734
|
-
files:
|
|
55523
|
+
bytes: list2.reduce((n, f) => n + f.bytes, 0),
|
|
55524
|
+
files: list2
|
|
54735
55525
|
};
|
|
54736
55526
|
}
|
|
54737
55527
|
};
|
|
@@ -55037,7 +55827,8 @@ function messageMd(m, level) {
|
|
|
55037
55827
|
const flags = [m.edited ? "edited" : void 0, m.deleted ? "deleted" : void 0].filter(Boolean);
|
|
55038
55828
|
const lines = [`${level} ${when(m)} \u2014 ${m.sender}${flags.length > 0 ? ` (${flags.join(", ")})` : ""}`, ""];
|
|
55039
55829
|
if (m.subject !== void 0) lines.push(`**Subject:** ${m.subject}`, "");
|
|
55040
|
-
|
|
55830
|
+
const body = m.content_html !== void 0 ? htmlToMarkdown2(m.content_html) : m.text;
|
|
55831
|
+
lines.push(body === "" ? "_(no text)_" : body, "");
|
|
55041
55832
|
const att = attachmentsLine(m);
|
|
55042
55833
|
if (att !== void 0) lines.push(att, "");
|
|
55043
55834
|
return lines.join("\n");
|
|
@@ -55047,7 +55838,7 @@ function threadName(root) {
|
|
|
55047
55838
|
const first = root.text.split("\n").find((l) => l.trim() !== "")?.trim() ?? "";
|
|
55048
55839
|
return first.length > 80 ? `${first.slice(0, 79)}\u2026` : first || "(no text)";
|
|
55049
55840
|
}
|
|
55050
|
-
function
|
|
55841
|
+
function renderMarkdown2(header, conversation, messages) {
|
|
55051
55842
|
const c = conversation;
|
|
55052
55843
|
const pre = [
|
|
55053
55844
|
`# ${c.title}`,
|
|
@@ -55079,7 +55870,7 @@ function renderMarkdown(header, conversation, messages) {
|
|
|
55079
55870
|
return [...pre, ...body].join("\n").replace(/\n*$/, "\n");
|
|
55080
55871
|
}
|
|
55081
55872
|
function renderConversation(format, header, conversation, messages) {
|
|
55082
|
-
return format === "markdown" ?
|
|
55873
|
+
return format === "markdown" ? renderMarkdown2(header, conversation, messages) : renderJsonl(header, conversation, messages);
|
|
55083
55874
|
}
|
|
55084
55875
|
|
|
55085
55876
|
// src/tools/export-attachments.ts
|
|
@@ -55687,7 +56478,7 @@ async function downloadSharedFile(sharepoint, file2, message, ids, naming, save)
|
|
|
55687
56478
|
});
|
|
55688
56479
|
const uri = file2.openUrl ?? file2.url;
|
|
55689
56480
|
const content = delivered.content.map(
|
|
55690
|
-
(
|
|
56481
|
+
(block2) => block2.type === "resource" ? { ...block2, resource: { ...block2.resource, uri } } : block2
|
|
55691
56482
|
);
|
|
55692
56483
|
return { content: [...content, ...caption.content] };
|
|
55693
56484
|
}
|
|
@@ -55947,6 +56738,9 @@ var TOOL2 = "teams_send_message";
|
|
|
55947
56738
|
var READBACK_MESSAGES = 50;
|
|
55948
56739
|
var MAX_CANDIDATES3 = 10;
|
|
55949
56740
|
var PREVIEW_CHARS3 = 200;
|
|
56741
|
+
var formatParam = external_exports.enum(MESSAGE_FORMATS).optional().describe(
|
|
56742
|
+
'How text is written (default "text"). text: plain text, escaped. markdown: **bold**, *italic*, ~~strike~~, `code`, fenced code blocks, - and 1. lists (nested by indenting), [text](https://\u2026) links; nothing else is markup.'
|
|
56743
|
+
);
|
|
55950
56744
|
var mentionArg = external_exports.object({
|
|
55951
56745
|
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.'),
|
|
55952
56746
|
person: external_exports.string().min(1).describe("Who to mention: an MRI (8:orgid:\u2026), or a display name matched among recent senders in this conversation.")
|
|
@@ -55994,7 +56788,7 @@ async function quoted(chatsvc, conversationId, id) {
|
|
|
55994
56788
|
});
|
|
55995
56789
|
}
|
|
55996
56790
|
const mri = senderMri(m.from) ?? "";
|
|
55997
|
-
return { id: m.id, senderMri: mri, senderName: m.imdisplayname?.trim() || mri, text:
|
|
56791
|
+
return { id: m.id, senderMri: mri, senderName: m.imdisplayname?.trim() || mri, text: htmlToText2(m.content ?? "") };
|
|
55998
56792
|
}
|
|
55999
56793
|
async function threadRoot(chatsvc, channelId, id, me) {
|
|
56000
56794
|
const m = await chatsvc.getMessage(channelId, id);
|
|
@@ -56022,21 +56816,22 @@ function registerSendTools(server, { chatsvc }) {
|
|
|
56022
56816
|
TOOL2,
|
|
56023
56817
|
{
|
|
56024
56818
|
title: "Send a Teams message",
|
|
56025
|
-
description: `Post a message as the signed-in user to any chat or channel, by id (from teams_list_conversations / teams_list_channels) or by name. text is plain text: it is escaped, newlines are kept, and :key: shortcodes
|
|
56819
|
+
description: `Post a message as the signed-in user to any chat or channel, by id (from teams_list_conversations / teams_list_channels) or by name. text is plain text by default: it is escaped, newlines are kept, and :key: shortcodes become emoji: Teams' animated ones for like, heart, laugh, surprised, sad, angry, smile, wink, cool, hearteyes, fire and party; the plain character for common names (:rocket:, :tada:, :thumbsup:, :eyes:, :white_check_mark:, \u2026) and unicode-style keys (:1f680_rocket:). format "markdown" reads text as Markdown instead: **bold**, *italic*, ~~strike~~, \`inline code\`, \`\`\` code blocks \`\`\`, bulleted (- item) and numbered (1. item) lists, [link text](https://\u2026), blank-line paragraphs and line breaks; raw HTML, headings, quotes and images are escaped and shown as written. 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,
|
|
56026
56820
|
annotations: toolAnnotations({ readOnly: false, destructive: true, idempotent: false, openWorld: true }),
|
|
56027
56821
|
_meta: workMeta("send", { aliases: ["message", "send a message", "reply", "tell", "post", "chat"] }),
|
|
56028
56822
|
inputSchema: {
|
|
56029
56823
|
conversation: external_exports.string().min(1).describe(
|
|
56030
56824
|
`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.`
|
|
56031
56825
|
),
|
|
56032
|
-
text: external_exports.string().min(1).describe(
|
|
56826
|
+
text: external_exports.string().min(1).describe('The message: plain text (newlines kept, :key: shortcodes become emoji), or Markdown with format "markdown".'),
|
|
56827
|
+
format: formatParam,
|
|
56033
56828
|
reply_to: external_exports.string().min(1).optional().describe("A message id. Channel: the root post to reply under (threaded). Chat: the message to quote-reply."),
|
|
56034
56829
|
quote: external_exports.string().min(1).optional().describe("A message id to quote-reply, in any conversation."),
|
|
56035
56830
|
mentions: external_exports.array(mentionArg).max(20).optional().describe("People to @-mention in text."),
|
|
56036
56831
|
confirmToken: confirmTokenParam
|
|
56037
56832
|
}
|
|
56038
56833
|
},
|
|
56039
|
-
async ({ conversation, text, reply_to, quote, mentions, confirmToken }, ctx) => {
|
|
56834
|
+
async ({ conversation, text, format = "text", reply_to, quote, mentions, confirmToken }, ctx) => {
|
|
56040
56835
|
try {
|
|
56041
56836
|
const [me, meName] = await Promise.all([chatsvc.meMri(), chatsvc.meDisplayName()]);
|
|
56042
56837
|
const target = await resolveTarget(chatsvc, conversation, me);
|
|
@@ -56056,7 +56851,8 @@ function registerSendTools(server, { chatsvc }) {
|
|
|
56056
56851
|
const people = await resolveMentions(chatsvc, target.id, mentions ?? []);
|
|
56057
56852
|
const rendered = renderMessageHtml(
|
|
56058
56853
|
text,
|
|
56059
|
-
people.map((p) => p.target)
|
|
56854
|
+
people.map((p) => p.target),
|
|
56855
|
+
format
|
|
56060
56856
|
);
|
|
56061
56857
|
const content = (q ? quoteHtml(q) : "") + rendered.html;
|
|
56062
56858
|
const properties = {
|
|
@@ -56082,6 +56878,7 @@ function registerSendTools(server, { chatsvc }) {
|
|
|
56082
56878
|
preview: {
|
|
56083
56879
|
conversation: untrustedField(target),
|
|
56084
56880
|
text,
|
|
56881
|
+
format,
|
|
56085
56882
|
...inChannel && reply_to !== void 0 ? { thread_root: reply_to } : {},
|
|
56086
56883
|
...people.length > 0 ? {
|
|
56087
56884
|
mentions: untrustedField(
|
|
@@ -56231,7 +57028,7 @@ function registerReactTools(server, { chatsvc }) {
|
|
|
56231
57028
|
message: untrustedField({
|
|
56232
57029
|
id: m.id,
|
|
56233
57030
|
sender: m.imdisplayname?.trim() || senderMri(m.from) || "unknown",
|
|
56234
|
-
preview: clipText(
|
|
57031
|
+
preview: clipText(htmlToText2(m.content ?? ""), PREVIEW_CHARS4)
|
|
56235
57032
|
}),
|
|
56236
57033
|
reaction: key,
|
|
56237
57034
|
already_reacted: already
|
|
@@ -56293,6 +57090,228 @@ function registerReactTools(server, { chatsvc }) {
|
|
|
56293
57090
|
);
|
|
56294
57091
|
}
|
|
56295
57092
|
|
|
57093
|
+
// src/tools/edit.ts
|
|
57094
|
+
init_zod();
|
|
57095
|
+
init_dist2();
|
|
57096
|
+
|
|
57097
|
+
// src/tools/own-message.ts
|
|
57098
|
+
init_dist2();
|
|
57099
|
+
var PARTICIPLE = { edit: "edited", delete: "deleted" };
|
|
57100
|
+
async function ownMessage(chatsvc, conversationId, id, me, verb) {
|
|
57101
|
+
const m = await chatsvc.getMessage(conversationId, id);
|
|
57102
|
+
if (m === void 0) {
|
|
57103
|
+
throw new McpToolError(`There is no message ${id} in this conversation to ${verb}.`, {
|
|
57104
|
+
hint: "Take message ids from teams_list_messages."
|
|
57105
|
+
});
|
|
57106
|
+
}
|
|
57107
|
+
if (senderMri(m.from)?.toLowerCase() !== me.toLowerCase()) {
|
|
57108
|
+
throw new McpToolError(`Message ${id} was not sent by you: you can ${verb} only your own messages.`, {
|
|
57109
|
+
hint: "Pick one of your own messages (fromMe: true in teams_list_messages)."
|
|
57110
|
+
});
|
|
57111
|
+
}
|
|
57112
|
+
if (!isUserMessage(m)) {
|
|
57113
|
+
throw new McpToolError(`Message ${id} is a system event (${m.messagetype}), not a message anyone wrote.`, {
|
|
57114
|
+
hint: `Only messages you wrote can be ${PARTICIPLE[verb]}.`
|
|
57115
|
+
});
|
|
57116
|
+
}
|
|
57117
|
+
return m;
|
|
57118
|
+
}
|
|
57119
|
+
async function writeAndReadBack(write, readBack, shows, verb, change) {
|
|
57120
|
+
let unconfirmed = false;
|
|
57121
|
+
try {
|
|
57122
|
+
await write();
|
|
57123
|
+
} catch (e) {
|
|
57124
|
+
if (!(e instanceof WriteOutcomeUnknownError)) throw e;
|
|
57125
|
+
unconfirmed = true;
|
|
57126
|
+
}
|
|
57127
|
+
let verified = false;
|
|
57128
|
+
let readBackFailed = false;
|
|
57129
|
+
try {
|
|
57130
|
+
verified = shows(await readBack());
|
|
57131
|
+
} catch {
|
|
57132
|
+
readBackFailed = true;
|
|
57133
|
+
}
|
|
57134
|
+
const check2 = "check the conversation (teams_list_messages)";
|
|
57135
|
+
if (unconfirmed && !verified) {
|
|
57136
|
+
return {
|
|
57137
|
+
status: "unknown",
|
|
57138
|
+
verified,
|
|
57139
|
+
warning: `Teams did not confirm this ${verb}, and reading the message back ${readBackFailed ? "failed" : `did not show ${change}`} \u2014 ${check2} before retrying.`
|
|
57140
|
+
};
|
|
57141
|
+
}
|
|
57142
|
+
const warning = unconfirmed ? `Teams did not confirm this ${verb}, but reading the message back shows ${change}.` : readBackFailed ? `Teams accepted the ${verb}, but reading the message back failed \u2014 ${check2}.` : !verified ? `Teams accepted the ${verb}, but reading the message back did not show ${change} \u2014 ${check2}.` : void 0;
|
|
57143
|
+
return { status: "done", verified, ...warning !== void 0 ? { warning } : {} };
|
|
57144
|
+
}
|
|
57145
|
+
|
|
57146
|
+
// src/tools/edit.ts
|
|
57147
|
+
var TOOL4 = "teams_edit_message";
|
|
57148
|
+
var QUOTE_BLOCK = /^\s*(<blockquote\b[^>]*schema\.skype\.com\/Reply[^>]*>[\s\S]*?<\/blockquote\s*>)/i;
|
|
57149
|
+
function quotePrefix(content) {
|
|
57150
|
+
return QUOTE_BLOCK.exec(content)?.[1] ?? "";
|
|
57151
|
+
}
|
|
57152
|
+
var readsAs = (m, content) => m !== void 0 && htmlToText2(m.content ?? "") === htmlToText2(content);
|
|
57153
|
+
var BLOCK_TAG = /\s*(<\/?(?:p|div|ol|ul|li|pre|blockquote|table|thead|tbody|tr|td|th|h[1-6])>)\s*/g;
|
|
57154
|
+
function sameBody(a, b) {
|
|
57155
|
+
const norm = (h) => sanitiseHtml2(h).replace(BLOCK_TAG, "$1").trim();
|
|
57156
|
+
return norm(a) === norm(b);
|
|
57157
|
+
}
|
|
57158
|
+
function registerEditTools(server, { chatsvc }) {
|
|
57159
|
+
server.registerTool(
|
|
57160
|
+
TOOL4,
|
|
57161
|
+
{
|
|
57162
|
+
title: "Edit a Teams message",
|
|
57163
|
+
description: `Replace the text of one of your own messages in any chat or channel. conversation is an id or name as for teams_list_messages; message_id comes from teams_list_messages and must be a message you sent (someone else's, a deleted one or a system event is refused). text replaces the whole message: plain text by default, or Markdown with format "markdown" (as teams_send_message reads it). mentions @-mention people as in teams_send_message. A quote-reply keeps its quote. Text that renders exactly as the message already does, mentioning the same people, changes nothing (status "unchanged"). Everyone in the conversation sees the message marked edited. The result says whether reading the message back shows the edit (verified); status "unknown" means Teams did not confirm it and the read-back did not show it \u2014 check the message before retrying. conversation "${SELF_CHAT}" (or "notes" / "self") is the user's own notes self-chat \u2014 use it to try this tool. ` + CONFIRM_FLOW_SENTENCE + " The preview shows the conversation, the current text, the new text and exactly what will replace it. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
57164
|
+
annotations: toolAnnotations({ readOnly: false, destructive: true, idempotent: true, openWorld: true }),
|
|
57165
|
+
_meta: workMeta("change", { aliases: ["edit", "edit message", "fix my message", "correct", "reword", "update message"] }),
|
|
57166
|
+
inputSchema: {
|
|
57167
|
+
conversation: external_exports.string().min(1).describe(
|
|
57168
|
+
`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.`
|
|
57169
|
+
),
|
|
57170
|
+
message_id: external_exports.string().min(1).describe("The message to edit \u2014 one you sent \u2014 as teams_list_messages lists it."),
|
|
57171
|
+
text: external_exports.string().min(1).describe('The whole new message: plain text (newlines kept, :key: shortcodes become emoji), or Markdown with format "markdown".'),
|
|
57172
|
+
format: formatParam,
|
|
57173
|
+
mentions: external_exports.array(mentionArg).max(20).optional().describe("People to @-mention in text."),
|
|
57174
|
+
confirmToken: confirmTokenParam
|
|
57175
|
+
}
|
|
57176
|
+
},
|
|
57177
|
+
async ({ conversation, message_id, text, format = "text", mentions, confirmToken }, ctx) => {
|
|
57178
|
+
try {
|
|
57179
|
+
const me = await chatsvc.meMri();
|
|
57180
|
+
const target = await resolveTarget(chatsvc, conversation, me, "edit a message in");
|
|
57181
|
+
const original = await ownMessage(chatsvc, target.id, message_id, me, "edit");
|
|
57182
|
+
if (isDeleted(original)) {
|
|
57183
|
+
throw new McpToolError(`Message ${message_id} has been deleted, so it cannot be edited.`, {
|
|
57184
|
+
hint: "Send a new message instead (teams_send_message)."
|
|
57185
|
+
});
|
|
57186
|
+
}
|
|
57187
|
+
const before = original.content ?? "";
|
|
57188
|
+
const people = await resolveMentions(chatsvc, target.id, mentions ?? []);
|
|
57189
|
+
const rendered = renderMessageHtml(
|
|
57190
|
+
text,
|
|
57191
|
+
people.map((p) => p.target),
|
|
57192
|
+
format
|
|
57193
|
+
);
|
|
57194
|
+
const content = quotePrefix(before) + rendered.html;
|
|
57195
|
+
const mentionedNow = rendered.mentions.map((m) => m.mri.toLowerCase());
|
|
57196
|
+
const mentionedBefore = mentionsOf(original.properties?.mentions).map((m) => m.mri.toLowerCase());
|
|
57197
|
+
if (sameBody(content, before) && mentionedNow.join("\n") === mentionedBefore.join("\n")) {
|
|
57198
|
+
return untrustedResult2({ status: "unchanged", conversation: target, message_id });
|
|
57199
|
+
}
|
|
57200
|
+
const qtdMsgs = original.properties?.qtdMsgs;
|
|
57201
|
+
const body = {
|
|
57202
|
+
content,
|
|
57203
|
+
messagetype: "RichText/Html",
|
|
57204
|
+
contenttype: "text",
|
|
57205
|
+
amsreferences: [],
|
|
57206
|
+
properties: {
|
|
57207
|
+
mentions: rendered.mentions.length > 0 ? mentionsProperty(rendered.mentions) : "[]",
|
|
57208
|
+
...typeof qtdMsgs === "string" && quotePrefix(before) !== "" ? { qtdMsgs } : {}
|
|
57209
|
+
}
|
|
57210
|
+
};
|
|
57211
|
+
const path = `/users/ME/conversations/${encodeURIComponent(target.id)}/messages/${encodeURIComponent(message_id)}`;
|
|
57212
|
+
const gate = await confirmWrite(ctx, {
|
|
57213
|
+
tool: TOOL4,
|
|
57214
|
+
action: "chat.edit_message",
|
|
57215
|
+
message: "Review and confirm this edit before it replaces your Teams message:",
|
|
57216
|
+
// The title is someone else's text: JSON-quoted so it cannot break out of its quotes.
|
|
57217
|
+
summary: `Edit your message ${message_id} in ${target.kind} ${JSON.stringify(target.title)}`,
|
|
57218
|
+
account: me,
|
|
57219
|
+
target: `${target.id}/${message_id}`,
|
|
57220
|
+
request: { method: "PUT", path, body },
|
|
57221
|
+
preview: {
|
|
57222
|
+
conversation: untrustedField(target),
|
|
57223
|
+
message_id,
|
|
57224
|
+
// The user's own text, but a quote-reply's quote is someone else's.
|
|
57225
|
+
current_text: untrustedField(htmlToText2(before)),
|
|
57226
|
+
text,
|
|
57227
|
+
format,
|
|
57228
|
+
...people.length > 0 ? {
|
|
57229
|
+
mentions: untrustedField(
|
|
57230
|
+
people.map((p, i) => ({ name_in_text: mentions[i].name_in_text, person: p.person, mri: p.target.mri }))
|
|
57231
|
+
)
|
|
57232
|
+
} : {}
|
|
57233
|
+
},
|
|
57234
|
+
confirmToken
|
|
57235
|
+
});
|
|
57236
|
+
if (gate) return gate;
|
|
57237
|
+
const { status, ...settled } = await writeAndReadBack(
|
|
57238
|
+
() => chatsvc.editMessage(target.id, message_id, body),
|
|
57239
|
+
() => chatsvc.getMessage(target.id, message_id),
|
|
57240
|
+
(m) => readsAs(m, content),
|
|
57241
|
+
"edit",
|
|
57242
|
+
"the new text"
|
|
57243
|
+
);
|
|
57244
|
+
return untrustedResult2({ status: status === "done" ? "edited" : "unknown", conversation: target, message_id, ...settled });
|
|
57245
|
+
} catch (err) {
|
|
57246
|
+
throw wrapApiError(err, "edit the message");
|
|
57247
|
+
}
|
|
57248
|
+
}
|
|
57249
|
+
);
|
|
57250
|
+
}
|
|
57251
|
+
|
|
57252
|
+
// src/tools/delete.ts
|
|
57253
|
+
init_zod();
|
|
57254
|
+
init_dist2();
|
|
57255
|
+
var TOOL5 = "teams_delete_message";
|
|
57256
|
+
function registerDeleteTools(server, { chatsvc }) {
|
|
57257
|
+
server.registerTool(
|
|
57258
|
+
TOOL5,
|
|
57259
|
+
{
|
|
57260
|
+
title: "Delete a Teams message",
|
|
57261
|
+
description: `Delete one of your own messages in any chat or channel. conversation is an id or name as for teams_list_messages; message_id comes from teams_list_messages and must be a message you sent (someone else's or a system event is refused). One already deleted is reported as status "already_deleted" with nothing asked or sent. Everyone in the conversation sees that the message was deleted, and this MCP cannot bring it back. The result says whether reading the message back shows it deleted (verified); status "unknown" means Teams did not confirm it and the read-back did not show it deleted \u2014 check before retrying. conversation "${SELF_CHAT}" (or "notes" / "self") is the user's own notes self-chat \u2014 use it to try this tool. ` + CONFIRM_FLOW_SENTENCE + " The preview shows the conversation and the message that will be deleted. " + CONFIRM_INJECTION_RULE + UNTRUSTED_DESCRIPTION_SUFFIX2,
|
|
57262
|
+
annotations: toolAnnotations({ readOnly: false, destructive: true, idempotent: true, openWorld: true }),
|
|
57263
|
+
_meta: workMeta("change", { aliases: ["delete", "delete message", "remove message", "unsend", "take back"] }),
|
|
57264
|
+
inputSchema: {
|
|
57265
|
+
conversation: external_exports.string().min(1).describe(
|
|
57266
|
+
`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.`
|
|
57267
|
+
),
|
|
57268
|
+
message_id: external_exports.string().min(1).describe("The message to delete \u2014 one you sent \u2014 as teams_list_messages lists it."),
|
|
57269
|
+
confirmToken: confirmTokenParam
|
|
57270
|
+
}
|
|
57271
|
+
},
|
|
57272
|
+
async ({ conversation, message_id, confirmToken }, ctx) => {
|
|
57273
|
+
try {
|
|
57274
|
+
const me = await chatsvc.meMri();
|
|
57275
|
+
const target = await resolveTarget(chatsvc, conversation, me, "delete a message in");
|
|
57276
|
+
const m = await ownMessage(chatsvc, target.id, message_id, me, "delete");
|
|
57277
|
+
if (isDeleted(m)) {
|
|
57278
|
+
return untrustedResult2({ status: "already_deleted", conversation: target, message_id });
|
|
57279
|
+
}
|
|
57280
|
+
const path = `/users/ME/conversations/${encodeURIComponent(target.id)}/messages/${encodeURIComponent(message_id)}`;
|
|
57281
|
+
const gate = await confirmWrite(ctx, {
|
|
57282
|
+
tool: TOOL5,
|
|
57283
|
+
action: "chat.delete_message",
|
|
57284
|
+
message: "Review and confirm before this Teams message of yours is deleted:",
|
|
57285
|
+
// The title is someone else's text: JSON-quoted so it cannot break out of its quotes.
|
|
57286
|
+
summary: `Delete your message ${message_id} in ${target.kind} ${JSON.stringify(target.title)}`,
|
|
57287
|
+
account: me,
|
|
57288
|
+
target: `${target.id}/${message_id}`,
|
|
57289
|
+
request: { method: "DELETE", path },
|
|
57290
|
+
preview: {
|
|
57291
|
+
conversation: untrustedField(target),
|
|
57292
|
+
message_id,
|
|
57293
|
+
time: normaliseMessage(m, me).time,
|
|
57294
|
+
// The user's own text, but a quote-reply's quote is someone else's.
|
|
57295
|
+
text: untrustedField(htmlToText2(m.content ?? ""))
|
|
57296
|
+
},
|
|
57297
|
+
confirmToken
|
|
57298
|
+
});
|
|
57299
|
+
if (gate) return gate;
|
|
57300
|
+
const { status, ...settled } = await writeAndReadBack(
|
|
57301
|
+
() => chatsvc.deleteMessage(target.id, message_id),
|
|
57302
|
+
() => chatsvc.getMessage(target.id, message_id),
|
|
57303
|
+
(back) => back === void 0 || isDeleted(back),
|
|
57304
|
+
"delete",
|
|
57305
|
+
"it deleted"
|
|
57306
|
+
);
|
|
57307
|
+
return untrustedResult2({ status: status === "done" ? "deleted" : "unknown", conversation: target, message_id, ...settled });
|
|
57308
|
+
} catch (err) {
|
|
57309
|
+
throw wrapApiError(err, "delete the message");
|
|
57310
|
+
}
|
|
57311
|
+
}
|
|
57312
|
+
);
|
|
57313
|
+
}
|
|
57314
|
+
|
|
56296
57315
|
// src/tools/group-chat.ts
|
|
56297
57316
|
init_zod();
|
|
56298
57317
|
init_dist2();
|
|
@@ -56788,7 +57807,7 @@ function activityRow(m) {
|
|
|
56788
57807
|
},
|
|
56789
57808
|
message_id: str3(a.sourceMessageId),
|
|
56790
57809
|
...replyChain !== void 0 ? { reply_chain_id: replyChain } : {},
|
|
56791
|
-
preview: clip(
|
|
57810
|
+
preview: clip(htmlToText2(str3(a.messagePreview) ?? ""))
|
|
56792
57811
|
};
|
|
56793
57812
|
}
|
|
56794
57813
|
async function nameRows(name, rows) {
|
|
@@ -57487,6 +58506,8 @@ await runMcp({
|
|
|
57487
58506
|
registerChangesTools,
|
|
57488
58507
|
registerAttachmentTools,
|
|
57489
58508
|
registerSendTools,
|
|
58509
|
+
registerEditTools,
|
|
58510
|
+
registerDeleteTools,
|
|
57490
58511
|
registerReactTools,
|
|
57491
58512
|
registerMarkReadTools,
|
|
57492
58513
|
registerGroupChatTools,
|