@celljs/ta-bots 4.16.0 → 4.18.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/host/index.mjs CHANGED
@@ -279,8 +279,516 @@ var BotServerTexts;
279
279
 
280
280
  // ../ta-protocol/esm/common/access-protocol.js
281
281
  var TaAccessServer = Symbol("TaAccessServer");
282
+ var TA_SIGN_IN_PATH = "/sign-in";
283
+ var TA_DEVICE_SIGN_IN_PATH = `${TA_SIGN_IN_PATH}/device`;
284
+ // ../ta-protocol/esm/common/ta-extension-host.js
285
+ var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
286
+ var TA_HOST_EVENT = "ta:host";
287
+ var TaHostUtil;
288
+ (function(TaHostUtil2) {
289
+ TaHostUtil2.WAIT_MS = 1000;
290
+ function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
291
+ return new Promise((resolve) => {
292
+ let heard = false;
293
+ let answered = false;
294
+ const timer = setTimeout(() => resolve(undefined), waitMs);
295
+ const request = {
296
+ name,
297
+ heard: () => {
298
+ heard = true;
299
+ },
300
+ resolve: (answer) => {
301
+ answered = true;
302
+ clearTimeout(timer);
303
+ resolve(answer);
304
+ }
305
+ };
306
+ events.emit(TA_HOST_EVENT, request);
307
+ if (!heard && !answered) {
308
+ clearTimeout(timer);
309
+ resolve(undefined);
310
+ }
311
+ });
312
+ }
313
+ TaHostUtil2.reach = reach;
314
+ function marked(systemPrompt, mark) {
315
+ return role(systemPrompt).includes(mark);
316
+ }
317
+ TaHostUtil2.marked = marked;
318
+ function role(systemPrompt) {
319
+ if (!systemPrompt) {
320
+ return "";
321
+ }
322
+ const open = `<addendum>
323
+ `;
324
+ const start = systemPrompt.indexOf(open);
325
+ const context = systemPrompt.indexOf(`<project_context>
326
+ `);
327
+ if (start < 0 || context >= 0 && context < start) {
328
+ return "";
329
+ }
330
+ const end = systemPrompt.indexOf(`
331
+ </addendum>`, start);
332
+ return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
333
+ }
334
+ TaHostUtil2.role = role;
335
+ })(TaHostUtil || (TaHostUtil = {}));
336
+ var TA_DOUBLE_FILE = { name: "@celljs/ta-web", key: "assistant.file" };
337
+ var TA_ASK_ENTRY = "ta-ask";
338
+ var TaAskUtil;
339
+ (function(TaAskUtil2) {
340
+ const LENGTH = 120;
341
+ function entry(question) {
342
+ const line = question.replace(/\s+/g, " ").trim();
343
+ return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
344
+ }
345
+ TaAskUtil2.entry = entry;
346
+ function asking(entries) {
347
+ var _a;
348
+ for (let i = entries.length - 1;i >= 0; i--) {
349
+ const entry2 = entries[i];
350
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
351
+ return;
352
+ }
353
+ if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
354
+ return read(entry2);
355
+ }
356
+ }
357
+ return;
358
+ }
359
+ TaAskUtil2.asking = asking;
360
+ function next(asked, entry2) {
361
+ var _a;
362
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
363
+ return;
364
+ }
365
+ return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
366
+ }
367
+ TaAskUtil2.next = next;
368
+ function read(found) {
369
+ var _a;
370
+ const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
371
+ if (typeof question !== "string" || !question.trim()) {
372
+ return;
373
+ }
374
+ const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
375
+ return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
376
+ }
377
+ })(TaAskUtil || (TaAskUtil = {}));
378
+
379
+ // ../ta-protocol/esm/common/delegate-protocol.js
380
+ var TaDelegateUtil;
381
+ (function(TaDelegateUtil2) {
382
+ TaDelegateUtil2.LEVELS = ["less", "balanced", "more"];
383
+ TaDelegateUtil2.DEFAULT = "balanced";
384
+ TaDelegateUtil2.WORK_TOOLS = ["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"];
385
+ TaDelegateUtil2.CHANGE_TOOLS = ["edit", "write"];
386
+ const LIMITS = {
387
+ less: { noChanges: false },
388
+ balanced: { noChanges: true, steps: 6 },
389
+ more: { noChanges: true, steps: 2 }
390
+ };
391
+ function parse(value) {
392
+ return TaDelegateUtil2.LEVELS.includes(value) ? value : TaDelegateUtil2.DEFAULT;
393
+ }
394
+ TaDelegateUtil2.parse = parse;
395
+ function mark(level) {
396
+ return `(delegate=${level})`;
397
+ }
398
+ TaDelegateUtil2.mark = mark;
399
+ function levelOf(systemPrompt) {
400
+ const role = TaHostUtil.role(systemPrompt);
401
+ return TaDelegateUtil2.LEVELS.find((level) => role.includes(mark(level)));
402
+ }
403
+ TaDelegateUtil2.levelOf = levelOf;
404
+ function limits(level) {
405
+ return LIMITS[level];
406
+ }
407
+ TaDelegateUtil2.limits = limits;
408
+ function refusal(level, tool, steps) {
409
+ if (!TaDelegateUtil2.WORK_TOOLS.includes(tool)) {
410
+ return;
411
+ }
412
+ const limit = LIMITS[level];
413
+ if (limit.noChanges && TaDelegateUtil2.CHANGE_TOOLS.includes(tool)) {
414
+ return "You do not change files yourself: hand this to a task with start_task, with instructions complete enough to do it. The user set how much you hand out in the settings of the double.";
415
+ }
416
+ if (limit.steps !== undefined && steps >= limit.steps) {
417
+ return "You have looked enough for this: hand the work to a task with start_task now, with what you found in its instructions, and tell the user what you started.";
418
+ }
419
+ return;
420
+ }
421
+ TaDelegateUtil2.refusal = refusal;
422
+ })(TaDelegateUtil || (TaDelegateUtil = {}));
423
+
424
+ // ../ta-protocol/esm/common/app-protocol.js
425
+ var FONT_SIZES = ["small", "standard", "large", "xlarge"];
426
+ var words = (en, zh, tw, ja) => ({ "en-US": en, "zh-CN": zh, "zh-TW": tw, "ja-JP": ja });
427
+ var SYSTEM = words("as the system", "跟随系统", "跟隨系統", "システムに合わせる");
428
+ var FONT_SHOWN = {
429
+ small: words("small", "小", "小", "小"),
430
+ standard: words("standard", "标准", "標準", "標準"),
431
+ large: words("large", "大", "大", "大"),
432
+ xlarge: words("extra large", "特大", "特大", "特大")
433
+ };
434
+ var TA_WEB_SETTINGS = [
435
+ {
436
+ key: "theme",
437
+ type: "enum",
438
+ values: ["system", "light", "dark"],
439
+ default: "system",
440
+ what: "Light or dark look; system follows the device.",
441
+ title: words("Theme", "外观", "外觀", "外観"),
442
+ shown: { system: SYSTEM, light: words("light", "浅色", "淺色", "ライト"), dark: words("dark", "深色", "深色", "ダーク") }
443
+ },
444
+ {
445
+ key: "language",
446
+ type: "enum",
447
+ values: ["system", ...TaLanguageUtil.ALL],
448
+ default: "system",
449
+ what: "The language of Ta's pages and of what Ta says; system follows the device.",
450
+ title: words("Language", "语言", "語言", "言語"),
451
+ shown: {
452
+ system: SYSTEM,
453
+ ...Object.fromEntries(TaLanguageUtil.ALL.map((language) => [
454
+ language,
455
+ words(TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language], TaLanguageUtil.NAMES[language])
456
+ ]))
457
+ }
458
+ },
459
+ {
460
+ key: "fontSize",
461
+ type: "enum",
462
+ values: FONT_SIZES,
463
+ default: "standard",
464
+ what: "The size of the text of the whole page.",
465
+ title: words("Text size", "字体大小", "字型大小", "文字サイズ"),
466
+ shown: FONT_SHOWN
467
+ },
468
+ {
469
+ key: "chatFontSize",
470
+ type: "enum",
471
+ values: FONT_SIZES,
472
+ default: "standard",
473
+ what: "The size of the text of conversations, on top of fontSize.",
474
+ title: words("Text size of conversations", "对话字体大小", "對話字型大小", "会話の文字サイズ"),
475
+ shown: FONT_SHOWN
476
+ },
477
+ {
478
+ key: "speak",
479
+ type: "boolean",
480
+ default: false,
481
+ what: "Read every reply aloud.",
482
+ title: words("Read replies aloud", "朗读回复", "朗讀回覆", "返信を読み上げ")
483
+ },
484
+ {
485
+ key: "speakTalk",
486
+ type: "boolean",
487
+ default: false,
488
+ what: "Read the reply aloud when the user spoke to the double by voice.",
489
+ title: words("Read aloud what was asked by voice", "语音提问时朗读回复", "語音提問時朗讀回覆", "音声で聞いたら読み上げ")
490
+ },
491
+ {
492
+ key: "callCaptions",
493
+ type: "boolean",
494
+ default: false,
495
+ what: "Show captions in a call: what the user says and what Ta reads.",
496
+ title: words("Call captions", "通话字幕", "通話字幕", "通話の字幕")
497
+ },
498
+ {
499
+ key: "voice",
500
+ type: "string",
501
+ default: "",
502
+ what: "The voice replies are read with (a voiceURI of the device's voices); empty for the most natural one.",
503
+ title: words("Voice", "朗读声音", "朗讀聲音", "読み上げの声")
504
+ },
505
+ {
506
+ key: "confirmTasks",
507
+ type: "boolean",
508
+ default: false,
509
+ what: "The double asks before it hands out work.",
510
+ title: words("Ask before handing out work", "派任务前先问我", "派任務前先問我", "作業を割り当てる前に確認")
511
+ },
512
+ {
513
+ key: "maxTasks",
514
+ type: "number",
515
+ values: [0, 2, 4, 8],
516
+ default: 0,
517
+ what: "How many of the double's tasks run at once; 0 for as many as it starts.",
518
+ title: words("Tasks at once", "同时运行的任务", "同時執行的任務", "同時に実行するタスク")
519
+ },
520
+ {
521
+ key: "delegate",
522
+ type: "enum",
523
+ values: TaDelegateUtil.LEVELS,
524
+ default: TaDelegateUtil.DEFAULT,
525
+ what: "How much of the work the double hands out to tasks rather than doing it itself.",
526
+ title: words("Hand out work", "派活多少", "派活多少", "作業の割り当て"),
527
+ shown: { less: words("less", "少", "少", "少なめ"), balanced: words("balanced", "适中", "適中", "ふつう"), more: words("more", "多", "多", "多め") }
528
+ },
529
+ {
530
+ key: "assistantModel",
531
+ type: "model",
532
+ default: "",
533
+ what: "The model of the double, <provider>/<model id>; empty for the default model.",
534
+ title: words("Model of the double", "分身的模型", "分身的模型", "分身のモデル")
535
+ },
536
+ {
537
+ key: "taskModel",
538
+ type: "model",
539
+ default: "",
540
+ what: "The model of the tasks the double starts; empty for the default model.",
541
+ title: words("Model of tasks", "任务的模型", "任務的模型", "タスクのモデル")
542
+ },
543
+ { key: "reduceMotion", type: "boolean", default: false, what: "Fewer animations.", title: words("Reduce motion", "减少动画", "減少動畫", "動きを減らす") },
544
+ {
545
+ key: "diagramStyle",
546
+ type: "enum",
547
+ values: ["clean", "sketch", "colour", "motion"],
548
+ default: "clean",
549
+ what: "How diagrams in replies draw: in the colours of the page, as by hand, a colour to a node, or coming in with flowing lines.",
550
+ title: words("Diagram style", "图表风格", "圖表風格", "図のスタイル"),
551
+ shown: {
552
+ clean: words("clean", "简洁", "簡潔", "シンプル"),
553
+ sketch: words("sketch", "草图", "草圖", "スケッチ"),
554
+ colour: words("colour", "彩色", "彩色", "カラー"),
555
+ motion: words("motion", "动效", "動效", "モーション")
556
+ }
557
+ },
558
+ {
559
+ key: "keepAliveMinutes",
560
+ type: "number",
561
+ values: [1, 5, 15, 30],
562
+ default: 5,
563
+ what: "How long an extension started on open keeps running once left, in minutes.",
564
+ title: words("Keep extensions running", "扩展离开后保留", "擴充功能離開後保留", "拡張機能を保持")
565
+ },
566
+ {
567
+ key: "chatFoldDays",
568
+ type: "number",
569
+ values: [3, 7, 30, 0],
570
+ default: 7,
571
+ what: "Conversations not updated for these days fold at the end of the list; 0 for none.",
572
+ title: words("Fold old conversations", "折叠旧对话", "摺疊舊對話", "古い会話を折りたたむ")
573
+ },
574
+ {
575
+ key: "chatArchiveDays",
576
+ type: "number",
577
+ values: [30, 90, 365, 0],
578
+ default: 30,
579
+ what: "Conversations not updated for these days are archived (out of the list, found by search); 0 for none.",
580
+ title: words("Archive old conversations", "归档旧对话", "歸檔舊對話", "古い会話をアーカイブ")
581
+ },
582
+ {
583
+ key: "recentShots",
584
+ type: "boolean",
585
+ default: true,
586
+ what: "The screenshot just taken is offered above the message box, once.",
587
+ title: words("Offer recent screenshots", "提示刚截的图", "提示剛截的圖", "撮ったばかりのスクリーンショットを提案")
588
+ }
589
+ ];
590
+ var TaAppUtil;
591
+ (function(TaAppUtil2) {
592
+ function check(spec, value) {
593
+ var _a, _b;
594
+ switch (spec.type) {
595
+ case "boolean":
596
+ return typeof value === "boolean" ? undefined : "true or false";
597
+ case "string":
598
+ return typeof value === "string" ? undefined : "a string";
599
+ case "model":
600
+ return value === "" || typeof value === "string" && /^[^/\s]+\/\S+$/.test(value) ? undefined : "<provider>/<model id>, or empty";
601
+ default:
602
+ return ((_a = spec.values) === null || _a === undefined ? undefined : _a.includes(value)) ? undefined : `one of ${(_b = spec.values) === null || _b === undefined ? undefined : _b.map((one) => JSON.stringify(one)).join(", ")}`;
603
+ }
604
+ }
605
+ TaAppUtil2.check = check;
606
+ function shown(value, language, spec) {
607
+ var _a;
608
+ const named = (_a = spec === null || spec === undefined ? undefined : spec.shown) === null || _a === undefined ? undefined : _a[String(value)];
609
+ if (named) {
610
+ return TaLanguageUtil.pick(language, named);
611
+ }
612
+ if (typeof value === "boolean") {
613
+ return TaLanguageUtil.pick(language, value ? words("on", "开", "開", "オン") : words("off", "关", "關", "オフ"));
614
+ }
615
+ if (value === "" || value === undefined || value === null) {
616
+ return TaLanguageUtil.pick(language, words("default", "默认", "預設", "デフォルト"));
617
+ }
618
+ return String(value);
619
+ }
620
+ TaAppUtil2.shown = shown;
621
+ })(TaAppUtil || (TaAppUtil = {}));
282
622
  // ../ta-protocol/esm/common/auth-protocol.js
