@celljs/ta-channels 4.19.0 → 4.20.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/web/index.js CHANGED
@@ -700,6 +700,12 @@ var FaceUtil;
700
700
  })(FaceUtil || (FaceUtil = {}));
701
701
 
702
702
  // web-src/channels-model.ts
703
+ var DEFAULT_LIMITS = { answer: 300000, channelDay: 5000000, allDay: 20000000 };
704
+ var LIMIT_CHOICES = {
705
+ answer: [1e5, 300000, 1e6],
706
+ channelDay: [2000000, 5000000, 20000000, 0],
707
+ allDay: [5000000, 20000000, 0]
708
+ };
703
709
  var NAME = "@celljs/ta-channels";
704
710
  var AGENT_MARK = "one of the agents of Ta";
705
711
  var MEMBER_CHANGES = ["lead", "remove", "mute", "unmute"];
@@ -711,15 +717,22 @@ var Keys;
711
717
  Keys.FOCUS = "focus";
712
718
  Keys.ANSWERED = "answered";
713
719
  Keys.CARDS = "cards";
720
+ Keys.LIMITS = "limits";
721
+ Keys.SPENT = "spent";
714
722
  Keys.MESSAGES = "messages/";
715
723
  Keys.messages = (channelId) => `${Keys.MESSAGES}${channelId}`;
716
724
  })(Keys ||= {});
717
725
  var USER = "user";
718
726
  var TA = "ta";
719
727
  var SYSTEM = "system";
720
- var MAX_HOPS = 3;
721
- var MAX_REPLIES = 8;
722
- var MAX_AGENT_REPLIES = 2;
728
+ var BUDGETS = {
729
+ short: { tokens: 200000, replies: 10 },
730
+ normal: { tokens: 800000, replies: 30 },
731
+ long: { tokens: 3000000, replies: 100 }
732
+ };
733
+ var DEFAULT_BUDGET = "normal";
734
+ var EXTEND_BY = 0.5;
735
+ var WATCH_MS = 30000;
723
736
  var MAX_MESSAGES = 200;
724
737
  var FACES = FACE_COUNT;
725
738
  var MAX_MEMBERS = 12;
@@ -733,25 +746,58 @@ var NOTICE_HEADINGS = { zh: ["决定", "约定", "待办"], en: ["Decisions", "C
733
746
  var ChannelsUtil;
734
747
  ((ChannelsUtil) => {
735
748
  function newRound() {
736
- return { total: 0, byAgent: {}, stopped: false };
749
+ return { total: 0, tokens: 0, stopped: false };
737
750
  }
738
751
  ChannelsUtil.newRound = newRound;
739
- function limit(round, targets, hops) {
740
- const allowed = [];
741
- const byAgent = { ...round.byAgent };
742
- let total = round.total;
743
- for (const id of targets) {
744
- if (hops < MAX_HOPS && total < MAX_REPLIES && (byAgent[id] ?? 0) < MAX_AGENT_REPLIES) {
745
- allowed.push(id);
746
- byAgent[id] = (byAgent[id] ?? 0) + 1;
747
- total++;
752
+ function budgetOf(channel) {
753
+ return channel?.budget && channel.budget in BUDGETS ? channel.budget : DEFAULT_BUDGET;
754
+ }
755
+ ChannelsUtil.budgetOf = budgetOf;
756
+ function limit(round, targets, budget, from, scale = 1) {
757
+ const fit = (extended2) => {
758
+ const { tokens, replies } = caps(budget, scale, extended2);
759
+ const open = (round.tokens ?? 0) < tokens;
760
+ const allowed2 = [];
761
+ let total2 = round.total;
762
+ for (const id of targets) {
763
+ if (open && total2 < replies) {
764
+ allowed2.push(id);
765
+ total2++;
766
+ }
748
767
  }
768
+ return { allowed: allowed2, total: total2 };
769
+ };
770
+ let extended = !!round.extended;
771
+ let { allowed, total } = fit(extended);
772
+ if (allowed.length < targets.length && round.progress && !extended) {
773
+ extended = true;
774
+ ({ allowed, total } = fit(true));
749
775
  }
750
- const cut = allowed.length < targets.length;
751
- const note = cut && !round.stopped;
752
- return { allowed, round: { total, byAgent, stopped: round.stopped || cut }, cut, note };
776
+ round = extended ? { ...round, extended } : round;
777
+ const cut = targets.filter((id) => !allowed.includes(id));
778
+ const pending = cut.length > 0 && from ? [...round.pending ?? [], { ...from, agentIds: cut }] : round.pending;
779
+ return { allowed, cut, round: { ...round, total, stopped: round.stopped || cut.length > 0, ...pending ? { pending } : {} } };
753
780
  }
754
781
  ChannelsUtil.limit = limit;
782
+ function used(round, budget, scale = 1) {
783
+ const limits = caps(budget, scale, !!round.extended);
784
+ return Math.max((round.tokens ?? 0) / limits.tokens, round.total / limits.replies);
785
+ }
786
+ ChannelsUtil.used = used;
787
+ function caps(budget, scale, extended) {
788
+ const { tokens, replies } = BUDGETS[budget];
789
+ const factor = scale * (extended ? 1 + EXTEND_BY : 1);
790
+ return { tokens: tokens * factor, replies: Math.max(1, Math.round(replies * factor)) };
791
+ }
792
+ ChannelsUtil.caps = caps;
793
+ function spent(before, after) {
794
+ if (!before || !after) {
795
+ return 0;
796
+ }
797
+ const delta = (key) => Math.max(0, (after[key] ?? 0) - (before[key] ?? 0));
798
+ return Math.round(delta("input") + delta("output") + delta("cacheWrite") + delta("cacheRead") / 10);
799
+ }
800
+ ChannelsUtil.spent = spent;
755
801
  function emptyTeam() {
756
802
  return { agents: [], channels: [] };
757
803
  }
@@ -968,6 +1014,24 @@ var ChannelsUtil;
968
1014
  delete channel.pinned;
969
1015
  }
970
1016
  }
1017
+ if (input.budget !== undefined) {
1018
+ if (typeof input.budget !== "string" || !(input.budget in BUDGETS)) {
1019
+ throw new Error(`The budget of a channel is one of ${Object.keys(BUDGETS).join(", ")}.`);
1020
+ }
1021
+ if (input.budget === DEFAULT_BUDGET) {
1022
+ delete channel.budget;
1023
+ } else {
1024
+ channel.budget = input.budget;
1025
+ }
1026
+ }
1027
+ if (input.dailyLimit === null) {
1028
+ delete channel.dailyLimit;
1029
+ } else if (input.dailyLimit !== undefined) {
1030
+ if (!LIMIT_CHOICES.channelDay.includes(input.dailyLimit)) {
1031
+ throw new Error(`The limit of a day of a channel is one of ${LIMIT_CHOICES.channelDay.join(", ")} tokens (0 for none), or null.`);
1032
+ }
1033
+ channel.dailyLimit = input.dailyLimit;
1034
+ }
971
1035
  return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, before };
972
1036
  }
973
1037
  ChannelsUtil.updateChannel = updateChannel;
@@ -1048,9 +1112,40 @@ var ChannelsUtil;
1048
1112
  delete agent.cwd;
1049
1113
  }
1050
1114
  }
1115
+ if (input.model !== undefined) {
1116
+ const model = checkModel(input.model);
1117
+ if (model) {
1118
+ agent.model = model;
1119
+ } else {
1120
+ delete agent.model;
1121
+ }
1122
+ }
1051
1123
  return { team: { ...team, agents: team.agents.map((other) => other.id === agent.id ? agent : other) }, agent, before };
1052
1124
  }
1053
1125
  ChannelsUtil.updateAgent = updateAgent;
1126
+ function checkModel(value) {
1127
+ if (value === "" || value === null) {
1128
+ return;
1129
+ }
1130
+ if (typeof value !== "string" || value.length > 200 || !/^[^/\s]+\/\S+$/.test(value)) {
1131
+ throw new Error("A model is named `<provider>/<model id>`.");
1132
+ }
1133
+ return value;
1134
+ }
1135
+ ChannelsUtil.checkModel = checkModel;
1136
+ function setChannelModel(team, input) {
1137
+ const channel = findChannel(team, typeof input.channel === "string" ? input.channel : "");
1138
+ if (!channel) {
1139
+ throw new Error(`No channel is ${String(input.channel)}.`);
1140
+ }
1141
+ let next = team;
1142
+ for (const id of channel.members) {
1143
+ next = updateAgent(next, { agent: id, model: input.model }).team;
1144
+ }
1145
+ const agents = next.agents.filter((agent) => channel.members.includes(agent.id));
1146
+ return { team: next, channel, agents };
1147
+ }
1148
+ ChannelsUtil.setChannelModel = setChannelModel;
1054
1149
  function removeAgent(team, ref) {
1055
1150
  const agent = findAgent(team, typeof ref === "string" ? ref : "");
1056
1151
  if (!agent) {
@@ -1274,7 +1369,40 @@ var JA = {
1274
1369
  answering: "{name} が回答中",
1275
1370
  failed: "回答がありません",
1276
1371
  mention: "@{name}",
1277
- stopped: "ラウンドの制限に達しました;あなたの番です。",
1372
+ stopped: "議論を一時停止しました。あなたの判断を待っています",
1373
+ stoppedStats: "返信 {replies} 件 · 約 {tokens} トークン",
1374
+ stoppedReplies: "返信 {replies} 件",
1375
+ keepGoing: "続ける",
1376
+ wrapUp: "{name} にまとめてもらう",
1377
+ wentOn: "続行済み",
1378
+ summedUp: "まとめ依頼済み",
1379
+ dailyChannel: "このグループの今日の上限に達しました。エージェントはあなたにだけ答えます",
1380
+ dailyAll: "すべてのグループの今日の上限に達し、一時停止しました",
1381
+ overBudget: "1回の回答の上限を超えたため停止",
1382
+ limitsTitle: "グループチャットの使用量",
1383
+ limitAnswer: "1回の回答",
1384
+ limitAnswerHint: "超えるとその場で回答を止めます",
1385
+ limitChannelDay: "1グループ1日あたり",
1386
+ limitChannelDayHint: "超えるとその日はあなたにだけ答えます",
1387
+ limitAllDay: "全グループ1日あたり",
1388
+ limitAllDayHint: "超えると全て一時停止して通知します",
1389
+ limitSpent: "今日の使用量",
1390
+ noLimit: "無制限",
1391
+ talkLength: "議論の長さ",
1392
+ budgetShortWord: "短い",
1393
+ budgetNormalWord: "標準",
1394
+ budgetLongWord: "長い",
1395
+ dailyLimit: "1日の上限",
1396
+ dailySpent: "今日 {spent}",
1397
+ dailySpentOf: "今日 {spent} / {limit}",
1398
+ limitDefault: "既定",
1399
+ idleRepeat: "同じ内容を繰り返していたため一時停止しました",
1400
+ idleAgree: "同意だけが続いたため一時停止しました",
1401
+ idlePingPong: "二人の往復に進展がないため一時停止しました",
1402
+ extendedOnce: "進展があったため一度延長済み",
1403
+ budgetShort: "短い議論 · 約 {n} 件",
1404
+ budgetNormal: "標準の議論 · 約 {n} 件",
1405
+ budgetLong: "長い議論 · 約 {n} 件",
1278
1406
  search: "検索",
1279
1407
  clear: "クリア",
1280
1408
  new: "新規",
@@ -1310,7 +1438,17 @@ var JA = {
1310
1438
  channelNamePlaceholder: "例:Project Falcon",
1311
1439
  addAgents: "エージェントを追加",
1312
1440
  searchAgents: "エージェントを検索、1 ~ {max} 件を選択",
1313
- showMembers: "メンバー",
1441
+ showMembers: "グループチャット情報",
1442
+ channelName: "グループ名",
1443
+ notSet: "未設定",
1444
+ pinChat: "チャットを固定",
1445
+ sameModel: "モデルを統一",
1446
+ sameModelHint: "ここのエージェントすべてが選んだモデルで答えます",
1447
+ mixedModels: "それぞれ",
1448
+ modelSwitched: "{count} 人のメンバーが選んだモデルに切り替わりました",
1449
+ agentSettings: "クイック設定",
1450
+ model: "モデル",
1451
+ agentSettingsHint: "モデルはすぐに、役割は次のセッションから反映されます。",
1314
1452
  canAdd: "{count} 個のエージェントを追加できます",
1315
1453
  findAgent: "エージェントを検索",
1316
1454
  addCount: "{count} 人を追加",
@@ -1473,7 +1611,40 @@ var ZH = {
1473
1611
  answering: "{name} 正在回答",
1474
1612
  failed: "没有回答",
1475
1613
  mention: "@{name}",
1476
- stopped: "已到交接上限,等你继续。",
1614
+ stopped: "讨论暂停,等你决定",
1615
+ stoppedStats: "{replies} 条回复 · 约 {tokens} tokens",
1616
+ stoppedReplies: "{replies} 条回复",
1617
+ keepGoing: "继续讨论",
1618
+ wrapUp: "请 {name} 总结",
1619
+ wentOn: "已继续",
1620
+ summedUp: "已请总结",
1621
+ dailyChannel: "这个群今天的用量到了上限,智能体只回答你",
1622
+ dailyAll: "所有群今天的用量到了上限,已全部暂停",
1623
+ overBudget: "超出单条回复上限,已停下",
1624
+ limitsTitle: "群聊用量",
1625
+ limitAnswer: "单条回复",
1626
+ limitAnswerHint: "超过就在原处停下这条回复",
1627
+ limitChannelDay: "每个群每天",
1628
+ limitChannelDayHint: "超过后当天这个群的智能体只回答你",
1629
+ limitAllDay: "所有群每天",
1630
+ limitAllDayHint: "超过后全部暂停并通知你",
1631
+ limitSpent: "今天已用",
1632
+ noLimit: "不限",
1633
+ talkLength: "讨论长度",
1634
+ budgetShortWord: "简短",
1635
+ budgetNormalWord: "标准",
1636
+ budgetLongWord: "深入",
1637
+ dailyLimit: "每天上限",
1638
+ dailySpent: "今天 {spent}",
1639
+ dailySpentOf: "今天 {spent} / {limit}",
1640
+ limitDefault: "默认",
1641
+ idleRepeat: "智能体在重复说过的话,先停下",
1642
+ idleAgree: "智能体只在附和,先停下",
1643
+ idlePingPong: "两人来回没有进展,先停下",
1644
+ extendedOnce: "有进展已自动续过一次",
1645
+ budgetShort: "简短讨论 · 约 {n} 条",
1646
+ budgetNormal: "标准讨论 · 约 {n} 条",
1647
+ budgetLong: "深入讨论 · 约 {n} 条",
1477
1648
  search: "搜索",
1478
1649
  clear: "清除",
1479
1650
  new: "新建",
@@ -1509,7 +1680,17 @@ var ZH = {
1509
1680
  channelNamePlaceholder: "例如:官网改版",
1510
1681
  addAgents: "添加智能体",
1511
1682
  searchAgents: "搜索智能体,选择 1–{max} 个",
1512
- showMembers: "群聊成员",
1683
+ showMembers: "群聊信息",
1684
+ channelName: "群聊名称",
1685
+ notSet: "未设置",
1686
+ pinChat: "置顶聊天",
1687
+ sameModel: "统一模型",
1688
+ sameModelHint: "群里的智能体都改用你选的模型",
1689
+ mixedModels: "各用各的",
1690
+ modelSwitched: "{count} 位成员已改用所选模型",
1691
+ agentSettings: "快捷设置",
1692
+ model: "模型",
1693
+ agentSettingsHint: "模型立即生效;职责从下一个会话起生效。",
1513
1694
  canAdd: "还能添加 {count} 个智能体",
1514
1695
  findAgent: "搜索智能体",
1515
1696
  addCount: "添加 {count} 位",
@@ -1672,7 +1853,40 @@ var ZH_TW = {
1672
1853
  answering: "{name} 正在回答",
1673
1854
  failed: "沒有回答",
1674
1855
  mention: "@{name}",
1675
- stopped: "已到交接上限,等你繼續。",
1856
+ stopped: "討論暫停,等你決定",
1857
+ stoppedStats: "{replies} 則回覆 · 約 {tokens} tokens",
1858
+ stoppedReplies: "{replies} 則回覆",
1859
+ keepGoing: "繼續討論",
1860
+ wrapUp: "請 {name} 總結",
1861
+ wentOn: "已繼續",
1862
+ summedUp: "已請總結",
1863
+ dailyChannel: "這個群今天的用量到了上限,智能體只回答你",
1864
+ dailyAll: "所有群今天的用量到了上限,已全部暫停",
1865
+ overBudget: "超出單則回覆上限,已停下",
1866
+ limitsTitle: "群聊用量",
1867
+ limitAnswer: "單則回覆",
1868
+ limitAnswerHint: "超過就在原處停下這則回覆",
1869
+ limitChannelDay: "每個群每天",
1870
+ limitChannelDayHint: "超過後當天這個群的智能體只回答你",
1871
+ limitAllDay: "所有群每天",
1872
+ limitAllDayHint: "超過後全部暫停並通知你",
1873
+ limitSpent: "今天已用",
1874
+ noLimit: "不限",
1875
+ talkLength: "討論長度",
1876
+ budgetShortWord: "簡短",
1877
+ budgetNormalWord: "標準",
1878
+ budgetLongWord: "深入",
1879
+ dailyLimit: "每天上限",
1880
+ dailySpent: "今天 {spent}",
1881
+ dailySpentOf: "今天 {spent} / {limit}",
1882
+ limitDefault: "預設",
1883
+ idleRepeat: "智能體在重複說過的話,先停下",
1884
+ idleAgree: "智能體只在附和,先停下",
1885
+ idlePingPong: "兩人來回沒有進展,先停下",
1886
+ extendedOnce: "有進展已自動續過一次",
1887
+ budgetShort: "簡短討論 · 約 {n} 則",
1888
+ budgetNormal: "標準討論 · 約 {n} 則",
1889
+ budgetLong: "深入討論 · 約 {n} 則",
1676
1890
  search: "搜尋",
1677
1891
  clear: "清除",
1678
1892
  new: "新建",
@@ -1708,7 +1922,17 @@ var ZH_TW = {
1708
1922
  channelNamePlaceholder: "例如:官網改版",
1709
1923
  addAgents: "新增智慧體",
1710
1924
  searchAgents: "搜尋智慧體,選擇 1–{max} 個",
1711
- showMembers: "群聊成員",
1925
+ showMembers: "群聊資訊",
1926
+ channelName: "群聊名稱",
1927
+ notSet: "未設定",
1928
+ pinChat: "置頂聊天",
1929
+ sameModel: "統一模型",
1930
+ sameModelHint: "群裡的智慧體都改用你選的模型",
1931
+ mixedModels: "各用各的",
1932
+ modelSwitched: "{count} 位成員已改用所選模型",
1933
+ agentSettings: "快捷設定",
1934
+ model: "模型",
1935
+ agentSettingsHint: "模型立即生效;職責從下一個會話起生效。",
1712
1936
  canAdd: "還能新增 {count} 個智慧體",
1713
1937
  findAgent: "搜尋智慧體",
1714
1938
  addCount: "新增 {count} 位",
@@ -1871,7 +2095,40 @@ var EN = {
1871
2095
  answering: "{name} is answering",
1872
2096
  failed: "did not answer",
1873
2097
  mention: "Mention {name}",
1874
- stopped: "The agents stopped at the limit of a round; it is your turn.",
2098
+ stopped: "The agents paused to wait for you",
2099
+ stoppedStats: "{replies} replies · about {tokens} tokens",
2100
+ stoppedReplies: "{replies} replies",
2101
+ keepGoing: "Go on",
2102
+ wrapUp: "Have {name} sum up",
2103
+ wentOn: "went on",
2104
+ summedUp: "summed up",
2105
+ dailyChannel: "This group chat reached its limit of the day; the agents only answer you",
2106
+ dailyAll: "All group chats reached the limit of the day; paused",
2107
+ overBudget: "stopped past the limit of one answer",
2108
+ limitsTitle: "Group chats",
2109
+ limitAnswer: "One answer",
2110
+ limitAnswerHint: "An answer spending more is stopped where it is",
2111
+ limitChannelDay: "One group chat a day",
2112
+ limitChannelDayHint: "Past it, its agents only answer you that day",
2113
+ limitAllDay: "All group chats a day",
2114
+ limitAllDayHint: "Past it, all pause and you are told",
2115
+ limitSpent: "Spent today",
2116
+ noLimit: "No limit",
2117
+ talkLength: "Length of talks",
2118
+ budgetShortWord: "Short",
2119
+ budgetNormalWord: "Normal",
2120
+ budgetLongWord: "Long",
2121
+ dailyLimit: "A day",
2122
+ dailySpent: "today {spent}",
2123
+ dailySpentOf: "today {spent} / {limit}",
2124
+ limitDefault: "Default",
2125
+ idleRepeat: "The agents were saying the same again; paused",
2126
+ idleAgree: "The agents only agreed; paused",
2127
+ idlePingPong: "Two agents went back and forth with nothing done; paused",
2128
+ extendedOnce: "went on once for the work done",
2129
+ budgetShort: "Short talks · about {n} replies",
2130
+ budgetNormal: "Normal talks · about {n} replies",
2131
+ budgetLong: "Long talks · about {n} replies",
1875
2132
  search: "Search",
1876
2133
  clear: "Clear",
1877
2134
  new: "New",
@@ -1907,7 +2164,17 @@ var EN = {
1907
2164
  channelNamePlaceholder: "For example: Project Falcon",
1908
2165
  addAgents: "Add agents",
1909
2166
  searchAgents: "Search agents, pick 1 to {max}",
1910
- showMembers: "Members",
2167
+ showMembers: "About the group chat",
2168
+ channelName: "Group name",
2169
+ notSet: "Not set",
2170
+ pinChat: "Pin the chat",
2171
+ sameModel: "Model for all",
2172
+ sameModelHint: "Every agent here answers with the model you pick",
2173
+ mixedModels: "Each its own",
2174
+ modelSwitched: "The {count} members answer with the model picked now.",
2175
+ agentSettings: "Quick settings",
2176
+ model: "Model",
2177
+ agentSettingsHint: "The model takes effect at once; the role from its next session.",
1911
2178
  canAdd: "{count} agents can join",
1912
2179
  findAgent: "Search agents",
1913
2180
  addCount: "Add {count}",
@@ -2047,6 +2314,7 @@ var ChannelWords;
2047
2314
  var DOUBLE_PAGE = "assistant/assistant";
2048
2315
  var CHANNEL_PAGE = `${NAME}/channel`;
2049
2316
  var MEMBERS_VIEW = `${NAME}/members`;
2317
+ var ROOM_INFO_VIEW = "@celljs/ta-rooms/members";
2050
2318
  var CHANNEL_KEY = "ta-channels.channel";
2051
2319
 
2052
2320
  class ChannelsUiStore {
@@ -2643,6 +2911,11 @@ class ChannelsClient {
2643
2911
  await this.load(true);
2644
2912
  return agent;
2645
2913
  }
2914
+ async setChannelModel(channelId, model) {
2915
+ const channel = await this.send({ kind: "setChannelModel", channel: channelId, model });
2916
+ await this.load(true);
2917
+ return channel;
2918
+ }
2646
2919
  async deleteAgent(agentId) {
2647
2920
  await this.deleting(agentId, async () => {
2648
2921
  await this.send({ kind: "deleteAgent", agent: agentId });
@@ -2683,6 +2956,15 @@ class ChannelsClient {
2683
2956
  async post(channelId, text) {
2684
2957
  await this.send({ kind: "post", channel: channelId, text });
2685
2958
  }
2959
+ async resumeRound(channelId, messageId, how) {
2960
+ await this.send({ kind: "resumeRound", channel: channelId, message: messageId, how });
2961
+ }
2962
+ async setLimits(limits) {
2963
+ await this.send({ kind: "setLimits", limits });
2964
+ }
2965
+ async watch(channelId) {
2966
+ await this.send({ kind: "watch", channel: channelId });
2967
+ }
2686
2968
  async changed(keys) {
2687
2969
  const reads = [];
2688
2970
  for (const key of keys) {
@@ -3365,415 +3647,193 @@ var HandOffView;
3365
3647
  HandOffView.composerAddon = composerAddon;
3366
3648
  })(HandOffView ||= {});
3367
3649
 
3368
- // web-src/members.tsx
3369
- function MembersView({ context }) {
3370
- const { pi, service, ui } = context;
3371
- const state = useChannels(service);
3372
- const { channelId, adding } = useUi(ui);
3373
- const faces = useFaces(state.team);
3374
- const w = ChannelViews.words(pi);
3375
- const channel = state.team.channels.find((candidate) => candidate.id === channelId);
3376
- if (!channel) {
3377
- return /* @__PURE__ */ React.createElement("div", {
3378
- className: "tac-view tac-members"
3379
- }, state.loaded && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
3380
- title: w.noChannel
3381
- }));
3650
+ // web-src/round-rules.ts
3651
+ var ChannelRounds;
3652
+ ((ChannelRounds) => {
3653
+ const SHORT = 20;
3654
+ const MIN_PAIRS = 8;
3655
+ const ALIKE = 0.8;
3656
+ const PING_PONG = 4;
3657
+ const NEW = 0.35;
3658
+ const CHANGES = new Set(["edit", "write", "delete", "move"]);
3659
+ function scale(watchedAt, pages, now) {
3660
+ if (watchedAt !== undefined && now - watchedAt < 2 * WATCH_MS) {
3661
+ return 2;
3662
+ }
3663
+ return pages === undefined || pages > 0 ? 1 : 0.5;
3664
+ }
3665
+ ChannelRounds.scale = scale;
3666
+ function idle(said, progress) {
3667
+ const last = said.at(-1);
3668
+ if (!last) {
3669
+ return;
3670
+ }
3671
+ const pairs = said.map((item) => pairsOf(item.text));
3672
+ const mine = pairs[pairs.length - 1];
3673
+ if (mine.length >= MIN_PAIRS && pairs.slice(0, -1).some((other) => alike(other, mine) >= ALIKE)) {
3674
+ return "repeat";
3675
+ }
3676
+ const recent = said.slice(-3);
3677
+ if (recent.length === 3 && recent.every((item) => units(item.text).join("").length < SHORT)) {
3678
+ return "agree";
3679
+ }
3680
+ const run = said.slice(-PING_PONG);
3681
+ const authors = new Set(run.map((item) => item.author));
3682
+ const alternate = run.every((item, i) => i === 0 || item.author !== run[i - 1].author);
3683
+ const start = said.length - PING_PONG;
3684
+ if (progress || start <= 0 || authors.size !== 2 || !alternate) {
3685
+ return;
3686
+ }
3687
+ const seen = new Set(pairs.slice(0, start).flat());
3688
+ for (const own of pairs.slice(start)) {
3689
+ const fresh = own.filter((pair) => !seen.has(pair)).length;
3690
+ if (own.length === 0 || fresh / own.length >= NEW) {
3691
+ return;
3692
+ }
3693
+ for (const pair of own) {
3694
+ seen.add(pair);
3695
+ }
3696
+ }
3697
+ return "pingPong";
3382
3698
  }
3383
- return adding ? /* @__PURE__ */ React.createElement(MemberPicker, {
3384
- key: channel.id,
3385
- context,
3386
- team: state.team,
3387
- channel,
3388
- faces
3389
- }) : /* @__PURE__ */ React.createElement(MemberList, {
3390
- key: channel.id,
3391
- context,
3392
- team: state.team,
3393
- channel,
3394
- faces,
3395
- working: state.working[channel.id] ?? []
3396
- });
3699
+ ChannelRounds.idle = idle;
3700
+ function day(now) {
3701
+ const date = new Date(now);
3702
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
3703
+ }
3704
+ ChannelRounds.day = day;
3705
+ function limits(stored) {
3706
+ const given = stored ?? {};
3707
+ const pick = (key) => LIMIT_CHOICES[key].includes(given[key]) ? given[key] : DEFAULT_LIMITS[key];
3708
+ return { answer: pick("answer"), channelDay: pick("channelDay"), allDay: pick("allDay") };
3709
+ }
3710
+ ChannelRounds.limits = limits;
3711
+ function today(stored, now) {
3712
+ const current = day(now);
3713
+ return stored?.day === current ? stored : { day: current, total: 0, channels: {} };
3714
+ }
3715
+ ChannelRounds.today = today;
3716
+ function spend(stored, channelId, tokens, now) {
3717
+ const current = today(stored, now);
3718
+ return { ...current, total: current.total + tokens, channels: { ...current.channels, [channelId]: (current.channels[channelId] ?? 0) + tokens } };
3719
+ }
3720
+ ChannelRounds.spend = spend;
3721
+ function held(spent, limits2, channelId, hops, granted = false) {
3722
+ if (granted) {
3723
+ return;
3724
+ }
3725
+ if (limits2.allDay > 0 && spent.total >= limits2.allDay) {
3726
+ return "all";
3727
+ }
3728
+ if (hops > 0 && limits2.channelDay > 0 && (spent.channels[channelId] ?? 0) >= limits2.channelDay) {
3729
+ return "channel";
3730
+ }
3731
+ return;
3732
+ }
3733
+ ChannelRounds.held = held;
3734
+ function changedFiles(entries) {
3735
+ for (const entry of entries) {
3736
+ const message = entry?.message;
3737
+ if (entry?.type !== "message" || message?.role !== "assistant" || !Array.isArray(message.content)) {
3738
+ continue;
3739
+ }
3740
+ for (const part of message.content) {
3741
+ if (part?.type !== "toolCall") {
3742
+ continue;
3743
+ }
3744
+ if (CHANGES.has(String(part.name)) || part.name === "agent_tool" && CHANGES.has(String(part.arguments?.kind))) {
3745
+ return true;
3746
+ }
3747
+ }
3748
+ }
3749
+ return false;
3750
+ }
3751
+ ChannelRounds.changedFiles = changedFiles;
3752
+ function units(text) {
3753
+ return text.replace(/@[^\s@#,,。::]+/g, " ").toLowerCase().match(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]|[\p{L}\p{N}]+/gu) ?? [];
3754
+ }
3755
+ function pairsOf(text) {
3756
+ const words = units(text);
3757
+ return words.length === 1 ? words : words.slice(1).map((word, i) => `${words[i]} ${word}`);
3758
+ }
3759
+ function alike(a, b) {
3760
+ if (a.length === 0 || b.length === 0) {
3761
+ return 0;
3762
+ }
3763
+ const left = new Map;
3764
+ for (const pair of a) {
3765
+ left.set(pair, (left.get(pair) ?? 0) + 1);
3766
+ }
3767
+ let common = 0;
3768
+ for (const pair of b) {
3769
+ const n = left.get(pair) ?? 0;
3770
+ if (n > 0) {
3771
+ left.set(pair, n - 1);
3772
+ common++;
3773
+ }
3774
+ }
3775
+ return 2 * common / (a.length + b.length);
3776
+ }
3777
+ })(ChannelRounds ||= {});
3778
+
3779
+ // web-src/limit-settings.tsx
3780
+ function amount(pi, tokens) {
3781
+ return tokens > 0 ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(tokens) : ChannelWords.of(pi.ui.language).noLimit;
3397
3782
  }
3398
- function MemberList({ context, team, channel, faces, working }) {
3399
- const { pi, service, ui } = context;
3400
- const w = ChannelViews.words(pi);
3401
- const [busy, setBusy] = React.useState();
3402
- const [confirming, setConfirming] = React.useState(false);
3403
- const UserPlus = ChannelViews.icon(pi, "UserPlus");
3404
- const Contact = ChannelViews.icon(pi, "Contact");
3405
- const Crown = ChannelViews.icon(pi, "Crown");
3406
- const BellOff = ChannelViews.icon(pi, "BellOff");
3407
- const RotateCcw = ChannelViews.icon(pi, "RotateCcw");
3408
- const X = ChannelViews.icon(pi, "X");
3409
- const Trash = ChannelViews.icon(pi, "Trash2");
3410
- const members = membersOf(team, channel);
3411
- const muted = channel.muted ?? [];
3412
- const run = (key, action) => {
3413
- setBusy(key);
3414
- action().catch((error) => pi.ui.notify(ChannelViews.message(error), "error")).finally(() => setBusy(undefined));
3415
- };
3416
- const change = (agent, kind) => run(`${kind}:${agent.id}`, () => service.changeMember(channel.id, agent.id, kind));
3417
- const reset = (agent) => run(`reset:${agent.id}`, async () => {
3418
- await service.resetAgent(agent.id);
3419
- context.sessions.delete(agent.id);
3420
- pi.ui.notify(ChannelWords.format(w.resetDone, { name: agent.name }), "info");
3421
- });
3422
- const remove = () => run("delete", () => service.deleteChannel(channel.id));
3423
- return /* @__PURE__ */ React.createElement("div", {
3424
- className: "tac-view tac-members"
3425
- }, /* @__PURE__ */ React.createElement("div", {
3426
- className: "tac-members-scroll"
3427
- }, /* @__PURE__ */ React.createElement("div", {
3428
- className: "tac-members-top"
3429
- }, /* @__PURE__ */ React.createElement(RoomFace, {
3430
- members,
3431
- faces,
3432
- size: 44,
3433
- working
3434
- }), /* @__PURE__ */ React.createElement("span", {
3435
- className: "tac-members-title"
3436
- }, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", null, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(members.length) })))), /* @__PURE__ */ React.createElement("div", {
3437
- className: "tac-members-label"
3438
- }, w.members, " · ", members.length), /* @__PURE__ */ React.createElement("button", {
3439
- type: "button",
3440
- className: "tac-member-main",
3441
- onClick: () => ui.set({ adding: true })
3442
- }, /* @__PURE__ */ React.createElement("span", {
3443
- className: "tac-member-plus"
3444
- }, /* @__PURE__ */ React.createElement(UserPlus, {
3445
- size: 16
3446
- })), /* @__PURE__ */ React.createElement("span", {
3447
- className: "tac-member-text"
3448
- }, /* @__PURE__ */ React.createElement("span", {
3449
- className: "tac-member-name"
3450
- }, w.addMembers))), pi.rooms && channel.by !== "ta" && /* @__PURE__ */ React.createElement("button", {
3451
- type: "button",
3452
- className: "tac-member-main",
3453
- onClick: () => openShareGroup(context, channel)
3454
- }, /* @__PURE__ */ React.createElement("span", {
3455
- className: "tac-member-plus"
3456
- }, /* @__PURE__ */ React.createElement(Contact, {
3457
- size: 16
3458
- })), /* @__PURE__ */ React.createElement("span", {
3459
- className: "tac-member-text"
3460
- }, /* @__PURE__ */ React.createElement("span", {
3461
- className: "tac-member-name"
3462
- }, w.inviteFriends))), members.map((agent, index) => {
3463
- const lead = index === 0;
3464
- const off = muted.includes(agent.id);
3465
- const answering = working.includes(agent.id);
3466
- const detail = answering ? w.replying : off ? w.muted : agent.role.split(`
3467
- `)[0] ?? "";
3468
- return /* @__PURE__ */ React.createElement("div", {
3469
- key: agent.id,
3470
- className: `tac-member${off ? " tac-muted" : ""}`
3471
- }, /* @__PURE__ */ React.createElement("button", {
3472
- type: "button",
3473
- className: "tac-member-main",
3474
- title: `${w.open}
3475
- ${agent.role}`,
3476
- onClick: () => ChannelViews.openAgent(context, agent.id).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"))
3477
- }, /* @__PURE__ */ React.createElement(AgentAvatar, {
3478
- agent,
3479
- faces,
3480
- size: 32,
3481
- working: answering
3482
- }), /* @__PURE__ */ React.createElement("span", {
3483
- className: "tac-member-text"
3484
- }, /* @__PURE__ */ React.createElement("span", {
3485
- className: "tac-member-name"
3486
- }, /* @__PURE__ */ React.createElement("span", {
3487
- className: "tac-member-label"
3488
- }, agent.name), lead && /* @__PURE__ */ React.createElement("span", {
3489
- className: "tac-lead",
3490
- title: w.leadHint
3491
- }, /* @__PURE__ */ React.createElement(Crown, {
3492
- size: 11
3493
- }), /* @__PURE__ */ React.createElement("span", null, w.lead)), agent.temporary && /* @__PURE__ */ React.createElement("span", {
3494
- className: "tac-temporary",
3495
- title: w.temporary
3496
- }, w.temporaryTag)), /* @__PURE__ */ React.createElement("span", {
3497
- className: `tac-member-detail${answering ? " tac-live" : ""}`
3498
- }, detail))), /* @__PURE__ */ React.createElement("span", {
3499
- className: "tac-member-actions"
3500
- }, agent.temporary && /* @__PURE__ */ React.createElement("button", {
3501
- type: "button",
3502
- className: "tac-action",
3503
- title: w.keep,
3504
- "aria-label": w.keep,
3505
- disabled: !!busy,
3506
- onClick: () => service.updateAgent(agent.id, { keep: true }).then(() => pi.ui.notify(ChannelWords.format(w.kept, { name: agent.name }), "info")).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"))
3507
- }, /* @__PURE__ */ React.createElement(UserPlus, {
3508
- size: 15
3509
- })), !lead && /* @__PURE__ */ React.createElement("button", {
3510
- type: "button",
3511
- className: "tac-action",
3512
- title: w.makeLead,
3513
- "aria-label": w.makeLead,
3514
- disabled: !!busy,
3515
- onClick: () => change(agent, "lead")
3516
- }, /* @__PURE__ */ React.createElement(Crown, {
3517
- size: 15
3518
- })), /* @__PURE__ */ React.createElement("button", {
3519
- type: "button",
3520
- className: `tac-action${off ? " tac-on" : ""}`,
3521
- title: off ? w.unmute : w.mute,
3522
- "aria-label": off ? w.unmute : w.mute,
3523
- "aria-pressed": off,
3524
- disabled: !!busy,
3525
- onClick: () => change(agent, off ? "unmute" : "mute")
3526
- }, /* @__PURE__ */ React.createElement(BellOff, {
3527
- size: 15
3528
- })), /* @__PURE__ */ React.createElement("button", {
3529
- type: "button",
3530
- className: "tac-action",
3531
- title: w.reset,
3532
- "aria-label": w.reset,
3533
- disabled: !!busy,
3534
- onClick: () => reset(agent)
3535
- }, /* @__PURE__ */ React.createElement(RotateCcw, {
3536
- size: 15
3537
- })), /* @__PURE__ */ React.createElement("button", {
3783
+ function useLimits(pi) {
3784
+ const read = React.useCallback(async () => ({
3785
+ limits: ChannelRounds.limits(await pi.storage.get(Keys.LIMITS)),
3786
+ ...((today) => ({ spent: today.total, channels: today.channels }))(ChannelRounds.today(await pi.storage.get(Keys.SPENT), Date.now()))
3787
+ }), [pi]);
3788
+ const [value, setValue] = React.useState({ limits: ChannelRounds.limits(undefined), spent: 0, channels: {} });
3789
+ React.useEffect(() => {
3790
+ let live = true;
3791
+ const load = () => void read().then((next) => live && setValue(next), () => {
3792
+ return;
3793
+ });
3794
+ load();
3795
+ const stop = pi.storage.onChange((keys) => (keys.includes(Keys.LIMITS) || keys.includes(Keys.SPENT)) && load());
3796
+ return () => {
3797
+ live = false;
3798
+ stop();
3799
+ };
3800
+ }, [pi, read]);
3801
+ return value;
3802
+ }
3803
+ function limitSettings(pi, service) {
3804
+ const words = () => ChannelWords.of(pi.ui.language);
3805
+ const row = (key) => function Choices() {
3806
+ const { limits } = useLimits(pi);
3807
+ const pick = (value) => void service.setLimits({ [key]: value }).catch((error) => pi.ui.notify(String(error?.message ?? error), "error"));
3808
+ return /* @__PURE__ */ React.createElement("fieldset", {
3809
+ className: "ta-segmented",
3810
+ "aria-label": words()[key === "answer" ? "limitAnswer" : key === "channelDay" ? "limitChannelDay" : "limitAllDay"]
3811
+ }, LIMIT_CHOICES[key].map((value) => /* @__PURE__ */ React.createElement("button", {
3812
+ key: value,
3538
3813
  type: "button",
3539
- className: "tac-action",
3540
- title: members.length === 1 ? w.onlyMember : w.remove,
3541
- "aria-label": w.remove,
3542
- disabled: !!busy || members.length === 1,
3543
- onClick: () => change(agent, "remove")
3544
- }, /* @__PURE__ */ React.createElement(X, {
3545
- size: 15
3546
- }))));
3547
- })), /* @__PURE__ */ React.createElement("div", {
3548
- className: "tac-members-foot"
3549
- }, confirming ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
3550
- className: "tac-members-ask"
3551
- }, ChannelWords.format(w.confirmDelete, { channel: channel.name })), /* @__PURE__ */ React.createElement("button", {
3552
- type: "button",
3553
- className: "tac-button",
3554
- onClick: () => setConfirming(false)
3555
- }, w.cancel), /* @__PURE__ */ React.createElement("button", {
3556
- type: "button",
3557
- className: busy === "delete" ? "tac-button tac-danger ta-busy" : "tac-button tac-danger",
3558
- disabled: !!busy,
3559
- onClick: remove
3560
- }, w.delete, busy === "delete" && /* @__PURE__ */ React.createElement("span", {
3561
- className: "ta-spinner ta-busy-mark"
3562
- }))) : /* @__PURE__ */ React.createElement("button", {
3563
- type: "button",
3564
- className: "tac-link tac-danger",
3565
- onClick: () => setConfirming(true)
3566
- }, /* @__PURE__ */ React.createElement(Trash, {
3567
- size: 14
3568
- }), w.deleteChannel)));
3569
- }
3570
- function MemberPicker({ context, team, channel, faces }) {
3571
- const { pi, service, ui } = context;
3572
- const w = ChannelViews.words(pi);
3573
- const [query, setQuery] = React.useState("");
3574
- const [picked, setPicked] = React.useState([]);
3575
- const ArrowLeft = ChannelViews.icon(pi, "ArrowLeft");
3576
- const Search = ChannelViews.icon(pi, "Search");
3577
- const Check = ChannelViews.icon(pi, "Check");
3578
- const UserPlus = ChannelViews.icon(pi, "UserPlus");
3579
- const back = () => ui.set({ adding: false });
3580
- const { busy, error, submit } = useSubmit(() => service.addMembers(channel.id, picked), back);
3581
- const others = team.agents.filter((agent) => !channel.members.includes(agent.id));
3582
- const shown = others.filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
3583
- const toggle = (id) => setPicked(picked.includes(id) ? picked.filter((other) => other !== id) : [...picked, id]);
3584
- return /* @__PURE__ */ React.createElement("div", {
3585
- className: "tac-view tac-members"
3586
- }, /* @__PURE__ */ React.createElement("div", {
3587
- className: "tac-members-head"
3588
- }, /* @__PURE__ */ React.createElement("button", {
3589
- type: "button",
3590
- className: "tac-action",
3591
- title: w.back,
3592
- "aria-label": w.back,
3593
- onClick: back
3594
- }, /* @__PURE__ */ React.createElement(ArrowLeft, {
3595
- size: 16
3596
- })), /* @__PURE__ */ React.createElement("strong", null, w.addMembers)), /* @__PURE__ */ React.createElement("label", {
3597
- className: "tac-search tac-members-search"
3598
- }, /* @__PURE__ */ React.createElement(Search, {
3599
- size: 14
3600
- }), /* @__PURE__ */ React.createElement("input", {
3601
- value: query,
3602
- placeholder: w.findAgent,
3603
- "aria-label": w.findAgent,
3604
- onChange: (event) => setQuery(event.target.value)
3605
- })), /* @__PURE__ */ React.createElement("div", {
3606
- className: "tac-members-scroll"
3607
- }, /* @__PURE__ */ React.createElement("div", {
3608
- className: "tac-members-label"
3609
- }, ChannelWords.format(w.canAdd, { count: String(others.length) })), others.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
3610
- compact: true,
3611
- title: w.allMembers
3612
- }), others.length > 0 && shown.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
3613
- compact: true,
3614
- title: w.noMatch
3615
- }), shown.map((agent) => {
3616
- const on = picked.includes(agent.id);
3617
- return /* @__PURE__ */ React.createElement("button", {
3618
- key: agent.id,
3619
- type: "button",
3620
- className: `tac-member-main tac-pick${on ? " tac-on" : ""}`,
3621
- "aria-pressed": on,
3622
- title: agent.role,
3623
- onClick: () => toggle(agent.id)
3624
- }, /* @__PURE__ */ React.createElement(AgentAvatar, {
3625
- agent,
3626
- faces,
3627
- size: 32
3628
- }), /* @__PURE__ */ React.createElement("span", {
3629
- className: "tac-member-text"
3630
- }, /* @__PURE__ */ React.createElement("span", {
3631
- className: "tac-member-name"
3632
- }, /* @__PURE__ */ React.createElement("span", {
3633
- className: "tac-member-label"
3634
- }, agent.name)), /* @__PURE__ */ React.createElement("span", {
3635
- className: "tac-member-detail"
3636
- }, agent.role.split(`
3637
- `)[0])), /* @__PURE__ */ React.createElement("span", {
3638
- className: "tac-check"
3639
- }, on && /* @__PURE__ */ React.createElement(Check, {
3640
- size: 12,
3641
- strokeWidth: 3
3642
- })));
3643
- }), /* @__PURE__ */ React.createElement("div", {
3644
- className: "tac-members-sep"
3645
- }), /* @__PURE__ */ React.createElement("button", {
3646
- type: "button",
3647
- className: "tac-member-main",
3648
- onClick: () => newAgent(context)
3649
- }, /* @__PURE__ */ React.createElement("span", {
3650
- className: "tac-member-plus"
3651
- }, /* @__PURE__ */ React.createElement(UserPlus, {
3652
- size: 16
3653
- })), /* @__PURE__ */ React.createElement("span", {
3654
- className: "tac-member-text"
3655
- }, /* @__PURE__ */ React.createElement("span", {
3656
- className: "tac-member-name"
3657
- }, w.newAgent)))), error && /* @__PURE__ */ React.createElement("div", {
3658
- className: "tac-empty tac-error"
3659
- }, error), /* @__PURE__ */ React.createElement("div", {
3660
- className: "tac-members-foot"
3661
- }, /* @__PURE__ */ React.createElement("button", {
3662
- type: "button",
3663
- className: busy ? "tac-button tac-primary tac-wide ta-busy" : "tac-button tac-primary tac-wide",
3664
- disabled: busy || picked.length === 0,
3665
- onClick: submit
3666
- }, picked.length > 0 ? ChannelWords.format(w.addCount, { count: String(picked.length) }) : w.add, busy && /* @__PURE__ */ React.createElement("span", {
3667
- className: "ta-spinner ta-busy-mark ta-on-brand"
3668
- }))));
3669
- }
3670
-
3671
- // ../ta-protocol/esm/common/team-protocol.js
3672
- var TA_OWNER = "owner";
3673
- var TA_UNDECLARED = "extensions.install";
3674
- var TaPermissionUtil;
3675
- (function(TaPermissionUtil2) {
3676
- function read(pi) {
3677
- const given = pi === null || pi === undefined ? undefined : pi.permissions;
3678
- const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
3679
- const host2 = map(given === null || given === undefined ? undefined : given.host);
3680
- const tools = map(given === null || given === undefined ? undefined : given.tools);
3681
- return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
3682
- }
3683
- TaPermissionUtil2.read = read;
3684
- function host(manifest, method, kind) {
3685
- var _a, _b, _c, _d;
3686
- const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
3687
- const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
3688
- 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;
3689
- }
3690
- TaPermissionUtil2.host = host;
3691
- })(TaPermissionUtil || (TaPermissionUtil = {}));
3692
- var action = (id, en, zh, tw, ja, more = {}) => ({
3693
- id,
3694
- area: id.split(".")[0],
3695
- title: { en, "zh-CN": zh, ...tw ? { "zh-TW": tw } : {}, ...ja ? { "ja-JP": ja } : {} },
3696
- ...more
3697
- });
3698
- var TA_ACTIONS = [
3699
- action("chat.view", "See conversations", "查看对话", "檢視對話", "会話を確認"),
3700
- action("chat.send", "Send in conversations", "在对话里发消息", "在對話裡發訊息", "会話にメッセージを送信"),
3701
- action("chat.create", "Start conversations", "新建对话", "新建對話", "新しい会話を開始"),
3702
- action("chat.stop", "Stop a reply", "停止回复", "停止回覆", "返信を停止"),
3703
- action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话", "改名、歸檔、關閉對話", "会話の名前変更、アーカイブ、クローズ"),
3704
- action("chat.share", "Share by a link", "生成分享链接", "生成分享連結", "共有リンクで共有"),
3705
- action("agent.view", "See agents", "查看智能体", "檢視智慧體", "エージェントを確認"),
3706
- action("agent.use", "Talk with agents", "和智能体对话", "和智慧體對話", "エージェントと対話"),
3707
- action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体", "新建、修改、刪除智慧體", "エージェントを作成・変更・削除"),
3708
- action("channel.view", "See channels", "查看频道", "檢視頻道", "チャネルを確認"),
3709
- action("channel.post", "Post in channels", "在频道里发言", "在頻道里發言", "チャネルに投稿"),
3710
- action("channel.manage", "Create and change channels", "新建、管理频道", "新建、管理頻道", "チャネルを作成・管理"),
3711
- action("task.view", "See tasks", "查看任务", "檢視任務", "タスクを確認"),
3712
- action("task.create", "Hand out tasks", "派任务", "派任務", "タスクを割り当て"),
3713
- action("task.manage", "Take over and stop tasks", "接管、停止任务", "接管、停止任務", "タスクを引き継ぎ・停止"),
3714
- action("files.read", "Read files", "读文件", "讀檔案", "ファイルを読取", { scoped: true }),
3715
- action("files.write", "Change files", "改文件", "改檔案", "ファイルを変更", { scoped: true }),
3716
- action("commands.run", "Let Ta run commands", "让 Ta 运行命令", "讓 Ta 執行命令", "Ta にコマンド実行を許可", { scoped: true, risky: true }),
3717
- action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
3718
- action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
3719
- action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
3720
- action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更", { grant: "single" }),
3721
- action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
3722
- action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
3723
- action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
3724
- action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
3725
- action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
3726
- action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
3727
- action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
3728
- action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
3729
- action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
3730
- action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
3731
- action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
3732
- ];
3733
- var TA_OWNER_ACTIONS = [
3734
- action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
3735
- action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
3736
- ];
3737
- var OWNER_AREAS = ["desktop"];
3738
- var TaActionUtil;
3739
- (function(TaActionUtil2) {
3740
- const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
3741
- const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
3742
- function info(id) {
3743
- return byId.get(id);
3744
- }
3745
- TaActionUtil2.info = info;
3746
- function title(id, language) {
3747
- var _a;
3748
- var _b, _c;
3749
- const title2 = (_a = titled.get(id)) === null || _a === undefined ? undefined : _a.title;
3750
- if (!title2) {
3751
- return id;
3752
- }
3753
- return TaLanguageUtil.pick(language, {
3754
- "zh-CN": title2["zh-CN"],
3755
- "zh-TW": (_b = title2["zh-TW"]) !== null && _b !== undefined ? _b : title2["zh-CN"],
3756
- "en-US": title2.en,
3757
- "ja-JP": (_c = title2["ja-JP"]) !== null && _c !== undefined ? _c : title2.en
3758
- });
3759
- }
3760
- TaActionUtil2.title = title;
3761
- function grantable(id) {
3762
- const info2 = byId.get(id);
3763
- return !!info2 && !OWNER_AREAS.includes(info2.area);
3764
- }
3765
- TaActionUtil2.grantable = grantable;
3766
- function inRoles(id) {
3767
- var _a;
3768
- return grantable(id) && ((_a = byId.get(id)) === null || _a === undefined ? undefined : _a.grant) !== "single";
3769
- }
3770
- TaActionUtil2.inRoles = inRoles;
3771
- function inside(dir, path) {
3772
- const base = dir.replace(/\/+$/, "");
3773
- return path === base || path.startsWith(`${base}/`) || base === "";
3814
+ "aria-pressed": limits[key] === value,
3815
+ className: limits[key] === value ? "ta-on" : "",
3816
+ onClick: () => pick(value)
3817
+ }, amount(pi, value))));
3818
+ };
3819
+ function Spent() {
3820
+ const { spent } = useLimits(pi);
3821
+ return /* @__PURE__ */ React.createElement("span", {
3822
+ className: "tac-limit-spent"
3823
+ }, spent > 0 ? amount(pi, spent) : "0");
3774
3824
  }
3775
- TaActionUtil2.inside = inside;
3776
- })(TaActionUtil || (TaActionUtil = {}));
3825
+ return {
3826
+ title: () => words().limitsTitle,
3827
+ icon: pi.ui.icons.Coins ?? pi.ui.icons.Gauge,
3828
+ group: "ta",
3829
+ rows: [
3830
+ { key: "answer", label: () => words().limitAnswer, description: () => words().limitAnswerHint, render: row("answer") },
3831
+ { key: "channelDay", label: () => words().limitChannelDay, description: () => words().limitChannelDayHint, render: row("channelDay") },
3832
+ { key: "allDay", label: () => words().limitAllDay, description: () => words().limitAllDayHint, render: row("allDay") },
3833
+ { key: "spent", label: () => words().limitSpent, render: Spent }
3834
+ ]
3835
+ };
3836
+ }
3777
3837
 
3778
3838
  // ../ta-protocol/esm/common/said-protocol.js
3779
3839
  var TaSaid;
@@ -4055,12 +4115,13 @@ var ChannelsText;
4055
4115
  "You work with the user, Ta and other agents in channels. A message for you starts with a <context> block: the channel, its members, the recent messages and who speaks to you; answer what follows the block.",
4056
4116
  "Do the part of the work your role covers with your tools, then answer: your answer is posted to the channel as it is.",
4057
4117
  "To hand work to another member, write @ and their name in your answer; name nobody when the work is done or you need the user.",
4118
+ "Name a member only when you need their part, not to thank them or agree: each answer spends what the user allows the channel before they look in. Once the members agree or the work is done, name nobody; the lead sums up for the user.",
4058
4119
  NOTICE_RULE
4059
4120
  ].join(`
4060
4121
  `);
4061
4122
  }
4062
4123
  ChannelsText.systemPrompt = systemPrompt;
4063
- function prompt(team, channel, history, message, agent) {
4124
+ function prompt(team, channel, history, message, agent, options = {}) {
4064
4125
  const labels = { user: "user", ta: "Ta" };
4065
4126
  const members = channel.members.map((id) => team.agents.find((other) => other.id === id)).filter((other) => !!other).map((other) => `@${other.name}${other.id === agent.id ? " (you)" : ""}: ${firstLine(other.role)}`);
4066
4127
  const before = history.filter((item) => item.id !== message.id && !item.failed && !item.notice).slice(-CONTEXT_MESSAGES);
@@ -4071,6 +4132,9 @@ var ChannelsText;
4071
4132
  if (before.length > 0) {
4072
4133
  lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
4073
4134
  }
4135
+ if (options.closing) {
4136
+ lines.push("", CLOSING_NOTE);
4137
+ }
4074
4138
  lines.push("", `${authorName(team, message.author, labels)} to you:`);
4075
4139
  const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels)}`;
4076
4140
  lines.push(TaMessageSource.line(NAME, `#${channel.name}${speaker}`));
@@ -4135,729 +4199,337 @@ var ChannelsText;
4135
4199
  `)[0];
4136
4200
  }
4137
4201
  })(ChannelsText ||= {});
4202
+ 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.";
4138
4203
  var NOTICE_RULE = [
4139
4204
  "A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
4140
4205
  `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.`
4141
4206
  ].join(`
4142
4207
  `);
4143
4208
 
4144
- // web-src/notice-util.ts
4145
- var NoticeUtil;
4146
- ((NoticeUtil) => {
4147
- const PARTS = {
4148
- 决定: "decisions",
4149
- decisions: "decisions",
4150
- 约定: "conventions",
4151
- conventions: "conventions",
4152
- 待办: "todo",
4153
- "to do": "todo",
4154
- todo: "todo",
4155
- "to-do": "todo"
4156
- };
4157
- function counts(text) {
4158
- const counts2 = { decisions: 0, conventions: 0, todo: 0, done: 0 };
4159
- let part;
4160
- for (const line of text.split(/\r?\n/)) {
4161
- const heading = /^\s*#{1,6}\s+(.+?)\s*#*\s*$/.exec(line) ?? /^\s*\*\*(.+?)\*\*\s*[::]?\s*$/.exec(line);
4162
- if (heading) {
4163
- part = PARTS[heading[1].replace(/[::]$/, "").trim().toLowerCase()];
4164
- continue;
4165
- }
4166
- const item = /^\s*(?:[-*+]|\d+[.)])\s+(\[( |x|X)\]\s+)?\S/.exec(line);
4167
- if (!part || !item) {
4168
- continue;
4169
- }
4170
- if (part === "todo" && item[2] && item[2] !== " ") {
4171
- counts2.done++;
4172
- } else {
4173
- counts2[part]++;
4174
- }
4209
+ // web-src/more-menu.tsx
4210
+ var MARGIN = 8;
4211
+ function MoreMenu({ pi, label, items }) {
4212
+ const w = ChannelViews.words(pi);
4213
+ const [open, setOpen] = React.useState(false);
4214
+ const anchor = React.useRef({
4215
+ right: 0,
4216
+ below: 0,
4217
+ above: 0,
4218
+ finger: undefined
4219
+ });
4220
+ const root = React.useRef(null);
4221
+ const menu = React.useRef(null);
4222
+ const Ellipsis = ChannelViews.icon(pi, "Ellipsis");
4223
+ const show = React.useCallback((button, at) => {
4224
+ const box = button.getBoundingClientRect();
4225
+ const touch = document.documentElement.hasAttribute("data-touch");
4226
+ const row = root.current?.parentElement?.getBoundingClientRect() ?? box;
4227
+ anchor.current = {
4228
+ right: box.right,
4229
+ below: at?.y ?? box.bottom,
4230
+ above: at?.y ?? box.top,
4231
+ finger: touch && at ? { ...at, around: { top: row.top, bottom: row.bottom } } : undefined
4232
+ };
4233
+ setOpen(true);
4234
+ }, []);
4235
+ React.useLayoutEffect(() => {
4236
+ const element = menu.current;
4237
+ if (!open || !element) {
4238
+ return;
4175
4239
  }
4176
- return counts2;
4177
- }
4178
- NoticeUtil.counts = counts;
4179
- function firstLine(text) {
4180
- for (const line of text.split(/\r?\n/)) {
4181
- const item = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+)$/.exec(line);
4182
- if (item) {
4183
- return item[1].replace(/[*_`~]+/g, "").trim();
4184
- }
4240
+ const { right, below, above, finger } = anchor.current;
4241
+ if (finger) {
4242
+ return pi.ui.attachMenu(element, finger, () => setOpen(false));
4185
4243
  }
4186
- return text.split(/\r?\n/).find((line) => line.trim() && !/^\s*#/.test(line))?.trim() ?? "";
4187
- }
4188
- NoticeUtil.firstLine = firstLine;
4189
- })(NoticeUtil ||= {});
4190
-
4191
- // web-src/notice.tsx
4192
- var NoticeView;
4193
- ((NoticeView) => {
4194
- function display(text) {
4195
- return text.replace(/^(\s*[-*+]\s+)\[ \]\s+/gm, "$1☐ ").replace(/^(\s*[-*+]\s+)\[[xX]\]\s+/gm, "$1☑ ");
4196
- }
4197
- NoticeView.display = display;
4198
- function counts(text, language) {
4199
- const w = ChannelWords.of(language);
4200
- const counts2 = NoticeUtil.counts(text);
4201
- if (counts2.decisions + counts2.conventions + counts2.todo === 0) {
4202
- return NoticeUtil.firstLine(text);
4244
+ const width = element.offsetWidth;
4245
+ const height = element.offsetHeight;
4246
+ const top = below + 4 + height <= window.innerHeight - MARGIN ? below + 4 : Math.max(MARGIN, above - 4 - height);
4247
+ element.style.top = `${top}px`;
4248
+ element.style.left = `${Math.max(MARGIN, right - width)}px`;
4249
+ }, [open, pi]);
4250
+ React.useEffect(() => {
4251
+ const row = root.current?.parentElement;
4252
+ const button = root.current?.querySelector(".tac-action");
4253
+ if (!row || !button) {
4254
+ return;
4203
4255
  }
4204
- const values = { decisions: String(counts2.decisions), conventions: String(counts2.conventions), todo: String(counts2.todo) };
4205
- return ChannelWords.format(w.noticeCounts, values).split(" · ").filter((_, at) => [counts2.decisions, counts2.conventions, counts2.todo][at] > 0).join(" · ");
4206
- }
4207
- NoticeView.counts = counts;
4208
- })(NoticeView ||= {});
4209
- function NoticeBar({
4210
- context,
4211
- channel,
4212
- state,
4213
- onState
4214
- }) {
4215
- const { pi, service } = context;
4216
- const { team } = useChannels(service);
4217
- const w = ChannelViews.words(pi);
4218
- const notice = channel.notice;
4219
- const [draft, setDraft] = React.useState("");
4220
- const [busy, setBusy] = React.useState(false);
4221
- const [error, setError] = React.useState();
4256
+ const onContextMenu = (event) => {
4257
+ event.preventDefault();
4258
+ show(button, event.clientX || event.clientY ? { x: event.clientX, y: event.clientY } : undefined);
4259
+ };
4260
+ row.addEventListener("contextmenu", onContextMenu);
4261
+ return () => row.removeEventListener("contextmenu", onContextMenu);
4262
+ }, [show]);
4222
4263
  React.useEffect(() => {
4223
- if (state.editing) {
4224
- setDraft(notice?.text ?? w.noticeTemplate);
4225
- setError(undefined);
4264
+ if (!open) {
4265
+ return;
4226
4266
  }
4227
- }, [state.editing]);
4228
- if (!notice && !state.editing) {
4229
- return null;
4230
- }
4231
- const Megaphone = ChannelViews.icon(pi, "Megaphone");
4232
- const Chevron = ChannelViews.icon(pi, "ChevronDown");
4233
- const Markdown = pi.ui.Markdown;
4234
- const save = (event) => {
4235
- event.preventDefault();
4236
- setBusy(true);
4237
- setError(undefined);
4238
- service.setNotice(channel.id, draft).then(() => {
4239
- setBusy(false);
4240
- onState({ open: true, editing: false });
4241
- }, (failure) => {
4242
- setBusy(false);
4243
- setError(ChannelViews.message(failure));
4244
- });
4245
- };
4246
- const open = state.open || state.editing;
4267
+ const close = (event) => {
4268
+ if (!root.current?.contains(event.target)) {
4269
+ setOpen(false);
4270
+ }
4271
+ };
4272
+ const onKey = (event) => {
4273
+ if (event.key === "Escape") {
4274
+ setOpen(false);
4275
+ }
4276
+ };
4277
+ document.addEventListener("pointerdown", close);
4278
+ document.addEventListener("keydown", onKey);
4279
+ return () => {
4280
+ document.removeEventListener("pointerdown", close);
4281
+ document.removeEventListener("keydown", onKey);
4282
+ };
4283
+ }, [open]);
4247
4284
  return /* @__PURE__ */ React.createElement("div", {
4248
- className: "tac-notice-bar",
4249
- "data-open": open ? "" : undefined
4285
+ className: "tac-item-more",
4286
+ ref: root
4250
4287
  }, /* @__PURE__ */ React.createElement("button", {
4251
4288
  type: "button",
4252
- className: "tac-notice-head",
4289
+ className: `tac-action${open ? " tac-on" : ""}`,
4290
+ title: w.more,
4291
+ "aria-label": w.more,
4292
+ "aria-haspopup": "menu",
4253
4293
  "aria-expanded": open,
4254
- title: open ? w.noticeHide : w.noticeShow,
4255
- onClick: () => onState({ open: !open, editing: false })
4256
- }, /* @__PURE__ */ React.createElement("span", {
4257
- className: "tac-notice-icon"
4258
- }, /* @__PURE__ */ React.createElement(Megaphone, {
4259
- size: 13,
4260
- strokeWidth: 2
4261
- })), /* @__PURE__ */ React.createElement("strong", null, w.notice), /* @__PURE__ */ React.createElement("span", {
4262
- className: "tac-notice-sum"
4263
- }, notice ? NoticeView.counts(notice.text, pi.ui.language) : w.noticeEmpty), /* @__PURE__ */ React.createElement("span", {
4264
- className: "tac-notice-chevron"
4265
- }, /* @__PURE__ */ React.createElement(Chevron, {
4294
+ onClick: (event) => {
4295
+ event.stopPropagation();
4296
+ if (open) {
4297
+ setOpen(false);
4298
+ } else {
4299
+ show(event.currentTarget);
4300
+ }
4301
+ }
4302
+ }, /* @__PURE__ */ React.createElement(Ellipsis, {
4266
4303
  size: 15
4267
- }))), open && !state.editing && notice && /* @__PURE__ */ React.createElement("div", {
4268
- className: "tac-notice-body"
4269
- }, /* @__PURE__ */ React.createElement("div", {
4270
- className: "tac-notice-text"
4271
- }, /* @__PURE__ */ React.createElement(Markdown, {
4272
- text: NoticeView.display(notice.text)
4273
- })), /* @__PURE__ */ React.createElement("div", {
4274
- className: "tac-notice-foot"
4275
- }, /* @__PURE__ */ React.createElement("span", null, ChannelWords.format(w.noticeBy, {
4276
- name: ChannelsText.authorName(team, notice.by, { user: w.you, ta: w.ta }),
4277
- time: SidebarUtil.time(notice.at, pi.ui.language)
4278
- })), /* @__PURE__ */ React.createElement("button", {
4279
- type: "button",
4280
- className: "tac-button tac-quiet",
4281
- onClick: () => onState({ open: true, editing: true })
4282
- }, w.noticeEdit))), state.editing && /* @__PURE__ */ React.createElement("form", {
4283
- className: "tac-notice-body tac-notice-form",
4284
- onSubmit: save
4285
- }, /* @__PURE__ */ React.createElement("p", {
4286
- className: "tac-dialog-note"
4287
- }, w.noticeHint), /* @__PURE__ */ React.createElement("textarea", {
4288
- className: "tac-input tac-notice-input",
4289
- value: draft,
4290
- "aria-label": w.noticeEdit,
4291
- autoFocus: true,
4292
- onChange: (event) => setDraft(event.target.value)
4293
- }), error && /* @__PURE__ */ React.createElement("div", {
4294
- className: "tac-error"
4295
- }, error), /* @__PURE__ */ React.createElement("div", {
4296
- className: "tac-notice-actions"
4297
- }, /* @__PURE__ */ React.createElement("button", {
4304
+ })), open && /* @__PURE__ */ React.createElement("div", {
4305
+ ref: menu,
4306
+ className: "tac-menu tac-agent-menu",
4307
+ role: "menu",
4308
+ "aria-label": label
4309
+ }, items().filter((section) => section.length > 0).map((section, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
4310
+ key: section[0]?.key ?? index
4311
+ }, index > 0 && /* @__PURE__ */ React.createElement("hr", {
4312
+ className: "tac-menu-line"
4313
+ }), section.map((item) => /* @__PURE__ */ React.createElement("button", {
4314
+ key: item.key,
4298
4315
  type: "button",
4299
- className: "tac-button tac-quiet",
4300
- onClick: () => onState({ open: !!notice, editing: false })
4301
- }, w.cancel), /* @__PURE__ */ React.createElement("button", {
4302
- type: "submit",
4303
- className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
4304
- disabled: busy || draft.trim() === (notice?.text ?? "")
4305
- }, w.save, busy && /* @__PURE__ */ React.createElement("span", {
4306
- className: "ta-spinner ta-busy-mark ta-on-brand"
4307
- })))));
4316
+ role: "menuitem",
4317
+ className: item.danger ? "tac-danger" : undefined,
4318
+ disabled: item.disabled,
4319
+ onClick: () => {
4320
+ setOpen(false);
4321
+ item.run();
4322
+ }
4323
+ }, item.icon, /* @__PURE__ */ React.createElement("span", {
4324
+ className: "tac-menu-label"
4325
+ }, item.label)))))));
4308
4326
  }
