@celljs/ta-channels 4.22.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 +1 -0
- package/README.md +1 -1
- package/extension/index.mjs +69 -13
- package/host/index.mjs +342 -140
- package/package.json +4 -4
- package/web/index.js +2071 -1642
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
|
-
-
|
|
40
|
+
- 用户没有 `@` 任何人的消息按群聊的"没 @ 时谁接话"(`Channel.reply`,群聊信息里改):负责人接(默认,即第一个没有免打扰的成员,它自己答或 `@` 别人)、大家都接(每个成员都收到,负责人一定答,其他成员没什么要补充就回 `PASS`,不贴出)、只回 @(没人接,和有好友的群聊一样)。点了名的(哪怕点的是免打扰的或不在群里的智能体)只交给点到的人。Ta 发的没点名的消息总是交给负责人;智能体的回答没有 `@` 谁时,接力到此结束。
|
|
41
41
|
- 页面的修改要等服务端处理;包被关掉或它的服务端没能启动时,页面上的操作会直接报错。
|
|
42
42
|
|
|
43
43
|
## 以后
|
package/extension/index.mjs
CHANGED
|
@@ -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
|
-
|
|
673
|
-
|
|
674
|
-
|
|
685
|
+
const choose = (key, choices, fallback, what) => {
|
|
686
|
+
const value = input[key];
|
|
687
|
+
if (value === undefined) {
|
|
688
|
+
return;
|
|
675
689
|
}
|
|
676
|
-
if (
|
|
677
|
-
|
|
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
|
|
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) {
|
|
@@ -1002,6 +1021,11 @@ var TaImageNote;
|
|
|
1002
1021
|
var TaImageSize;
|
|
1003
1022
|
(function(TaImageSize2) {
|
|
1004
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;
|
|
1005
1029
|
function of(base64) {
|
|
1006
1030
|
var _a, _b, _c;
|
|
1007
1031
|
let bytes;
|
|
@@ -1672,18 +1696,38 @@ var ChannelsText;
|
|
|
1672
1696
|
}
|
|
1673
1697
|
ChannelsText.mentions = mentions;
|
|
1674
1698
|
function targets(team, channel, message) {
|
|
1675
|
-
const
|
|
1676
|
-
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);
|
|
1677
1700
|
const named = mentions(message.text, members).filter((id) => id !== message.author);
|
|
1678
1701
|
if (message.author === SYSTEM) {
|
|
1679
1702
|
return [];
|
|
1680
1703
|
}
|
|
1681
|
-
if (named.length > 0 || message.author !== TA) {
|
|
1704
|
+
if (named.length > 0 || message.author !== TA && message.author !== USER || mentions(message.text, team.agents).length > 0) {
|
|
1682
1705
|
return named;
|
|
1683
1706
|
}
|
|
1684
|
-
|
|
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] : [];
|
|
1685
1712
|
}
|
|
1686
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;
|
|
1687
1731
|
function authorName(team, author, labels) {
|
|
1688
1732
|
if (author === SYSTEM) {
|
|
1689
1733
|
return "channel";
|
|
@@ -1718,18 +1762,29 @@ var ChannelsText;
|
|
|
1718
1762
|
lines.push("", "Notice of the channel (follow it; keep it with update_channel_notice):", channel.notice.text);
|
|
1719
1763
|
}
|
|
1720
1764
|
if (before.length > 0) {
|
|
1721
|
-
lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item
|
|
1765
|
+
lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${said(item)}`));
|
|
1722
1766
|
}
|
|
1723
1767
|
if (options.closing) {
|
|
1724
1768
|
lines.push("", CLOSING_NOTE);
|
|
1725
1769
|
}
|
|
1770
|
+
if (mayPass(team, channel, message, agent)) {
|
|
1771
|
+
lines.push("", PASS_NOTE);
|
|
1772
|
+
}
|
|
1726
1773
|
lines.push("", `${authorName(team, message.author, labels)} to you:`);
|
|
1727
1774
|
const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels)}`;
|
|
1728
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
|
+
}
|
|
1729
1779
|
return TaMessageContext.wrap(lines.join(`
|
|
1730
1780
|
`), message.text);
|
|
1731
1781
|
}
|
|
1732
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;
|
|
1733
1788
|
function summary(team) {
|
|
1734
1789
|
if (team.agents.length === 0) {
|
|
1735
1790
|
return "No agents and no channels yet.";
|
|
@@ -1744,7 +1799,7 @@ var ChannelsText;
|
|
|
1744
1799
|
ChannelsText.summary = summary;
|
|
1745
1800
|
function transcript(team, messages) {
|
|
1746
1801
|
const labels = { user: "user", ta: "Ta" };
|
|
1747
|
-
return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${item
|
|
1802
|
+
return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${said(item)}`).join(`
|
|
1748
1803
|
|
|
1749
1804
|
`);
|
|
1750
1805
|
}
|
|
@@ -1788,6 +1843,7 @@ var ChannelsText;
|
|
|
1788
1843
|
}
|
|
1789
1844
|
})(ChannelsText ||= {});
|
|
1790
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.`;
|
|
1791
1847
|
var NOTICE_RULE = [
|
|
1792
1848
|
"A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
|
|
1793
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.`
|