@celljs/ta-bots 4.13.0 → 4.14.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.
@@ -27,6 +27,27 @@ var TaHostUtil;
27
27
  });
28
28
  }
29
29
  TaHostUtil2.reach = reach;
30
+ function marked(systemPrompt, mark) {
31
+ return role(systemPrompt).includes(mark);
32
+ }
33
+ TaHostUtil2.marked = marked;
34
+ function role(systemPrompt) {
35
+ if (!systemPrompt) {
36
+ return "";
37
+ }
38
+ const open = `<addendum>
39
+ `;
40
+ const start = systemPrompt.indexOf(open);
41
+ const context = systemPrompt.indexOf(`<project_context>
42
+ `);
43
+ if (start < 0 || context >= 0 && context < start) {
44
+ return "";
45
+ }
46
+ const end = systemPrompt.indexOf(`
47
+ </addendum>`, start);
48
+ return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
49
+ }
50
+ TaHostUtil2.role = role;
30
51
  })(TaHostUtil || (TaHostUtil = {}));
31
52
  var TA_ASK_ENTRY = "ta-ask";
32
53
  var TaAskUtil;
package/host/index.mjs CHANGED
@@ -381,120 +381,6 @@ var TaPackageTextUtil;
381
381
  }
382
382
  TaPackageTextUtil2.pick = pick;
383
383
  })(TaPackageTextUtil || (TaPackageTextUtil = {}));
384
- // ../ta-protocol/esm/common/relay-protocol.js
385
- var TaRelayServer = Symbol("TaRelayServer");
386
- // ../ta-protocol/esm/common/remote-protocol.js
387
- var TaRemoteServer = Symbol("TaRemoteServer");
388
- // ../ta-protocol/esm/common/room-protocol.js
389
- var TaRoomServer = Symbol("TaRoomServer");
390
- var TaRoomWatchUtil;
391
- (function(TaRoomWatchUtil2) {
392
- function of(messages, state) {
393
- const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === "string" && prefix.length > 0) : [];
394
- return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
395
- }
396
- TaRoomWatchUtil2.of = of;
397
- function union(watches) {
398
- let messages = false;
399
- const state = [];
400
- for (const watch of watches) {
401
- messages || (messages = watch.messages);
402
- state.push(...watch.state);
403
- }
404
- return of(messages, messages ? [] : state);
405
- }
406
- TaRoomWatchUtil2.union = union;
407
- function same(a, b) {
408
- return a === b || !!a && !!b && a.messages === b.messages && a.state.join(`
409
- `) === b.state.join(`
410
- `);
411
- }
412
- TaRoomWatchUtil2.same = same;
413
- function hears(watch, event) {
414
- if (event.type === "message") {
415
- return watch.messages;
416
- }
417
- if (event.type === "state") {
418
- return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
419
- }
420
- return true;
421
- }
422
- TaRoomWatchUtil2.hears = hears;
423
- })(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
424
- // ../ta-protocol/esm/common/settings-protocol.js
425
- var TaSettingsServer = Symbol("TaSettingsServer");
426
- // ../ta-protocol/esm/common/ta-extension-host.js
427
- var TA_HOST_EVENT = "ta:host";
428
- var TaHostUtil;
429
- (function(TaHostUtil2) {
430
- TaHostUtil2.WAIT_MS = 1000;
431
- function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
432
- return new Promise((resolve) => {
433
- let heard = false;
434
- let answered = false;
435
- const timer = setTimeout(() => resolve(undefined), waitMs);
436
- const request = {
437
- name,
438
- heard: () => {
439
- heard = true;
440
- },
441
- resolve: (answer) => {
442
- answered = true;
443
- clearTimeout(timer);
444
- resolve(answer);
445
- }
446
- };
447
- events.emit(TA_HOST_EVENT, request);
448
- if (!heard && !answered) {
449
- clearTimeout(timer);
450
- resolve(undefined);
451
- }
452
- });
453
- }
454
- TaHostUtil2.reach = reach;
455
- })(TaHostUtil || (TaHostUtil = {}));
456
- var TA_DOUBLE_FILE = { name: "@celljs/ta-web", key: "assistant.file" };
457
- var TA_ASK_ENTRY = "ta-ask";
458
- var TaAskUtil;
459
- (function(TaAskUtil2) {
460
- const LENGTH = 120;
461
- function entry(question) {
462
- const line = question.replace(/\s+/g, " ").trim();
463
- return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
464
- }
465
- TaAskUtil2.entry = entry;
466
- function asking(entries) {
467
- var _a;
468
- for (let i = entries.length - 1;i >= 0; i--) {
469
- const entry2 = entries[i];
470
- if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
471
- return;
472
- }
473
- if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
474
- return read(entry2);
475
- }
476
- }
477
- return;
478
- }
479
- TaAskUtil2.asking = asking;
480
- function next(asked, entry2) {
481
- var _a;
482
- if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
483
- return;
484
- }
485
- return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
486
- }
487
- TaAskUtil2.next = next;
488
- function read(found) {
489
- var _a;
490
- const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
491
- if (typeof question !== "string" || !question.trim()) {
492
- return;
493
- }
494
- const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
495
- return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
496
- }
497
- })(TaAskUtil || (TaAskUtil = {}));
498
384
  // ../ta-protocol/esm/common/ta-protocol.js