283
623
  var TaAuthServer = Symbol("TaAuthServer");
624
+ // ../ta-protocol/esm/common/deployment-protocol.js
625
+ var TA_WELL_KNOWN_PATH = "/.well-known/ta";
626
+
627
+ class TaDeploymentError extends Error {
628
+ }
629
+ var TaDeploymentUtil;
630
+ (function(TaDeploymentUtil2) {
631
+ TaDeploymentUtil2.DISTRIBUTION_FILE = "distribution.json";
632
+ function url(value) {
633
+ if (typeof value !== "string" || !value.trim()) {
634
+ return;
635
+ }
636
+ try {
637
+ const parsed = new URL(value.trim());
638
+ if (!/^https?:$/.test(parsed.protocol) || parsed.search || parsed.hash || parsed.username || parsed.password) {
639
+ return;
640
+ }
641
+ return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, "");
642
+ } catch (_a) {
643
+ return;
644
+ }
645
+ }
646
+ TaDeploymentUtil2.url = url;
647
+ function name(value) {
648
+ return typeof value === "string" && value.trim() ? value.trim().slice(0, 80) : undefined;
649
+ }
650
+ function describe(env, own, version) {
651
+ var _a, _b;
652
+ const gateway = (_a = url(own.gateway)) !== null && _a !== undefined ? _a : url(env.TA_GATEWAY_URL);
653
+ const relay = (_b = url(own.relay)) !== null && _b !== undefined ? _b : url(env.TA_RELAY_URL);
654
+ const called = name(env.TA_DEPLOYMENT_NAME);
655
+ return { v: 1, ...called ? { name: called } : {}, ...gateway ? { gateway } : {}, ...relay ? { relay } : {}, ...version ? { version } : {} };
656
+ }
657
+ TaDeploymentUtil2.describe = describe;
658
+ TaDeploymentUtil2.HEADERS = {
659
+ "content-type": "application/json",
660
+ "access-control-allow-origin": "*",
661
+ "cache-control": "no-store"
662
+ };
663
+ function parse(value) {
664
+ const given = value;
665
+ if (!given || typeof given !== "object" || given.v !== 1) {
666
+ return;
667
+ }
668
+ const deployment = describe({ TA_DEPLOYMENT_NAME: given.name, TA_GATEWAY_URL: given.gateway, TA_RELAY_URL: given.relay }, {});
669
+ const version = name(given.version);
670
+ return version ? { ...deployment, version } : deployment;
671
+ }
672
+ TaDeploymentUtil2.parse = parse;
673
+ async function discover(address, timeoutMs = 6000) {
674
+ const base = url(address);
675
+ if (!base) {
676
+ throw new TaDeploymentError(`${address} is not an address of http or https.`);
677
+ }
678
+ const controller = new AbortController;
679
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
680
+ try {
681
+ const response = await fetch(`${base}${TA_WELL_KNOWN_PATH}`, { signal: controller.signal, redirect: "follow" });
682
+ if (!response.ok) {
683
+ throw new TaDeploymentError(`${base} is not a deployment of Ta (${response.status}).`);
684
+ }
685
+ const deployment = parse(await response.json().catch(() => {
686
+ return;
687
+ }));
688
+ if (!deployment || !deployment.gateway && !deployment.relay) {
689
+ throw new TaDeploymentError(`${base} is not a deployment of Ta.`);
690
+ }
691
+ return deployment;
692
+ } catch (error) {
693
+ if ((error === null || error === undefined ? undefined : error.name) === "AbortError") {
694
+ throw new TaDeploymentError(`${base} did not answer in time.`);
695
+ }
696
+ throw error;
697
+ } finally {
698
+ clearTimeout(timer);
699
+ }
700
+ }
701
+ TaDeploymentUtil2.discover = discover;
702
+ function distribution(value) {
703
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
704
+ throw new TaDeploymentError(`${TaDeploymentUtil2.DISTRIBUTION_FILE} holds a JSON object.`);
705
+ }
706
+ const given = value;
707
+ const result = {};
708
+ if (given.name !== undefined) {
709
+ result.name = name(given.name);
710
+ }
711
+ for (const key of ["relay", "gateway"]) {
712
+ if (given[key] !== undefined) {
713
+ const address = url(given[key]);
714
+ if (!address) {
715
+ throw new TaDeploymentError(`"${key}" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
716
+ }
717
+ result[key] = address;
718
+ }
719
+ }
720
+ if (given.updates !== undefined) {
721
+ const updates = given.updates;
722
+ const base = url(updates === null || updates === undefined ? undefined : updates.base);
723
+ if (!base && (updates === null || updates === undefined ? undefined : updates.base) !== undefined) {
724
+ throw new TaDeploymentError(`"updates.base" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
725
+ }
726
+ const key = typeof (updates === null || updates === undefined ? undefined : updates.key) === "string" && updates.key.includes("PUBLIC KEY") ? updates.key : undefined;
727
+ if ((updates === null || updates === undefined ? undefined : updates.key) !== undefined && !key) {
728
+ throw new TaDeploymentError(`"updates.key" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is a public key in PEM.`);
729
+ }
730
+ result.updates = { ...base ? { base } : {}, ...key ? { key } : {} };
731
+ }
732
+ if (given.reach !== undefined) {
733
+ result.reach = reach(given.reach);
734
+ }
735
+ if (given.inside !== undefined) {
736
+ const inside = url(given.inside);
737
+ if (!inside) {
738
+ throw new TaDeploymentError(`"inside" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not an address of http or https.`);
739
+ }
740
+ result.inside = inside;
741
+ }
742
+ return result;
743
+ }
744
+ TaDeploymentUtil2.distribution = distribution;
745
+ function reach(value) {
746
+ const given = typeof value === "string" ? { "*": value } : value;
747
+ const entries = given && typeof given === "object" && !Array.isArray(given) ? Object.entries(given) : [];
748
+ const result = {};
749
+ for (const [language, text] of entries) {
750
+ if (typeof text !== "string" || !text.trim()) {
751
+ throw new TaDeploymentError(`"reach.${language}" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is not a sentence.`);
752
+ }
753
+ result[language] = text.trim().slice(0, 200);
754
+ }
755
+ if (Object.keys(result).length === 0) {
756
+ throw new TaDeploymentError(`"reach" of ${TaDeploymentUtil2.DISTRIBUTION_FILE} is a sentence, or one by language.`);
757
+ }
758
+ return result;
759
+ }
760
+ function reachIn(reach2, language) {
761
+ var _a, _b, _c, _d, _e;
762
+ if (!reach2) {
763
+ return;
764
+ }
765
+ const base = language.split("-")[0];
766
+ const near = Object.keys(reach2).find((key) => key.split("-")[0] === base);
767
+ return (_e = (_d = (_c = (_b = (_a = reach2[language]) !== null && _a !== undefined ? _a : reach2[base]) !== null && _b !== undefined ? _b : near && reach2[near]) !== null && _c !== undefined ? _c : reach2["*"]) !== null && _d !== undefined ? _d : reach2.en) !== null && _e !== undefined ? _e : Object.values(reach2)[0];
768
+ }
769
+ TaDeploymentUtil2.reachIn = reachIn;
770
+ function apply(distribution2, env) {
771
+ const defaults = { TA_DEPLOYMENT_NAME: distribution2.name, TA_RELAY_URL: distribution2.relay, TA_GATEWAY_URL: distribution2.gateway };
772
+ for (const [key, value] of Object.entries(defaults)) {
773
+ if (value && !env[key]) {
774
+ env[key] = value;
775
+ }
776
+ }
777
+ }
778
+ TaDeploymentUtil2.apply = apply;
779
+ })(TaDeploymentUtil || (TaDeploymentUtil = {}));
780
+ // ../ta-protocol/esm/common/error-protocol.js
781
+ var TaErrorUtil;
782
+ (function(TaErrorUtil2) {
783
+ function code(error) {
784
+ var _a;
785
+ var _b;
786
+ const failure = error;
787
+ const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
788
+ return typeof code2 === "string" ? code2 : undefined;
789
+ }
790
+ TaErrorUtil2.code = code;
791
+ })(TaErrorUtil || (TaErrorUtil = {}));
284
792
  // ../ta-protocol/esm/common/gateway-protocol.js
