@celljs/ta-bots 4.11.0 → 4.13.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.
@@ -5,19 +5,70 @@ var TaHostUtil;
5
5
  TaHostUtil2.WAIT_MS = 1000;
6
6
  function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
7
7
  return new Promise((resolve) => {
8
+ let heard = false;
9
+ let answered = false;
8
10
  const timer = setTimeout(() => resolve(undefined), waitMs);
9
11
  const request = {
10
12
  name,
13
+ heard: () => {
14
+ heard = true;
15
+ },
11
16
  resolve: (answer) => {
17
+ answered = true;
12
18
  clearTimeout(timer);
13
19
  resolve(answer);
14
20
  }
15
21
  };
16
22
  events.emit(TA_HOST_EVENT, request);
23
+ if (!heard && !answered) {
24
+ clearTimeout(timer);
25
+ resolve(undefined);
26
+ }
17
27
  });
18
28
  }
19
29
  TaHostUtil2.reach = reach;
20
30
  })(TaHostUtil || (TaHostUtil = {}));
31
+ var TA_ASK_ENTRY = "ta-ask";
32
+ var TaAskUtil;
33
+ (function(TaAskUtil2) {
34
+ const LENGTH = 120;
35
+ function entry(question) {
36
+ const line = question.replace(/\s+/g, " ").trim();
37
+ return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
38
+ }
39
+ TaAskUtil2.entry = entry;
40
+ function asking(entries) {
41
+ var _a;
42
+ for (let i = entries.length - 1;i >= 0; i--) {
43
+ const entry2 = entries[i];
44
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
45
+ return;
46
+ }
47
+ if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
48
+ return read(entry2);
49
+ }
50
+ }
51
+ return;
52
+ }
53
+ TaAskUtil2.asking = asking;
54
+ function next(asked, entry2) {
55
+ var _a;
56
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
57
+ return;
58
+ }
59
+ return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
60
+ }
61
+ TaAskUtil2.next = next;
62
+ function read(found) {
63
+ var _a;
64
+ const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
65
+ if (typeof question !== "string" || !question.trim()) {
66
+ return;
67
+ }
68
+ const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
69
+ return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
70
+ }
71
+ })(TaAskUtil || (TaAskUtil = {}));
21
72
 
22
73
  // web-src/bots-protocol.ts
23
74
  var NAME = "@celljs/ta-bots";
package/host/index.mjs CHANGED
@@ -430,20 +430,71 @@ var TaHostUtil;
430
430
  TaHostUtil2.WAIT_MS = 1000;
431
431
  function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
432
432
  return new Promise((resolve) => {
433
+ let heard = false;
434
+ let answered = false;
433
435
  const timer = setTimeout(() => resolve(undefined), waitMs);
434
436
  const request = {
435
437
  name,
438
+ heard: () => {
439
+ heard = true;
440
+ },
436
441
  resolve: (answer) => {
442
+ answered = true;
437
443
  clearTimeout(timer);
438
444
  resolve(answer);
439
445
  }
440
446
  };
441
447
  events.emit(TA_HOST_EVENT, request);
448
+ if (!heard && !answered) {
449
+ clearTimeout(timer);
450
+ resolve(undefined);
451
+ }
442
452
  });
443
453
  }
444
454
  TaHostUtil2.reach = reach;
445
455
  })(TaHostUtil || (TaHostUtil = {}));
446
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 = {}));
447
498
  // ../ta-protocol/esm/common/ta-protocol.js
448
499
  var TaServer = Symbol("TaServer");
449
500
  var TaClient = Symbol("TaClient");