499
385
  var TaServer = Symbol("TaServer");
500
386
  var TaClient = Symbol("TaClient");
@@ -680,6 +566,177 @@ var TaSkillUse;
680
566
  }
681
567
  TaSkillUse2.command = command;
682
568
  })(TaSkillUse || (TaSkillUse = {}));
569
+
570
+ // ../ta-protocol/esm/common/presence-protocol.js
571
+ var TaPresenceServer = Symbol("TaPresenceServer");
572
+ var TaMessageAuthor;
573
+ (function(TaMessageAuthor2) {
574
+ const LINE = /^\[ta:by ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
575
+ const LINES = /^\[ta:by [^\]\n]*\]$\n?/gm;
576
+ function strip(message) {
577
+ const context = TaMessageContext.read(message);
578
+ if (context === undefined || !LINE.test(context)) {
579
+ return message;
580
+ }
581
+ const kept = context.replace(LINES, "").replace(/\n+$/, "");
582
+ const body = TaMessageContext.strip(message);
583
+ return kept.trim() ? TaMessageContext.wrap(kept, body) : body;
584
+ }
585
+ TaMessageAuthor2.strip = strip;
586
+ function mark(message, id, name) {
587
+ const plain = strip(message);
588
+ if (/^[/!]/.test(plain)) {
589
+ return plain;
590
+ }
591
+ const line = `[ta:by ${id.replace(/[\s\]]/g, "")} ${name.replace(/[\]\n]/g, " ").trim() || id}]`;
592
+ const context = TaMessageContext.read(plain);
593
+ return TaMessageContext.wrap(context === undefined ? line : `${context}
594
+ ${line}`, TaMessageContext.strip(plain));
595
+ }
596
+ TaMessageAuthor2.mark = mark;
597
+ function of(message) {
598
+ var _a;
599
+ const context = TaMessageContext.read(message);
600
+ const match = context === undefined ? null : LINE.exec(context);
601
+ return match ? { id: match[1], name: ((_a = match[2]) !== null && _a !== undefined ? _a : match[1]).trim() } : undefined;
602
+ }
603
+ TaMessageAuthor2.of = of;
604
+ })(TaMessageAuthor || (TaMessageAuthor = {}));
605
+ // ../ta-protocol/esm/common/relay-protocol.js
606
+ var TaRelayServer = Symbol("TaRelayServer");
607
+ // ../ta-protocol/esm/common/remote-protocol.js
608
+ var TaRemoteServer = Symbol("TaRemoteServer");
609
+ // ../ta-protocol/esm/common/room-protocol.js
610
+ var TaRoomServer = Symbol("TaRoomServer");
611
+ var TaRoomWatchUtil;
612
+ (function(TaRoomWatchUtil2) {
613
+ function of(messages, state) {
614
+ const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === "string" && prefix.length > 0) : [];
615
+ return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
616
+ }
617
+ TaRoomWatchUtil2.of = of;
618
+ function union(watches) {
619
+ let messages = false;
620
+ const state = [];
621
+ for (const watch of watches) {
622
+ messages || (messages = watch.messages);
623
+ state.push(...watch.state);
624
+ }
625
+ return of(messages, messages ? [] : state);
626
+ }
627
+ TaRoomWatchUtil2.union = union;
628
+ function same(a, b) {
629
+ return a === b || !!a && !!b && a.messages === b.messages && a.state.join(`
630
+ `) === b.state.join(`
631
+ `);
632
+ }
633
+ TaRoomWatchUtil2.same = same;
634
+ function hears(watch, event) {
635
+ if (event.type === "message") {
636
+ return watch.messages;
637
+ }
638
+ if (event.type === "state") {
639
+ return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
640
+ }
641
+ return true;
642
+ }
643
+ TaRoomWatchUtil2.hears = hears;
644
+ })(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
645
+ // ../ta-protocol/esm/common/settings-protocol.js
646
+ var TaSettingsServer = Symbol("TaSettingsServer");
647
+ // ../ta-protocol/esm/common/ta-extension-host.js
648
+ var TA_HOST_EVENT = "ta:host";
649
+ var TaHostUtil;
650
+ (function(TaHostUtil2) {
651
+ TaHostUtil2.WAIT_MS = 1000;
652
+ function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
653
+ return new Promise((resolve) => {
654
+ let heard = false;
655
+ let answered = false;
656
+ const timer = setTimeout(() => resolve(undefined), waitMs);
657
+ const request = {
658
+ name,
659
+ heard: () => {
660
+ heard = true;
661
+ },
662
+ resolve: (answer) => {
663
+ answered = true;
664
+ clearTimeout(timer);
665
+ resolve(answer);
666
+ }
667
+ };
668
+ events.emit(TA_HOST_EVENT, request);
669
+ if (!heard && !answered) {
670
+ clearTimeout(timer);
671
+ resolve(undefined);
672
+ }
673
+ });
674
+ }
675
+ TaHostUtil2.reach = reach;
676
+ function marked(systemPrompt, mark) {
677
+ return role(systemPrompt).includes(mark);
678
+ }
679
+ TaHostUtil2.marked = marked;
680
+ function role(systemPrompt) {
681
+ if (!systemPrompt) {
682
+ return "";
683
+ }
684
+ const open = `<addendum>
685
+ `;
686
+ const start = systemPrompt.indexOf(open);
687
+ const context = systemPrompt.indexOf(`<project_context>
688
+ `);
689
+ if (start < 0 || context >= 0 && context < start) {
690
+ return "";
691
+ }
692
+ const end = systemPrompt.indexOf(`
693
+ </addendum>`, start);
694
+ return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
695
+ }
696
+ TaHostUtil2.role = role;
697
+ })(TaHostUtil || (TaHostUtil = {}));
698
+ var TA_DOUBLE_FILE = { name: "@celljs/ta-web", key: "assistant.file" };
699
+ var TA_ASK_ENTRY = "ta-ask";
700
+ var TaAskUtil;
701
+ (function(TaAskUtil2) {
702
+ const LENGTH = 120;
703
+ function entry(question) {
704
+ const line = question.replace(/\s+/g, " ").trim();
705
+ return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
706
+ }
707
+ TaAskUtil2.entry = entry;
708
+ function asking(entries) {
709
+ var _a;
710
+ for (let i = entries.length - 1;i >= 0; i--) {
711
+ const entry2 = entries[i];
712
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
713
+ return;
714
+ }
715
+ if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
716
+ return read(entry2);
717
+ }
718
+ }
719
+ return;
720
+ }
721
+ TaAskUtil2.asking = asking;
722
+ function next(asked, entry2) {
723
+ var _a;
724
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
725
+ return;
726
+ }
727
+ return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
728
+ }
729
+ TaAskUtil2.next = next;
730
+ function read(found) {
731
+ var _a;
732
+ const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
733
+ if (typeof question !== "string" || !question.trim()) {
734
+ return;
735
+ }
736
+ const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
737
+ return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
738
+ }
739
+ })(TaAskUtil || (TaAskUtil = {}));
683
740
  // ../ta-protocol/esm/common/team-protocol.js
684
741
  var TA_UNDECLARED = "extensions.install";
685
742
  var TaPermissionUtil;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@celljs/ta-bots",
3
- "version": "4.13.0",
3
+ "version": "4.14.0",
4
4
  "description": "A pi package for Ta: bots of WeChat (ClawBot) and WeCom connected to the double, an agent or a conversation, messages and files both ways",
5
5
  "keywords": [
6
6
  "pi-package"
7
7
  ],
8
- "homepage": "https://github.com/cellbang/cell",
8
+ "homepage": "https://github.com/cellbang/ta",
9
9
  "bugs": {
10
- "url": "https://github.com/cellbang/cell/issues"
10
+ "url": "https://github.com/cellbang/ta/issues"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -27,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.13.0",
31
- "@celljs/ta-web": "4.13.0",
30
+ "@celljs/ta-protocol": "4.14.0",
31
+ "@celljs/ta-web": "4.14.0",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {