@primusclaw/personal-agent-teams 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/dist/main.js CHANGED
@@ -87,6 +87,7 @@ function voteOf(activity) {
87
87
  import { z as z2 } from "zod";
88
88
  import { cpHead, pyStr as pyStr2 } from "@primusclaw/personal-agent";
89
89
  var FILE_DOWNLOAD_INFO = "application/vnd.microsoft.teams.file.download.info";
90
+ var NOT_FILES = /* @__PURE__ */ new Set(["text/html", "forwardedmessagereference"]);
90
91
  var teamsFileHandle = z2.object({
91
92
  kind: z2.enum(["pasted", "download"]),
92
93
  url: z2.string(),
@@ -127,7 +128,7 @@ function inboundFiles(activity) {
127
128
  files.push(teamsFile(name, "", { kind: "pasted", url: contentUrl, index }));
128
129
  } else if (kind === FILE_DOWNLOAD_INFO && typeof downloadUrl === "string") {
129
130
  files.push(teamsFile(name, sentFileType(content["fileType"]), { kind: "download", url: downloadUrl, index }));
130
- } else if (name && kind !== "text/html" && !kind.startsWith("application/vnd.microsoft.card.")) {
131
+ } else if (name && !NOT_FILES.has(kind) && !kind.startsWith("application/vnd.microsoft.card.")) {
131
132
  unreadable.push(name);
132
133
  }
133
134
  }
@@ -138,7 +139,7 @@ function inboundFiles(activity) {
138
139
  import {
139
140
  err,
140
141
  ok,
141
- pyStr as pyStr10,
142
+ pyStr as pyStr11,
142
143
  silentLogger
143
144
  } from "@primusclaw/personal-agent";
144
145
 
@@ -194,50 +195,200 @@ function cardVerb(activity) {
194
195
  return cpHead2(pyStr3(verb) || "unknown", 40);
195
196
  }
196
197
 
197
- // packages/teams/src/activity/inbound/identity.ts
198
- import { cpHead as cpHead3, pyStr as pyStr4, pyStrip as pyStrip2 } from "@primusclaw/personal-agent";
199
- function senderOf(activity) {
200
- const who = partOf(activity, "from");
201
- const aadId = who["aadObjectId"];
202
- if (typeof aadId !== "string" || !aadId) return void 0;
203
- const email = pyStrip2(pyStr4(who["userPrincipalName"]) || pyStr4(who["email"]));
204
- return { aadId, name: pyStr4(who["name"]), email: email.includes("@") ? email : "" };
198
+ // packages/teams/src/activity/inbound/forwards.ts
199
+ import {
200
+ isPySpace,
201
+ own as own3,
202
+ pySplit,
203
+ pyStr as pyStr7,
204
+ squashSpaces as squashSpaces3
205
+ } from "@primusclaw/personal-agent";
206
+
207
+ // packages/teams/src/activity/inbound/markup.ts
208
+ import { cpLength, pyStr as pyStr4, pyStrip as pyStrip2 } from "@primusclaw/personal-agent";
209
+
210
+ // packages/teams/src/activity/inbound/patterns.ts
211
+ import { own } from "@primusclaw/personal-agent";
212
+ var SPACE_CHARS = "\\t\\n\\v\\f\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
213
+ var SPACE = `[${SPACE_CHARS}]`;
214
+ var WORD = "[\\p{L}\\p{N}_]";
215
+ var NOT_WORD_NEXT = `(?!${WORD})`;
216
+ var FOLDS = { i: "\\u0130\\u0131", k: "\\u212a", s: "\\u017f" };
217
+ var SYNTAX = /[\\^$.*+?()[\]{}|/]/;
218
+ function literalChar(ch) {
219
+ return SYNTAX.test(ch) ? `\\${ch}` : ch;
205
220
  }
206
- function conversationType(activity) {
207
- return partOf(activity, "conversation")["conversationType"];
221
+ function caseless(literal) {
222
+ let source = "";
223
+ for (const ch of literal) {
224
+ const lower = ch.toLowerCase();
225
+ const upper = ch.toUpperCase();
226
+ if (lower === upper || Array.from(lower).length > 1 || Array.from(upper).length > 1) {
227
+ source += literalChar(ch);
228
+ continue;
229
+ }
230
+ source += `[${lower}${upper}${own(FOLDS, lower) ?? ""}]`;
231
+ }
232
+ return source;
208
233
  }
209
- function isPersonal(activity) {
210
- return conversationType(activity) === "personal";
234
+
235
+ // packages/teams/src/activity/inbound/markup.ts
236
+ var AT_TAG = /<\/?[Aa][Tt]>/g;
237
+ var LINK_CHARS = 2e3;
238
+ var WEB_URL = new RegExp(`^${caseless("http")}${caseless("s")}?://[^${SPACE_CHARS}<>"']+$`, "u");
239
+ function webUrl(raw) {
240
+ const url = typeof raw === "string" ? pyStrip2(raw) : "";
241
+ return cpLength(url) <= LINK_CHARS && WEB_URL.test(url) ? url : "";
211
242
  }
212
- function isGroup(activity) {
213
- return conversationType(activity) === "groupChat";
243
+ function findTags(text4, names, closing) {
244
+ const head = new RegExp(`${closing ? "(/?)" : "()"}(?:${names.map(caseless).join("|")})${NOT_WORD_NEXT}`, "uy");
245
+ const found = [];
246
+ let gt = -1;
247
+ let at = text4.indexOf("<");
248
+ while (at >= 0) {
249
+ head.lastIndex = at + 1;
250
+ const match = head.exec(text4);
251
+ if (match) {
252
+ const nameEnd = head.lastIndex;
253
+ if (gt < nameEnd) gt = text4.indexOf(">", nameEnd);
254
+ if (gt < 0) break;
255
+ found.push({ start: at, end: gt + 1, closing: match[1] === "/", attrs: text4.slice(nameEnd, gt) });
256
+ at = text4.indexOf("<", gt + 1);
257
+ } else {
258
+ at = text4.indexOf("<", at + 1);
259
+ }
260
+ }
261
+ return found;
214
262
  }
215
- function conversationKind(activity) {
216
- if (isPersonal(activity)) return "personal";
217
- return isGroup(activity) ? "group" : "channel";
263
+ function replaceTags(text4, tags, by) {
264
+ let out = "";
265
+ let resume = 0;
266
+ for (const tag of tags) {
267
+ out += text4.slice(resume, tag.start) + by;
268
+ resume = tag.end;
269
+ }
270
+ return out + text4.slice(resume);
218
271
  }
219
- function conversationId(activity) {
220
- return pyStr4(partOf(activity, "conversation")["id"]);
272
+ var REPLY_ITEMTYPE = new RegExp(caseless("schema.skype.com/Reply"), "u");
273
+ var FORWARD_ITEMTYPE = new RegExp(caseless("schema.skype.com/Forward"), "u");
274
+ function cutReplies(markup) {
275
+ return cutBlockquotes(markup, REPLY_ITEMTYPE);
221
276
  }
222
- function tenantOf(activity) {
223
- const channelData = activity.channelData;
224
- const tenant = isFields(channelData) ? channelData["tenant"] : void 0;
225
- const fromChannel = isFields(tenant) ? tenant["id"] : void 0;
226
- return pyStr4(partOf(activity, "conversation")["tenantId"]) || pyStr4(fromChannel);
277
+ function cutForwards(markup) {
278
+ return cutBlockquotes(markup, FORWARD_ITEMTYPE);
227
279
  }
228
- var ALNUM = /[\p{L}\p{N}]/u;
229
- function clientPlatform(activity) {
230
- const info = entitiesOf(activity).find((entity) => entity["type"] === "clientInfo");
231
- const platform = info?.["platform"];
232
- if (typeof platform !== "string") return "";
233
- return cpHead3(
234
- Array.from(platform).filter((ch) => ALNUM.test(ch)).join(""),
235
- 16
236
- );
280
+ function cutBlockquotes(markup, itemtype) {
281
+ const kept = [];
282
+ const cut = [];
283
+ let depth = 0;
284
+ let attrs = "";
285
+ let start = 0;
286
+ let resume = 0;
287
+ for (const tag of findTags(markup, ["blockquote"], true)) {
288
+ if (depth === 0) {
289
+ if (!tag.closing && itemtype.test(tag.attrs)) {
290
+ kept.push(markup.slice(resume, tag.start));
291
+ [depth, attrs, start] = [1, tag.attrs, tag.end];
292
+ }
293
+ continue;
294
+ }
295
+ depth += tag.closing ? -1 : 1;
296
+ if (depth === 0) {
297
+ cut.push([attrs, markup.slice(start, tag.start)]);
298
+ resume = tag.end;
299
+ }
300
+ }
301
+ if (depth) {
302
+ cut.push([attrs, markup.slice(start)]);
303
+ resume = markup.length;
304
+ }
305
+ kept.push(markup.slice(resume));
306
+ return { kept: kept.join(""), cut };
307
+ }
308
+ function written(activity) {
309
+ let text4 = pyStr4(activity.text);
310
+ const reply = REPLY_ITEMTYPE.test(text4);
311
+ const forward = FORWARD_ITEMTYPE.test(text4);
312
+ if (reply || forward) {
313
+ let kept = forward ? cutForwards(text4).kept : text4;
314
+ kept = reply ? cutReplies(kept).kept : kept;
315
+ text4 = replaceTags(kept, findTags(kept, ["p", "div", "br", "span"], true), " ");
316
+ }
317
+ text4 = replaceTags(text4, findTags(text4, ["attachment"], true), "");
318
+ return replaceTags(text4, findTags(text4, ["quoted"], true), "");
319
+ }
320
+ var MESSAGE_ID = new RegExp(caseless("messageId"), "gu");
321
+ var SPACE_ONE = new RegExp(`^${SPACE}$`, "u");
322
+ function idHeadEnd(text4, at) {
323
+ let i = at;
324
+ while (i < text4.length && SPACE_ONE.test(text4.charAt(i))) i += 1;
325
+ if (text4.charAt(i) !== "=") return void 0;
326
+ i += 1;
327
+ while (i < text4.length && SPACE_ONE.test(text4.charAt(i))) i += 1;
328
+ return text4.charAt(i) === '"' || text4.charAt(i) === "'" ? i + 1 : i;
329
+ }
330
+ var VALUE_STOP = new RegExp(`["'/>${SPACE_CHARS}]`, "u");
331
+ var WORD_CHAR = new RegExp(`^${WORD}$`, "u");
332
+ function valueEnds(text4) {
333
+ let runStart = 0;
334
+ let runEnd = -1;
335
+ return (at) => {
336
+ if (at >= runStart && at < runEnd) return runEnd;
337
+ let end = at;
338
+ while (end < text4.length && !VALUE_STOP.test(text4[end] ?? "")) end++;
339
+ [runStart, runEnd] = [at, end];
340
+ return end;
341
+ };
342
+ }
343
+ function codePointBefore(text4, at) {
344
+ if (at <= 0) return void 0;
345
+ const low = text4.charCodeAt(at - 1);
346
+ const pair = low >= 56320 && low <= 57343 && at >= 2 ? text4.slice(at - 2, at) : text4.slice(at - 1, at);
347
+ return Array.from(pair).at(-1);
348
+ }
349
+ function idCandidates(text4) {
350
+ const end = valueEnds(text4);
351
+ const found = [];
352
+ for (const match of text4.matchAll(MESSAGE_ID)) {
353
+ const before = codePointBefore(text4, match.index);
354
+ if (before !== void 0 && WORD_CHAR.test(before)) continue;
355
+ const valueStart = idHeadEnd(text4, match.index + match[0].length);
356
+ if (valueStart === void 0) continue;
357
+ const valueEnd = end(valueStart);
358
+ if (valueEnd > valueStart) found.push({ start: match.index, valueStart, valueEnd });
359
+ }
360
+ return found;
361
+ }
362
+ function quotedIds(text4) {
363
+ const candidates = idCandidates(text4);
364
+ const ids = [];
365
+ let next = 0;
366
+ let resume = 0;
367
+ let gt = -1;
368
+ for (const tag of quotedStarts(text4)) {
369
+ if (tag.start < resume) continue;
370
+ if (gt < tag.nameEnd) gt = text4.indexOf(">", tag.nameEnd);
371
+ const segmentEnd = gt < 0 ? text4.length : gt;
372
+ while (next < candidates.length && (candidates[next]?.start ?? 0) < tag.nameEnd) next++;
373
+ const found = candidates[next];
374
+ if (found === void 0 || found.start >= segmentEnd) continue;
375
+ ids.push(text4.slice(found.valueStart, found.valueEnd));
376
+ resume = found.valueEnd;
377
+ }
378
+ return ids;
379
+ }
380
+ var QUOTED_HEAD = new RegExp(`${caseless("quoted")}${NOT_WORD_NEXT}`, "uy");
381
+ function quotedStarts(text4) {
382
+ const starts = [];
383
+ for (let at = text4.indexOf("<"); at >= 0; at = text4.indexOf("<", at + 1)) {
384
+ QUOTED_HEAD.lastIndex = at + 1;
385
+ if (QUOTED_HEAD.test(text4)) starts.push({ start: at, nameEnd: QUOTED_HEAD.lastIndex });
386
+ }
387
+ return starts;
237
388
  }
238
389
 
239
- // packages/teams/src/activity/inbound/links.ts
240
- import { pyStr as pyStr6, squashSpaces } from "@primusclaw/personal-agent";
390
+ // packages/teams/src/activity/inbound/quotes-html.ts
391
+ import { pyStr as pyStr5, squashSpaces } from "@primusclaw/personal-agent";
241
392
 
242
393
  // packages/teams/src/html/html5-entities.ts
243
394
  var HTML5_ENTITIES = "AElig=C6|AElig;=C6|AMP=26|AMP;=26|Aacute=C1|Aacute;=C1|Abreve;=102|Acirc=C2|Acirc;=C2|Acy;=410|Afr;=1D504|Agrave=C0|Agrave;=C0|Alpha;=391|Amacr;=100|And;=2A53|Aogon;=104|Aopf;=1D538|ApplyFunction;=2061|Aring=C5|Aring;=C5|Ascr;=1D49C|Assign;=2254|Atilde=C3|Atilde;=C3|Auml=C4|Auml;=C4|Backslash;=2216|Barv;=2AE7|Barwed;=2306|Bcy;=411|Because;=2235|Bernoullis;=212C|Beta;=392|Bfr;=1D505|Bopf;=1D539|Breve;=2D8|Bscr;=212C|Bumpeq;=224E|CHcy;=427|COPY=A9|COPY;=A9|Cacute;=106|Cap;=22D2|CapitalDifferentialD;=2145|Cayleys;=212D|Ccaron;=10C|Ccedil=C7|Ccedil;=C7|Ccirc;=108|Cconint;=2230|Cdot;=10A|Cedilla;=B8|CenterDot;=B7|Cfr;=212D|Chi;=3A7|CircleDot;=2299|CircleMinus;=2296|CirclePlus;=2295|CircleTimes;=2297|ClockwiseContourIntegral;=2232|CloseCurlyDoubleQuote;=201D|CloseCurlyQuote;=2019|Colon;=2237|Colone;=2A74|Congruent;=2261|Conint;=222F|ContourIntegral;=222E|Copf;=2102|Coproduct;=2210|CounterClockwiseContourIntegral;=2233|Cross;=2A2F|Cscr;=1D49E|Cup;=22D3|CupCap;=224D|DD;=2145|DDotrahd;=2911|DJcy;=402|DScy;=405|DZcy;=40F|Dagger;=2021|Darr;=21A1|Dashv;=2AE4|Dcaron;=10E|Dcy;=414|Del;=2207|Delta;=394|Dfr;=1D507|DiacriticalAcute;=B4|DiacriticalDot;=2D9|DiacriticalDoubleAcute;=2DD|DiacriticalGrave;=60|DiacriticalTilde;=2DC|Diamond;=22C4|DifferentialD;=2146|Dopf;=1D53B|Dot;=A8|DotDot;=20DC|DotEqual;=2250|DoubleContourIntegral;=222F|DoubleDot;=A8|DoubleDownArrow;=21D3|DoubleLeftArrow;=21D0|DoubleLeftRightArrow;=21D4|DoubleLeftTee;=2AE4|DoubleLongLeftArrow;=27F8|DoubleLongLeftRightArrow;=27FA|DoubleLongRightArrow;=27F9|DoubleRightArrow;=21D2|DoubleRightTee;=22A8|DoubleUpArrow;=21D1|DoubleUpDownArrow;=21D5|DoubleVerticalBar;=2225|DownArrow;=2193|DownArrowBar;=2913|DownArrowUpArrow;=21F5|DownBreve;=311|DownLeftRightVector;=2950|DownLeftTeeVector;=295E|DownLeftVector;=21BD|DownLeftVectorBar;=2956|DownRightTeeVector;=295F|DownRightVector;=21C1|DownRightVectorBar;=2957|DownTee;=22A4|DownTeeArrow;=21A7|Downarrow;=21D3|Dscr;=1D49F|Dstrok;=110|ENG;=14A|ETH=D0|ETH;=D0|Eacute=C9|Eacute;=C9|Ecaron;=11A|Ecirc=CA|Ecirc;=CA|Ecy;=42D|Edot;=116|Efr;=1D508|Egrave=C8|Egrave;=C8|Element;=2208|Emacr;=112|EmptySmallSquare;=25FB|EmptyVerySmallSquare;=25AB|Eogon;=118|Eopf;=1D53C|Epsilon;=395|Equal;=2A75|EqualTilde;=2242|Equilibrium;=21CC|Escr;=2130|Esim;=2A73|Eta;=397|Euml=CB|Euml;=CB|Exists;=2203|ExponentialE;=2147|Fcy;=424|Ffr;=1D509|FilledSmallSquare;=25FC|FilledVerySmallSquare;=25AA|Fopf;=1D53D|ForAll;=2200|Fouriertrf;=2131|Fscr;=2131|GJcy;=403|GT=3E|GT;=3E|Gamma;=393|Gammad;=3DC|Gbreve;=11E|Gcedil;=122|Gcirc;=11C|Gcy;=413|Gdot;=120|Gfr;=1D50A|Gg;=22D9|Gopf;=1D53E|GreaterEqual;=2265|GreaterEqualLess;=22DB|GreaterFullEqual;=2267|GreaterGreater;=2AA2|GreaterLess;=2277|GreaterSlantEqual;=2A7E|GreaterTilde;=2273|Gscr;=1D4A2|Gt;=226B|HARDcy;=42A|Hacek;=2C7|Hat;=5E|Hcirc;=124|Hfr;=210C|HilbertSpace;=210B|Hopf;=210D|HorizontalLine;=2500|Hscr;=210B|Hstrok;=126|HumpDownHump;=224E|HumpEqual;=224F|IEcy;=415|IJlig;=132|IOcy;=401|Iacute=CD|Iacute;=CD|Icirc=CE|Icirc;=CE|Icy;=418|Idot;=130|Ifr;=2111|Igrave=CC|Igrave;=CC|Im;=2111|Imacr;=12A|ImaginaryI;=2148|Implies;=21D2|Int;=222C|Integral;=222B|Intersection;=22C2|InvisibleComma;=2063|InvisibleTimes;=2062|Iogon;=12E|Iopf;=1D540|Iota;=399|Iscr;=2110|Itilde;=128|Iukcy;=406|Iuml=CF|Iuml;=CF|Jcirc;=134|Jcy;=419|Jfr;=1D50D|Jopf;=1D541|Jscr;=1D4A5|Jsercy;=408|Jukcy;=404|KHcy;=425|KJcy;=40C|Kappa;=39A|Kcedil;=136|Kcy;=41A|Kfr;=1D50E|Kopf;=1D542|Kscr;=1D4A6|LJcy;=409|LT=3C|LT;=3C|Lacute;=139|Lambda;=39B|Lang;=27EA|Laplacetrf;=2112|Larr;=219E|Lcaron;=13D|Lcedil;=13B|Lcy;=41B|LeftAngleBracket;=27E8|LeftArrow;=2190|LeftArrowBar;=21E4|LeftArrowRightArrow;=21C6|LeftCeiling;=2308|LeftDoubleBracket;=27E6|LeftDownTeeVector;=2961|LeftDownVector;=21C3|LeftDownVectorBar;=2959|LeftFloor;=230A|LeftRightArrow;=2194|LeftRightVector;=294E|LeftTee;=22A3|LeftTeeArrow;=21A4|LeftTeeVector;=295A|LeftTriangle;=22B2|LeftTriangleBar;=29CF|LeftTriangleEqual;=22B4|LeftUpDownVector;=2951|LeftUpTeeVector;=2960|LeftUpVector;=21BF|LeftUpVectorBar;=2958|LeftVector;=21BC|LeftVectorBar;=2952|Leftarrow;=21D0|Leftrightarrow;=21D4|LessEqualGreater;=22DA|LessFullEqual;=2266|LessGreater;=2276|LessLess;=2AA1|LessSlantEqual;=2A7D|LessTilde;=2272|Lfr;=1D50F|Ll;=22D8|Lleftarrow;=21DA|Lmidot;=13F|LongLeftArrow;=27F5|LongLeftRightArrow;=27F7|LongRightArrow;=27F6|Longleftarrow;=27F8|Longleftrightarrow;=27FA|Longrightarrow;=27F9|Lopf;=1D543|LowerLeftArrow;=2199|LowerRightArrow;=2198|Lscr;=2112|Lsh;=21B0|Lstrok;=141|Lt;=226A|Map;=2905|Mcy;=41C|MediumSpace;=205F|Mellintrf;=2133|Mfr;=1D510|MinusPlus;=2213|Mopf;=1D544|Mscr;=2133|Mu;=39C|NJcy;=40A|Nacute;=143|Ncaron;=147|Ncedil;=145|Ncy;=41D|NegativeMediumSpace;=200B|NegativeThickSpace;=200B|NegativeThinSpace;=200B|NegativeVeryThinSpace;=200B|NestedGreaterGreater;=226B|NestedLessLess;=226A|NewLine;=A|Nfr;=1D511|NoBreak;=2060|NonBreakingSpace;=A0|Nopf;=2115|Not;=2AEC|NotCongruent;=2262|NotCupCap;=226D|NotDoubleVerticalBar;=2226|NotElement;=2209|NotEqual;=2260|NotEqualTilde;=2242,338|NotExists;=2204|NotGreater;=226F|NotGreaterEqual;=2271|NotGreaterFullEqual;=2267,338|NotGreaterGreater;=226B,338|NotGreaterLess;=2279|NotGreaterSlantEqual;=2A7E,338|NotGreaterTilde;=2275|NotHumpDownHump;=224E,338|NotHumpEqual;=224F,338|NotLeftTriangle;=22EA|NotLeftTriangleBar;=29CF,338|NotLeftTriangleEqual;=22EC|NotLess;=226E|NotLessEqual;=2270|NotLessGreater;=2278|NotLessLess;=226A,338|NotLessSlantEqual;=2A7D,338|NotLessTilde;=2274|NotNestedGreaterGreater;=2AA2,338|NotNestedLessLess;=2AA1,338|NotPrecedes;=2280|NotPrecedesEqual;=2AAF,338|NotPrecedesSlantEqual;=22E0|NotReverseElement;=220C|NotRightTriangle;=22EB|NotRightTriangleBar;=29D0,338|NotRightTriangleEqual;=22ED|NotSquareSubset;=228F,338|NotSquareSubsetEqual;=22E2|NotSquareSuperset;=2290,338|NotSquareSupersetEqual;=22E3|NotSubset;=2282,20D2|NotSubsetEqual;=2288|NotSucceeds;=2281|NotSucceedsEqual;=2AB0,338|NotSucceedsSlantEqual;=22E1|NotSucceedsTilde;=227F,338|NotSuperset;=2283,20D2|NotSupersetEqual;=2289|NotTilde;=2241|NotTildeEqual;=2244|NotTildeFullEqual;=2247|NotTildeTilde;=2249|NotVerticalBar;=2224|Nscr;=1D4A9|Ntilde=D1|Ntilde;=D1|Nu;=39D|OElig;=152|Oacute=D3|Oacute;=D3|Ocirc=D4|Ocirc;=D4|Ocy;=41E|Odblac;=150|Ofr;=1D512|Ograve=D2|Ograve;=D2|Omacr;=14C|Omega;=3A9|Omicron;=39F|Oopf;=1D546|OpenCurlyDoubleQuote;=201C|OpenCurlyQuote;=2018|Or;=2A54|Oscr;=1D4AA|Oslash=D8|Oslash;=D8|Otilde=D5|Otilde;=D5|Otimes;=2A37|Ouml=D6|Ouml;=D6|OverBar;=203E|OverBrace;=23DE|OverBracket;=23B4|OverParenthesis;=23DC|PartialD;=2202|Pcy;=41F|Pfr;=1D513|Phi;=3A6|Pi;=3A0|PlusMinus;=B1|Poincareplane;=210C|Popf;=2119|Pr;=2ABB|Precedes;=227A|PrecedesEqual;=2AAF|PrecedesSlantEqual;=227C|PrecedesTilde;=227E|Prime;=2033|Product;=220F|Proportion;=2237|Proportional;=221D|Pscr;=1D4AB|Psi;=3A8|QUOT=22|QUOT;=22|Qfr;=1D514|Qopf;=211A|Qscr;=1D4AC|RBarr;=2910|REG=AE|REG;=AE|Racute;=154|Rang;=27EB|Rarr;=21A0|Rarrtl;=2916|Rcaron;=158|Rcedil;=156|Rcy;=420|Re;=211C|ReverseElement;=220B|ReverseEquilibrium;=21CB|ReverseUpEquilibrium;=296F|Rfr;=211C|Rho;=3A1|RightAngleBracket;=27E9|RightArrow;=2192|RightArrowBar;=21E5|RightArrowLeftArrow;=21C4|RightCeiling;=2309|RightDoubleBracket;=27E7|RightDownTeeVector;=295D|RightDownVector;=21C2|RightDownVectorBar;=2955|RightFloor;=230B|RightTee;=22A2|RightTeeArrow;=21A6|RightTeeVector;=295B|RightTriangle;=22B3|RightTriangleBar;=29D0|RightTriangleEqual;=22B5|RightUpDownVector;=294F|RightUpTeeVector;=295C|RightUpVector;=21BE|RightUpVectorBar;=2954|RightVector;=21C0|RightVectorBar;=2953|Rightarrow;=21D2|Ropf;=211D|RoundImplies;=2970|Rrightarrow;=21DB|Rscr;=211B|Rsh;=21B1|RuleDelayed;=29F4|SHCHcy;=429|SHcy;=428|SOFTcy;=42C|Sacute;=15A|Sc;=2ABC|Scaron;=160|Scedil;=15E|Scirc;=15C|Scy;=421|Sfr;=1D516|ShortDownArrow;=2193|ShortLeftArrow;=2190|ShortRightArrow;=2192|ShortUpArrow;=2191|Sigma;=3A3|SmallCircle;=2218|Sopf;=1D54A|Sqrt;=221A|Square;=25A1|SquareIntersection;=2293|SquareSubset;=228F|SquareSubsetEqual;=2291|SquareSuperset;=2290|SquareSupersetEqual;=2292|SquareUnion;=2294|Sscr;=1D4AE|Star;=22C6|Sub;=22D0|Subset;=22D0|SubsetEqual;=2286|Succeeds;=227B|SucceedsEqual;=2AB0|SucceedsSlantEqual;=227D|SucceedsTilde;=227F|SuchThat;=220B|Sum;=2211|Sup;=22D1|Superset;=2283|SupersetEqual;=2287|Supset;=22D1|THORN=DE|THORN;=DE|TRADE;=2122|TSHcy;=40B|TScy;=426|Tab;=9|Tau;=3A4|Tcaron;=164|Tcedil;=162|Tcy;=422|Tfr;=1D517|Therefore;=2234|Theta;=398|ThickSpace;=205F,200A|ThinSpace;=2009|Tilde;=223C|TildeEqual;=2243|TildeFullEqual;=2245|TildeTilde;=2248|Topf;=1D54B|TripleDot;=20DB|Tscr;=1D4AF|Tstrok;=166|Uacute=DA|Uacute;=DA|Uarr;=219F|Uarrocir;=2949|Ubrcy;=40E|Ubreve;=16C|Ucirc=DB|Ucirc;=DB|Ucy;=423|Udblac;=170|Ufr;=1D518|Ugrave=D9|Ugrave;=D9|Umacr;=16A|UnderBar;=5F|UnderBrace;=23DF|UnderBracket;=23B5|UnderParenthesis;=23DD|Union;=22C3|UnionPlus;=228E|Uogon;=172|Uopf;=1D54C|UpArrow;=2191|UpArrowBar;=2912|UpArrowDownArrow;=21C5|UpDownArrow;=2195|UpEquilibrium;=296E|UpTee;=22A5|UpTeeArrow;=21A5|Uparrow;=21D1|Updownarrow;=21D5|UpperLeftArrow;=2196|UpperRightArrow;=2197|Upsi;=3D2|Upsilon;=3A5|Uring;=16E|Uscr;=1D4B0|Utilde;=168|Uuml=DC|Uuml;=DC|VDash;=22AB|Vbar;=2AEB|Vcy;=412|Vdash;=22A9|Vdashl;=2AE6|Vee;=22C1|Verbar;=2016|Vert;=2016|VerticalBar;=2223|VerticalLine;=7C|VerticalSeparator;=2758|VerticalTilde;=2240|VeryThinSpace;=200A|Vfr;=1D519|Vopf;=1D54D|Vscr;=1D4B1|Vvdash;=22AA|Wcirc;=174|Wedge;=22C0|Wfr;=1D51A|Wopf;=1D54E|Wscr;=1D4B2|Xfr;=1D51B|Xi;=39E|Xopf;=1D54F|Xscr;=1D4B3|YAcy;=42F|YIcy;=407|YUcy;=42E|Yacute=DD|Yacute;=DD|Ycirc;=176|Ycy;=42B|Yfr;=1D51C|Yopf;=1D550|Yscr;=1D4B4|Yuml;=178|ZHcy;=416|Zacute;=179|Zcaron;=17D|Zcy;=417|Zdot;=17B|ZeroWidthSpace;=200B|Zeta;=396|Zfr;=2128|Zopf;=2124|Zscr;=1D4B5|aacute=E1|aacute;=E1|abreve;=103|ac;=223E|acE;=223E,333|acd;=223F|acirc=E2|acirc;=E2|acute=B4|acute;=B4|acy;=430|aelig=E6|aelig;=E6|af;=2061|afr;=1D51E|agrave=E0|agrave;=E0|alefsym;=2135|aleph;=2135|alpha;=3B1|amacr;=101|amalg;=2A3F|amp=26|amp;=26|and;=2227|andand;=2A55|andd;=2A5C|andslope;=2A58|andv;=2A5A|ang;=2220|ange;=29A4|angle;=2220|angmsd;=2221|angmsdaa;=29A8|angmsdab;=29A9|angmsdac;=29AA|angmsdad;=29AB|angmsdae;=29AC|angmsdaf;=29AD|angmsdag;=29AE|angmsdah;=29AF|angrt;=221F|angrtvb;=22BE|angrtvbd;=299D|angsph;=2222|angst;=C5|angzarr;=237C|aogon;=105|aopf;=1D552|ap;=2248|apE;=2A70|apacir;=2A6F|ape;=224A|apid;=224B|apos;=27|approx;=2248|approxeq;=224A|aring=E5|aring;=E5|ascr;=1D4B6|ast;=2A|asymp;=2248|asympeq;=224D|atilde=E3|atilde;=E3|auml=E4|auml;=E4|awconint;=2233|awint;=2A11|bNot;=2AED|backcong;=224C|backepsilon;=3F6|backprime;=2035|backsim;=223D|backsimeq;=22CD|barvee;=22BD|barwed;=2305|barwedge;=2305|bbrk;=23B5|bbrktbrk;=23B6|bcong;=224C|bcy;=431|bdquo;=201E|becaus;=2235|because;=2235|bemptyv;=29B0|bepsi;=3F6|bernou;=212C|beta;=3B2|beth;=2136|between;=226C|bfr;=1D51F|bigcap;=22C2|bigcirc;=25EF|bigcup;=22C3|bigodot;=2A00|bigoplus;=2A01|bigotimes;=2A02|bigsqcup;=2A06|bigstar;=2605|bigtriangledown;=25BD|bigtriangleup;=25B3|biguplus;=2A04|bigvee;=22C1|bigwedge;=22C0|bkarow;=290D|blacklozenge;=29EB|blacksquare;=25AA|blacktriangle;=25B4|blacktriangledown;=25BE|blacktriangleleft;=25C2|blacktriangleright;=25B8|blank;=2423|blk12;=2592|blk14;=2591|blk34;=2593|block;=2588|bne;=3D,20E5|bnequiv;=2261,20E5|bnot;=2310|bopf;=1D553|bot;=22A5|bottom;=22A5|bowtie;=22C8|boxDL;=2557|boxDR;=2554|boxDl;=2556|boxDr;=2553|boxH;=2550|boxHD;=2566|boxHU;=2569|boxHd;=2564|boxHu;=2567|boxUL;=255D|boxUR;=255A|boxUl;=255C|boxUr;=2559|boxV;=2551|boxVH;=256C|boxVL;=2563|boxVR;=2560|boxVh;=256B|boxVl;=2562|boxVr;=255F|boxbox;=29C9|boxdL;=2555|boxdR;=2552|boxdl;=2510|boxdr;=250C|boxh;=2500|boxhD;=2565|boxhU;=2568|boxhd;=252C|boxhu;=2534|boxminus;=229F|boxplus;=229E|boxtimes;=22A0|boxuL;=255B|boxuR;=2558|boxul;=2518|boxur;=2514|boxv;=2502|boxvH;=256A|boxvL;=2561|boxvR;=255E|boxvh;=253C|boxvl;=2524|boxvr;=251C|bprime;=2035|breve;=2D8|brvbar=A6|brvbar;=A6|bscr;=1D4B7|bsemi;=204F|bsim;=223D|bsime;=22CD|bsol;=5C|bsolb;=29C5|bsolhsub;=27C8|bull;=2022|bullet;=2022|bump;=224E|bumpE;=2AAE|bumpe;=224F|bumpeq;=224F|cacute;=107|cap;=2229|capand;=2A44|capbrcup;=2A49|capcap;=2A4B|capcup;=2A47|capdot;=2A40|caps;=2229,FE00|caret;=2041|caron;=2C7|ccaps;=2A4D|ccaron;=10D|ccedil=E7|ccedil;=E7|ccirc;=109|ccups;=2A4C|ccupssm;=2A50|cdot;=10B|cedil=B8|cedil;=B8|cemptyv;=29B2|cent=A2|cent;=A2|centerdot;=B7|cfr;=1D520|chcy;=447|check;=2713|checkmark;=2713|chi;=3C7|cir;=25CB|cirE;=29C3|circ;=2C6|circeq;=2257|circlearrowleft;=21BA|circlearrowright;=21BB|circledR;=AE|circledS;=24C8|circledast;=229B|circledcirc;=229A|circleddash;=229D|cire;=2257|cirfnint;=2A10|cirmid;=2AEF|cirscir;=29C2|clubs;=2663|clubsuit;=2663|colon;=3A|colone;=2254|coloneq;=2254|comma;=2C|commat;=40|comp;=2201|compfn;=2218|complement;=2201|complexes;=2102|cong;=2245|congdot;=2A6D|conint;=222E|copf;=1D554|coprod;=2210|copy=A9|copy;=A9|copysr;=2117|crarr;=21B5|cross;=2717|cscr;=1D4B8|csub;=2ACF|csube;=2AD1|csup;=2AD0|csupe;=2AD2|ctdot;=22EF|cudarrl;=2938|cudarrr;=2935|cuepr;=22DE|cuesc;=22DF|cularr;=21B6|cularrp;=293D|cup;=222A|cupbrcap;=2A48|cupcap;=2A46|cupcup;=2A4A|cupdot;=228D|cupor;=2A45|cups;=222A,FE00|curarr;=21B7|curarrm;=293C|curlyeqprec;=22DE|curlyeqsucc;=22DF|curlyvee;=22CE|curlywedge;=22CF|curren=A4|curren;=A4|curvearrowleft;=21B6|curvearrowright;=21B7|cuvee;=22CE|cuwed;=22CF|cwconint;=2232|cwint;=2231|cylcty;=232D|dArr;=21D3|dHar;=2965|dagger;=2020|daleth;=2138|darr;=2193|dash;=2010|dashv;=22A3|dbkarow;=290F|dblac;=2DD|dcaron;=10F|dcy;=434|dd;=2146|ddagger;=2021|ddarr;=21CA|ddotseq;=2A77|deg=B0|deg;=B0|delta;=3B4|demptyv;=29B1|dfisht;=297F|dfr;=1D521|dharl;=21C3|dharr;=21C2|diam;=22C4|diamond;=22C4|diamondsuit;=2666|diams;=2666|die;=A8|digamma;=3DD|disin;=22F2|div;=F7|divide=F7|divide;=F7|divideontimes;=22C7|divonx;=22C7|djcy;=452|dlcorn;=231E|dlcrop;=230D|dollar;=24|dopf;=1D555|dot;=2D9|doteq;=2250|doteqdot;=2251|dotminus;=2238|dotplus;=2214|dotsquare;=22A1|doublebarwedge;=2306|downarrow;=2193|downdownarrows;=21CA|downharpoonleft;=21C3|downharpoonright;=21C2|drbkarow;=2910|drcorn;=231F|drcrop;=230C|dscr;=1D4B9|dscy;=455|dsol;=29F6|dstrok;=111|dtdot;=22F1|dtri;=25BF|dtrif;=25BE|duarr;=21F5|duhar;=296F|dwangle;=29A6|dzcy;=45F|dzigrarr;=27FF|eDDot;=2A77|eDot;=2251|eacute=E9|eacute;=E9|easter;=2A6E|ecaron;=11B|ecir;=2256|ecirc=EA|ecirc;=EA|ecolon;=2255|ecy;=44D|edot;=117|ee;=2147|efDot;=2252|efr;=1D522|eg;=2A9A|egrave=E8|egrave;=E8|egs;=2A96|egsdot;=2A98|el;=2A99|elinters;=23E7|ell;=2113|els;=2A95|elsdot;=2A97|emacr;=113|empty;=2205|emptyset;=2205|emptyv;=2205|emsp13;=2004|emsp14;=2005|emsp;=2003|eng;=14B|ensp;=2002|eogon;=119|eopf;=1D556|epar;=22D5|eparsl;=29E3|eplus;=2A71|epsi;=3B5|epsilon;=3B5|epsiv;=3F5|eqcirc;=2256|eqcolon;=2255|eqsim;=2242|eqslantgtr;=2A96|eqslantless;=2A95|equals;=3D|equest;=225F|equiv;=2261|equivDD;=2A78|eqvparsl;=29E5|erDot;=2253|erarr;=2971|escr;=212F|esdot;=2250|esim;=2242|eta;=3B7|eth=F0|eth;=F0|euml=EB|euml;=EB|euro;=20AC|excl;=21|exist;=2203|expectation;=2130|exponentiale;=2147|fallingdotseq;=2252|fcy;=444|female;=2640|ffilig;=FB03|fflig;=FB00|ffllig;=FB04|ffr;=1D523|filig;=FB01|fjlig;=66,6A|flat;=266D|fllig;=FB02|fltns;=25B1|fnof;=192|fopf;=1D557|forall;=2200|fork;=22D4|forkv;=2AD9|fpartint;=2A0D|frac12=BD|frac12;=BD|frac13;=2153|frac14=BC|frac14;=BC|frac15;=2155|frac16;=2159|frac18;=215B|frac23;=2154|frac25;=2156|frac34=BE|frac34;=BE|frac35;=2157|frac38;=215C|frac45;=2158|frac56;=215A|frac58;=215D|frac78;=215E|frasl;=2044|frown;=2322|fscr;=1D4BB|gE;=2267|gEl;=2A8C|gacute;=1F5|gamma;=3B3|gammad;=3DD|gap;=2A86|gbreve;=11F|gcirc;=11D|gcy;=433|gdot;=121|ge;=2265|gel;=22DB|geq;=2265|geqq;=2267|geqslant;=2A7E|ges;=2A7E|gescc;=2AA9|gesdot;=2A80|gesdoto;=2A82|gesdotol;=2A84|gesl;=22DB,FE00|gesles;=2A94|gfr;=1D524|gg;=226B|ggg;=22D9|gimel;=2137|gjcy;=453|gl;=2277|glE;=2A92|gla;=2AA5|glj;=2AA4|gnE;=2269|gnap;=2A8A|gnapprox;=2A8A|gne;=2A88|gneq;=2A88|gneqq;=2269|gnsim;=22E7|gopf;=1D558|grave;=60|gscr;=210A|gsim;=2273|gsime;=2A8E|gsiml;=2A90|gt=3E|gt;=3E|gtcc;=2AA7|gtcir;=2A7A|gtdot;=22D7|gtlPar;=2995|gtquest;=2A7C|gtrapprox;=2A86|gtrarr;=2978|gtrdot;=22D7|gtreqless;=22DB|gtreqqless;=2A8C|gtrless;=2277|gtrsim;=2273|gvertneqq;=2269,FE00|gvnE;=2269,FE00|hArr;=21D4|hairsp;=200A|half;=BD|hamilt;=210B|hardcy;=44A|harr;=2194|harrcir;=2948|harrw;=21AD|hbar;=210F|hcirc;=125|hearts;=2665|heartsuit;=2665|hellip;=2026|hercon;=22B9|hfr;=1D525|hksearow;=2925|hkswarow;=2926|hoarr;=21FF|homtht;=223B|hookleftarrow;=21A9|hookrightarrow;=21AA|hopf;=1D559|horbar;=2015|hscr;=1D4BD|hslash;=210F|hstrok;=127|hybull;=2043|hyphen;=2010|iacute=ED|iacute;=ED|ic;=2063|icirc=EE|icirc;=EE|icy;=438|iecy;=435|iexcl=A1|iexcl;=A1|iff;=21D4|ifr;=1D526|igrave=EC|igrave;=EC|ii;=2148|iiiint;=2A0C|iiint;=222D|iinfin;=29DC|iiota;=2129|ijlig;=133|imacr;=12B|image;=2111|imagline;=2110|imagpart;=2111|imath;=131|imof;=22B7|imped;=1B5|in;=2208|incare;=2105|infin;=221E|infintie;=29DD|inodot;=131|int;=222B|intcal;=22BA|integers;=2124|intercal;=22BA|intlarhk;=2A17|intprod;=2A3C|iocy;=451|iogon;=12F|iopf;=1D55A|iota;=3B9|iprod;=2A3C|iquest=BF|iquest;=BF|iscr;=1D4BE|isin;=2208|isinE;=22F9|isindot;=22F5|isins;=22F4|isinsv;=22F3|isinv;=2208|it;=2062|itilde;=129|iukcy;=456|iuml=EF|iuml;=EF|jcirc;=135|jcy;=439|jfr;=1D527|jmath;=237|jopf;=1D55B|jscr;=1D4BF|jsercy;=458|jukcy;=454|kappa;=3BA|kappav;=3F0|kcedil;=137|kcy;=43A|kfr;=1D528|kgreen;=138|khcy;=445|kjcy;=45C|kopf;=1D55C|kscr;=1D4C0|lAarr;=21DA|lArr;=21D0|lAtail;=291B|lBarr;=290E|lE;=2266|lEg;=2A8B|lHar;=2962|lacute;=13A|laemptyv;=29B4|lagran;=2112|lambda;=3BB|lang;=27E8|langd;=2991|langle;=27E8|lap;=2A85|laquo=AB|laquo;=AB|larr;=2190|larrb;=21E4|larrbfs;=291F|larrfs;=291D|larrhk;=21A9|larrlp;=21AB|larrpl;=2939|larrsim;=2973|larrtl;=21A2|lat;=2AAB|latail;=2919|late;=2AAD|lates;=2AAD,FE00|lbarr;=290C|lbbrk;=2772|lbrace;=7B|lbrack;=5B|lbrke;=298B|lbrksld;=298F|lbrkslu;=298D|lcaron;=13E|lcedil;=13C|lceil;=2308|lcub;=7B|lcy;=43B|ldca;=2936|ldquo;=201C|ldquor;=201E|ldrdhar;=2967|ldrushar;=294B|ldsh;=21B2|le;=2264|leftarrow;=2190|leftarrowtail;=21A2|leftharpoondown;=21BD|leftharpoonup;=21BC|leftleftarrows;=21C7|leftrightarrow;=2194|leftrightarrows;=21C6|leftrightharpoons;=21CB|leftrightsquigarrow;=21AD|leftthreetimes;=22CB|leg;=22DA|leq;=2264|leqq;=2266|leqslant;=2A7D|les;=2A7D|lescc;=2AA8|lesdot;=2A7F|lesdoto;=2A81|lesdotor;=2A83|lesg;=22DA,FE00|lesges;=2A93|lessapprox;=2A85|lessdot;=22D6|lesseqgtr;=22DA|lesseqqgtr;=2A8B|lessgtr;=2276|lesssim;=2272|lfisht;=297C|lfloor;=230A|lfr;=1D529|lg;=2276|lgE;=2A91|lhard;=21BD|lharu;=21BC|lharul;=296A|lhblk;=2584|ljcy;=459|ll;=226A|llarr;=21C7|llcorner;=231E|llhard;=296B|lltri;=25FA|lmidot;=140|lmoust;=23B0|lmoustache;=23B0|lnE;=2268|lnap;=2A89|lnapprox;=2A89|lne;=2A87|lneq;=2A87|lneqq;=2268|lnsim;=22E6|loang;=27EC|loarr;=21FD|lobrk;=27E6|longleftarrow;=27F5|longleftrightarrow;=27F7|longmapsto;=27FC|longrightarrow;=27F6|looparrowleft;=21AB|looparrowright;=21AC|lopar;=2985|lopf;=1D55D|loplus;=2A2D|lotimes;=2A34|lowast;=2217|lowbar;=5F|loz;=25CA|lozenge;=25CA|lozf;=29EB|lpar;=28|lparlt;=2993|lrarr;=21C6|lrcorner;=231F|lrhar;=21CB|lrhard;=296D|lrm;=200E|lrtri;=22BF|lsaquo;=2039|lscr;=1D4C1|lsh;=21B0|lsim;=2272|lsime;=2A8D|lsimg;=2A8F|lsqb;=5B|lsquo;=2018|lsquor;=201A|lstrok;=142|lt=3C|lt;=3C|ltcc;=2AA6|ltcir;=2A79|ltdot;=22D6|lthree;=22CB|ltimes;=22C9|ltlarr;=2976|ltquest;=2A7B|ltrPar;=2996|ltri;=25C3|ltrie;=22B4|ltrif;=25C2|lurdshar;=294A|luruhar;=2966|lvertneqq;=2268,FE00|lvnE;=2268,FE00|mDDot;=223A|macr=AF|macr;=AF|male;=2642|malt;=2720|maltese;=2720|map;=21A6|mapsto;=21A6|mapstodown;=21A7|mapstoleft;=21A4|mapstoup;=21A5|marker;=25AE|mcomma;=2A29|mcy;=43C|mdash;=2014|measuredangle;=2221|mfr;=1D52A|mho;=2127|micro=B5|micro;=B5|mid;=2223|midast;=2A|midcir;=2AF0|middot=B7|middot;=B7|minus;=2212|minusb;=229F|minusd;=2238|minusdu;=2A2A|mlcp;=2ADB|mldr;=2026|mnplus;=2213|models;=22A7|mopf;=1D55E|mp;=2213|mscr;=1D4C2|mstpos;=223E|mu;=3BC|multimap;=22B8|mumap;=22B8|nGg;=22D9,338|nGt;=226B,20D2|nGtv;=226B,338|nLeftarrow;=21CD|nLeftrightarrow;=21CE|nLl;=22D8,338|nLt;=226A,20D2|nLtv;=226A,338|nRightarrow;=21CF|nVDash;=22AF|nVdash;=22AE|nabla;=2207|nacute;=144|nang;=2220,20D2|nap;=2249|napE;=2A70,338|napid;=224B,338|napos;=149|napprox;=2249|natur;=266E|natural;=266E|naturals;=2115|nbsp=A0|nbsp;=A0|nbump;=224E,338|nbumpe;=224F,338|ncap;=2A43|ncaron;=148|ncedil;=146|ncong;=2247|ncongdot;=2A6D,338|ncup;=2A42|ncy;=43D|ndash;=2013|ne;=2260|neArr;=21D7|nearhk;=2924|nearr;=2197|nearrow;=2197|nedot;=2250,338|nequiv;=2262|nesear;=2928|nesim;=2242,338|nexist;=2204|nexists;=2204|nfr;=1D52B|ngE;=2267,338|nge;=2271|ngeq;=2271|ngeqq;=2267,338|ngeqslant;=2A7E,338|nges;=2A7E,338|ngsim;=2275|ngt;=226F|ngtr;=226F|nhArr;=21CE|nharr;=21AE|nhpar;=2AF2|ni;=220B|nis;=22FC|nisd;=22FA|niv;=220B|njcy;=45A|nlArr;=21CD|nlE;=2266,338|nlarr;=219A|nldr;=2025|nle;=2270|nleftarrow;=219A|nleftrightarrow;=21AE|nleq;=2270|nleqq;=2266,338|nleqslant;=2A7D,338|nles;=2A7D,338|nless;=226E|nlsim;=2274|nlt;=226E|nltri;=22EA|nltrie;=22EC|nmid;=2224|nopf;=1D55F|not=AC|not;=AC|notin;=2209|notinE;=22F9,338|notindot;=22F5,338|notinva;=2209|notinvb;=22F7|notinvc;=22F6|notni;=220C|notniva;=220C|notnivb;=22FE|notnivc;=22FD|npar;=2226|nparallel;=2226|nparsl;=2AFD,20E5|npart;=2202,338|npolint;=2A14|npr;=2280|nprcue;=22E0|npre;=2AAF,338|nprec;=2280|npreceq;=2AAF,338|nrArr;=21CF|nrarr;=219B|nrarrc;=2933,338|nrarrw;=219D,338|nrightarrow;=219B|nrtri;=22EB|nrtrie;=22ED|nsc;=2281|nsccue;=22E1|nsce;=2AB0,338|nscr;=1D4C3|nshortmid;=2224|nshortparallel;=2226|nsim;=2241|nsime;=2244|nsimeq;=2244|nsmid;=2224|nspar;=2226|nsqsube;=22E2|nsqsupe;=22E3|nsub;=2284|nsubE;=2AC5,338|nsube;=2288|nsubset;=2282,20D2|nsubseteq;=2288|nsubseteqq;=2AC5,338|nsucc;=2281|nsucceq;=2AB0,338|nsup;=2285|nsupE;=2AC6,338|nsupe;=2289|nsupset;=2283,20D2|nsupseteq;=2289|nsupseteqq;=2AC6,338|ntgl;=2279|ntilde=F1|ntilde;=F1|ntlg;=2278|ntriangleleft;=22EA|ntrianglelefteq;=22EC|ntriangleright;=22EB|ntrianglerighteq;=22ED|nu;=3BD|num;=23|numero;=2116|numsp;=2007|nvDash;=22AD|nvHarr;=2904|nvap;=224D,20D2|nvdash;=22AC|nvge;=2265,20D2|nvgt;=3E,20D2|nvinfin;=29DE|nvlArr;=2902|nvle;=2264,20D2|nvlt;=3C,20D2|nvltrie;=22B4,20D2|nvrArr;=2903|nvrtrie;=22B5,20D2|nvsim;=223C,20D2|nwArr;=21D6|nwarhk;=2923|nwarr;=2196|nwarrow;=2196|nwnear;=2927|oS;=24C8|oacute=F3|oacute;=F3|oast;=229B|ocir;=229A|ocirc=F4|ocirc;=F4|ocy;=43E|odash;=229D|odblac;=151|odiv;=2A38|odot;=2299|odsold;=29BC|oelig;=153|ofcir;=29BF|ofr;=1D52C|ogon;=2DB|ograve=F2|ograve;=F2|ogt;=29C1|ohbar;=29B5|ohm;=3A9|oint;=222E|olarr;=21BA|olcir;=29BE|olcross;=29BB|oline;=203E|olt;=29C0|omacr;=14D|omega;=3C9|omicron;=3BF|omid;=29B6|ominus;=2296|oopf;=1D560|opar;=29B7|operp;=29B9|oplus;=2295|or;=2228|orarr;=21BB|ord;=2A5D|order;=2134|orderof;=2134|ordf=AA|ordf;=AA|ordm=BA|ordm;=BA|origof;=22B6|oror;=2A56|orslope;=2A57|orv;=2A5B|oscr;=2134|oslash=F8|oslash;=F8|osol;=2298|otilde=F5|otilde;=F5|otimes;=2297|otimesas;=2A36|ouml=F6|ouml;=F6|ovbar;=233D|par;=2225|para=B6|para;=B6|parallel;=2225|parsim;=2AF3|parsl;=2AFD|part;=2202|pcy;=43F|percnt;=25|period;=2E|permil;=2030|perp;=22A5|pertenk;=2031|pfr;=1D52D|phi;=3C6|phiv;=3D5|phmmat;=2133|phone;=260E|pi;=3C0|pitchfork;=22D4|piv;=3D6|planck;=210F|planckh;=210E|plankv;=210F|plus;=2B|plusacir;=2A23|plusb;=229E|pluscir;=2A22|plusdo;=2214|plusdu;=2A25|pluse;=2A72|plusmn=B1|plusmn;=B1|plussim;=2A26|plustwo;=2A27|pm;=B1|pointint;=2A15|popf;=1D561|pound=A3|pound;=A3|pr;=227A|prE;=2AB3|prap;=2AB7|prcue;=227C|pre;=2AAF|prec;=227A|precapprox;=2AB7|preccurlyeq;=227C|preceq;=2AAF|precnapprox;=2AB9|precneqq;=2AB5|precnsim;=22E8|precsim;=227E|prime;=2032|primes;=2119|prnE;=2AB5|prnap;=2AB9|prnsim;=22E8|prod;=220F|profalar;=232E|profline;=2312|profsurf;=2313|prop;=221D|propto;=221D|prsim;=227E|prurel;=22B0|pscr;=1D4C5|psi;=3C8|puncsp;=2008|qfr;=1D52E|qint;=2A0C|qopf;=1D562|qprime;=2057|qscr;=1D4C6|quaternions;=210D|quatint;=2A16|quest;=3F|questeq;=225F|quot=22|quot;=22|rAarr;=21DB|rArr;=21D2|rAtail;=291C|rBarr;=290F|rHar;=2964|race;=223D,331|racute;=155|radic;=221A|raemptyv;=29B3|rang;=27E9|rangd;=2992|range;=29A5|rangle;=27E9|raquo=BB|raquo;=BB|rarr;=2192|rarrap;=2975|rarrb;=21E5|rarrbfs;=2920|rarrc;=2933|rarrfs;=291E|rarrhk;=21AA|rarrlp;=21AC|rarrpl;=2945|rarrsim;=2974|rarrtl;=21A3|rarrw;=219D|ratail;=291A|ratio;=2236|rationals;=211A|rbarr;=290D|rbbrk;=2773|rbrace;=7D|rbrack;=5D|rbrke;=298C|rbrksld;=298E|rbrkslu;=2990|rcaron;=159|rcedil;=157|rceil;=2309|rcub;=7D|rcy;=440|rdca;=2937|rdldhar;=2969|rdquo;=201D|rdquor;=201D|rdsh;=21B3|real;=211C|realine;=211B|realpart;=211C|reals;=211D|rect;=25AD|reg=AE|reg;=AE|rfisht;=297D|rfloor;=230B|rfr;=1D52F|rhard;=21C1|rharu;=21C0|rharul;=296C|rho;=3C1|rhov;=3F1|rightarrow;=2192|rightarrowtail;=21A3|rightharpoondown;=21C1|rightharpoonup;=21C0|rightleftarrows;=21C4|rightleftharpoons;=21CC|rightrightarrows;=21C9|rightsquigarrow;=219D|rightthreetimes;=22CC|ring;=2DA|risingdotseq;=2253|rlarr;=21C4|rlhar;=21CC|rlm;=200F|rmoust;=23B1|rmoustache;=23B1|rnmid;=2AEE|roang;=27ED|roarr;=21FE|robrk;=27E7|ropar;=2986|ropf;=1D563|roplus;=2A2E|rotimes;=2A35|rpar;=29|rpargt;=2994|rppolint;=2A12|rrarr;=21C9|rsaquo;=203A|rscr;=1D4C7|rsh;=21B1|rsqb;=5D|rsquo;=2019|rsquor;=2019|rthree;=22CC|rtimes;=22CA|rtri;=25B9|rtrie;=22B5|rtrif;=25B8|rtriltri;=29CE|ruluhar;=2968|rx;=211E|sacute;=15B|sbquo;=201A|sc;=227B|scE;=2AB4|scap;=2AB8|scaron;=161|sccue;=227D|sce;=2AB0|scedil;=15F|scirc;=15D|scnE;=2AB6|scnap;=2ABA|scnsim;=22E9|scpolint;=2A13|scsim;=227F|scy;=441|sdot;=22C5|sdotb;=22A1|sdote;=2A66|seArr;=21D8|searhk;=2925|searr;=2198|searrow;=2198|sect=A7|sect;=A7|semi;=3B|seswar;=2929|setminus;=2216|setmn;=2216|sext;=2736|sfr;=1D530|sfrown;=2322|sharp;=266F|shchcy;=449|shcy;=448|shortmid;=2223|shortparallel;=2225|shy=AD|shy;=AD|sigma;=3C3|sigmaf;=3C2|sigmav;=3C2|sim;=223C|simdot;=2A6A|sime;=2243|simeq;=2243|simg;=2A9E|simgE;=2AA0|siml;=2A9D|simlE;=2A9F|simne;=2246|simplus;=2A24|simrarr;=2972|slarr;=2190|smallsetminus;=2216|smashp;=2A33|smeparsl;=29E4|smid;=2223|smile;=2323|smt;=2AAA|smte;=2AAC|smtes;=2AAC,FE00|softcy;=44C|sol;=2F|solb;=29C4|solbar;=233F|sopf;=1D564|spades;=2660|spadesuit;=2660|spar;=2225|sqcap;=2293|sqcaps;=2293,FE00|sqcup;=2294|sqcups;=2294,FE00|sqsub;=228F|sqsube;=2291|sqsubset;=228F|sqsubseteq;=2291|sqsup;=2290|sqsupe;=2292|sqsupset;=2290|sqsupseteq;=2292|squ;=25A1|square;=25A1|squarf;=25AA|squf;=25AA|srarr;=2192|sscr;=1D4C8|ssetmn;=2216|ssmile;=2323|sstarf;=22C6|star;=2606|starf;=2605|straightepsilon;=3F5|straightphi;=3D5|strns;=AF|sub;=2282|subE;=2AC5|subdot;=2ABD|sube;=2286|subedot;=2AC3|submult;=2AC1|subnE;=2ACB|subne;=228A|subplus;=2ABF|subrarr;=2979|subset;=2282|subseteq;=2286|subseteqq;=2AC5|subsetneq;=228A|subsetneqq;=2ACB|subsim;=2AC7|subsub;=2AD5|subsup;=2AD3|succ;=227B|succapprox;=2AB8|succcurlyeq;=227D|succeq;=2AB0|succnapprox;=2ABA|succneqq;=2AB6|succnsim;=22E9|succsim;=227F|sum;=2211|sung;=266A|sup1=B9|sup1;=B9|sup2=B2|sup2;=B2|sup3=B3|sup3;=B3|sup;=2283|supE;=2AC6|supdot;=2ABE|supdsub;=2AD8|supe;=2287|supedot;=2AC4|suphsol;=27C9|suphsub;=2AD7|suplarr;=297B|supmult;=2AC2|supnE;=2ACC|supne;=228B|supplus;=2AC0|supset;=2283|supseteq;=2287|supseteqq;=2AC6|supsetneq;=228B|supsetneqq;=2ACC|supsim;=2AC8|supsub;=2AD4|supsup;=2AD6|swArr;=21D9|swarhk;=2926|swarr;=2199|swarrow;=2199|swnwar;=292A|szlig=DF|szlig;=DF|target;=2316|tau;=3C4|tbrk;=23B4|tcaron;=165|tcedil;=163|tcy;=442|tdot;=20DB|telrec;=2315|tfr;=1D531|there4;=2234|therefore;=2234|theta;=3B8|thetasym;=3D1|thetav;=3D1|thickapprox;=2248|thicksim;=223C|thinsp;=2009|thkap;=2248|thksim;=223C|thorn=FE|thorn;=FE|tilde;=2DC|times=D7|times;=D7|timesb;=22A0|timesbar;=2A31|timesd;=2A30|tint;=222D|toea;=2928|top;=22A4|topbot;=2336|topcir;=2AF1|topf;=1D565|topfork;=2ADA|tosa;=2929|tprime;=2034|trade;=2122|triangle;=25B5|triangledown;=25BF|triangleleft;=25C3|trianglelefteq;=22B4|triangleq;=225C|triangleright;=25B9|trianglerighteq;=22B5|tridot;=25EC|trie;=225C|triminus;=2A3A|triplus;=2A39|trisb;=29CD|tritime;=2A3B|trpezium;=23E2|tscr;=1D4C9|tscy;=446|tshcy;=45B|tstrok;=167|twixt;=226C|twoheadleftarrow;=219E|twoheadrightarrow;=21A0|uArr;=21D1|uHar;=2963|uacute=FA|uacute;=FA|uarr;=2191|ubrcy;=45E|ubreve;=16D|ucirc=FB|ucirc;=FB|ucy;=443|udarr;=21C5|udblac;=171|udhar;=296E|ufisht;=297E|ufr;=1D532|ugrave=F9|ugrave;=F9|uharl;=21BF|uharr;=21BE|uhblk;=2580|ulcorn;=231C|ulcorner;=231C|ulcrop;=230F|ultri;=25F8|umacr;=16B|uml=A8|uml;=A8|uogon;=173|uopf;=1D566|uparrow;=2191|updownarrow;=2195|upharpoonleft;=21BF|upharpoonright;=21BE|uplus;=228E|upsi;=3C5|upsih;=3D2|upsilon;=3C5|upuparrows;=21C8|urcorn;=231D|urcorner;=231D|urcrop;=230E|uring;=16F|urtri;=25F9|uscr;=1D4CA|utdot;=22F0|utilde;=169|utri;=25B5|utrif;=25B4|uuarr;=21C8|uuml=FC|uuml;=FC|uwangle;=29A7|vArr;=21D5|vBar;=2AE8|vBarv;=2AE9|vDash;=22A8|vangrt;=299C|varepsilon;=3F5|varkappa;=3F0|varnothing;=2205|varphi;=3D5|varpi;=3D6|varpropto;=221D|varr;=2195|varrho;=3F1|varsigma;=3C2|varsubsetneq;=228A,FE00|varsubsetneqq;=2ACB,FE00|varsupsetneq;=228B,FE00|varsupsetneqq;=2ACC,FE00|vartheta;=3D1|vartriangleleft;=22B2|vartriangleright;=22B3|vcy;=432|vdash;=22A2|vee;=2228|veebar;=22BB|veeeq;=225A|vellip;=22EE|verbar;=7C|vert;=7C|vfr;=1D533|vltri;=22B2|vnsub;=2282,20D2|vnsup;=2283,20D2|vopf;=1D567|vprop;=221D|vrtri;=22B3|vscr;=1D4CB|vsubnE;=2ACB,FE00|vsubne;=228A,FE00|vsupnE;=2ACC,FE00|vsupne;=228B,FE00|vzigzag;=299A|wcirc;=175|wedbar;=2A5F|wedge;=2227|wedgeq;=2259|weierp;=2118|wfr;=1D534|wopf;=1D568|wp;=2118|wr;=2240|wreath;=2240|wscr;=1D4CC|xcap;=22C2|xcirc;=25EF|xcup;=22C3|xdtri;=25BD|xfr;=1D535|xhArr;=27FA|xharr;=27F7|xi;=3BE|xlArr;=27F8|xlarr;=27F5|xmap;=27FC|xnis;=22FB|xodot;=2A00|xopf;=1D569|xoplus;=2A01|xotime;=2A02|xrArr;=27F9|xrarr;=27F6|xscr;=1D4CD|xsqcup;=2A06|xuplus;=2A04|xutri;=25B3|xvee;=22C1|xwedge;=22C0|yacute=FD|yacute;=FD|yacy;=44F|ycirc;=177|ycy;=44B|yen=A5|yen;=A5|yfr;=1D536|yicy;=457|yopf;=1D56A|yscr;=1D4CE|yucy;=44E|yuml=FF|yuml;=FF|zacute;=17A|zcaron;=17E|zcy;=437|zdot;=17C|zeetrf;=2128|zeta;=3B6|zfr;=1D537|zhcy;=436|zigrarr;=21DD|zopf;=1D56B|zscr;=1D4CF|zwj;=200D|zwnj;=200C";
@@ -466,179 +617,483 @@ function tokenize(markup) {
466
617
  return new Lexer(markup).run();
467
618
  }
468
619
 
469
- // packages/teams/src/activity/inbound/markup.ts
470
- import { cpLength, pyStr as pyStr5, pyStrip as pyStrip3 } from "@primusclaw/personal-agent";
471
-
472
- // packages/teams/src/activity/inbound/patterns.ts
473
- import { own } from "@primusclaw/personal-agent";
474
- var SPACE_CHARS = "\\t\\n\\v\\f\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
475
- var SPACE = `[${SPACE_CHARS}]`;
476
- var WORD = "[\\p{L}\\p{N}_]";
477
- var NOT_WORD_NEXT = `(?!${WORD})`;
478
- var FOLDS = { i: "\\u0130\\u0131", k: "\\u212a", s: "\\u017f" };
479
- var SYNTAX = /[\\^$.*+?()[\]{}|/]/;
480
- function literalChar(ch) {
481
- return SYNTAX.test(ch) ? `\\${ch}` : ch;
482
- }
483
- function caseless(literal) {
484
- let source = "";
485
- for (const ch of literal) {
486
- const lower = ch.toLowerCase();
487
- const upper = ch.toUpperCase();
488
- if (lower === upper || Array.from(lower).length > 1 || Array.from(upper).length > 1) {
489
- source += literalChar(ch);
490
- continue;
620
+ // packages/teams/src/activity/inbound/quotes-html.ts
621
+ var FIELDS = /* @__PURE__ */ new Map([
622
+ ["mri", "sender"],
623
+ ["time", "time"],
624
+ ["preview", "text"],
625
+ ["copy", "text"]
626
+ ]);
627
+ var BREAKS = /* @__PURE__ */ new Set(["br", "p", "div", "li", "tr"]);
628
+ var VOID = /* @__PURE__ */ new Set(["br", "img", "hr", "wbr", "input", "meta", "link"]);
629
+ var ITEMID = new RegExp(`(?<!${WORD})${caseless("itemid")}${SPACE}*=${SPACE}*["']?([^"'>${SPACE_CHARS}]+)`, "u");
630
+ var MARK_OPEN = "\uE010";
631
+ var MARK_CLOSE = "\uE011";
632
+ var MARKS = /[\uE010\uE011]/gu;
633
+ function imageMarker(index) {
634
+ return `${MARK_OPEN}img${String(index)}${MARK_CLOSE}`;
635
+ }
636
+ var IMAGE_MARKER = /\uE010img([0-9]+)\uE011/gu;
637
+ var EMOJI_ITEMTYPE = /^https?:\/\/schema\.skype\.com\/Emoji$/iu;
638
+ var ReplyReader = class {
639
+ senderId = "";
640
+ time = "";
641
+ parts = { sender: [], text: [] };
642
+ everything = [];
643
+ /** The images read, in order, when the reader reads them (`readImages`); else an `<img>` says nothing. */
644
+ images;
645
+ field = "";
646
+ depth = 0;
647
+ /**
648
+ * How deep in a blockquote of its own the reader is, in a forwarded message (one read with images): a message
649
+ * forwarded from a reply chain holds the reply's quote, whose author and preview are part of what was forwarded, not
650
+ * the forwarded message's own.
651
+ */
652
+ nested = 0;
653
+ /** The link being read, and the words shown for it so far. */
654
+ href = "";
655
+ words = "";
656
+ constructor(readImages = false) {
657
+ this.images = readImages ? [] : void 0;
658
+ }
659
+ read(tokens) {
660
+ for (const token of tokens) {
661
+ if (token.kind === "data") this.data(token.text);
662
+ else if (token.kind === "end") this.end(token.tag);
663
+ else if (token.selfClosing) this.breakAt(token.tag);
664
+ else this.start(token.tag, token.attrs);
491
665
  }
492
- source += `[${lower}${upper}${own(FOLDS, lower) ?? ""}]`;
666
+ return this;
493
667
  }
494
- return source;
495
- }
496
-
497
- // packages/teams/src/activity/inbound/markup.ts
498
- var AT_TAG = /<\/?[Aa][Tt]>/g;
499
- var LINK_CHARS = 2e3;
500
- var WEB_URL = new RegExp(`^${caseless("http")}${caseless("s")}?://[^${SPACE_CHARS}<>"']+$`, "u");
501
- function webUrl(raw) {
502
- const url = typeof raw === "string" ? pyStrip3(raw) : "";
503
- return cpLength(url) <= LINK_CHARS && WEB_URL.test(url) ? url : "";
504
- }
505
- function findTags(text4, names, closing) {
506
- const head = new RegExp(`${closing ? "(/?)" : "()"}(?:${names.map(caseless).join("|")})${NOT_WORD_NEXT}`, "uy");
507
- const found = [];
508
- let gt = -1;
509
- let at = text4.indexOf("<");
510
- while (at >= 0) {
511
- head.lastIndex = at + 1;
512
- const match = head.exec(text4);
513
- if (match) {
514
- const nameEnd = head.lastIndex;
515
- if (gt < nameEnd) gt = text4.indexOf(">", nameEnd);
516
- if (gt < 0) break;
517
- found.push({ start: at, end: gt + 1, closing: match[1] === "/", attrs: text4.slice(nameEnd, gt) });
518
- at = text4.indexOf("<", gt + 1);
519
- } else {
520
- at = text4.indexOf("<", at + 1);
668
+ breakAt(tag) {
669
+ if (BREAKS.has(tag)) this.say("\n");
670
+ }
671
+ start(tag, attrs) {
672
+ this.breakAt(tag);
673
+ if (tag === "img") this.image(attrs);
674
+ if (VOID.has(tag)) return;
675
+ if (tag === "blockquote" && this.images !== void 0) this.nested++;
676
+ if (tag === "a") [this.href, this.words] = [webUrl(attrValue(attrs, "href")), ""];
677
+ if (this.field) {
678
+ this.depth++;
679
+ return;
680
+ }
681
+ if (this.nested > 0) return;
682
+ const field = FIELDS.get(pyStr5(attrValue(attrs, "itemprop")).toLowerCase());
683
+ if (field === "time") {
684
+ this.time ||= pyStr5(attrValue(attrs, "itemid"));
685
+ } else if (field) {
686
+ if (field === "sender") this.senderId ||= pyStr5(attrValue(attrs, "itemid"));
687
+ [this.field, this.depth] = [field, 1];
521
688
  }
522
689
  }
523
- return found;
690
+ /** An emoji is its own character; any other image is a marker (when images are read). */
691
+ image(attrs) {
692
+ if (this.images === void 0) return;
693
+ const alt = squashSpaces(pyStr5(attrValue(attrs, "alt")).replace(MARKS, ""));
694
+ if (EMOJI_ITEMTYPE.test(pyStr5(attrValue(attrs, "itemtype")).trim())) {
695
+ this.say(alt);
696
+ return;
697
+ }
698
+ this.images.push({ src: webUrl(attrValue(attrs, "src")), itemId: pyStr5(attrValue(attrs, "itemid")), alt });
699
+ this.say(imageMarker(this.images.length - 1));
700
+ }
701
+ end(tag) {
702
+ this.breakAt(tag);
703
+ if (VOID.has(tag)) return;
704
+ if (tag === "blockquote" && this.nested > 0) this.nested--;
705
+ if (tag === "a") {
706
+ if (this.href && !this.words.includes(this.href)) this.say(` <${this.href}>`);
707
+ this.href = "";
708
+ }
709
+ if (this.field) {
710
+ this.depth--;
711
+ if (this.depth <= 0) this.field = "";
712
+ }
713
+ }
714
+ data(text4) {
715
+ const words = this.images === void 0 ? text4 : text4.replace(MARKS, "");
716
+ this.words += words;
717
+ this.say(words);
718
+ }
719
+ say(piece) {
720
+ this.everything.push(piece);
721
+ if (this.field) this.parts[this.field].push(piece);
722
+ }
723
+ };
724
+ function htmlForward(attrs, inner) {
725
+ const reader2 = new ReplyReader(true).read(tokenize(inner));
726
+ const quote2 = quoteOf(attrs, reader2);
727
+ return {
728
+ messageId: quote2.messageId,
729
+ senderId: quote2.senderId,
730
+ sender: quote2.sender,
731
+ time: quote2.time,
732
+ text: quote2.text,
733
+ images: reader2.images ?? []
734
+ };
524
735
  }
525
- function replaceTags(text4, tags, by) {
526
- let out = "";
527
- let resume = 0;
528
- for (const tag of tags) {
529
- out += text4.slice(resume, tag.start) + by;
530
- resume = tag.end;
736
+ function htmlQuote(attrs, inner) {
737
+ return quoteOf(attrs, new ReplyReader().read(tokenize(inner)));
738
+ }
739
+ function quoteOf(attrs, reader2) {
740
+ const sender = squashSpaces(reader2.parts.sender.join(""));
741
+ let text4 = reader2.parts.text.join("");
742
+ if (!text4) {
743
+ const everything = reader2.everything.join("");
744
+ text4 = sender ? everything.replace(sender, () => "") : everything;
531
745
  }
532
- return out + text4.slice(resume);
746
+ return {
747
+ messageId: ITEMID.exec(attrs)?.[1] ?? "",
748
+ senderId: reader2.senderId,
749
+ sender,
750
+ time: reader2.time,
751
+ text: text4,
752
+ deleted: false,
753
+ source: "html"
754
+ };
533
755
  }
534
- var REPLY_ITEMTYPE = new RegExp(caseless("schema.skype.com/Reply"), "u");
535
- function cutReplies(markup) {
536
- const kept = [];
537
- const cut = [];
538
- let depth = 0;
539
- let attrs = "";
540
- let start = 0;
541
- let resume = 0;
542
- for (const tag of findTags(markup, ["blockquote"], true)) {
543
- if (depth === 0) {
544
- if (!tag.closing && REPLY_ITEMTYPE.test(tag.attrs)) {
545
- kept.push(markup.slice(resume, tag.start));
546
- [depth, attrs, start] = [1, tag.attrs, tag.end];
547
- }
548
- continue;
756
+ function htmlQuotes(activity) {
757
+ const cut = [...cutReplies(cutForwards(pyStr5(activity.text)).kept).cut];
758
+ for (const attachment of attachmentsOf(activity)) {
759
+ const content = attachment["content"];
760
+ if (pyStr5(attachment["contentType"]).toLowerCase() === "text/html" && typeof content === "string") {
761
+ cut.push(...cutReplies(cutForwards(content).kept).cut);
549
762
  }
550
- depth += tag.closing ? -1 : 1;
551
- if (depth === 0) {
552
- cut.push([attrs, markup.slice(start, tag.start)]);
553
- resume = tag.end;
763
+ }
764
+ return cut.map(([attrs, inner]) => htmlQuote(attrs, inner));
765
+ }
766
+
767
+ // packages/teams/src/activity/inbound/quotes.ts
768
+ import { cpHead as cpHead3, pyStr as pyStr6, pyStrip as pyStrip3, squashSpaces as squashSpaces2, own as own2 } from "@primusclaw/personal-agent";
769
+ function entityQuotes(activity) {
770
+ const quotes = [];
771
+ for (const entity of entitiesOf(activity)) {
772
+ const data = entity["type"] === "quotedReply" ? entity["quotedReply"] : void 0;
773
+ if (!isFields(data)) continue;
774
+ quotes.push({
775
+ messageId: pyStr6(data["messageId"]),
776
+ senderId: pyStr6(data["senderId"]),
777
+ sender: squashSpaces2(pyStr6(data["senderName"])),
778
+ time: pyStr6(data["time"]),
779
+ text: pyStr6(data["preview"]),
780
+ deleted: data["isReplyDeleted"] === true,
781
+ source: "entity"
782
+ });
783
+ }
784
+ return quotes;
785
+ }
786
+ function sameQuote(known, html) {
787
+ if (known.messageId) return known.messageId === html.messageId;
788
+ return known.sender === html.sender && known.text === html.text;
789
+ }
790
+ function quotesOf(activity) {
791
+ const quotes = entityQuotes(activity);
792
+ for (const html of htmlQuotes(activity)) {
793
+ const same = quotes.findIndex((q) => sameQuote(q, html));
794
+ const known = quotes[same];
795
+ if (known === void 0) {
796
+ quotes.push(html);
797
+ continue;
554
798
  }
799
+ quotes[same] = {
800
+ ...known,
801
+ senderId: known.senderId || html.senderId,
802
+ sender: known.sender || html.sender,
803
+ time: known.time || html.time,
804
+ text: known.text || html.text
805
+ };
555
806
  }
556
- if (depth) {
557
- cut.push([attrs, markup.slice(start)]);
558
- resume = markup.length;
807
+ for (const id of quotedIds(pyStr6(activity.text))) {
808
+ if (!quotes.some((q) => q.messageId === id)) {
809
+ quotes.push({
810
+ messageId: id,
811
+ senderId: "",
812
+ sender: "",
813
+ time: "",
814
+ text: "",
815
+ deleted: false,
816
+ source: "placeholder"
817
+ });
818
+ }
559
819
  }
560
- kept.push(markup.slice(resume));
561
- return { kept: kept.join(""), cut };
820
+ return quotes;
562
821
  }
563
- function written(activity) {
564
- let text4 = pyStr5(activity.text);
565
- if (REPLY_ITEMTYPE.test(text4)) {
566
- const { kept } = cutReplies(text4);
567
- text4 = replaceTags(kept, findTags(kept, ["p", "div", "br", "span"], true), " ");
822
+ function isBotQuote(quote2, bot) {
823
+ const botId = pyStr6(bot["id"]).toLowerCase();
824
+ const quoteId = quote2.senderId.toLowerCase();
825
+ if (botId && quoteId) {
826
+ const botTail = botId.slice(botId.lastIndexOf(":") + 1);
827
+ const quoteTail = quoteId.slice(quoteId.lastIndexOf(":") + 1);
828
+ return quoteId === botId || quoteTail !== "" && quoteTail === botTail;
568
829
  }
569
- return replaceTags(text4, findTags(text4, ["quoted"], true), "");
830
+ return !quoteId && Boolean(quote2.sender) && quote2.sender.toLowerCase() === pyStrip3(pyStr6(bot["name"])).toLowerCase();
570
831
  }
571
- var MESSAGE_ID = new RegExp(caseless("messageId"), "gu");
572
- var SPACE_ONE = new RegExp(`^${SPACE}$`, "u");
573
- function idHeadEnd(text4, at) {
574
- let i = at;
575
- while (i < text4.length && SPACE_ONE.test(text4.charAt(i))) i += 1;
576
- if (text4.charAt(i) !== "=") return void 0;
577
- i += 1;
578
- while (i < text4.length && SPACE_ONE.test(text4.charAt(i))) i += 1;
579
- return text4.charAt(i) === '"' || text4.charAt(i) === "'" ? i + 1 : i;
832
+ var KIND_CHAR = /^[\p{L}\p{N}/._-]$/u;
833
+ function kindsOf(items, key) {
834
+ if (!Array.isArray(items)) return [];
835
+ return items.filter(isFields).slice(0, 10).map(
836
+ (item3) => Array.from(cpHead3(pyStr6(own2(item3, key)), 40)).filter((ch) => KIND_CHAR.test(ch)).join("")
837
+ );
580
838
  }
581
- var VALUE_STOP = new RegExp(`["'/>${SPACE_CHARS}]`, "u");
582
- var WORD_CHAR = new RegExp(`^${WORD}$`, "u");
583
- function valueEnds(text4) {
584
- let runStart = 0;
585
- let runEnd = -1;
586
- return (at) => {
587
- if (at >= runStart && at < runEnd) return runEnd;
588
- let end = at;
589
- while (end < text4.length && !VALUE_STOP.test(text4[end] ?? "")) end++;
590
- [runStart, runEnd] = [at, end];
591
- return end;
592
- };
839
+ function logPlaceholderQuotes(activity, quotes, logger) {
840
+ if (!quotes.some((q) => q.source === "placeholder")) return;
841
+ logger.warn("a quoted placeholder came with no quote data", {
842
+ entityTypes: kindsOf(activity.entities, "type").join(","),
843
+ attachmentTypes: kindsOf(activity.attachments, "contentType").join(",")
844
+ });
593
845
  }
594
- function codePointBefore(text4, at) {
595
- if (at <= 0) return void 0;
596
- const low = text4.charCodeAt(at - 1);
597
- const pair = low >= 56320 && low <= 57343 && at >= 2 ? text4.slice(at - 2, at) : text4.slice(at - 1, at);
598
- return Array.from(pair).at(-1);
846
+
847
+ // packages/teams/src/activity/inbound/forwards.ts
848
+ var FORWARD_REFERENCE = "forwardedmessagereference";
849
+ var REFERENCE_CHARS = 1e6;
850
+ function str(value) {
851
+ return typeof value === "string" ? value : "";
599
852
  }
600
- function idCandidates(text4) {
601
- const end = valueEnds(text4);
853
+ function htmlForwards(activity) {
854
+ const markups = [pyStr7(activity.text)];
855
+ for (const attachment of attachmentsOf(activity)) {
856
+ const content = attachment["content"];
857
+ if (pyStr7(attachment["contentType"]).toLowerCase() === "text/html" && typeof content === "string") {
858
+ markups.push(content);
859
+ }
860
+ }
602
861
  const found = [];
603
- for (const match of text4.matchAll(MESSAGE_ID)) {
604
- const before = codePointBefore(text4, match.index);
605
- if (before !== void 0 && WORD_CHAR.test(before)) continue;
606
- const valueStart = idHeadEnd(text4, match.index + match[0].length);
607
- if (valueStart === void 0) continue;
608
- const valueEnd = end(valueStart);
609
- if (valueEnd > valueStart) found.push({ start: match.index, valueStart, valueEnd });
862
+ for (const markup of markups) {
863
+ if (!FORWARD_ITEMTYPE.test(markup)) continue;
864
+ found.push(cutForwards(markup).cut.map(([attrs, inner]) => ({ ...htmlForward(attrs, inner), source: "html" })));
610
865
  }
611
866
  return found;
612
867
  }
613
- function quotedIds(text4) {
614
- const candidates = idCandidates(text4);
615
- const ids = [];
616
- let next = 0;
617
- let resume = 0;
618
- let gt = -1;
619
- for (const tag of quotedStarts(text4)) {
620
- if (tag.start < resume) continue;
621
- if (gt < tag.nameEnd) gt = text4.indexOf(">", tag.nameEnd);
622
- const segmentEnd = gt < 0 ? text4.length : gt;
623
- while (next < candidates.length && (candidates[next]?.start ?? 0) < tag.nameEnd) next++;
624
- const found = candidates[next];
625
- if (found === void 0 || found.start >= segmentEnd) continue;
626
- ids.push(text4.slice(found.valueStart, found.valueEnd));
627
- resume = found.valueEnd;
868
+ function referenceContent(content) {
869
+ if (isFields(content)) return content;
870
+ if (typeof content !== "string" || content.length > REFERENCE_CHARS) return void 0;
871
+ try {
872
+ const parsed = JSON.parse(content);
873
+ return isFields(parsed) ? parsed : void 0;
874
+ } catch {
875
+ return void 0;
628
876
  }
629
- return ids;
630
877
  }
631
- var QUOTED_HEAD = new RegExp(`${caseless("quoted")}${NOT_WORD_NEXT}`, "uy");
632
- function quotedStarts(text4) {
633
- const starts = [];
634
- for (let at = text4.indexOf("<"); at >= 0; at = text4.indexOf("<", at + 1)) {
635
- QUOTED_HEAD.lastIndex = at + 1;
636
- if (QUOTED_HEAD.test(text4)) starts.push({ start: at, nameEnd: QUOTED_HEAD.lastIndex });
878
+ function senderOf(content) {
879
+ const sender = content["originalMessageSender"];
880
+ if (!isFields(sender)) return { name: "", id: "" };
881
+ for (const kind of ["user", "application", "device"]) {
882
+ const who = own3(sender, kind);
883
+ if (isFields(who) && (str(who["displayName"]) || str(who["id"]))) {
884
+ return { name: squashSpaces3(str(who["displayName"])), id: str(who["id"]) };
885
+ }
637
886
  }
638
- return starts;
887
+ return { name: "", id: "" };
888
+ }
889
+ function referenceForwards(activity) {
890
+ const found = [];
891
+ for (const attachment of attachmentsOf(activity)) {
892
+ if (pyStr7(attachment["contentType"]).toLowerCase() !== FORWARD_REFERENCE) continue;
893
+ const content = referenceContent(attachment["content"]) ?? {};
894
+ const html = htmlForward("", str(content["originalMessageContent"]));
895
+ const sender = senderOf(content);
896
+ found.push({
897
+ messageId: str(content["originalMessageId"]) || pyStr7(attachment["id"]),
898
+ senderId: sender.id,
899
+ sender: sender.name,
900
+ time: str(content["originalSentDateTime"]),
901
+ text: html.text,
902
+ images: html.images,
903
+ source: "reference"
904
+ });
905
+ }
906
+ return found;
907
+ }
908
+ function plainText(read) {
909
+ return squashSpaces3(read.text.replace(IMAGE_MARKER, ""));
910
+ }
911
+ function sameForward(known, other) {
912
+ if (known.messageId && other.messageId) return known.messageId === other.messageId;
913
+ return plainText(known) !== "" && plainText(known) === plainText(other);
914
+ }
915
+ function imageKey(image) {
916
+ return objectIdOf(image) || image.src;
917
+ }
918
+ function withImagesOf(known, other) {
919
+ const have = new Set(known.images.map(imageKey).filter(Boolean));
920
+ const more = other.images.filter((image) => {
921
+ const key = imageKey(image);
922
+ if (key && have.has(key)) return false;
923
+ if (key) have.add(key);
924
+ return true;
925
+ });
926
+ if (more.length === 0) return { text: known.text, images: known.images };
927
+ const images = [...known.images, ...more];
928
+ const markers = more.map((_, at) => imageMarker(known.images.length + at)).join(" ");
929
+ return { text: known.text ? `${known.text}
930
+ ${markers}` : markers, images };
931
+ }
932
+ function forwardsRead(activity) {
933
+ const found = referenceForwards(activity);
934
+ for (const markup of htmlForwards(activity)) {
935
+ const taken = /* @__PURE__ */ new Set();
936
+ for (const html of markup) {
937
+ const same = found.findIndex((known2, at) => !taken.has(at) && sameForward(known2, html));
938
+ const known = found[same];
939
+ if (known === void 0) {
940
+ taken.add(found.length);
941
+ found.push(html);
942
+ continue;
943
+ }
944
+ taken.add(same);
945
+ found[same] = {
946
+ ...known,
947
+ senderId: known.senderId || html.senderId,
948
+ sender: known.sender || html.sender,
949
+ time: known.time || html.time,
950
+ ...plainText(known) || known.images.length ? withImagesOf(known, html) : { text: html.text, images: html.images }
951
+ };
952
+ }
953
+ }
954
+ return found;
955
+ }
956
+ var OBJECT_PATH = /\/objects\/([A-Za-z0-9._~-]{1,200})\/views\//u;
957
+ var OBJECT_ID = /^[A-Za-z0-9._~-]{1,200}$/u;
958
+ function objectIdOf(image) {
959
+ if (OBJECT_ID.test(image.itemId) && image.itemId.includes("-")) return image.itemId;
960
+ return OBJECT_PATH.exec(image.src)?.[1] ?? "";
961
+ }
962
+ function connectorImageUrl(serviceUrl, objectId) {
963
+ if (!serviceUrl.startsWith("https://")) return "";
964
+ const base2 = serviceUrl.endsWith("/") ? serviceUrl : `${serviceUrl}/`;
965
+ return `${base2}v3/attachments/${encodeURIComponent(objectId)}/views/original`;
966
+ }
967
+ function decoded(text4) {
968
+ try {
969
+ return decodeURIComponent(text4);
970
+ } catch {
971
+ return text4;
972
+ }
973
+ }
974
+ function tidy(text4) {
975
+ return text4.split("\n").map((line2) => line2.trimEnd()).filter((line2) => line2.trim() !== "").join("\n").trim();
976
+ }
977
+ function forwardsOf(activity, files, logger) {
978
+ const read = forwardsRead(activity);
979
+ const all = [...files];
980
+ if (read.length === 0) return { forwards: [], files: all };
981
+ const serviceUrl = pyStr7(activity.serviceUrl);
982
+ const placeOf = /* @__PURE__ */ new Map();
983
+ for (const [at, file] of all.entries()) {
984
+ const url = str(file.handle["url"]);
985
+ const id = file.handle["kind"] === "pasted" ? /\/attachments\/([^/]+)\/views\//u.exec(url)?.[1] ?? "" : "";
986
+ if (id) placeOf.set(decoded(id), at + 1);
987
+ }
988
+ const forwards = read.map((forward) => {
989
+ const words = forward.images.map((image) => {
990
+ const id = objectIdOf(image);
991
+ const url = id ? connectorImageUrl(serviceUrl, id) : "";
992
+ if (!url) return "[image not passed on]";
993
+ let place = placeOf.get(id);
994
+ if (place === void 0) {
995
+ place = all.length + 1;
996
+ const handle = { kind: "pasted", url, index: place };
997
+ all.push({ name: "", type: "", handle: { ...handle } });
998
+ placeOf.set(id, place);
999
+ }
1000
+ return `[image-${String(place)}]`;
1001
+ });
1002
+ return {
1003
+ messageId: forward.messageId,
1004
+ author: forward.sender,
1005
+ text: tidy(forward.text.replace(IMAGE_MARKER, (_, at) => words[Number(at)] ?? "")),
1006
+ sentAt: forward.time,
1007
+ source: forward.source
1008
+ };
1009
+ });
1010
+ logger?.info("forwarded messages read", {
1011
+ count: forwards.length,
1012
+ sources: [...new Set(read.map((f) => f.source))].sort().join("+"),
1013
+ images: read.reduce((n, f) => n + f.images.length, 0),
1014
+ attachmentTypes: kindsOf(activity.attachments, "contentType").join(",")
1015
+ });
1016
+ return { forwards, files: all };
1017
+ }
1018
+ function forwardsInText(activity) {
1019
+ return FORWARD_ITEMTYPE.test(pyStr7(activity.text));
1020
+ }
1021
+ var LINK_ADDRESS = / <https?:\/\/[^\s<>]+>/gu;
1022
+ function ownWords(text4, forwards, keepSome = false) {
1023
+ const said = forwards.map((f) => squashSpaces3(f.text.replace(/\[image(?:-[0-9]+| not passed on)\]/gu, ""))).filter(Boolean);
1024
+ if (said.length === 0) return text4;
1025
+ let own14 = squashSpaces3(text4);
1026
+ for (const one of [...said].reverse()) {
1027
+ const shown = squashSpaces3(one.replace(LINK_ADDRESS, ""));
1028
+ const copy2 = [one, shown].find((words) => words !== "" && (own14 === words || own14.endsWith(` ${words}`)));
1029
+ if (copy2 === void 0) return text4;
1030
+ own14 = own14 === copy2 ? "" : own14.slice(0, own14.length - copy2.length - 1);
1031
+ }
1032
+ if (own14 === "" && keepSome) return text4;
1033
+ return firstWords(text4, pySplit(own14).length);
1034
+ }
1035
+ function firstWords(text4, count2) {
1036
+ let at = 0;
1037
+ for (let words = 0; words < count2; words += 1) {
1038
+ while (at < text4.length && isPySpace(text4.charAt(at))) at += 1;
1039
+ while (at < text4.length && !isPySpace(text4.charAt(at))) at += 1;
1040
+ }
1041
+ return text4.slice(0, at);
1042
+ }
1043
+ var READ_KINDS = /^(?:text\/html|image\/.*|application\/vnd\.microsoft\.card\..*|application\/vnd\.microsoft\.teams\.file\.download\.info|forwardedmessagereference)$/u;
1044
+ function logUnreadKinds(activity, logger) {
1045
+ const kinds = kindsOf(activity.attachments, "contentType");
1046
+ if (!kinds.some((kind) => !READ_KINDS.test(kind.toLowerCase()))) return;
1047
+ logger.info("an attachment of a kind not read", {
1048
+ attachmentTypes: kinds.join(","),
1049
+ entityTypes: kindsOf(activity.entities, "type").join(",")
1050
+ });
1051
+ }
1052
+
1053
+ // packages/teams/src/activity/inbound/identity.ts
1054
+ import { cpHead as cpHead4, pyStr as pyStr8, pyStrip as pyStrip4 } from "@primusclaw/personal-agent";
1055
+ function senderOf2(activity) {
1056
+ const who = partOf(activity, "from");
1057
+ const aadId = who["aadObjectId"];
1058
+ if (typeof aadId !== "string" || !aadId) return void 0;
1059
+ const email = pyStrip4(pyStr8(who["userPrincipalName"]) || pyStr8(who["email"]));
1060
+ return { aadId, name: pyStr8(who["name"]), email: email.includes("@") ? email : "" };
1061
+ }
1062
+ function conversationType(activity) {
1063
+ return partOf(activity, "conversation")["conversationType"];
1064
+ }
1065
+ function isPersonal(activity) {
1066
+ return conversationType(activity) === "personal";
1067
+ }
1068
+ function isGroup(activity) {
1069
+ return conversationType(activity) === "groupChat";
1070
+ }
1071
+ function conversationKind(activity) {
1072
+ if (isPersonal(activity)) return "personal";
1073
+ return isGroup(activity) ? "group" : "channel";
1074
+ }
1075
+ function conversationId(activity) {
1076
+ return pyStr8(partOf(activity, "conversation")["id"]);
1077
+ }
1078
+ function tenantOf(activity) {
1079
+ const channelData = activity.channelData;
1080
+ const tenant = isFields(channelData) ? channelData["tenant"] : void 0;
1081
+ const fromChannel = isFields(tenant) ? tenant["id"] : void 0;
1082
+ return pyStr8(partOf(activity, "conversation")["tenantId"]) || pyStr8(fromChannel);
1083
+ }
1084
+ var ALNUM = /[\p{L}\p{N}]/u;
1085
+ function clientPlatform(activity) {
1086
+ const info = entitiesOf(activity).find((entity) => entity["type"] === "clientInfo");
1087
+ const platform = info?.["platform"];
1088
+ if (typeof platform !== "string") return "";
1089
+ return cpHead4(
1090
+ Array.from(platform).filter((ch) => ALNUM.test(ch)).join(""),
1091
+ 16
1092
+ );
639
1093
  }
640
1094
 
641
1095
  // packages/teams/src/activity/inbound/links.ts
1096
+ import { pyStr as pyStr9, squashSpaces as squashSpaces4 } from "@primusclaw/personal-agent";
642
1097
  var LINK_COUNT = 20;
643
1098
  var CARD_TYPES = ["application/vnd.microsoft.card.", "application/vnd.microsoft.teams.card."];
644
1099
  var PLAIN_ENTITIES = /* @__PURE__ */ new Set(["mention", "clientInfo", "quotedReply", "ProductInfo", "streamInfo"]);
@@ -652,7 +1107,7 @@ function htmlLinks(markup) {
652
1107
  let words = "";
653
1108
  const end = () => {
654
1109
  if (url) {
655
- const label = squashSpaces(words);
1110
+ const label = squashSpaces4(words);
656
1111
  found.push({ url, label: label === url ? "" : label });
657
1112
  }
658
1113
  [url, words] = ["", ""];
@@ -671,8 +1126,8 @@ function htmlLinks(markup) {
671
1126
  }
672
1127
  function objectLinks(node, title, depth) {
673
1128
  const found = [];
674
- const own13 = node["title"];
675
- const label = typeof own13 === "string" ? squashSpaces(own13) : title;
1129
+ const own14 = node["title"];
1130
+ const label = typeof own14 === "string" ? squashSpaces4(own14) : title;
676
1131
  const action2 = node["type"] === "openUrl" || node["type"] === "Action.OpenUrl" ? webUrl(node["value"]) : "";
677
1132
  if (action2) found.push({ url: action2, label });
678
1133
  for (const [key, value] of Object.entries(node)) {
@@ -694,12 +1149,12 @@ function cardLinks(node, title = "", depth = 0) {
694
1149
  function attachmentLinks(activity) {
695
1150
  const found = [];
696
1151
  for (const attachment of attachmentsOf(activity)) {
697
- const kind = pyStr6(attachment["contentType"]).toLowerCase();
1152
+ const kind = pyStr9(attachment["contentType"]).toLowerCase();
698
1153
  const content = attachment["content"];
699
1154
  if (kind === "text/html" && typeof content === "string") {
700
- found.push(...htmlLinks(cutReplies(content).kept));
1155
+ found.push(...htmlLinks(cutForwards(cutReplies(content).kept).kept));
701
1156
  } else if (CARD_TYPES.some((prefix) => kind.startsWith(prefix))) {
702
- found.push(...cardLinks(content, pyStr6(attachment["name"])));
1157
+ found.push(...cardLinks(content, pyStr9(attachment["name"])));
703
1158
  const url = "contentUrl" in attachment ? webUrl(attachment["contentUrl"]) : "";
704
1159
  if (url) found.push({ url, label: "" });
705
1160
  }
@@ -707,308 +1162,127 @@ function attachmentLinks(activity) {
707
1162
  return found;
708
1163
  }
709
1164
  function linksOf(activity) {
710
- const found = attachmentLinks(activity);
711
- for (const entity of entitiesOf(activity)) {
712
- const type = entity["type"];
713
- if (!(typeof type === "string" && PLAIN_ENTITIES.has(type))) found.push(...cardLinks(entity));
714
- }
715
- const unique = /* @__PURE__ */ new Map();
716
- for (const link2 of found) if (!unique.has(link2.url)) unique.set(link2.url, link2);
717
- return [...unique.values()].slice(0, LINK_COUNT);
718
- }
719
- function inboundLinksOf(activity) {
720
- return linksOf(activity).map((link2) => ({ url: link2.url, title: link2.label }));
721
- }
722
-
723
- // packages/teams/src/activity/inbound/mentions.ts
724
- import { BOT_NAME, cpLength as cpLength2, pyLstrip, pyStr as pyStr7, pyStrip as pyStrip4 } from "@primusclaw/personal-agent";
725
- var DEFAULT_BOT_NAME = BOT_NAME;
726
- function isMention(entity) {
727
- return entity["type"] === "mention";
728
- }
729
- function mentionsBot(entity, botId) {
730
- const mentioned2 = entity["mentioned"];
731
- return isMention(entity) && Boolean(botId) && isFields(mentioned2) && mentioned2["id"] === botId;
732
- }
733
- function isMentioned(activity) {
734
- const botId = botIdOf(activity);
735
- return entitiesOf(activity).some((entity) => mentionsBot(entity, botId));
736
- }
737
- function isTargeted(activity) {
738
- const recipient = partOf(activity, "recipient");
739
- return recipient["isTargeted"] === true || recipient["is_targeted"] === true;
740
- }
741
- var toBot = /* @__PURE__ */ new Map();
742
- function toBotPattern(botName) {
743
- let pattern = toBot.get(botName);
744
- if (pattern === void 0) {
745
- const name = caseless(botName);
746
- const lead = `(?:${SPACE}|&${caseless("nbsp")};|<(?:${["p", "div", "span"].map(caseless).join("|")})${NOT_WORD_NEXT}[^>]*>)*`;
747
- const at = `<${caseless("at")}>${SPACE}*(?:@${SPACE}*)?${name}${SPACE}*</${caseless("at")}>`;
748
- pattern = new RegExp(`^${lead}(?:${at}|@${SPACE}*${name})(?![\\p{L}\\p{N}_-])`, "u");
749
- toBot.set(botName, pattern);
750
- }
751
- return pattern;
752
- }
753
- function addressedToBot(activity, botName = DEFAULT_BOT_NAME) {
754
- return toBotPattern(botName).test(written(activity));
755
- }
756
- function messageText(activity) {
757
- let text4 = written(activity);
758
- const botId = botIdOf(activity);
759
- for (const entity of entitiesOf(activity)) {
760
- if (isMention(entity) && (!botId || mentionsBot(entity, botId) || !truthy(entity["mentioned"]))) {
761
- text4 = text4.replaceAll(pyStr7(entity["text"]), "");
762
- }
763
- }
764
- return pyStrip4(text4.replace(AT_TAG, ""));
765
- }
766
- var HOLD_OPEN = String.fromCharCode(57344);
767
- var HOLD_CLOSE = String.fromCharCode(57345);
768
- var HELD = new RegExp(`${HOLD_OPEN}([0-9]+)${HOLD_CLOSE}`, "g");
769
- function holdMentions(activity, botId) {
770
- let text4 = written(activity);
771
- const others = [];
772
- for (const entity of entitiesOf(activity).filter(isMention)) {
773
- const raw = pyStr7(entity["text"]);
774
- const mentioned2 = entity["mentioned"];
775
- if (!raw || !text4.includes(raw)) continue;
776
- if (mentionsBot(entity, botId)) {
777
- text4 = text4.replaceAll(raw, "");
778
- } else if (isFields(mentioned2) && truthy(mentioned2)) {
779
- const at = text4.indexOf(raw);
780
- text4 = `${text4.slice(0, at)}${HOLD_OPEN}${String(others.length)}${HOLD_CLOSE}${text4.slice(at + raw.length)}`;
781
- others.push({ entity, mentioned: mentioned2, shown: raw.replace(AT_TAG, "") });
782
- }
783
- }
784
- for (const entity of entitiesOf(activity).filter(isMention)) {
785
- if (!truthy(entity["mentioned"])) text4 = text4.replaceAll(pyStr7(entity["text"]), "");
786
- }
787
- return { held: text4.replace(AT_TAG, ""), others };
788
- }
789
- function release(held, others) {
790
- const offsets = /* @__PURE__ */ new Map();
791
- let text4 = "";
792
- let resume = 0;
793
- for (const match of held.matchAll(HELD)) {
794
- text4 += held.slice(resume, match.index);
795
- const index = Number(match[1]);
796
- offsets.set(index, cpLength2(text4));
797
- text4 += others[index]?.shown ?? "";
798
- resume = match.index + match[0].length;
799
- }
800
- text4 += held.slice(resume);
801
- const lead = cpLength2(text4) - cpLength2(pyLstrip(text4));
802
- for (const [index, offset] of offsets) offsets.set(index, offset - lead);
803
- return { text: pyStrip4(text4), offsets };
804
- }
805
- function inbound(other, offset) {
806
- return {
807
- channelUserId: pyStr7(other.mentioned["id"]),
808
- userId: pyStr7(other.mentioned["aadObjectId"]),
809
- name: pyStr7(other.mentioned["name"]),
810
- shown: other.shown,
811
- offset
812
- };
813
- }
814
- function mentionsOf(activity) {
815
- const botId = botIdOf(activity);
816
- if (!botId) return [];
817
- const words = messageText(activity);
818
- const { held, others } = holdMentions(activity, botId);
819
- const { text: text4, offsets } = release(held, others);
820
- const exact = text4 === words && !written(activity).includes(HOLD_OPEN);
821
- const found = [];
822
- others.forEach((other, index) => {
823
- const offset = exact ? offsets.get(index) ?? -1 : cpIndexOf(words, other.shown);
824
- if (offset >= 0 && other.shown) found.push(inbound(other, offset));
825
- });
826
- return found;
827
- }
828
- function cpIndexOf(text4, part) {
829
- const at = text4.indexOf(part);
830
- return at < 0 ? -1 : cpLength2(text4.slice(0, at));
831
- }
832
-
833
- // packages/teams/src/activity/inbound/quotes.ts
834
- import { cpHead as cpHead4, pyStr as pyStr9, pyStrip as pyStrip5, squashSpaces as squashSpaces3, own as own2 } from "@primusclaw/personal-agent";
835
-
836
- // packages/teams/src/activity/inbound/quotes-html.ts
837
- import { pyStr as pyStr8, squashSpaces as squashSpaces2 } from "@primusclaw/personal-agent";
838
- var FIELDS = /* @__PURE__ */ new Map([
839
- ["mri", "sender"],
840
- ["time", "time"],
841
- ["preview", "text"],
842
- ["copy", "text"]
843
- ]);
844
- var BREAKS = /* @__PURE__ */ new Set(["br", "p", "div", "li", "tr"]);
845
- var VOID = /* @__PURE__ */ new Set(["br", "img", "hr", "wbr", "input", "meta", "link"]);
846
- var ITEMID = new RegExp(`(?<!${WORD})${caseless("itemid")}${SPACE}*=${SPACE}*["']?([^"'>${SPACE_CHARS}]+)`, "u");
847
- var ReplyReader = class {
848
- senderId = "";
849
- time = "";
850
- parts = { sender: [], text: [] };
851
- everything = [];
852
- field = "";
853
- depth = 0;
854
- /** The link being read, and the words shown for it so far. */
855
- href = "";
856
- words = "";
857
- read(tokens) {
858
- for (const token of tokens) {
859
- if (token.kind === "data") this.data(token.text);
860
- else if (token.kind === "end") this.end(token.tag);
861
- else if (token.selfClosing) this.breakAt(token.tag);
862
- else this.start(token.tag, token.attrs);
863
- }
864
- return this;
865
- }
866
- breakAt(tag) {
867
- if (BREAKS.has(tag)) this.say("\n");
868
- }
869
- start(tag, attrs) {
870
- this.breakAt(tag);
871
- if (VOID.has(tag)) return;
872
- if (tag === "a") [this.href, this.words] = [webUrl(attrValue(attrs, "href")), ""];
873
- if (this.field) {
874
- this.depth++;
875
- return;
876
- }
877
- const field = FIELDS.get(pyStr8(attrValue(attrs, "itemprop")).toLowerCase());
878
- if (field === "time") {
879
- this.time ||= pyStr8(attrValue(attrs, "itemid"));
880
- } else if (field) {
881
- if (field === "sender") this.senderId ||= pyStr8(attrValue(attrs, "itemid"));
882
- [this.field, this.depth] = [field, 1];
883
- }
884
- }
885
- end(tag) {
886
- this.breakAt(tag);
887
- if (VOID.has(tag)) return;
888
- if (tag === "a") {
889
- if (this.href && !this.words.includes(this.href)) this.say(` <${this.href}>`);
890
- this.href = "";
891
- }
892
- if (this.field) {
893
- this.depth--;
894
- if (this.depth <= 0) this.field = "";
895
- }
896
- }
897
- data(text4) {
898
- this.words += text4;
899
- this.say(text4);
900
- }
901
- say(piece) {
902
- this.everything.push(piece);
903
- if (this.field) this.parts[this.field].push(piece);
904
- }
905
- };
906
- function htmlQuote(attrs, inner) {
907
- const reader2 = new ReplyReader().read(tokenize(inner));
908
- const sender = squashSpaces2(reader2.parts.sender.join(""));
909
- let text4 = reader2.parts.text.join("");
910
- if (!text4) {
911
- const everything = reader2.everything.join("");
912
- text4 = sender ? everything.replace(sender, () => "") : everything;
913
- }
914
- return {
915
- messageId: ITEMID.exec(attrs)?.[1] ?? "",
916
- senderId: reader2.senderId,
917
- sender,
918
- time: reader2.time,
919
- text: text4,
920
- deleted: false,
921
- source: "html"
922
- };
923
- }
924
- function htmlQuotes(activity) {
925
- const cut = [...cutReplies(pyStr8(activity.text)).cut];
926
- for (const attachment of attachmentsOf(activity)) {
927
- const content = attachment["content"];
928
- if (pyStr8(attachment["contentType"]).toLowerCase() === "text/html" && typeof content === "string") {
929
- cut.push(...cutReplies(content).cut);
930
- }
1165
+ const found = attachmentLinks(activity);
1166
+ for (const entity of entitiesOf(activity)) {
1167
+ const type = entity["type"];
1168
+ if (!(typeof type === "string" && PLAIN_ENTITIES.has(type))) found.push(...cardLinks(entity));
931
1169
  }
932
- return cut.map(([attrs, inner]) => htmlQuote(attrs, inner));
1170
+ const unique = /* @__PURE__ */ new Map();
1171
+ for (const link2 of found) if (!unique.has(link2.url)) unique.set(link2.url, link2);
1172
+ return [...unique.values()].slice(0, LINK_COUNT);
1173
+ }
1174
+ function inboundLinksOf(activity) {
1175
+ return linksOf(activity).map((link2) => ({ url: link2.url, title: link2.label }));
933
1176
  }
934
1177
 
935
- // packages/teams/src/activity/inbound/quotes.ts
936
- function entityQuotes(activity) {
937
- const quotes = [];
938
- for (const entity of entitiesOf(activity)) {
939
- const data = entity["type"] === "quotedReply" ? entity["quotedReply"] : void 0;
940
- if (!isFields(data)) continue;
941
- quotes.push({
942
- messageId: pyStr9(data["messageId"]),
943
- senderId: pyStr9(data["senderId"]),
944
- sender: squashSpaces3(pyStr9(data["senderName"])),
945
- time: pyStr9(data["time"]),
946
- text: pyStr9(data["preview"]),
947
- deleted: data["isReplyDeleted"] === true,
948
- source: "entity"
949
- });
1178
+ // packages/teams/src/activity/inbound/mentions.ts
1179
+ import { BOT_NAME, cpLength as cpLength2, pyLstrip, pyStr as pyStr10, pyStrip as pyStrip5 } from "@primusclaw/personal-agent";
1180
+ var DEFAULT_BOT_NAME = BOT_NAME;
1181
+ function isMention(entity) {
1182
+ return entity["type"] === "mention";
1183
+ }
1184
+ function mentionsBot(entity, botId) {
1185
+ const mentioned2 = entity["mentioned"];
1186
+ return isMention(entity) && Boolean(botId) && isFields(mentioned2) && mentioned2["id"] === botId;
1187
+ }
1188
+ function isMentioned(activity) {
1189
+ const botId = botIdOf(activity);
1190
+ return entitiesOf(activity).some((entity) => mentionsBot(entity, botId));
1191
+ }
1192
+ function isTargeted(activity) {
1193
+ const recipient = partOf(activity, "recipient");
1194
+ return recipient["isTargeted"] === true || recipient["is_targeted"] === true;
1195
+ }
1196
+ var toBot = /* @__PURE__ */ new Map();
1197
+ function toBotPattern(botName) {
1198
+ let pattern = toBot.get(botName);
1199
+ if (pattern === void 0) {
1200
+ const name = caseless(botName);
1201
+ const lead = `(?:${SPACE}|&${caseless("nbsp")};|<(?:${["p", "div", "span"].map(caseless).join("|")})${NOT_WORD_NEXT}[^>]*>)*`;
1202
+ const at = `<${caseless("at")}>${SPACE}*(?:@${SPACE}*)?${name}${SPACE}*</${caseless("at")}>`;
1203
+ pattern = new RegExp(`^${lead}(?:${at}|@${SPACE}*${name})(?![\\p{L}\\p{N}_-])`, "u");
1204
+ toBot.set(botName, pattern);
950
1205
  }
951
- return quotes;
1206
+ return pattern;
952
1207
  }
953
- function sameQuote(known, html) {
954
- if (known.messageId) return known.messageId === html.messageId;
955
- return known.sender === html.sender && known.text === html.text;
1208
+ function addressedToBot(activity, botName = DEFAULT_BOT_NAME) {
1209
+ return toBotPattern(botName).test(written(activity));
956
1210
  }
957
- function quotesOf(activity) {
958
- const quotes = entityQuotes(activity);
959
- for (const html of htmlQuotes(activity)) {
960
- const same = quotes.findIndex((q) => sameQuote(q, html));
961
- const known = quotes[same];
962
- if (known === void 0) {
963
- quotes.push(html);
964
- continue;
1211
+ function messageText(activity) {
1212
+ let text4 = written(activity);
1213
+ const botId = botIdOf(activity);
1214
+ for (const entity of entitiesOf(activity)) {
1215
+ if (isMention(entity) && (!botId || mentionsBot(entity, botId) || !truthy(entity["mentioned"]))) {
1216
+ text4 = text4.replaceAll(pyStr10(entity["text"]), "");
965
1217
  }
966
- quotes[same] = {
967
- ...known,
968
- senderId: known.senderId || html.senderId,
969
- sender: known.sender || html.sender,
970
- time: known.time || html.time,
971
- text: known.text || html.text
972
- };
973
1218
  }
974
- for (const id of quotedIds(pyStr9(activity.text))) {
975
- if (!quotes.some((q) => q.messageId === id)) {
976
- quotes.push({
977
- messageId: id,
978
- senderId: "",
979
- sender: "",
980
- time: "",
981
- text: "",
982
- deleted: false,
983
- source: "placeholder"
984
- });
1219
+ return pyStrip5(text4.replace(AT_TAG, ""));
1220
+ }
1221
+ var HOLD_OPEN = String.fromCharCode(57344);
1222
+ var HOLD_CLOSE = String.fromCharCode(57345);
1223
+ var HELD = new RegExp(`${HOLD_OPEN}([0-9]+)${HOLD_CLOSE}`, "g");
1224
+ function holdMentions(activity, botId) {
1225
+ let text4 = written(activity);
1226
+ const others = [];
1227
+ for (const entity of entitiesOf(activity).filter(isMention)) {
1228
+ const raw = pyStr10(entity["text"]);
1229
+ const mentioned2 = entity["mentioned"];
1230
+ if (!raw || !text4.includes(raw)) continue;
1231
+ if (mentionsBot(entity, botId)) {
1232
+ text4 = text4.replaceAll(raw, "");
1233
+ } else if (isFields(mentioned2) && truthy(mentioned2)) {
1234
+ const at = text4.indexOf(raw);
1235
+ text4 = `${text4.slice(0, at)}${HOLD_OPEN}${String(others.length)}${HOLD_CLOSE}${text4.slice(at + raw.length)}`;
1236
+ others.push({ entity, mentioned: mentioned2, shown: raw.replace(AT_TAG, "") });
985
1237
  }
986
1238
  }
987
- return quotes;
1239
+ for (const entity of entitiesOf(activity).filter(isMention)) {
1240
+ if (!truthy(entity["mentioned"])) text4 = text4.replaceAll(pyStr10(entity["text"]), "");
1241
+ }
1242
+ return { held: text4.replace(AT_TAG, ""), others };
988
1243
  }
989
- function isBotQuote(quote2, bot) {
990
- const botId = pyStr9(bot["id"]).toLowerCase();
991
- const quoteId = quote2.senderId.toLowerCase();
992
- if (botId && quoteId) {
993
- const botTail = botId.slice(botId.lastIndexOf(":") + 1);
994
- const quoteTail = quoteId.slice(quoteId.lastIndexOf(":") + 1);
995
- return quoteId === botId || quoteTail !== "" && quoteTail === botTail;
1244
+ function release(held, others) {
1245
+ const offsets = /* @__PURE__ */ new Map();
1246
+ let text4 = "";
1247
+ let resume = 0;
1248
+ for (const match of held.matchAll(HELD)) {
1249
+ text4 += held.slice(resume, match.index);
1250
+ const index = Number(match[1]);
1251
+ offsets.set(index, cpLength2(text4));
1252
+ text4 += others[index]?.shown ?? "";
1253
+ resume = match.index + match[0].length;
996
1254
  }
997
- return !quoteId && Boolean(quote2.sender) && quote2.sender.toLowerCase() === pyStrip5(pyStr9(bot["name"])).toLowerCase();
1255
+ text4 += held.slice(resume);
1256
+ const lead = cpLength2(text4) - cpLength2(pyLstrip(text4));
1257
+ for (const [index, offset] of offsets) offsets.set(index, offset - lead);
1258
+ return { text: pyStrip5(text4), offsets };
998
1259
  }
999
- var KIND_CHAR = /^[\p{L}\p{N}/._-]$/u;
1000
- function kindsOf(items, key) {
1001
- if (!Array.isArray(items)) return [];
1002
- return items.filter(isFields).slice(0, 10).map(
1003
- (item3) => Array.from(cpHead4(pyStr9(own2(item3, key)), 40)).filter((ch) => KIND_CHAR.test(ch)).join("")
1004
- );
1260
+ function inbound(other, offset) {
1261
+ return {
1262
+ channelUserId: pyStr10(other.mentioned["id"]),
1263
+ userId: pyStr10(other.mentioned["aadObjectId"]),
1264
+ name: pyStr10(other.mentioned["name"]),
1265
+ shown: other.shown,
1266
+ offset
1267
+ };
1005
1268
  }
1006
- function logPlaceholderQuotes(activity, quotes, logger) {
1007
- if (!quotes.some((q) => q.source === "placeholder")) return;
1008
- logger.warn("a quoted placeholder came with no quote data", {
1009
- entityTypes: kindsOf(activity.entities, "type").join(","),
1010
- attachmentTypes: kindsOf(activity.attachments, "contentType").join(",")
1269
+ function mentionsOf(activity) {
1270
+ const botId = botIdOf(activity);
1271
+ if (!botId) return [];
1272
+ const words = messageText(activity);
1273
+ const { held, others } = holdMentions(activity, botId);
1274
+ const { text: text4, offsets } = release(held, others);
1275
+ const exact = text4 === words && !written(activity).includes(HOLD_OPEN);
1276
+ const found = [];
1277
+ others.forEach((other, index) => {
1278
+ const offset = exact ? offsets.get(index) ?? -1 : cpIndexOf(words, other.shown);
1279
+ if (offset >= 0 && other.shown) found.push(inbound(other, offset));
1011
1280
  });
1281
+ return found;
1282
+ }
1283
+ function cpIndexOf(text4, part) {
1284
+ const at = text4.indexOf(part);
1285
+ return at < 0 ? -1 : cpLength2(text4.slice(0, at));
1012
1286
  }
1013
1287
 
1014
1288
  // packages/teams/src/activity/inbound/to-event.ts
@@ -1034,10 +1308,10 @@ function conversationRefOf(activity) {
1034
1308
  }
1035
1309
  function base(activity, sender) {
1036
1310
  return {
1037
- id: pyStr10(activity.id),
1311
+ id: pyStr11(activity.id),
1038
1312
  sender,
1039
1313
  conversation: conversationRefOf(activity),
1040
- locale: pyStr10(activity.locale),
1314
+ locale: pyStr11(activity.locale),
1041
1315
  clientPlatform: clientPlatform(activity)
1042
1316
  };
1043
1317
  }
@@ -1046,16 +1320,18 @@ function messageOf(activity, sender, options) {
1046
1320
  const personal = isPersonal(activity);
1047
1321
  const found = quotesOf(activity);
1048
1322
  const attached = inboundFiles(activity);
1323
+ const forwarded = forwardsOf(activity, attached.files, logger);
1049
1324
  logPlaceholderQuotes(activity, found, logger);
1325
+ logUnreadKinds(activity, logger);
1050
1326
  const bot = partOf(activity, "recipient");
1051
1327
  return {
1052
1328
  type: "message",
1053
1329
  ...base(activity, sender),
1054
- text: messageText(activity),
1330
+ text: forwarded.forwards.length && !forwardsInText(activity) ? ownWords(messageText(activity), forwarded.forwards, /<attachment\b/iu.test(pyStr11(activity.text))) : messageText(activity),
1055
1331
  mentioned: isMentioned(activity),
1056
1332
  targeted: isTargeted(activity),
1057
1333
  namesBotFirst: addressedToBot(activity, options.botName ?? DEFAULT_BOT_NAME),
1058
- conversationName: personal ? "" : pyStr10(partOf(activity, "conversation")["name"]),
1334
+ conversationName: personal ? "" : pyStr11(partOf(activity, "conversation")["name"]),
1059
1335
  mentions: mentionsOf(activity),
1060
1336
  links: inboundLinksOf(activity),
1061
1337
  quotes: found.map((q) => ({
@@ -1067,7 +1343,8 @@ function messageOf(activity, sender, options) {
1067
1343
  deleted: q.deleted,
1068
1344
  source: q.source
1069
1345
  })),
1070
- files: attached.files,
1346
+ ...forwarded.forwards.length ? { forwards: forwarded.forwards } : {},
1347
+ files: forwarded.files,
1071
1348
  unreadableFiles: attached.unreadable,
1072
1349
  provenance: "typed"
1073
1350
  };
@@ -1078,7 +1355,7 @@ function actionOf(activity, sender) {
1078
1355
  ...base(activity, sender),
1079
1356
  verb: cardKindOf(activity),
1080
1357
  data: cardDataOf(activity) ?? {},
1081
- cardMessageId: pyStr10(activity.replyToId),
1358
+ cardMessageId: pyStr11(activity.replyToId),
1082
1359
  invoke: isCardClick(activity),
1083
1360
  clickVerb: cardVerb(activity)
1084
1361
  };
@@ -1087,11 +1364,11 @@ function toInboundEvent(raw, options = {}) {
1087
1364
  const parsed = parseActivity(raw);
1088
1365
  if (!parsed.ok) return parsed;
1089
1366
  const activity = parsed.value;
1090
- const who = senderOf(activity);
1367
+ const who = senderOf2(activity);
1091
1368
  if (who === void 0) return err({ kind: "no_sender" });
1092
1369
  const sender = {
1093
1370
  id: who.aadId,
1094
- channelUserId: pyStr10(partOf(activity, "from")["id"]),
1371
+ channelUserId: pyStr11(partOf(activity, "from")["id"]),
1095
1372
  name: who.name,
1096
1373
  email: who.email
1097
1374
  };
@@ -1108,7 +1385,7 @@ function toInboundEvent(raw, options = {}) {
1108
1385
  }
1109
1386
 
1110
1387
  // packages/teams/src/activity/outbound.ts
1111
- import { pySplit, own as own3 } from "@primusclaw/personal-agent";
1388
+ import { pySplit as pySplit2, own as own4 } from "@primusclaw/personal-agent";
1112
1389
 
1113
1390
  // packages/teams/src/cards/json.ts
1114
1391
  function isObject(value) {
@@ -1122,7 +1399,7 @@ function textActivity(text4) {
1122
1399
  return { type: "message", text: text4, textFormat: "markdown" };
1123
1400
  }
1124
1401
  function copy(activity, key) {
1125
- const value = own3(activity, key);
1402
+ const value = own4(activity, key);
1126
1403
  return value === void 0 ? {} : { [key]: value };
1127
1404
  }
1128
1405
  function activityOfReference(reference2, activityId) {
@@ -1136,7 +1413,7 @@ function activityOfReference(reference2, activityId) {
1136
1413
  text: ""
1137
1414
  };
1138
1415
  for (const optional of ["channelId", "locale"]) {
1139
- if (own3(reference2, optional)) Object.assign(activity, copy(reference2, optional));
1416
+ if (own4(reference2, optional)) Object.assign(activity, copy(reference2, optional));
1140
1417
  }
1141
1418
  return activity;
1142
1419
  }
@@ -1150,7 +1427,7 @@ function deleteEnvelope(reference2, activityId) {
1150
1427
  return { operation: "delete", reference: reference2, activity: { type: "message" }, activity_id: activityId };
1151
1428
  }
1152
1429
  function withMention(activity, teamsId, name) {
1153
- const shown = Array.from(pySplit(name.replace(/[<>]/g, " ")).join(" ")).slice(0, MENTION_NAME_MAX).join("");
1430
+ const shown = Array.from(pySplit2(name.replace(/[<>]/g, " ")).join(" ")).slice(0, MENTION_NAME_MAX).join("");
1154
1431
  if (!(teamsId && shown)) return activity;
1155
1432
  const tag = `<at>${shown}</at>`;
1156
1433
  const entities = Array.isArray(activity["entities"]) ? activity["entities"].filter(isObject) : [];
@@ -1255,11 +1532,11 @@ function restoreConversationRef(stored) {
1255
1532
  }
1256
1533
 
1257
1534
  // packages/teams/src/config/env.ts
1258
- import { pyRstrip as pyRstrip3, pyStrip as pyStrip7, own as own5 } from "@primusclaw/personal-agent";
1535
+ import { pyRstrip as pyRstrip3, pyStrip as pyStrip7, own as own6 } from "@primusclaw/personal-agent";
1259
1536
 
1260
1537
  // packages/teams/src/azure/workload-identity.ts
1261
1538
  import { readFileSync } from "node:fs";
1262
- import { pyRstrip as pyRstrip2, silentLogger as silentLogger3, own as own4 } from "@primusclaw/personal-agent";
1539
+ import { pyRstrip as pyRstrip2, silentLogger as silentLogger3, own as own5 } from "@primusclaw/personal-agent";
1263
1540
 
1264
1541
  // packages/teams/src/connector/errors.ts
1265
1542
  var TokenError = class extends Error {
@@ -1294,16 +1571,16 @@ var DeadlineError = class extends Error {
1294
1571
 
1295
1572
  // packages/teams/src/connector/timer.ts
1296
1573
  function startTimer(clock, ms, reason, parent) {
1297
- const own13 = new AbortController();
1574
+ const own14 = new AbortController();
1298
1575
  const stop = new AbortController();
1299
1576
  clock.sleep(ms, stop.signal).then(
1300
1577
  () => {
1301
- own13.abort(new DeadlineError(reason));
1578
+ own14.abort(new DeadlineError(reason));
1302
1579
  },
1303
1580
  () => void 0
1304
1581
  // the timer was disposed: its sleep is cancelled, nothing is due
1305
1582
  );
1306
- const signal = parent === void 0 ? own13.signal : AbortSignal.any([parent, own13.signal]);
1583
+ const signal = parent === void 0 ? own14.signal : AbortSignal.any([parent, own14.signal]);
1307
1584
  return {
1308
1585
  signal,
1309
1586
  dispose: () => {
@@ -1384,7 +1661,7 @@ function signAssertion(signer, claims) {
1384
1661
 
1385
1662
  // packages/teams/src/connector/tokens/federated.ts
1386
1663
  import { z as z5 } from "zod";
1387
- import { cpHead as cpHead5, pyStr as pyStr11, silentLogger as silentLogger2 } from "@primusclaw/personal-agent";
1664
+ import { cpHead as cpHead5, pyStr as pyStr12, silentLogger as silentLogger2 } from "@primusclaw/personal-agent";
1388
1665
 
1389
1666
  // packages/teams/src/connector/py-parse.ts
1390
1667
  import { pyRstrip, pyStrip as pyStrip6 } from "@primusclaw/personal-agent";
@@ -1631,7 +1908,7 @@ function entraCodes(text4) {
1631
1908
  if (list === void 0) return "";
1632
1909
  const codes = list.map(pyInt);
1633
1910
  if (codes.some((code) => code === void 0)) return "";
1634
- const error = pyStr11(parsed.data.error);
1911
+ const error = pyStr12(parsed.data.error);
1635
1912
  const shown = codes.slice(0, 3).map((code) => `AADSTS${String(code)}`).join(",");
1636
1913
  if (!(codes.length || error)) return "";
1637
1914
  return ` (${cpHead5(error, 40)}${error && shown ? ": " : ""}${shown})`;
@@ -1652,7 +1929,7 @@ var SETTINGS = {
1652
1929
  keyFile: "BOT_ASSERTION_KEY_FILE"
1653
1930
  };
1654
1931
  function workerIdentityFromEnv(env, why) {
1655
- const get3 = (name) => (own4(env, name) ?? "").trim();
1932
+ const get3 = (name) => (own5(env, name) ?? "").trim();
1656
1933
  const missing = Object.values(SETTINGS).filter((name) => !get3(name));
1657
1934
  if (missing.length) throw new WorkerIdentityError(`${why} needs the worker identity: set ${missing.join(", ")}`);
1658
1935
  const issuer = get3(SETTINGS.issuer);
@@ -1768,7 +2045,7 @@ var TeamsConfigError = class extends Error {
1768
2045
  var ON = ["1", "true", "yes", "on"];
1769
2046
  var OFF = ["0", "false", "no", "off"];
1770
2047
  function get(env, name, fallback = "") {
1771
- return pyStrip7(own5(env, name) ?? fallback);
2048
+ return pyStrip7(own6(env, name) ?? fallback);
1772
2049
  }
1773
2050
  function required(env, name) {
1774
2051
  const value = get(env, name);
@@ -1969,7 +2246,7 @@ var Person = z6.object({
1969
2246
  function aadOf(request) {
1970
2247
  return (request.params["aad"] ?? "").toLowerCase();
1971
2248
  }
1972
- function str(value) {
2249
+ function str2(value) {
1973
2250
  return typeof value === "string" || typeof value === "number" ? String(value) : "";
1974
2251
  }
1975
2252
  async function personState(deps, aad, scope) {
@@ -2012,11 +2289,11 @@ function putPersonRoute(deps) {
2012
2289
  const parsed = Person.safeParse(bodyJson(request));
2013
2290
  if (!parsed.success) return Promise.resolve(json(400, { error: "name_and_key_required" }));
2014
2291
  const data = parsed.data;
2015
- const name = str(data.name);
2016
- const outcome = deps.links.redeemPending(aad, name, deps.links.stashPending(str(data.key)));
2292
+ const name = str2(data.name);
2293
+ const outcome = deps.links.redeemPending(aad, name, deps.links.stashPending(str2(data.key)));
2017
2294
  if (outcome !== "ok") return Promise.resolve(json(409, { error: "not_linked", outcome }));
2018
- if (str(data.claw_user_id)) deps.links.setClawUserId(aad, str(data.claw_user_id));
2019
- deps.members.rememberMember(str(data.teams_id) || `29:${aad}`, aad, name);
2295
+ if (str2(data.claw_user_id)) deps.links.setClawUserId(aad, str2(data.claw_user_id));
2296
+ deps.members.rememberMember(str2(data.teams_id) || `29:${aad}`, aad, name);
2020
2297
  if (data.subscribe === false) deps.notifySubs.claimNotifyAttempt(aad, NO_SUBSCRIPTION_SECONDS);
2021
2298
  return Promise.resolve(json(200, { status: "linked" }));
2022
2299
  }
@@ -2534,11 +2811,124 @@ function teamsVersion() {
2534
2811
  return packageVersion(new URL("../package.json", import.meta.url));
2535
2812
  }
2536
2813
 
2537
- // packages/teams/src/servicebus/consumer.ts
2814
+ // packages/teams/src/probe/probe.ts
2538
2815
  import { errorName as errorName3, silentLogger as silentLogger8 } from "@primusclaw/personal-agent";
2816
+ var PROBE = "primusclaw.probe";
2817
+ var PROBE_CONVERSATION = "primusclaw-probe";
2818
+ var PROBE_REPLY_TIMEOUT_MS = 12e4;
2819
+ var PROBE_ID = /^[A-Za-z0-9-]{1,64}$/;
2820
+ var ISO_UTC = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z$/;
2821
+ function sentAtMs(value) {
2822
+ if (typeof value !== "string" || !ISO_UTC.test(value)) return void 0;
2823
+ const ms = Date.parse(value);
2824
+ return Number.isFinite(ms) ? ms : void 0;
2825
+ }
2826
+ var DeliveryProbe = class {
2827
+ constructor(parts) {
2828
+ this.parts = parts;
2829
+ this.logger = parts.logger ?? silentLogger8;
2830
+ }
2831
+ parts;
2832
+ logger;
2833
+ stopping = new AbortController();
2834
+ waiting = /* @__PURE__ */ new Set();
2835
+ /** Whether `body` is a probe (the inbound handler hands it here instead of reading it as an activity). */
2836
+ static is(body) {
2837
+ return body["type"] === PROBE;
2838
+ }
2839
+ /**
2840
+ * Answer one probe: queue the answer, and wait for its ack in the background (the ack comes on the probe's own session,
2841
+ * which the consumer reads only after this returns). A probe that cannot be read is logged and dropped; one whose answer
2842
+ * cannot be queued is counted unanswered at once. Never throws: a redelivered probe would measure the redelivery.
2843
+ */
2844
+ async answer(body) {
2845
+ const id = body["id"];
2846
+ const sent = sentAtMs(body["sent_at"]);
2847
+ if (typeof id !== "string" || !PROBE_ID.test(id) || sent === void 0) {
2848
+ this.logger.warn("delivery probe not read", { why: "malformed" });
2849
+ return;
2850
+ }
2851
+ const outbox = this.parts.outbox;
2852
+ if (outbox === void 0 || this.stopping.signal.aborted) return;
2853
+ const ack = `probe-${id}`;
2854
+ const waiter = this.parts.acks.expect(ack);
2855
+ try {
2856
+ await outbox.publish(
2857
+ envelope("probe", { conversation: { id: PROBE_CONVERSATION } }, { type: "typing" }, { ack })
2858
+ );
2859
+ } catch (error) {
2860
+ this.parts.acks.forget(ack);
2861
+ const feedbackMs2 = this.since(sent);
2862
+ this.logger.warn("delivery probe", {
2863
+ id,
2864
+ outcome: "not_queued",
2865
+ feedback_ms: feedbackMs2,
2866
+ error: errorName3(error)
2867
+ });
2868
+ this.parts.stats?.probed(feedbackMs2, null);
2869
+ return;
2870
+ }
2871
+ const feedbackMs = this.since(sent);
2872
+ const waiting = this.awaitAck(id, ack, waiter.promise, sent, feedbackMs);
2873
+ this.waiting.add(waiting);
2874
+ void waiting.finally(() => this.waiting.delete(waiting));
2875
+ }
2876
+ /** Resolves once every probe answered so far has its ack or has timed out (a test waits for it). */
2877
+ settled() {
2878
+ return Promise.all([...this.waiting]).then(() => void 0);
2879
+ }
2880
+ /** Stop waiting for acks: the worker is stopping (the probes still out are neither answered nor counted). */
2881
+ close() {
2882
+ this.stopping.abort(new DOMException("the worker is stopping", "AbortError"));
2883
+ }
2884
+ since(sent) {
2885
+ return Math.max(Math.trunc(this.parts.clock.epochMs() - sent), 0);
2886
+ }
2887
+ async awaitAck(id, ack, acked, sent, feedbackMs) {
2888
+ const timer = new AbortController();
2889
+ const signal = AbortSignal.any([timer.signal, this.stopping.signal]);
2890
+ const timedOut = this.parts.clock.sleep(this.parts.timeoutMs ?? PROBE_REPLY_TIMEOUT_MS, signal).then(
2891
+ () => "timeout",
2892
+ () => "stopped"
2893
+ // (the ack came first, or the worker is stopping)
2894
+ );
2895
+ let outcome;
2896
+ try {
2897
+ outcome = await Promise.race([acked.then(() => "acked"), timedOut]);
2898
+ } finally {
2899
+ timer.abort();
2900
+ this.parts.acks.forget(ack);
2901
+ }
2902
+ if (outcome === "stopped") return;
2903
+ if (outcome === "timeout") {
2904
+ this.parts.acks.gaveUp(ack);
2905
+ this.logger.warn("delivery probe", { id, outcome: "unanswered", feedback_ms: feedbackMs });
2906
+ this.parts.stats?.probed(feedbackMs, null);
2907
+ return;
2908
+ }
2909
+ const replyMs = this.since(sent);
2910
+ this.logger.info("delivery probe", { id, outcome: "answered", feedback_ms: feedbackMs, reply_ms: replyMs });
2911
+ this.parts.stats?.probed(feedbackMs, replyMs);
2912
+ }
2913
+ };
2914
+
2915
+ // packages/teams/src/servicebus/consumer.ts
2916
+ import { errorName as errorName4, silentLogger as silentLogger9 } from "@primusclaw/personal-agent";
2539
2917
  var IDLE_MS = 2e4;
2540
2918
  var BACKOFF_MS = 3e3;
2541
2919
  var NO_SESSION_PAUSE_MS = 1e3;
2920
+ var ACCEPT_DEADLINE_MS = 12e4;
2921
+ var RECEIVE_DEADLINE_MS = IDLE_MS + 4e4;
2922
+ var SETTLE_DEADLINE_MS = 6e4;
2923
+ var SESSION_HOLD_MS = 4 * 6e4;
2924
+ var WedgedCall = class extends Error {
2925
+ constructor(call) {
2926
+ super(`${call} did not answer in time`);
2927
+ this.call = call;
2928
+ }
2929
+ call;
2930
+ name = "WedgedCall";
2931
+ };
2542
2932
  function isIdleTimeout(error) {
2543
2933
  const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
2544
2934
  return code === "ServiceTimeout" || code === "SessionCannotBeLocked";
@@ -2598,53 +2988,162 @@ function decode(body) {
2598
2988
  var InboundConsumer = class {
2599
2989
  constructor(parts) {
2600
2990
  this.parts = parts;
2601
- this.logger = parts.logger ?? silentLogger8;
2991
+ this.logger = parts.logger ?? silentLogger9;
2602
2992
  }
2603
2993
  parts;
2604
- stopped = false;
2994
+ stopping = new AbortController();
2605
2995
  logger;
2606
- /** Run the receivers until `stop`. */
2996
+ /** Which connection the receivers are on: a receiver re-opens it only if no other has since it took its session. */
2997
+ generation = 0;
2998
+ /** How many receivers are in a pass on each connection (by generation): a session taken there may be in hand. */
2999
+ holders = /* @__PURE__ */ new Map();
3000
+ /** The close of each connection given up on, run once its last holder lets go. */
3001
+ retiring = /* @__PURE__ */ new Map();
3002
+ /** (a method, not a getter: the stop comes between two reads, which a narrowed property would hide) */
3003
+ isStopped() {
3004
+ return this.stopping.signal.aborted;
3005
+ }
3006
+ /** Run the receivers until `stop`; resolves once each has settled what it took and closed its session. */
2607
3007
  async run() {
2608
3008
  await Promise.all(Array.from({ length: this.parts.receivers }, () => this.loop()));
2609
3009
  }
3010
+ /** Take nothing more: the waits end now, a message being handled is finished, and `run` resolves after the drain. */
2610
3011
  stop() {
2611
- this.stopped = true;
3012
+ if (this.isStopped()) return;
3013
+ this.logger.info("inbound consumer stopping: draining the sessions it holds");
3014
+ this.stopping.abort(new DOMException("the worker is stopping", "AbortError"));
2612
3015
  }
2613
- async loop() {
2614
- while (!this.stopped) {
2615
- let receiver;
2616
- try {
2617
- receiver = await this.parts.client.acceptNextSession(this.parts.queue);
2618
- } catch (error) {
2619
- await this.pause(error);
2620
- continue;
3016
+ /**
3017
+ * `call`, given up as wedged (WedgedCall) when it has not answered within `ms`; with `stoppable`, ended (rejected) by
3018
+ * the stop too. The deadline is this consumer's own timer, so an SDK call that ignores its abort signal still ends.
3019
+ */
3020
+ async within(call, ms, work, stoppable = false) {
3021
+ const timer = new AbortController();
3022
+ const signal = stoppable ? AbortSignal.any([timer.signal, this.stopping.signal]) : timer.signal;
3023
+ const deadline = this.parts.clock.sleep(ms, signal).then(
3024
+ () => {
3025
+ throw new WedgedCall(call);
3026
+ },
3027
+ (error) => {
3028
+ if (stoppable && this.isStopped()) throw error;
3029
+ return new Promise(() => void 0);
2621
3030
  }
3031
+ );
3032
+ work.catch(() => void 0);
3033
+ try {
3034
+ return await Promise.race([work, deadline]);
3035
+ } finally {
3036
+ timer.abort();
3037
+ }
3038
+ }
3039
+ async loop() {
3040
+ while (!this.isStopped()) {
3041
+ const generation = this.generation;
3042
+ this.hold(generation);
3043
+ let failed;
2622
3044
  try {
2623
- await this.drain(receiver);
2624
- } catch (error) {
2625
- await this.pause(error);
3045
+ failed = await this.pass(generation);
2626
3046
  } finally {
2627
- await receiver.close().catch((error) => {
2628
- this.logger.info("closing a session receiver failed", { error: errorName3(error) });
2629
- });
3047
+ this.letGo(generation);
2630
3048
  }
3049
+ if (failed !== void 0 && !this.isStopped()) await this.pause(failed.error, generation, failed.rearmed);
3050
+ }
3051
+ }
3052
+ /** Take a session on the current connection and handle it until it goes quiet; what failed, for the pause after. */
3053
+ async pass(generation) {
3054
+ let receiver;
3055
+ const accepting = this.parts.client.acceptNextSession(this.parts.queue, this.stopping.signal);
3056
+ try {
3057
+ receiver = await this.within("accept", ACCEPT_DEADLINE_MS, accepting, true);
3058
+ } catch (error) {
3059
+ accepting.then((late) => late.close()).catch(() => void 0);
3060
+ return { error, rearmed: false };
3061
+ }
3062
+ let failed;
3063
+ try {
3064
+ await this.drain(receiver);
3065
+ } catch (error) {
3066
+ failed = { error, rearmed: true };
3067
+ if (error instanceof WedgedCall && !this.isStopped()) this.rearm(error.call, generation);
2631
3068
  }
3069
+ await this.within("close", SETTLE_DEADLINE_MS, receiver.close()).catch((error) => {
3070
+ this.logger.info("closing a session receiver failed", { error: errorName4(error) });
3071
+ });
3072
+ return failed;
3073
+ }
3074
+ hold(generation) {
3075
+ this.holders.set(generation, (this.holders.get(generation) ?? 0) + 1);
3076
+ }
3077
+ letGo(generation) {
3078
+ const left = (this.holders.get(generation) ?? 1) - 1;
3079
+ if (left > 0) this.holders.set(generation, left);
3080
+ else {
3081
+ this.holders.delete(generation);
3082
+ this.retire(generation);
3083
+ }
3084
+ }
3085
+ /** Close a connection given up on, once no receiver holds a session taken on it (a wedged close is not waited for). */
3086
+ retire(generation) {
3087
+ const close = this.retiring.get(generation);
3088
+ if (close === void 0 || this.holders.has(generation)) return;
3089
+ this.retiring.delete(generation);
3090
+ void close().catch((error) => {
3091
+ this.logger.info("closing a re-opened inbound connection failed", { error: errorName4(error) });
3092
+ });
2632
3093
  }
2633
- async pause(error) {
3094
+ async pause(error, generation, rearmed = false) {
2634
3095
  if (isIdleTimeout(error)) {
2635
- await this.parts.clock.sleep(NO_SESSION_PAUSE_MS);
3096
+ await this.parts.clock.sleep(NO_SESSION_PAUSE_MS, this.stopping.signal).catch(() => void 0);
2636
3097
  return;
2637
3098
  }
2638
- this.logger.warn("inbound receiver error", { error: errorName3(error) });
2639
- await this.parts.clock.sleep(BACKOFF_MS);
3099
+ if (!(error instanceof WedgedCall)) this.logger.warn("inbound receiver error", { error: errorName4(error) });
3100
+ else if (!rearmed && !this.isStopped()) this.rearm(error.call, generation);
3101
+ await this.parts.clock.sleep(BACKOFF_MS, this.stopping.signal).catch(() => void 0);
3102
+ }
3103
+ /**
3104
+ * A call hung: a new connection is opened, once for all receivers that were on the old one, and the session taken
3105
+ * again. The old connection is closed when its last holder lets go (`retire`), not now: see the head of this file.
3106
+ */
3107
+ rearm(call, generation) {
3108
+ const reopen = this.parts.client.reopen?.bind(this.parts.client);
3109
+ const reopened = generation === this.generation && reopen !== void 0;
3110
+ if (reopened) {
3111
+ this.retiring.set(generation, reopen());
3112
+ this.generation += 1;
3113
+ this.retire(generation);
3114
+ }
3115
+ this.logger.warn("inbound receiver re-armed", { call, reopened });
3116
+ if (reopened || reopen === void 0) this.parts.stats?.rearmed?.();
2640
3117
  }
2641
3118
  async drain(receiver) {
3119
+ const taken = this.parts.clock.monotonicMs();
2642
3120
  for (; ; ) {
2643
- const messages = await receiver.receive(1, IDLE_MS);
2644
- if (messages.length === 0 || this.stopped) return;
2645
- for (const message2 of messages) await this.dispatch(receiver, message2);
3121
+ if (this.parts.clock.monotonicMs() - taken >= SESSION_HOLD_MS) return;
3122
+ let messages;
3123
+ try {
3124
+ messages = await this.within(
3125
+ "receive",
3126
+ RECEIVE_DEADLINE_MS,
3127
+ receiver.receive(1, IDLE_MS, this.stopping.signal),
3128
+ true
3129
+ );
3130
+ } catch (error) {
3131
+ if (this.isStopped()) return;
3132
+ throw error;
3133
+ }
3134
+ if (messages.length === 0) return;
3135
+ for (const message2 of messages) {
3136
+ if (this.isStopped()) await this.release(receiver, message2);
3137
+ else await this.dispatch(receiver, message2);
3138
+ }
3139
+ if (this.isStopped()) return;
2646
3140
  }
2647
3141
  }
3142
+ /** A message taken after the stop goes back to the queue at once, for the next worker. */
3143
+ async release(receiver, message2) {
3144
+ this.logLine(message2, "released", queueLagMs(message2, this.parts.clock.epochMs()), 0);
3145
+ await this.within("abandon", SETTLE_DEADLINE_MS, receiver.abandon(message2));
3146
+ }
2648
3147
  async dispatch(receiver, message2) {
2649
3148
  let body;
2650
3149
  try {
@@ -2652,7 +3151,11 @@ var InboundConsumer = class {
2652
3151
  } catch (error) {
2653
3152
  const why = error instanceof Error ? error.message : "undecodable";
2654
3153
  this.logLine(message2, "dead_lettered", queueLagMs(message2, this.parts.clock.epochMs()), 0);
2655
- await receiver.deadLetter(message2, "malformed", Array.from(why).slice(0, 200).join(""));
3154
+ await this.within(
3155
+ "dead-letter",
3156
+ SETTLE_DEADLINE_MS,
3157
+ receiver.deadLetter(message2, "malformed", Array.from(why).slice(0, 200).join(""))
3158
+ );
2656
3159
  return;
2657
3160
  }
2658
3161
  const timing = clientTiming(body);
@@ -2660,13 +3163,13 @@ var InboundConsumer = class {
2660
3163
  try {
2661
3164
  await this.parts.handle(body);
2662
3165
  } catch (error) {
2663
- this.logger.error("handler failed; abandoning for redelivery", { error: errorName3(error) });
3166
+ this.logger.error("handler failed; abandoning for redelivery", { error: errorName4(error) });
2664
3167
  this.record(message2, timing, started, false);
2665
- await receiver.abandon(message2);
3168
+ await this.within("abandon", SETTLE_DEADLINE_MS, receiver.abandon(message2));
2666
3169
  return;
2667
3170
  }
2668
3171
  this.record(message2, timing, started, true);
2669
- await receiver.complete(message2);
3172
+ await this.within("complete", SETTLE_DEADLINE_MS, receiver.complete(message2));
2670
3173
  }
2671
3174
  record(message2, timing, started, ok5) {
2672
3175
  const handleMs = Math.trunc(this.parts.clock.monotonicMs() - started);
@@ -2688,7 +3191,7 @@ var InboundConsumer = class {
2688
3191
  };
2689
3192
 
2690
3193
  // packages/teams/src/surface.ts
2691
- import { errorName as errorName5, silentLogger as silentLogger12 } from "@primusclaw/personal-agent";
3194
+ import { errorName as errorName6, silentLogger as silentLogger13 } from "@primusclaw/personal-agent";
2692
3195
 
2693
3196
  // packages/teams/src/activity/decorations.ts
2694
3197
  var ROOT_ENTITY_TYPE = "https://schema.org/Message";
@@ -2816,7 +3319,7 @@ function teamsCaps(mode) {
2816
3319
  }
2817
3320
 
2818
3321
  // packages/teams/src/messenger/conversation.ts
2819
- import { err as err4, ok as ok4, silentLogger as silentLogger11 } from "@primusclaw/personal-agent";
3322
+ import { err as err4, ok as ok4, silentLogger as silentLogger12 } from "@primusclaw/personal-agent";
2820
3323
 
2821
3324
  // packages/teams/src/outbound/outbox.ts
2822
3325
  var DeleteUnsupportedError = class extends Error {
@@ -2944,7 +3447,7 @@ function streamedLineBreaks(text4) {
2944
3447
  }
2945
3448
 
2946
3449
  // packages/teams/src/stream/informative.ts
2947
- import { pyLstrip as pyLstrip2, squashSpaces as squashSpaces4 } from "@primusclaw/personal-agent";
3450
+ import { pyLstrip as pyLstrip2, squashSpaces as squashSpaces5 } from "@primusclaw/personal-agent";
2948
3451
  var INFORMATIVE_MAX_CHARS = 1e3;
2949
3452
  var INFORMATIVE_MAX_BYTES = 1024;
2950
3453
  var STATUS_JOIN = " \xB7 ";
@@ -2953,7 +3456,7 @@ function utf8Length(text4) {
2953
3456
  return Buffer.byteLength(text4, "utf8");
2954
3457
  }
2955
3458
  function informativeText(lines) {
2956
- const text4 = lines.map(squashSpaces4).filter((line2) => line2 !== "").join(STATUS_JOIN);
3459
+ const text4 = lines.map(squashSpaces5).filter((line2) => line2 !== "").join(STATUS_JOIN);
2957
3460
  const chars = Array.from(text4);
2958
3461
  if (chars.length <= INFORMATIVE_MAX_CHARS && utf8Length(text4) <= INFORMATIVE_MAX_BYTES) return text4;
2959
3462
  const budgetChars = INFORMATIVE_MAX_CHARS - 1;
@@ -2973,7 +3476,7 @@ function informativeText(lines) {
2973
3476
  }
2974
3477
 
2975
3478
  // packages/teams/src/stream/teams-stream.ts
2976
- import { errorName as errorName4, silentLogger as silentLogger9 } from "@primusclaw/personal-agent";
3479
+ import { errorName as errorName5, silentLogger as silentLogger10 } from "@primusclaw/personal-agent";
2977
3480
 
2978
3481
  // packages/teams/src/activity/stream-activity.ts
2979
3482
  var STREAM_ENTITY_TYPE = "streaminfo";
@@ -2983,8 +3486,8 @@ function streamActivity(kind, text4, replyTo, sequence, streamId = "") {
2983
3486
  return { type: "typing", text: text4, replyToId: replyTo, entities: [info] };
2984
3487
  }
2985
3488
  function streamFinal(activity, replyTo, streamId) {
2986
- const own13 = Array.isArray(activity["entities"]) ? activity["entities"] : [];
2987
- const entities = own13.filter((e) => !(isObject(e) && e["type"] === STREAM_ENTITY_TYPE));
3489
+ const own14 = Array.isArray(activity["entities"]) ? activity["entities"] : [];
3490
+ const entities = own14.filter((e) => !(isObject(e) && e["type"] === STREAM_ENTITY_TYPE));
2988
3491
  const final = { type: STREAM_ENTITY_TYPE, streamType: "final", streamId };
2989
3492
  return { ...activity, type: "message", replyToId: replyTo, entities: [final, ...entities] };
2990
3493
  }
@@ -3008,7 +3511,7 @@ var MIN_INTERVAL_MS = 1e3;
3008
3511
  var TeamsStream = class {
3009
3512
  constructor(parts) {
3010
3513
  this.parts = parts;
3011
- this.logger = parts.logger ?? silentLogger9;
3514
+ this.logger = parts.logger ?? silentLogger10;
3012
3515
  }
3013
3516
  parts;
3014
3517
  streamId = "";
@@ -3062,8 +3565,8 @@ var TeamsStream = class {
3062
3565
  return error;
3063
3566
  }
3064
3567
  this.broken = true;
3065
- this.logger.warn("teams stream request failed; falling back", { error: errorName4(error) });
3066
- return new StreamRefusedError(errorName4(error));
3568
+ this.logger.warn("teams stream request failed; falling back", { error: errorName5(error) });
3569
+ return new StreamRefusedError(errorName5(error));
3067
3570
  }
3068
3571
  /** Open the stream with its first informative update (or, `kind` streaming, its first text). */
3069
3572
  start(text4, kind = "informative") {
@@ -3225,7 +3728,7 @@ function withFeedbackLoop(activity) {
3225
3728
  }
3226
3729
 
3227
3730
  // packages/teams/src/richtext/index.ts
3228
- import { silentLogger as silentLogger10 } from "@primusclaw/personal-agent";
3731
+ import { silentLogger as silentLogger11 } from "@primusclaw/personal-agent";
3229
3732
 
3230
3733
  // packages/teams/src/richtext/blocks.ts
3231
3734
  import { cpLength as cpLength6 } from "@primusclaw/personal-agent";
@@ -3253,7 +3756,7 @@ var RichTextError = class extends Error {
3253
3756
  import { cpLength as cpLength3 } from "@primusclaw/personal-agent";
3254
3757
 
3255
3758
  // packages/teams/src/richtext/escape.ts
3256
- import { isPySpace } from "@primusclaw/personal-agent";
3759
+ import { isPySpace as isPySpace2 } from "@primusclaw/personal-agent";
3257
3760
  var PY_SPACE = "\\t\\n\\v\\f\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
3258
3761
  var S = `[${PY_SPACE}]`;
3259
3762
  var NS = `[^${PY_SPACE}]`;
@@ -3284,7 +3787,7 @@ function cpBefore(text4, i) {
3284
3787
  return text4.charAt(i - 1);
3285
3788
  }
3286
3789
  function isSpace2(ch) {
3287
- return ch !== "" && isPySpace(ch);
3790
+ return ch !== "" && isPySpace2(ch);
3288
3791
  }
3289
3792
  function isAlnum(ch) {
3290
3793
  return ALNUM2.test(ch);
@@ -3300,8 +3803,8 @@ function advanceCp(text4, i, count2) {
3300
3803
  function strip(text4) {
3301
3804
  let start = 0;
3302
3805
  let end = text4.length;
3303
- while (start < end && isPySpace(text4.charAt(start))) start++;
3304
- while (end > start && isPySpace(text4.charAt(end - 1))) end--;
3806
+ while (start < end && isPySpace2(text4.charAt(start))) start++;
3807
+ while (end > start && isPySpace2(text4.charAt(end - 1))) end--;
3305
3808
  return text4.slice(start, end);
3306
3809
  }
3307
3810
  function lstripChars(text4, chars) {
@@ -3447,7 +3950,7 @@ function safeUrl(raw) {
3447
3950
  }
3448
3951
 
3449
3952
  // packages/teams/src/richtext/check.ts
3450
- import { own as own6 } from "@primusclaw/personal-agent";
3953
+ import { own as own7 } from "@primusclaw/personal-agent";
3451
3954
  var TAG = /<(\/?)([A-Za-z0-9]+)((?:[^<>A-Za-z0-9][^<>]*)?)>/gu;
3452
3955
  var SPAN_STYLES = /* @__PURE__ */ new Set([
3453
3956
  `font-size:${String(LEAD_PX)}px`,
@@ -3467,7 +3970,7 @@ var ENTITY_TEXT = {
3467
3970
  "&quot;": '"'
3468
3971
  };
3469
3972
  function unescapeEntities(text4) {
3470
- return text4.replace(ENTITY, (entity) => own6(ENTITY_TEXT, entity) ?? entity);
3973
+ return text4.replace(ENTITY, (entity) => own7(ENTITY_TEXT, entity) ?? entity);
3471
3974
  }
3472
3975
  function checkText(text4) {
3473
3976
  if (text4.includes("<") || text4.includes(">") || text4.replace(ENTITY, "").includes("&")) {
@@ -3510,7 +4013,7 @@ function checkHtml(markup) {
3510
4013
  }
3511
4014
 
3512
4015
  // packages/teams/src/richtext/inline.ts
3513
- import { cpLength as cpLength4, own as own7 } from "@primusclaw/personal-agent";
4016
+ import { cpLength as cpLength4, own as own8 } from "@primusclaw/personal-agent";
3514
4017
 
3515
4018
  // packages/teams/src/richtext/scan.ts
3516
4019
  var BACKTICKS = /`+/g;
@@ -3834,7 +4337,7 @@ var InlineReader = class {
3834
4337
  this.dead.set(key, i + size);
3835
4338
  continue;
3836
4339
  }
3837
- const [tag, kind] = own7(EMPHASIS, key) ?? ["i", "other"];
4340
+ const [tag, kind] = own8(EMPHASIS, key) ?? ["i", "other"];
3838
4341
  const inner = text4.slice(i + size, at);
3839
4342
  this.push({ html: `<${tag}>${this.sub(inner)}</${tag}>`, plain: inner, kind }, at + size);
3840
4343
  return;
@@ -3894,7 +4397,7 @@ function startsBlock(line2) {
3894
4397
  }
3895
4398
 
3896
4399
  // packages/teams/src/richtext/status.ts
3897
- import { cpLength as cpLength5, own as own8 } from "@primusclaw/personal-agent";
4400
+ import { cpLength as cpLength5, own as own9 } from "@primusclaw/personal-agent";
3898
4401
  var MARKER = new RegExp(`^${S}*(\u2705|\u274C|\u23F3|\u26A0\\ufe0f?)`, "u");
3899
4402
  var LABEL_END = new RegExp(
3900
4403
  `\uFF1A|:(?:${S}|$)|[\uFF0C\u3002\uFF1B\uFF01\uFF1F]|[,;](?:${S}|$)|${S}[\u2014\u2013-]+${S}|\u2014+|\\.(?:${S}|$)|[!?](?:${S}|$)`,
@@ -3902,7 +4405,7 @@ var LABEL_END = new RegExp(
3902
4405
  );
3903
4406
  function colorOf(plain2) {
3904
4407
  const m = MARKER.exec(plain2);
3905
- return m?.[1] ? own8(STATUS_COLORS, m[1].charAt(0)) ?? null : null;
4408
+ return m?.[1] ? own9(STATUS_COLORS, m[1].charAt(0)) ?? null : null;
3906
4409
  }
3907
4410
  function paint(color, inner) {
3908
4411
  return `<span style="color:${color}">${inner}</span>`;
@@ -4109,7 +4612,7 @@ function toTeamsHtml(markdown, options = {}) {
4109
4612
  function markdownActivity(markdown) {
4110
4613
  return { type: "message", text: markdown, textFormat: "markdown" };
4111
4614
  }
4112
- function richTextActivity(markdown, options = {}, logger = silentLogger10) {
4615
+ function richTextActivity(markdown, options = {}, logger = silentLogger11) {
4113
4616
  try {
4114
4617
  return { type: "message", text: toTeamsHtml(markdown, options), textFormat: "xml" };
4115
4618
  } catch (err5) {
@@ -4188,7 +4691,7 @@ function reference(ref) {
4188
4691
  var TeamsConversation = class {
4189
4692
  constructor(parts) {
4190
4693
  this.parts = parts;
4191
- this.logger = parts.logger ?? silentLogger11;
4694
+ this.logger = parts.logger ?? silentLogger12;
4192
4695
  }
4193
4696
  parts;
4194
4697
  edited = /* @__PURE__ */ new Set();
@@ -4365,7 +4868,7 @@ var TeamsSurface = class {
4365
4868
  this.parts = parts;
4366
4869
  this.caps = teamsCaps(parts.mode);
4367
4870
  this.busy = new BusyConversations(parts.clock);
4368
- this.logger = parts.logger ?? silentLogger12;
4871
+ this.logger = parts.logger ?? silentLogger13;
4369
4872
  }
4370
4873
  parts;
4371
4874
  caps;
@@ -4411,7 +4914,7 @@ var TeamsSurface = class {
4411
4914
  if (typeof channelId === "string" && channelId) wire["channelId"] = channelId;
4412
4915
  return this.conversation({ id, kind: "personal", tenantId: via.tenantId, wire });
4413
4916
  } catch (error) {
4414
- this.logger.warn("a 1:1 chat could not be opened", { error: errorName5(error) });
4917
+ this.logger.warn("a 1:1 chat could not be opened", { error: errorName6(error) });
4415
4918
  return void 0;
4416
4919
  }
4417
4920
  }
@@ -4422,7 +4925,7 @@ var TeamsSurface = class {
4422
4925
  try {
4423
4926
  return (await outbox.listMembers(serviceUrl, conversation.id)).map(rosterMember);
4424
4927
  } catch (error) {
4425
- this.logger.warn("a group chat's members could not be read", { error: errorName5(error) });
4928
+ this.logger.warn("a group chat's members could not be read", { error: errorName6(error) });
4426
4929
  return void 0;
4427
4930
  }
4428
4931
  }
@@ -4443,7 +4946,7 @@ import {
4443
4946
  } from "@primusclaw/personal-agent";
4444
4947
 
4445
4948
  // packages/teams/src/cards/cjk.ts
4446
- import { cpLength as cpLength7, cpSlice, pyRstrip as pyRstrip4, pyStr as pyStr12, pyStrip as pyStrip12, squashSpaces as squashSpaces5, own as own9 } from "@primusclaw/personal-agent";
4949
+ import { cpLength as cpLength7, cpSlice, pyRstrip as pyRstrip4, pyStr as pyStr13, pyStrip as pyStrip12, squashSpaces as squashSpaces6, own as own10 } from "@primusclaw/personal-agent";
4447
4950
  var CJK = "[\\u3400-\\u9fff\\uf900-\\ufaff\\u3000-\\u303f\\uff00-\\uffef]";
4448
4951
  var HALF_TO_FULL = { ",": "\uFF0C", ":": "\uFF1A", ";": "\uFF1B", "?": "\uFF1F", "!": "\uFF01" };
4449
4952
  var AFTER_CJK = new RegExp(`(?<=${CJK}) ?([,:;?!])(?![A-Za-z0-9_/.]{0,40}://) ?`, "g");
@@ -4452,10 +4955,10 @@ var CODE = /(`[^`]*`|\[[^[\]]*\]\([^()\s]*\)|https?:\/\/\S+)/;
4452
4955
  var HAS_CJK = new RegExp(CJK);
4453
4956
  var BETWEEN_CJK = new RegExp(`(?<=${CJK})(?=${CJK})`, "g");
4454
4957
  function hasCjk(text4) {
4455
- return HAS_CJK.test(pyStr12(text4));
4958
+ return HAS_CJK.test(pyStr13(text4));
4456
4959
  }
4457
4960
  function full(half) {
4458
- return own9(HALF_TO_FULL, half) ?? half;
4961
+ return own10(HALF_TO_FULL, half) ?? half;
4459
4962
  }
4460
4963
  function fullWidthParens(text4) {
4461
4964
  let out = "";
@@ -4477,7 +4980,7 @@ function fullWidthParens(text4) {
4477
4980
  return out + text4.slice(i);
4478
4981
  }
4479
4982
  function zh(text4) {
4480
- const value = pyStr12(text4);
4983
+ const value = pyStr13(text4);
4481
4984
  if (!hasCjk(value)) return value;
4482
4985
  const parts = value.split(CODE);
4483
4986
  for (let i = 0; i < parts.length; i += 2) {
@@ -4489,7 +4992,7 @@ function zh(text4) {
4489
4992
  return parts.join("");
4490
4993
  }
4491
4994
  function clip(text4, limit) {
4492
- const line2 = squashSpaces5(pyStr12(text4));
4995
+ const line2 = squashSpaces6(pyStr13(text4));
4493
4996
  return cpLength7(line2) <= limit ? line2 : pyRstrip4(cpSlice(line2, 0, limit - 1)) + "\u2026";
4494
4997
  }
4495
4998
  function unbroken(name) {
@@ -4497,7 +5000,7 @@ function unbroken(name) {
4497
5000
  }
4498
5001
 
4499
5002
  // packages/teams/src/cards/kit.ts
4500
- import { pyStr as pyStr13, pyStrip as pyStrip13 } from "@primusclaw/personal-agent";
5003
+ import { pyStr as pyStr14, pyStrip as pyStrip13 } from "@primusclaw/personal-agent";
4501
5004
  var CARD_VERSION = "1.5";
4502
5005
  var SCHEMA = "http://adaptivecards.io/schemas/adaptive-card.json";
4503
5006
  var ADAPTIVE_CARD = "application/vnd.microsoft.card.adaptive";
@@ -4635,7 +5138,7 @@ function row(rowId, meaning, words, detail = "") {
4635
5138
  };
4636
5139
  }
4637
5140
  function facts(rows, limit = FACT_VALUE_MAX) {
4638
- const kept = rows.filter(([, value]) => pyStrip13(pyStr13(value)) !== "").map(([name, value]) => ({ title: unbroken(zh(clip(name, FACT_TITLE_MAX))), value: zh(clip(value, limit)) }));
5141
+ const kept = rows.filter(([, value]) => pyStrip13(pyStr14(value)) !== "").map(([name, value]) => ({ title: unbroken(zh(clip(name, FACT_TITLE_MAX))), value: zh(clip(value, limit)) }));
4639
5142
  return kept.length ? [{ type: "FactSet", facts: kept }] : [];
4640
5143
  }
4641
5144
  function fold(foldId, items, label = "\u8BE6\u60C5") {
@@ -4695,7 +5198,7 @@ import {
4695
5198
  boardMeaning,
4696
5199
  itemLabel,
4697
5200
  markdownPlain,
4698
- own as own10,
5201
+ own as own11,
4699
5202
  cardLang,
4700
5203
  workCardText
4701
5204
  } from "@primusclaw/personal-agent";
@@ -4788,7 +5291,7 @@ function boardSection(column, kind, model, lang) {
4788
5291
  const rows = column.slice(0, BOARD_LINES).map((item3) => itemRow(item3, model.now, lang));
4789
5292
  return [
4790
5293
  { ...section(icon(emoji, `${t.column({ state })} \xB7 ${String(column.length)}`), tone), id: `band-${emoji}` },
4791
- ...foldRest(`more-${state}`, rows, own10(BOARD_SHOWN, state) ?? 0, column.length, t)
5294
+ ...foldRest(`more-${state}`, rows, own11(BOARD_SHOWN, state) ?? 0, column.length, t)
4792
5295
  ];
4793
5296
  }
4794
5297
  function askedSection(asked, lang) {
@@ -5274,7 +5777,7 @@ import {
5274
5777
  maskedTarget,
5275
5778
  openUrl as clawUrl,
5276
5779
  proactiveText as proactiveText2,
5277
- pyStr as pyStr14
5780
+ pyStr as pyStr15
5278
5781
  } from "@primusclaw/personal-agent";
5279
5782
  var en = proactiveText2.in("en");
5280
5783
  var RUN_ENDS = ["run.completed", "run.failed"];
@@ -5282,8 +5785,8 @@ function showButton2(sessionId, title = en.showHere) {
5282
5785
  return execute(title, "primusclaw.show", { primusclaw: "show", session_id: sessionId });
5283
5786
  }
5284
5787
  function showAction2(event, title = en.showHere) {
5285
- const sessionId = pyStr14(event["session_id"]);
5286
- if (!RUN_ENDS.includes(pyStr14(event["type"])) || !sessionId) return [];
5788
+ const sessionId = pyStr15(event["session_id"]);
5789
+ if (!RUN_ENDS.includes(pyStr15(event["type"])) || !sessionId) return [];
5287
5790
  return [showButton2(sessionId, title)];
5288
5791
  }
5289
5792
  function openAction(event, publicBaseUrl, title = en.openInClaw) {
@@ -5299,14 +5802,14 @@ var LOOK = {
5299
5802
  };
5300
5803
  function runEvent(model) {
5301
5804
  const { event } = model;
5302
- const kind = pyStr14(event["type"]);
5805
+ const kind = pyStr15(event["type"]);
5303
5806
  const plain2 = ["", "default", "notice"];
5304
5807
  const [status, tone, meaning] = Object.hasOwn(LOOK, kind) ? LOOK[kind] ?? plain2 : plain2;
5305
- const title = pyStr14(event["title"]);
5808
+ const title = pyStr15(event["title"]);
5306
5809
  const said = clip(title || status || en.notice, TITLE_MAX);
5307
5810
  const subtitle = title && status && !said.toLowerCase().includes(status.toLowerCase()) ? status : "";
5308
5811
  const body = [header(said, { tone, subtitle, emoji: meaning })];
5309
- const summary = clip(pyStr14(event["summary"]), NOTICE_SUMMARY_MAX);
5812
+ const summary = clip(pyStr15(event["summary"]), NOTICE_SUMMARY_MAX);
5310
5813
  if (summary) body.push(text2(summary, { maxLines: 3 }));
5311
5814
  return message(body, buttons([...showAction2(event), ...openAction(event, model.publicBaseUrl)]));
5312
5815
  }
@@ -5329,7 +5832,7 @@ function digest(model) {
5329
5832
  emoji: "notice"
5330
5833
  })
5331
5834
  ];
5332
- const named = (e) => pyStr14(e["title"]) || pyStr14(e["type"]);
5835
+ const named = (e) => pyStr15(e["title"]) || pyStr15(e["type"]);
5333
5836
  for (const e of [...failed, ...completed]) {
5334
5837
  if (body.length >= 6) break;
5335
5838
  const url = clawUrl(e["link"], model.publicBaseUrl);
@@ -5346,7 +5849,7 @@ function targetText(target) {
5346
5849
  function proactiveApproval(model) {
5347
5850
  const { event } = model;
5348
5851
  const approval = objectOf(event["approval"]);
5349
- const tool = clip(pyStr14(approval["tool"]) || en.anAction, TITLE_MAX);
5852
+ const tool = clip(pyStr15(approval["tool"]) || en.anAction, TITLE_MAX);
5350
5853
  const until = clockText2(model.expiresAt, model.zone);
5351
5854
  const body = [
5352
5855
  header(en.approvalNeeded({ tool }), {
@@ -5355,10 +5858,10 @@ function proactiveApproval(model) {
5355
5858
  emoji: "needs_you"
5356
5859
  })
5357
5860
  ];
5358
- const target = pyStr14(approval["target"]);
5861
+ const target = pyStr15(approval["target"]);
5359
5862
  if (target) body.push(targetText(clip(target, TARGET_MAX)));
5360
5863
  const actions = [
5361
- ...decisionButtons(tool, pyStr14(event["session_id"]), pyStr14(approval["tool_use_id"]), "en"),
5864
+ ...decisionButtons(tool, pyStr15(event["session_id"]), pyStr15(approval["tool_use_id"]), "en"),
5362
5865
  ...openAction(event, model.publicBaseUrl, en.details)
5363
5866
  ];
5364
5867
  return message(body, actions);
@@ -5366,16 +5869,16 @@ function proactiveApproval(model) {
5366
5869
  function itemApproval(model) {
5367
5870
  const { event } = model;
5368
5871
  const approval = objectOf(event["approval"]);
5369
- const tool = pyStr14(approval["tool"]);
5872
+ const tool = pyStr15(approval["tool"]);
5370
5873
  const lang = itemLang(event);
5371
5874
  const t = proactiveText2.in(lang);
5372
5875
  const view = approvalView2({ tool, toolInput: null, event: { summary: event["summary"] }, lang, group: false });
5373
5876
  const body = approvalBody(view);
5374
5877
  body.splice(1, 0, text2(itemRequestLabel(event, "task", lang), { subtle: true, size: "Small" }));
5375
- if (pyStr14(approval["target"])) body.push(targetText(maskedTarget(approval["target"])));
5878
+ if (pyStr15(approval["target"])) body.push(targetText(maskedTarget(approval["target"])));
5376
5879
  body.push(note(t.until({ until: clockText2(model.expiresAt, model.zone), zone: model.zone })));
5377
5880
  const actions = [
5378
- ...decisionButtons(tool || en.anAction, pyStr14(event["session_id"]), pyStr14(approval["tool_use_id"]), lang),
5881
+ ...decisionButtons(tool || en.anAction, pyStr15(event["session_id"]), pyStr15(approval["tool_use_id"]), lang),
5379
5882
  ...openAction(event, model.publicBaseUrl, t.details)
5380
5883
  ];
5381
5884
  return message(body, actions);
@@ -5384,8 +5887,8 @@ function itemQuestion(model) {
5384
5887
  const { event } = model;
5385
5888
  return approvalRenderers.question({
5386
5889
  questions: cardQuestions(event["questions"]),
5387
- sessionId: pyStr14(event["session_id"]),
5388
- toolUseId: pyStr14(objectOf(event["approval"])["tool_use_id"]),
5890
+ sessionId: pyStr15(event["session_id"]),
5891
+ toolUseId: pyStr15(objectOf(event["approval"])["tool_use_id"]),
5389
5892
  group: false,
5390
5893
  ownerName: "",
5391
5894
  note: itemRequestLabel(event, "asks", itemLang(event))
@@ -5844,7 +6347,7 @@ import {
5844
6347
  REVIEW_MODES,
5845
6348
  githubConfirmButtons
5846
6349
  } from "@primusclaw/personal-agent";
5847
- import { own as own11 } from "@primusclaw/personal-agent";
6350
+ import { own as own12 } from "@primusclaw/personal-agent";
5848
6351
  var MARKDOWN = /([\\`*_[\]<])/gu;
5849
6352
  function plain(value) {
5850
6353
  return value.replace(MARKDOWN, "\\$1");
@@ -5872,8 +6375,8 @@ function reviewModeCard(model) {
5872
6375
  if (model.lead) body.push(text2(model.lead));
5873
6376
  const english = [];
5874
6377
  for (const mode of order) {
5875
- const [zh2, en2] = own11(REVIEW_MODES, mode) ?? ["", ""];
5876
- const [whatZh = "", whatEn = ""] = own11(MODE_WHAT, mode) ?? [];
6378
+ const [zh2, en2] = own12(REVIEW_MODES, mode) ?? ["", ""];
6379
+ const [whatZh = "", whatEn = ""] = own12(MODE_WHAT, mode) ?? [];
5877
6380
  const current = mode === model.current;
5878
6381
  body.push({
5879
6382
  type: "Container",
@@ -5899,7 +6402,7 @@ function reviewModeCard(model) {
5899
6402
  body.push(...fold("review-mode-en", english, "English"));
5900
6403
  if (model.hint) body.push(note(model.hint.split(" / ")[0] ?? ""));
5901
6404
  const choices = order.map(
5902
- (m) => execute(own11(MODE_BUTTON, m) ?? m, "primusclaw.github_mode", { primusclaw: "github_mode", mode: m })
6405
+ (m) => execute(own12(MODE_BUTTON, m) ?? m, "primusclaw.github_mode", { primusclaw: "github_mode", mode: m })
5903
6406
  );
5904
6407
  return message(body, buttons([...choices, ...model.hint ? addAppButton(model.installUrl, model.bot) : []]));
5905
6408
  }
@@ -6313,16 +6816,16 @@ var RENDERERS = {
6313
6816
  };
6314
6817
 
6315
6818
  // packages/teams/src/assembly/inbound.ts
6316
- import { silentLogger as silentLogger13 } from "@primusclaw/personal-agent";
6819
+ import { silentLogger as silentLogger14 } from "@primusclaw/personal-agent";
6317
6820
 
6318
6821
  // packages/teams/src/activity/inbound/group-changes.ts
6319
- import { pyStr as pyStr15 } from "@primusclaw/personal-agent";
6822
+ import { pyStr as pyStr16 } from "@primusclaw/personal-agent";
6320
6823
  function eventTypeOf(activity) {
6321
6824
  const data = activity.channelData;
6322
- return isFields(data) ? pyStr15(data["eventType"]) : "";
6825
+ return isFields(data) ? pyStr16(data["eventType"]) : "";
6323
6826
  }
6324
6827
  function botRemoved(activity) {
6325
- if (activity.type === "installationUpdate") return pyStr15(activity["action"]).startsWith("remove");
6828
+ if (activity.type === "installationUpdate") return pyStr16(activity["action"]).startsWith("remove");
6326
6829
  if (activity.type !== "conversationUpdate") return false;
6327
6830
  const bot = botIdOf(activity);
6328
6831
  const removed = activity["membersRemoved"];
@@ -6332,8 +6835,8 @@ function applyGroupChange(raw, context, textOf) {
6332
6835
  const parsed = parseActivity(raw);
6333
6836
  if (!parsed.ok || !isGroup(parsed.value)) return false;
6334
6837
  const activity = parsed.value;
6335
- const chatId = pyStr15(partOf(activity, "conversation")["id"]);
6336
- const messageId = pyStr15(activity.id);
6838
+ const chatId = pyStr16(partOf(activity, "conversation")["id"]);
6839
+ const messageId = pyStr16(activity.id);
6337
6840
  if (!chatId) return false;
6338
6841
  if (botRemoved(activity)) {
6339
6842
  context.forget(chatId);
@@ -6358,13 +6861,17 @@ function text3(value) {
6358
6861
  return typeof value === "number" && value !== 0 ? String(value) : "";
6359
6862
  }
6360
6863
  function inboundHandler(parts) {
6361
- const logger = parts.logger ?? silentLogger13;
6864
+ const logger = parts.logger ?? silentLogger14;
6362
6865
  return async (body) => {
6363
6866
  if (body["type"] === DELIVERED) {
6364
6867
  const activityId = text3(body["activity_id"]);
6365
6868
  parts.acks.resolve(text3(body["ack"]), activityId || void 0);
6366
6869
  return;
6367
6870
  }
6871
+ if (DeliveryProbe.is(body)) {
6872
+ await parts.probe?.answer(body);
6873
+ return;
6874
+ }
6368
6875
  if (body["type"] !== "message" && body["type"] !== "invoke") {
6369
6876
  if (parts.groupContext !== void 0) applyGroupChange(body, parts.groupContext, (a) => editedText(a, parts));
6370
6877
  return;
@@ -6384,11 +6891,11 @@ function editedText(activity, parts) {
6384
6891
 
6385
6892
  // packages/teams/src/assembly/outbound.ts
6386
6893
  import { readFileSync as readFileSync2 } from "node:fs";
6387
- import { silentLogger as silentLogger19 } from "@primusclaw/personal-agent";
6894
+ import { silentLogger as silentLogger20, turn as turn3 } from "@primusclaw/personal-agent";
6388
6895
  import { StartupError } from "@primusclaw/personal-agent-runtime/worker";
6389
6896
 
6390
6897
  // packages/teams/src/connector/outbox.ts
6391
- import { pyStr as pyStr18, silentLogger as silentLogger14 } from "@primusclaw/personal-agent";
6898
+ import { pyStr as pyStr19, silentLogger as silentLogger15 } from "@primusclaw/personal-agent";
6392
6899
 
6393
6900
  // packages/teams/src/connector/limits.ts
6394
6901
  var DEFAULT_LIMITS = {
@@ -6405,7 +6912,7 @@ var DEFAULT_LIMITS = {
6405
6912
  };
6406
6913
 
6407
6914
  // packages/teams/src/connector/request.ts
6408
- import { pyStr as pyStr16, pyStrip as pyStrip15 } from "@primusclaw/personal-agent";
6915
+ import { pyStr as pyStr17, pyStrip as pyStrip15 } from "@primusclaw/personal-agent";
6409
6916
  var CONVERSATION_SAFE = ":@;=";
6410
6917
  function quote(text4, safe) {
6411
6918
  try {
@@ -6418,17 +6925,17 @@ function conversationUrl(serviceUrl, conversationId2) {
6418
6925
  return `${rstripSlash(serviceUrl)}/v3/conversations/${quote(conversationId2, CONVERSATION_SAFE)}`;
6419
6926
  }
6420
6927
  function idText(value) {
6421
- return quote(pyStr16(value), "");
6928
+ return quote(pyStr17(value), "");
6422
6929
  }
6423
6930
  function address(envelope2, policy) {
6424
6931
  const { reference: reference2, activity } = envelope2;
6425
6932
  if (!isObject(reference2) || !isObject(activity)) {
6426
6933
  throw new UnaddressableError("an outbound envelope needs a reference and an activity");
6427
6934
  }
6428
- const serviceUrl = pyStrip15(pyStr16(reference2["serviceUrl"]));
6935
+ const serviceUrl = pyStrip15(pyStr17(reference2["serviceUrl"]));
6429
6936
  const raw = reference2["conversation"];
6430
6937
  const conversation = pyTruthy(raw) && raw !== void 0 ? raw : {};
6431
- const conversationId2 = isObject(conversation) ? pyStr16(conversation["id"]) : "";
6938
+ const conversationId2 = isObject(conversation) ? pyStr17(conversation["id"]) : "";
6432
6939
  if (!serviceUrl || !conversationId2 || !isObject(conversation)) {
6433
6940
  throw new UnaddressableError("the conversation reference has no serviceUrl or conversation id");
6434
6941
  }
@@ -6448,7 +6955,7 @@ function payloadOf(at, operation, activityId) {
6448
6955
  return payload;
6449
6956
  }
6450
6957
  function buildRequest(envelope2, policy = DEFAULT_CONNECTOR_HOSTS) {
6451
- const operation = (pyStr16(envelope2["operation"]) || "send").toLowerCase();
6958
+ const operation = (pyStr17(envelope2["operation"]) || "send").toLowerCase();
6452
6959
  const at = address(envelope2, policy);
6453
6960
  const activityId = envelope2["activity_id"];
6454
6961
  switch (operation) {
@@ -6490,7 +6997,7 @@ function buildListMembers(serviceUrl, conversationId2, policy = DEFAULT_CONNECTO
6490
6997
 
6491
6998
  // packages/teams/src/connector/response.ts
6492
6999
  import { z as z7 } from "zod";
6493
- import { cpHead as cpHead6, pyStr as pyStr17 } from "@primusclaw/personal-agent";
7000
+ import { cpHead as cpHead6, pyStr as pyStr18 } from "@primusclaw/personal-agent";
6494
7001
  function json2(text4) {
6495
7002
  try {
6496
7003
  return JSON.parse(text4);
@@ -6502,11 +7009,11 @@ var WithId = z7.object({ id: z7.unknown().optional() });
6502
7009
  var WithError = z7.object({ error: z7.object({ code: z7.unknown().optional() }) });
6503
7010
  function answerId(text4) {
6504
7011
  const parsed = WithId.safeParse(json2(text4));
6505
- return parsed.success ? pyStr17(parsed.data.id) || void 0 : void 0;
7012
+ return parsed.success ? pyStr18(parsed.data.id) || void 0 : void 0;
6506
7013
  }
6507
7014
  function errorCode(text4) {
6508
7015
  const parsed = WithError.safeParse(json2(text4));
6509
- return parsed.success ? cpHead6(pyStr17(parsed.data.error.code), 60) : "";
7016
+ return parsed.success ? cpHead6(pyStr18(parsed.data.error.code), 60) : "";
6510
7017
  }
6511
7018
  function retryAfterMs(header2) {
6512
7019
  const seconds = pyFloat(header2 ?? "");
@@ -6519,10 +7026,10 @@ function memberList(text4) {
6519
7026
  }
6520
7027
 
6521
7028
  // packages/teams/src/connector/retry.ts
6522
- import { errorName as errorName6 } from "@primusclaw/personal-agent";
7029
+ import { errorName as errorName7 } from "@primusclaw/personal-agent";
6523
7030
  function networkReason(error) {
6524
7031
  const cause = error instanceof Error && error.cause instanceof Error ? error.cause : error;
6525
- return `network: ${errorName6(cause)}`;
7032
+ return `network: ${errorName7(cause)}`;
6526
7033
  }
6527
7034
  var ConnectorClient = class {
6528
7035
  constructor(deps) {
@@ -6620,9 +7127,9 @@ function describe(envelope2) {
6620
7127
  const reference2 = isObject(envelope2["reference"]) ? envelope2["reference"] : {};
6621
7128
  const conversation = isObject(reference2["conversation"]) ? reference2["conversation"] : {};
6622
7129
  return {
6623
- operation: pyStr18(envelope2["operation"]) || "send",
6624
- kind: pyStr18(activity["type"]) || "message",
6625
- key: pyStr18(conversation["id"]),
7130
+ operation: pyStr19(envelope2["operation"]) || "send",
7131
+ kind: pyStr19(activity["type"]) || "message",
7132
+ key: pyStr19(conversation["id"]),
6626
7133
  ...outboundLogFields(envelope2)
6627
7134
  };
6628
7135
  }
@@ -6634,7 +7141,7 @@ var ConnectorOutbox = class {
6634
7141
  this.options = options;
6635
7142
  this.fallback = options.fallback;
6636
7143
  this.clock = options.clock;
6637
- this.logger = options.logger ?? silentLogger14;
7144
+ this.logger = options.logger ?? silentLogger15;
6638
7145
  this.policy = options.policy ?? DEFAULT_CONNECTOR_HOSTS;
6639
7146
  this.plain = options.plain ?? plainDecorations;
6640
7147
  this.limits = { ...DEFAULT_LIMITS, ...options.limits };
@@ -6942,7 +7449,7 @@ function buildRequestLazily(envelope2, policy) {
6942
7449
  }
6943
7450
 
6944
7451
  // packages/teams/src/connector/tokens/client-secret.ts
6945
- import { silentLogger as silentLogger15 } from "@primusclaw/personal-agent";
7452
+ import { silentLogger as silentLogger16 } from "@primusclaw/personal-agent";
6946
7453
  var ClientSecretTokenProvider = class extends CachedTokenProvider {
6947
7454
  source = "secret";
6948
7455
  scope;
@@ -6967,7 +7474,7 @@ var ClientSecretTokenProvider = class extends CachedTokenProvider {
6967
7474
  this.tenantId = options.tenantId;
6968
7475
  this.#secret = options.clientSecret;
6969
7476
  this.fetch = options.fetch ?? globalThis.fetch;
6970
- this.logger = options.logger ?? silentLogger15;
7477
+ this.logger = options.logger ?? silentLogger16;
6971
7478
  this.url = options.url || `${ENTRA_TOKEN_HOST}/${pyQuote(options.tenantId, "")}/oauth2/v2.0/token`;
6972
7479
  this.scope = options.scope ?? BOT_CONNECTOR_SCOPE;
6973
7480
  }
@@ -7006,7 +7513,7 @@ var ClientSecretTokenProvider = class extends CachedTokenProvider {
7006
7513
  };
7007
7514
 
7008
7515
  // packages/teams/src/connector/tokens/imds.ts
7009
- import { silentLogger as silentLogger16 } from "@primusclaw/personal-agent";
7516
+ import { silentLogger as silentLogger17 } from "@primusclaw/personal-agent";
7010
7517
  var BOT_CONNECTOR_RESOURCE = "https://api.botframework.com";
7011
7518
  var IMDS_TOKEN_URL = "http://169.254.169.254/metadata/identity/oauth2/token";
7012
7519
  var IMDS_API_VERSION = "2018-02-01";
@@ -7017,7 +7524,7 @@ var ImdsTokenProvider = class extends CachedTokenProvider {
7017
7524
  this.clientId = clientId;
7018
7525
  if (!clientId) throw new Error("the managed identity's client id is required");
7019
7526
  this.fetch = options.fetch ?? globalThis.fetch;
7020
- this.logger = options.logger ?? silentLogger16;
7527
+ this.logger = options.logger ?? silentLogger17;
7021
7528
  this.url = options.url ?? IMDS_TOKEN_URL;
7022
7529
  }
7023
7530
  clientId;
@@ -7051,9 +7558,9 @@ var ImdsTokenProvider = class extends CachedTokenProvider {
7051
7558
  };
7052
7559
 
7053
7560
  // packages/teams/src/gate/no-queue.ts
7054
- import { silentLogger as silentLogger17 } from "@primusclaw/personal-agent";
7561
+ import { silentLogger as silentLogger18 } from "@primusclaw/personal-agent";
7055
7562
  var NoQueue = class {
7056
- constructor(logger = silentLogger17) {
7563
+ constructor(logger = silentLogger18) {
7057
7564
  this.logger = logger;
7058
7565
  }
7059
7566
  logger;
@@ -7097,7 +7604,8 @@ function rawBody(message2) {
7097
7604
  return Buffer.from(typeof body === "string" ? body : JSON.stringify(body ?? null));
7098
7605
  }
7099
7606
  function azureBusClient(connection, lockRenewalMs) {
7100
- const client = typeof connection === "string" ? new ServiceBusClient(connection) : new ServiceBusClient(connection.namespace, connection.credential);
7607
+ const open = () => typeof connection === "string" ? new ServiceBusClient(connection) : new ServiceBusClient(connection.namespace, connection.credential);
7608
+ let client = open();
7101
7609
  return {
7102
7610
  sender(queue) {
7103
7611
  const sender = client.createSender(queue);
@@ -7106,10 +7614,11 @@ function azureBusClient(connection, lockRenewalMs) {
7106
7614
  close: () => sender.close()
7107
7615
  };
7108
7616
  },
7109
- async acceptNextSession(queue) {
7617
+ async acceptNextSession(queue, signal) {
7110
7618
  const receiver = await client.acceptNextSession(queue, {
7111
7619
  maxAutoLockRenewalDurationInMs: lockRenewalMs,
7112
- skipParsingBodyAsJson: true
7620
+ skipParsingBodyAsJson: true,
7621
+ ...signal ? { abortSignal: signal } : {}
7113
7622
  });
7114
7623
  const held = /* @__PURE__ */ new Map();
7115
7624
  const sdk = (message2) => {
@@ -7119,8 +7628,11 @@ function azureBusClient(connection, lockRenewalMs) {
7119
7628
  return found;
7120
7629
  };
7121
7630
  return {
7122
- async receive(count2, waitMs) {
7123
- const messages = await receiver.receiveMessages(count2, { maxWaitTimeInMs: waitMs });
7631
+ async receive(count2, waitMs, signal2) {
7632
+ const messages = await receiver.receiveMessages(count2, {
7633
+ maxWaitTimeInMs: waitMs,
7634
+ ...signal2 ? { abortSignal: signal2 } : {}
7635
+ });
7124
7636
  return messages.map((m) => {
7125
7637
  const received = {
7126
7638
  body: rawBody(m),
@@ -7141,12 +7653,17 @@ function azureBusClient(connection, lockRenewalMs) {
7141
7653
  close: () => receiver.close()
7142
7654
  };
7143
7655
  },
7656
+ reopen() {
7657
+ const old = client;
7658
+ client = open();
7659
+ return () => old.close();
7660
+ },
7144
7661
  close: () => client.close()
7145
7662
  };
7146
7663
  }
7147
7664
 
7148
7665
  // packages/teams/src/servicebus/outbox.ts
7149
- import { errorName as errorName7, pyJsonDumps, silentLogger as silentLogger18 } from "@primusclaw/personal-agent";
7666
+ import { errorName as errorName8, pyJsonDumps, silentLogger as silentLogger19 } from "@primusclaw/personal-agent";
7150
7667
  var IDLE_REOPEN_MS = 24e4;
7151
7668
  var ServiceBusOutbox = class {
7152
7669
  constructor(client, queue, clock, logger) {
@@ -7155,7 +7672,7 @@ var ServiceBusOutbox = class {
7155
7672
  this.clock = clock;
7156
7673
  this.sender = client.sender(queue);
7157
7674
  this.usedAt = clock.monotonicMs();
7158
- this.logger = logger ?? silentLogger18;
7675
+ this.logger = logger ?? silentLogger19;
7159
7676
  }
7160
7677
  client;
7161
7678
  queue;
@@ -7188,7 +7705,7 @@ var ServiceBusOutbox = class {
7188
7705
  try {
7189
7706
  await stale.close();
7190
7707
  } catch (error) {
7191
- this.logger.info("closing the idle outbound sender failed", { error: errorName7(error) });
7708
+ this.logger.info("closing the idle outbound sender failed", { error: errorName8(error) });
7192
7709
  }
7193
7710
  }
7194
7711
  async close() {
@@ -7198,10 +7715,11 @@ var ServiceBusOutbox = class {
7198
7715
  };
7199
7716
 
7200
7717
  // packages/teams/src/assembly/outbound.ts
7201
- var LOCK_RENEWAL_MS = 5 * 6e4;
7718
+ var HANDLER_MARGIN_MS = 10 * 6e4;
7719
+ var LOCK_RENEWAL_MS = SESSION_HOLD_MS + RECEIVE_DEADLINE_MS + turn3.TURN_DEADLINE_SECONDS * 1e3 + HANDLER_MARGIN_MS + SETTLE_DEADLINE_MS;
7202
7720
  function botTokenSource(settings, deps) {
7203
7721
  const { bot } = settings;
7204
- const logger = deps.logger ?? silentLogger19;
7722
+ const logger = deps.logger ?? silentLogger20;
7205
7723
  const base2 = { clock: deps.clock, logger, ...deps.fetch ? { fetch: deps.fetch } : {} };
7206
7724
  if (bot.clientSecretIgnored) {
7207
7725
  logger.warn("BOT_CLIENT_SECRET is set but not used: BOT_TOKEN_SOURCE names another source", {
@@ -7265,7 +7783,7 @@ function busConnections(settings, credential) {
7265
7783
  function gateOutbound(gate, deps) {
7266
7784
  const tokens = new GateToken(gate.runId);
7267
7785
  const policy = onlyConnector(gate.connectorUrl);
7268
- (deps.logger ?? silentLogger19).warn("release gate test entry: outbound to the recording connector only; no queue", {
7786
+ (deps.logger ?? silentLogger20).warn("release gate test entry: outbound to the recording connector only; no queue", {
7269
7787
  runId: gate.runId
7270
7788
  });
7271
7789
  const outbox = new ConnectorOutbox({
@@ -7281,9 +7799,9 @@ function gateOutbound(gate, deps) {
7281
7799
  function productionOutbound(settings, outbound, deps) {
7282
7800
  const queue = new ServiceBusOutbox(outbound, settings.bus.outboundQueue, deps.clock, deps.logger);
7283
7801
  if (settings.outboundMode !== "direct") {
7284
- return { outbox: queue, tokens: void 0, policy: DEFAULT_CONNECTOR_HOSTS, close: () => queue.close() };
7802
+ return { outbox: queue, queue, tokens: void 0, policy: DEFAULT_CONNECTOR_HOSTS, close: () => queue.close() };
7285
7803
  }
7286
- (deps.logger ?? silentLogger19).info("outbound mode: direct to the Bot Connector (the queue is the fallback)");
7804
+ (deps.logger ?? silentLogger20).info("outbound mode: direct to the Bot Connector (the queue is the fallback)");
7287
7805
  const tokens = botTokenSource(settings, deps);
7288
7806
  const outbox = new ConnectorOutbox({
7289
7807
  tokens,
@@ -7294,6 +7812,7 @@ function productionOutbound(settings, outbound, deps) {
7294
7812
  });
7295
7813
  return {
7296
7814
  outbox,
7815
+ queue,
7297
7816
  tokens,
7298
7817
  policy: DEFAULT_CONNECTOR_HOSTS,
7299
7818
  close: async () => {
@@ -7313,15 +7832,15 @@ import { EnvSecretSource, secretsSourceOf, wantedSecrets } from "@primusclaw/per
7313
7832
  import { z as z8 } from "zod";
7314
7833
  import {
7315
7834
  cpSlice as cpSlice2,
7316
- errorName as errorName8,
7317
- pyStr as pyStr19,
7835
+ errorName as errorName9,
7836
+ pyStr as pyStr20,
7318
7837
  pyStrip as pyStrip17,
7319
7838
  SecretsUnavailable as SecretsUnavailable2,
7320
- silentLogger as silentLogger20
7839
+ silentLogger as silentLogger21
7321
7840
  } from "@primusclaw/personal-agent";
7322
7841
 
7323
7842
  // packages/teams/src/azure/keyvault-config.ts
7324
- import { pyRstrip as pyRstrip6, SecretsUnavailable, pyStrip as pyStrip16, own as own12 } from "@primusclaw/personal-agent";
7843
+ import { pyRstrip as pyRstrip6, SecretsUnavailable, pyStrip as pyStrip16, own as own13 } from "@primusclaw/personal-agent";
7325
7844
  import { SETTING_ALIASES, settingValue } from "@primusclaw/personal-agent-runtime";
7326
7845
  var KEYVAULT_SCOPE = "https://vault.azure.net/.default";
7327
7846
  var KEYVAULT_API_VERSION = "7.4";
@@ -7341,7 +7860,7 @@ var ENV_NAMES = {
7341
7860
  FEEDBACK_GITHUB_APP_KEY: "FEEDBACK_GITHUB_KEY_FILE"
7342
7861
  };
7343
7862
  function get2(env, name) {
7344
- return pyStrip16(own12(env, name) ?? "");
7863
+ return pyStrip16(own13(env, name) ?? "");
7345
7864
  }
7346
7865
  function shadowedSettings(env, names) {
7347
7866
  return names.flatMap((name) => {
@@ -7401,7 +7920,7 @@ function vaultErrorCode(text4) {
7401
7920
  const error = body === void 0 ? void 0 : dictOf(body["error"]);
7402
7921
  const inner = error === void 0 ? void 0 : dictOf(error["innererror"]);
7403
7922
  if (error === void 0 || inner === void 0) return "";
7404
- const codes = [error["code"], inner["code"]].map((code) => cpSlice2(pyStr19(code), 0, 60)).filter(Boolean);
7923
+ const codes = [error["code"], inner["code"]].map((code) => cpSlice2(pyStr20(code), 0, 60)).filter(Boolean);
7405
7924
  return codes.length ? ` (${codes.join(": ")})` : "";
7406
7925
  }
7407
7926
  function secretValue(name, text4) {
@@ -7423,7 +7942,7 @@ var KeyVaultSecretSource = class {
7423
7942
  this.credential = credential;
7424
7943
  this.options = options;
7425
7944
  this.fetch = options.fetch ?? globalThis.fetch;
7426
- this.logger = options.logger ?? silentLogger20;
7945
+ this.logger = options.logger ?? silentLogger21;
7427
7946
  this.sleep = options.sleep ?? ((ms, signal) => options.clock.sleep(ms, signal));
7428
7947
  }
7429
7948
  url;
@@ -7531,7 +8050,7 @@ var KeyVaultSecretSource = class {
7531
8050
  status = response.status;
7532
8051
  text4 = await response.text();
7533
8052
  } catch (error) {
7534
- return { reason: `Key Vault unreachable (${errorName8(error)})`, transient: true, missing: false };
8053
+ return { reason: `Key Vault unreachable (${errorName9(error)})`, transient: true, missing: false };
7535
8054
  } finally {
7536
8055
  timer.dispose();
7537
8056
  }
@@ -7659,13 +8178,14 @@ function surfaceOf(teams, outbound, gate, deps) {
7659
8178
  return { acks, surface };
7660
8179
  }
7661
8180
  function connect(teams, parts, context) {
7662
- const { botName, acks, inbound: inbound2, gate } = parts;
8181
+ const { botName, acks, inbound: inbound2, gate, probe } = parts;
7663
8182
  const handle = inboundHandler({
7664
8183
  acks,
7665
8184
  route: context.route,
7666
8185
  botName,
7667
8186
  logger: context.logger,
7668
- groupContext: context.groupContext
8187
+ groupContext: context.groupContext,
8188
+ probe
7669
8189
  });
7670
8190
  const source = inbound2 === void 0 ? void 0 : new InboundConsumer({
7671
8191
  client: inbound2,
@@ -7677,6 +8197,9 @@ function connect(teams, parts, context) {
7677
8197
  stats: {
7678
8198
  processed: (lag, ms, ok5) => {
7679
8199
  context.metrics.processed(lag ?? null, ms, ok5);
8200
+ },
8201
+ rearmed: () => {
8202
+ context.metrics.inboundRearmed?.();
7680
8203
  }
7681
8204
  }
7682
8205
  });
@@ -7696,11 +8219,25 @@ function connect(teams, parts, context) {
7696
8219
  function opened(teams, botName, gate, deps) {
7697
8220
  const { outbound, inbound: inbound2 } = transport(teams, gate, deps);
7698
8221
  const { acks, surface } = surfaceOf(teams, outbound, gate, deps);
8222
+ let probe;
7699
8223
  return {
7700
8224
  surface,
7701
8225
  typedEvent: teamsTypedEvent(botName, deps.logger),
7702
- connect: (context) => connect(teams, { botName, acks, inbound: inbound2, gate }, context),
7703
- closes: [() => outbound.close(), () => inbound2?.close()]
8226
+ connect: (context) => {
8227
+ probe = new DeliveryProbe({
8228
+ outbox: outbound.queue,
8229
+ acks,
8230
+ clock: context.clock,
8231
+ logger: context.logger,
8232
+ stats: {
8233
+ probed: (feedbackMs, replyMs) => {
8234
+ context.metrics.probed?.(feedbackMs, replyMs);
8235
+ }
8236
+ }
8237
+ });
8238
+ return connect(teams, { botName, acks, inbound: inbound2, gate, probe }, context);
8239
+ },
8240
+ closes: [() => probe?.close(), () => outbound.close(), () => inbound2?.close()]
7704
8241
  };
7705
8242
  }
7706
8243
  function teamsSurface() {