@celljs/ta-channels 4.21.0 → 4.23.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/README.en.md CHANGED
@@ -10,6 +10,7 @@ A built-in Ta package (enabled by default but can be toggled in the Web client's
10
10
 
11
11
  - **Agent**: a normal Ta session plus a name and responsibility (as `appendSystemPrompt`); the session name is the agent's name, and the session belongs to the `@celljs/ta-channels` group (folded into one row in the conversation list). Each agent has its own cartoon avatar (those of `ui.Face`, drawn by `FaceUtil` of ta-relay, with 25 shapes and color schemes stored in `face`; on creation, it tries to avoid duplicates with existing avatars; old data without `face` is assigned by id), blinks, and looks left and right while answering; Ta itself remains the Cell logo. The session file is recorded when first opened and reopened from the file next time. A session with an agent has no team tools.
12
12
  - **Channel**: members (agents, with the first being the lead) and messages. Messages are sent to members `@`-mentioned; agents' answers are posted back to the channel, and if they `@` someone in their answer, it is passed on to them. Each agent processes one message at a time. Users can mute members in a channel (`muted`): they do not answer anything in this channel, even if `@`-mentioned; when the lead is muted, messages with no one `@`-mentioned go to the next unmuted member.
13
+ - **Who answers without @** (`Channel.reply`, in the chat info): what the user says naming nobody goes to the lead (the default; it answers or names someone), to every member (the lead always answers, the others answer `PASS`, not posted, when their part adds nothing), or to nobody, as in a group chat with friends. A message naming anyone, even a muted agent or one not in the chat, goes only to whom it names; what Ta says naming nobody always goes to the lead.
13
14
  - **Budget of a discussion** (`ChannelsUtil.limit`, design in docs/design/ta-channel-rounds.md): a message of the user or Ta starts a round; agents hand on without a limit of hops, within the tokens and answers the channel's length of talks allows (short / normal / long, in its … menu), and are told to conclude past 70% of it; the budget doubles while the user watches the channel and halves while nobody is there, a round stops early when the agents only agree, repeat themselves or hand back and forth bringing nothing new, and one that changed files or the notice goes on once past it (×1.5). Three more limits, in tokens, are set in Settings → Group chats: an answer past its own is stopped where it is, a channel past its own of the day (set in its info, or the default) answers only the user, and past that of all channels all pause and the user is told; Go on lets a round past those of the day. Where it stops, the channel adds a line "The agents paused to wait for you" with the replies and tokens of the round, and two buttons: Go on (the hand-ons it cut go on, the budget anew) and Have the lead sum up, chosen once; the return of `post_to_channel` says so too.
14
15
  - **Tools**: each session in Ta (web pages and other clients connected to ta serve) has `create_agent`, `create_channel`, `add_to_channel`, `post_to_channel`, and `list_channels`. When a user specifies a goal ("assemble a team to do the landing page"), Ta creates agents and channels, posts the goal, and waits for answers from each member before replying to the user. When a role is missing from a channel, Ta uses `add_to_channel` to add an existing agent (added after existing members; lead unchanged). The open page marks this channel with a green dot in the sidebar, which disappears when opened. Pausing Ta just stops waiting; agents continue to answer in the channel.
15
16
  - **Hand over to…** (WeChat's forward, of work rather than of words): say "give this to @life" in a conversation, or pick Hand over to… in the + of the message box and an agent or a channel; Ta first writes a brief in that conversation (the goal, what is done and decided, what is left or blocks, the files and commands that matter), then hands it over with the tool `hand_off`. An agent gets the brief as a message of its own conversation (starting with "Handed over from 'that conversation'", the session file of the conversation in the `<context>` for the model, to read when the brief is not enough) and goes on; a channel gets it as a message of Ta's, which its lead answers. Neither is waited for: the user follows it there. The conversation it came from keeps a card "Handed over to @life" (the model does not read it) with the brief, Open going to the agent's conversation or the channel. An external agent without Ta's tools writes the brief in a `ta-handoff` block in the turn the + asked for, and the pi extension hands it over. On the server it is `TeamService.handOff` (`web-src/handoff.ts`).
package/README.md CHANGED
@@ -37,7 +37,7 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 包 关
37
37
  ## 限制
38
38
 
39
39
  - 只有 ta serve 有团队:单独运行 `ta`(CLI,没有 ta serve)时,团队工具仍然存在,但调用时会返回"需要 ta serve"的说明,不会创建或转发任何东西。包的服务端没能启动时,工具会说明启动失败,请看 ta serve 的日志。
40
- - 没有 `@` 任何人的消息(用户或 Ta 发的)交给负责人,即频道的第一个没有免打扰的成员;智能体的回答没有 `@` 谁时,接力到此结束。
40
+ - 用户没有 `@` 任何人的消息按群聊的"没 @ 时谁接话"(`Channel.reply`,群聊信息里改):负责人接(默认,即第一个没有免打扰的成员,它自己答或 `@` 别人)、大家都接(每个成员都收到,负责人一定答,其他成员没什么要补充就回 `PASS`,不贴出)、只回 @(没人接,和有好友的群聊一样)。点了名的(哪怕点的是免打扰的或不在群里的智能体)只交给点到的人。Ta 发的没点名的消息总是交给负责人;智能体的回答没有 `@` 谁时,接力到此结束。
41
41
  - 页面的修改要等服务端处理;包被关掉或它的服务端没能启动时,页面上的操作会直接报错。
42
42
 
43
43
  ## 以后
@@ -388,6 +388,9 @@ var BUDGETS = {
388
388
  long: { tokens: 3000000, replies: 100 }
389
389
  };
390
390
  var DEFAULT_BUDGET = "normal";
391
+ var REPLIES = ["mentioned", "lead", "all"];
392
+ var DEFAULT_REPLY = "lead";
393
+ var PASS = "PASS";
391
394
  var EXTEND_BY = 0.5;
392
395
  var MAX_MESSAGES = 200;
393
396
  var FACES = FACE_COUNT;
@@ -400,6 +403,16 @@ var NOTICE_HEADINGS = { zh: ["决定", "约定", "待办"], en: ["Decisions", "C
400
403
  // web-src/channels-util.ts
401
404
  var ChannelsUtil;
402
405
  ((ChannelsUtil) => {
406
+ function may(team) {
407
+ const given = team.may;
408
+ return {
409
+ create: !given || given.create,
410
+ agent: (id) => !given || given.agents.includes(id),
411
+ manage: (id) => !given || given.manage.includes(id),
412
+ edit: (id) => !given || given.edit.includes(id)
413
+ };
414
+ }
415
+ ChannelsUtil.may = may;
403
416
  function newRound() {
404
417
  return { total: 0, tokens: 0, stopped: false };
405
418
  }
@@ -669,16 +682,22 @@ var ChannelsUtil;
669
682
  delete channel.pinned;
670
683
  }
671
684
  }
672
- if (input.budget !== undefined) {
673
- if (typeof input.budget !== "string" || !(input.budget in BUDGETS)) {
674
- throw new Error(`The budget of a channel is one of ${Object.keys(BUDGETS).join(", ")}.`);
685
+ const choose = (key, choices, fallback, what) => {
686
+ const value = input[key];
687
+ if (value === undefined) {
688
+ return;
675
689
  }
676
- if (input.budget === DEFAULT_BUDGET) {
677
- delete channel.budget;
690
+ if (typeof value !== "string" || !choices.includes(value)) {
691
+ throw new Error(`${what} is one of ${choices.join(", ")}.`);
692
+ }
693
+ if (value === fallback) {
694
+ delete channel[key];
678
695
  } else {
679
- channel.budget = input.budget;
696
+ channel[key] = value;
680
697
  }
681
- }
698
+ };
699
+ choose("budget", Object.keys(BUDGETS), DEFAULT_BUDGET, "The budget of a channel");
700
+ choose("reply", REPLIES, DEFAULT_REPLY, "Who answers what names nobody in a channel");
682
701
  if (input.dailyLimit === null) {
683
702
  delete channel.dailyLimit;
684
703
  } else if (input.dailyLimit !== undefined) {
@@ -687,6 +706,12 @@ var ChannelsUtil;
687
706
  }
688
707
  channel.dailyLimit = input.dailyLimit;
689
708
  }
709
+ if (input.shared !== undefined) {
710
+ if (typeof input.shared !== "string" || !input.shared) {
711
+ throw new Error("The group chat a channel became is the id of a room.");
712
+ }
713
+ channel.shared = input.shared;
714
+ }
690
715
  return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, before };
691
716
  }
692
717
  ChannelsUtil.updateChannel = updateChannel;
@@ -699,6 +724,10 @@ var ChannelsUtil;
699
724
  return team.channels.filter((channel) => channel.by === "ta");
700
725
  }
701
726
  ChannelsUtil.taskChannels = taskChannels;
727
+ function liveChannels(team) {
728
+ return ownChannels(team).filter((channel) => !channel.shared);
729
+ }
730
+ ChannelsUtil.liveChannels = liveChannels;
702
731
  function ownChannels(team) {
703
732
  return team.channels.filter((channel) => channel.by !== "ta");
704
733
  }
@@ -992,6 +1021,11 @@ var TaImageNote;
992
1021
  var TaImageSize;
993
1022
  (function(TaImageSize2) {
994
1023
  const JPEG_BYTES = 256 * 1024;
1024
+ function type(bytes) {
1025
+ const at = (offset, ...values) => values.every((value, index) => bytes[offset + index] === value);
1026
+ return at(0, 255, 216, 255) ? "image/jpeg" : at(0, 137, 80, 78, 71) ? "image/png" : at(0, 71, 73, 70, 56) ? "image/gif" : at(0, 82, 73, 70, 70) && at(8, 87, 69, 66, 80) ? "image/webp" : undefined;
1027
+ }
1028
+ TaImageSize2.type = type;
995
1029
  function of(base64) {
996
1030
  var _a, _b, _c;
997
1031
  let bytes;
@@ -1662,18 +1696,38 @@ var ChannelsText;
1662
1696
  }
1663
1697
  ChannelsText.mentions = mentions;
1664
1698
  function targets(team, channel, message) {
1665
- const muted = channel.muted ?? [];
1666
- const members = channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
1699
+ const members = answering(team, channel);
1667
1700
  const named = mentions(message.text, members).filter((id) => id !== message.author);
1668
1701
  if (message.author === SYSTEM) {
1669
1702
  return [];
1670
1703
  }
1671
- if (named.length > 0 || message.author !== USER && message.author !== TA) {
1704
+ if (named.length > 0 || message.author !== TA && message.author !== USER || mentions(message.text, team.agents).length > 0) {
1672
1705
  return named;
1673
1706
  }
1674
- return members.length > 0 ? [members[0].id] : [];
1707
+ const reply = message.author === TA ? "lead" : replyOf(channel);
1708
+ if (reply === "all") {
1709
+ return members.map((agent) => agent.id);
1710
+ }
1711
+ return reply === "lead" && members.length > 0 ? [members[0].id] : [];
1675
1712
  }
1676
1713
  ChannelsText.targets = targets;
1714
+ function replyOf(channel) {
1715
+ return channel?.reply && REPLIES.includes(channel.reply) ? channel.reply : DEFAULT_REPLY;
1716
+ }
1717
+ ChannelsText.replyOf = replyOf;
1718
+ function passes(text) {
1719
+ return text.replace(/[\s.。!!*_`"'“”]/g, "").toUpperCase() === PASS;
1720
+ }
1721
+ ChannelsText.passes = passes;
1722
+ function answering(team, channel) {
1723
+ const muted = channel.muted ?? [];
1724
+ return channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
1725
+ }
1726
+ function mayPass(team, channel, message, agent) {
1727
+ const members = answering(team, channel);
1728
+ return message.author === USER && replyOf(channel) === "all" && members[0]?.id !== agent.id && mentions(message.text, team.agents).length === 0;
1729
+ }
1730
+ ChannelsText.mayPass = mayPass;
1677
1731
  function authorName(team, author, labels) {
1678
1732
  if (author === SYSTEM) {
1679
1733
  return "channel";
@@ -1708,18 +1762,29 @@ var ChannelsText;
1708
1762
  lines.push("", "Notice of the channel (follow it; keep it with update_channel_notice):", channel.notice.text);
1709
1763
  }
1710
1764
  if (before.length > 0) {
1711
- lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
1765
+ lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${said(item)}`));
1712
1766
  }
1713
1767
  if (options.closing) {
1714
1768
  lines.push("", CLOSING_NOTE);
1715
1769
  }
1770
+ if (mayPass(team, channel, message, agent)) {
1771
+ lines.push("", PASS_NOTE);
1772
+ }
1716
1773
  lines.push("", `${authorName(team, message.author, labels)} to you:`);
1717
1774
  const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels)}`;
1718
1775
  lines.push(TaMessageSource.line(NAME, `#${channel.name}${speaker}`));
1776
+ if (message.images?.length) {
1777
+ lines.push(`(${message.images.length > 1 ? `${message.images.length} pictures` : "A picture"} sent with it, attached.)`);
1778
+ }
1719
1779
  return TaMessageContext.wrap(lines.join(`
1720
1780
  `), message.text);
1721
1781
  }
1722
1782
  ChannelsText.prompt = prompt;
1783
+ function said(message) {
1784
+ const pictures = message.images?.length ? `[${message.images.length > 1 ? `${message.images.length} pictures` : "picture"}]` : "";
1785
+ return [pictures, message.text].filter(Boolean).join(" ");
1786
+ }
1787
+ ChannelsText.said = said;
1723
1788
  function summary(team) {
1724
1789
  if (team.agents.length === 0) {
1725
1790
  return "No agents and no channels yet.";
@@ -1734,7 +1799,7 @@ var ChannelsText;
1734
1799
  ChannelsText.summary = summary;
1735
1800
  function transcript(team, messages) {
1736
1801
  const labels = { user: "user", ta: "Ta" };
1737
- return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${item.text}`).join(`
1802
+ return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${said(item)}`).join(`
1738
1803
 
1739
1804
  `);
1740
1805
  }
@@ -1778,6 +1843,7 @@ var ChannelsText;
1778
1843
  }
1779
1844
  })(ChannelsText ||= {});
1780
1845
  var CLOSING_NOTE = "This discussion has spent most of what the user allows it before they look in: conclude now. Hand on only if the work cannot go on without that member; the lead sums up what was concluded and what the user is to decide.";
1846
+ var PASS_NOTE = `The user named nobody, and every member got this message: answer only if your role has something of its own to add; the lead answers for the channel. Else answer exactly ${PASS}, which is not posted.`;
1781
1847
  var NOTICE_RULE = [
1782
1848
  "A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
1783
1849
  `When the talk settles a decision or a convention, or adds, assigns or finishes a to-do, update it with update_channel_notice: the whole notice, short, under the headings ### ${NOTICE_HEADINGS.zh.join(" / ")} (### ${NOTICE_HEADINGS.en.join(" / ")} in English), in the language of the channel, to-dos as - [ ] or - [x] with who does them. The lead keeps it most; leave it for small talk.`