285
793
  var TaGatewayServer = Symbol("TaGatewayServer");
286
794
  // ../ta-protocol/esm/common/location.js
@@ -344,19 +852,19 @@ var TaLocation;
344
852
  TaLocation2.isHost = isHost;
345
853
  const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
346
854
  function readHost(input) {
347
- const words = input.trim().split(/\s+/).filter(Boolean);
348
- if (words[0] === "ssh") {
349
- words.shift();
855
+ const words2 = input.trim().split(/\s+/).filter(Boolean);
856
+ if (words2[0] === "ssh") {
857
+ words2.shift();
350
858
  }
351
859
  let destination;
352
860
  let port;
353
861
  let user;
354
862
  const options = [];
355
- for (let i = 0;i < words.length; i++) {
356
- const word = words[i];
863
+ for (let i = 0;i < words2.length; i++) {
864
+ const word = words2[i];
357
865
  const glued = /^-([pl])(.+)$/.exec(word);
358
866
  if (word === "-p" || word === "-l" || glued) {
359
- const value = glued ? glued[2] : words[++i];
867
+ const value = glued ? glued[2] : words2[++i];
360
868
  if (value === undefined) {
361
869
  return { error: "invalid" };
362
870
  }
@@ -366,7 +874,7 @@ var TaLocation;
366
874
  user = value;
367
875
  }
368
876
  } else if (word === "-o" || word.startsWith("-o")) {
369
- const value = word === "-o" ? words[++i] : word.slice(2);
877
+ const value = word === "-o" ? words2[++i] : word.slice(2);
370
878
  const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
371
879
  if (!option) {
372
880
  options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
@@ -376,7 +884,7 @@ var TaLocation;
376
884
  user = option[2];
377
885
  }
378
886
  } else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
379
- options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
887
+ options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words2[i + 1] !== undefined ? `${word} ${words2[++i]}` : word);
380
888
  } else if (destination === undefined) {
381
889
  destination = word;
382
890
  } else {
@@ -482,44 +990,7 @@ var TaLocation;
482
990
  return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
483
991
  }
484
992
  })(TaLocation || (TaLocation = {}));