4309
4327
 
4310
- // web-src/room.tsx
4311
- var RUN_MS = 5 * 60 * 1000;
4312
- var PAUSE_MS = 15 * 60 * 1000;
4313
- var RoomUtil;
4314
- ((RoomUtil) => {
4315
- function rows(messages) {
4316
- return messages.map((message, index) => {
4317
- const before = messages[index - 1];
4318
- const separator = !before || message.at - before.at > PAUSE_MS;
4319
- const first = separator || before.author !== message.author || before.by !== message.by || before.author === SYSTEM || !!before.notice || message.at - before.at > RUN_MS;
4320
- return { message, first, separator };
4321
- });
4328
+ // web-src/agent-menu.tsx
4329
+ async function copy(text) {
4330
+ try {
4331
+ await navigator.clipboard.writeText(text);
4332
+ return true;
4333
+ } catch {
4334
+ return false;
4322
4335
  }
4323
- RoomUtil.rows = rows;
4324
- })(RoomUtil ||= {});
4325
- function Mentions({ text, agents }) {
4326
- const names = new Set(agents.map((agent) => agent.name.toLowerCase()));
4327
- const parts = text.split(/(@[^\s@#,,。::]+)/);
4328
- return /* @__PURE__ */ React.createElement("span", null, parts.map((part, index) => part.startsWith("@") && names.has(part.slice(1).toLowerCase()) ? /* @__PURE__ */ React.createElement("span", {
4329
- key: index,
4330
- className: "tac-mention"
4331
- }, part) : part));
4332
4336
  }
4333
- function ChannelHead({ context }) {
4334
- const { pi, service, ui } = context;
4335
- const state = useChannels(service);
4336
- const { channelId } = useUi(ui);
4337
- const faces = useFaces(state.team);
4338
- const w = ChannelViews.words(pi);
4339
- const shown = !!pi.ui.useView(MEMBERS_VIEW)?.shown;
4340
- const channel = state.team.channels.find((candidate) => candidate.id === channelId);
4341
- if (!channel) {
4342
- return null;
4343
- }
4344
- const members = membersOf(state.team, channel);
4345
- const working = state.working[channel.id] ?? [];
4346
- return /* @__PURE__ */ React.createElement("div", {
4347
- className: "tac-head"
4348
- }, /* @__PURE__ */ React.createElement("div", {
4349
- className: "tac-head-title"
4350
- }, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", {
4351
- className: "tac-head-count"
4352
- }, ChannelWords.format(w.memberCount, { count: String(members.length) })), channel.topic && /* @__PURE__ */ React.createElement("span", {
4353
- className: "tac-head-topic"
4354
- }, channel.topic)), /* @__PURE__ */ React.createElement("button", {
4355
- type: "button",
4356
- className: `tac-head-members${shown ? " tac-on" : ""}`,
4357
- title: w.showMembers,
4358
- "aria-label": w.showMembers,
4359
- "aria-pressed": shown,
4360
- onClick: () => context.showMembers()
4361
- }, members.slice(0, 5).map((agent) => /* @__PURE__ */ React.createElement("span", {
4362
- key: agent.id,
4363
- className: "tac-head-face"
4364
- }, /* @__PURE__ */ React.createElement(AgentAvatar, {
4365
- agent,
4366
- faces,
4367
- size: 24,
4368
- working: working.includes(agent.id)
4369
- }))), members.length > 5 && /* @__PURE__ */ React.createElement("span", {
4370
- className: "tac-head-more"
4371
- }, "+", members.length - 5)));
4337
+ function download(name, text) {
4338
+ const url = URL.createObjectURL(new Blob([text], { type: "text/markdown;charset=utf-8" }));
4339
+ const link = document.createElement("a");
4340
+ link.href = url;
4341
+ link.download = name;
4342
+ link.click();
4343
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
4372
4344
  }
4373
- function ChannelSceneHead({ context, channelId }) {
4374
- const { pi, service } = context;
4375
- const state = useChannels(service);
4376
- const faces = useFaces(state.team);
4377
- const w = ChannelViews.words(pi);
4378
- const channel = state.team.channels.find((candidate) => candidate.id === channelId);
4379
- if (!channel) {
4380
- return null;
4345
+ async function deleteAgent(context, agent) {
4346
+ const w = ChannelViews.words(context.pi);
4347
+ const sure = await context.pi.ui.confirm(ChannelWords.format(w.confirmDeleteAgent, { name: agent.name }), undefined, {
4348
+ confirmLabel: w.delete,
4349
+ danger: true
4350
+ });
4351
+ if (sure) {
4352
+ await context.service.deleteAgent(agent.id);
4353
+ context.sessions.delete(agent.id);
4381
4354
  }
4382
- const members = membersOf(state.team, channel);
4383
- const working = state.working[channel.id] ?? [];
4384
- const External = ChannelViews.icon(pi, "ExternalLink");
4385
- return /* @__PURE__ */ React.createElement("div", {
4386
- className: "tac-scene-head"
4387
- }, /* @__PURE__ */ React.createElement(RoomFace, {
4388
- members,
4389
- faces,
4390
- size: 26,
4391
- working
4392
- }), /* @__PURE__ */ React.createElement("div", {
4393
- className: "tac-scene-title"
4394
- }, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", null, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(members.length) }))), /* @__PURE__ */ React.createElement("button", {
4395
- type: "button",
4396
- className: "tac-button tac-scene-main",
4397
- title: w.openInMainHint,
4398
- onClick: () => context.showChannel(channel.id)
4399
- }, /* @__PURE__ */ React.createElement(External, {
4400
- size: 13
4401
- }), w.openInMain));
4402
- }
4403
- var mePromise;
4404
- function useMe(pi) {
4405
- const [me, setMe] = React.useState(TA_OWNER);
4406
- React.useEffect(() => {
4407
- mePromise ??= pi.server.getServerInfo().then((info) => info.member?.id ?? TA_OWNER, () => TA_OWNER);
4408
- let live = true;
4409
- mePromise.then((id) => live && setMe(id));
4410
- return () => {
4411
- live = false;
4412
- };
4413
- }, [pi]);
4414
- return me;
4415
4355
  }
4416
- function ChannelRoom({ context, channelId: fixed }) {
4417
- const { pi, service, ui } = context;
4418
- const me = useMe(pi);
4419
- const state = useChannels(service);
4420
- const shown = useUi(ui).channelId;
4421
- const channelId = fixed ?? shown;
4422
- const faces = useFaces(state.team);
4356
+ function AgentMenu({ context, agent, cwd, working }) {
4357
+ const { pi, service } = context;
4423
4358
  const w = ChannelViews.words(pi);
4424
- const channel = state.team.channels.find((candidate) => candidate.id === channelId);
4425
- const messages = channel ? state.messages[channel.id] : undefined;
4426
- const working = channel ? state.working[channel.id] ?? [] : [];
4427
- React.useEffect(() => {
4428
- if (channelId) {
4429
- service.messages(channelId);
4359
+ const [dialog, setDialog] = React.useState();
4360
+ const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
4361
+ const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
4362
+ const act = (action) => () => {
4363
+ Promise.resolve().then(action).catch(fail);
4364
+ };
4365
+ const openSession = async () => {
4366
+ if (!agent.sessionFile) {
4367
+ return;
4430
4368
  }
4431
- }, [service, channelId]);
4432
- const sent = React.useMemo(() => messages?.filter((message) => message.author === USER).length ?? 0, [messages]);
4433
- const list = pi.ui.useChatScroll(sent, channelId);
4434
- const [notice, setNotice] = React.useState({ open: false, editing: false });
4435
- React.useEffect(() => setNotice({ open: false, editing: false }), [channelId]);
4436
- const Markdown = pi.ui.Markdown;
4437
- const Composer = pi.ui.Composer;
4438
- const Avatar = pi.ui.Avatar;
4439
- if (!channel) {
4440
- return /* @__PURE__ */ React.createElement("div", {
4441
- className: "tac-room-page"
4442
- }, state.loaded && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
4443
- title: w.pick
4444
- }));
4445
- }
4446
- const members = membersOf(state.team, channel);
4447
- const agentOf = (id) => state.team.agents.find((agent) => agent.id === id);
4448
- const name = (id) => ChannelsText.authorName(state.team, id, { user: w.you, ta: w.ta });
4449
- const time = (at) => SidebarUtil.time(at, pi.ui.language);
4450
- const mention = (agent) => ({
4451
- key: agent.id,
4452
- label: agent.name,
4453
- icon: /* @__PURE__ */ React.createElement(AgentAvatar, {
4454
- agent,
4455
- faces,
4456
- size: 20
4457
- }),
4458
- detail: agent.id === channel.members[0] ? w.lead : undefined,
4459
- insert: `@${agent.name} `
4369
+ return (await pi.server.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
4370
+ };
4371
+ const stop = act(async () => {
4372
+ const session = await openSession();
4373
+ if (session) {
4374
+ await pi.server.abort(session.sessionId);
4375
+ }
4376
+ pi.ui.notify(ChannelWords.format(w.stoppedAgent, { name: agent.name }), "info");
4460
4377
  });
4461
- return /* @__PURE__ */ React.createElement("div", {
4462
- className: "tac-room-page"
4463
- }, /* @__PURE__ */ React.createElement(NoticeBar, {
4378
+ const restart = act(async () => {
4379
+ await service.resetAgent(agent.id);
4380
+ context.sessions.delete(agent.id);
4381
+ pi.ui.notify(ChannelWords.format(w.resetDone, { name: agent.name }), "info");
4382
+ });
4383
+ const copyCwd = act(async () => {
4384
+ if (await copy(cwd)) {
4385
+ pi.ui.notify(ChannelWords.format(w.copied, { path: cwd }), "info");
4386
+ }
4387
+ });
4388
+ const exportMarkdown = act(async () => {
4389
+ const session = await openSession();
4390
+ const sessionId = session?.sessionId ?? (agent.sessionFile ? await service.openAgent(agent.id) : undefined);
4391
+ const { messages } = sessionId ? await pi.server.getMessages(sessionId) : { messages: [] };
4392
+ if (!messages.some((message) => message.role === "assistant")) {
4393
+ pi.ui.notify(ChannelWords.format(w.nothingToExport, { name: agent.name }), "info");
4394
+ return;
4395
+ }
4396
+ download(`${agent.name}.md`, ChannelsText.markdown(agent, messages, { user: w.you }));
4397
+ });
4398
+ const remove = act(() => deleteAgent(context, agent));
4399
+ const pin = act(() => service.updateAgent(agent.id, { pinned: !agent.pinned }));
4400
+ const keep = act(async () => {
4401
+ await service.updateAgent(agent.id, { keep: true });
4402
+ pi.ui.notify(ChannelWords.format(w.kept, { name: agent.name }), "info");
4403
+ });
4404
+ const show = (next) => () => setDialog(next);
4405
+ const item = (key, label, glyph, run, options = {}) => ({
4406
+ key,
4407
+ label,
4408
+ icon: icon(glyph),
4409
+ run,
4410
+ ...options
4411
+ });
4412
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(MoreMenu, {
4413
+ pi,
4414
+ label: agent.name,
4415
+ items: () => [
4416
+ [
4417
+ ...agent.temporary ? [item("keep", w.keep, "UserPlus", keep)] : [],
4418
+ item("pin", agent.pinned ? w.unpin : w.pin, agent.pinned ? "PinOff" : "Pin", pin)
4419
+ ],
4420
+ [item("stop", w.stop, "Square", stop, { disabled: !working && !agent.sessionFile }), item("restart", w.restart, "RotateCcw", restart)],
4421
+ [
4422
+ item("settings", w.agentSettings, "SlidersHorizontal", show("settings")),
4423
+ item("rename", w.rename, "Pencil", show("rename")),
4424
+ item("role", w.editRole, "ScrollText", show("role")),
4425
+ item("move", w.moveTo, "FolderInput", show("move")),
4426
+ item("copy", w.copyCwd, "Copy", copyCwd)
4427
+ ],
4428
+ [
4429
+ item("card", w.shareCard, "Contact", show("card")),
4430
+ item("export", w.exportChat, "Download", exportMarkdown),
4431
+ item("join", w.joinChannel, "UserPlus", show("join"))
4432
+ ],
4433
+ [item("delete", w.deleteAgent, "Trash2", remove, { danger: true })]
4434
+ ]
4435
+ }), dialog === "settings" && /* @__PURE__ */ React.createElement(AgentSettingsDialog, {
4464
4436
  context,
4465
- channel,
4466
- state: notice,
4467
- onState: setNotice
4468
- }), /* @__PURE__ */ React.createElement("div", {
4469
- className: "tac-chat ta-conversation",
4470
- ref: list
4471
- }, /* @__PURE__ */ React.createElement("div", {
4472
- className: "tac-chat-col"
4473
- }, messages && messages.length === 0 && /* @__PURE__ */ React.createElement("div", {
4474
- className: "tac-chat-empty"
4475
- }, /* @__PURE__ */ React.createElement(RoomFace, {
4476
- members,
4477
- faces,
4478
- size: 56,
4479
- working
4480
- }), /* @__PURE__ */ React.createElement("strong", null, channel.name), channel.topic && /* @__PURE__ */ React.createElement("span", null, channel.topic), /* @__PURE__ */ React.createElement("span", {
4481
- className: "tac-chat-hint"
4482
- }, w.quiet)), messages && RoomUtil.rows(messages).map(({ message, first, separator }) => /* @__PURE__ */ React.createElement(React.Fragment, {
4483
- key: message.id
4484
- }, separator && /* @__PURE__ */ React.createElement("div", {
4485
- className: "tac-chat-time"
4486
- }, time(message.at)), message.author === SYSTEM ? /* @__PURE__ */ React.createElement("div", {
4487
- className: "tac-notice",
4488
- role: "note"
4489
- }, w.stopped) : message.notice ? /* @__PURE__ */ React.createElement("button", {
4490
- type: "button",
4491
- className: "tac-notice tac-notice-line",
4492
- disabled: !channel.notice,
4493
- onClick: () => setNotice({ open: true, editing: false })
4494
- }, ChannelWords.format(message.notice === "cleared" ? w.noticeCleared : w.noticeUpdated, { name: name(message.author) })) : message.author === USER && (message.by ?? TA_OWNER) !== me ? /* @__PURE__ */ React.createElement("div", {
4495
- className: `tac-msg${first ? " tac-first" : ""}`
4496
- }, /* @__PURE__ */ React.createElement("div", {
4497
- className: "tac-msg-face"
4498
- }, first && pi.ui.Face && /* @__PURE__ */ React.createElement(pi.ui.Face, {
4499
- seed: message.by ?? TA_OWNER,
4500
- double: (message.by ?? TA_OWNER) === TA_OWNER,
4501
- size: 28
4502
- })), /* @__PURE__ */ React.createElement("div", {
4503
- className: "tac-msg-col"
4504
- }, first && /* @__PURE__ */ React.createElement("div", {
4505
- className: "tac-msg-name"
4506
- }, message.byName ?? w.owner), /* @__PURE__ */ React.createElement("div", {
4507
- className: "tac-msg-bubble",
4508
- title: time(message.at)
4509
- }, /* @__PURE__ */ React.createElement(Mentions, {
4510
- text: message.text,
4511
- agents: state.team.agents
4512
- })))) : message.author === USER ? /* @__PURE__ */ React.createElement("div", {
4513
- className: "ta-message ta-user tac-mine"
4514
- }, /* @__PURE__ */ React.createElement("div", {
4515
- className: "ta-bubble"
4516
- }, /* @__PURE__ */ React.createElement(Mentions, {
4517
- text: message.text,
4518
- agents: state.team.agents
4519
- }))) : /* @__PURE__ */ React.createElement("div", {
4520
- className: `tac-msg${first ? " tac-first" : ""}`
4521
- }, /* @__PURE__ */ React.createElement("div", {
4522
- className: "tac-msg-face"
4523
- }, first && (message.author === TA ? /* @__PURE__ */ React.createElement(Avatar, {
4524
- size: 28
4525
- }) : /* @__PURE__ */ React.createElement(AgentAvatar, {
4526
- agent: agentOf(message.author),
4527
- faces,
4528
- size: 28,
4529
- working: working.includes(message.author)
4530
- }))), /* @__PURE__ */ React.createElement("div", {
4531
- className: "tac-msg-col"
4532
- }, first && /* @__PURE__ */ React.createElement("div", {
4533
- className: "tac-msg-name"
4534
- }, name(message.author), message.author === channel.members[0] && /* @__PURE__ */ React.createElement("span", {
4535
- className: "tac-msg-lead"
4536
- }, w.lead)), /* @__PURE__ */ React.createElement("div", {
4537
- className: `tac-msg-bubble${message.failed ? " tac-failed" : ""}`,
4538
- title: time(message.at)
4539
- }, message.failed && /* @__PURE__ */ React.createElement("div", {
4540
- className: "tac-msg-failed"
4541
- }, w.failed), /* @__PURE__ */ React.createElement(Markdown, {
4542
- text: ChannelsText.markMentions(message.text, state.team.agents)
4543
- })))))), working.length > 0 && /* @__PURE__ */ React.createElement("div", {
4544
- className: "tac-live",
4545
- role: "status"
4546
- }, /* @__PURE__ */ React.createElement("span", {
4547
- className: "tac-live-faces"
4548
- }, working.map((id) => /* @__PURE__ */ React.createElement(Face, {
4549
- key: id,
4550
- face: faces.get(id) ?? 0,
4551
- size: 18,
4552
- working: true
4553
- }))), ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") })))), /* @__PURE__ */ React.createElement("div", {
4554
- className: "tac-chat-bottom"
4555
- }, /* @__PURE__ */ React.createElement(Composer, {
4556
- placeholder: ChannelWords.format(w.placeholder, { channel: channel.name }),
4557
- draft: channel.id,
4558
- mentions: members.map((agent) => ({ name: agent.name, detail: agent.role.split(`
4559
- `)[0] })),
4560
- actions: [
4561
- members.map(mention),
4562
- [
4563
- {
4564
- key: "notice",
4565
- label: w.noticeEdit,
4566
- icon: ChannelViews.maybeIcon(pi, "Megaphone", null, 16),
4567
- run: () => setNotice({ open: true, editing: true })
4568
- },
4569
- {
4570
- key: "add",
4571
- label: w.addMembers,
4572
- icon: ChannelViews.maybeIcon(pi, "UserPlus", null, 16),
4573
- run: () => {
4574
- if (fixed) {
4575
- ui.set({ channelId: fixed });
4576
- }
4577
- context.showMembers(true);
4578
- }
4579
- }
4580
- ],
4581
- [
4582
- {
4583
- key: "make-extension",
4584
- label: w.makeExtension,
4585
- detail: w.makeExtensionDetail,
4586
- icon: ChannelViews.maybeIcon(pi, "Sparkles", null, 16),
4587
- run: () => void service.post(channel.id, w.makeExtensionAsk).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"))
4588
- }
4589
- ]
4590
- ],
4591
- onSend: (text) => service.post(channel.id, text)
4592
- })));
4593
- }
4594
-
4595
- // web-src/more-menu.tsx
4596
- var MARGIN = 8;
4597
- function MoreMenu({ pi, label, items }) {
4598
- const w = ChannelViews.words(pi);
4599
- const [open, setOpen] = React.useState(false);
4600
- const anchor = React.useRef({
4601
- right: 0,
4602
- below: 0,
4603
- above: 0,
4604
- finger: undefined
4605
- });
4606
- const root = React.useRef(null);
4607
- const menu = React.useRef(null);
4608
- const Ellipsis = ChannelViews.icon(pi, "Ellipsis");
4609
- const show = React.useCallback((button, at) => {
4610
- const box = button.getBoundingClientRect();
4611
- const touch = document.documentElement.hasAttribute("data-touch");
4612
- const row = root.current?.parentElement?.getBoundingClientRect() ?? box;
4613
- anchor.current = {
4614
- right: box.right,
4615
- below: at?.y ?? box.bottom,
4616
- above: at?.y ?? box.top,
4617
- finger: touch && at ? { ...at, around: { top: row.top, bottom: row.bottom } } : undefined
4618
- };
4619
- setOpen(true);
4620
- }, []);
4621
- React.useLayoutEffect(() => {
4622
- const element = menu.current;
4623
- if (!open || !element) {
4624
- return;
4625
- }
4626
- const { right, below, above, finger } = anchor.current;
4627
- if (finger) {
4628
- return pi.ui.attachMenu(element, finger, () => setOpen(false));
4629
- }
4630
- const width = element.offsetWidth;
4631
- const height = element.offsetHeight;
4632
- const top = below + 4 + height <= window.innerHeight - MARGIN ? below + 4 : Math.max(MARGIN, above - 4 - height);
4633
- element.style.top = `${top}px`;
4634
- element.style.left = `${Math.max(MARGIN, right - width)}px`;
4635
- }, [open, pi]);
4636
- React.useEffect(() => {
4637
- const row = root.current?.parentElement;
4638
- const button = root.current?.querySelector(".tac-action");
4639
- if (!row || !button) {
4640
- return;
4641
- }
4642
- const onContextMenu = (event) => {
4643
- event.preventDefault();
4644
- show(button, event.clientX || event.clientY ? { x: event.clientX, y: event.clientY } : undefined);
4645
- };
4646
- row.addEventListener("contextmenu", onContextMenu);
4647
- return () => row.removeEventListener("contextmenu", onContextMenu);
4648
- }, [show]);
4649
- React.useEffect(() => {
4650
- if (!open) {
4651
- return;
4652
- }
4653
- const close = (event) => {
4654
- if (!root.current?.contains(event.target)) {
4655
- setOpen(false);
4656
- }
4657
- };
4658
- const onKey = (event) => {
4659
- if (event.key === "Escape") {
4660
- setOpen(false);
4661
- }
4662
- };
4663
- document.addEventListener("pointerdown", close);
4664
- document.addEventListener("keydown", onKey);
4665
- return () => {
4666
- document.removeEventListener("pointerdown", close);
4667
- document.removeEventListener("keydown", onKey);
4668
- };
4669
- }, [open]);
4670
- return /* @__PURE__ */ React.createElement("div", {
4671
- className: "tac-item-more",
4672
- ref: root
4673
- }, /* @__PURE__ */ React.createElement("button", {
4674
- type: "button",
4675
- className: `tac-action${open ? " tac-on" : ""}`,
4676
- title: w.more,
4677
- "aria-label": w.more,
4678
- "aria-haspopup": "menu",
4679
- "aria-expanded": open,
4680
- onClick: (event) => {
4681
- event.stopPropagation();
4682
- if (open) {
4683
- setOpen(false);
4684
- } else {
4685
- show(event.currentTarget);
4437
+ agent,
4438
+ onClose: () => setDialog(undefined)
4439
+ }), dialog === "rename" && /* @__PURE__ */ React.createElement(RenameDialog, {
4440
+ context,
4441
+ agent,
4442
+ onClose: () => setDialog(undefined)
4443
+ }), dialog === "role" && /* @__PURE__ */ React.createElement(RoleDialog, {
4444
+ context,
4445
+ agent,
4446
+ onClose: () => setDialog(undefined)
4447
+ }), dialog === "join" && /* @__PURE__ */ React.createElement(JoinDialog, {
4448
+ context,
4449
+ agent,
4450
+ onClose: () => setDialog(undefined)
4451
+ }), dialog === "card" && /* @__PURE__ */ React.createElement(CardDialog, {
4452
+ context,
4453
+ agent,
4454
+ onClose: () => setDialog(undefined)
4455
+ }), dialog === "move" && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
4456
+ initial: cwd,
4457
+ onClose: () => setDialog(undefined),
4458
+ onPick: async (path) => {
4459
+ setDialog(undefined);
4460
+ if (path !== cwd) {
4461
+ await service.updateAgent(agent.id, { cwd: path }).catch(fail);
4462
+ context.sessions.delete(agent.id);
4686
4463
  }
4687
4464
  }
4688
- }, /* @__PURE__ */ React.createElement(Ellipsis, {
4689
- size: 15
4690
- })), open && /* @__PURE__ */ React.createElement("div", {
4691
- ref: menu,
4692
- className: "tac-menu tac-agent-menu",
4693
- role: "menu",
4694
- "aria-label": label
4695
- }, items().filter((section) => section.length > 0).map((section, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
4696
- key: section[0]?.key ?? index
4697
- }, index > 0 && /* @__PURE__ */ React.createElement("hr", {
4698
- className: "tac-menu-line"
4699
- }), section.map((item) => /* @__PURE__ */ React.createElement("button", {
4700
- key: item.key,
4701
- type: "button",
4702
- role: "menuitem",
4703
- className: item.danger ? "tac-danger" : undefined,
4704
- disabled: item.disabled,
4705
- onClick: () => {
4706
- setOpen(false);
4707
- item.run();
4708
- }
4709
- }, item.icon, /* @__PURE__ */ React.createElement("span", {
4710
- className: "tac-menu-label"
4711
- }, item.label)))))));
4465
+ }));
4712
4466
  }
4713
-
4714
- // web-src/agent-menu.tsx
4715
- async function copy(text) {
4716
- try {
4717
- await navigator.clipboard.writeText(text);
4718
- return true;
4719
- } catch {
4720
- return false;
4721
- }
4467
+ function useSave(action, onClose) {
4468
+ const [busy, setBusy] = React.useState(false);
4469
+ const [error, setError] = React.useState();
4470
+ const submit = (event) => {
4471
+ event.preventDefault();
4472
+ setBusy(true);
4473
+ setError(undefined);
4474
+ action().then(onClose, (failure) => {
4475
+ setBusy(false);
4476
+ setError(ChannelViews.message(failure));
4477
+ });
4478
+ };
4479
+ return { busy, error, submit };
4722
4480
  }
4723
- function download(name, text) {
4724
- const url = URL.createObjectURL(new Blob([text], { type: "text/markdown;charset=utf-8" }));
4725
- const link = document.createElement("a");
4726
- link.href = url;
4727
- link.download = name;
4728
- link.click();
4729
- setTimeout(() => URL.revokeObjectURL(url), 1000);
4730
- }
4731
- async function deleteAgent(context, agent) {
4732
- const w = ChannelViews.words(context.pi);
4733
- const sure = await context.pi.ui.confirm(ChannelWords.format(w.confirmDeleteAgent, { name: agent.name }), undefined, {
4734
- confirmLabel: w.delete,
4735
- danger: true
4736
- });
4737
- if (sure) {
4738
- await context.service.deleteAgent(agent.id);
4739
- context.sessions.delete(agent.id);
4740
- }
4741
- }
4742
- function AgentMenu({ context, agent, cwd, working }) {
4481
+ function AgentSettingsDialog({ context, agent, onClose }) {
4743
4482
  const { pi, service } = context;
4744
4483
  const w = ChannelViews.words(pi);
4745
- const [dialog, setDialog] = React.useState();
4746
- const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
4747
- const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
4748
- const act = (action2) => () => {
4749
- Promise.resolve().then(action2).catch(fail);
4750
- };
4751
- const openSession = async () => {
4752
- if (!agent.sessionFile) {
4753
- return;
4754
- }
4755
- return (await pi.server.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
4756
- };
4757
- const stop = act(async () => {
4758
- const session = await openSession();
4759
- if (session) {
4760
- await pi.server.abort(session.sessionId);
4761
- }
4762
- pi.ui.notify(ChannelWords.format(w.stoppedAgent, { name: agent.name }), "info");
4763
- });
4764
- const restart = act(async () => {
4765
- await service.resetAgent(agent.id);
4766
- context.sessions.delete(agent.id);
4767
- pi.ui.notify(ChannelWords.format(w.resetDone, { name: agent.name }), "info");
4768
- });
4769
- const copyCwd = act(async () => {
4770
- if (await copy(cwd)) {
4771
- pi.ui.notify(ChannelWords.format(w.copied, { path: cwd }), "info");
4772
- }
4773
- });
4774
- const exportMarkdown = act(async () => {
4775
- const session = await openSession();
4776
- const sessionId = session?.sessionId ?? (agent.sessionFile ? await service.openAgent(agent.id) : undefined);
4777
- const { messages } = sessionId ? await pi.server.getMessages(sessionId) : { messages: [] };
4778
- if (!messages.some((message) => message.role === "assistant")) {
4779
- pi.ui.notify(ChannelWords.format(w.nothingToExport, { name: agent.name }), "info");
4780
- return;
4781
- }
4782
- download(`${agent.name}.md`, ChannelsText.markdown(agent, messages, { user: w.you }));
4783
- });
4784
- const remove = act(() => deleteAgent(context, agent));
4785
- const pin = act(() => service.updateAgent(agent.id, { pinned: !agent.pinned }));
4786
- const keep = act(async () => {
4787
- await service.updateAgent(agent.id, { keep: true });
4788
- pi.ui.notify(ChannelWords.format(w.kept, { name: agent.name }), "info");
4789
- });
4790
- const show = (next) => () => setDialog(next);
4791
- const item = (key, label, glyph, run, options = {}) => ({
4792
- key,
4793
- label,
4794
- icon: icon(glyph),
4795
- run,
4796
- ...options
4797
- });
4798
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(MoreMenu, {
4799
- pi,
4800
- label: agent.name,
4801
- items: () => [
4802
- [
4803
- ...agent.temporary ? [item("keep", w.keep, "UserPlus", keep)] : [],
4804
- item("pin", agent.pinned ? w.unpin : w.pin, agent.pinned ? "PinOff" : "Pin", pin)
4805
- ],
4806
- [item("stop", w.stop, "Square", stop, { disabled: !working && !agent.sessionFile }), item("restart", w.restart, "RotateCcw", restart)],
4807
- [
4808
- item("rename", w.rename, "Pencil", show("rename")),
4809
- item("role", w.editRole, "ScrollText", show("role")),
4810
- item("move", w.moveTo, "FolderInput", show("move")),
4811
- item("copy", w.copyCwd, "Copy", copyCwd)
4812
- ],
4813
- [
4814
- item("card", w.shareCard, "Contact", show("card")),
4815
- item("export", w.exportChat, "Download", exportMarkdown),
4816
- item("join", w.joinChannel, "UserPlus", show("join"))
4817
- ],
4818
- [item("delete", w.deleteAgent, "Trash2", remove, { danger: true })]
4819
- ]
4820
- }), dialog === "rename" && /* @__PURE__ */ React.createElement(RenameDialog, {
4821
- context,
4822
- agent,
4823
- onClose: () => setDialog(undefined)
4824
- }), dialog === "role" && /* @__PURE__ */ React.createElement(RoleDialog, {
4825
- context,
4826
- agent,
4827
- onClose: () => setDialog(undefined)
4828
- }), dialog === "join" && /* @__PURE__ */ React.createElement(JoinDialog, {
4829
- context,
4830
- agent,
4831
- onClose: () => setDialog(undefined)
4832
- }), dialog === "card" && /* @__PURE__ */ React.createElement(CardDialog, {
4833
- context,
4834
- agent,
4835
- onClose: () => setDialog(undefined)
4836
- }), dialog === "move" && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
4837
- initial: cwd,
4838
- onClose: () => setDialog(undefined),
4839
- onPick: async (path) => {
4840
- setDialog(undefined);
4841
- if (path !== cwd) {
4842
- await service.updateAgent(agent.id, { cwd: path }).catch(fail);
4843
- context.sessions.delete(agent.id);
4844
- }
4845
- }
4846
- }));
4847
- }
4848
- function useSave(action2, onClose) {
4849
- const [busy, setBusy] = React.useState(false);
4850
- const [error, setError] = React.useState();
4851
- const submit = (event) => {
4852
- event.preventDefault();
4853
- setBusy(true);
4854
- setError(undefined);
4855
- action2().then(onClose, (failure) => {
4856
- setBusy(false);
4857
- setError(ChannelViews.message(failure));
4858
- });
4484
+ const [name, setName] = React.useState(agent.name);
4485
+ const [model, setModel] = React.useState(agent.model ?? "");
4486
+ const [role, setRole] = React.useState(agent.role);
4487
+ const change = {
4488
+ ...name.trim() !== agent.name ? { name } : {},
4489
+ ...model !== (agent.model ?? "") ? { model } : {},
4490
+ ...role.trim() !== agent.role ? { role } : {}
4859
4491
  };
4860
- return { busy, error, submit };
4492
+ const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, change), onClose);
4493
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
4494
+ title: `${w.agentSettings} · ${agent.name}`,
4495
+ onClose
4496
+ }, /* @__PURE__ */ React.createElement("form", {
4497
+ className: "tac-dialog",
4498
+ onSubmit: submit
4499
+ }, /* @__PURE__ */ React.createElement("label", {
4500
+ className: "tac-dialog-label"
4501
+ }, w.name, /* @__PURE__ */ React.createElement("input", {
4502
+ className: "tac-input tac-dialog-input",
4503
+ value: name,
4504
+ maxLength: 32,
4505
+ onChange: (event) => setName(event.target.value)
4506
+ })), /* @__PURE__ */ React.createElement("div", {
4507
+ className: "tac-dialog-field"
4508
+ }, /* @__PURE__ */ React.createElement("span", null, w.model), /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
4509
+ cwd: agent.cwd,
4510
+ value: model,
4511
+ label: w.model,
4512
+ onChange: setModel
4513
+ })), /* @__PURE__ */ React.createElement("label", {
4514
+ className: "tac-dialog-label"
4515
+ }, w.editRole, /* @__PURE__ */ React.createElement("textarea", {
4516
+ className: "tac-input tac-settings-role",
4517
+ value: role,
4518
+ placeholder: w.rolePlaceholder,
4519
+ onChange: (event) => setRole(event.target.value)
4520
+ })), /* @__PURE__ */ React.createElement("p", {
4521
+ className: "tac-dialog-note"
4522
+ }, w.agentSettingsHint), error && /* @__PURE__ */ React.createElement("div", {
4523
+ className: "tac-error"
4524
+ }, error), /* @__PURE__ */ React.createElement("div", {
4525
+ className: "tac-dialog-actions"
4526
+ }, /* @__PURE__ */ React.createElement("button", {
4527
+ type: "submit",
4528
+ className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
4529
+ disabled: busy || !name.trim() || !role.trim() || Object.keys(change).length === 0
4530
+ }, w.save, busy && /* @__PURE__ */ React.createElement("span", {
4531
+ className: "ta-spinner ta-busy-mark ta-on-brand"
4532
+ })))));
4861
4533
  }
4862
4534
  function RenameDialog({ context, agent, onClose }) {
4863
4535
  const { pi, service } = context;
@@ -4964,294 +4636,1348 @@ function JoinDialog({ context, agent, onClose }) {
4964
4636
  }, error)));