@@ -481,7 +532,34 @@ ${message}`;
481
532
  return message.replace(BLOCK, "");
482
533
  }
483
534
  TaMessageContext2.strip = strip;
535
+ function read(message) {
536
+ var _a;
537
+ const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
538
+ return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
539
+ }
540
+ TaMessageContext2.read = read;
484
541
  })(TaMessageContext || (TaMessageContext = {}));
542
+ var TaMessageSource;
543
+ (function(TaMessageSource2) {
544
+ TaMessageSource2.DOUBLE = "ta:double";
545
+ const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
546
+ function mark(message, from, detail) {
547
+ if (/^[/!]/.test(message) || of(message)) {
548
+ return message;
549
+ }
550
+ const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
551
+ const context = TaMessageContext.read(message);
552
+ return TaMessageContext.wrap(context === undefined ? line : `${context}
553
+ ${line}`, TaMessageContext.strip(message));
554
+ }
555
+ TaMessageSource2.mark = mark;
556
+ function of(message) {
557
+ const context = TaMessageContext.read(message);
558
+ const match = context === undefined ? null : LINE.exec(context);
559
+ return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
560
+ }
561
+ TaMessageSource2.of = of;
562
+ })(TaMessageSource || (TaMessageSource = {}));
485
563
  var TaImageNote;
486
564
  (function(TaImageNote2) {
487
565
  const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
@@ -602,6 +680,85 @@ var TaSkillUse;
602
680
  }
603
681
  TaSkillUse2.command = command;
604
682
  })(TaSkillUse || (TaSkillUse = {}));
683
+ // ../ta-protocol/esm/common/team-protocol.js
684
+ var TA_UNDECLARED = "extensions.install";
685
+ var TaPermissionUtil;
686
+ (function(TaPermissionUtil2) {
687
+ function read(pi) {
688
+ const given = pi === null || pi === undefined ? undefined : pi.permissions;
689
+ const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
690
+ const host2 = map(given === null || given === undefined ? undefined : given.host);
691
+ const tools = map(given === null || given === undefined ? undefined : given.tools);
692
+ return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
693
+ }
694
+ TaPermissionUtil2.read = read;
695
+ function host(manifest, method, kind) {
696
+ var _a, _b, _c, _d;
697
+ const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
698
+ const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
699
+ return (_d = (_c = (_b = kind ? own(`${method}:${kind}`) : undefined) !== null && _b !== undefined ? _b : own(method)) !== null && _c !== undefined ? _c : own("*")) !== null && _d !== undefined ? _d : TA_UNDECLARED;
700
+ }
701
+ TaPermissionUtil2.host = host;
702
+ })(TaPermissionUtil || (TaPermissionUtil = {}));
703
+ var action = (id, en, zh, more = {}) => ({
704
+ id,
705
+ area: id.split(".")[0],
706
+ title: { en, "zh-CN": zh },
707
+ ...more
708
+ });
709
+ var TA_ACTIONS = [
710
+ action("chat.view", "See conversations", "查看对话"),
711
+ action("chat.send", "Send in conversations", "在对话里发消息"),
712
+ action("chat.create", "Start conversations", "新建对话"),
713
+ action("chat.stop", "Stop a reply", "停止回复"),
714
+ action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话"),
715
+ action("chat.share", "Share by a link", "生成分享链接"),
716
+ action("agent.view", "See agents", "查看智能体"),
717
+ action("agent.use", "Talk with agents", "和智能体对话"),
718
+ action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体"),
719
+ action("channel.view", "See channels", "查看频道"),
720
+ action("channel.post", "Post in channels", "在频道里发言"),
721
+ action("channel.manage", "Create and change channels", "新建、管理频道"),
722
+ action("task.view", "See tasks", "查看任务"),
723
+ action("task.create", "Hand out tasks", "派任务"),
724
+ action("task.manage", "Take over and stop tasks", "接管、停止任务"),
725
+ action("files.read", "Read files", "读文件", { scoped: true }),
726
+ action("files.write", "Change files", "改文件", { scoped: true }),
727
+ action("commands.run", "Let Ta run commands", "让 Ta 运行命令", { scoped: true, risky: true }),
728
+ action("commands.terminal", "Open terminals", "打开终端", { scoped: true, risky: true }),
729
+ action("hosts.use", "Use remote hosts", "使用远程主机", { risky: true }),
730
+ action("models.use", "Use the models", "使用模型"),
731
+ action("models.manage", "Sign in to models", "登录和更换模型账号"),
732
+ action("cron.view", "See scheduled tasks", "查看定时任务"),
733
+ action("cron.manage", "Change scheduled tasks", "管理定时任务"),
734
+ action("extensions.use", "Use extensions", "使用扩展"),
735
+ action("extensions.install", "Install and turn off extensions", "安装、停用扩展"),
736
+ action("settings.view", "See settings", "查看设置"),
737
+ action("settings.manage", "Change settings", "修改设置"),
738
+ action("members.view", "See members", "查看成员"),
739
+ action("members.invite", "Invite people", "邀请别人"),
740
+ action("members.approve", "Answer requests", "处理申请"),
741
+ action("members.roles", "Change roles and members", "管理角色和成员"),
742
+ action("audit.view", "See the record", "查看记录")
743
+ ];
744
+ var TaActionUtil;
745
+ (function(TaActionUtil2) {
746
+ const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
747
+ function info(id) {
748
+ return byId.get(id);
749
+ }
750
+ TaActionUtil2.info = info;
751
+ function title(id, language) {
752
+ const found = byId.get(id);
753
+ return found ? language.startsWith("zh") ? found.title["zh-CN"] : found.title.en : id;
754
+ }
755
+ TaActionUtil2.title = title;
756
+ function inside(dir, path) {
757
+ const base = dir.replace(/\/+$/, "");
758
+ return path === base || path.startsWith(`${base}/`) || base === "";
759
+ }
760
+ TaActionUtil2.inside = inside;
761
+ })(TaActionUtil || (TaActionUtil = {}));
605
762
  // ../ta-protocol/esm/common/workspace-protocol.js
606
763
  var TaWorkspaceServer = Symbol("TaWorkspaceServer");
607
764
  var TaTerminalServer = Symbol("TaTerminalServer");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-bots",
3
- "version": "4.11.0",
3
+ "version": "4.13.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"
@@ -27,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.11.0",
31
- "@celljs/ta-web": "4.11.0",
30
+ "@celljs/ta-protocol": "4.13.0",
31
+ "@celljs/ta-web": "4.13.0",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
@@ -50,6 +50,11 @@
50
50
  "host": "./host/index.mjs",
51
51
  "extensions": [
52
52
  "./extension/index.mjs"
53
- ]
53
+ ],
54
+ "permissions": {
55
+ "host": {
56
+ "*": "settings.manage"
57
+ }
58
+ }
54
59
  }
55
60
  }