485
- // ../ta-protocol/esm/common/package-protocol.js
486
- var TaPackageServer = Symbol("TaPackageServer");
487
- var TaPackageTextUtil;
488
- (function(TaPackageTextUtil2) {
489
- function pick(text, language) {
490
- var _a, _b, _c, _d, _e;
491
- if (text === undefined || typeof text === "string") {
492
- return text;
493
- }
494
- const base = language.split("-")[0];
495
- const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
496
- return (_e = (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[base]) !== null && _b !== undefined ? _b : kin === undefined ? undefined : text[kin]) !== null && _c !== undefined ? _c : text.en) !== null && _d !== undefined ? _d : text["en-US"]) !== null && _e !== undefined ? _e : Object.values(text)[0];
497
- }
498
- TaPackageTextUtil2.pick = pick;
499
- })(TaPackageTextUtil || (TaPackageTextUtil = {}));
500
- // ../ta-protocol/esm/common/ta-protocol.js
501
- var TaServer = Symbol("TaServer");
502
- var TaClient = Symbol("TaClient");
503
- var TaErrorUtil;
504
- (function(TaErrorUtil2) {
505
- function code(error) {
506
- var _a;
507
- var _b;
508
- const failure = error;
509
- const code2 = (_b = failure === null || failure === undefined ? undefined : failure.code) !== null && _b !== undefined ? _b : (_a = failure === null || failure === undefined ? undefined : failure.data) === null || _a === undefined ? undefined : _a.code;
510
- return typeof code2 === "string" ? code2 : undefined;
511
- }
512
- TaErrorUtil2.code = code;
513
- })(TaErrorUtil || (TaErrorUtil = {}));
514
- var TaSlashCommandUtil;
515
- (function(TaSlashCommandUtil2) {
516
- function description(command, language) {
517
- var _a, _b;
518
- const { descriptions } = command;
519
- return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
520
- }
521
- TaSlashCommandUtil2.description = description;
522
- })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
993
+ // ../ta-protocol/esm/common/message-protocol.js
523
994
  var TaMessageContext;