4965
4637
  }
4966
4638
 
4967
- // web-src/tasks.tsx
4968
- var BUILDING_MS = 60 * 1000;
4969
-
4970
- class ChannelTaskSource {
4971
- context;
4972
- shown = new Map;
4973
- list = [];
4974
- listeners = new Set;
4975
- reading = new Set;
4976
- stop;
4977
- constructor(context) {
4978
- this.context = context;
4639
+ // ../ta-protocol/esm/common/team-protocol.js
4640
+ var TA_OWNER = "owner";
4641
+ var TA_UNDECLARED = "extensions.install";
4642
+ var TaPermissionUtil;
4643
+ (function(TaPermissionUtil2) {
4644
+ function read(pi) {
4645
+ const given = pi === null || pi === undefined ? undefined : pi.permissions;
4646
+ const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
4647
+ const host2 = map(given === null || given === undefined ? undefined : given.host);
4648
+ const tools = map(given === null || given === undefined ? undefined : given.tools);
4649
+ return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
4979
4650
  }
4980
- tasks() {
4981
- return this.list;
4651
+ TaPermissionUtil2.read = read;
4652
+ function host(manifest, method, kind) {
4653
+ var _a, _b, _c, _d;
4654
+ const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
4655
+ const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
4656
+ 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;
4982
4657
  }
4983
- subscribe(listener) {
4984
- if (this.listeners.size === 0) {
4985
- this.stop = this.context.service.subscribe((state) => this.build(state));
4986
- this.build(this.context.service.state);
4987
- }
4988
- this.listeners.add(listener);
4989
- return () => {
4990
- this.listeners.delete(listener);
4991
- if (this.listeners.size === 0) {
4992
- this.stop?.();
4993
- this.stop = undefined;
4994
- }
4995
- };
4658
+ TaPermissionUtil2.host = host;
4659
+ })(TaPermissionUtil || (TaPermissionUtil = {}));
4660
+ var action = (id, en, zh, tw, ja, more = {}) => ({
4661
+ id,
4662
+ area: id.split(".")[0],
4663
+ title: { en, "zh-CN": zh, ...tw ? { "zh-TW": tw } : {}, ...ja ? { "ja-JP": ja } : {} },
4664
+ ...more
4665
+ });
4666
+ var TA_ACTIONS = [
4667
+ action("chat.view", "See conversations", "查看对话", "檢視對話", "会話を確認"),
4668
+ action("chat.send", "Send in conversations", "在对话里发消息", "在對話裡發訊息", "会話にメッセージを送信"),
4669
+ action("chat.create", "Start conversations", "新建对话", "新建對話", "新しい会話を開始"),
4670
+ action("chat.stop", "Stop a reply", "停止回复", "停止回覆", "返信を停止"),
4671
+ action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话", "改名、歸檔、關閉對話", "会話の名前変更、アーカイブ、クローズ"),
4672
+ action("chat.share", "Share by a link", "生成分享链接", "生成分享連結", "共有リンクで共有"),
4673
+ action("agent.view", "See agents", "查看智能体", "檢視智慧體", "エージェントを確認"),
4674
+ action("agent.use", "Talk with agents", "和智能体对话", "和智慧體對話", "エージェントと対話"),
4675
+ action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体", "新建、修改、刪除智慧體", "エージェントを作成・変更・削除"),
4676
+ action("channel.view", "See channels", "查看频道", "檢視頻道", "チャネルを確認"),
4677
+ action("channel.post", "Post in channels", "在频道里发言", "在頻道里發言", "チャネルに投稿"),
4678
+ action("channel.manage", "Create and change channels", "新建、管理频道", "新建、管理頻道", "チャネルを作成・管理"),
4679
+ action("task.view", "See tasks", "查看任务", "檢視任務", "タスクを確認"),
4680
+ action("task.create", "Hand out tasks", "派任务", "派任務", "タスクを割り当て"),
4681
+ action("task.manage", "Take over and stop tasks", "接管、停止任务", "接管、停止任務", "タスクを引き継ぎ・停止"),
4682
+ action("files.read", "Read files", "读文件", "讀檔案", "ファイルを読取", { scoped: true }),
4683
+ action("files.write", "Change files", "改文件", "改檔案", "ファイルを変更", { scoped: true }),
4684
+ action("commands.run", "Let Ta run commands", "让 Ta 运行命令", "讓 Ta 執行命令", "Ta にコマンド実行を許可", { scoped: true, risky: true }),
4685
+ action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
4686
+ action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
4687
+ action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
4688
+ action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更", { grant: "single" }),
4689
+ action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
4690
+ action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
4691
+ action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
4692
+ action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
4693
+ action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
4694
+ action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
4695
+ action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
4696
+ action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
4697
+ action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
4698
+ action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
4699
+ action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
4700
+ ];
4701
+ var TA_OWNER_ACTIONS = [
4702
+ action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
4703
+ action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
4704
+ ];
4705
+ var OWNER_AREAS = ["desktop"];
4706
+ var TaActionUtil;
4707
+ (function(TaActionUtil2) {
4708
+ const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
4709
+ const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
4710
+ function info(id) {
4711
+ return byId.get(id);
4996
4712
  }
4997
- refresh() {
4998
- this.shown.clear();
4999
- this.build(this.context.service.state);
4713
+ TaActionUtil2.info = info;
4714
+ function title(id, language) {
4715
+ var _a;
4716
+ var _b, _c;
4717
+ const title2 = (_a = titled.get(id)) === null || _a === undefined ? undefined : _a.title;
4718
+ if (!title2) {
4719
+ return id;
4720
+ }
4721
+ return TaLanguageUtil.pick(language, {
4722
+ "zh-CN": title2["zh-CN"],
4723
+ "zh-TW": (_b = title2["zh-TW"]) !== null && _b !== undefined ? _b : title2["zh-CN"],
4724
+ "en-US": title2.en,
4725
+ "ja-JP": (_c = title2["ja-JP"]) !== null && _c !== undefined ? _c : title2.en
4726
+ });
5000
4727
  }
5001
- build(state) {
5002
- const { team } = state;
5003
- const faces = ChannelsUtil.faces(team.agents);
5004
- const next = new Map;
5005
- const channels = ChannelsUtil.taskChannels(team);
5006
- let changed = channels.length !== this.list.length;
5007
- const list = channels.map((channel, index) => {
5008
- const messages = state.messages[channel.id];
5009
- if (!messages) {
5010
- this.read(channel.id);
4728
+ TaActionUtil2.title = title;
4729
+ function grantable(id) {
4730
+ const info2 = byId.get(id);
4731
+ return !!info2 && !OWNER_AREAS.includes(info2.area);
4732
+ }
4733
+ TaActionUtil2.grantable = grantable;
4734
+ function inRoles(id) {
4735
+ var _a;
4736
+ return grantable(id) && ((_a = byId.get(id)) === null || _a === undefined ? undefined : _a.grant) !== "single";
4737
+ }
4738
+ TaActionUtil2.inRoles = inRoles;
4739
+ function inside(dir, path) {
4740
+ const base = dir.replace(/\/+$/, "");
4741
+ return path === base || path.startsWith(`${base}/`) || base === "";
4742
+ }
4743
+ TaActionUtil2.inside = inside;
4744
+ })(TaActionUtil || (TaActionUtil = {}));
4745
+
4746
+ // web-src/notice-util.ts
4747
+ var NoticeUtil;
4748
+ ((NoticeUtil) => {
4749
+ const PARTS = {
4750
+ 决定: "decisions",
4751
+ decisions: "decisions",
4752
+ 约定: "conventions",
4753
+ conventions: "conventions",
4754
+ 待办: "todo",
4755
+ "to do": "todo",
4756
+ todo: "todo",
4757
+ "to-do": "todo"
4758
+ };
4759
+ function counts(text) {
4760
+ const counts2 = { decisions: 0, conventions: 0, todo: 0, done: 0 };
4761
+ let part;
4762
+ for (const line of text.split(/\r?\n/)) {
4763
+ const heading = /^\s*#{1,6}\s+(.+?)\s*#*\s*$/.exec(line) ?? /^\s*\*\*(.+?)\*\*\s*[::]?\s*$/.exec(line);
4764
+ if (heading) {
4765
+ part = PARTS[heading[1].replace(/[::]$/, "").trim().toLowerCase()];
4766
+ continue;
4767
+ }
4768
+ const item = /^\s*(?:[-*+]|\d+[.)])\s+(\[( |x|X)\]\s+)?\S/.exec(line);
4769
+ if (!part || !item) {
4770
+ continue;
4771
+ }
4772
+ if (part === "todo" && item[2] && item[2] !== " ") {
4773
+ counts2.done++;
4774
+ } else {
4775
+ counts2[part]++;
5011
4776
  }
5012
- const members = membersOf(team, channel);
5013
- const working = state.working[channel.id] ?? [];
5014
- const { status, detail, endedAt } = this.status(state, channel, messages, working);
5015
- const signature = members.map((agent) => `${agent.id}:${faces.get(agent.id)}:${working.includes(agent.id) ? 1 : 0}`).join(",");
5016
- const before = this.shown.get(channel.id);
5017
- const shown = before && before.channel === channel && before.faces === signature && before.status === status && before.detail === detail && before.endedAt === endedAt ? before : {
5018
- channel,
5019
- members,
5020
- faces: signature,
5021
- status,
5022
- detail,
5023
- endedAt,
5024
- entry: this.entry(channel, members, faces, working, status, detail, endedAt)
5025
- };
5026
- next.set(channel.id, shown);
5027
- changed ||= shown.entry !== this.list[index];
5028
- return shown.entry;
5029
- });
5030
- this.shown = next;
5031
- if (!changed) {
5032
- return;
5033
- }
5034
- this.list = list;
5035
- for (const listener of this.listeners) {
5036
- listener();
5037
4777
  }
4778
+ return counts2;
5038
4779
  }
5039
- read(channelId) {
5040
- if (!this.reading.has(channelId)) {
5041
- this.reading.add(channelId);
5042
- this.context.service.messages(channelId).catch(() => this.reading.delete(channelId));
4780
+ NoticeUtil.counts = counts;
4781
+ function firstLine(text) {
4782
+ for (const line of text.split(/\r?\n/)) {
4783
+ const item = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+)$/.exec(line);
4784
+ if (item) {
4785
+ return item[1].replace(/[*_`~]+/g, "").trim();
4786
+ }
5043
4787
  }
4788
+ return text.split(/\r?\n/).find((line) => line.trim() && !/^\s*#/.test(line))?.trim() ?? "";
5044
4789
  }
5045
- status(state, channel, messages, working) {
5046
- const w = ChannelViews.words(this.context.pi);
5047
- const name = (id) => ChannelsText.authorName(state.team, id, { user: w.you, ta: w.ta });
5048
- if (working.length > 0) {
5049
- return { status: "running", detail: ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") }) };
5050
- }
5051
- const last = messages?.at(-1);
5052
- if (!last) {
5053
- const building = Date.now() - channel.createdAt < BUILDING_MS;
5054
- return building ? { status: "running", detail: w.building } : { status: "done", detail: channel.topic || w.noMessages, endedAt: channel.createdAt };
5055
- }
5056
- if (last.author === SYSTEM) {
5057
- return { status: "waiting", detail: w.yourTurn };
4790
+ NoticeUtil.firstLine = firstLine;
4791
+ })(NoticeUtil ||= {});
4792
+
4793
+ // web-src/notice.tsx
4794
+ var NoticeView;
4795
+ ((NoticeView) => {
4796
+ function display(text) {
4797
+ return text.replace(/^(\s*[-*+]\s+)\[ \]\s+/gm, "$1☐ ").replace(/^(\s*[-*+]\s+)\[[xX]\]\s+/gm, "$1☑ ");
4798
+ }
4799
+ NoticeView.display = display;
4800
+ function counts(text, language) {
4801
+ const w = ChannelWords.of(language);
4802
+ const counts2 = NoticeUtil.counts(text);
4803
+ if (counts2.decisions + counts2.conventions + counts2.todo === 0) {
4804
+ return NoticeUtil.firstLine(text);
5058
4805
  }
5059
- const said = `${name(last.author)}:${last.text.replace(/\s+/g, " ").slice(0, 120)}`;
5060
- return { status: last.failed ? "failed" : "done", detail: said, endedAt: last.at };
4806
+ const values = { decisions: String(counts2.decisions), conventions: String(counts2.conventions), todo: String(counts2.todo) };
4807
+ return ChannelWords.format(w.noticeCounts, values).split(" · ").filter((_, at) => [counts2.decisions, counts2.conventions, counts2.todo][at] > 0).join(" · ");
5061
4808
  }
5062
- entry(channel, members, faces, working, status, detail, endedAt) {
5063
- return {
5064
- id: channel.id,
5065
- title: taskTitle(channel),
5066
- status,
5067
- detail,
5068
- startedAt: channel.createdAt,
5069
- endedAt: status === "running" || status === "waiting" ? undefined : endedAt,
5070
- origin: channel.origin,
5071
- icon: ({ size }) => /* @__PURE__ */ React.createElement(RoomFace, {
5072
- members,
5073
- faces,
5074
- size,
5075
- working
5076
- }),
5077
- open: () => openScene(this.context, channel),
5078
- show: () => this.context.showChannel(channel.id),
5079
- menu: () => taskMenu(this.context, channel, working),
5080
- remove: () => deleteTeam(this.context, channel),
5081
- removeHint: ChannelWords.format(ChannelViews.words(this.context.pi).deleteTaskHint, { channel: channel.name })
5082
- };
4809
+ NoticeView.counts = counts;
4810
+ })(NoticeView ||= {});
4811
+ function NoticeBar({
4812
+ context,
4813
+ channel,
4814
+ state,
4815
+ onState
4816
+ }) {
4817
+ const { pi, service } = context;
4818
+ const { team } = useChannels(service);
4819
+ const w = ChannelViews.words(pi);
4820
+ const notice = channel.notice;
4821
+ const [draft, setDraft] = React.useState("");
4822
+ const [busy, setBusy] = React.useState(false);
4823
+ const [error, setError] = React.useState();
4824
+ React.useEffect(() => {
4825
+ if (state.editing) {
4826
+ setDraft(notice?.text ?? w.noticeTemplate);
4827
+ setError(undefined);
4828
+ }
4829
+ }, [state.editing]);
4830
+ if (!notice && !state.editing) {
4831
+ return null;
5083
4832
  }
4833
+ const Megaphone = ChannelViews.icon(pi, "Megaphone");
4834
+ const Chevron = ChannelViews.icon(pi, "ChevronDown");
4835
+ const Markdown = pi.ui.Markdown;
4836
+ const save = (event) => {
4837
+ event.preventDefault();
4838
+ setBusy(true);
4839
+ setError(undefined);
4840
+ service.setNotice(channel.id, draft).then(() => {
4841
+ setBusy(false);
4842
+ onState({ open: true, editing: false });
4843
+ }, (failure) => {
4844
+ setBusy(false);
4845
+ setError(ChannelViews.message(failure));
4846
+ });
4847
+ };
4848
+ const open = state.open || state.editing;
4849
+ return /* @__PURE__ */ React.createElement("div", {
4850
+ className: "tac-notice-bar",
4851
+ "data-open": open ? "" : undefined
4852
+ }, /* @__PURE__ */ React.createElement("button", {
4853
+ type: "button",
4854
+ className: "tac-notice-head",
4855
+ "aria-expanded": open,
4856
+ title: open ? w.noticeHide : w.noticeShow,
4857
+ onClick: () => onState({ open: !open, editing: false })
4858
+ }, /* @__PURE__ */ React.createElement("span", {
4859
+ className: "tac-notice-icon"
4860
+ }, /* @__PURE__ */ React.createElement(Megaphone, {
4861
+ size: 13,
4862
+ strokeWidth: 2
4863
+ })), /* @__PURE__ */ React.createElement("strong", null, w.notice), /* @__PURE__ */ React.createElement("span", {
4864
+ className: "tac-notice-sum"
4865
+ }, notice ? NoticeView.counts(notice.text, pi.ui.language) : w.noticeEmpty), /* @__PURE__ */ React.createElement("span", {
4866
+ className: "tac-notice-chevron"
4867
+ }, /* @__PURE__ */ React.createElement(Chevron, {
4868
+ size: 15
4869
+ }))), open && !state.editing && notice && /* @__PURE__ */ React.createElement("div", {
4870
+ className: "tac-notice-body"
4871
+ }, /* @__PURE__ */ React.createElement("div", {
4872
+ className: "tac-notice-text"
4873
+ }, /* @__PURE__ */ React.createElement(Markdown, {
4874
+ text: NoticeView.display(notice.text)
4875
+ })), /* @__PURE__ */ React.createElement("div", {
4876
+ className: "tac-notice-foot"
4877
+ }, /* @__PURE__ */ React.createElement("span", null, ChannelWords.format(w.noticeBy, {
4878
+ name: ChannelsText.authorName(team, notice.by, { user: w.you, ta: w.ta }),
4879
+ time: SidebarUtil.time(notice.at, pi.ui.language)
4880
+ })), /* @__PURE__ */ React.createElement("button", {
4881
+ type: "button",
4882
+ className: "tac-button tac-quiet",
4883
+ onClick: () => onState({ open: true, editing: true })
4884
+ }, w.noticeEdit))), state.editing && /* @__PURE__ */ React.createElement("form", {
4885
+ className: "tac-notice-body tac-notice-form",
4886
+ onSubmit: save
4887
+ }, /* @__PURE__ */ React.createElement("p", {
4888
+ className: "tac-dialog-note"
4889
+ }, w.noticeHint), /* @__PURE__ */ React.createElement("textarea", {
4890
+ className: "tac-input tac-notice-input",
4891
+ value: draft,
4892
+ "aria-label": w.noticeEdit,
4893
+ autoFocus: true,
4894
+ onChange: (event) => setDraft(event.target.value)
4895
+ }), error && /* @__PURE__ */ React.createElement("div", {
4896
+ className: "tac-error"
4897
+ }, error), /* @__PURE__ */ React.createElement("div", {
4898
+ className: "tac-notice-actions"
4899
+ }, /* @__PURE__ */ React.createElement("button", {
4900
+ type: "button",
4901
+ className: "tac-button tac-quiet",
4902
+ onClick: () => onState({ open: !!notice, editing: false })
4903
+ }, w.cancel), /* @__PURE__ */ React.createElement("button", {
4904
+ type: "submit",
4905
+ className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
4906
+ disabled: busy || draft.trim() === (notice?.text ?? "")
4907
+ }, w.save, busy && /* @__PURE__ */ React.createElement("span", {
4908
+ className: "ta-spinner ta-busy-mark ta-on-brand"
4909
+ })))));
4910
+ }
4911
+
4912
+ // web-src/room.tsx
4913
+ var RUN_MS = 5 * 60 * 1000;
4914
+ var PAUSE_MS = 15 * 60 * 1000;
4915
+ var RoomUtil;
4916
+ ((RoomUtil) => {
4917
+ function rows(messages) {
4918
+ return messages.map((message, index) => {
4919
+ const before = messages[index - 1];
4920
+ const separator = !before || message.at - before.at > PAUSE_MS;
4921
+ const first = separator || before.author !== message.author || before.by !== message.by || before.author === SYSTEM || !!before.notice || message.at - before.at > RUN_MS;
4922
+ return { message, first, separator };
4923
+ });
4924
+ }
4925
+ RoomUtil.rows = rows;
4926
+ })(RoomUtil ||= {});
4927
+ function Mentions({ text, agents }) {
4928
+ const names = new Set(agents.map((agent) => agent.name.toLowerCase()));
4929
+ const parts = text.split(/(@[^\s@#,,。::]+)/);
4930
+ return /* @__PURE__ */ React.createElement("span", null, parts.map((part, index) => part.startsWith("@") && names.has(part.slice(1).toLowerCase()) ? /* @__PURE__ */ React.createElement("span", {
4931
+ key: index,
4932
+ className: "tac-mention"
4933
+ }, part) : part));
4934
+ }
4935
+ function StopLine({
4936
+ context,
4937
+ channel,
4938
+ message,
4939
+ later,
4940
+ agents
4941
+ }) {
4942
+ const { pi, service } = context;
4943
+ const w = ChannelViews.words(pi);
4944
+ const [busy, setBusy] = React.useState(false);
4945
+ const stop = message.stop;
4946
+ const lead = agents.find((agent) => agent.id === channel.members.find((id) => !(channel.muted ?? []).includes(id)));
4947
+ const replies = String(stop?.replies ?? 0);
4948
+ const tokens = stop?.tokens ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(stop.tokens) : "";
4949
+ const stats = stop ? ChannelWords.format(tokens ? w.stoppedStats : w.stoppedReplies, { replies, tokens }) : "";
4950
+ const resumed = stop?.resumed === "continue" ? w.wentOn : stop?.resumed === "wrapUp" ? w.summedUp : "";
4951
+ const why = stop?.daily === "all" ? w.dailyAll : stop?.daily === "channel" ? w.dailyChannel : stop?.idle === "repeat" ? w.idleRepeat : stop?.idle === "agree" ? w.idleAgree : stop?.idle === "pingPong" ? w.idlePingPong : w.stopped;
4952
+ const extended = stop?.extended ? w.extendedOnce : "";
4953
+ const go = (how) => {
4954
+ setBusy(true);
4955
+ service.resumeRound(channel.id, message.id, how).catch((error) => pi.ui.notify(ChannelViews.message(error), "error")).finally(() => setBusy(false));
4956
+ };
4957
+ const open = !!stop?.pending.length && !stop.resumed && !later;
4958
+ return /* @__PURE__ */ React.createElement("div", {
4959
+ className: "tac-stop",
4960
+ role: "note"
4961
+ }, /* @__PURE__ */ React.createElement("div", {
4962
+ className: "tac-notice"
4963
+ }, why), /* @__PURE__ */ React.createElement("div", {
4964
+ className: "tac-stop-meta"
4965
+ }, [stats, extended, resumed].filter(Boolean).join(" · ")), open && /* @__PURE__ */ React.createElement("div", {
4966
+ className: "tac-stop-actions"
4967
+ }, /* @__PURE__ */ React.createElement("button", {
4968
+ type: "button",
4969
+ className: "tac-stop-button",
4970
+ disabled: busy,
4971
+ onClick: () => go("continue")
4972
+ }, w.keepGoing), lead && /* @__PURE__ */ React.createElement("button", {
4973
+ type: "button",
4974
+ className: "tac-stop-button",
4975
+ disabled: busy,
4976
+ onClick: () => go("wrapUp")
4977
+ }, ChannelWords.format(w.wrapUp, { name: `@${lead.name}` }))));
4978
+ }
4979
+ function ChannelHead({ context }) {
4980
+ const { pi, service, ui } = context;
4981
+ const state = useChannels(service);
4982
+ const { channelId } = useUi(ui);
4983
+ const faces = useFaces(state.team);
4984
+ const w = ChannelViews.words(pi);
4985
+ const shown = !!pi.ui.useView(MEMBERS_VIEW)?.shown;
4986
+ const roomInfo = !!pi.ui.useView(ROOM_INFO_VIEW)?.shown;
4987
+ const follow = React.useRef(roomInfo);
4988
+ follow.current = roomInfo;
4989
+ React.useEffect(() => {
4990
+ if (channelId && follow.current) {
4991
+ context.showMembers();
4992
+ }
4993
+ }, [channelId, context]);
4994
+ const channel = state.team.channels.find((candidate) => candidate.id === channelId);
4995
+ if (!channel) {
4996
+ return null;
4997
+ }
4998
+ const members = membersOf(state.team, channel);
4999
+ const working = state.working[channel.id] ?? [];
5000
+ return /* @__PURE__ */ React.createElement("div", {
5001
+ className: "tac-head"
5002
+ }, /* @__PURE__ */ React.createElement("div", {
5003
+ className: "tac-head-title"
5004
+ }, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", {
5005
+ className: "tac-head-count"
5006
+ }, ChannelWords.format(w.memberCount, { count: String(members.length) })), channel.topic && /* @__PURE__ */ React.createElement("span", {
5007
+ className: "tac-head-topic"
5008
+ }, channel.topic)), /* @__PURE__ */ React.createElement("button", {
5009
+ type: "button",
5010
+ className: `tac-head-members${shown ? " tac-on" : ""}`,
5011
+ title: w.showMembers,
5012
+ "aria-label": w.showMembers,
5013
+ "aria-pressed": shown,
5014
+ onClick: () => context.showMembers()
5015
+ }, members.slice(0, 5).map((agent) => /* @__PURE__ */ React.createElement("span", {
5016
+ key: agent.id,
5017
+ className: "tac-head-face"
5018
+ }, /* @__PURE__ */ React.createElement(AgentAvatar, {
5019
+ agent,
5020
+ faces,
5021
+ size: 24,
5022
+ working: working.includes(agent.id)
5023
+ }))), members.length > 5 && /* @__PURE__ */ React.createElement("span", {
5024
+ className: "tac-head-more"
5025
+ }, "+", members.length - 5)));
5026
+ }
5027
+ function ChannelSceneHead({ context, channelId }) {
5028
+ const { pi, service } = context;
5029
+ const state = useChannels(service);
5030
+ const faces = useFaces(state.team);
5031
+ const w = ChannelViews.words(pi);
5032
+ const channel = state.team.channels.find((candidate) => candidate.id === channelId);
5033
+ if (!channel) {
5034
+ return null;
5035
+ }
5036
+ const members = membersOf(state.team, channel);
5037
+ const working = state.working[channel.id] ?? [];
5038
+ const External = ChannelViews.icon(pi, "ExternalLink");
5039
+ return /* @__PURE__ */ React.createElement("div", {
5040
+ className: "tac-scene-head"
5041
+ }, /* @__PURE__ */ React.createElement(RoomFace, {
5042
+ members,
5043
+ faces,
5044
+ size: 26,
5045
+ working
5046
+ }), /* @__PURE__ */ React.createElement("div", {
5047
+ className: "tac-scene-title"
5048
+ }, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", null, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(members.length) }))), /* @__PURE__ */ React.createElement("button", {
5049
+ type: "button",
5050
+ className: "tac-button tac-scene-main",
5051
+ title: w.openInMainHint,
5052
+ onClick: () => context.showChannel(channel.id)
5053
+ }, /* @__PURE__ */ React.createElement(External, {
5054
+ size: 13
5055
+ }), w.openInMain));
5056
+ }
5057
+ var mePromise;
5058
+ function useMe(pi) {
5059
+ const [me, setMe] = React.useState(TA_OWNER);
5060
+ React.useEffect(() => {
5061
+ mePromise ??= pi.server.getServerInfo().then((info) => info.member?.id ?? TA_OWNER, () => TA_OWNER);
5062
+ let live = true;
5063
+ mePromise.then((id) => live && setMe(id));
5064
+ return () => {
5065
+ live = false;
5066
+ };
5067
+ }, [pi]);
5068
+ return me;
5069
+ }
5070
+ function ChannelRoom({ context, channelId: fixed }) {
5071
+ const { pi, service, ui } = context;
5072
+ const me = useMe(pi);
5073
+ const state = useChannels(service);
5074
+ const shown = useUi(ui).channelId;
5075
+ const channelId = fixed ?? shown;
5076
+ const faces = useFaces(state.team);
5077
+ const w = ChannelViews.words(pi);
5078
+ const channel = state.team.channels.find((candidate) => candidate.id === channelId);
5079
+ const messages = channel ? state.messages[channel.id] : undefined;
5080
+ const working = channel ? state.working[channel.id] ?? [] : [];
5081
+ React.useEffect(() => {
5082
+ if (channelId) {
5083
+ service.messages(channelId);
5084
+ }
5085
+ }, [service, channelId]);
5086
+ React.useEffect(() => {
5087
+ if (!channelId) {
5088
+ return;
5089
+ }
5090
+ const watch = () => document.visibilityState === "visible" && void service.watch(channelId).catch(() => {
5091
+ return;
5092
+ });
5093
+ watch();
5094
+ const timer = setInterval(watch, WATCH_MS);
5095
+ document.addEventListener("visibilitychange", watch);
5096
+ return () => {
5097
+ clearInterval(timer);
5098
+ document.removeEventListener("visibilitychange", watch);
5099
+ };
5100
+ }, [service, channelId]);
5101
+ const sent = React.useMemo(() => messages?.filter((message) => message.author === USER).length ?? 0, [messages]);
5102
+ const list = pi.ui.useChatScroll(sent, channelId);
5103
+ const [notice, setNotice] = React.useState({ open: false, editing: false });
5104
+ React.useEffect(() => setNotice({ open: false, editing: false }), [channelId]);
5105
+ const Markdown = pi.ui.Markdown;
5106
+ const Composer = pi.ui.Composer;
5107
+ const Avatar = pi.ui.Avatar;
5108
+ if (!channel) {
5109
+ return /* @__PURE__ */ React.createElement("div", {
5110
+ className: "tac-room-page"
5111
+ }, state.loaded && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
5112
+ title: w.pick
5113
+ }));
5114
+ }
5115
+ const members = membersOf(state.team, channel);
5116
+ const agentOf = (id) => state.team.agents.find((agent) => agent.id === id);
5117
+ const name = (id) => ChannelsText.authorName(state.team, id, { user: w.you, ta: w.ta });
5118
+ const time = (at) => SidebarUtil.time(at, pi.ui.language);
5119
+ const mention = (agent) => ({
5120
+ key: agent.id,
5121
+ label: agent.name,
5122
+ icon: /* @__PURE__ */ React.createElement(AgentAvatar, {
5123
+ agent,
5124
+ faces,
5125
+ size: 20
5126
+ }),
5127
+ detail: agent.id === channel.members[0] ? w.lead : undefined,
5128
+ insert: `@${agent.name} `
5129
+ });
5130
+ return /* @__PURE__ */ React.createElement("div", {
5131
+ className: "tac-room-page"
5132
+ }, /* @__PURE__ */ React.createElement(NoticeBar, {
5133
+ context,
5134
+ channel,
5135
+ state: notice,
5136
+ onState: setNotice
5137
+ }), /* @__PURE__ */ React.createElement("div", {
5138
+ className: "tac-chat ta-conversation",
5139
+ ref: list
5140
+ }, /* @__PURE__ */ React.createElement("div", {
5141
+ className: "tac-chat-col"
5142
+ }, messages && messages.length === 0 && /* @__PURE__ */ React.createElement("div", {
5143
+ className: "tac-chat-empty"
5144
+ }, /* @__PURE__ */ React.createElement(RoomFace, {
5145
+ members,
5146
+ faces,
5147
+ size: 56,
5148
+ working
5149
+ }), /* @__PURE__ */ React.createElement("strong", null, channel.name), channel.topic && /* @__PURE__ */ React.createElement("span", null, channel.topic), /* @__PURE__ */ React.createElement("span", {
5150
+ className: "tac-chat-hint"
5151
+ }, w.quiet)), messages && RoomUtil.rows(messages).map(({ message, first, separator }) => /* @__PURE__ */ React.createElement(React.Fragment, {
5152
+ key: message.id
5153
+ }, separator && /* @__PURE__ */ React.createElement("div", {
5154
+ className: "tac-chat-time"
5155
+ }, time(message.at)), message.author === SYSTEM ? /* @__PURE__ */ React.createElement(StopLine, {
5156
+ context,
5157
+ channel,
5158
+ message,
5159
+ agents: state.team.agents,
5160
+ later: messages.some((other) => other.at > message.at && (other.author === USER || other.author === TA))
5161
+ }) : message.notice ? /* @__PURE__ */ React.createElement("button", {
5162
+ type: "button",
5163
+ className: "tac-notice tac-notice-line",
5164
+ disabled: !channel.notice,
5165
+ onClick: () => setNotice({ open: true, editing: false })
5166
+ }, ChannelWords.format(message.notice === "cleared" ? w.noticeCleared : w.noticeUpdated, { name: name(message.author) })) : message.author === USER && (message.by ?? TA_OWNER) !== me ? /* @__PURE__ */ React.createElement("div", {
5167
+ className: `tac-msg${first ? " tac-first" : ""}`
5168
+ }, /* @__PURE__ */ React.createElement("div", {
5169
+ className: "tac-msg-face"
5170
+ }, first && pi.ui.Face && /* @__PURE__ */ React.createElement(pi.ui.Face, {
5171
+ seed: message.by ?? TA_OWNER,
5172
+ double: (message.by ?? TA_OWNER) === TA_OWNER,
5173
+ size: 28
5174
+ })), /* @__PURE__ */ React.createElement("div", {
5175
+ className: "tac-msg-col"
5176
+ }, first && /* @__PURE__ */ React.createElement("div", {
5177
+ className: "tac-msg-name"
5178
+ }, message.byName ?? w.owner), /* @__PURE__ */ React.createElement("div", {
5179
+ className: "tac-msg-bubble",
5180
+ title: time(message.at)
5181
+ }, /* @__PURE__ */ React.createElement(Mentions, {
5182
+ text: message.text,
5183
+ agents: state.team.agents
5184
+ })))) : message.author === USER ? /* @__PURE__ */ React.createElement("div", {
5185
+ className: "ta-message ta-user tac-mine"
5186
+ }, /* @__PURE__ */ React.createElement("div", {
5187
+ className: "ta-bubble"
5188
+ }, /* @__PURE__ */ React.createElement(Mentions, {
5189
+ text: message.text,
5190
+ agents: state.team.agents
5191
+ }))) : /* @__PURE__ */ React.createElement("div", {
5192
+ className: `tac-msg${first ? " tac-first" : ""}`
5193
+ }, /* @__PURE__ */ React.createElement("div", {
5194
+ className: "tac-msg-face"
5195
+ }, first && (message.author === TA ? /* @__PURE__ */ React.createElement(Avatar, {
5196
+ size: 28
5197
+ }) : /* @__PURE__ */ React.createElement(AgentAvatar, {
5198
+ agent: agentOf(message.author),
5199
+ faces,
5200
+ size: 28,
5201
+ working: working.includes(message.author)
5202
+ }))), /* @__PURE__ */ React.createElement("div", {
5203
+ className: "tac-msg-col"
5204
+ }, first && /* @__PURE__ */ React.createElement("div", {
5205
+ className: "tac-msg-name"
5206
+ }, name(message.author), message.author === channel.members[0] && /* @__PURE__ */ React.createElement("span", {
5207
+ className: "tac-msg-lead"
5208
+ }, w.lead)), /* @__PURE__ */ React.createElement("div", {
5209
+ className: `tac-msg-bubble${message.failed ? " tac-failed" : ""}`,
5210
+ title: time(message.at)
5211
+ }, message.failed && /* @__PURE__ */ React.createElement("div", {
5212
+ className: "tac-msg-failed"
5213
+ }, w.failed), message.overBudget && /* @__PURE__ */ React.createElement("div", {
5214
+ className: "tac-msg-over"
5215
+ }, w.overBudget), /* @__PURE__ */ React.createElement(Markdown, {
5216
+ text: ChannelsText.markMentions(message.text, state.team.agents)
5217
+ })))))), working.length > 0 && /* @__PURE__ */ React.createElement("div", {
5218
+ className: "tac-live",
5219
+ role: "status"
5220
+ }, /* @__PURE__ */ React.createElement("span", {
5221
+ className: "tac-live-faces"
5222
+ }, working.map((id) => /* @__PURE__ */ React.createElement(Face, {
5223
+ key: id,
5224
+ face: faces.get(id) ?? 0,
5225
+ size: 18,
5226
+ working: true
5227
+ }))), ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") })))), /* @__PURE__ */ React.createElement("div", {
5228
+ className: "tac-chat-bottom"
5229
+ }, /* @__PURE__ */ React.createElement(Composer, {
5230
+ placeholder: ChannelWords.format(w.placeholder, { channel: channel.name }),
5231
+ draft: channel.id,
5232
+ mentions: members.map((agent) => ({ name: agent.name, detail: agent.role.split(`
5233
+ `)[0] })),
5234
+ actions: [
5235
+ members.map(mention),
5236
+ [
5237
+ {
5238
+ key: "notice",
5239
+ label: w.noticeEdit,
5240
+ icon: ChannelViews.maybeIcon(pi, "Megaphone", null, 16),
5241
+ run: () => setNotice({ open: true, editing: true })
5242
+ },
5243
+ {
5244
+ key: "add",
5245
+ label: w.addMembers,
5246
+ icon: ChannelViews.maybeIcon(pi, "UserPlus", null, 16),
5247
+ run: () => {
5248
+ if (fixed) {
5249
+ ui.set({ channelId: fixed });
5250
+ }
5251
+ context.showMembers(true);
5252
+ }
5253
+ }
5254
+ ],
5255
+ [
5256
+ {
5257
+ key: "make-extension",
5258
+ label: w.makeExtension,
5259
+ detail: w.makeExtensionDetail,
5260
+ icon: ChannelViews.maybeIcon(pi, "Sparkles", null, 16),
5261
+ run: () => void service.post(channel.id, w.makeExtensionAsk).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"))
5262
+ }
5263
+ ]
5264
+ ],
5265
+ onSend: (text) => service.post(channel.id, text)
5266
+ })));
5267
+ }
5268
+
5269
+ // web-src/tasks.tsx
5270
+ var BUILDING_MS = 60 * 1000;
5271
+
5272
+ class ChannelTaskSource {
5273
+ context;
5274
+ shown = new Map;
5275
+ list = [];
5276
+ listeners = new Set;
5277
+ reading = new Set;
5278
+ stop;
5279
+ constructor(context) {
5280
+ this.context = context;
5281
+ }
5282
+ tasks() {
5283
+ return this.list;
5284
+ }
5285
+ subscribe(listener) {
5286
+ if (this.listeners.size === 0) {
5287
+ this.stop = this.context.service.subscribe((state) => this.build(state));
5288
+ this.build(this.context.service.state);
5289
+ }
5290
+ this.listeners.add(listener);
5291
+ return () => {
5292
+ this.listeners.delete(listener);
5293
+ if (this.listeners.size === 0) {
5294
+ this.stop?.();
5295
+ this.stop = undefined;
5296
+ }
5297
+ };
5298
+ }
5299
+ refresh() {
5300
+ this.shown.clear();
5301
+ this.build(this.context.service.state);
5302
+ }
5303
+ build(state) {
5304
+ const { team } = state;
5305
+ const faces = ChannelsUtil.faces(team.agents);
5306
+ const next = new Map;
5307
+ const channels = ChannelsUtil.taskChannels(team);
5308
+ let changed = channels.length !== this.list.length;
5309
+ const list = channels.map((channel, index) => {
5310
+ const messages = state.messages[channel.id];
5311
+ if (!messages) {
5312
+ this.read(channel.id);
5313
+ }
5314
+ const members = membersOf(team, channel);
5315
+ const working = state.working[channel.id] ?? [];
5316
+ const { status, detail, endedAt } = this.status(state, channel, messages, working);
5317
+ const signature = members.map((agent) => `${agent.id}:${faces.get(agent.id)}:${working.includes(agent.id) ? 1 : 0}`).join(",");
5318
+ const before = this.shown.get(channel.id);
5319
+ const shown = before && before.channel === channel && before.faces === signature && before.status === status && before.detail === detail && before.endedAt === endedAt ? before : {
5320
+ channel,
5321
+ members,
5322
+ faces: signature,
5323
+ status,
5324
+ detail,
5325
+ endedAt,
5326
+ entry: this.entry(channel, members, faces, working, status, detail, endedAt)
5327
+ };
5328
+ next.set(channel.id, shown);
5329
+ changed ||= shown.entry !== this.list[index];
5330
+ return shown.entry;
5331
+ });
5332
+ this.shown = next;
5333
+ if (!changed) {
5334
+ return;
5335
+ }
5336
+ this.list = list;
5337
+ for (const listener of this.listeners) {
5338
+ listener();
5339
+ }
5340
+ }
5341
+ read(channelId) {
5342
+ if (!this.reading.has(channelId)) {
5343
+ this.reading.add(channelId);
5344
+ this.context.service.messages(channelId).catch(() => this.reading.delete(channelId));
5345
+ }
5346
+ }
5347
+ status(state, channel, messages, working) {
5348
+ const w = ChannelViews.words(this.context.pi);
5349
+ const name = (id) => ChannelsText.authorName(state.team, id, { user: w.you, ta: w.ta });
5350
+ if (working.length > 0) {
5351
+ return { status: "running", detail: ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") }) };
5352
+ }
5353
+ const last = messages?.at(-1);
5354
+ if (!last) {
5355
+ const building = Date.now() - channel.createdAt < BUILDING_MS;
5356
+ return building ? { status: "running", detail: w.building } : { status: "done", detail: channel.topic || w.noMessages, endedAt: channel.createdAt };
5357
+ }
5358
+ if (last.author === SYSTEM) {
5359
+ return { status: "waiting", detail: w.yourTurn };
5360
+ }
5361
+ const said = `${name(last.author)}:${last.text.replace(/\s+/g, " ").slice(0, 120)}`;
5362
+ return { status: last.failed ? "failed" : "done", detail: said, endedAt: last.at };
5363
+ }
5364
+ entry(channel, members, faces, working, status, detail, endedAt) {
5365
+ return {
5366
+ id: channel.id,
5367
+ title: taskTitle(channel),
5368
+ status,
5369
+ detail,
5370
+ startedAt: channel.createdAt,
5371
+ endedAt: status === "running" || status === "waiting" ? undefined : endedAt,
5372
+ origin: channel.origin,
5373
+ icon: ({ size }) => /* @__PURE__ */ React.createElement(RoomFace, {
5374
+ members,
5375
+ faces,
5376
+ size,
5377
+ working
5378
+ }),
5379
+ open: () => openScene(this.context, channel),
5380
+ show: () => this.context.showChannel(channel.id),
5381
+ menu: () => taskMenu(this.context, channel, working),
5382
+ remove: () => deleteTeam(this.context, channel),
5383
+ removeHint: ChannelWords.format(ChannelViews.words(this.context.pi).deleteTaskHint, { channel: channel.name })
5384
+ };
5385
+ }
5386
+ }
5387
+ function taskTitle(channel) {
5388
+ return channel.name;
5389
+ }
5390
+ async function deleteTeam(context, channel) {
5391
+ await context.service.deleteChannel(channel.id);
5392
+ context.pi.ui.closeEditor(`channel:${channel.id}`);
5393
+ }
5394
+ function openScene(context, channel) {
5395
+ context.pi.ui.openEditor({
5396
+ id: `channel:${channel.id}`,
5397
+ title: channel.name,
5398
+ icon: ChannelViews.icon(context.pi, "Hash"),
5399
+ render: () => /* @__PURE__ */ React.createElement("div", {
5400
+ className: "tac-scene"
5401
+ }, /* @__PURE__ */ React.createElement(ChannelSceneHead, {
5402
+ context,
5403
+ channelId: channel.id
5404
+ }), /* @__PURE__ */ React.createElement(ChannelRoom, {
5405
+ context,
5406
+ channelId: channel.id
5407
+ }))
5408
+ });
5409
+ }
5410
+ function taskMenu(context, channel, working) {
5411
+ const { pi, service } = context;
5412
+ const w = ChannelViews.words(pi);
5413
+ const icon = (name) => ChannelViews.icon(pi, name);
5414
+ const act = (action2) => () => {
5415
+ Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
5416
+ };
5417
+ const temporary = membersOf(service.state.team, channel).filter((agent) => agent.temporary);
5418
+ return [
5419
+ working.length > 0 ? [
5420
+ {
5421
+ key: "stop",
5422
+ label: w.stopAnswering,
5423
+ icon: icon("Square"),
5424
+ run: act(async () => {
5425
+ await TeamActions.stop(context, working);
5426
+ pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info");
5427
+ })
5428
+ }
5429
+ ] : [],
5430
+ [
5431
+ { key: "main", label: w.openInMain, icon: icon("ExternalLink"), run: () => context.showChannel(channel.id) },
5432
+ ...temporary.length > 0 ? [
5433
+ {
5434
+ key: "keep",
5435
+ label: w.keepMembers,
5436
+ icon: icon("UserPlus"),
5437
+ run: act(async () => {
5438
+ await TeamActions.keep(context, temporary);
5439
+ pi.ui.notify(ChannelWords.format(w.keptMembers, { names: temporary.map((agent) => `@${agent.name}`).join("、") }), "info");
5440
+ })
5441
+ }
5442
+ ] : []
5443
+ ],
5444
+ [
5445
+ {
5446
+ key: "delete",
5447
+ label: w.deleteTask,
5448
+ icon: icon("Trash2"),
5449
+ danger: true,
5450
+ run: act(() => pi.ui.removeTasks([
5451
+ {
5452
+ title: taskTitle(channel),
5453
+ removeHint: ChannelWords.format(w.deleteTaskHint, { channel: channel.name }),
5454
+ remove: () => deleteTeam(context, channel)
5455
+ }
5456
+ ]))
5457
+ }
5458
+ ]
5459
+ ];
5460
+ }
5461
+ var TeamActions;
5462
+ ((TeamActions) => {
5463
+ async function stop(context, agentIds) {
5464
+ const { pi, service } = context;
5465
+ const files = new Set(service.state.team.agents.filter((agent) => agentIds.includes(agent.id) && agent.sessionFile).map((agent) => agent.sessionFile));
5466
+ const sessions = (await pi.server.listSessions()).filter((session) => session.sessionFile && files.has(session.sessionFile));
5467
+ await Promise.all(sessions.map((session) => pi.server.abort(session.sessionId)));
5468
+ }
5469
+ TeamActions.stop = stop;
5470
+ async function keep(context, agents) {
5471
+ for (const agent of agents) {
5472
+ await context.service.updateAgent(agent.id, { keep: true });
5473
+ }
5474
+ }
5475
+ TeamActions.keep = keep;
5476
+ })(TeamActions ||= {});
5477
+
5478
+ // web-src/channel-menu.tsx
5479
+ function download2(name, text) {
5480
+ const url = URL.createObjectURL(new Blob([text], { type: "text/markdown;charset=utf-8" }));
5481
+ const link = document.createElement("a");
5482
+ link.href = url;
5483
+ link.download = name;
5484
+ link.click();
5485
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
5486
+ }
5487
+ async function deleteChannel(context, channel) {
5488
+ const w = ChannelViews.words(context.pi);
5489
+ const sure = await context.pi.ui.confirm(ChannelWords.format(w.confirmDelete, { channel: channel.name }), undefined, {
5490
+ confirmLabel: w.delete,
5491
+ danger: true
5492
+ });
5493
+ if (sure) {
5494
+ await context.service.deleteChannel(channel.id);
5495
+ }
5496
+ }
5497
+ async function renameChannel(context, channel) {
5498
+ const w = ChannelViews.words(context.pi);
5499
+ const name = await context.pi.ui.input(ChannelWords.format(w.renameChannel, { channel: channel.name }), w.channelNamePlaceholder, { value: channel.name });
5500
+ if (name !== undefined && name.trim() !== channel.name) {
5501
+ await context.service.updateChannel(channel.id, { name });
5502
+ }
5503
+ }
5504
+ async function editChannelTopic(context, channel) {
5505
+ const w = ChannelViews.words(context.pi);
5506
+ const topic = await context.pi.ui.input(w.editTopic, w.topicPlaceholder, { value: channel.topic ?? "" });
5507
+ if (topic !== undefined && topic.trim() !== (channel.topic ?? "")) {
5508
+ await context.service.updateChannel(channel.id, { topic });
5509
+ }
5510
+ }
5511
+ function ChannelMenu({ context, channel, working }) {
5512
+ const { pi, service, ui } = context;
5513
+ const { fresh } = useUi(ui);
5514
+ const w = ChannelViews.words(pi);
5515
+ const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
5516
+ const act = (action2) => () => {
5517
+ Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
5518
+ };
5519
+ const unread = fresh.includes(channel.id);
5520
+ const pin = act(() => service.updateChannel(channel.id, { pinned: !channel.pinned }));
5521
+ const markRead = act(() => ui.set({ fresh: unread ? fresh.filter((id) => id !== channel.id) : [...fresh, channel.id] }));
5522
+ const rename = act(() => renameChannel(context, channel));
5523
+ const editTopic = act(() => editChannelTopic(context, channel));
5524
+ const members = act(() => {
5525
+ context.showChannel(channel.id);
5526
+ context.showMembers();
5527
+ });
5528
+ const stop = act(async () => {
5529
+ await TeamActions.stop(context, working);
5530
+ pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info");
5531
+ });
5532
+ const exportMarkdown = act(async () => {
5533
+ const messages = await service.messages(channel.id);
5534
+ if (!messages.some((message) => message.text.trim())) {
5535
+ pi.ui.notify(ChannelWords.format(w.noMessagesToExport, { channel: channel.name }), "info");
5536
+ return;
5537
+ }
5538
+ download2(`${channel.name}.md`, ChannelsText.channelMarkdown(service.state.team, channel, messages, { user: w.you, ta: w.ta }));
5539
+ });
5540
+ const remove = act(() => deleteChannel(context, channel));
5541
+ const budget = ChannelsUtil.budgetOf(channel);
5542
+ const budgets = [
5543
+ ["short", w.budgetShort],
5544
+ ["normal", w.budgetNormal],
5545
+ ["long", w.budgetLong]
5546
+ ];
5547
+ const budgetItem = ([key, label]) => ({
5548
+ key: `budget-${key}`,
5549
+ label: ChannelWords.format(label, { n: String(BUDGETS[key].replies) }),
5550
+ icon: key === budget ? icon("Check") : /* @__PURE__ */ React.createElement("span", {
5551
+ className: "tac-menu-blank"
5552
+ }),
5553
+ run: act(() => key !== budget && service.updateChannel(channel.id, { budget: key }))
5554
+ });
5555
+ const item = (key, label, glyph, run, options = {}) => ({
5556
+ key,
5557
+ label,
5558
+ icon: icon(glyph),
5559
+ run,
5560
+ ...options
5561
+ });
5562
+ return /* @__PURE__ */ React.createElement(MoreMenu, {
5563
+ pi,
5564
+ label: channel.name,
5565
+ items: () => [
5566
+ [
5567
+ item("pin", channel.pinned ? w.unpin : w.pin, channel.pinned ? "PinOff" : "Pin", pin),
5568
+ item("read", unread ? w.markRead : w.markUnread, unread ? "MessageSquareText" : "MessageSquareDot", markRead)
5569
+ ],
5570
+ [item("rename", w.rename, "Pencil", rename), item("topic", w.editTopic, "Text", editTopic), item("members", w.showMembers, "Users", members)],
5571
+ budgets.map(budgetItem),
5572
+ [item("stop", w.stopAnswering, "Square", stop, { disabled: working.length === 0 }), item("export", w.exportChat, "Download", exportMarkdown)],
5573
+ [item("delete", w.deleteChannel, "Trash2", remove, { danger: true })]
5574
+ ]
5575
+ });
5576
+ }
5577
+
5578
+ // web-src/members.tsx
5579
+ function MembersView({ context }) {
5580
+ const { pi, service, ui } = context;
5581
+ const state = useChannels(service);
5582
+ const { channelId, adding } = useUi(ui);
5583
+ const faces = useFaces(state.team);
5584
+ const w = ChannelViews.words(pi);
5585
+ const channel = state.team.channels.find((candidate) => candidate.id === channelId);
5586
+ if (!channel) {
5587
+ return /* @__PURE__ */ React.createElement("div", {
5588
+ className: "tac-view tac-members"
5589
+ }, state.loaded && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
5590
+ title: w.noChannel
5591
+ }));
5592
+ }
5593
+ return adding ? /* @__PURE__ */ React.createElement(MemberPicker, {
5594
+ key: channel.id,
5595
+ context,
5596
+ team: state.team,
5597
+ channel,
5598
+ faces
5599
+ }) : /* @__PURE__ */ React.createElement(MemberList, {
5600
+ key: channel.id,
5601
+ context,
5602
+ team: state.team,
5603
+ channel,
5604
+ faces,
5605
+ working: state.working[channel.id] ?? []
5606
+ });
5607
+ }
5608
+ function MemberList({ context, team, channel, faces, working }) {
5609
+ const { pi, service, ui } = context;
5610
+ const w = ChannelViews.words(pi);
5611
+ const [busy, setBusy] = React.useState();
5612
+ const [confirming, setConfirming] = React.useState(false);
5613
+ const [editing, setEditing] = React.useState();
5614
+ const UserPlus = ChannelViews.icon(pi, "UserPlus");
5615
+ const Contact = ChannelViews.icon(pi, "Contact");
5616
+ const Crown = ChannelViews.icon(pi, "Crown");
5617
+ const BellOff = ChannelViews.icon(pi, "BellOff");
5618
+ const RotateCcw = ChannelViews.icon(pi, "RotateCcw");
5619
+ const X = ChannelViews.icon(pi, "X");
5620
+ const Trash = ChannelViews.icon(pi, "Trash2");
5621
+ const Sliders = pi.ui.icons.SlidersHorizontal ?? ChannelViews.icon(pi, "Pencil");
5622
+ const members = membersOf(team, channel);
5623
+ const models = new Set(members.map((agent) => agent.model ?? ""));
5624
+ const shared = models.size === 1 ? [...models][0] : undefined;
5625
+ const muted = channel.muted ?? [];
5626
+ const run = (key, action2) => {
5627
+ setBusy(key);
5628
+ action2().catch((error) => pi.ui.notify(ChannelViews.message(error), "error")).finally(() => setBusy(undefined));
5629
+ };
5630
+ const change = (agent, kind) => run(`${kind}:${agent.id}`, () => service.changeMember(channel.id, agent.id, kind));
5631
+ const reset = (agent) => run(`reset:${agent.id}`, async () => {
5632
+ await service.resetAgent(agent.id);
5633
+ context.sessions.delete(agent.id);
5634
+ pi.ui.notify(ChannelWords.format(w.resetDone, { name: agent.name }), "info");
5635
+ });
5636
+ const remove = () => run("delete", () => service.deleteChannel(channel.id));
5637
+ const setModel = (model) => run("model", async () => {
5638
+ await service.setChannelModel(channel.id, model);
5639
+ pi.ui.notify(ChannelWords.format(w.modelSwitched, { count: String(members.length) }), "info");
5640
+ });
5641
+ return /* @__PURE__ */ React.createElement("div", {
5642
+ className: "tac-view tac-members"
5643
+ }, /* @__PURE__ */ React.createElement("div", {
5644
+ className: "tac-members-scroll"
5645
+ }, /* @__PURE__ */ React.createElement("div", {
5646
+ className: "tac-members-top"
5647
+ }, /* @__PURE__ */ React.createElement(RoomFace, {
5648
+ members,
5649
+ faces,
5650
+ size: 44,
5651
+ working
5652
+ }), /* @__PURE__ */ React.createElement("span", {
5653
+ className: "tac-members-title"
5654
+ }, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", null, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(members.length) })))), /* @__PURE__ */ React.createElement("div", {
5655
+ className: "tac-members-label"
5656
+ }, /* @__PURE__ */ React.createElement("span", null, w.members, " · ", members.length), /* @__PURE__ */ React.createElement("span", {
5657
+ className: "tac-members-model",
5658
+ title: w.sameModelHint
5659
+ }, /* @__PURE__ */ React.createElement("span", null, w.sameModel), /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
5660
+ value: shared ?? "",
5661
+ defaultLabel: shared === undefined ? w.mixedModels : undefined,
5662
+ label: w.sameModelHint,
5663
+ disabled: !!busy,
5664
+ onChange: setModel
5665
+ }))), /* @__PURE__ */ React.createElement("button", {
5666
+ type: "button",
5667
+ className: "tac-member-main",
5668
+ onClick: () => ui.set({ adding: true })
5669
+ }, /* @__PURE__ */ React.createElement("span", {
5670
+ className: "tac-member-plus"
5671
+ }, /* @__PURE__ */ React.createElement(UserPlus, {
5672
+ size: 16
5673
+ })), /* @__PURE__ */ React.createElement("span", {
5674
+ className: "tac-member-text"
5675
+ }, /* @__PURE__ */ React.createElement("span", {
5676
+ className: "tac-member-name"
5677
+ }, w.addMembers))), pi.rooms && channel.by !== "ta" && /* @__PURE__ */ React.createElement("button", {
5678
+ type: "button",
5679
+ className: "tac-member-main",
5680
+ onClick: () => openShareGroup(context, channel)
5681
+ }, /* @__PURE__ */ React.createElement("span", {
5682
+ className: "tac-member-plus"
5683
+ }, /* @__PURE__ */ React.createElement(Contact, {
5684
+ size: 16
5685
+ })), /* @__PURE__ */ React.createElement("span", {
5686
+ className: "tac-member-text"
5687
+ }, /* @__PURE__ */ React.createElement("span", {
5688
+ className: "tac-member-name"
5689
+ }, w.inviteFriends))), members.map((agent, index) => {
5690
+ const lead = index === 0;
5691
+ const off = muted.includes(agent.id);
5692
+ const answering = working.includes(agent.id);
5693
+ const detail = answering ? w.replying : off ? w.muted : agent.role.split(`
5694
+ `)[0] ?? "";
5695
+ return /* @__PURE__ */ React.createElement("div", {
5696
+ key: agent.id,
5697
+ className: `tac-member${off ? " tac-muted" : ""}`
5698
+ }, /* @__PURE__ */ React.createElement("button", {
5699
+ type: "button",
5700
+ className: "tac-member-main",
5701
+ title: `${w.open}
5702
+ ${agent.role}`,
5703
+ onClick: () => ChannelViews.openAgent(context, agent.id).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"))
5704
+ }, /* @__PURE__ */ React.createElement(AgentAvatar, {
5705
+ agent,
5706
+ faces,
5707
+ size: 32,
5708
+ working: answering
5709
+ }), /* @__PURE__ */ React.createElement("span", {
5710
+ className: "tac-member-text"
5711
+ }, /* @__PURE__ */ React.createElement("span", {
5712
+ className: "tac-member-name"
5713
+ }, /* @__PURE__ */ React.createElement("span", {
5714
+ className: "tac-member-label"
5715
+ }, agent.name), lead && /* @__PURE__ */ React.createElement("span", {
5716
+ className: "tac-lead",
5717
+ title: w.leadHint
5718
+ }, /* @__PURE__ */ React.createElement(Crown, {
5719
+ size: 11
5720
+ }), /* @__PURE__ */ React.createElement("span", null, w.lead)), agent.temporary && /* @__PURE__ */ React.createElement("span", {
5721
+ className: "tac-temporary",
5722
+ title: w.temporary
5723
+ }, w.temporaryTag)), /* @__PURE__ */ React.createElement("span", {
5724
+ className: `tac-member-detail${answering ? " tac-live" : ""}`
5725
+ }, detail))), /* @__PURE__ */ React.createElement("span", {
5726
+ className: "tac-member-actions"
5727
+ }, /* @__PURE__ */ React.createElement("button", {
5728
+ type: "button",
5729
+ className: "tac-action",
5730
+ title: w.agentSettings,
5731
+ "aria-label": `${w.agentSettings} · ${agent.name}`,
5732
+ disabled: !!busy,
5733
+ onClick: () => setEditing(agent)
5734
+ }, /* @__PURE__ */ React.createElement(Sliders, {
5735
+ size: 15
5736
+ })), agent.temporary && /* @__PURE__ */ React.createElement("button", {
5737
+ type: "button",
5738
+ className: "tac-action",
5739
+ title: w.keep,
5740
+ "aria-label": w.keep,
5741
+ disabled: !!busy,
5742
+ onClick: () => service.updateAgent(agent.id, { keep: true }).then(() => pi.ui.notify(ChannelWords.format(w.kept, { name: agent.name }), "info")).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"))
5743
+ }, /* @__PURE__ */ React.createElement(UserPlus, {
5744
+ size: 15
5745
+ })), !lead && /* @__PURE__ */ React.createElement("button", {
5746
+ type: "button",
5747
+ className: "tac-action",
5748
+ title: w.makeLead,
5749
+ "aria-label": w.makeLead,
5750
+ disabled: !!busy,
5751
+ onClick: () => change(agent, "lead")
5752
+ }, /* @__PURE__ */ React.createElement(Crown, {
5753
+ size: 15
5754
+ })), /* @__PURE__ */ React.createElement("button", {
5755
+ type: "button",
5756
+ className: `tac-action${off ? " tac-on" : ""}`,
5757
+ title: off ? w.unmute : w.mute,
5758
+ "aria-label": off ? w.unmute : w.mute,
5759
+ "aria-pressed": off,
5760
+ disabled: !!busy,
5761
+ onClick: () => change(agent, off ? "unmute" : "mute")
5762
+ }, /* @__PURE__ */ React.createElement(BellOff, {
5763
+ size: 15
5764
+ })), /* @__PURE__ */ React.createElement("button", {
5765
+ type: "button",
5766
+ className: "tac-action",
5767
+ title: w.reset,
5768
+ "aria-label": w.reset,
5769
+ disabled: !!busy,
5770
+ onClick: () => reset(agent)
5771
+ }, /* @__PURE__ */ React.createElement(RotateCcw, {
5772
+ size: 15
5773
+ })), /* @__PURE__ */ React.createElement("button", {
5774
+ type: "button",
5775
+ className: "tac-action",
5776
+ title: members.length === 1 ? w.onlyMember : w.remove,
5777
+ "aria-label": w.remove,
5778
+ disabled: !!busy || members.length === 1,
5779
+ onClick: () => change(agent, "remove")
5780
+ }, /* @__PURE__ */ React.createElement(X, {
5781
+ size: 15
5782
+ }))));
5783
+ }), /* @__PURE__ */ React.createElement(ChannelSettings, {
5784
+ context,
5785
+ channel
5786
+ })), editing && /* @__PURE__ */ React.createElement(AgentSettingsDialog, {
5787
+ context,
5788
+ agent: editing,
5789
+ onClose: () => setEditing(undefined)
5790
+ }), /* @__PURE__ */ React.createElement("div", {
5791
+ className: "tac-members-foot"
5792
+ }, confirming ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
5793
+ className: "tac-members-ask"
5794
+ }, ChannelWords.format(w.confirmDelete, { channel: channel.name })), /* @__PURE__ */ React.createElement("button", {
5795
+ type: "button",
5796
+ className: "tac-button",
5797
+ onClick: () => setConfirming(false)
5798
+ }, w.cancel), /* @__PURE__ */ React.createElement("button", {
5799
+ type: "button",
5800
+ className: busy === "delete" ? "tac-button tac-danger ta-busy" : "tac-button tac-danger",
5801
+ disabled: !!busy,
5802
+ onClick: remove
5803
+ }, w.delete, busy === "delete" && /* @__PURE__ */ React.createElement("span", {
5804
+ className: "ta-spinner ta-busy-mark"
5805
+ }))) : /* @__PURE__ */ React.createElement("button", {
5806
+ type: "button",
5807
+ className: "tac-link tac-danger",
5808
+ onClick: () => setConfirming(true)
5809
+ }, /* @__PURE__ */ React.createElement(Trash, {
5810
+ size: 14
5811
+ }), w.deleteChannel)));
5084
5812
  }
5085
- function taskTitle(channel) {
5086
- return channel.name;
5087
- }
5088
- async function deleteTeam(context, channel) {
5089
- await context.service.deleteChannel(channel.id);
5090
- context.pi.ui.closeEditor(`channel:${channel.id}`);
5091
- }
5092
- function openScene(context, channel) {
5093
- context.pi.ui.openEditor({
5094
- id: `channel:${channel.id}`,
5095
- title: channel.name,
5096
- icon: ChannelViews.icon(context.pi, "Hash"),
5097
- render: () => /* @__PURE__ */ React.createElement("div", {
5098
- className: "tac-scene"
5099
- }, /* @__PURE__ */ React.createElement(ChannelSceneHead, {
5100
- context,
5101
- channelId: channel.id
5102
- }), /* @__PURE__ */ React.createElement(ChannelRoom, {
5103
- context,
5104
- channelId: channel.id
5105
- }))
5106
- });
5107
- }
5108
- function taskMenu(context, channel, working) {
5813
+ function ChannelSettings({ context, channel }) {
5109
5814
  const { pi, service } = context;
5110
5815
  const w = ChannelViews.words(pi);
5111
- const icon = (name) => ChannelViews.icon(pi, name);
5112
- const act = (action2) => () => {
5113
- Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
5114
- };
5115
- const temporary = membersOf(service.state.team, channel).filter((agent) => agent.temporary);
5116
- return [
5117
- working.length > 0 ? [
5118
- {
5119
- key: "stop",
5120
- label: w.stopAnswering,
5121
- icon: icon("Square"),
5122
- run: act(async () => {
5123
- await TeamActions.stop(context, working);
5124
- pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info");
5125
- })
5126
- }
5127
- ] : [],
5128
- [
5129
- { key: "main", label: w.openInMain, icon: icon("ExternalLink"), run: () => context.showChannel(channel.id) },
5130
- ...temporary.length > 0 ? [
5131
- {
5132
- key: "keep",
5133
- label: w.keepMembers,
5134
- icon: icon("UserPlus"),
5135
- run: act(async () => {
5136
- await TeamActions.keep(context, temporary);
5137
- pi.ui.notify(ChannelWords.format(w.keptMembers, { names: temporary.map((agent) => `@${agent.name}`).join("、") }), "info");
5138
- })
5139
- }
5140
- ] : []
5141
- ],
5142
- [
5143
- {
5144
- key: "delete",
5145
- label: w.deleteTask,
5146
- icon: icon("Trash2"),
5147
- danger: true,
5148
- run: act(() => pi.ui.removeTasks([
5149
- {
5150
- title: taskTitle(channel),
5151
- removeHint: ChannelWords.format(w.deleteTaskHint, { channel: channel.name }),
5152
- remove: () => deleteTeam(context, channel)
5153
- }
5154
- ]))
5155
- }
5156
- ]
5157
- ];
5158
- }
5159
- var TeamActions;
5160
- ((TeamActions) => {
5161
- async function stop(context, agentIds) {
5162
- const { pi, service } = context;
5163
- const files = new Set(service.state.team.agents.filter((agent) => agentIds.includes(agent.id) && agent.sessionFile).map((agent) => agent.sessionFile));
5164
- const sessions = (await pi.server.listSessions()).filter((session) => session.sessionFile && files.has(session.sessionFile));
5165
- await Promise.all(sessions.map((session) => pi.server.abort(session.sessionId)));
5166
- }
5167
- TeamActions.stop = stop;
5168
- async function keep(context, agents) {
5169
- for (const agent of agents) {
5170
- await context.service.updateAgent(agent.id, { keep: true });
5171
- }
5172
- }
5173
- TeamActions.keep = keep;
5174
- })(TeamActions ||= {});
5175
-
5176
- // web-src/channel-menu.tsx
5177
- function download2(name, text) {
5178
- const url = URL.createObjectURL(new Blob([text], { type: "text/markdown;charset=utf-8" }));
5179
- const link = document.createElement("a");
5180
- link.href = url;
5181
- link.download = name;
5182
- link.click();
5183
- setTimeout(() => URL.revokeObjectURL(url), 1000);
5816
+ const Chevron = ChannelViews.icon(pi, "ChevronRight");
5817
+ const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
5818
+ const row = (label, value, edit) => /* @__PURE__ */ React.createElement("button", {
5819
+ type: "button",
5820
+ className: "tac-setting",
5821
+ onClick: () => edit().catch(fail)
5822
+ }, /* @__PURE__ */ React.createElement("span", {
5823
+ className: "tac-setting-label"
5824
+ }, label), /* @__PURE__ */ React.createElement("span", {
5825
+ className: "tac-setting-value"
5826
+ }, value), /* @__PURE__ */ React.createElement(Chevron, {
5827
+ size: 15
5828
+ }));
5829
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
5830
+ className: "tac-members-sep"
5831
+ }), row(w.channelName, channel.name, () => renameChannel(context, channel)), row(w.topic, channel.topic ?? w.notSet, () => editChannelTopic(context, channel)), /* @__PURE__ */ React.createElement("div", {
5832
+ className: "tac-setting"
5833
+ }, /* @__PURE__ */ React.createElement("span", {
5834
+ className: "tac-setting-label"
5835
+ }, w.pinChat), /* @__PURE__ */ React.createElement(pi.ui.Switch, {
5836
+ checked: !!channel.pinned,
5837
+ label: w.pinChat,
5838
+ onChange: (pinned) => service.updateChannel(channel.id, { pinned }).catch(fail)
5839
+ })), /* @__PURE__ */ React.createElement(ChannelLimits, {
5840
+ context,
5841
+ channel
5842
+ }));
5184
5843
  }
5185
- async function deleteChannel(context, channel) {
5186
- const w = ChannelViews.words(context.pi);
5187
- const sure = await context.pi.ui.confirm(ChannelWords.format(w.confirmDelete, { channel: channel.name }), undefined, {
5188
- confirmLabel: w.delete,
5189
- danger: true
5190
- });
5191
- if (sure) {
5192
- await context.service.deleteChannel(channel.id);
5193
- }
5844
+ function ChannelLimits({ context, channel }) {
5845
+ const { pi, service } = context;
5846
+ const w = ChannelViews.words(pi);
5847
+ const { limits, channels } = useLimits(pi);
5848
+ const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
5849
+ const budget = ChannelsUtil.budgetOf(channel);
5850
+ const budgets = [
5851
+ ["short", w.budgetShortWord],
5852
+ ["normal", w.budgetNormalWord],
5853
+ ["long", w.budgetLongWord]
5854
+ ];
5855
+ const daily = [null, ...LIMIT_CHOICES.channelDay];
5856
+ const own = channel.dailyLimit ?? null;
5857
+ const limit = channel.dailyLimit ?? limits.channelDay;
5858
+ const spent = channels[channel.id] ?? 0;
5859
+ const segment = (label, values, current, word, pick) => /* @__PURE__ */ React.createElement("fieldset", {
5860
+ className: "ta-segmented tac-limit-segments",
5861
+ "aria-label": label
5862
+ }, values.map((value) => /* @__PURE__ */ React.createElement("button", {
5863
+ key: String(value),
5864
+ type: "button",
5865
+ "aria-pressed": value === current,
5866
+ className: value === current ? "ta-on" : "",
5867
+ onClick: () => value !== current && pick(value)
5868
+ }, word(value))));
5869
+ return /* @__PURE__ */ React.createElement("div", {
5870
+ className: "tac-limits"
5871
+ }, /* @__PURE__ */ React.createElement("div", {
5872
+ className: "tac-limit-head"
5873
+ }, /* @__PURE__ */ React.createElement("span", null, w.talkLength)), segment(w.talkLength, budgets.map(([key]) => key), budget, (key) => budgets.find(([other]) => other === key)?.[1] ?? key, (key) => service.updateChannel(channel.id, { budget: key }).catch(fail)), /* @__PURE__ */ React.createElement("div", {
5874
+ className: "tac-limit-head"
5875
+ }, /* @__PURE__ */ React.createElement("span", null, w.dailyLimit), /* @__PURE__ */ React.createElement("span", {
5876
+ className: "tac-limit-spent"
5877
+ }, ChannelWords.format(limit > 0 ? w.dailySpentOf : w.dailySpent, {
5878
+ spent: amount(pi, spent) === w.noLimit ? "0" : amount(pi, spent),
5879
+ limit: amount(pi, limit)
5880
+ }))), segment(w.dailyLimit, daily, own, (value) => value === null ? w.limitDefault : amount(pi, value), (value) => service.updateChannel(channel.id, { dailyLimit: value }).catch(fail)));
5194
5881
  }
5195
- function ChannelMenu({ context, channel, working }) {
5882
+ function MemberPicker({ context, team, channel, faces }) {
5196
5883
  const { pi, service, ui } = context;
5197
- const { fresh } = useUi(ui);
5198
5884
  const w = ChannelViews.words(pi);
5199
- const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
5200
- const act = (action2) => () => {
5201
- Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
5202
- };
5203
- const unread = fresh.includes(channel.id);
5204
- const pin = act(() => service.updateChannel(channel.id, { pinned: !channel.pinned }));
5205
- const markRead = act(() => ui.set({ fresh: unread ? fresh.filter((id) => id !== channel.id) : [...fresh, channel.id] }));
5206
- const rename = act(async () => {
5207
- const name = await pi.ui.input(ChannelWords.format(w.renameChannel, { channel: channel.name }), w.channelNamePlaceholder, { value: channel.name });
5208
- if (name !== undefined && name.trim() !== channel.name) {
5209
- await service.updateChannel(channel.id, { name });
5210
- }
5211
- });
5212
- const editTopic = act(async () => {
5213
- const topic = await pi.ui.input(w.editTopic, w.topicPlaceholder, { value: channel.topic ?? "" });
5214
- if (topic !== undefined && topic.trim() !== (channel.topic ?? "")) {
5215
- await service.updateChannel(channel.id, { topic });
5216
- }
5217
- });
5218
- const members = act(() => {
5219
- context.showChannel(channel.id);
5220
- context.showMembers();
5221
- });
5222
- const stop = act(async () => {
5223
- await TeamActions.stop(context, working);
5224
- pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info");
5225
- });
5226
- const exportMarkdown = act(async () => {
5227
- const messages = await service.messages(channel.id);
5228
- if (!messages.some((message) => message.text.trim())) {
5229
- pi.ui.notify(ChannelWords.format(w.noMessagesToExport, { channel: channel.name }), "info");
5230
- return;
5231
- }
5232
- download2(`${channel.name}.md`, ChannelsText.channelMarkdown(service.state.team, channel, messages, { user: w.you, ta: w.ta }));
5233
- });
5234
- const remove = act(() => deleteChannel(context, channel));
5235
- const item = (key, label, glyph, run, options = {}) => ({
5236
- key,
5237
- label,
5238
- icon: icon(glyph),
5239
- run,
5240
- ...options
5241
- });
5242
- return /* @__PURE__ */ React.createElement(MoreMenu, {
5243
- pi,
5244
- label: channel.name,
5245
- items: () => [
5246
- [
5247
- item("pin", channel.pinned ? w.unpin : w.pin, channel.pinned ? "PinOff" : "Pin", pin),
5248
- item("read", unread ? w.markRead : w.markUnread, unread ? "MessageSquareText" : "MessageSquareDot", markRead)
5249
- ],
5250
- [item("rename", w.rename, "Pencil", rename), item("topic", w.editTopic, "Text", editTopic), item("members", w.showMembers, "Users", members)],
5251
- [item("stop", w.stopAnswering, "Square", stop, { disabled: working.length === 0 }), item("export", w.exportChat, "Download", exportMarkdown)],
5252
- [item("delete", w.deleteChannel, "Trash2", remove, { danger: true })]
5253
- ]
5254
- });
5885
+ const [query, setQuery] = React.useState("");
5886
+ const [picked, setPicked] = React.useState([]);
5887
+ const ArrowLeft = ChannelViews.icon(pi, "ArrowLeft");
5888
+ const Search = ChannelViews.icon(pi, "Search");
5889
+ const Check = ChannelViews.icon(pi, "Check");
5890
+ const UserPlus = ChannelViews.icon(pi, "UserPlus");
5891
+ const back = () => ui.set({ adding: false });
5892
+ const { busy, error, submit } = useSubmit(() => service.addMembers(channel.id, picked), back);
5893
+ const others = team.agents.filter((agent) => !channel.members.includes(agent.id));
5894
+ const shown = others.filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
5895
+ const toggle = (id) => setPicked(picked.includes(id) ? picked.filter((other) => other !== id) : [...picked, id]);
5896
+ return /* @__PURE__ */ React.createElement("div", {
5897
+ className: "tac-view tac-members"
5898
+ }, /* @__PURE__ */ React.createElement("div", {
5899
+ className: "tac-members-head"
5900
+ }, /* @__PURE__ */ React.createElement("button", {
5901
+ type: "button",
5902
+ className: "tac-action",
5903
+ title: w.back,
5904
+ "aria-label": w.back,
5905
+ onClick: back
5906
+ }, /* @__PURE__ */ React.createElement(ArrowLeft, {
5907
+ size: 16
5908
+ })), /* @__PURE__ */ React.createElement("strong", null, w.addMembers)), /* @__PURE__ */ React.createElement("label", {
5909
+ className: "tac-search tac-members-search"
5910
+ }, /* @__PURE__ */ React.createElement(Search, {
5911
+ size: 14
5912
+ }), /* @__PURE__ */ React.createElement("input", {
5913
+ value: query,
5914
+ placeholder: w.findAgent,
5915
+ "aria-label": w.findAgent,
5916
+ onChange: (event) => setQuery(event.target.value)
5917
+ })), /* @__PURE__ */ React.createElement("div", {
5918
+ className: "tac-members-scroll"
5919
+ }, /* @__PURE__ */ React.createElement("div", {
5920
+ className: "tac-members-label"
5921
+ }, ChannelWords.format(w.canAdd, { count: String(others.length) })), others.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
5922
+ compact: true,
5923
+ title: w.allMembers
5924
+ }), others.length > 0 && shown.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
5925
+ compact: true,
5926
+ title: w.noMatch
5927
+ }), shown.map((agent) => {
5928
+ const on = picked.includes(agent.id);
5929
+ return /* @__PURE__ */ React.createElement("button", {
5930
+ key: agent.id,
5931
+ type: "button",
5932
+ className: `tac-member-main tac-pick${on ? " tac-on" : ""}`,
5933
+ "aria-pressed": on,
5934
+ title: agent.role,
5935
+ onClick: () => toggle(agent.id)
5936
+ }, /* @__PURE__ */ React.createElement(AgentAvatar, {
5937
+ agent,
5938
+ faces,
5939
+ size: 32
5940
+ }), /* @__PURE__ */ React.createElement("span", {
5941
+ className: "tac-member-text"
5942
+ }, /* @__PURE__ */ React.createElement("span", {
5943
+ className: "tac-member-name"
5944
+ }, /* @__PURE__ */ React.createElement("span", {
5945
+ className: "tac-member-label"
5946
+ }, agent.name)), /* @__PURE__ */ React.createElement("span", {
5947
+ className: "tac-member-detail"
5948
+ }, agent.role.split(`
5949
+ `)[0])), /* @__PURE__ */ React.createElement("span", {
5950
+ className: "tac-check"
5951
+ }, on && /* @__PURE__ */ React.createElement(Check, {
5952
+ size: 12,
5953
+ strokeWidth: 3
5954
+ })));
5955
+ }), /* @__PURE__ */ React.createElement("div", {
5956
+ className: "tac-members-sep"
5957
+ }), /* @__PURE__ */ React.createElement("button", {
5958
+ type: "button",
5959
+ className: "tac-member-main",
5960
+ onClick: () => newAgent(context)
5961
+ }, /* @__PURE__ */ React.createElement("span", {
5962
+ className: "tac-member-plus"
5963
+ }, /* @__PURE__ */ React.createElement(UserPlus, {
5964
+ size: 16
5965
+ })), /* @__PURE__ */ React.createElement("span", {
5966
+ className: "tac-member-text"
5967
+ }, /* @__PURE__ */ React.createElement("span", {
5968
+ className: "tac-member-name"
5969
+ }, w.newAgent)))), error && /* @__PURE__ */ React.createElement("div", {
5970
+ className: "tac-empty tac-error"
5971
+ }, error), /* @__PURE__ */ React.createElement("div", {
5972
+ className: "tac-members-foot"
5973
+ }, /* @__PURE__ */ React.createElement("button", {
5974
+ type: "button",
5975
+ className: busy ? "tac-button tac-primary tac-wide ta-busy" : "tac-button tac-primary tac-wide",
5976
+ disabled: busy || picked.length === 0,
5977
+ onClick: submit
5978
+ }, picked.length > 0 ? ChannelWords.format(w.addCount, { count: String(picked.length) }) : w.add, busy && /* @__PURE__ */ React.createElement("span", {
5979
+ className: "ta-spinner ta-busy-mark ta-on-brand"
5980
+ }))));
5255
5981
  }
5256
5982
 
5257
5983
  // web-src/sidebar-hooks.ts
@@ -5617,13 +6343,13 @@ function TaskItem({ context, task, selection, seen }) {
5617
6343
  })
5618
6344
  });
5619
6345
  }
5620
- function HomeRow({ pi, item }) {
6346
+ function HomeRow({ pi, item, selected = false }) {
5621
6347
  const [opening, setOpening] = React.useState(false);
5622
6348
  const Glyph = item.icon;
5623
6349
  const Own = item.face;
5624
6350
  const open = () => {
5625
6351
  setOpening(true);
5626
- Promise.resolve().then(() => item.open()).catch((error) => pi.ui.notify(ChannelViews.message(error), "error")).finally(() => setOpening(false));
6352
+ Promise.resolve().then(() => pi.ui.openHome ? pi.ui.openHome(item) : item.open()).catch((error) => pi.ui.notify(ChannelViews.message(error), "error")).finally(() => setOpening(false));
5627
6353
  };
5628
6354
  return /* @__PURE__ */ React.createElement(Row, {
5629
6355
  pi,
@@ -5643,7 +6369,7 @@ function HomeRow({ pi, item }) {
5643
6369
  fresh: item.unseen,
5644
6370
  dot: item.unseen ? "attention" : undefined,
5645
6371
  time: item.at ? SidebarUtil.time(item.at, pi.ui.language) : "",
5646
- selected: false,
6372
+ selected,
5647
6373
  onSelect: open
5648
6374
  });
5649
6375
  }
@@ -5663,6 +6389,7 @@ function AgentsSidebar({ context, partners = false }) {
5663
6389
  const agentPage = pi.ui.useView(AGENT_PAGE);
5664
6390
  const tasks = pi.ui.useTasks();
5665
6391
  const homeItems = pi.ui.useHomeItems?.() ?? NO_HOME_ITEMS;
6392
+ const shownHome = pi.ui.useHomeShown?.();
5666
6393
  const homeShown = homeItems.filter((item) => SidebarUtil.matches(query, item.title, item.detail));
5667
6394
  const homeSections = SidebarUtil.homeSections(partners ? homeShown.filter((item) => SidebarUtil.place(item) === "partners") : homeShown);
5668
6395
  const partnerTop = partners ? homeShown.filter((item) => SidebarUtil.place(item) === "partners" && !item.section) : [];
@@ -5690,7 +6417,7 @@ function AgentsSidebar({ context, partners = false }) {
5690
6417
  const answering = React.useMemo(() => SidebarUtil.answering(team.agents, openSessions, context.sessions), [team.agents, openSessions, context.sessions]);
5691
6418
  const asking = React.useMemo(() => SidebarUtil.waiting(team.agents, openSessions, context.sessions), [team.agents, openSessions, context.sessions]);
5692
6419
  const doubleBusy = !!double?.busy;
5693
- const pageShown = !!double?.shown || !!channelPage?.shown || !!agentPage?.shown;
6420
+ const pageShown = !!double?.shown || !!channelPage?.shown || !!agentPage?.shown || !!shownHome;
5694
6421
  const shownFile = shownSession ? openSessions.find((session) => session.sessionId === shownSession)?.sessionFile : undefined;
5695
6422
  const shownAgent = pageShown ? undefined : team.agents.find((agent) => !!shownSession && context.sessions.get(agent.id) === shownSession || !!shownFile && agent.sessionFile === shownFile)?.id;
5696
6423
  const doubleAt = double?.preview?.at;
@@ -5793,7 +6520,8 @@ function AgentsSidebar({ context, partners = false }) {
5793
6520
  })), (partners ? partnerTop : homeShown.filter((item) => !item.section)).map((item) => /* @__PURE__ */ React.createElement(HomeRow, {
5794
6521
  key: item.key,
5795
6522
  pi,
5796
- item
6523
+ item,
6524
+ selected: item.key === shownHome
5797
6525
  })), draft && /* @__PURE__ */ React.createElement(Row, {
5798
6526
  pi,
5799
6527
  avatar: /* @__PURE__ */ React.createElement(Face, {
@@ -5865,7 +6593,8 @@ function AgentsSidebar({ context, partners = false }) {
5865
6593
  return /* @__PURE__ */ React.createElement(HomeRow, {
5866
6594
  key: entry.item.key,
5867
6595
  pi,
5868
- item: entry.item
6596
+ item: entry.item,
6597
+ selected: entry.item.key === shownHome
5869
6598
  });
5870
6599
  }
5871
6600
  const { channel } = entry;
@@ -5982,7 +6711,8 @@ function AgentsSidebar({ context, partners = false }) {
5982
6711
  }, section.items.map((item) => /* @__PURE__ */ React.createElement(HomeRow, {
5983
6712
  key: item.key,
5984
6713
  pi,
5985
- item
6714
+ item,
6715
+ selected: item.key === shownHome
5986
6716
  }))))), selection.selecting && SelectBar && /* @__PURE__ */ React.createElement(SelectBar, {
5987
6717
  count: selection.selected.length,
5988
6718
  total: selection.removable.length,
@@ -6164,6 +6894,23 @@ var STYLE = `
6164
6894
  .tac-msg-failed { margin-bottom: 4px; color: var(--ta-red); font-size: calc(12px * var(--ta-font-scale)); }
6165
6895
  .tac-msg-bubble pre { max-width: 100%; overflow-x: auto; }
6166
6896
  .tac-mention { color: var(--ta-link); }
6897
+ .tac-menu-blank { display: inline-block; flex: none; width: 15px; height: 15px; }
6898
+ .tac-stop { align-self: center; display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 10px 0; }
6899
+ .tac-stop .tac-notice { margin: 0; text-align: center; }
6900
+ .tac-stop-meta { max-width: 100%; padding: 0 12px; color: var(--ta-muted); font-size: calc(11.5px * var(--ta-font-scale)); text-align: center; }
6901
+ .tac-msg-over { margin-bottom: 4px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
6902
+ .tac-limits { display: flex; flex-direction: column; gap: 6px; padding: 6px 10px 4px; }
6903
+ .tac-limit-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 4px; color: var(--ta-text); font-size: calc(13.5px * var(--ta-font-scale)); }
6904
+ .tac-limit-head .tac-limit-spent { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
6905
+ .tac-limit-segments { width: 100%; }
6906
+ .tac-limit-segments > button { flex: 1; min-width: 0; padding-left: 4px; padding-right: 4px; white-space: nowrap; }
6907
+ .tac-limit-spent { color: var(--ta-secondary); font-variant-numeric: tabular-nums; }
6908
+ .tac-stop-meta:empty { display: none; }
6909
+ .tac-stop-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
6910
+ .tac-stop-button { padding: 4px 12px; border: 1px solid var(--ta-border-muted); border-radius: 999px; background: var(--ta-raised, var(--ta-main)); color: var(--ta-text); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background 120ms; }
6911
+ @media (hover: hover) { .tac-stop-button:hover:not(:disabled) { background: var(--ta-hover); } }
6912
+ .tac-stop-button:active:not(:disabled) { background: var(--ta-hover); }
6913
+ .tac-stop-button:disabled { opacity: 0.5; cursor: default; }
6167
6914
  .tac-notice { align-self: center; margin: 10px 0; padding: 3px 10px; border-radius: 999px; background: var(--ta-hover); color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
6168
6915
  /* The notice of a channel (notice.tsx): a line over the chat, open to read and to write */
6169
6916
  .tac-notice-bar { flex: none; width: 100%; max-width: calc(var(--ta-col) + 48px); margin: 0 auto; padding: 8px 24px 0; box-sizing: border-box; }
@@ -6350,6 +7097,22 @@ textarea.tac-input { resize: vertical; min-height: 56px; line-height: 1.5; }
6350
7097
  .tac-pick.tac-on .tac-check { border-color: var(--ta-green); background: var(--ta-green); }
6351
7098
  .tac-members-foot { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex: none; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--ta-border-muted); }
6352
7099
  .tac-members-ask { flex: 1; min-width: 0; color: var(--ta-body); font-size: calc(12.5px * var(--ta-font-scale)); }
7100
+ .tac-members-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
7101
+ .tac-members-model { display: inline-flex; align-items: center; gap: 2px; min-width: 0; }
7102
+ .tac-members-model > span { flex: none; }
7103
+ .tac-members-model .ta-model-field { max-width: 150px; height: 24px; padding: 0 4px 0 6px; border: 0; border-radius: 6px; background: none; color: var(--ta-secondary); font-size: calc(12px * var(--ta-font-scale)); }
7104
+ .tac-members-model .ta-model-field:not(:disabled):hover { background: var(--ta-hover); color: var(--ta-text); }
7105
+ .tac-members-model .ta-model-field > svg { width: 13px; height: 13px; }
7106
+ .tac-setting { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 0 10px; border: 0; border-radius: 10px; background: none; color: var(--ta-text); font: inherit; font-size: calc(13.5px * var(--ta-font-scale)); text-align: left; box-sizing: border-box; }
7107
+ button.tac-setting { cursor: pointer; }
7108
+ button.tac-setting:hover { background: var(--ta-hover); }
7109
+ button.tac-setting:focus-visible { outline: 1px solid var(--ta-border-focus); outline-offset: -1px; }
7110
+ .tac-setting > svg { flex: none; color: var(--ta-muted); }
7111
+ .tac-setting-label { flex: 1; min-width: 0; }
7112
+ .tac-setting-value { flex: none; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; color: var(--ta-muted); }
7113
+ .tac-dialog-field { display: flex; flex-direction: column; gap: 8px; color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); }
7114
+ .tac-dialog-field .ta-model-field { width: 100%; height: 40px; padding: 0 12px; border-radius: 8px; font-size: calc(14px * var(--ta-font-scale)); }
7115
+ textarea.tac-settings-role { min-height: 120px; max-height: 40vh; line-height: 1.6; }
6353
7116
  .tac-button.tac-wide { flex: 1; height: 36px; border-radius: 10px; font-size: calc(13.5px * var(--ta-font-scale)); }
6354
7117
  @media (hover: none) {
6355
7118
  .tac-member-actions { opacity: 1; }
@@ -6631,6 +7394,7 @@ function activate(pi) {
6631
7394
  }
6632
7395
  };
6633
7396
  pi.registerTasks(tasks);
7397
+ pi.registerSettings(limitSettings(pi, service));
6634
7398
  new ChannelToolLines(context).register();
6635
7399
  pi.registerMessageRenderer(HandOff.CARD, HandOffView.card(context));
6636
7400
  pi.registerComposerAddon(HandOffView.composerAddon(context));