524
995
  (function(TaMessageContext2) {
525
996
  const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
@@ -544,23 +1015,47 @@ ${message}`;
544
1015
  var TaMessageSource;
545
1016
  (function(TaMessageSource2) {
546
1017
  TaMessageSource2.DOUBLE = "ta:double";
547
- const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
1018
+ const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
548
1019
  function mark(message, from, detail) {
549
- if (/^[/!]/.test(message) || of(message)) {
550
- return message;
551
- }
552
- const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
553
- const context = TaMessageContext.read(message);
554
- return TaMessageContext.wrap(context === undefined ? line : `${context}
555
- ${line}`, TaMessageContext.strip(message));
1020
+ return marked(message, line(from, detail));
556
1021
  }
557
1022
  TaMessageSource2.mark = mark;
1023
+ function notice(message, from, detail) {
1024
+ return marked(message, line(from, detail, true));
1025
+ }
1026
+ TaMessageSource2.notice = notice;
1027
+ function line(from, detail, notice2 = false) {
1028
+ return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
1029
+ }
1030
+ TaMessageSource2.line = line;
558
1031
  function of(message) {
559
1032
  const context = TaMessageContext.read(message);
560
1033
  const match = context === undefined ? null : LINE.exec(context);
561
- return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
1034
+ return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
562
1035
  }
563
1036
  TaMessageSource2.of = of;
1037
+ function isNotice(message) {
1038
+ var _a;
1039
+ return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
1040
+ }
1041
+ TaMessageSource2.isNotice = isNotice;
1042
+ TaMessageSource2.SECTION = "ta-sources";
1043
+ TaMessageSource2.PROMPT = [
1044
+ "Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
1045
+ "One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
1046
+ "- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
1047
+ "- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
1048
+ "- Never quote it as the user's words nor answer it as if they had said it."
1049
+ ].join(`
1050
+ `);
1051
+ function marked(message, source) {
1052
+ if (/^[/!]/.test(message) || of(message)) {
1053
+ return message;
1054
+ }
1055
+ const context = TaMessageContext.read(message);
1056
+ return TaMessageContext.wrap(context === undefined ? source : `${context}
1057
+ ${source}`, TaMessageContext.strip(message));
1058
+ }
564
1059
  })(TaMessageSource || (TaMessageSource = {}));
565
1060
  var TaImageNote;
566
1061
  (function(TaImageNote2) {
@@ -682,7 +1177,212 @@ var TaSkillUse;
682
1177
  }
683
1178
  TaSkillUse2.command = command;
684
1179
  })(TaSkillUse || (TaSkillUse = {}));
685
-
1180
+ var TaTaskNote;
1181
+ (function(TaTaskNote2) {
1182
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
1183
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
1184
+ function write(note) {
1185
+ const attributes = [`id="${quote(note.id)}"`];
1186
+ if (note.was !== undefined) {
1187
+ attributes.push(`was="${quote(note.was)}"`);
1188
+ }
1189
+ attributes.push(`title="${quote(note.title)}"`);
1190
+ if (note.status !== undefined) {
1191
+ attributes.push(`status="${quote(note.status)}"`);
1192
+ }
1193
+ return `<task_${note.kind} ${attributes.join(" ")}>
1194
+ ${note.body}
1195
+ </task_${note.kind}>`;
1196
+ }
1197
+ TaTaskNote2.write = write;
1198
+ function parse(text) {
1199
+ const match = NOTE.exec(text.trim());
1200
+ if (!match) {
1201
+ return;
1202
+ }
1203
+ const attributes = {};
1204
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
1205
+ attributes[name] = unquote(value);
1206
+ }
1207
+ if (!attributes.id || attributes.title === undefined) {
1208
+ return;
1209
+ }
1210
+ const { id, title, status, was } = attributes;
1211
+ return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
1212
+ }
1213
+ TaTaskNote2.parse = parse;
1214
+ function quote(text) {
1215
+ return text.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/\n/g, " ");
1216
+ }
1217
+ function unquote(text) {
1218
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, "&");
1219
+ }
1220
+ })(TaTaskNote || (TaTaskNote = {}));
1221
+ var TaSecretRef;
1222
+ (function(TaSecretRef2) {
1223
+ TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
1224
+ const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
1225
+ const KINDS = [
1226
+ [/^PHONE(?:_\d+)?$/, "phone"],
1227
+ [/^EMAIL(?:_\d+)?$/, "email"],
1228
+ [/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
1229
+ [/^BANK_CARD(?:_\d+)?$/, "bankCard"]
1230
+ ];
1231
+ function has(text) {
1232
+ return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
1233
+ }
1234
+ TaSecretRef2.has = has;
1235
+ function kind(name) {
1236
+ var _a;
1237
+ var _b;
1238
+ return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
1239
+ }
1240
+ TaSecretRef2.kind = kind;
1241
+ function split(text) {
1242
+ if (!has(text)) {
1243
+ return [{ text }];
1244
+ }
1245
+ const parts = [];
1246
+ let at = 0;
1247
+ for (const match of text.matchAll(REF)) {
1248
+ if (match.index > at) {
1249
+ parts.push({ text: text.slice(at, match.index) });
1250
+ }
1251
+ parts.push({ secret: match[1], kind: kind(match[1]) });
1252
+ at = match.index + match[0].length;
1253
+ }
1254
+ if (at < text.length) {
1255
+ parts.push({ text: text.slice(at) });
1256
+ }
1257
+ return parts;
1258
+ }
1259
+ TaSecretRef2.split = split;
1260
+ function plain(text, label) {
1261
+ return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
1262
+ }
1263
+ TaSecretRef2.plain = plain;
1264
+ })(TaSecretRef || (TaSecretRef = {}));
1265
+ // ../ta-protocol/esm/common/package-protocol.js
1266
+ var TaPackageServer = Symbol("TaPackageServer");
1267
+ var TaPackageTextUtil;
1268
+ (function(TaPackageTextUtil2) {
1269
+ function pick(text, language) {
1270
+ var _a, _b, _c, _d, _e;
1271
+ if (text === undefined || typeof text === "string") {
1272
+ return text;
1273
+ }
1274
+ const base = language.split("-")[0];
1275
+ const kin = Object.keys(text).find((key) => key.split("-")[0] === base);
1276
+ return (_e = (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[base]) !== null && _b !== undefined ? _b : kin === undefined ? undefined : text[kin]) !== null && _c !== undefined ? _c : text.en) !== null && _d !== undefined ? _d : text["en-US"]) !== null && _e !== undefined ? _e : Object.values(text)[0];
1277
+ }
1278
+ TaPackageTextUtil2.pick = pick;
1279
+ })(TaPackageTextUtil || (TaPackageTextUtil = {}));
1280
+ // ../ta-protocol/esm/common/page-protocol.js
1281
+ var TaPageServer = Symbol("TaPageServer");
1282
+ // ../ta-protocol/esm/common/path-map.js
1283
+ var TaPathMap;
1284
+ (function(TaPathMap2) {
1285
+ function isWindows(path2) {
1286
+ return /^[a-zA-Z]:([\\/]|$)/.test(path2) || /^\\\\[^\\]/.test(path2);
1287
+ }
1288
+ TaPathMap2.isWindows = isWindows;
1289
+ function rest(path2, base) {
1290
+ const windows = isWindows(base);
1291
+ if (windows ? !isWindows(path2) : !base.startsWith("/") || !path2.startsWith("/")) {
1292
+ return;
1293
+ }
1294
+ const within = parts(base, windows);
1295
+ const all = parts(path2, windows);
1296
+ if (!within.length || all.length < within.length) {
1297
+ return;
1298
+ }
1299
+ const same = (a, b) => windows ? a.toLowerCase() === b.toLowerCase() : a === b;
1300
+ return within.every((part, i) => same(part, all[i])) ? all.slice(within.length) : undefined;
1301
+ }
1302
+ TaPathMap2.rest = rest;
1303
+ function under(path2, base) {
1304
+ return rest(path2, base) !== undefined;
1305
+ }
1306
+ TaPathMap2.under = under;
1307
+ function join2(base, parts2) {
1308
+ if (!parts2.length) {
1309
+ return base;
1310
+ }
1311
+ const sep = isWindows(base) ? "\\" : "/";
1312
+ return `${base.replace(/[\\/]+$/, "")}${sep}${parts2.join(sep)}`;
1313
+ }
1314
+ TaPathMap2.join = join2;
1315
+ function basename(path2) {
1316
+ var _a;
1317
+ return (_a = path2.split(/[\\/]+/).filter(Boolean).pop()) !== null && _a !== undefined ? _a : "";
1318
+ }
1319
+ TaPathMap2.basename = basename;
1320
+ function path(value, pairs) {
1321
+ for (const [from, to] of deepest(pairs)) {
1322
+ const found = rest(value, from);
1323
+ if (found) {
1324
+ return join2(to, found);
1325
+ }
1326
+ }
1327
+ return value;
1328
+ }
1329
+ TaPathMap2.path = path;
1330
+ function text(value, pairs) {
1331
+ const order = deepest(pairs);
1332
+ if (!order.length) {
1333
+ return value;
1334
+ }
1335
+ const end = String.raw`\s"'<>|*?:;,`;
1336
+ const pattern = new RegExp(String.raw`(^|[^\w.~-])(?:${order.map(([from]) => `(${source(from)})`).join("|")})((?:[\\/][^\\/${end}]*)*)(?=$|[\\/${end})\]}])`, "g");
1337
+ return value.replace(pattern, (...match) => {
1338
+ var _a;
1339
+ const before = match[1];
1340
+ const found = order.findIndex((_, i) => match[i + 2] !== undefined);
1341
+ const tail = (_a = match[order.length + 2]) !== null && _a !== undefined ? _a : "";
1342
+ return `${before}${join2(order[found][1], tail.split(/[\\/]+/).filter(Boolean))}`;
1343
+ });
1344
+ }
1345
+ TaPathMap2.text = text;
1346
+ function json(value, pairs) {
1347
+ const order = deepest(pairs);
1348
+ if (!order.length) {
1349
+ return value;
1350
+ }
1351
+ const one = (each) => {
1352
+ const whole = path(each, order);
1353
+ return whole !== each ? whole : text(each, order);
1354
+ };
1355
+ const walk = (each) => {
1356
+ if (typeof each === "string") {
1357
+ return one(each);
1358
+ }
1359
+ if (Array.isArray(each)) {
1360
+ return each.map(walk);
1361
+ }
1362
+ if (each && typeof each === "object") {
1363
+ return Object.fromEntries(Object.entries(each).map(([key, inner]) => [one(key), walk(inner)]));
1364
+ }
1365
+ return each;
1366
+ };
1367
+ return walk(value);
1368
+ }
1369
+ TaPathMap2.json = json;
1370
+ function parts(path2, windows) {
1371
+ return path2.split(windows ? /[\\/]+/ : /\/+/).filter(Boolean);
1372
+ }
1373
+ function deepest(pairs) {
1374
+ return pairs.filter(([from, to]) => from && to && from !== to && parts(from, isWindows(from)).length > 0).sort(([a], [b]) => parts(b, isWindows(b)).length - parts(a, isWindows(a)).length);
1375
+ }
1376
+ function source(base) {
1377
+ const windows = isWindows(base);
1378
+ const quote = (part) => [...part].map((char) => windows && char.toLowerCase() !== char.toUpperCase() ? `[${char.toLowerCase()}${char.toUpperCase()}]` : char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
1379
+ const each = parts(base, windows).map(quote);
1380
+ if (!windows) {
1381
+ return `/${each.join("/+")}`;
1382
+ }
1383
+ return `${base.startsWith("\\\\") ? String.raw`\\\\` : ""}${each.join(String.raw`[\\/]+`)}`;
1384
+ }
1385
+ })(TaPathMap || (TaPathMap = {}));
686
1386
  // ../ta-protocol/esm/common/presence-protocol.js
687
1387
  var TaPresenceServer = Symbol("TaPresenceServer");
688
1388
  var TaMessageAuthor;
@@ -758,101 +1458,281 @@ var TaRoomWatchUtil;
758
1458
  }
759
1459
  TaRoomWatchUtil2.hears = hears;
760
1460
  })(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
761
- // ../ta-protocol/esm/common/settings-protocol.js
762
- var TaSettingsServer = Symbol("TaSettingsServer");
763
- // ../ta-protocol/esm/common/ta-extension-host.js
764
- var TA_HOST_EVENT = "ta:host";
765
- var TaHostUtil;
766
- (function(TaHostUtil2) {
767
- TaHostUtil2.WAIT_MS = 1000;
768
- function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
769
- return new Promise((resolve) => {
770
- let heard = false;
771
- let answered = false;
772
- const timer = setTimeout(() => resolve(undefined), waitMs);
773
- const request = {
774
- name,
775
- heard: () => {
776
- heard = true;
777
- },
778
- resolve: (answer) => {
779
- answered = true;
780
- clearTimeout(timer);
781
- resolve(answer);
782
- }
783
- };
784
- events.emit(TA_HOST_EVENT, request);
785
- if (!heard && !answered) {
786
- clearTimeout(timer);
787
- resolve(undefined);
788
- }
789
- });
790
- }
791
- TaHostUtil2.reach = reach;
792
- function marked(systemPrompt, mark) {
793
- return role(systemPrompt).includes(mark);
1461
+ // ../ta-protocol/esm/common/said-protocol.js
1462
+ var TaSaid;
1463
+ (function(TaSaid2) {
1464
+ const CARD = /^ta-/i;
1465
+ const READ = 4000;
1466
+ const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
1467
+ const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
1468
+ const MARKS_ONLY = /^[-*_=|:+\s]+$/;
1469
+ const MARKS = [
1470
+ ["context", /<\/?context>/],
1471
+ ["source", /\[ta:(?:from|notice|by) /],
1472
+ ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
1473
+ ["skill", /<skill name="|<\/skill>/],
1474
+ ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
1475
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/]
1476
+ ];
1477
+ function text(content, joiner = `
1478
+ `) {
1479
+ if (typeof content === "string") {
1480
+ return content;
1481
+ }
1482
+ return Array.isArray(content) ? content.filter((part) => (part === null || part === undefined ? undefined : part.type) === "text" && typeof part.text === "string").map((part) => part.text).join(joiner) : "";
1483
+ }
1484
+ TaSaid2.text = text;
1485
+ function words2(role, text2, options = {}) {
1486
+ const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
1487
+ return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
1488
+ }
1489
+ TaSaid2.words = words2;
1490
+ function of(message, options) {
1491
+ return message ? words2(message.role, text(message.content), options) : "";
1492
+ }
1493
+ TaSaid2.of = of;
1494
+ function notice(message) {
1495
+ return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
1496
+ }
1497
+ TaSaid2.notice = notice;
1498
+ function marksOnly(role, text2) {
1499
+ return !!text2.trim() && !line(words2(role, text2), { chars: Number.POSITIVE_INFINITY });
1500
+ }
1501
+ TaSaid2.marksOnly = marksOnly;
1502
+ function line(markdown, options) {
1503
+ var _a;
1504
+ const read = markdown.slice(0, READ);
1505
+ const prose = withoutFences(read, () => true, true).trim();
1506
+ const lines = plain(prose || codeOf(read)).split(`
1507
+ `).map((part) => part.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+)/, "").replace(/\*{1,3}|`+|~~|(?<![\p{L}\p{N}])_{1,3}|_{1,3}(?![\p{L}\p{N}])/gu, "").replace(/\s+/g, " ").trim()).filter((part) => part && !MARKS_ONLY.test(part) && !TAG_LINE.test(part));
1508
+ const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
1509
+ const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
1510
+ `);
1511
+ return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
794
1512
  }
795
- TaHostUtil2.marked = marked;
796
- function role(systemPrompt) {
797
- if (!systemPrompt) {
798
- return "";
799
- }
800
- const open = `<addendum>
801
- `;
802
- const start = systemPrompt.indexOf(open);
803
- const context = systemPrompt.indexOf(`<project_context>
1513
+ TaSaid2.line = line;
1514
+ function leaks(shown, options = {}) {
1515
+ const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
1516
+ const lines = shown.split(`
804
1517
  `);
805
- if (start < 0 || context >= 0 && context < start) {
1518
+ if (options.cards !== true && lines.some((part) => {
1519
+ var _a;
1520
+ var _b;
1521
+ return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
1522
+ })) {
1523
+ found.push("card");
1524
+ }
1525
+ if (lines.some((part) => TAG_LINE.test(part.trim()))) {
1526
+ found.push("tag");
1527
+ }
1528
+ return found;
1529
+ }
1530
+ TaSaid2.leaks = leaks;
1531
+ const SUMMARY = `<conversation_history_summary>
1532
+ <summary>
1533
+ 1. Primary Request and Intent:
1534
+ The user works on the relay.
1535
+ </summary>
1536
+ </conversation_history_summary>`;
1537
+ TaSaid2.SAMPLES = [
1538
+ {
1539
+ mark: "context and where it came from",
1540
+ role: "user",
1541
+ text: `<context>
1542
+ The channel #ops, its members.
1543
+ [ta:from @celljs/ta-channels #ops]
1544
+ </context>
1545
+ Check the build`,
1546
+ said: "Check the build"
1547
+ },
1548
+ {
1549
+ mark: "a notice, not the user",
1550
+ role: "user",
1551
+ text: `<context>
1552
+ [ta:notice @celljs/ta-call]
1553
+ </context>
1554
+ The work finished. Its last words: tests pass.`,
1555
+ said: "The work finished. Its last words: tests pass."
1556
+ },
1557
+ { mark: "one let in", role: "user", text: `<context>
1558
+ [ta:by p-7 Alice]
1559
+ </context>
1560
+ Hello there`, said: "Hello there" },
1561
+ {
1562
+ mark: "notes of images",
1563
+ role: "user",
1564
+ text: `Look at this
1565
+ [Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
1566
+ [Image converted from image/heic to image/png.]`,
1567
+ said: "Look at this"
1568
+ },
1569
+ {
1570
+ mark: "a skill run",
1571
+ role: "user",
1572
+ text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
1573
+ # Ta package
1574
+ Steps.
1575
+ </skill>
1576
+
1577
+ Make a card`,
1578
+ said: "Make a card"
1579
+ },
1580
+ {
1581
+ mark: "a note of a task",
1582
+ role: "user",
1583
+ text: `<task_update id="t1" title="Fix login" status="done">
1584
+ All tests pass.
1585
+ </task_update>`,
1586
+ said: "Fix login"
1587
+ },
1588
+ { mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
1589
+ Now t2.
1590
+ </task_renamed>` },
1591
+ { mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
1592
+ Switched to voice.`, said: "Switched to voice." },
1593
+ { mark: "a summary alone", role: "assistant", text: SUMMARY },
1594
+ { mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
1595
+ <summary>` },
1596
+ {
1597
+ mark: "a card after the answer",
1598
+ role: "assistant",
1599
+ text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
1600
+ said: "tests pass"
1601
+ },
1602
+ { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
1603
+ { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
1604
+ { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
1605
+ { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
1606
+ </system-reminder>
1607
+ Ready.`, said: "Ready." }
1608
+ ];
1609
+ function userWords(text2) {
1610
+ const said = TaImageNote.strip(TaMessageContext.strip(text2));
1611
+ const skill = TaSkillUse.parse(said);
1612
+ if (skill) {
1613
+ return TaSkillUse.command(skill);
1614
+ }
1615
+ const note = TaTaskNote.parse(said);
1616
+ if (!note) {
1617
+ return said;
1618
+ }
1619
+ if (note.kind === "renamed") {
806
1620
  return "";
807
1621
  }
808
- const end = systemPrompt.indexOf(`
809
- </addendum>`, start);
810
- return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
811
- }
812
- TaHostUtil2.role = role;
813
- })(TaHostUtil || (TaHostUtil = {}));
814
- var TA_DOUBLE_FILE = { name: "@celljs/ta-web", key: "assistant.file" };
815
- var TA_ASK_ENTRY = "ta-ask";
816
- var TaAskUtil;
817
- (function(TaAskUtil2) {
818
- const LENGTH = 120;
819
- function entry(question) {
820
- const line = question.replace(/\s+/g, " ").trim();
821
- return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
1622
+ return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
822
1623
  }
823
- TaAskUtil2.entry = entry;
824
- function asking(entries) {
825
- var _a;
826
- for (let i = entries.length - 1;i >= 0; i--) {
827
- const entry2 = entries[i];
828
- if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
829
- return;
1624
+ function withoutFences(text2, drop, tags = false) {
1625
+ const kept = [];
1626
+ let fence;
1627
+ let left = false;
1628
+ for (const part of text2.split(`
1629
+ `)) {
1630
+ const open = FENCE.exec(part);
1631
+ if (!fence && open) {
1632
+ fence = { mark: open[1], dropped: drop(open[2]) };
1633
+ } else if (fence && closes(part, fence.mark)) {
1634
+ const dropped = fence.dropped;
1635
+ fence = undefined;
1636
+ if (dropped) {
1637
+ continue;
1638
+ }
830
1639
  }
831
- if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
832
- return read(entry2);
1640
+ if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
1641
+ left = true;
1642
+ } else {
1643
+ kept.push(part);
833
1644
  }
834
1645
  }
835
- return;
1646
+ return left ? kept.join(`
1647
+ `).replace(/\n{3,}/g, `
1648
+
1649
+ `) : kept.join(`
1650
+ `);
836
1651
  }
837
- TaAskUtil2.asking = asking;
838
- function next(asked, entry2) {
839
- var _a;
840
- if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
841
- return;
1652
+ function codeOf(text2) {
1653
+ const code = [];
1654
+ let fence;
1655
+ for (const part of text2.split(`
1656
+ `)) {
1657
+ const open = FENCE.exec(part);
1658
+ if (!fence && open) {
1659
+ fence = { mark: open[1], card: CARD.test(open[2]) };
1660
+ } else if (fence && closes(part, fence.mark)) {
1661
+ fence = undefined;
1662
+ } else if (fence && !fence.card) {
1663
+ code.push(part);
1664
+ }
842
1665
  }
843
- return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
1666
+ return code.join(`
1667
+ `);
844
1668
  }
845
- TaAskUtil2.next = next;
846
- function read(found) {
1669
+ function closes(part, mark) {
847
1670
  var _a;
848
- const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
849
- if (typeof question !== "string" || !question.trim()) {
1671
+ const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
1672
+ return !!close && close[0] === mark[0] && close.length >= mark.length;
1673
+ }
1674
+ function plain(text2) {
1675
+ const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
1676
+ const words3 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
1677
+ return words3 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
1678
+ }
1679
+ })(TaSaid || (TaSaid = {}));
1680
+ // ../ta-protocol/esm/common/screen-share-protocol.js
1681
+ var TaScreenShareServer = Symbol("TaScreenShareServer");
1682
+ var TaDesktopUtil;
1683
+ (function(TaDesktopUtil2) {
1684
+ TaDesktopUtil2.DEFAULT_PORT = 5900;
1685
+ function id(target) {
1686
+ var _a;
1687
+ return `${(_a = target.via) !== null && _a !== undefined ? _a : ""}|${host(target)}:${port(target)}`;
1688
+ }
1689
+ TaDesktopUtil2.id = id;
1690
+ function host(target) {
1691
+ var _a;
1692
+ return ((_a = target.host) !== null && _a !== undefined ? _a : "").trim() || "127.0.0.1";
1693
+ }
1694
+ TaDesktopUtil2.host = host;
1695
+ function port(target) {
1696
+ var _a;
1697
+ return (_a = target.port) !== null && _a !== undefined ? _a : TaDesktopUtil2.DEFAULT_PORT;
1698
+ }
1699
+ TaDesktopUtil2.port = port;
1700
+ function parse(id2) {
1701
+ const match = /^([^|]*)\|(.+):(\d+)$/.exec(String(id2 !== null && id2 !== undefined ? id2 : ""));
1702
+ if (!match) {
850
1703
  return;
851
1704
  }
852
- const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
853
- return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
1705
+ const port2 = Number(match[3]);
1706
+ return port2 > 0 && port2 < 65536 ? { via: match[1], host: match[2], port: port2 } : undefined;
854
1707
  }
855
- })(TaAskUtil || (TaAskUtil = {}));
1708
+ TaDesktopUtil2.parse = parse;
1709
+ function validPort(port2) {
1710
+ return typeof port2 === "number" && Number.isInteger(port2) && port2 >= 1024 && port2 < 65536;
1711
+ }
1712
+ TaDesktopUtil2.validPort = validPort;
1713
+ function loopback(host2) {
1714
+ return /^(127\.\d+\.\d+\.\d+|localhost|::1|\[::1\])$/i.test(host2);
1715
+ }
1716
+ TaDesktopUtil2.loopback = loopback;
1717
+ function validHost(host2) {
1718
+ return typeof host2 === "string" && /^[A-Za-z0-9.:\-[\]]{1,253}$/.test(host2);
1719
+ }
1720
+ TaDesktopUtil2.validHost = validHost;
1721
+ })(TaDesktopUtil || (TaDesktopUtil = {}));
1722
+ // ../ta-protocol/esm/common/settings-protocol.js
1723
+ var TaSettingsServer = Symbol("TaSettingsServer");
1724
+ // ../ta-protocol/esm/common/ta-protocol.js
1725
+ var TaServer = Symbol("TaServer");
1726
+ var TaClient = Symbol("TaClient");
1727
+ var TaSlashCommandUtil;
1728
+ (function(TaSlashCommandUtil2) {
1729
+ function description(command, language) {
1730
+ var _a, _b;
1731
+ const { descriptions } = command;
1732
+ return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
1733
+ }
1734
+ TaSlashCommandUtil2.description = description;
1735
+ })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
856
1736
  // ../ta-protocol/esm/common/team-protocol.js
857
1737
  var TA_UNDECLARED = "extensions.install";
858
1738
  var TaPermissionUtil;
@@ -901,7 +1781,7 @@ var TA_ACTIONS = [
901
1781
  action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
902
1782
  action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
903
1783
  action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
904
- action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更"),
1784
+ action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更", { grant: "single" }),
905
1785
  action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
906
1786
  action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
907
1787
  action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
@@ -914,9 +1794,15 @@ var TA_ACTIONS = [
914
1794
  action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
915
1795
  action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
916
1796
  ];
1797
+ var TA_OWNER_ACTIONS = [
1798
+ action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
1799
+ action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
1800
+ ];
1801
+ var OWNER_AREAS = ["desktop"];
917
1802
  var TaActionUtil;
918
1803
  (function(TaActionUtil2) {
919
1804
  const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
1805
+ const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
920
1806
  function info(id) {
921
1807
  return byId.get(id);
922
1808
  }
@@ -924,7 +1810,7 @@ var TaActionUtil;
924
1810
  function title(id, language) {
925
1811
  var _a;
926
1812
  var _b, _c;
927
- const title2 = (_a = byId.get(id)) === null || _a === undefined ? undefined : _a.title;
1813
+ const title2 = (_a = titled.get(id)) === null || _a === undefined ? undefined : _a.title;
928
1814
  if (!title2) {
929
1815
  return id;
930
1816
  }
@@ -936,6 +1822,16 @@ var TaActionUtil;
936
1822
  });
937
1823
  }
938
1824
  TaActionUtil2.title = title;
1825
+ function grantable(id) {
1826
+ const info2 = byId.get(id);
1827
+ return !!info2 && !OWNER_AREAS.includes(info2.area);
1828
+ }
1829
+ TaActionUtil2.grantable = grantable;
1830
+ function inRoles(id) {
1831
+ var _a;
1832
+ return grantable(id) && ((_a = byId.get(id)) === null || _a === undefined ? undefined : _a.grant) !== "single";
1833
+ }
1834
+ TaActionUtil2.inRoles = inRoles;
939
1835
  function inside(dir, path) {
940
1836
  const base = dir.replace(/\/+$/, "");
941
1837
  return path === base || path.startsWith(`${base}/`) || base === "";
@@ -944,6 +1840,55 @@ var TaActionUtil;
944
1840
  })(TaActionUtil || (TaActionUtil = {}));
945
1841
  // ../ta-protocol/esm/common/usage-protocol.js
946
1842
  var TaUsageServer = Symbol("TaUsageServer");
1843
+ // ../ta-protocol/esm/common/voice-protocol.js
1844
+ var TaVoiceServer = Symbol("TaVoiceServer");
1845
+ var TaBargeIn;
1846
+ (function(TaBargeIn2) {
1847
+ TaBargeIn2.DEFAULTS = { duck: 0.2, speechMs: 500, level: 0.02, words: 2, waitMs: 1500, echo: 0.3, joinMs: 300, tap: false };
1848
+ TaBargeIn2.SENSITIVITY = [
1849
+ { speechMs: 1000, level: 0.05 },
1850
+ { speechMs: 750, level: 0.035 },
1851
+ { speechMs: TaBargeIn2.DEFAULTS.speechMs, level: TaBargeIn2.DEFAULTS.level },
1852
+ { speechMs: 300, level: 0.012 },
1853
+ { speechMs: 150, level: 0.006 }
1854
+ ];
1855
+ function sensitivity(bargeIn) {
1856
+ let nearest = 0;
1857
+ TaBargeIn2.SENSITIVITY.forEach((step, index) => {
1858
+ if (Math.abs(step.speechMs - bargeIn.speechMs) < Math.abs(TaBargeIn2.SENSITIVITY[nearest].speechMs - bargeIn.speechMs)) {
1859
+ nearest = index;
1860
+ }
1861
+ });
1862
+ return nearest;
1863
+ }
1864
+ TaBargeIn2.sensitivity = sensitivity;
1865
+ function pick(value) {
1866
+ const given = value && typeof value === "object" ? value : {};
1867
+ const out = typeof given.tap === "boolean" ? { tap: given.tap } : {};
1868
+ for (const key of Object.keys(RANGES)) {
1869
+ const number = given[key];
1870
+ if (typeof number === "number" && Number.isFinite(number)) {
1871
+ const [min, max] = RANGES[key];
1872
+ out[key] = Math.min(max, Math.max(min, number));
1873
+ }
1874
+ }
1875
+ return out;
1876
+ }
1877
+ TaBargeIn2.pick = pick;
1878
+ const RANGES = {
1879
+ duck: [0, 1],
1880
+ speechMs: [0, 5000],
1881
+ level: [0, 1],
1882
+ words: [1, 50],
1883
+ waitMs: [100, 1e4],
1884
+ echo: [0, 4],
1885
+ joinMs: [0, 3000]
1886
+ };
1887
+ function resolve(value) {
1888
+ return { ...TaBargeIn2.DEFAULTS, ...pick(value) };
1889
+ }
1890
+ TaBargeIn2.resolve = resolve;
1891
+ })(TaBargeIn || (TaBargeIn = {}));
947
1892
  // ../ta-protocol/esm/common/workspace-protocol.js
948
1893
  var TaWorkspaceServer = Symbol("TaWorkspaceServer");
949
1894
  var TaTerminalServer = Symbol("TaTerminalServer");
@@ -1831,7 +2776,7 @@ class WecomChannel {
1831
2776
  if (!text && files.length === 0) {
1832
2777
  return;
1833
2778
  }
1834
- this.messageHandler({ chat, from: { id: from }, group, text, files, handle: frame.headers?.req_id });
2779
+ this.messageHandler({ chat, from: { id: from }, group, text, files, handle: frame.headers?.req_id, ...body.msgid ? { id: body.msgid } : {} });
1835
2780
  }
1836
2781
  async download(kind, media) {
1837
2782
  const response = await this.fetcher(media.url, { signal: AbortSignal.timeout(DOWNLOAD_MS) });
@@ -2326,8 +3271,9 @@ class WeixinChannel {
2326
3271
  if (texts.length === 0 && files.length === 0) {
2327
3272
  return;
2328
3273
  }
3274
+ const id = message.message_id === undefined ? undefined : String(message.message_id);
2329
3275
  this.messageHandler({ chat, from: { id: chat }, text: texts.join(`
2330
- `), files });
3276
+ `), files, ...id ? { id } : {} });
2331
3277
  }
2332
3278
  async media(item) {
2333
3279
  const of = (kind, media, aesKey) => media?.media && (media.media.encrypt_query_param || media.media.full_url) ? { kind, media: media.media, aesKey: aesKey ?? media.media.aes_key } : undefined;
@@ -2473,6 +3419,8 @@ class WeixinLogins extends LoginBook {
2473
3419
 
2474
3420
  // web-src/bot-service.ts
2475
3421
  var PENDING_MS = 30 * 60000;
3422
+ var HEARD_MS = 30 * 60000;
3423
+ var HEARD_MAX = 1000;
2476
3424
 
2477
3425
  class BotService {
2478
3426
  host;
@@ -2480,6 +3428,7 @@ class BotService {
2480
3428
  status = {};
2481
3429
  channels = new Map;
2482
3430
  pending = new Map;
3431
+ heard = new Map;
2483
3432
  lastChat = new Map;
2484
3433
  store;
2485
3434
  bridge;
@@ -2611,19 +3560,34 @@ class BotService {
2611
3560
  }
2612
3561
  async replied(origins, text) {
2613
3562
  const sent = [];
3563
+ const chats = new Map;
2614
3564
  for (const origin of BotService.unique(origins)) {
2615
- const bot = this.bots.find((other) => other.id === origin.botId);
2616
- const channel = this.channels.get(origin.botId);
3565
+ const key = `${origin.botId}
3566
+ ${origin.chat}`;
3567
+ chats.set(key, [...chats.get(key) ?? [], origin]);
3568
+ }
3569
+ for (const same of chats.values()) {
3570
+ const { botId, chat } = same[0];
3571
+ const bot = this.bots.find((other) => other.id === botId);
3572
+ const channel = this.channels.get(botId);
2617
3573
  if (!bot || !channel) {
2618
3574
  continue;
2619
3575
  }
2620
- const pending = origin.reply ? this.pending.get(origin.reply) : undefined;
2621
- try {
3576
+ const waiting = same.flatMap((origin) => {
3577
+ const pending = origin.reply ? this.pending.get(origin.reply) : undefined;
2622
3578
  if (pending) {
2623
3579
  this.done(origin.reply);
2624
- await (text ? pending.reply.finish(text) : pending.reply.cancel());
3580
+ }
3581
+ return pending ? [pending] : [];
3582
+ });
3583
+ try {
3584
+ await Promise.all(waiting.slice(1).map((pending) => pending.reply.cancel().catch(() => {
3585
+ return;
3586
+ })));
3587
+ if (waiting[0]) {
3588
+ await (text ? waiting[0].reply.finish(text) : waiting[0].reply.cancel());
2625
3589
  } else if (text) {
2626
- await channel.sendText(origin.chat, text);
3590
+ await channel.sendText(chat, text);
2627
3591
  }
2628
3592
  sent.push({ botId: bot.id, kind: bot.kind, botName: bot.name, text });
2629
3593
  } catch (error) {
@@ -2749,7 +3713,7 @@ class BotService {
2749
3713
  }
2750
3714
  async receive(botId, channel, message) {
2751
3715
  const bot = this.bots.find((other) => other.id === botId);
2752
- if (!bot) {
3716
+ if (!bot || this.heardBefore(bot.id, message.id)) {
2753
3717
  return;
2754
3718
  }
2755
3719
  this.lastChat.set(bot.id, message.chat);
@@ -2792,6 +3756,25 @@ class BotService {
2792
3756
  });
2793
3757
  }
2794
3758
  }
3759
+ heardBefore(botId, id) {
3760
+ if (!id) {
3761
+ return false;
3762
+ }
3763
+ const now = Date.now();
3764
+ const key = `${botId}
3765
+ ${id}`;
3766
+ if (this.heard.has(key)) {
3767
+ return true;
3768
+ }
3769
+ for (const [other, at] of this.heard) {
3770
+ if (now - at < HEARD_MS && this.heard.size < HEARD_MAX) {
3771
+ break;
3772
+ }
3773
+ this.heard.delete(other);
3774
+ }
3775
+ this.heard.set(key, now);
3776
+ return false;
3777
+ }
2795
3778
  done(id) {
2796
3779
  const pending = this.pending.get(id);
2797
3780
  if (pending) {