@celljs/ta-channels 4.21.0 → 4.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -0
- package/README.md +1 -1
- package/extension/index.mjs +79 -13
- package/host/index.mjs +402 -143
- package/package.json +4 -4
- package/web/index.js +2320 -1750
package/web/index.js
CHANGED
|
@@ -144,6 +144,11 @@ var TaImageNote;
|
|
|
144
144
|
var TaImageSize;
|
|
145
145
|
(function(TaImageSize2) {
|
|
146
146
|
const JPEG_BYTES = 256 * 1024;
|
|
147
|
+
function type(bytes) {
|
|
148
|
+
const at = (offset, ...values) => values.every((value, index) => bytes[offset + index] === value);
|
|
149
|
+
return at(0, 255, 216, 255) ? "image/jpeg" : at(0, 137, 80, 78, 71) ? "image/png" : at(0, 71, 73, 70, 56) ? "image/gif" : at(0, 82, 73, 70, 70) && at(8, 87, 69, 66, 80) ? "image/webp" : undefined;
|
|
150
|
+
}
|
|
151
|
+
TaImageSize2.type = type;
|
|
147
152
|
function of(base64) {
|
|
148
153
|
var _a, _b, _c;
|
|
149
154
|
let bytes;
|
|
@@ -731,6 +736,9 @@ var BUDGETS = {
|
|
|
731
736
|
long: { tokens: 3000000, replies: 100 }
|
|
732
737
|
};
|
|
733
738
|
var DEFAULT_BUDGET = "normal";
|
|
739
|
+
var REPLIES = ["mentioned", "lead", "all"];
|
|
740
|
+
var DEFAULT_REPLY = "lead";
|
|
741
|
+
var PASS = "PASS";
|
|
734
742
|
var EXTEND_BY = 0.5;
|
|
735
743
|
var WATCH_MS = 30000;
|
|
736
744
|
var MAX_MESSAGES = 200;
|
|
@@ -745,6 +753,16 @@ var NOTICE_HEADINGS = { zh: ["决定", "约定", "待办"], en: ["Decisions", "C
|
|
|
745
753
|
// web-src/channels-util.ts
|
|
746
754
|
var ChannelsUtil;
|
|
747
755
|
((ChannelsUtil) => {
|
|
756
|
+
function may(team) {
|
|
757
|
+
const given = team.may;
|
|
758
|
+
return {
|
|
759
|
+
create: !given || given.create,
|
|
760
|
+
agent: (id) => !given || given.agents.includes(id),
|
|
761
|
+
manage: (id) => !given || given.manage.includes(id),
|
|
762
|
+
edit: (id) => !given || given.edit.includes(id)
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
ChannelsUtil.may = may;
|
|
748
766
|
function newRound() {
|
|
749
767
|
return { total: 0, tokens: 0, stopped: false };
|
|
750
768
|
}
|
|
@@ -1014,16 +1032,22 @@ var ChannelsUtil;
|
|
|
1014
1032
|
delete channel.pinned;
|
|
1015
1033
|
}
|
|
1016
1034
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1035
|
+
const choose = (key, choices, fallback, what) => {
|
|
1036
|
+
const value = input[key];
|
|
1037
|
+
if (value === undefined) {
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
if (typeof value !== "string" || !choices.includes(value)) {
|
|
1041
|
+
throw new Error(`${what} is one of ${choices.join(", ")}.`);
|
|
1020
1042
|
}
|
|
1021
|
-
if (
|
|
1022
|
-
delete channel
|
|
1043
|
+
if (value === fallback) {
|
|
1044
|
+
delete channel[key];
|
|
1023
1045
|
} else {
|
|
1024
|
-
channel
|
|
1046
|
+
channel[key] = value;
|
|
1025
1047
|
}
|
|
1026
|
-
}
|
|
1048
|
+
};
|
|
1049
|
+
choose("budget", Object.keys(BUDGETS), DEFAULT_BUDGET, "The budget of a channel");
|
|
1050
|
+
choose("reply", REPLIES, DEFAULT_REPLY, "Who answers what names nobody in a channel");
|
|
1027
1051
|
if (input.dailyLimit === null) {
|
|
1028
1052
|
delete channel.dailyLimit;
|
|
1029
1053
|
} else if (input.dailyLimit !== undefined) {
|
|
@@ -1032,6 +1056,12 @@ var ChannelsUtil;
|
|
|
1032
1056
|
}
|
|
1033
1057
|
channel.dailyLimit = input.dailyLimit;
|
|
1034
1058
|
}
|
|
1059
|
+
if (input.shared !== undefined) {
|
|
1060
|
+
if (typeof input.shared !== "string" || !input.shared) {
|
|
1061
|
+
throw new Error("The group chat a channel became is the id of a room.");
|
|
1062
|
+
}
|
|
1063
|
+
channel.shared = input.shared;
|
|
1064
|
+
}
|
|
1035
1065
|
return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, before };
|
|
1036
1066
|
}
|
|
1037
1067
|
ChannelsUtil.updateChannel = updateChannel;
|
|
@@ -1044,6 +1074,10 @@ var ChannelsUtil;
|
|
|
1044
1074
|
return team.channels.filter((channel) => channel.by === "ta");
|
|
1045
1075
|
}
|
|
1046
1076
|
ChannelsUtil.taskChannels = taskChannels;
|
|
1077
|
+
function liveChannels(team) {
|
|
1078
|
+
return ownChannels(team).filter((channel) => !channel.shared);
|
|
1079
|
+
}
|
|
1080
|
+
ChannelsUtil.liveChannels = liveChannels;
|
|
1047
1081
|
function ownChannels(team) {
|
|
1048
1082
|
return team.channels.filter((channel) => channel.by !== "ta");
|
|
1049
1083
|
}
|
|
@@ -1345,17 +1379,19 @@ var JA = {
|
|
|
1345
1379
|
topic: "トピック",
|
|
1346
1380
|
members: "メンバー",
|
|
1347
1381
|
addMembers: "メンバーを追加",
|
|
1348
|
-
|
|
1349
|
-
|
|
1382
|
+
mentionMember: "メンバー",
|
|
1383
|
+
makeExtension: "保存",
|
|
1384
|
+
makeExtensionDetail: "ここで決めたやり方をワンタップで再利用できるように保存",
|
|
1350
1385
|
makeExtensionAsk: "このグループチャットで作成された事項を拡張機能にする(ta-package スキルで)、将来は 1 クリックで再利用可能",
|
|
1351
1386
|
add: "追加",
|
|
1352
1387
|
allMembers: "すべてのエージェントがこのグループチャットに既に含まれています",
|
|
1353
|
-
membersHint: "
|
|
1388
|
+
membersHint: "最初に選択したメンバーがリーダー:Ta がグループに任せた仕事を受けます。答えてほしいエージェントは @ で指定します。",
|
|
1354
1389
|
create: "作成",
|
|
1355
1390
|
cancel: "キャンセル",
|
|
1356
1391
|
back: "戻る",
|
|
1357
1392
|
send: "送信",
|
|
1358
1393
|
you: "あなた",
|
|
1394
|
+
picture: "[画像]",
|
|
1359
1395
|
owner: "オーナー",
|
|
1360
1396
|
ta: "Ta",
|
|
1361
1397
|
lead: "リーダー",
|
|
@@ -1364,8 +1400,10 @@ var JA = {
|
|
|
1364
1400
|
noAgents: "まだエージェントがありません",
|
|
1365
1401
|
noAgentsHint: "グループチャットはエージェントで構成されます:最初に 1 つ作成",
|
|
1366
1402
|
pick: "グループチャットを選択",
|
|
1367
|
-
quiet: "まだメッセージがありません。@
|
|
1403
|
+
quiet: "まだメッセージがありません。@ で指定したエージェントが答えます。",
|
|
1368
1404
|
placeholder: "{channel} に送信;@ でメンバーを指定",
|
|
1405
|
+
placeholderLead: "{channel} に送信;@ なしは{lead}が回答",
|
|
1406
|
+
placeholderAll: "{channel} に送信;誰でも回答できます",
|
|
1369
1407
|
answering: "{name} が回答中",
|
|
1370
1408
|
failed: "回答がありません",
|
|
1371
1409
|
mention: "@{name}",
|
|
@@ -1392,6 +1430,10 @@ var JA = {
|
|
|
1392
1430
|
budgetShortWord: "短い",
|
|
1393
1431
|
budgetNormalWord: "標準",
|
|
1394
1432
|
budgetLongWord: "長い",
|
|
1433
|
+
replyHead: "@ なしのとき",
|
|
1434
|
+
replyMentionedWord: "@ のみ",
|
|
1435
|
+
replyLeadWord: "リーダー",
|
|
1436
|
+
replyAllWord: "全員",
|
|
1395
1437
|
dailyLimit: "1日の上限",
|
|
1396
1438
|
dailySpent: "今日 {spent}",
|
|
1397
1439
|
dailySpentOf: "今日 {spent} / {limit}",
|
|
@@ -1418,10 +1460,9 @@ var JA = {
|
|
|
1418
1460
|
agentTag: "エージェント",
|
|
1419
1461
|
noPartners: "まだ仲間がいません",
|
|
1420
1462
|
noPartnersHint: "+ でエージェントやグループチャットを作るか、友だちを追加して",
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
shareGroupHint: "同じ名前のグループチャットを作り、選んだ友だちと中継で暗号化して共有します。エージェントも一緒に入ります。ここの履歴はこのコンピュータに残り、友だちには送られません。",
|
|
1463
|
+
shareGroupHint: "このグループチャットを選んだ友だちと中継で暗号化して共有します。エージェントもそのまま残ります。友だちには参加後のメッセージが見え、それ以前の履歴はこのコンピュータにあなただけのものとして残ります。",
|
|
1464
|
+
sharedBefore: "それ以前の履歴(あなただけに表示)",
|
|
1465
|
+
sharedBeforeTile: "以前の履歴",
|
|
1425
1466
|
sharedMade: "「{name}」を友だちと共有しました。参加するとすぐ入れます。",
|
|
1426
1467
|
addFriends: "友だちを追加",
|
|
1427
1468
|
friend: "友だち",
|
|
@@ -1559,6 +1600,11 @@ var JA = {
|
|
|
1559
1600
|
shareCard: "カードを共有…",
|
|
1560
1601
|
cardTitle: "{name} のカード",
|
|
1561
1602
|
cardKind: "エージェントカード",
|
|
1603
|
+
profileTitle: "エージェントのプロフィール",
|
|
1604
|
+
noAgentOpen: "エージェントとの会話を開くと、ここにプロフィールが表示されます",
|
|
1605
|
+
sendMessage: "メッセージ",
|
|
1606
|
+
workDir: "作業ディレクトリ",
|
|
1607
|
+
deleteAgentLong: "エージェントを削除",
|
|
1562
1608
|
cardGets: "相手は自分のエージェントとして追加し、自分のプロジェクトに合わせて役割を調整します",
|
|
1563
1609
|
cardHint: "役割のみ(秘密のように見えるものは除去)、ディレクトリと会話は含まれません。リンクは 30 日間有効で、このコンピューターがオフでも開けます。",
|
|
1564
1610
|
cardRedacted: "役割に {n} 箇所の秘密のように見えるものが除去されました。",
|
|
@@ -1588,17 +1634,19 @@ var ZH = {
|
|
|
1588
1634
|
topic: "主题",
|
|
1589
1635
|
members: "成员",
|
|
1590
1636
|
addMembers: "添加成员",
|
|
1591
|
-
|
|
1592
|
-
|
|
1637
|
+
mentionMember: "成员",
|
|
1638
|
+
makeExtension: "存下来",
|
|
1639
|
+
makeExtensionDetail: "把这里商量出的做法存成以后一键再用的",
|
|
1593
1640
|
makeExtensionAsk: "把这个群聊里商量和做成的事做成扩展(用 ta-package 技能),以后一键就能再用",
|
|
1594
1641
|
add: "添加",
|
|
1595
1642
|
allMembers: "所有智能体都已在这个群聊里",
|
|
1596
|
-
membersHint: "
|
|
1643
|
+
membersHint: "先选的成员是负责人:Ta 派给群的事由它接。想让哪个智能体回答你,就 @ 它。",
|
|
1597
1644
|
create: "创建",
|
|
1598
1645
|
cancel: "取消",
|
|
1599
1646
|
back: "返回",
|
|
1600
1647
|
send: "发送",
|
|
1601
1648
|
you: "你",
|
|
1649
|
+
picture: "[图片]",
|
|
1602
1650
|
owner: "所有者",
|
|
1603
1651
|
ta: "Ta",
|
|
1604
1652
|
lead: "负责人",
|
|
@@ -1607,8 +1655,10 @@ var ZH = {
|
|
|
1607
1655
|
noAgents: "还没有智能体",
|
|
1608
1656
|
noAgentsHint: "群聊由智能体组成,先新建一个",
|
|
1609
1657
|
pick: "选一个群聊",
|
|
1610
|
-
quiet: "
|
|
1658
|
+
quiet: "还没有消息。@ 哪个智能体,它就会回答。",
|
|
1611
1659
|
placeholder: "发到 {channel};@ 点名成员",
|
|
1660
|
+
placeholderLead: "发到 {channel};不 @ 时{lead}来答",
|
|
1661
|
+
placeholderAll: "发到 {channel};大家都可以接话",
|
|
1612
1662
|
answering: "{name} 正在回答",
|
|
1613
1663
|
failed: "没有回答",
|
|
1614
1664
|
mention: "@{name}",
|
|
@@ -1635,6 +1685,10 @@ var ZH = {
|
|
|
1635
1685
|
budgetShortWord: "简短",
|
|
1636
1686
|
budgetNormalWord: "标准",
|
|
1637
1687
|
budgetLongWord: "深入",
|
|
1688
|
+
replyHead: "没 @ 时谁接话",
|
|
1689
|
+
replyMentionedWord: "只回 @",
|
|
1690
|
+
replyLeadWord: "负责人接",
|
|
1691
|
+
replyAllWord: "大家都接",
|
|
1638
1692
|
dailyLimit: "每天上限",
|
|
1639
1693
|
dailySpent: "今天 {spent}",
|
|
1640
1694
|
dailySpentOf: "今天 {spent} / {limit}",
|
|
@@ -1661,10 +1715,9 @@ var ZH = {
|
|
|
1661
1715
|
agentTag: "智能体",
|
|
1662
1716
|
noPartners: "还没有伙伴",
|
|
1663
1717
|
noPartnersHint: "点 + 新建智能体或群聊,或加个好友",
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
shareGroupHint: "会新建一个同名的群聊,经中继加密和你选的好友共享,群里的智能体一起进去;这里的聊天记录留在本机,不发给好友。",
|
|
1718
|
+
shareGroupHint: "这个群聊会经中继加密和你选的好友共享,群里的智能体都在。好友从加入起看到新消息,之前的记录只留在本机,只有你能看到。",
|
|
1719
|
+
sharedBefore: "之前的聊天记录,只有你能看到",
|
|
1720
|
+
sharedBeforeTile: "之前的记录",
|
|
1668
1721
|
sharedMade: "已和好友共享「{name}」:好友点加入就进来。",
|
|
1669
1722
|
addFriends: "添加好友",
|
|
1670
1723
|
friend: "好友",
|
|
@@ -1802,6 +1855,11 @@ var ZH = {
|
|
|
1802
1855
|
shareCard: "分享名片…",
|
|
1803
1856
|
cardTitle: "{name} 的名片",
|
|
1804
1857
|
cardKind: "智能体名片",
|
|
1858
|
+
profileTitle: "智能体资料",
|
|
1859
|
+
noAgentOpen: "打开和智能体的对话后,这里显示它的资料",
|
|
1860
|
+
sendMessage: "发消息",
|
|
1861
|
+
workDir: "工作目录",
|
|
1862
|
+
deleteAgentLong: "删除智能体",
|
|
1805
1863
|
cardGets: "对方把它加为自己的智能体,并按自己的项目调整职责",
|
|
1806
1864
|
cardHint: "只带上职责(隐去疑似密钥),不带工作目录和对话。链接 30 天内有效,你的电脑关机也能打开。",
|
|
1807
1865
|
cardRedacted: "职责里有 {n} 处疑似密钥已隐去。",
|
|
@@ -1831,17 +1889,19 @@ var ZH_TW = {
|
|
|
1831
1889
|
topic: "主題",
|
|
1832
1890
|
members: "成員",
|
|
1833
1891
|
addMembers: "新增成員",
|
|
1834
|
-
|
|
1835
|
-
|
|
1892
|
+
mentionMember: "成員",
|
|
1893
|
+
makeExtension: "存下來",
|
|
1894
|
+
makeExtensionDetail: "把這裡商量出的做法存成以後一鍵再用的",
|
|
1836
1895
|
makeExtensionAsk: "把這個群聊里商量和做成的事做成擴充功能(用 ta-package 技能),以後一鍵就能再用",
|
|
1837
1896
|
add: "新增",
|
|
1838
1897
|
allMembers: "所有智慧體都已在這個群聊里",
|
|
1839
|
-
membersHint: "
|
|
1898
|
+
membersHint: "先選的成員是負責人:Ta 派給群的事由它接。想讓哪個智慧體回答你,就 @ 它。",
|
|
1840
1899
|
create: "建立",
|
|
1841
1900
|
cancel: "取消",
|
|
1842
1901
|
back: "返回",
|
|
1843
1902
|
send: "傳送",
|
|
1844
1903
|
you: "你",
|
|
1904
|
+
picture: "[圖片]",
|
|
1845
1905
|
owner: "所有者",
|
|
1846
1906
|
ta: "Ta",
|
|
1847
1907
|
lead: "負責人",
|
|
@@ -1850,8 +1910,10 @@ var ZH_TW = {
|
|
|
1850
1910
|
noAgents: "還沒有智慧體",
|
|
1851
1911
|
noAgentsHint: "群聊由智慧體組成,先新建一個",
|
|
1852
1912
|
pick: "選一個群聊",
|
|
1853
|
-
quiet: "
|
|
1913
|
+
quiet: "還沒有訊息。@ 哪個智慧體,它就會回答。",
|
|
1854
1914
|
placeholder: "發到 {channel};@ 點名成員",
|
|
1915
|
+
placeholderLead: "發到 {channel};不 @ 時{lead}來答",
|
|
1916
|
+
placeholderAll: "發到 {channel};大家都可以接話",
|
|
1855
1917
|
answering: "{name} 正在回答",
|
|
1856
1918
|
failed: "沒有回答",
|
|
1857
1919
|
mention: "@{name}",
|
|
@@ -1878,6 +1940,10 @@ var ZH_TW = {
|
|
|
1878
1940
|
budgetShortWord: "簡短",
|
|
1879
1941
|
budgetNormalWord: "標準",
|
|
1880
1942
|
budgetLongWord: "深入",
|
|
1943
|
+
replyHead: "沒 @ 時誰接話",
|
|
1944
|
+
replyMentionedWord: "只回 @",
|
|
1945
|
+
replyLeadWord: "負責人接",
|
|
1946
|
+
replyAllWord: "大家都接",
|
|
1881
1947
|
dailyLimit: "每天上限",
|
|
1882
1948
|
dailySpent: "今天 {spent}",
|
|
1883
1949
|
dailySpentOf: "今天 {spent} / {limit}",
|
|
@@ -1904,10 +1970,9 @@ var ZH_TW = {
|
|
|
1904
1970
|
agentTag: "智慧體",
|
|
1905
1971
|
noPartners: "還沒有夥伴",
|
|
1906
1972
|
noPartnersHint: "點 + 新建智慧體或群聊,或加個好友",
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
shareGroupHint: "會新建一個同名的群聊,經中繼加密和你選的好友共享,群裡的智慧體一起進去;這裡的聊天記錄留在本機,不發給好友。",
|
|
1973
|
+
shareGroupHint: "這個群聊會經中繼加密和你選的好友共享,群裡的智慧體都在。好友從加入起看到新訊息,之前的記錄只留在本機,只有你能看到。",
|
|
1974
|
+
sharedBefore: "之前的聊天記錄,只有你能看到",
|
|
1975
|
+
sharedBeforeTile: "之前的記錄",
|
|
1911
1976
|
sharedMade: "已和好友共享「{name}」:好友點加入就進來。",
|
|
1912
1977
|
addFriends: "新增好友",
|
|
1913
1978
|
friend: "好友",
|
|
@@ -2045,6 +2110,11 @@ var ZH_TW = {
|
|
|
2045
2110
|
shareCard: "分享名片…",
|
|
2046
2111
|
cardTitle: "{name} 的名片",
|
|
2047
2112
|
cardKind: "智慧體名片",
|
|
2113
|
+
profileTitle: "智慧體資料",
|
|
2114
|
+
noAgentOpen: "開啟與智慧體的對話後,這裡顯示它的資料",
|
|
2115
|
+
sendMessage: "發訊息",
|
|
2116
|
+
workDir: "工作目錄",
|
|
2117
|
+
deleteAgentLong: "刪除智慧體",
|
|
2048
2118
|
cardGets: "對方把它加為自己的智慧體,並按自己的專案調整職責",
|
|
2049
2119
|
cardHint: "只帶上職責(隱去疑似金鑰),不帶工作目錄和對話。連結 30 天內有效,你的電腦關機也能開啟。",
|
|
2050
2120
|
cardRedacted: "職責裡有 {n} 處疑似金鑰已隱去。",
|
|
@@ -2074,17 +2144,19 @@ var EN = {
|
|
|
2074
2144
|
topic: "Topic",
|
|
2075
2145
|
members: "Members",
|
|
2076
2146
|
addMembers: "Add members",
|
|
2077
|
-
|
|
2078
|
-
|
|
2147
|
+
mentionMember: "Member",
|
|
2148
|
+
makeExtension: "Keep",
|
|
2149
|
+
makeExtensionDetail: "Make what was worked out here a one-tap thing to use again",
|
|
2079
2150
|
makeExtensionAsk: "Make what this group chat worked out an extension, with the ta-package skill, to do it again in a click",
|
|
2080
2151
|
add: "Add",
|
|
2081
2152
|
allMembers: "Every agent is in this group chat already",
|
|
2082
|
-
membersHint: "The first one you pick leads: it answers what
|
|
2153
|
+
membersHint: "The first one you pick leads: it answers what Ta hands the group chat. Mention an agent with @ to have it answer you.",
|
|
2083
2154
|
create: "Create",
|
|
2084
2155
|
cancel: "Cancel",
|
|
2085
2156
|
back: "Back",
|
|
2086
2157
|
send: "Send",
|
|
2087
2158
|
you: "You",
|
|
2159
|
+
picture: "[Picture]",
|
|
2088
2160
|
owner: "Owner",
|
|
2089
2161
|
ta: "Ta",
|
|
2090
2162
|
lead: "Lead",
|
|
@@ -2093,8 +2165,10 @@ var EN = {
|
|
|
2093
2165
|
noAgents: "No agents yet",
|
|
2094
2166
|
noAgentsHint: "A group chat is made of agents: create one first",
|
|
2095
2167
|
pick: "Pick a group chat",
|
|
2096
|
-
quiet: "Nothing said yet. Mention
|
|
2168
|
+
quiet: "Nothing said yet. Mention an agent with @ to have it answer.",
|
|
2097
2169
|
placeholder: "Message {channel}; @ names a member",
|
|
2170
|
+
placeholderLead: "Message {channel}; {lead} answers without @",
|
|
2171
|
+
placeholderAll: "Message {channel}; anyone may answer",
|
|
2098
2172
|
answering: "{name} is answering",
|
|
2099
2173
|
failed: "did not answer",
|
|
2100
2174
|
mention: "Mention {name}",
|
|
@@ -2121,6 +2195,10 @@ var EN = {
|
|
|
2121
2195
|
budgetShortWord: "Short",
|
|
2122
2196
|
budgetNormalWord: "Normal",
|
|
2123
2197
|
budgetLongWord: "Long",
|
|
2198
|
+
replyHead: "Without @",
|
|
2199
|
+
replyMentionedWord: "Only @",
|
|
2200
|
+
replyLeadWord: "The lead",
|
|
2201
|
+
replyAllWord: "Everyone",
|
|
2124
2202
|
dailyLimit: "A day",
|
|
2125
2203
|
dailySpent: "today {spent}",
|
|
2126
2204
|
dailySpentOf: "today {spent} / {limit}",
|
|
@@ -2147,10 +2225,9 @@ var EN = {
|
|
|
2147
2225
|
agentTag: "Agent",
|
|
2148
2226
|
noPartners: "No one to work with yet",
|
|
2149
2227
|
noPartnersHint: "Create an agent or a group chat with +, or add a friend",
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
shareGroupHint: "A group chat of the same name is made, shared with the friends you pick through the relay, sealed; its agents go in too. What was said here stays on this computer.",
|
|
2228
|
+
shareGroupHint: "This group chat is shared with the friends you pick through the relay, sealed, its agents in it too. They see what is said from when they join; what was said before stays on this computer, for you alone.",
|
|
2229
|
+
sharedBefore: "What was said before, for you alone",
|
|
2230
|
+
sharedBeforeTile: "Earlier",
|
|
2154
2231
|
sharedMade: "“{name}” is shared with your friends now: they are in once they join.",
|
|
2155
2232
|
addFriends: "Add friends",
|
|
2156
2233
|
friend: "Friend",
|
|
@@ -2288,6 +2365,11 @@ var EN = {
|
|
|
2288
2365
|
shareCard: "Share card…",
|
|
2289
2366
|
cardTitle: "{name}'s card",
|
|
2290
2367
|
cardKind: "An agent's card",
|
|
2368
|
+
profileTitle: "Agent profile",
|
|
2369
|
+
noAgentOpen: "Open a conversation with an agent to see its profile here",
|
|
2370
|
+
sendMessage: "Message",
|
|
2371
|
+
workDir: "Directory",
|
|
2372
|
+
deleteAgentLong: "Delete agent",
|
|
2291
2373
|
cardGets: "They add it as an agent of their own, fitted to their project",
|
|
2292
2374
|
cardHint: "Only its role goes, secrets taken out; not its directory nor its conversation. The link works for 30 days, while this computer is off too.",
|
|
2293
2375
|
cardRedacted: "{n} places that looked like secrets were taken out.",
|
|
@@ -2318,6 +2400,7 @@ var ChannelWords;
|
|
|
2318
2400
|
var DOUBLE_PAGE = "assistant/assistant";
|
|
2319
2401
|
var CHANNEL_PAGE = `${NAME}/channel`;
|
|
2320
2402
|
var MEMBERS_VIEW = `${NAME}/members`;
|
|
2403
|
+
var AGENT_INFO_VIEW = `${NAME}/agent-info`;
|
|
2321
2404
|
var ROOM_INFO_VIEW = "@celljs/ta-rooms/members";
|
|
2322
2405
|
var CHANNEL_KEY = "ta-channels.channel";
|
|
2323
2406
|
|
|
@@ -2825,1819 +2908,1985 @@ function registerCardOpener(context) {
|
|
|
2825
2908
|
}, { specific: true });
|
|
2826
2909
|
}
|
|
2827
2910
|
|
|
2828
|
-
//
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2911
|
+
// ../ta-protocol/esm/common/said-protocol.js
|
|
2912
|
+
var TaSaid;
|
|
2913
|
+
(function(TaSaid2) {
|
|
2914
|
+
const CARD = /^ta-/i;
|
|
2915
|
+
const READ = 4000;
|
|
2916
|
+
const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
|
|
2917
|
+
const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
|
|
2918
|
+
const MARKS_ONLY = /^[-*_=|:+\s]+$/;
|
|
2919
|
+
const MARKS = [
|
|
2920
|
+
["context", /<\/?context>/],
|
|
2921
|
+
["source", /\[ta:(?:from|notice|by) /],
|
|
2922
|
+
["image note", /\[Image: original \d+x\d+|\[Image converted from /],
|
|
2923
|
+
["skill", /<skill name="|<\/skill>/],
|
|
2924
|
+
["task note", /<\/?task_(?:update|adopted|renamed)\b/],
|
|
2925
|
+
["summary", /<\/?(?:conversation_history_summary|summary)>/]
|
|
2926
|
+
];
|
|
2927
|
+
function text(content, joiner = `
|
|
2928
|
+
`) {
|
|
2929
|
+
if (typeof content === "string") {
|
|
2930
|
+
return content;
|
|
2931
|
+
}
|
|
2932
|
+
return Array.isArray(content) ? content.filter((part) => (part === null || part === undefined ? undefined : part.type) === "text" && typeof part.text === "string").map((part) => part.text).join(joiner) : "";
|
|
2841
2933
|
}
|
|
2842
|
-
|
|
2843
|
-
|
|
2934
|
+
TaSaid2.text = text;
|
|
2935
|
+
function words(role, text2, options = {}) {
|
|
2936
|
+
const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
|
|
2937
|
+
return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
|
|
2844
2938
|
}
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
return
|
|
2939
|
+
TaSaid2.words = words;
|
|
2940
|
+
function of(message, options) {
|
|
2941
|
+
return message ? words(message.role, text(message.content), options) : "";
|
|
2848
2942
|
}
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
return ()
|
|
2943
|
+
TaSaid2.of = of;
|
|
2944
|
+
function notice(message) {
|
|
2945
|
+
return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
|
|
2852
2946
|
}
|
|
2853
|
-
|
|
2854
|
-
|
|
2947
|
+
TaSaid2.notice = notice;
|
|
2948
|
+
function marksOnly(role, text2) {
|
|
2949
|
+
return !!text2.trim() && !line(words(role, text2), { chars: Number.POSITIVE_INFINITY });
|
|
2855
2950
|
}
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2951
|
+
TaSaid2.marksOnly = marksOnly;
|
|
2952
|
+
function line(markdown, options) {
|
|
2953
|
+
var _a;
|
|
2954
|
+
const read = markdown.slice(0, READ);
|
|
2955
|
+
const prose = withoutFences(read, () => true, true).trim();
|
|
2956
|
+
const lines = plain(prose || codeOf(read)).split(`
|
|
2957
|
+
`).map((part) => part.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+)/, "").replace(/\*{1,3}|`+|~~|(?<![\p{L}\p{N}])_{1,3}|_{1,3}(?![\p{L}\p{N}])/gu, "").replace(/\s+/g, " ").trim()).filter((part) => part && !MARKS_ONLY.test(part) && !TAG_LINE.test(part));
|
|
2958
|
+
const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
|
|
2959
|
+
const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
|
|
2960
|
+
`);
|
|
2961
|
+
return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
|
|
2962
|
+
}
|
|
2963
|
+
TaSaid2.line = line;
|
|
2964
|
+
function leaks(shown, options = {}) {
|
|
2965
|
+
const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
|
|
2966
|
+
const lines = shown.split(`
|
|
2967
|
+
`);
|
|
2968
|
+
if (options.cards !== true && lines.some((part) => {
|
|
2969
|
+
var _a;
|
|
2970
|
+
var _b;
|
|
2971
|
+
return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
|
|
2972
|
+
})) {
|
|
2973
|
+
found.push("card");
|
|
2863
2974
|
}
|
|
2864
|
-
|
|
2975
|
+
if (lines.some((part) => TAG_LINE.test(part.trim()))) {
|
|
2976
|
+
found.push("tag");
|
|
2977
|
+
}
|
|
2978
|
+
return found;
|
|
2865
2979
|
}
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2980
|
+
TaSaid2.leaks = leaks;
|
|
2981
|
+
const SUMMARY = `<conversation_history_summary>
|
|
2982
|
+
<summary>
|
|
2983
|
+
1. Primary Request and Intent:
|
|
2984
|
+
The user works on the relay.
|
|
2985
|
+
</summary>
|
|
2986
|
+
</conversation_history_summary>`;
|
|
2987
|
+
TaSaid2.SAMPLES = [
|
|
2988
|
+
{
|
|
2989
|
+
mark: "context and where it came from",
|
|
2990
|
+
role: "user",
|
|
2991
|
+
text: `<context>
|
|
2992
|
+
The channel #ops, its members.
|
|
2993
|
+
[ta:from @celljs/ta-channels #ops]
|
|
2994
|
+
</context>
|
|
2995
|
+
Check the build`,
|
|
2996
|
+
said: "Check the build"
|
|
2997
|
+
},
|
|
2998
|
+
{
|
|
2999
|
+
mark: "a notice, not the user",
|
|
3000
|
+
role: "user",
|
|
3001
|
+
text: `<context>
|
|
3002
|
+
[ta:notice @celljs/ta-call]
|
|
3003
|
+
</context>
|
|
3004
|
+
The work finished. Its last words: tests pass.`,
|
|
3005
|
+
said: "The work finished. Its last words: tests pass."
|
|
3006
|
+
},
|
|
3007
|
+
{ mark: "one let in", role: "user", text: `<context>
|
|
3008
|
+
[ta:by p-7 Alice]
|
|
3009
|
+
</context>
|
|
3010
|
+
Hello there`, said: "Hello there" },
|
|
3011
|
+
{
|
|
3012
|
+
mark: "notes of images",
|
|
3013
|
+
role: "user",
|
|
3014
|
+
text: `Look at this
|
|
3015
|
+
[Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
|
|
3016
|
+
[Image converted from image/heic to image/png.]`,
|
|
3017
|
+
said: "Look at this"
|
|
3018
|
+
},
|
|
3019
|
+
{
|
|
3020
|
+
mark: "a skill run",
|
|
3021
|
+
role: "user",
|
|
3022
|
+
text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
|
|
3023
|
+
# Ta package
|
|
3024
|
+
Steps.
|
|
3025
|
+
</skill>
|
|
3026
|
+
|
|
3027
|
+
Make a card`,
|
|
3028
|
+
said: "Make a card"
|
|
3029
|
+
},
|
|
3030
|
+
{
|
|
3031
|
+
mark: "a note of a task",
|
|
3032
|
+
role: "user",
|
|
3033
|
+
text: `<task_update id="t1" title="Fix login" status="done">
|
|
3034
|
+
All tests pass.
|
|
3035
|
+
</task_update>`,
|
|
3036
|
+
said: "Fix login"
|
|
3037
|
+
},
|
|
3038
|
+
{ mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
|
|
3039
|
+
Now t2.
|
|
3040
|
+
</task_renamed>` },
|
|
3041
|
+
{ mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
|
|
3042
|
+
Switched to voice.`, said: "Switched to voice." },
|
|
3043
|
+
{ mark: "a summary alone", role: "assistant", text: SUMMARY },
|
|
3044
|
+
{ mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
|
|
3045
|
+
<summary>` },
|
|
3046
|
+
{
|
|
3047
|
+
mark: "a card after the answer",
|
|
3048
|
+
role: "assistant",
|
|
3049
|
+
text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
|
|
3050
|
+
said: "tests pass"
|
|
3051
|
+
},
|
|
3052
|
+
{ mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
|
|
3053
|
+
{ mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
|
|
3054
|
+
{ mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
|
|
3055
|
+
{ mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
|
|
3056
|
+
</system-reminder>
|
|
3057
|
+
Ready.`, said: "Ready." }
|
|
3058
|
+
];
|
|
3059
|
+
function userWords(text2) {
|
|
3060
|
+
const said = TaImageNote.strip(TaMessageContext.strip(text2));
|
|
3061
|
+
const skill = TaSkillUse.parse(said);
|
|
3062
|
+
if (skill) {
|
|
3063
|
+
return TaSkillUse.command(skill);
|
|
2870
3064
|
}
|
|
2871
|
-
const
|
|
2872
|
-
|
|
2873
|
-
|
|
3065
|
+
const note = TaTaskNote.parse(said);
|
|
3066
|
+
if (!note) {
|
|
3067
|
+
return said;
|
|
3068
|
+
}
|
|
3069
|
+
if (note.kind === "renamed") {
|
|
3070
|
+
return "";
|
|
3071
|
+
}
|
|
3072
|
+
return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
|
|
2874
3073
|
}
|
|
2875
|
-
|
|
2876
|
-
const
|
|
2877
|
-
|
|
2878
|
-
|
|
3074
|
+
function withoutFences(text2, drop, tags = false) {
|
|
3075
|
+
const kept = [];
|
|
3076
|
+
let fence;
|
|
3077
|
+
let left = false;
|
|
3078
|
+
for (const part of text2.split(`
|
|
3079
|
+
`)) {
|
|
3080
|
+
const open = FENCE.exec(part);
|
|
3081
|
+
if (!fence && open) {
|
|
3082
|
+
fence = { mark: open[1], dropped: drop(open[2]) };
|
|
3083
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
3084
|
+
const dropped = fence.dropped;
|
|
3085
|
+
fence = undefined;
|
|
3086
|
+
if (dropped) {
|
|
3087
|
+
continue;
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
|
|
3091
|
+
left = true;
|
|
3092
|
+
} else {
|
|
3093
|
+
kept.push(part);
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
return left ? kept.join(`
|
|
3097
|
+
`).replace(/\n{3,}/g, `
|
|
3098
|
+
|
|
3099
|
+
`) : kept.join(`
|
|
3100
|
+
`);
|
|
2879
3101
|
}
|
|
2880
|
-
|
|
2881
|
-
const
|
|
2882
|
-
|
|
2883
|
-
|
|
3102
|
+
function codeOf(text2) {
|
|
3103
|
+
const code = [];
|
|
3104
|
+
let fence;
|
|
3105
|
+
for (const part of text2.split(`
|
|
3106
|
+
`)) {
|
|
3107
|
+
const open = FENCE.exec(part);
|
|
3108
|
+
if (!fence && open) {
|
|
3109
|
+
fence = { mark: open[1], card: CARD.test(open[2]) };
|
|
3110
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
3111
|
+
fence = undefined;
|
|
3112
|
+
} else if (fence && !fence.card) {
|
|
3113
|
+
code.push(part);
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
return code.join(`
|
|
3117
|
+
`);
|
|
2884
3118
|
}
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
return
|
|
2889
|
-
}
|
|
2890
|
-
async changeMember(channelId, agentId, change) {
|
|
2891
|
-
const channel = await this.send({ kind: "changeMember", channel: channelId, agent: agentId, change });
|
|
2892
|
-
await this.load(true);
|
|
2893
|
-
return channel;
|
|
2894
|
-
}
|
|
2895
|
-
async updateChannel(channelId, change) {
|
|
2896
|
-
const channel = await this.send({ kind: "updateChannel", channel: channelId, ...change });
|
|
2897
|
-
await this.load(true);
|
|
2898
|
-
return channel;
|
|
2899
|
-
}
|
|
2900
|
-
async deleteChannel(channelId) {
|
|
2901
|
-
await this.deleting(channelId, async () => {
|
|
2902
|
-
await this.send({ kind: "deleteChannel", channel: channelId });
|
|
2903
|
-
const { [channelId]: _gone, ...messages } = this.current.messages;
|
|
2904
|
-
this.update({ messages });
|
|
2905
|
-
await this.load(true);
|
|
2906
|
-
});
|
|
2907
|
-
}
|
|
2908
|
-
async resetAgent(agentId) {
|
|
2909
|
-
const agent = await this.send({ kind: "resetAgent", agent: agentId });
|
|
2910
|
-
await this.load(true);
|
|
2911
|
-
return agent;
|
|
3119
|
+
function closes(part, mark) {
|
|
3120
|
+
var _a;
|
|
3121
|
+
const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
|
|
3122
|
+
return !!close && close[0] === mark[0] && close.length >= mark.length;
|
|
2912
3123
|
}
|
|
2913
|
-
|
|
2914
|
-
const
|
|
2915
|
-
|
|
2916
|
-
return
|
|
3124
|
+
function plain(text2) {
|
|
3125
|
+
const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
3126
|
+
const words2 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
|
|
3127
|
+
return words2 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
2917
3128
|
}
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
3129
|
+
})(TaSaid || (TaSaid = {}));
|
|
3130
|
+
|
|
3131
|
+
// web-src/channels-text.ts
|
|
3132
|
+
var ChannelsText;
|
|
3133
|
+
((ChannelsText) => {
|
|
3134
|
+
function markMentions(text, agents) {
|
|
3135
|
+
if (agents.length === 0) {
|
|
3136
|
+
return text;
|
|
3137
|
+
}
|
|
3138
|
+
const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
3139
|
+
const pattern = new RegExp(`(?<![*A-Za-z0-9_])@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
|
|
3140
|
+
return text.split(/(```[\s\S]*?(?:```|$)|`[^`\n]*`)/).map((part, index) => index % 2 === 1 ? part : part.replace(pattern, "**$&**")).join("");
|
|
2922
3141
|
}
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
}
|
|
3142
|
+
ChannelsText.markMentions = markMentions;
|
|
3143
|
+
function mentions(text, agents) {
|
|
3144
|
+
if (agents.length === 0) {
|
|
3145
|
+
return [];
|
|
3146
|
+
}
|
|
3147
|
+
const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
3148
|
+
const pattern = new RegExp(`@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
|
|
3149
|
+
const found = [];
|
|
3150
|
+
for (const match of text.matchAll(pattern)) {
|
|
3151
|
+
const agent = agents.find((candidate) => candidate.name.toLowerCase() === match[1].toLowerCase());
|
|
3152
|
+
if (agent && !found.includes(agent.id)) {
|
|
3153
|
+
found.push(agent.id);
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
return found;
|
|
2928
3157
|
}
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
3158
|
+
ChannelsText.mentions = mentions;
|
|
3159
|
+
function targets(team, channel, message) {
|
|
3160
|
+
const members = answering(team, channel);
|
|
3161
|
+
const named = mentions(message.text, members).filter((id) => id !== message.author);
|
|
3162
|
+
if (message.author === SYSTEM) {
|
|
3163
|
+
return [];
|
|
2935
3164
|
}
|
|
3165
|
+
if (named.length > 0 || message.author !== TA && message.author !== USER || mentions(message.text, team.agents).length > 0) {
|
|
3166
|
+
return named;
|
|
3167
|
+
}
|
|
3168
|
+
const reply = message.author === TA ? "lead" : replyOf(channel);
|
|
3169
|
+
if (reply === "all") {
|
|
3170
|
+
return members.map((agent) => agent.id);
|
|
3171
|
+
}
|
|
3172
|
+
return reply === "lead" && members.length > 0 ? [members[0].id] : [];
|
|
2936
3173
|
}
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
return
|
|
3174
|
+
ChannelsText.targets = targets;
|
|
3175
|
+
function replyOf(channel) {
|
|
3176
|
+
return channel?.reply && REPLIES.includes(channel.reply) ? channel.reply : DEFAULT_REPLY;
|
|
2940
3177
|
}
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
return channel;
|
|
3178
|
+
ChannelsText.replyOf = replyOf;
|
|
3179
|
+
function passes(text) {
|
|
3180
|
+
return text.replace(/[\s.。!!*_`"'“”]/g, "").toUpperCase() === PASS;
|
|
2945
3181
|
}
|
|
2946
|
-
|
|
2947
|
-
|
|
3182
|
+
ChannelsText.passes = passes;
|
|
3183
|
+
function answering(team, channel) {
|
|
3184
|
+
const muted = channel.muted ?? [];
|
|
3185
|
+
return channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
|
|
2948
3186
|
}
|
|
2949
|
-
|
|
2950
|
-
|
|
3187
|
+
function mayPass(team, channel, message, agent) {
|
|
3188
|
+
const members = answering(team, channel);
|
|
3189
|
+
return message.author === USER && replyOf(channel) === "all" && members[0]?.id !== agent.id && mentions(message.text, team.agents).length === 0;
|
|
2951
3190
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
3191
|
+
ChannelsText.mayPass = mayPass;
|
|
3192
|
+
function authorName(team, author, labels) {
|
|
3193
|
+
if (author === SYSTEM) {
|
|
3194
|
+
return "channel";
|
|
3195
|
+
}
|
|
3196
|
+
if (author === USER) {
|
|
3197
|
+
return labels.user;
|
|
3198
|
+
}
|
|
3199
|
+
if (author === TA) {
|
|
3200
|
+
return labels.ta;
|
|
3201
|
+
}
|
|
3202
|
+
return team.agents.find((agent) => agent.id === author)?.name ?? author;
|
|
2954
3203
|
}
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
3204
|
+
ChannelsText.authorName = authorName;
|
|
3205
|
+
function systemPrompt(agent) {
|
|
3206
|
+
return [
|
|
3207
|
+
`You are ${agent.name}, ${AGENT_MARK}. Your role: ${agent.role}`,
|
|
3208
|
+
"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.",
|
|
3209
|
+
"Do the part of the work your role covers with your tools, then answer: your answer is posted to the channel as it is.",
|
|
3210
|
+
"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.",
|
|
3211
|
+
"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.",
|
|
3212
|
+
NOTICE_RULE
|
|
3213
|
+
].join(`
|
|
3214
|
+
`);
|
|
2959
3215
|
}
|
|
2960
|
-
|
|
2961
|
-
|
|
3216
|
+
ChannelsText.systemPrompt = systemPrompt;
|
|
3217
|
+
function prompt(team, channel, history, message, agent, options = {}) {
|
|
3218
|
+
const labels = { user: "user", ta: "Ta" };
|
|
3219
|
+
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)}`);
|
|
3220
|
+
const before = history.filter((item) => item.id !== message.id && !item.failed && !item.notice).slice(-CONTEXT_MESSAGES);
|
|
3221
|
+
const lines = [`[#${channel.name}]${channel.topic ? ` ${channel.topic}` : ""}`, "Members:", ...members.map((line) => `- ${line}`)];
|
|
3222
|
+
if (channel.notice) {
|
|
3223
|
+
lines.push("", "Notice of the channel (follow it; keep it with update_channel_notice):", channel.notice.text);
|
|
3224
|
+
}
|
|
3225
|
+
if (before.length > 0) {
|
|
3226
|
+
lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${said(item)}`));
|
|
3227
|
+
}
|
|
3228
|
+
if (options.closing) {
|
|
3229
|
+
lines.push("", CLOSING_NOTE);
|
|
3230
|
+
}
|
|
3231
|
+
if (mayPass(team, channel, message, agent)) {
|
|
3232
|
+
lines.push("", PASS_NOTE);
|
|
3233
|
+
}
|
|
3234
|
+
lines.push("", `${authorName(team, message.author, labels)} to you:`);
|
|
3235
|
+
const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels)}`;
|
|
3236
|
+
lines.push(TaMessageSource.line(NAME, `#${channel.name}${speaker}`));
|
|
3237
|
+
if (message.images?.length) {
|
|
3238
|
+
lines.push(`(${message.images.length > 1 ? `${message.images.length} pictures` : "A picture"} sent with it, attached.)`);
|
|
3239
|
+
}
|
|
3240
|
+
return TaMessageContext.wrap(lines.join(`
|
|
3241
|
+
`), message.text);
|
|
2962
3242
|
}
|
|
2963
|
-
|
|
2964
|
-
|
|
3243
|
+
ChannelsText.prompt = prompt;
|
|
3244
|
+
function said(message) {
|
|
3245
|
+
const pictures = message.images?.length ? `[${message.images.length > 1 ? `${message.images.length} pictures` : "picture"}]` : "";
|
|
3246
|
+
return [pictures, message.text].filter(Boolean).join(" ");
|
|
2965
3247
|
}
|
|
2966
|
-
|
|
2967
|
-
|
|
3248
|
+
ChannelsText.said = said;
|
|
3249
|
+
function summary(team) {
|
|
3250
|
+
if (team.agents.length === 0) {
|
|
3251
|
+
return "No agents and no channels yet.";
|
|
3252
|
+
}
|
|
3253
|
+
const name = (id) => team.agents.find((agent) => agent.id === id)?.name ?? id;
|
|
3254
|
+
const agents = team.agents.map((agent) => `- @${agent.name}: ${firstLine(agent.role)}`);
|
|
3255
|
+
const channels = team.channels.map((channel) => `- #${channel.name}${channel.topic ? ` (${channel.topic})` : ""}: ${channel.members.map((id) => `@${name(id)}`).join(", ")}${channel.muted?.length ? `; muted by the user, answering nothing: ${channel.muted.map((id) => `@${name(id)}`).join(", ")}` : ""}${channel.notice ? `
|
|
3256
|
+
notice: ${channel.notice.text.replace(/\s+/g, " ").slice(0, 300)}` : ""}`);
|
|
3257
|
+
return ["Agents:", ...agents, "", "Channels:", ...channels.length > 0 ? channels : ["none yet"]].join(`
|
|
3258
|
+
`);
|
|
2968
3259
|
}
|
|
2969
|
-
|
|
2970
|
-
|
|
3260
|
+
ChannelsText.summary = summary;
|
|
3261
|
+
function transcript(team, messages) {
|
|
3262
|
+
const labels = { user: "user", ta: "Ta" };
|
|
3263
|
+
return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${said(item)}`).join(`
|
|
3264
|
+
|
|
3265
|
+
`);
|
|
2971
3266
|
}
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
reads.push(this.storage.get(Keys.FOCUS).then(async (focus) => {
|
|
2984
|
-
if (focus) {
|
|
2985
|
-
await this.load(true);
|
|
2986
|
-
for (const listener of this.focusListeners) {
|
|
2987
|
-
listener(focus.channelId);
|
|
2988
|
-
}
|
|
2989
|
-
}
|
|
2990
|
-
}));
|
|
3267
|
+
ChannelsText.transcript = transcript;
|
|
3268
|
+
function markdown(agent, messages, labels) {
|
|
3269
|
+
const parts = [`# ${agent.name}`, "", `> ${firstLine(agent.role)}`];
|
|
3270
|
+
for (const message of messages) {
|
|
3271
|
+
const { role, content } = message ?? {};
|
|
3272
|
+
if (role !== "user" && role !== "assistant") {
|
|
3273
|
+
continue;
|
|
3274
|
+
}
|
|
3275
|
+
const text = TaSaid.words(role, TaSaid.text(content, ""));
|
|
3276
|
+
if (text) {
|
|
3277
|
+
parts.push("", `## ${role === "user" ? labels.user : agent.name}`, "", text);
|
|
2991
3278
|
}
|
|
2992
3279
|
}
|
|
2993
|
-
|
|
3280
|
+
return `${parts.join(`
|
|
3281
|
+
`)}
|
|
3282
|
+
`;
|
|
2994
3283
|
}
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
3284
|
+
ChannelsText.markdown = markdown;
|
|
3285
|
+
function channelMarkdown(team, channel, messages, labels) {
|
|
3286
|
+
const parts = [`# #${channel.name}`];
|
|
3287
|
+
if (channel.topic) {
|
|
3288
|
+
parts.push("", `> ${firstLine(channel.topic)}`);
|
|
2999
3289
|
}
|
|
3290
|
+
for (const message of messages) {
|
|
3291
|
+
const text = message.text.trim();
|
|
3292
|
+
if (text && message.author !== SYSTEM) {
|
|
3293
|
+
parts.push("", `## ${authorName(team, message.author, labels)}${message.failed ? " (failed)" : ""}`, "", text);
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
return `${parts.join(`
|
|
3297
|
+
`)}
|
|
3298
|
+
`;
|
|
3000
3299
|
}
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
const [friends, setFriends] = React.useState([]);
|
|
3006
|
-
React.useEffect(() => {
|
|
3007
|
-
let live = true;
|
|
3008
|
-
pi.rooms?.listFriends().then((list) => live && setFriends(list.filter((friend) => friend.status === "friend")), () => {
|
|
3009
|
-
return;
|
|
3010
|
-
});
|
|
3011
|
-
return () => {
|
|
3012
|
-
live = false;
|
|
3013
|
-
};
|
|
3014
|
-
}, [pi]);
|
|
3015
|
-
return friends;
|
|
3016
|
-
}
|
|
3017
|
-
async function createShared(context, title, friends, agents) {
|
|
3018
|
-
const { pi } = context;
|
|
3019
|
-
const rooms = pi.rooms;
|
|
3020
|
-
if (!rooms) {
|
|
3021
|
-
throw new Error(ChannelViews.words(pi).sharedNeedsRooms);
|
|
3022
|
-
}
|
|
3023
|
-
const room = await rooms.createRoom({ kind: ROOMS_KIND, title });
|
|
3024
|
-
await rooms.inviteFriends(room.id, friends);
|
|
3025
|
-
for (const agent of agents) {
|
|
3026
|
-
await pi.packages.callPackageHost(ROOMS_PACKAGE, "doubles", [{ kind: "invite", room: room.id, agent }]).catch((error) => {
|
|
3027
|
-
pi.ui.notify(ChannelViews.message(error), "error");
|
|
3028
|
-
});
|
|
3300
|
+
ChannelsText.channelMarkdown = channelMarkdown;
|
|
3301
|
+
function firstLine(text) {
|
|
3302
|
+
return text.split(`
|
|
3303
|
+
`)[0];
|
|
3029
3304
|
}
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
}
|
|
3033
|
-
var
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
const friends = useFriends(pi);
|
|
3039
|
-
const Check = ChannelViews.icon(pi, "Check");
|
|
3040
|
-
const [picked, setPicked] = React.useState([]);
|
|
3041
|
-
const [busy, setBusy] = React.useState(false);
|
|
3042
|
-
const [error, setError] = React.useState();
|
|
3043
|
-
const toggle = (friend) => setPicked(picked.includes(friend.id) ? picked.filter((id) => id !== friend.id) : [...picked, friend.id]);
|
|
3044
|
-
const share = () => {
|
|
3045
|
-
setBusy(true);
|
|
3046
|
-
setError(undefined);
|
|
3047
|
-
createShared(context, channel.name, picked, channel.members).then(() => {
|
|
3048
|
-
onClose();
|
|
3049
|
-
pi.ui.notify(ChannelWords.format(w.sharedMade, { name: channel.name }), "info");
|
|
3050
|
-
}, (failure) => {
|
|
3051
|
-
setBusy(false);
|
|
3052
|
-
setError(ChannelViews.message(failure));
|
|
3053
|
-
});
|
|
3054
|
-
};
|
|
3055
|
-
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3056
|
-
title: w.inviteFriends,
|
|
3057
|
-
onClose
|
|
3058
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
3059
|
-
className: "tac-dialog"
|
|
3060
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
3061
|
-
className: "tac-dialog-note"
|
|
3062
|
-
}, w.shareGroupHint), /* @__PURE__ */ React.createElement("div", {
|
|
3063
|
-
className: "tac-pick-list"
|
|
3064
|
-
}, friends.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3065
|
-
compact: true,
|
|
3066
|
-
title: w.noFriends
|
|
3067
|
-
}), friends.map((friend) => {
|
|
3068
|
-
const on = picked.includes(friend.id);
|
|
3069
|
-
return /* @__PURE__ */ React.createElement("button", {
|
|
3070
|
-
key: friend.id,
|
|
3071
|
-
type: "button",
|
|
3072
|
-
"aria-pressed": on,
|
|
3073
|
-
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
3074
|
-
onClick: () => toggle(friend)
|
|
3075
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
3076
|
-
className: "tac-check"
|
|
3077
|
-
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
3078
|
-
size: 13,
|
|
3079
|
-
strokeWidth: 3
|
|
3080
|
-
})), pi.ui.Face ? /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
3081
|
-
seed: friend.id,
|
|
3082
|
-
size: 30,
|
|
3083
|
-
look: friend.look
|
|
3084
|
-
}) : /* @__PURE__ */ React.createElement("span", {
|
|
3085
|
-
className: "tac-pick-face"
|
|
3086
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
3087
|
-
className: "tac-pick-text"
|
|
3088
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
3089
|
-
className: "tac-pick-name"
|
|
3090
|
-
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
3091
|
-
className: "tac-pick-role"
|
|
3092
|
-
}, w.friend)));
|
|
3093
|
-
})), error && /* @__PURE__ */ React.createElement("div", {
|
|
3094
|
-
className: "tac-empty tac-error"
|
|
3095
|
-
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
3096
|
-
className: "tac-dialog-actions"
|
|
3097
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
3098
|
-
type: "button",
|
|
3099
|
-
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
3100
|
-
disabled: busy || picked.length === 0,
|
|
3101
|
-
onClick: share
|
|
3102
|
-
}, w.shareGroup, busy && /* @__PURE__ */ React.createElement("span", {
|
|
3103
|
-
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
3104
|
-
})))));
|
|
3105
|
-
}
|
|
3106
|
-
function openShareGroup(context, channel) {
|
|
3107
|
-
context.pi.ui.custom?.(({ close }) => /* @__PURE__ */ React.createElement(ShareDialog, {
|
|
3108
|
-
context,
|
|
3109
|
-
channel,
|
|
3110
|
-
onClose: close
|
|
3111
|
-
}));
|
|
3112
|
-
}
|
|
3305
|
+
})(ChannelsText ||= {});
|
|
3306
|
+
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.";
|
|
3307
|
+
var PASS_NOTE = `The user named nobody, and every member got this message: answer only if your role has something of its own to add; the lead answers for the channel. Else answer exactly ${PASS}, which is not posted.`;
|
|
3308
|
+
var NOTICE_RULE = [
|
|
3309
|
+
"A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
|
|
3310
|
+
`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.`
|
|
3311
|
+
].join(`
|
|
3312
|
+
`);
|
|
3113
3313
|
|
|
3114
|
-
// web-src/
|
|
3115
|
-
var
|
|
3116
|
-
|
|
3117
|
-
function newAgent(context) {
|
|
3118
|
-
const { pi, service, ui } = context;
|
|
3119
|
-
if (!ui.state.draft) {
|
|
3120
|
-
const team = service.state.team;
|
|
3121
|
-
const name = ChannelsUtil.freeName(team, ChannelViews.words(pi).newAgentName);
|
|
3122
|
-
ui.set({ draft: { name, face: ChannelsUtil.freeFaceFor(team.agents, ChannelsUtil.newId("draft")) } });
|
|
3123
|
-
}
|
|
3124
|
-
pi.ui.showView(AGENT_PAGE);
|
|
3125
|
-
}
|
|
3126
|
-
function Identity({ context, onClose }) {
|
|
3127
|
-
const { pi, ui } = context;
|
|
3128
|
-
const { draft } = useUi(ui);
|
|
3314
|
+
// web-src/more-menu.tsx
|
|
3315
|
+
var MARGIN = 8;
|
|
3316
|
+
function MoreMenu({ pi, label, items }) {
|
|
3129
3317
|
const w = ChannelViews.words(pi);
|
|
3130
|
-
const
|
|
3131
|
-
const
|
|
3132
|
-
|
|
3133
|
-
|
|
3318
|
+
const [open, setOpen] = React.useState(false);
|
|
3319
|
+
const anchor = React.useRef({
|
|
3320
|
+
right: 0,
|
|
3321
|
+
below: 0,
|
|
3322
|
+
above: 0,
|
|
3323
|
+
finger: undefined
|
|
3324
|
+
});
|
|
3325
|
+
const root = React.useRef(null);
|
|
3326
|
+
const menu = React.useRef(null);
|
|
3327
|
+
const Ellipsis = ChannelViews.icon(pi, "Ellipsis");
|
|
3328
|
+
const show = React.useCallback((button, at) => {
|
|
3329
|
+
const box = button.getBoundingClientRect();
|
|
3330
|
+
const touch = document.documentElement.hasAttribute("data-touch");
|
|
3331
|
+
const row = root.current?.parentElement?.getBoundingClientRect() ?? box;
|
|
3332
|
+
anchor.current = {
|
|
3333
|
+
right: box.right,
|
|
3334
|
+
below: at?.y ?? box.bottom,
|
|
3335
|
+
above: at?.y ?? box.top,
|
|
3336
|
+
finger: touch && at ? { ...at, around: { top: row.top, bottom: row.bottom } } : undefined
|
|
3337
|
+
};
|
|
3338
|
+
setOpen(true);
|
|
3339
|
+
}, []);
|
|
3340
|
+
React.useLayoutEffect(() => {
|
|
3341
|
+
const element = menu.current;
|
|
3342
|
+
if (!open || !element) {
|
|
3343
|
+
return;
|
|
3344
|
+
}
|
|
3345
|
+
const { right, below, above, finger } = anchor.current;
|
|
3346
|
+
if (finger) {
|
|
3347
|
+
return pi.ui.attachMenu(element, finger, () => setOpen(false));
|
|
3348
|
+
}
|
|
3349
|
+
const width = element.offsetWidth;
|
|
3350
|
+
const height = element.offsetHeight;
|
|
3351
|
+
const top = below + 4 + height <= window.innerHeight - MARGIN ? below + 4 : Math.max(MARGIN, above - 4 - height);
|
|
3352
|
+
element.style.top = `${top}px`;
|
|
3353
|
+
element.style.left = `${Math.max(MARGIN, right - width)}px`;
|
|
3354
|
+
}, [open, pi]);
|
|
3355
|
+
React.useEffect(() => {
|
|
3356
|
+
const row = root.current?.parentElement;
|
|
3357
|
+
const button = root.current?.querySelector(".tac-action");
|
|
3358
|
+
if (!row || !button) {
|
|
3359
|
+
return;
|
|
3360
|
+
}
|
|
3361
|
+
const onContextMenu = (event) => {
|
|
3362
|
+
event.preventDefault();
|
|
3363
|
+
show(button, event.clientX || event.clientY ? { x: event.clientX, y: event.clientY } : undefined);
|
|
3364
|
+
};
|
|
3365
|
+
row.addEventListener("contextmenu", onContextMenu);
|
|
3366
|
+
return () => row.removeEventListener("contextmenu", onContextMenu);
|
|
3367
|
+
}, [show]);
|
|
3134
3368
|
React.useEffect(() => {
|
|
3369
|
+
if (!open) {
|
|
3370
|
+
return;
|
|
3371
|
+
}
|
|
3135
3372
|
const close = (event) => {
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3373
|
+
if (!root.current?.contains(event.target)) {
|
|
3374
|
+
setOpen(false);
|
|
3375
|
+
}
|
|
3376
|
+
};
|
|
3377
|
+
const onKey = (event) => {
|
|
3378
|
+
if (event.key === "Escape") {
|
|
3379
|
+
setOpen(false);
|
|
3139
3380
|
}
|
|
3140
3381
|
};
|
|
3141
|
-
const onKey = (event) => event.key === "Escape" && onClose();
|
|
3142
3382
|
document.addEventListener("pointerdown", close);
|
|
3143
3383
|
document.addEventListener("keydown", onKey);
|
|
3144
3384
|
return () => {
|
|
3145
3385
|
document.removeEventListener("pointerdown", close);
|
|
3146
3386
|
document.removeEventListener("keydown", onKey);
|
|
3147
3387
|
};
|
|
3148
|
-
}, [
|
|
3149
|
-
if (!draft) {
|
|
3150
|
-
return null;
|
|
3151
|
-
}
|
|
3152
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
3153
|
-
className: "tac-identity",
|
|
3154
|
-
ref,
|
|
3155
|
-
role: "dialog",
|
|
3156
|
-
"aria-label": w.editAgent
|
|
3157
|
-
}, /* @__PURE__ */ React.createElement("label", {
|
|
3158
|
-
className: "tac-identity-label"
|
|
3159
|
-
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
3160
|
-
className: "tac-input",
|
|
3161
|
-
value: draft.name,
|
|
3162
|
-
maxLength: 40,
|
|
3163
|
-
ref: name,
|
|
3164
|
-
onChange: (event) => ui.set({ draft: { ...draft, name: event.target.value } }),
|
|
3165
|
-
onKeyDown: (event) => event.key === "Enter" && onClose()
|
|
3166
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
3167
|
-
className: "tac-identity-label"
|
|
3168
|
-
}, w.avatar), /* @__PURE__ */ React.createElement("div", {
|
|
3169
|
-
className: "tac-faces"
|
|
3170
|
-
}, Array.from({ length: FACES }, (_, face) => /* @__PURE__ */ React.createElement("button", {
|
|
3171
|
-
key: face,
|
|
3172
|
-
type: "button",
|
|
3173
|
-
"aria-pressed": draft.face === face,
|
|
3174
|
-
className: `tac-face-pick${draft.face === face ? " tac-on" : ""}`,
|
|
3175
|
-
onClick: () => ui.set({ draft: { ...draft, face } })
|
|
3176
|
-
}, /* @__PURE__ */ React.createElement(Face, {
|
|
3177
|
-
face,
|
|
3178
|
-
size: 30
|
|
3179
|
-
})))));
|
|
3180
|
-
}
|
|
3181
|
-
function NewAgentHead({ context }) {
|
|
3182
|
-
const { pi, ui } = context;
|
|
3183
|
-
const { draft, editing } = useUi(ui);
|
|
3184
|
-
const w = ChannelViews.words(pi);
|
|
3185
|
-
const Down = ChannelViews.icon(pi, "ChevronDown");
|
|
3186
|
-
if (!draft) {
|
|
3187
|
-
return null;
|
|
3188
|
-
}
|
|
3388
|
+
}, [open]);
|
|
3189
3389
|
return /* @__PURE__ */ React.createElement("div", {
|
|
3190
|
-
className: "tac-
|
|
3191
|
-
|
|
3192
|
-
className: "tac-new-title"
|
|
3390
|
+
className: "tac-item-more",
|
|
3391
|
+
ref: root
|
|
3193
3392
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
3194
3393
|
type: "button",
|
|
3195
|
-
className:
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3394
|
+
className: `tac-action${open ? " tac-on" : ""}`,
|
|
3395
|
+
title: w.more,
|
|
3396
|
+
"aria-label": w.more,
|
|
3397
|
+
"aria-haspopup": "menu",
|
|
3398
|
+
"aria-expanded": open,
|
|
3399
|
+
onClick: (event) => {
|
|
3400
|
+
event.stopPropagation();
|
|
3401
|
+
if (open) {
|
|
3402
|
+
setOpen(false);
|
|
3403
|
+
} else {
|
|
3404
|
+
show(event.currentTarget);
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
}, /* @__PURE__ */ React.createElement(Ellipsis, {
|
|
3408
|
+
size: 15
|
|
3409
|
+
})), open && /* @__PURE__ */ React.createElement("div", {
|
|
3410
|
+
ref: menu,
|
|
3411
|
+
className: "tac-menu tac-agent-menu",
|
|
3412
|
+
role: "menu",
|
|
3413
|
+
"aria-label": label
|
|
3414
|
+
}, items().filter((section) => section.length > 0).map((section, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
3415
|
+
key: section[0]?.key ?? index
|
|
3416
|
+
}, index > 0 && /* @__PURE__ */ React.createElement("hr", {
|
|
3417
|
+
className: "tac-menu-line"
|
|
3418
|
+
}), section.map((item) => /* @__PURE__ */ React.createElement("button", {
|
|
3419
|
+
key: item.key,
|
|
3208
3420
|
type: "button",
|
|
3209
|
-
|
|
3421
|
+
role: "menuitem",
|
|
3422
|
+
className: item.danger ? "tac-danger" : undefined,
|
|
3423
|
+
disabled: item.disabled,
|
|
3210
3424
|
onClick: () => {
|
|
3211
|
-
|
|
3212
|
-
|
|
3425
|
+
setOpen(false);
|
|
3426
|
+
item.run();
|
|
3213
3427
|
}
|
|
3214
|
-
},
|
|
3428
|
+
}, item.icon, /* @__PURE__ */ React.createElement("span", {
|
|
3429
|
+
className: "tac-menu-label"
|
|
3430
|
+
}, item.label)))))));
|
|
3215
3431
|
}
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3432
|
+
|
|
3433
|
+
// web-src/agent-menu.tsx
|
|
3434
|
+
async function copy(text) {
|
|
3435
|
+
try {
|
|
3436
|
+
await navigator.clipboard.writeText(text);
|
|
3437
|
+
return true;
|
|
3438
|
+
} catch {
|
|
3439
|
+
return false;
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
function download(name, text) {
|
|
3443
|
+
const url = URL.createObjectURL(new Blob([text], { type: "text/markdown;charset=utf-8" }));
|
|
3444
|
+
const link = document.createElement("a");
|
|
3445
|
+
link.href = url;
|
|
3446
|
+
link.download = name;
|
|
3447
|
+
link.click();
|
|
3448
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
3449
|
+
}
|
|
3450
|
+
async function deleteAgent(context, agent) {
|
|
3451
|
+
const w = ChannelViews.words(context.pi);
|
|
3452
|
+
const sure = await context.pi.ui.confirm(ChannelWords.format(w.confirmDeleteAgent, { name: agent.name }), undefined, {
|
|
3453
|
+
confirmLabel: w.delete,
|
|
3454
|
+
danger: true
|
|
3455
|
+
});
|
|
3456
|
+
if (sure) {
|
|
3457
|
+
await context.service.deleteAgent(agent.id);
|
|
3458
|
+
context.sessions.delete(agent.id);
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
var AgentActions;
|
|
3462
|
+
((AgentActions) => {
|
|
3463
|
+
function fail(context, error) {
|
|
3464
|
+
context.pi.ui.notify(ChannelViews.message(error), "error");
|
|
3465
|
+
}
|
|
3466
|
+
function run(context, action) {
|
|
3467
|
+
return () => {
|
|
3468
|
+
Promise.resolve().then(action).catch((error) => fail(context, error));
|
|
3469
|
+
};
|
|
3470
|
+
}
|
|
3471
|
+
AgentActions.run = run;
|
|
3472
|
+
async function openSession(context, agent) {
|
|
3473
|
+
if (!agent.sessionFile) {
|
|
3226
3474
|
return;
|
|
3227
3475
|
}
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3476
|
+
return (await context.pi.server.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
|
|
3477
|
+
}
|
|
3478
|
+
async function stop(context, agent) {
|
|
3479
|
+
const session = await openSession(context, agent);
|
|
3480
|
+
if (session) {
|
|
3481
|
+
await context.pi.server.abort(session.sessionId);
|
|
3231
3482
|
}
|
|
3232
|
-
|
|
3233
|
-
if (!draft) {
|
|
3234
|
-
return null;
|
|
3483
|
+
context.pi.ui.notify(ChannelWords.format(ChannelViews.words(context.pi).stoppedAgent, { name: agent.name }), "info");
|
|
3235
3484
|
}
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
pi.ui.notify(ChannelViews.
|
|
3485
|
+
AgentActions.stop = stop;
|
|
3486
|
+
async function restart(context, agent) {
|
|
3487
|
+
await context.service.resetAgent(agent.id);
|
|
3488
|
+
context.sessions.delete(agent.id);
|
|
3489
|
+
context.pi.ui.notify(ChannelWords.format(ChannelViews.words(context.pi).resetDone, { name: agent.name }), "info");
|
|
3490
|
+
}
|
|
3491
|
+
AgentActions.restart = restart;
|
|
3492
|
+
async function copyCwd(context, cwd) {
|
|
3493
|
+
if (await copy(cwd)) {
|
|
3494
|
+
context.pi.ui.notify(ChannelWords.format(ChannelViews.words(context.pi).copied, { path: cwd }), "info");
|
|
3246
3495
|
}
|
|
3247
|
-
}
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
}
|
|
3276
|
-
|
|
3277
|
-
function
|
|
3496
|
+
}
|
|
3497
|
+
AgentActions.copyCwd = copyCwd;
|
|
3498
|
+
async function exportChat(context, agent) {
|
|
3499
|
+
const { pi, service } = context;
|
|
3500
|
+
const w = ChannelViews.words(pi);
|
|
3501
|
+
const session = await openSession(context, agent);
|
|
3502
|
+
const sessionId = session?.sessionId ?? (agent.sessionFile ? await service.openAgent(agent.id) : undefined);
|
|
3503
|
+
const { messages } = sessionId ? await pi.server.getMessages(sessionId) : { messages: [] };
|
|
3504
|
+
if (!messages.some((message) => message.role === "assistant")) {
|
|
3505
|
+
pi.ui.notify(ChannelWords.format(w.nothingToExport, { name: agent.name }), "info");
|
|
3506
|
+
return;
|
|
3507
|
+
}
|
|
3508
|
+
download(`${agent.name}.md`, ChannelsText.markdown(agent, messages, { user: w.you }));
|
|
3509
|
+
}
|
|
3510
|
+
AgentActions.exportChat = exportChat;
|
|
3511
|
+
function show(context, Dialog, agent) {
|
|
3512
|
+
context.pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(Dialog, {
|
|
3513
|
+
context,
|
|
3514
|
+
agent,
|
|
3515
|
+
onClose: close
|
|
3516
|
+
}));
|
|
3517
|
+
}
|
|
3518
|
+
function shareCard(context, agent) {
|
|
3519
|
+
show(context, CardDialog, agent);
|
|
3520
|
+
}
|
|
3521
|
+
AgentActions.shareCard = shareCard;
|
|
3522
|
+
function joinChannel(context, agent) {
|
|
3523
|
+
show(context, JoinDialog, agent);
|
|
3524
|
+
}
|
|
3525
|
+
AgentActions.joinChannel = joinChannel;
|
|
3526
|
+
async function profile(context, agent) {
|
|
3527
|
+
await ChannelViews.openAgent(context, agent.id);
|
|
3528
|
+
await context.pi.ui.showView(AGENT_INFO_VIEW);
|
|
3529
|
+
}
|
|
3530
|
+
AgentActions.profile = profile;
|
|
3531
|
+
function menu(context, agent, working) {
|
|
3532
|
+
const w = ChannelViews.words(context.pi);
|
|
3533
|
+
const edits = ChannelsUtil.may(context.service.state.team).agent(agent.id);
|
|
3534
|
+
const icon = (name) => ChannelViews.icon(context.pi, name);
|
|
3535
|
+
return [
|
|
3536
|
+
[
|
|
3537
|
+
{ key: "stop", label: w.stop, icon: icon("Square"), disabled: !working && !agent.sessionFile, run: run(context, () => stop(context, agent)) },
|
|
3538
|
+
...edits ? [{ key: "restart", label: w.restart, icon: icon("RotateCcw"), run: run(context, () => restart(context, agent)) }] : []
|
|
3539
|
+
],
|
|
3540
|
+
[
|
|
3541
|
+
...edits ? [{ key: "card", label: w.shareCard, icon: icon("Contact"), run: () => shareCard(context, agent) }] : [],
|
|
3542
|
+
...edits ? [{ key: "join", label: w.joinChannel, icon: icon("UserPlus"), run: () => joinChannel(context, agent) }] : [],
|
|
3543
|
+
{ key: "export", label: w.exportChat, icon: icon("Download"), run: run(context, () => exportChat(context, agent)) }
|
|
3544
|
+
]
|
|
3545
|
+
];
|
|
3546
|
+
}
|
|
3547
|
+
AgentActions.menu = menu;
|
|
3548
|
+
})(AgentActions ||= {});
|
|
3549
|
+
function AgentMenu({ context, agent, cwd, working }) {
|
|
3278
3550
|
const { pi, service } = context;
|
|
3279
|
-
const { team } = useChannels(service);
|
|
3280
|
-
const faces = useFaces(team);
|
|
3281
3551
|
const w = ChannelViews.words(pi);
|
|
3282
|
-
const
|
|
3283
|
-
const
|
|
3284
|
-
const
|
|
3285
|
-
const
|
|
3286
|
-
const
|
|
3287
|
-
const
|
|
3288
|
-
const
|
|
3289
|
-
const
|
|
3290
|
-
const
|
|
3552
|
+
const [dialog, setDialog] = React.useState();
|
|
3553
|
+
const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
|
|
3554
|
+
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
3555
|
+
const act = (action) => AgentActions.run(context, action);
|
|
3556
|
+
const stop = act(() => AgentActions.stop(context, agent));
|
|
3557
|
+
const restart = act(() => AgentActions.restart(context, agent));
|
|
3558
|
+
const copyCwd = act(() => AgentActions.copyCwd(context, cwd));
|
|
3559
|
+
const exportMarkdown = act(() => AgentActions.exportChat(context, agent));
|
|
3560
|
+
const remove = act(() => deleteAgent(context, agent));
|
|
3561
|
+
const pin = act(() => service.updateAgent(agent.id, { pinned: !agent.pinned }));
|
|
3562
|
+
const keep = act(async () => {
|
|
3563
|
+
await service.updateAgent(agent.id, { keep: true });
|
|
3564
|
+
pi.ui.notify(ChannelWords.format(w.kept, { name: agent.name }), "info");
|
|
3565
|
+
});
|
|
3566
|
+
const show = (next) => () => setDialog(next);
|
|
3567
|
+
const edits = ChannelsUtil.may(service.state.team).agent(agent.id);
|
|
3568
|
+
const item = (key, label, glyph, run, options = {}) => ({
|
|
3569
|
+
key,
|
|
3570
|
+
label,
|
|
3571
|
+
icon: icon(glyph),
|
|
3572
|
+
run,
|
|
3573
|
+
...options
|
|
3574
|
+
});
|
|
3575
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(MoreMenu, {
|
|
3576
|
+
pi,
|
|
3577
|
+
label: agent.name,
|
|
3578
|
+
items: () => [
|
|
3579
|
+
edits ? [
|
|
3580
|
+
...agent.temporary ? [item("keep", w.keep, "UserPlus", keep)] : [],
|
|
3581
|
+
item("pin", agent.pinned ? w.unpin : w.pin, agent.pinned ? "PinOff" : "Pin", pin)
|
|
3582
|
+
] : [],
|
|
3583
|
+
[
|
|
3584
|
+
item("stop", w.stop, "Square", stop, { disabled: !working && !agent.sessionFile }),
|
|
3585
|
+
...edits ? [item("restart", w.restart, "RotateCcw", restart)] : []
|
|
3586
|
+
],
|
|
3587
|
+
edits ? [
|
|
3588
|
+
item("settings", w.agentSettings, "SlidersHorizontal", show("settings")),
|
|
3589
|
+
item("rename", w.rename, "Pencil", show("rename")),
|
|
3590
|
+
item("role", w.editRole, "ScrollText", show("role")),
|
|
3591
|
+
item("move", w.moveTo, "FolderInput", show("move")),
|
|
3592
|
+
item("copy", w.copyCwd, "Copy", copyCwd)
|
|
3593
|
+
] : [],
|
|
3594
|
+
[
|
|
3595
|
+
...edits ? [item("card", w.shareCard, "Contact", show("card"))] : [],
|
|
3596
|
+
item("export", w.exportChat, "Download", exportMarkdown),
|
|
3597
|
+
...edits ? [item("join", w.joinChannel, "UserPlus", show("join"))] : []
|
|
3598
|
+
],
|
|
3599
|
+
edits ? [item("delete", w.deleteAgent, "Trash2", remove, { danger: true })] : []
|
|
3600
|
+
]
|
|
3601
|
+
}), dialog === "settings" && /* @__PURE__ */ React.createElement(AgentSettingsDialog, {
|
|
3602
|
+
context,
|
|
3603
|
+
agent,
|
|
3604
|
+
onClose: () => setDialog(undefined)
|
|
3605
|
+
}), dialog === "rename" && /* @__PURE__ */ React.createElement(RenameDialog, {
|
|
3606
|
+
context,
|
|
3607
|
+
agent,
|
|
3608
|
+
onClose: () => setDialog(undefined)
|
|
3609
|
+
}), dialog === "role" && /* @__PURE__ */ React.createElement(RoleDialog, {
|
|
3610
|
+
context,
|
|
3611
|
+
agent,
|
|
3612
|
+
onClose: () => setDialog(undefined)
|
|
3613
|
+
}), dialog === "join" && /* @__PURE__ */ React.createElement(JoinDialog, {
|
|
3614
|
+
context,
|
|
3615
|
+
agent,
|
|
3616
|
+
onClose: () => setDialog(undefined)
|
|
3617
|
+
}), dialog === "card" && /* @__PURE__ */ React.createElement(CardDialog, {
|
|
3618
|
+
context,
|
|
3619
|
+
agent,
|
|
3620
|
+
onClose: () => setDialog(undefined)
|
|
3621
|
+
}), dialog === "move" && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
|
|
3622
|
+
initial: cwd,
|
|
3623
|
+
onClose: () => setDialog(undefined),
|
|
3624
|
+
onPick: async (path) => {
|
|
3625
|
+
setDialog(undefined);
|
|
3626
|
+
if (path !== cwd) {
|
|
3627
|
+
await service.updateAgent(agent.id, { cwd: path }).catch(fail);
|
|
3628
|
+
context.sessions.delete(agent.id);
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
}));
|
|
3632
|
+
}
|
|
3633
|
+
function useSave(action, onClose) {
|
|
3291
3634
|
const [busy, setBusy] = React.useState(false);
|
|
3292
3635
|
const [error, setError] = React.useState();
|
|
3293
|
-
const
|
|
3294
|
-
const shown = team.agents.filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
|
|
3295
|
-
const full = picked.length >= MAX_MEMBERS;
|
|
3296
|
-
const toggle = (agent) => setPicked(picked.includes(agent.id) ? picked.filter((id) => id !== agent.id) : full ? picked : [...picked, agent.id]);
|
|
3297
|
-
const create = (event) => {
|
|
3636
|
+
const submit = (event) => {
|
|
3298
3637
|
event.preventDefault();
|
|
3299
3638
|
setBusy(true);
|
|
3300
3639
|
setError(undefined);
|
|
3301
|
-
|
|
3302
|
-
createShared(context, name.trim(), pickedFriends, picked).then(onClose, (failure) => {
|
|
3303
|
-
setBusy(false);
|
|
3304
|
-
setError(ChannelViews.message(failure));
|
|
3305
|
-
});
|
|
3306
|
-
return;
|
|
3307
|
-
}
|
|
3308
|
-
service.createChannel({ name, members: picked }).then((channel) => {
|
|
3309
|
-
onClose();
|
|
3310
|
-
context.showChannel(channel.id);
|
|
3311
|
-
}, (failure) => {
|
|
3640
|
+
action().then(onClose, (failure) => {
|
|
3312
3641
|
setBusy(false);
|
|
3313
3642
|
setError(ChannelViews.message(failure));
|
|
3314
3643
|
});
|
|
3315
3644
|
};
|
|
3316
|
-
return
|
|
3317
|
-
|
|
3645
|
+
return { busy, error, submit };
|
|
3646
|
+
}
|
|
3647
|
+
function AgentSettingsDialog({ context, agent, onClose }) {
|
|
3648
|
+
const { pi, service } = context;
|
|
3649
|
+
const w = ChannelViews.words(pi);
|
|
3650
|
+
const [name, setName] = React.useState(agent.name);
|
|
3651
|
+
const [model, setModel] = React.useState(agent.model ?? "");
|
|
3652
|
+
const [role, setRole] = React.useState(agent.role);
|
|
3653
|
+
const change = {
|
|
3654
|
+
...name.trim() !== agent.name ? { name } : {},
|
|
3655
|
+
...model !== (agent.model ?? "") ? { model } : {},
|
|
3656
|
+
...role.trim() !== agent.role ? { role } : {}
|
|
3657
|
+
};
|
|
3658
|
+
const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, change), onClose);
|
|
3659
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3660
|
+
title: `${w.agentSettings} · ${agent.name}`,
|
|
3318
3661
|
onClose
|
|
3319
3662
|
}, /* @__PURE__ */ React.createElement("form", {
|
|
3320
3663
|
className: "tac-dialog",
|
|
3321
|
-
onSubmit:
|
|
3664
|
+
onSubmit: submit
|
|
3322
3665
|
}, /* @__PURE__ */ React.createElement("label", {
|
|
3323
3666
|
className: "tac-dialog-label"
|
|
3324
3667
|
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
3325
3668
|
className: "tac-input tac-dialog-input",
|
|
3326
3669
|
value: name,
|
|
3327
|
-
|
|
3328
|
-
maxLength: 40,
|
|
3329
|
-
autoFocus: true,
|
|
3670
|
+
maxLength: 32,
|
|
3330
3671
|
onChange: (event) => setName(event.target.value)
|
|
3331
3672
|
})), /* @__PURE__ */ React.createElement("div", {
|
|
3673
|
+
className: "tac-dialog-field"
|
|
3674
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.model), /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
|
|
3675
|
+
cwd: agent.cwd,
|
|
3676
|
+
value: model,
|
|
3677
|
+
label: w.model,
|
|
3678
|
+
onChange: setModel
|
|
3679
|
+
})), /* @__PURE__ */ React.createElement("label", {
|
|
3332
3680
|
className: "tac-dialog-label"
|
|
3333
|
-
},
|
|
3334
|
-
className: "tac-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
}
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
})
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
3365
|
-
size: 13,
|
|
3366
|
-
strokeWidth: 3
|
|
3367
|
-
})), /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
3368
|
-
agent,
|
|
3369
|
-
faces,
|
|
3370
|
-
size: 30
|
|
3371
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
3372
|
-
className: "tac-pick-text"
|
|
3373
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
3374
|
-
className: "tac-pick-name"
|
|
3375
|
-
}, agent.name, picked[0] === agent.id && /* @__PURE__ */ React.createElement("span", {
|
|
3376
|
-
className: "tac-msg-lead"
|
|
3377
|
-
}, w.lead)), /* @__PURE__ */ React.createElement("span", {
|
|
3378
|
-
className: "tac-pick-role"
|
|
3379
|
-
}, agent.role.split(`
|
|
3380
|
-
`)[0])));
|
|
3381
|
-
})), friends.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
3681
|
+
}, w.editRole, /* @__PURE__ */ React.createElement("textarea", {
|
|
3682
|
+
className: "tac-input tac-settings-role",
|
|
3683
|
+
value: role,
|
|
3684
|
+
placeholder: w.rolePlaceholder,
|
|
3685
|
+
onChange: (event) => setRole(event.target.value)
|
|
3686
|
+
})), /* @__PURE__ */ React.createElement("p", {
|
|
3687
|
+
className: "tac-dialog-note"
|
|
3688
|
+
}, w.agentSettingsHint), error && /* @__PURE__ */ React.createElement("div", {
|
|
3689
|
+
className: "tac-error"
|
|
3690
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
3691
|
+
className: "tac-dialog-actions"
|
|
3692
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
3693
|
+
type: "submit",
|
|
3694
|
+
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
3695
|
+
disabled: busy || !name.trim() || !role.trim() || Object.keys(change).length === 0
|
|
3696
|
+
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
3697
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
3698
|
+
})))));
|
|
3699
|
+
}
|
|
3700
|
+
function RenameDialog({ context, agent, onClose }) {
|
|
3701
|
+
const { pi, service } = context;
|
|
3702
|
+
const w = ChannelViews.words(pi);
|
|
3703
|
+
const [name, setName] = React.useState(agent.name);
|
|
3704
|
+
const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, { name }), onClose);
|
|
3705
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3706
|
+
title: w.rename,
|
|
3707
|
+
onClose
|
|
3708
|
+
}, /* @__PURE__ */ React.createElement("form", {
|
|
3709
|
+
className: "tac-dialog",
|
|
3710
|
+
onSubmit: submit
|
|
3711
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
3382
3712
|
className: "tac-dialog-label"
|
|
3383
|
-
},
|
|
3384
|
-
className: "tac-dialog-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
}))), (picked.length > 0 || shared) && /* @__PURE__ */ React.createElement("div", {
|
|
3713
|
+
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
3714
|
+
className: "tac-input tac-dialog-input",
|
|
3715
|
+
value: name,
|
|
3716
|
+
maxLength: 32,
|
|
3717
|
+
autoFocus: true,
|
|
3718
|
+
onChange: (event) => setName(event.target.value)
|
|
3719
|
+
})), error && /* @__PURE__ */ React.createElement("div", {
|
|
3720
|
+
className: "tac-error"
|
|
3721
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
3722
|
+
className: "tac-dialog-actions"
|
|
3723
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
3724
|
+
type: "submit",
|
|
3725
|
+
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
3726
|
+
disabled: busy || !name.trim() || name.trim() === agent.name
|
|
3727
|
+
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
3728
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
3729
|
+
})))));
|
|
3730
|
+
}
|
|
3731
|
+
function RoleDialog({ context, agent, onClose }) {
|
|
3732
|
+
const { pi, service } = context;
|
|
3733
|
+
const w = ChannelViews.words(pi);
|
|
3734
|
+
const [role, setRole] = React.useState(agent.role);
|
|
3735
|
+
const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, { role }), onClose);
|
|
3736
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3737
|
+
title: `${w.editRole} · ${agent.name}`,
|
|
3738
|
+
onClose
|
|
3739
|
+
}, /* @__PURE__ */ React.createElement("form", {
|
|
3740
|
+
className: "tac-dialog",
|
|
3741
|
+
onSubmit: submit
|
|
3742
|
+
}, /* @__PURE__ */ React.createElement("p", {
|
|
3414
3743
|
className: "tac-dialog-note"
|
|
3415
|
-
},
|
|
3416
|
-
className: "tac-
|
|
3744
|
+
}, w.roleHint), /* @__PURE__ */ React.createElement("textarea", {
|
|
3745
|
+
className: "tac-input tac-role-input",
|
|
3746
|
+
value: role,
|
|
3747
|
+
placeholder: w.rolePlaceholder,
|
|
3748
|
+
"aria-label": w.editRole,
|
|
3749
|
+
autoFocus: true,
|
|
3750
|
+
onChange: (event) => setRole(event.target.value)
|
|
3751
|
+
}), error && /* @__PURE__ */ React.createElement("div", {
|
|
3752
|
+
className: "tac-error"
|
|
3417
3753
|
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
3418
3754
|
className: "tac-dialog-actions"
|
|
3419
3755
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
3420
3756
|
type: "submit",
|
|
3421
3757
|
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
3422
|
-
disabled: busy || !
|
|
3423
|
-
}, w.
|
|
3758
|
+
disabled: busy || !role.trim() || role.trim() === agent.role
|
|
3759
|
+
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
3424
3760
|
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
3425
3761
|
})))));
|
|
3426
3762
|
}
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
(
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
const
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
promptSnippet: "Hand the work over to one of the user's agents or channels",
|
|
3440
|
-
parameters: {
|
|
3441
|
-
type: "object",
|
|
3442
|
-
properties: {
|
|
3443
|
-
to: { type: "string", description: "@name of an agent or #name of a channel." },
|
|
3444
|
-
brief: { type: "string", description: "Complete in itself: the receiver sees only this." }
|
|
3445
|
-
},
|
|
3446
|
-
required: ["to", "brief"]
|
|
3447
|
-
}
|
|
3763
|
+
function JoinDialog({ context, agent, onClose }) {
|
|
3764
|
+
const { pi, service } = context;
|
|
3765
|
+
const { team } = useChannels(service);
|
|
3766
|
+
const w = ChannelViews.words(pi);
|
|
3767
|
+
const Hash = ChannelViews.icon(pi, "Hash");
|
|
3768
|
+
const [error, setError] = React.useState();
|
|
3769
|
+
const open = team.channels.filter((channel) => !channel.members.includes(agent.id));
|
|
3770
|
+
const join = (channelId, name) => {
|
|
3771
|
+
service.addMembers(channelId, [agent.id]).then(() => {
|
|
3772
|
+
onClose();
|
|
3773
|
+
pi.ui.notify(ChannelWords.format(w.joined, { name: agent.name, channel: name }), "info");
|
|
3774
|
+
}, (failure) => setError(ChannelViews.message(failure)));
|
|
3448
3775
|
};
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3776
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3777
|
+
title: `${w.joinChannel} · ${agent.name}`,
|
|
3778
|
+
onClose
|
|
3779
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3780
|
+
className: "tac-dialog"
|
|
3781
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3782
|
+
className: "tac-pick-list"
|
|
3783
|
+
}, open.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3784
|
+
compact: true,
|
|
3785
|
+
title: w.noChannelToJoin
|
|
3786
|
+
}), open.map((channel) => /* @__PURE__ */ React.createElement("button", {
|
|
3787
|
+
key: channel.id,
|
|
3788
|
+
type: "button",
|
|
3789
|
+
className: "tac-pick",
|
|
3790
|
+
disabled: channel.members.length >= MAX_MEMBERS,
|
|
3791
|
+
onClick: () => join(channel.id, channel.name)
|
|
3792
|
+
}, /* @__PURE__ */ React.createElement(Hash, {
|
|
3793
|
+
size: 16
|
|
3794
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
3795
|
+
className: "tac-pick-text"
|
|
3796
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3797
|
+
className: "tac-pick-name"
|
|
3798
|
+
}, channel.name), /* @__PURE__ */ React.createElement("span", {
|
|
3799
|
+
className: "tac-pick-role"
|
|
3800
|
+
}, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(channel.members.length) })))))), error && /* @__PURE__ */ React.createElement("div", {
|
|
3801
|
+
className: "tac-error"
|
|
3802
|
+
}, error)));
|
|
3803
|
+
}
|
|
3804
|
+
function useShownAgent(context) {
|
|
3805
|
+
const { pi, service } = context;
|
|
3806
|
+
const { team } = useChannels(service);
|
|
3807
|
+
const sessionId = pi.ui.useSessionId();
|
|
3808
|
+
const sessions = pi.ui.useSessions();
|
|
3809
|
+
const channelPage = !!pi.ui.useView(CHANNEL_PAGE)?.shown;
|
|
3810
|
+
if (channelPage || !sessionId) {
|
|
3811
|
+
return;
|
|
3474
3812
|
}
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3813
|
+
const file = sessions.find((session) => session.sessionId === sessionId)?.sessionFile;
|
|
3814
|
+
return team.agents.find((agent) => !!file && agent.sessionFile === file || context.sessions.get(agent.id) === sessionId);
|
|
3815
|
+
}
|
|
3816
|
+
function AgentInfoView({ context }) {
|
|
3817
|
+
const { pi, service } = context;
|
|
3818
|
+
const { team, working, loaded } = useChannels(service);
|
|
3819
|
+
const w = ChannelViews.words(pi);
|
|
3820
|
+
const [dialog, setDialog] = React.useState();
|
|
3821
|
+
const serverCwd = useServerCwd(pi);
|
|
3822
|
+
const faces = useFaces(team);
|
|
3823
|
+
const agent = useShownAgent(context);
|
|
3824
|
+
if (!agent) {
|
|
3825
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
3826
|
+
className: "tac-view tac-members"
|
|
3827
|
+
}, loaded && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3828
|
+
title: w.noAgentOpen
|
|
3829
|
+
}));
|
|
3478
3830
|
}
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3831
|
+
const edits = ChannelsUtil.may(team).agent(agent.id);
|
|
3832
|
+
const busy = Object.values(working).some((ids) => ids.includes(agent.id));
|
|
3833
|
+
const cwd = agent.cwd ?? serverCwd ?? "";
|
|
3834
|
+
const Chevron = ChannelViews.icon(pi, "ChevronRight");
|
|
3835
|
+
const Trash = ChannelViews.icon(pi, "Trash2");
|
|
3836
|
+
const HostTag = pi.ui.HostTag;
|
|
3837
|
+
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
3838
|
+
const act = (action2) => AgentActions.run(context, action2);
|
|
3839
|
+
const rename = act(async () => {
|
|
3840
|
+
const name = await pi.ui.input(w.rename, w.name, { value: agent.name });
|
|
3841
|
+
if (name !== undefined && name.trim() && name.trim() !== agent.name) {
|
|
3842
|
+
await service.updateAgent(agent.id, { name });
|
|
3843
|
+
}
|
|
3844
|
+
});
|
|
3845
|
+
const row = (label, value, edit) => edit && edits ? /* @__PURE__ */ React.createElement("button", {
|
|
3846
|
+
type: "button",
|
|
3847
|
+
className: "tac-setting",
|
|
3848
|
+
onClick: edit
|
|
3849
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3850
|
+
className: "tac-setting-label"
|
|
3851
|
+
}, label), /* @__PURE__ */ React.createElement("span", {
|
|
3852
|
+
className: "tac-setting-value"
|
|
3853
|
+
}, value), /* @__PURE__ */ React.createElement(Chevron, {
|
|
3854
|
+
size: 15
|
|
3855
|
+
})) : /* @__PURE__ */ React.createElement("div", {
|
|
3856
|
+
className: "tac-setting"
|
|
3857
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3858
|
+
className: "tac-setting-label"
|
|
3859
|
+
}, label), /* @__PURE__ */ React.createElement("span", {
|
|
3860
|
+
className: "tac-setting-value"
|
|
3861
|
+
}, value));
|
|
3862
|
+
const action = (label, run) => /* @__PURE__ */ React.createElement("button", {
|
|
3863
|
+
type: "button",
|
|
3864
|
+
className: "tac-setting",
|
|
3865
|
+
onClick: run
|
|
3866
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3867
|
+
className: "tac-setting-label"
|
|
3868
|
+
}, label), /* @__PURE__ */ React.createElement(Chevron, {
|
|
3869
|
+
size: 15
|
|
3870
|
+
}));
|
|
3871
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
3872
|
+
className: "tac-view tac-members"
|
|
3873
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3874
|
+
className: "tac-members-scroll"
|
|
3875
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3876
|
+
className: "tac-members-top"
|
|
3877
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
3878
|
+
face: faces.get(agent.id) ?? agent.face ?? 0,
|
|
3879
|
+
size: 44,
|
|
3880
|
+
working: busy
|
|
3881
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
3882
|
+
className: "tac-members-title"
|
|
3883
|
+
}, /* @__PURE__ */ React.createElement("strong", null, agent.name), /* @__PURE__ */ React.createElement("span", null, agent.role.split(`
|
|
3884
|
+
`)[0] || w.agentTag))), /* @__PURE__ */ React.createElement("div", {
|
|
3885
|
+
className: "tac-members-sep"
|
|
3886
|
+
}), row(w.name, agent.name, rename), /* @__PURE__ */ React.createElement("div", {
|
|
3887
|
+
className: "tac-setting tac-setting-model"
|
|
3888
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3889
|
+
className: "tac-setting-label"
|
|
3890
|
+
}, w.model), edits ? /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
|
|
3891
|
+
cwd: agent.cwd,
|
|
3892
|
+
value: agent.model ?? "",
|
|
3893
|
+
label: w.model,
|
|
3894
|
+
onChange: (model) => void service.updateAgent(agent.id, { model }).catch(fail)
|
|
3895
|
+
}) : /* @__PURE__ */ React.createElement("span", {
|
|
3896
|
+
className: "tac-setting-value"
|
|
3897
|
+
}, agent.model || "—")), row(w.editRole, agent.role.split(`
|
|
3898
|
+
`)[0], () => setDialog("role")), row(w.workDir, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(HostTag, {
|
|
3899
|
+
location: cwd
|
|
3900
|
+
}), cwd && SidebarUtil.folder(cwd)), () => setDialog("move")), /* @__PURE__ */ React.createElement("div", {
|
|
3901
|
+
className: "tac-members-sep"
|
|
3902
|
+
}), edits && action(w.shareCard, () => AgentActions.shareCard(context, agent)), edits && action(w.joinChannel, () => AgentActions.joinChannel(context, agent)), action(w.exportChat, act(() => AgentActions.exportChat(context, agent))), cwd && action(w.copyCwd, act(() => AgentActions.copyCwd(context, cwd)))), edits && /* @__PURE__ */ React.createElement("div", {
|
|
3903
|
+
className: "tac-members-foot"
|
|
3904
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
3905
|
+
type: "button",
|
|
3906
|
+
className: "tac-link tac-danger",
|
|
3907
|
+
onClick: act(() => deleteAgent(context, agent))
|
|
3908
|
+
}, /* @__PURE__ */ React.createElement(Trash, {
|
|
3909
|
+
size: 14
|
|
3910
|
+
}), w.deleteAgentLong)), dialog === "role" && /* @__PURE__ */ React.createElement(RoleDialog, {
|
|
3911
|
+
context,
|
|
3912
|
+
agent,
|
|
3913
|
+
onClose: () => setDialog(undefined)
|
|
3914
|
+
}), dialog === "move" && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
|
|
3915
|
+
initial: cwd,
|
|
3916
|
+
onClose: () => setDialog(undefined),
|
|
3917
|
+
onPick: async (path) => {
|
|
3918
|
+
setDialog(undefined);
|
|
3919
|
+
if (path !== cwd) {
|
|
3920
|
+
await service.updateAgent(agent.id, { cwd: path }).catch(fail);
|
|
3921
|
+
context.sessions.delete(agent.id);
|
|
3487
3922
|
}
|
|
3488
|
-
const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
|
|
3489
|
-
const end = lines.findIndex((line, at) => at > index && close.test(line));
|
|
3490
|
-
found = lines.slice(index + 1, end < 0 ? lines.length : end);
|
|
3491
|
-
index = end < 0 ? lines.length : end;
|
|
3492
3923
|
}
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
return brief || undefined;
|
|
3496
|
-
}
|
|
3497
|
-
HandOff.find = find;
|
|
3498
|
-
function message(origin, brief, language) {
|
|
3499
|
-
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
3500
|
-
const head = TaLanguageUtil.pick(language, {
|
|
3501
|
-
"zh-CN": `(交接自“${title}”)`,
|
|
3502
|
-
"zh-TW": `(交接自「${title}」)`,
|
|
3503
|
-
"en-US": `(Handed over from “${title}”)`,
|
|
3504
|
-
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
3505
|
-
});
|
|
3506
|
-
const context = [
|
|
3507
|
-
"The user handed you this work from another conversation of theirs, which you do not see; the brief below is all it says. Go on from there in this conversation, which the user follows; ask them when the brief leaves out something you need.",
|
|
3508
|
-
origin.sessionFile ? `That conversation is pi's session file ${origin.sessionFile}${origin.cwd ? `, working in ${origin.cwd}` : ""}: read it only when the brief is not enough.` : ""
|
|
3509
|
-
].filter(Boolean).join(`
|
|
3510
|
-
`);
|
|
3511
|
-
return TaMessageContext.wrap(context, `${head}
|
|
3924
|
+
}));
|
|
3925
|
+
}
|
|
3512
3926
|
|
|
3513
|
-
|
|
3927
|
+
// web-src/channels.ts
|
|
3928
|
+
class ChannelsClient {
|
|
3929
|
+
storage;
|
|
3930
|
+
send;
|
|
3931
|
+
current = { team: ChannelsUtil.emptyTeam(), messages: {}, working: {}, answered: {}, loaded: false, deleting: [] };
|
|
3932
|
+
listeners = new Set;
|
|
3933
|
+
focusListeners = new Set;
|
|
3934
|
+
loading;
|
|
3935
|
+
pictures = new Map;
|
|
3936
|
+
unlisten;
|
|
3937
|
+
constructor(storage, send) {
|
|
3938
|
+
this.storage = storage;
|
|
3939
|
+
this.send = send;
|
|
3940
|
+
this.unlisten = storage.onChange((keys) => void this.changed(keys));
|
|
3514
3941
|
}
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
3518
|
-
return `${TaLanguageUtil.pick(language, {
|
|
3519
|
-
"zh-CN": `(交接自“${title}”)`,
|
|
3520
|
-
"zh-TW": `(交接自「${title}」)`,
|
|
3521
|
-
"en-US": `(Handed over from “${title}”)`,
|
|
3522
|
-
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
3523
|
-
})}
|
|
3524
|
-
|
|
3525
|
-
${brief.trim()}`;
|
|
3942
|
+
get state() {
|
|
3943
|
+
return this.current;
|
|
3526
3944
|
}
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
return
|
|
3945
|
+
subscribe(listener) {
|
|
3946
|
+
this.listeners.add(listener);
|
|
3947
|
+
return () => this.listeners.delete(listener);
|
|
3530
3948
|
}
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
return
|
|
3949
|
+
onFocus(listener) {
|
|
3950
|
+
this.focusListeners.add(listener);
|
|
3951
|
+
return () => this.focusListeners.delete(listener);
|
|
3534
3952
|
}
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3953
|
+
dispose() {
|
|
3954
|
+
this.unlisten();
|
|
3955
|
+
}
|
|
3956
|
+
load(again = false) {
|
|
3957
|
+
if (!this.loading || again) {
|
|
3958
|
+
this.loading = Promise.all([
|
|
3959
|
+
this.storage.get(Keys.TEAM),
|
|
3960
|
+
this.storage.get(Keys.WORKING),
|
|
3961
|
+
this.storage.get(Keys.ANSWERED)
|
|
3962
|
+
]).then(([team, working, answered]) => this.update({ team: team ?? ChannelsUtil.emptyTeam(), working: working ?? {}, answered: answered ?? {}, loaded: true }));
|
|
3545
3963
|
}
|
|
3546
|
-
|
|
3547
|
-
return channel ? membersOf(team, channel) : [];
|
|
3964
|
+
return this.loading;
|
|
3548
3965
|
}
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
}
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
const faces = useFaces(team);
|
|
3558
|
-
if (!card?.target) {
|
|
3559
|
-
return null;
|
|
3966
|
+
async messages(channelId, again = false) {
|
|
3967
|
+
const known = this.current.messages[channelId];
|
|
3968
|
+
if (known && !again) {
|
|
3969
|
+
return known;
|
|
3970
|
+
}
|
|
3971
|
+
const messages = await this.storage.get(Keys.messages(channelId)) ?? [];
|
|
3972
|
+
this.update({ messages: { ...this.current.messages, [channelId]: messages } });
|
|
3973
|
+
return messages;
|
|
3560
3974
|
}
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
}
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
}
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3975
|
+
async createAgent(input) {
|
|
3976
|
+
const agent = await this.send({ kind: "createAgent", ...input });
|
|
3977
|
+
await this.load(true);
|
|
3978
|
+
return agent;
|
|
3979
|
+
}
|
|
3980
|
+
async createChannel(input) {
|
|
3981
|
+
const channel = await this.send({ kind: "createChannel", ...input });
|
|
3982
|
+
await this.load(true);
|
|
3983
|
+
return channel;
|
|
3984
|
+
}
|
|
3985
|
+
async addMembers(channelId, members) {
|
|
3986
|
+
const channel = await this.send({ kind: "addMembers", channel: channelId, members });
|
|
3987
|
+
await this.load(true);
|
|
3988
|
+
return channel;
|
|
3989
|
+
}
|
|
3990
|
+
async changeMember(channelId, agentId, change) {
|
|
3991
|
+
const channel = await this.send({ kind: "changeMember", channel: channelId, agent: agentId, change });
|
|
3992
|
+
await this.load(true);
|
|
3993
|
+
return channel;
|
|
3994
|
+
}
|
|
3995
|
+
async updateChannel(channelId, change) {
|
|
3996
|
+
const channel = await this.send({ kind: "updateChannel", channel: channelId, ...change });
|
|
3997
|
+
await this.load(true);
|
|
3998
|
+
return channel;
|
|
3999
|
+
}
|
|
4000
|
+
async deleteChannel(channelId) {
|
|
4001
|
+
await this.deleting(channelId, async () => {
|
|
4002
|
+
await this.send({ kind: "deleteChannel", channel: channelId });
|
|
4003
|
+
const { [channelId]: _gone, ...messages } = this.current.messages;
|
|
4004
|
+
this.update({ messages });
|
|
4005
|
+
await this.load(true);
|
|
3589
4006
|
});
|
|
3590
4007
|
}
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
if (!node2) {
|
|
3596
|
-
const Face2 = () => {
|
|
3597
|
-
const team = useTeam(context);
|
|
3598
|
-
const faces = useFaces(team);
|
|
3599
|
-
const members = HandOffViewUtil.members(team, target);
|
|
3600
|
-
return members.length ? /* @__PURE__ */ React.createElement(RoomFace, {
|
|
3601
|
-
members,
|
|
3602
|
-
faces,
|
|
3603
|
-
size: 16,
|
|
3604
|
-
working: []
|
|
3605
|
-
}) : null;
|
|
3606
|
-
};
|
|
3607
|
-
node2 = /* @__PURE__ */ React.createElement(Face2, null);
|
|
3608
|
-
icons.set(key, node2);
|
|
3609
|
-
}
|
|
3610
|
-
return node2;
|
|
4008
|
+
async resetAgent(agentId) {
|
|
4009
|
+
const agent = await this.send({ kind: "resetAgent", agent: agentId });
|
|
4010
|
+
await this.load(true);
|
|
4011
|
+
return agent;
|
|
3611
4012
|
}
|
|
3612
|
-
|
|
3613
|
-
const
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
message: HandOff.ask(context.pi.ui.language, to),
|
|
3617
|
-
streamingBehavior: "followUp"
|
|
3618
|
-
}).catch((error) => context.pi.ui.notify(ChannelViews.message(error), "error"));
|
|
3619
|
-
return {
|
|
3620
|
-
actions: (conversation) => {
|
|
3621
|
-
const { team } = context.service.state;
|
|
3622
|
-
if (conversation.group === NAME || team.agents.length === 0 && team.channels.length === 0) {
|
|
3623
|
-
return [];
|
|
3624
|
-
}
|
|
3625
|
-
const w = ChannelViews.words(context.pi);
|
|
3626
|
-
const Forward = ChannelViews.icon(context.pi, "Forward");
|
|
3627
|
-
const agents = team.agents.filter((agent) => !agent.temporary).map((agent) => ({
|
|
3628
|
-
key: `handoff:agent:${agent.id}`,
|
|
3629
|
-
label: agent.name,
|
|
3630
|
-
detail: agent.role.split(`
|
|
3631
|
-
`)[0],
|
|
3632
|
-
group: w.agents,
|
|
3633
|
-
icon: icon(context, { kind: "agent", id: agent.id }, icons),
|
|
3634
|
-
run: () => send(conversation, `@${agent.name}`)
|
|
3635
|
-
}));
|
|
3636
|
-
const channels = team.channels.map((channel) => ({
|
|
3637
|
-
key: `handoff:channel:${channel.id}`,
|
|
3638
|
-
label: `#${channel.name}`,
|
|
3639
|
-
detail: channel.topic,
|
|
3640
|
-
group: w.channels,
|
|
3641
|
-
icon: icon(context, { kind: "channel", id: channel.id }, icons),
|
|
3642
|
-
run: () => send(conversation, `#${channel.name}`)
|
|
3643
|
-
}));
|
|
3644
|
-
return [{ key: "handoff", label: w.handOff, detail: w.handOffDetail, icon: /* @__PURE__ */ React.createElement(Forward, {
|
|
3645
|
-
size: 16
|
|
3646
|
-
}), items: [...agents, ...channels] }];
|
|
3647
|
-
},
|
|
3648
|
-
subscribe: (listener) => context.service.subscribe(listener)
|
|
3649
|
-
};
|
|
4013
|
+
async updateAgent(agentId, change) {
|
|
4014
|
+
const agent = await this.send({ kind: "updateAgent", agent: agentId, ...change });
|
|
4015
|
+
await this.load(true);
|
|
4016
|
+
return agent;
|
|
3650
4017
|
}
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
var ChannelRounds;
|
|
3656
|
-
((ChannelRounds) => {
|
|
3657
|
-
const SHORT = 20;
|
|
3658
|
-
const MIN_PAIRS = 8;
|
|
3659
|
-
const ALIKE = 0.8;
|
|
3660
|
-
const PING_PONG = 4;
|
|
3661
|
-
const NEW = 0.35;
|
|
3662
|
-
const CHANGES = new Set(["edit", "write", "delete", "move"]);
|
|
3663
|
-
function scale(watchedAt, pages, now) {
|
|
3664
|
-
if (watchedAt !== undefined && now - watchedAt < 2 * WATCH_MS) {
|
|
3665
|
-
return 2;
|
|
3666
|
-
}
|
|
3667
|
-
return pages === undefined || pages > 0 ? 1 : 0.5;
|
|
4018
|
+
async setChannelModel(channelId, model) {
|
|
4019
|
+
const channel = await this.send({ kind: "setChannelModel", channel: channelId, model });
|
|
4020
|
+
await this.load(true);
|
|
4021
|
+
return channel;
|
|
3668
4022
|
}
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
}
|
|
3680
|
-
|
|
3681
|
-
if (recent.length === 3 && recent.every((item) => units(item.text).join("").length < SHORT)) {
|
|
3682
|
-
return "agree";
|
|
3683
|
-
}
|
|
3684
|
-
const run = said.slice(-PING_PONG);
|
|
3685
|
-
const authors = new Set(run.map((item) => item.author));
|
|
3686
|
-
const alternate = run.every((item, i) => i === 0 || item.author !== run[i - 1].author);
|
|
3687
|
-
const start = said.length - PING_PONG;
|
|
3688
|
-
if (progress || start <= 0 || authors.size !== 2 || !alternate) {
|
|
3689
|
-
return;
|
|
3690
|
-
}
|
|
3691
|
-
const seen = new Set(pairs.slice(0, start).flat());
|
|
3692
|
-
for (const own of pairs.slice(start)) {
|
|
3693
|
-
const fresh = own.filter((pair) => !seen.has(pair)).length;
|
|
3694
|
-
if (own.length === 0 || fresh / own.length >= NEW) {
|
|
3695
|
-
return;
|
|
3696
|
-
}
|
|
3697
|
-
for (const pair of own) {
|
|
3698
|
-
seen.add(pair);
|
|
3699
|
-
}
|
|
4023
|
+
async deleteAgent(agentId) {
|
|
4024
|
+
await this.deleting(agentId, async () => {
|
|
4025
|
+
await this.send({ kind: "deleteAgent", agent: agentId });
|
|
4026
|
+
await this.load(true);
|
|
4027
|
+
});
|
|
4028
|
+
}
|
|
4029
|
+
async deleting(id, action) {
|
|
4030
|
+
this.update({ deleting: [...this.current.deleting, id] });
|
|
4031
|
+
try {
|
|
4032
|
+
await action();
|
|
4033
|
+
} finally {
|
|
4034
|
+
this.update({ deleting: this.current.deleting.filter((other) => other !== id) });
|
|
3700
4035
|
}
|
|
3701
|
-
return "pingPong";
|
|
3702
4036
|
}
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
4037
|
+
async openAgent(agentId) {
|
|
4038
|
+
const { sessionId } = await this.send({ kind: "openAgent", agent: agentId });
|
|
4039
|
+
return sessionId;
|
|
3707
4040
|
}
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
return { answer: pick("answer"), channelDay: pick("channelDay"), allDay: pick("allDay") };
|
|
4041
|
+
async setNotice(channelId, text) {
|
|
4042
|
+
const channel = await this.send({ kind: "setNotice", channel: channelId, text });
|
|
4043
|
+
await this.load(true);
|
|
4044
|
+
return channel;
|
|
3713
4045
|
}
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
const current = day(now);
|
|
3717
|
-
return stored?.day === current ? stored : { day: current, total: 0, channels: {} };
|
|
4046
|
+
shareAgent(agentId, color) {
|
|
4047
|
+
return this.send({ kind: "shareAgent", agent: agentId, ...color ? { color } : {} });
|
|
3718
4048
|
}
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
const current = today(stored, now);
|
|
3722
|
-
return { ...current, total: current.total + tokens, channels: { ...current.channels, [channelId]: (current.channels[channelId] ?? 0) + tokens } };
|
|
4049
|
+
async stopCard(agentId) {
|
|
4050
|
+
return await this.send({ kind: "stopCard", agent: agentId });
|
|
3723
4051
|
}
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
if (granted) {
|
|
3727
|
-
return;
|
|
3728
|
-
}
|
|
3729
|
-
if (limits2.allDay > 0 && spent.total >= limits2.allDay) {
|
|
3730
|
-
return "all";
|
|
3731
|
-
}
|
|
3732
|
-
if (hops > 0 && limits2.channelDay > 0 && (spent.channels[channelId] ?? 0) >= limits2.channelDay) {
|
|
3733
|
-
return "channel";
|
|
3734
|
-
}
|
|
3735
|
-
return;
|
|
4052
|
+
openCard(link, password) {
|
|
4053
|
+
return this.send({ kind: "openCard", link, ...password ? { password } : {} });
|
|
3736
4054
|
}
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
4055
|
+
async addFromCard(link, cwd, password) {
|
|
4056
|
+
const added = await this.send({ kind: "addFromCard", link, cwd, ...password ? { password } : {} });
|
|
4057
|
+
await this.load(true);
|
|
4058
|
+
return added;
|
|
4059
|
+
}
|
|
4060
|
+
async post(channelId, text, images = []) {
|
|
4061
|
+
await this.send({
|
|
4062
|
+
kind: "post",
|
|
4063
|
+
channel: channelId,
|
|
4064
|
+
text,
|
|
4065
|
+
...images.length ? { images: images.map(({ data, mimeType, width, height }) => ({ data, mimeType, width, height })) } : {}
|
|
4066
|
+
});
|
|
4067
|
+
}
|
|
4068
|
+
picture(channelId, id) {
|
|
4069
|
+
const key = `${channelId}:${id}`;
|
|
4070
|
+
let read = this.pictures.get(key);
|
|
4071
|
+
if (!read) {
|
|
4072
|
+
read = this.send({ kind: "picture", channel: channelId, id }).then((data) => typeof data === "string" ? data : "", () => "");
|
|
4073
|
+
this.pictures.set(key, read);
|
|
4074
|
+
for (const old of this.pictures.keys()) {
|
|
4075
|
+
if (this.pictures.size <= 60) {
|
|
4076
|
+
break;
|
|
3750
4077
|
}
|
|
4078
|
+
this.pictures.delete(old);
|
|
3751
4079
|
}
|
|
3752
4080
|
}
|
|
3753
|
-
return
|
|
4081
|
+
return read;
|
|
3754
4082
|
}
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
return text.replace(/@[^\s@#,,。::]+/g, " ").toLowerCase().match(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]|[\p{L}\p{N}]+/gu) ?? [];
|
|
4083
|
+
async resumeRound(channelId, messageId, how) {
|
|
4084
|
+
await this.send({ kind: "resumeRound", channel: channelId, message: messageId, how });
|
|
3758
4085
|
}
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
return words.length === 1 ? words : words.slice(1).map((word, i) => `${words[i]} ${word}`);
|
|
4086
|
+
async setLimits(limits) {
|
|
4087
|
+
await this.send({ kind: "setLimits", limits });
|
|
3762
4088
|
}
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
const
|
|
3768
|
-
for (const
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
4089
|
+
async watch(channelId) {
|
|
4090
|
+
await this.send({ kind: "watch", channel: channelId });
|
|
4091
|
+
}
|
|
4092
|
+
async changed(keys) {
|
|
4093
|
+
const reads = [];
|
|
4094
|
+
for (const key of keys) {
|
|
4095
|
+
if (key === Keys.TEAM || key === Keys.WORKING || key === Keys.ANSWERED) {
|
|
4096
|
+
reads.push(this.load(true));
|
|
4097
|
+
} else if (key.startsWith(Keys.MESSAGES)) {
|
|
4098
|
+
const channelId = key.slice(Keys.MESSAGES.length);
|
|
4099
|
+
if (this.current.messages[channelId]) {
|
|
4100
|
+
reads.push(this.messages(channelId, true));
|
|
4101
|
+
}
|
|
4102
|
+
} else if (key === Keys.FOCUS) {
|
|
4103
|
+
reads.push(this.storage.get(Keys.FOCUS).then(async (focus) => {
|
|
4104
|
+
if (focus) {
|
|
4105
|
+
await this.load(true);
|
|
4106
|
+
for (const listener of this.focusListeners) {
|
|
4107
|
+
listener(focus.channelId);
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
}));
|
|
3777
4111
|
}
|
|
3778
4112
|
}
|
|
3779
|
-
|
|
4113
|
+
await Promise.all(reads).catch((error) => console.error(error));
|
|
4114
|
+
}
|
|
4115
|
+
update(change) {
|
|
4116
|
+
this.current = { ...this.current, ...change };
|
|
4117
|
+
for (const listener of this.listeners) {
|
|
4118
|
+
listener(this.current);
|
|
4119
|
+
}
|
|
3780
4120
|
}
|
|
3781
|
-
})(ChannelRounds ||= {});
|
|
3782
|
-
|
|
3783
|
-
// web-src/limit-settings.tsx
|
|
3784
|
-
function amount(pi, tokens) {
|
|
3785
|
-
return tokens > 0 ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(tokens) : ChannelWords.of(pi.ui.language).noLimit;
|
|
3786
4121
|
}
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
}), [pi]);
|
|
3792
|
-
const [value, setValue] = React.useState({ limits: ChannelRounds.limits(undefined), spent: 0, channels: {} });
|
|
4122
|
+
|
|
4123
|
+
// web-src/shared-group.tsx
|
|
4124
|
+
function useFriends(pi) {
|
|
4125
|
+
const [friends, setFriends] = React.useState([]);
|
|
3793
4126
|
React.useEffect(() => {
|
|
3794
4127
|
let live = true;
|
|
3795
|
-
|
|
4128
|
+
pi.rooms?.listFriends().then((list) => live && setFriends(list.filter((friend) => friend.status === "friend")), () => {
|
|
3796
4129
|
return;
|
|
3797
4130
|
});
|
|
3798
|
-
load();
|
|
3799
|
-
const stop = pi.storage.onChange((keys) => (keys.includes(Keys.LIMITS) || keys.includes(Keys.SPENT)) && load());
|
|
3800
4131
|
return () => {
|
|
3801
4132
|
live = false;
|
|
3802
|
-
stop();
|
|
3803
4133
|
};
|
|
3804
|
-
}, [pi
|
|
3805
|
-
return
|
|
4134
|
+
}, [pi]);
|
|
4135
|
+
return friends;
|
|
3806
4136
|
}
|
|
3807
|
-
function
|
|
3808
|
-
const
|
|
3809
|
-
const
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
return /* @__PURE__ */ React.createElement("fieldset", {
|
|
3813
|
-
className: "ta-segmented",
|
|
3814
|
-
"aria-label": words()[key === "answer" ? "limitAnswer" : key === "channelDay" ? "limitChannelDay" : "limitAllDay"]
|
|
3815
|
-
}, LIMIT_CHOICES[key].map((value) => /* @__PURE__ */ React.createElement("button", {
|
|
3816
|
-
key: value,
|
|
3817
|
-
type: "button",
|
|
3818
|
-
"aria-pressed": limits[key] === value,
|
|
3819
|
-
className: limits[key] === value ? "ta-on" : "",
|
|
3820
|
-
onClick: () => pick(value)
|
|
3821
|
-
}, amount(pi, value))));
|
|
3822
|
-
};
|
|
3823
|
-
function Spent() {
|
|
3824
|
-
const { spent } = useLimits(pi);
|
|
3825
|
-
return /* @__PURE__ */ React.createElement("span", {
|
|
3826
|
-
className: "tac-limit-spent"
|
|
3827
|
-
}, spent > 0 ? amount(pi, spent) : "0");
|
|
4137
|
+
async function createShared(context, title, friends, agents) {
|
|
4138
|
+
const { pi } = context;
|
|
4139
|
+
const rooms = pi.rooms;
|
|
4140
|
+
if (!rooms) {
|
|
4141
|
+
throw new Error(ChannelViews.words(pi).sharedNeedsRooms);
|
|
3828
4142
|
}
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
4143
|
+
const room = await rooms.createRoom({ kind: ROOMS_KIND, title });
|
|
4144
|
+
await rooms.inviteFriends(room.id, friends);
|
|
4145
|
+
for (const agent of agents) {
|
|
4146
|
+
await pi.packages.callPackageHost(ROOMS_PACKAGE, "doubles", [{ kind: "invite", room: room.id, agent }]).catch((error) => {
|
|
4147
|
+
pi.ui.notify(ChannelViews.message(error), "error");
|
|
4148
|
+
});
|
|
4149
|
+
}
|
|
4150
|
+
const { link } = await rooms.invite(room.id);
|
|
4151
|
+
await pi.openLink?.(link);
|
|
4152
|
+
return room.id;
|
|
4153
|
+
}
|
|
4154
|
+
var ROOMS_PACKAGE = "@celljs/ta-rooms";
|
|
4155
|
+
var ROOMS_KIND = "ta-rooms";
|
|
4156
|
+
async function becomeGroup(context, channel, friends, agents) {
|
|
4157
|
+
const { pi } = context;
|
|
4158
|
+
const members = [...channel.members, ...agents.filter((id) => !channel.members.includes(id))];
|
|
4159
|
+
const room = await createShared(context, channel.name, friends, members);
|
|
4160
|
+
await context.service.updateChannel(channel.id, { shared: room });
|
|
4161
|
+
pi.ui.notify(ChannelWords.format(ChannelViews.words(pi).sharedMade, { name: channel.name }), "info");
|
|
3840
4162
|
}
|
|
3841
4163
|
|
|
3842
|
-
//
|
|
3843
|
-
var
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
const
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
["context", /<\/?context>/],
|
|
3852
|
-
["source", /\[ta:(?:from|notice|by) /],
|
|
3853
|
-
["image note", /\[Image: original \d+x\d+|\[Image converted from /],
|
|
3854
|
-
["skill", /<skill name="|<\/skill>/],
|
|
3855
|
-
["task note", /<\/?task_(?:update|adopted|renamed)\b/],
|
|
3856
|
-
["summary", /<\/?(?:conversation_history_summary|summary)>/]
|
|
3857
|
-
];
|
|
3858
|
-
function text(content, joiner = `
|
|
3859
|
-
`) {
|
|
3860
|
-
if (typeof content === "string") {
|
|
3861
|
-
return content;
|
|
3862
|
-
}
|
|
3863
|
-
return Array.isArray(content) ? content.filter((part) => (part === null || part === undefined ? undefined : part.type) === "text" && typeof part.text === "string").map((part) => part.text).join(joiner) : "";
|
|
3864
|
-
}
|
|
3865
|
-
TaSaid2.text = text;
|
|
3866
|
-
function words(role, text2, options = {}) {
|
|
3867
|
-
const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
|
|
3868
|
-
return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
|
|
3869
|
-
}
|
|
3870
|
-
TaSaid2.words = words;
|
|
3871
|
-
function of(message, options) {
|
|
3872
|
-
return message ? words(message.role, text(message.content), options) : "";
|
|
3873
|
-
}
|
|
3874
|
-
TaSaid2.of = of;
|
|
3875
|
-
function notice(message) {
|
|
3876
|
-
return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
|
|
4164
|
+
// web-src/create.tsx
|
|
4165
|
+
var noBack = (_open, _close) => false;
|
|
4166
|
+
var AGENT_PAGE = `${NAME}/agent`;
|
|
4167
|
+
function newAgent(context) {
|
|
4168
|
+
const { pi, service, ui } = context;
|
|
4169
|
+
if (!ui.state.draft) {
|
|
4170
|
+
const team = service.state.team;
|
|
4171
|
+
const name = ChannelsUtil.freeName(team, ChannelViews.words(pi).newAgentName);
|
|
4172
|
+
ui.set({ draft: { name, face: ChannelsUtil.freeFaceFor(team.agents, ChannelsUtil.newId("draft")) } });
|
|
3877
4173
|
}
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
4174
|
+
pi.ui.showView(AGENT_PAGE);
|
|
4175
|
+
}
|
|
4176
|
+
function Identity({ context, onClose }) {
|
|
4177
|
+
const { pi, ui } = context;
|
|
4178
|
+
const { draft } = useUi(ui);
|
|
4179
|
+
const w = ChannelViews.words(pi);
|
|
4180
|
+
const ref = React.useRef(null);
|
|
4181
|
+
const name = React.useRef(null);
|
|
4182
|
+
React.useEffect(() => name.current?.select(), []);
|
|
4183
|
+
(pi.ui.useBackLayer ?? noBack)(true, onClose);
|
|
4184
|
+
React.useEffect(() => {
|
|
4185
|
+
const close = (event) => {
|
|
4186
|
+
const target = event.target;
|
|
4187
|
+
if (!ref.current?.contains(target) && !target.closest?.(".tac-identity-open")) {
|
|
4188
|
+
onClose();
|
|
4189
|
+
}
|
|
4190
|
+
};
|
|
4191
|
+
const onKey = (event) => event.key === "Escape" && onClose();
|
|
4192
|
+
document.addEventListener("pointerdown", close);
|
|
4193
|
+
document.addEventListener("keydown", onKey);
|
|
4194
|
+
return () => {
|
|
4195
|
+
document.removeEventListener("pointerdown", close);
|
|
4196
|
+
document.removeEventListener("keydown", onKey);
|
|
4197
|
+
};
|
|
4198
|
+
}, [onClose]);
|
|
4199
|
+
if (!draft) {
|
|
4200
|
+
return null;
|
|
3881
4201
|
}
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
4202
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4203
|
+
className: "tac-identity",
|
|
4204
|
+
ref,
|
|
4205
|
+
role: "dialog",
|
|
4206
|
+
"aria-label": w.editAgent
|
|
4207
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
4208
|
+
className: "tac-identity-label"
|
|
4209
|
+
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
4210
|
+
className: "tac-input",
|
|
4211
|
+
value: draft.name,
|
|
4212
|
+
maxLength: 40,
|
|
4213
|
+
ref: name,
|
|
4214
|
+
onChange: (event) => ui.set({ draft: { ...draft, name: event.target.value } }),
|
|
4215
|
+
onKeyDown: (event) => event.key === "Enter" && onClose()
|
|
4216
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
4217
|
+
className: "tac-identity-label"
|
|
4218
|
+
}, w.avatar), /* @__PURE__ */ React.createElement("div", {
|
|
4219
|
+
className: "tac-faces"
|
|
4220
|
+
}, Array.from({ length: FACES }, (_, face) => /* @__PURE__ */ React.createElement("button", {
|
|
4221
|
+
key: face,
|
|
4222
|
+
type: "button",
|
|
4223
|
+
"aria-pressed": draft.face === face,
|
|
4224
|
+
className: `tac-face-pick${draft.face === face ? " tac-on" : ""}`,
|
|
4225
|
+
onClick: () => ui.set({ draft: { ...draft, face } })
|
|
4226
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
4227
|
+
face,
|
|
4228
|
+
size: 30
|
|
4229
|
+
})))));
|
|
4230
|
+
}
|
|
4231
|
+
function NewAgentHead({ context }) {
|
|
4232
|
+
const { pi, ui } = context;
|
|
4233
|
+
const { draft, editing } = useUi(ui);
|
|
4234
|
+
const w = ChannelViews.words(pi);
|
|
4235
|
+
const Down = ChannelViews.icon(pi, "ChevronDown");
|
|
4236
|
+
if (!draft) {
|
|
4237
|
+
return null;
|
|
3893
4238
|
}
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
4239
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4240
|
+
className: "tac-new-head"
|
|
4241
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4242
|
+
className: "tac-new-title"
|
|
4243
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
4244
|
+
type: "button",
|
|
4245
|
+
className: "tac-new-trigger tac-identity-open",
|
|
4246
|
+
"aria-expanded": editing,
|
|
4247
|
+
title: w.editAgent,
|
|
4248
|
+
onClick: () => ui.set({ editing: !editing })
|
|
4249
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
4250
|
+
face: draft.face,
|
|
4251
|
+
size: 20
|
|
4252
|
+
}), /* @__PURE__ */ React.createElement("span", null, draft.name || w.newAgentName), /* @__PURE__ */ React.createElement(Down, {
|
|
4253
|
+
size: 14
|
|
4254
|
+
})), editing && /* @__PURE__ */ React.createElement(Identity, {
|
|
4255
|
+
context,
|
|
4256
|
+
onClose: () => ui.set({ editing: false })
|
|
4257
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
4258
|
+
type: "button",
|
|
4259
|
+
className: "tac-button tac-quiet",
|
|
4260
|
+
onClick: () => {
|
|
4261
|
+
ui.set({ draft: undefined, editing: false });
|
|
4262
|
+
pi.ui.showView("");
|
|
3905
4263
|
}
|
|
3906
|
-
|
|
3907
|
-
|
|
4264
|
+
}, w.cancel));
|
|
4265
|
+
}
|
|
4266
|
+
function NewAgentPage({ context }) {
|
|
4267
|
+
const { pi, service, ui } = context;
|
|
4268
|
+
const { draft } = useUi(ui);
|
|
4269
|
+
const { loaded } = useChannels(service);
|
|
4270
|
+
const w = ChannelViews.words(pi);
|
|
4271
|
+
const Pencil = ChannelViews.icon(pi, "Pencil");
|
|
4272
|
+
const Composer = pi.ui.Composer;
|
|
4273
|
+
const first = React.useRef(true);
|
|
4274
|
+
React.useEffect(() => {
|
|
4275
|
+
if (!loaded || !first.current) {
|
|
4276
|
+
return;
|
|
3908
4277
|
}
|
|
3909
|
-
|
|
4278
|
+
first.current = false;
|
|
4279
|
+
if (!ui.state.draft) {
|
|
4280
|
+
newAgent(context);
|
|
4281
|
+
}
|
|
4282
|
+
}, [loaded, ui, context]);
|
|
4283
|
+
if (!draft) {
|
|
4284
|
+
return null;
|
|
3910
4285
|
}
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
{
|
|
3920
|
-
|
|
3921
|
-
role: "user",
|
|
3922
|
-
text: `<context>
|
|
3923
|
-
The channel #ops, its members.
|
|
3924
|
-
[ta:from @celljs/ta-channels #ops]
|
|
3925
|
-
</context>
|
|
3926
|
-
Check the build`,
|
|
3927
|
-
said: "Check the build"
|
|
3928
|
-
},
|
|
3929
|
-
{
|
|
3930
|
-
mark: "a notice, not the user",
|
|
3931
|
-
role: "user",
|
|
3932
|
-
text: `<context>
|
|
3933
|
-
[ta:notice @celljs/ta-call]
|
|
3934
|
-
</context>
|
|
3935
|
-
The work finished. Its last words: tests pass.`,
|
|
3936
|
-
said: "The work finished. Its last words: tests pass."
|
|
3937
|
-
},
|
|
3938
|
-
{ mark: "one let in", role: "user", text: `<context>
|
|
3939
|
-
[ta:by p-7 Alice]
|
|
3940
|
-
</context>
|
|
3941
|
-
Hello there`, said: "Hello there" },
|
|
3942
|
-
{
|
|
3943
|
-
mark: "notes of images",
|
|
3944
|
-
role: "user",
|
|
3945
|
-
text: `Look at this
|
|
3946
|
-
[Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
|
|
3947
|
-
[Image converted from image/heic to image/png.]`,
|
|
3948
|
-
said: "Look at this"
|
|
3949
|
-
},
|
|
3950
|
-
{
|
|
3951
|
-
mark: "a skill run",
|
|
3952
|
-
role: "user",
|
|
3953
|
-
text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
|
|
3954
|
-
# Ta package
|
|
3955
|
-
Steps.
|
|
3956
|
-
</skill>
|
|
3957
|
-
|
|
3958
|
-
Make a card`,
|
|
3959
|
-
said: "Make a card"
|
|
3960
|
-
},
|
|
3961
|
-
{
|
|
3962
|
-
mark: "a note of a task",
|
|
3963
|
-
role: "user",
|
|
3964
|
-
text: `<task_update id="t1" title="Fix login" status="done">
|
|
3965
|
-
All tests pass.
|
|
3966
|
-
</task_update>`,
|
|
3967
|
-
said: "Fix login"
|
|
3968
|
-
},
|
|
3969
|
-
{ mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
|
|
3970
|
-
Now t2.
|
|
3971
|
-
</task_renamed>` },
|
|
3972
|
-
{ mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
|
|
3973
|
-
Switched to voice.`, said: "Switched to voice." },
|
|
3974
|
-
{ mark: "a summary alone", role: "assistant", text: SUMMARY },
|
|
3975
|
-
{ mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
|
|
3976
|
-
<summary>` },
|
|
3977
|
-
{
|
|
3978
|
-
mark: "a card after the answer",
|
|
3979
|
-
role: "assistant",
|
|
3980
|
-
text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
|
|
3981
|
-
said: "tests pass"
|
|
3982
|
-
},
|
|
3983
|
-
{ mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
|
|
3984
|
-
{ mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
|
|
3985
|
-
{ mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
|
|
3986
|
-
{ mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
|
|
3987
|
-
</system-reminder>
|
|
3988
|
-
Ready.`, said: "Ready." }
|
|
3989
|
-
];
|
|
3990
|
-
function userWords(text2) {
|
|
3991
|
-
const said = TaImageNote.strip(TaMessageContext.strip(text2));
|
|
3992
|
-
const skill = TaSkillUse.parse(said);
|
|
3993
|
-
if (skill) {
|
|
3994
|
-
return TaSkillUse.command(skill);
|
|
4286
|
+
const send = async (text) => {
|
|
4287
|
+
const agent = await service.createAgent({ name: draft.name, role: DEFAULT_ROLE, face: draft.face, cwd: draft.cwd });
|
|
4288
|
+
ui.set({ draft: undefined, editing: false });
|
|
4289
|
+
try {
|
|
4290
|
+
const sessionId = await service.openAgent(agent.id);
|
|
4291
|
+
context.sessions.set(agent.id, sessionId);
|
|
4292
|
+
await pi.switchSession(sessionId);
|
|
4293
|
+
await pi.sendUserMessage(text);
|
|
4294
|
+
} catch (error) {
|
|
4295
|
+
pi.ui.notify(ChannelViews.message(error), "error");
|
|
3995
4296
|
}
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
4297
|
+
};
|
|
4298
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4299
|
+
className: "tac-new-page"
|
|
4300
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4301
|
+
className: "tac-new-col"
|
|
4302
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
4303
|
+
face: draft.face,
|
|
4304
|
+
size: 88
|
|
4305
|
+
}), /* @__PURE__ */ React.createElement("h2", {
|
|
4306
|
+
className: "tac-new-name"
|
|
4307
|
+
}, /* @__PURE__ */ React.createElement("span", null, draft.name || w.newAgentName), /* @__PURE__ */ React.createElement("button", {
|
|
4308
|
+
type: "button",
|
|
4309
|
+
className: "tac-action tac-identity-open",
|
|
4310
|
+
title: w.editAgent,
|
|
4311
|
+
"aria-label": w.editAgent,
|
|
4312
|
+
onClick: () => ui.set({ editing: !ui.state.editing })
|
|
4313
|
+
}, /* @__PURE__ */ React.createElement(Pencil, {
|
|
4314
|
+
size: 14
|
|
4315
|
+
}))), /* @__PURE__ */ React.createElement("p", {
|
|
4316
|
+
className: "tac-new-hint"
|
|
4317
|
+
}, w.newAgentHint), /* @__PURE__ */ React.createElement("div", {
|
|
4318
|
+
className: "tac-new-box"
|
|
4319
|
+
}, /* @__PURE__ */ React.createElement(Composer, {
|
|
4320
|
+
placeholder: ChannelWords.format(w.agentPlaceholder, { name: draft.name || w.newAgentName }),
|
|
4321
|
+
onSend: send,
|
|
4322
|
+
cwd: draft.cwd,
|
|
4323
|
+
onPickCwd: (cwd) => ui.set({ draft: { ...draft, cwd } }),
|
|
4324
|
+
draft: "new-agent"
|
|
4325
|
+
}))));
|
|
4326
|
+
}
|
|
4327
|
+
function NewChannelDialog({ context, onClose }) {
|
|
4328
|
+
const { pi, service } = context;
|
|
4329
|
+
const { team } = useChannels(service);
|
|
4330
|
+
const faces = useFaces(team);
|
|
4331
|
+
const w = ChannelViews.words(pi);
|
|
4332
|
+
const Search = ChannelViews.icon(pi, "Search");
|
|
4333
|
+
const Check = ChannelViews.icon(pi, "Check");
|
|
4334
|
+
const [name, setName] = React.useState("");
|
|
4335
|
+
const [query, setQuery] = React.useState("");
|
|
4336
|
+
const [picked, setPicked] = React.useState([]);
|
|
4337
|
+
const friends = useFriends(pi);
|
|
4338
|
+
const [pickedFriends, setPickedFriends] = React.useState([]);
|
|
4339
|
+
const shared = pickedFriends.length > 0;
|
|
4340
|
+
const toggleFriend = (friend) => setPickedFriends(pickedFriends.includes(friend.id) ? pickedFriends.filter((id) => id !== friend.id) : [...pickedFriends, friend.id]);
|
|
4341
|
+
const [busy, setBusy] = React.useState(false);
|
|
4342
|
+
const [error, setError] = React.useState();
|
|
4343
|
+
const Dialog = pi.ui.Dialog;
|
|
4344
|
+
const shown = team.agents.filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
|
|
4345
|
+
const full = picked.length >= MAX_MEMBERS;
|
|
4346
|
+
const toggle = (agent) => setPicked(picked.includes(agent.id) ? picked.filter((id) => id !== agent.id) : full ? picked : [...picked, agent.id]);
|
|
4347
|
+
const create = (event) => {
|
|
4348
|
+
event.preventDefault();
|
|
4349
|
+
setBusy(true);
|
|
4350
|
+
setError(undefined);
|
|
4351
|
+
if (shared) {
|
|
4352
|
+
createShared(context, name.trim(), pickedFriends, picked).then(onClose, (failure) => {
|
|
4353
|
+
setBusy(false);
|
|
4354
|
+
setError(ChannelViews.message(failure));
|
|
4355
|
+
});
|
|
4356
|
+
return;
|
|
3999
4357
|
}
|
|
4000
|
-
|
|
4001
|
-
|
|
4358
|
+
service.createChannel({ name, members: picked }).then((channel) => {
|
|
4359
|
+
onClose();
|
|
4360
|
+
context.showChannel(channel.id);
|
|
4361
|
+
}, (failure) => {
|
|
4362
|
+
setBusy(false);
|
|
4363
|
+
setError(ChannelViews.message(failure));
|
|
4364
|
+
});
|
|
4365
|
+
};
|
|
4366
|
+
return /* @__PURE__ */ React.createElement(Dialog, {
|
|
4367
|
+
title: w.newChannel,
|
|
4368
|
+
onClose
|
|
4369
|
+
}, /* @__PURE__ */ React.createElement("form", {
|
|
4370
|
+
className: "tac-dialog",
|
|
4371
|
+
onSubmit: create
|
|
4372
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
4373
|
+
className: "tac-dialog-label"
|
|
4374
|
+
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
4375
|
+
className: "tac-input tac-dialog-input",
|
|
4376
|
+
value: name,
|
|
4377
|
+
placeholder: w.channelNamePlaceholder,
|
|
4378
|
+
maxLength: 40,
|
|
4379
|
+
autoFocus: true,
|
|
4380
|
+
onChange: (event) => setName(event.target.value)
|
|
4381
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
4382
|
+
className: "tac-dialog-label"
|
|
4383
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.addAgents), /* @__PURE__ */ React.createElement("span", {
|
|
4384
|
+
className: "tac-dialog-count"
|
|
4385
|
+
}, picked.length, "/", MAX_MEMBERS)), /* @__PURE__ */ React.createElement("label", {
|
|
4386
|
+
className: "tac-dialog-search"
|
|
4387
|
+
}, /* @__PURE__ */ React.createElement(Search, {
|
|
4388
|
+
size: 15
|
|
4389
|
+
}), /* @__PURE__ */ React.createElement("input", {
|
|
4390
|
+
value: query,
|
|
4391
|
+
placeholder: ChannelWords.format(w.searchAgents, { max: String(MAX_MEMBERS) }),
|
|
4392
|
+
"aria-label": w.search,
|
|
4393
|
+
onChange: (event) => setQuery(event.target.value)
|
|
4394
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
4395
|
+
className: "tac-pick-list"
|
|
4396
|
+
}, team.agents.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4397
|
+
compact: true,
|
|
4398
|
+
title: w.noAgents,
|
|
4399
|
+
hint: w.noAgentsHint
|
|
4400
|
+
}), team.agents.length > 0 && shown.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4401
|
+
compact: true,
|
|
4402
|
+
title: w.noMatch
|
|
4403
|
+
}), shown.map((agent) => {
|
|
4404
|
+
const on = picked.includes(agent.id);
|
|
4405
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
4406
|
+
key: agent.id,
|
|
4407
|
+
type: "button",
|
|
4408
|
+
"aria-pressed": on,
|
|
4409
|
+
disabled: !on && full,
|
|
4410
|
+
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
4411
|
+
onClick: () => toggle(agent)
|
|
4412
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4413
|
+
className: "tac-check"
|
|
4414
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
4415
|
+
size: 13,
|
|
4416
|
+
strokeWidth: 3
|
|
4417
|
+
})), /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
4418
|
+
agent,
|
|
4419
|
+
faces,
|
|
4420
|
+
size: 30
|
|
4421
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
4422
|
+
className: "tac-pick-text"
|
|
4423
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4424
|
+
className: "tac-pick-name"
|
|
4425
|
+
}, agent.name, picked[0] === agent.id && /* @__PURE__ */ React.createElement("span", {
|
|
4426
|
+
className: "tac-msg-lead"
|
|
4427
|
+
}, w.lead)), /* @__PURE__ */ React.createElement("span", {
|
|
4428
|
+
className: "tac-pick-role"
|
|
4429
|
+
}, agent.role.split(`
|
|
4430
|
+
`)[0])));
|
|
4431
|
+
})), friends.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
4432
|
+
className: "tac-dialog-label"
|
|
4433
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.addFriends), shared && /* @__PURE__ */ React.createElement("span", {
|
|
4434
|
+
className: "tac-dialog-count"
|
|
4435
|
+
}, pickedFriends.length)), /* @__PURE__ */ React.createElement("div", {
|
|
4436
|
+
className: "tac-pick-list"
|
|
4437
|
+
}, friends.map((friend) => {
|
|
4438
|
+
const on = pickedFriends.includes(friend.id);
|
|
4439
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
4440
|
+
key: friend.id,
|
|
4441
|
+
type: "button",
|
|
4442
|
+
"aria-pressed": on,
|
|
4443
|
+
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
4444
|
+
onClick: () => toggleFriend(friend)
|
|
4445
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4446
|
+
className: "tac-check"
|
|
4447
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
4448
|
+
size: 13,
|
|
4449
|
+
strokeWidth: 3
|
|
4450
|
+
})), pi.ui.Face ? /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
4451
|
+
seed: friend.id,
|
|
4452
|
+
size: 30,
|
|
4453
|
+
look: friend.look
|
|
4454
|
+
}) : /* @__PURE__ */ React.createElement("span", {
|
|
4455
|
+
className: "tac-pick-face"
|
|
4456
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
4457
|
+
className: "tac-pick-text"
|
|
4458
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4459
|
+
className: "tac-pick-name"
|
|
4460
|
+
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
4461
|
+
className: "tac-pick-role"
|
|
4462
|
+
}, w.friend)));
|
|
4463
|
+
}))), (picked.length > 0 || shared) && /* @__PURE__ */ React.createElement("div", {
|
|
4464
|
+
className: "tac-dialog-note"
|
|
4465
|
+
}, shared ? w.sharedHint : w.membersHint), error && /* @__PURE__ */ React.createElement("div", {
|
|
4466
|
+
className: "tac-empty tac-error"
|
|
4467
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4468
|
+
className: "tac-dialog-actions"
|
|
4469
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
4470
|
+
type: "submit",
|
|
4471
|
+
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4472
|
+
disabled: busy || !name.trim() || picked.length === 0 && !shared
|
|
4473
|
+
}, w.create, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4474
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4475
|
+
})))));
|
|
4476
|
+
}
|
|
4477
|
+
|
|
4478
|
+
// web-src/handoff.ts
|
|
4479
|
+
var HandOff;
|
|
4480
|
+
((HandOff) => {
|
|
4481
|
+
HandOff.TOOL = "hand_off";
|
|
4482
|
+
HandOff.CARD = "ta-channels-handoff";
|
|
4483
|
+
HandOff.BLOCK = "ta-handoff";
|
|
4484
|
+
const MARK = /\[ta-handoff:([^\]\s]+)\]/;
|
|
4485
|
+
HandOff.DEFINITION = {
|
|
4486
|
+
name: HandOff.TOOL,
|
|
4487
|
+
label: "Hand off",
|
|
4488
|
+
description: "Hands the work of this conversation over to one of the user's agents (@name) or channels (#name), when the user says so (hand it to, give it to, 交给, 转给). The other side does not see this conversation: write the brief it needs to go on, in the user's language: the goal, what is done and decided, what is left or blocks, the files, branches, commands and links that matter. It works on it in its own conversation, which the user follows; you stop working on it here. list_channels lists the team. After the call, say in one line to whom it went.",
|
|
4489
|
+
promptSnippet: "Hand the work over to one of the user's agents or channels",
|
|
4490
|
+
parameters: {
|
|
4491
|
+
type: "object",
|
|
4492
|
+
properties: {
|
|
4493
|
+
to: { type: "string", description: "@name of an agent or #name of a channel." },
|
|
4494
|
+
brief: { type: "string", description: "Complete in itself: the receiver sees only this." }
|
|
4495
|
+
},
|
|
4496
|
+
required: ["to", "brief"]
|
|
4002
4497
|
}
|
|
4003
|
-
|
|
4498
|
+
};
|
|
4499
|
+
function ref(target) {
|
|
4500
|
+
return `${target.kind === "agent" ? "@" : "#"}${target.name}`;
|
|
4004
4501
|
}
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
`
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
}
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
}
|
|
4020
|
-
}
|
|
4021
|
-
if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
|
|
4022
|
-
left = true;
|
|
4023
|
-
} else {
|
|
4024
|
-
kept.push(part);
|
|
4025
|
-
}
|
|
4026
|
-
}
|
|
4027
|
-
return left ? kept.join(`
|
|
4028
|
-
`).replace(/\n{3,}/g, `
|
|
4029
|
-
|
|
4030
|
-
`) : kept.join(`
|
|
4502
|
+
HandOff.ref = ref;
|
|
4503
|
+
function ask(language, to) {
|
|
4504
|
+
const fence = "```";
|
|
4505
|
+
const context = [
|
|
4506
|
+
`[ta-handoff:${to}]`,
|
|
4507
|
+
`The user hands the work of this conversation over to ${to}, which does not see this conversation.`,
|
|
4508
|
+
`- Write the brief it needs to go on: the goal, what is done and decided, what is left or blocks, the files, branches, commands and links that matter, in the user's language. Leave out what was only tried and dropped.`,
|
|
4509
|
+
`- With the tool ${HandOff.TOOL}, call it with to "${to}" and the brief, then say in one line that it went.`,
|
|
4510
|
+
`- Without it, say in one line what you hand over, then end your answer with the brief in a fenced block of the language ${HandOff.BLOCK}, which Ta reads to hand it over (a longer fence when the brief has one of its own):`,
|
|
4511
|
+
`${fence}${HandOff.BLOCK}`,
|
|
4512
|
+
"<the brief>",
|
|
4513
|
+
fence,
|
|
4514
|
+
`- When the conversation holds nothing to hand over yet, say so and ask what ${to} should do.`
|
|
4515
|
+
].join(`
|
|
4031
4516
|
`);
|
|
4517
|
+
const line = TaLanguageUtil.pick(language, {
|
|
4518
|
+
"zh-CN": `把这件事交给 ${to}`,
|
|
4519
|
+
"zh-TW": `把這件事交給 ${to}`,
|
|
4520
|
+
"en-US": `Hand this over to ${to}`,
|
|
4521
|
+
"ja-JP": `これを ${to} に引き継ぐ`
|
|
4522
|
+
});
|
|
4523
|
+
return TaMessageContext.wrap(context, line);
|
|
4032
4524
|
}
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4525
|
+
HandOff.ask = ask;
|
|
4526
|
+
function asked(text) {
|
|
4527
|
+
return MARK.exec(text)?.[1];
|
|
4528
|
+
}
|
|
4529
|
+
HandOff.asked = asked;
|
|
4530
|
+
function find(text) {
|
|
4531
|
+
const lines = text.split(/\r?\n/);
|
|
4532
|
+
let found;
|
|
4533
|
+
for (let index = 0;index < lines.length; index++) {
|
|
4534
|
+
const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
|
|
4535
|
+
if (open?.[2] !== HandOff.BLOCK) {
|
|
4536
|
+
continue;
|
|
4045
4537
|
}
|
|
4538
|
+
const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
|
|
4539
|
+
const end = lines.findIndex((line, at) => at > index && close.test(line));
|
|
4540
|
+
found = lines.slice(index + 1, end < 0 ? lines.length : end);
|
|
4541
|
+
index = end < 0 ? lines.length : end;
|
|
4046
4542
|
}
|
|
4047
|
-
|
|
4048
|
-
`);
|
|
4049
|
-
|
|
4050
|
-
function closes(part, mark) {
|
|
4051
|
-
var _a;
|
|
4052
|
-
const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
|
|
4053
|
-
return !!close && close[0] === mark[0] && close.length >= mark.length;
|
|
4543
|
+
const brief = found?.join(`
|
|
4544
|
+
`).trim();
|
|
4545
|
+
return brief || undefined;
|
|
4054
4546
|
}
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
const
|
|
4058
|
-
|
|
4547
|
+
HandOff.find = find;
|
|
4548
|
+
function message(origin, brief, language) {
|
|
4549
|
+
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
4550
|
+
const head = TaLanguageUtil.pick(language, {
|
|
4551
|
+
"zh-CN": `(交接自“${title}”)`,
|
|
4552
|
+
"zh-TW": `(交接自「${title}」)`,
|
|
4553
|
+
"en-US": `(Handed over from “${title}”)`,
|
|
4554
|
+
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
4555
|
+
});
|
|
4556
|
+
const context = [
|
|
4557
|
+
"The user handed you this work from another conversation of theirs, which you do not see; the brief below is all it says. Go on from there in this conversation, which the user follows; ask them when the brief leaves out something you need.",
|
|
4558
|
+
origin.sessionFile ? `That conversation is pi's session file ${origin.sessionFile}${origin.cwd ? `, working in ${origin.cwd}` : ""}: read it only when the brief is not enough.` : ""
|
|
4559
|
+
].filter(Boolean).join(`
|
|
4560
|
+
`);
|
|
4561
|
+
return TaMessageContext.wrap(context, `${head}
|
|
4562
|
+
|
|
4563
|
+
${brief.trim()}`);
|
|
4059
4564
|
}
|
|
4060
|
-
|
|
4565
|
+
HandOff.message = message;
|
|
4566
|
+
function channelText(origin, brief, language) {
|
|
4567
|
+
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
4568
|
+
return `${TaLanguageUtil.pick(language, {
|
|
4569
|
+
"zh-CN": `(交接自“${title}”)`,
|
|
4570
|
+
"zh-TW": `(交接自「${title}」)`,
|
|
4571
|
+
"en-US": `(Handed over from “${title}”)`,
|
|
4572
|
+
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
4573
|
+
})}
|
|
4061
4574
|
|
|
4062
|
-
|
|
4063
|
-
var ChannelsText;
|
|
4064
|
-
((ChannelsText) => {
|
|
4065
|
-
function markMentions(text, agents) {
|
|
4066
|
-
if (agents.length === 0) {
|
|
4067
|
-
return text;
|
|
4068
|
-
}
|
|
4069
|
-
const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
4070
|
-
const pattern = new RegExp(`(?<![*A-Za-z0-9_])@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
|
|
4071
|
-
return text.split(/(```[\s\S]*?(?:```|$)|`[^`\n]*`)/).map((part, index) => index % 2 === 1 ? part : part.replace(pattern, "**$&**")).join("");
|
|
4575
|
+
${brief.trim()}`;
|
|
4072
4576
|
}
|
|
4073
|
-
|
|
4074
|
-
function
|
|
4075
|
-
|
|
4076
|
-
return [];
|
|
4077
|
-
}
|
|
4078
|
-
const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
4079
|
-
const pattern = new RegExp(`@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
|
|
4080
|
-
const found = [];
|
|
4081
|
-
for (const match of text.matchAll(pattern)) {
|
|
4082
|
-
const agent = agents.find((candidate) => candidate.name.toLowerCase() === match[1].toLowerCase());
|
|
4083
|
-
if (agent && !found.includes(agent.id)) {
|
|
4084
|
-
found.push(agent.id);
|
|
4085
|
-
}
|
|
4086
|
-
}
|
|
4087
|
-
return found;
|
|
4577
|
+
HandOff.channelText = channelText;
|
|
4578
|
+
function serverLanguage(env = typeof process === "undefined" ? {} : process.env) {
|
|
4579
|
+
return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
|
|
4088
4580
|
}
|
|
4089
|
-
|
|
4090
|
-
function
|
|
4091
|
-
|
|
4092
|
-
const members = channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
|
|
4093
|
-
const named = mentions(message.text, members).filter((id) => id !== message.author);
|
|
4094
|
-
if (message.author === SYSTEM) {
|
|
4095
|
-
return [];
|
|
4096
|
-
}
|
|
4097
|
-
if (named.length > 0 || message.author !== USER && message.author !== TA) {
|
|
4098
|
-
return named;
|
|
4099
|
-
}
|
|
4100
|
-
return members.length > 0 ? [members[0].id] : [];
|
|
4581
|
+
HandOff.serverLanguage = serverLanguage;
|
|
4582
|
+
function result(target) {
|
|
4583
|
+
return `Handed over to ${ref(target)}; it works on it in its own conversation, which the user follows. Do not go on with it here.`;
|
|
4101
4584
|
}
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
return
|
|
4585
|
+
HandOff.result = result;
|
|
4586
|
+
})(HandOff ||= {});
|
|
4587
|
+
|
|
4588
|
+
// web-src/handoff-view.tsx
|
|
4589
|
+
var HandOffViewUtil;
|
|
4590
|
+
((HandOffViewUtil) => {
|
|
4591
|
+
function members(team, target) {
|
|
4592
|
+
if (target.kind === "agent") {
|
|
4593
|
+
const agent = team.agents.find((candidate) => candidate.id === target.id);
|
|
4594
|
+
return agent ? [agent] : [];
|
|
4112
4595
|
}
|
|
4113
|
-
|
|
4596
|
+
const channel = team.channels.find((candidate) => candidate.id === target.id);
|
|
4597
|
+
return channel ? membersOf(team, channel) : [];
|
|
4114
4598
|
}
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4599
|
+
HandOffViewUtil.members = members;
|
|
4600
|
+
})(HandOffViewUtil ||= {});
|
|
4601
|
+
function useTeam(context) {
|
|
4602
|
+
return React.useSyncExternalStore((listener) => context.service.subscribe(listener), () => context.service.state).team;
|
|
4603
|
+
}
|
|
4604
|
+
function HandOffCard({ context, message }) {
|
|
4605
|
+
const card = message.details;
|
|
4606
|
+
const team = useTeam(context);
|
|
4607
|
+
const faces = useFaces(team);
|
|
4608
|
+
if (!card?.target) {
|
|
4609
|
+
return null;
|
|
4126
4610
|
}
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4611
|
+
const w = ChannelViews.words(context.pi);
|
|
4612
|
+
const members = HandOffViewUtil.members(team, card.target);
|
|
4613
|
+
const open = () => card.target.kind === "agent" ? void ChannelViews.openAgent(context, card.target.id).catch((error) => context.pi.ui.notify(ChannelViews.message(error), "error")) : context.showChannel(card.target.id);
|
|
4614
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4615
|
+
className: "tac-handoff"
|
|
4616
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4617
|
+
className: "tac-handoff-head"
|
|
4618
|
+
}, members.length > 0 && /* @__PURE__ */ React.createElement(RoomFace, {
|
|
4619
|
+
members,
|
|
4620
|
+
faces,
|
|
4621
|
+
size: 20,
|
|
4622
|
+
working: []
|
|
4623
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
4624
|
+
className: "tac-handoff-title"
|
|
4625
|
+
}, w.handedTo.replace("{to}", HandOff.ref(card.target))), members.length > 0 && /* @__PURE__ */ React.createElement("button", {
|
|
4626
|
+
type: "button",
|
|
4627
|
+
className: "tac-link",
|
|
4628
|
+
onClick: open
|
|
4629
|
+
}, w.handOffOpen)), /* @__PURE__ */ React.createElement("div", {
|
|
4630
|
+
className: "tac-handoff-brief"
|
|
4631
|
+
}, card.brief));
|
|
4632
|
+
}
|
|
4633
|
+
var HandOffView;
|
|
4634
|
+
((HandOffView) => {
|
|
4635
|
+
function card(context) {
|
|
4636
|
+
return ({ message }) => /* @__PURE__ */ React.createElement(HandOffCard, {
|
|
4637
|
+
context,
|
|
4638
|
+
message
|
|
4639
|
+
});
|
|
4147
4640
|
}
|
|
4148
|
-
|
|
4149
|
-
function
|
|
4150
|
-
|
|
4151
|
-
|
|
4641
|
+
HandOffView.card = card;
|
|
4642
|
+
function icon(context, target, icons) {
|
|
4643
|
+
const key = `${target.kind}:${target.id}`;
|
|
4644
|
+
let node2 = icons.get(key);
|
|
4645
|
+
if (!node2) {
|
|
4646
|
+
const Face2 = () => {
|
|
4647
|
+
const team = useTeam(context);
|
|
4648
|
+
const faces = useFaces(team);
|
|
4649
|
+
const members = HandOffViewUtil.members(team, target);
|
|
4650
|
+
return members.length ? /* @__PURE__ */ React.createElement(RoomFace, {
|
|
4651
|
+
members,
|
|
4652
|
+
faces,
|
|
4653
|
+
size: 16,
|
|
4654
|
+
working: []
|
|
4655
|
+
}) : null;
|
|
4656
|
+
};
|
|
4657
|
+
node2 = /* @__PURE__ */ React.createElement(Face2, null);
|
|
4658
|
+
icons.set(key, node2);
|
|
4152
4659
|
}
|
|
4153
|
-
|
|
4154
|
-
const agents = team.agents.map((agent) => `- @${agent.name}: ${firstLine(agent.role)}`);
|
|
4155
|
-
const channels = team.channels.map((channel) => `- #${channel.name}${channel.topic ? ` (${channel.topic})` : ""}: ${channel.members.map((id) => `@${name(id)}`).join(", ")}${channel.muted?.length ? `; muted by the user, answering nothing: ${channel.muted.map((id) => `@${name(id)}`).join(", ")}` : ""}${channel.notice ? `
|
|
4156
|
-
notice: ${channel.notice.text.replace(/\s+/g, " ").slice(0, 300)}` : ""}`);
|
|
4157
|
-
return ["Agents:", ...agents, "", "Channels:", ...channels.length > 0 ? channels : ["none yet"]].join(`
|
|
4158
|
-
`);
|
|
4159
|
-
}
|
|
4160
|
-
ChannelsText.summary = summary;
|
|
4161
|
-
function transcript(team, messages) {
|
|
4162
|
-
const labels = { user: "user", ta: "Ta" };
|
|
4163
|
-
return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${item.text}`).join(`
|
|
4164
|
-
|
|
4165
|
-
`);
|
|
4660
|
+
return node2;
|
|
4166
4661
|
}
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
const
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4662
|
+
function composerAddon(context) {
|
|
4663
|
+
const icons = new Map;
|
|
4664
|
+
const send = (conversation, to) => void context.pi.server.prompt(conversation.sessionId, {
|
|
4665
|
+
clientMessageId: ChannelsUtil.newId("handoff-ask"),
|
|
4666
|
+
message: HandOff.ask(context.pi.ui.language, to),
|
|
4667
|
+
streamingBehavior: "followUp"
|
|
4668
|
+
}).catch((error) => context.pi.ui.notify(ChannelViews.message(error), "error"));
|
|
4669
|
+
return {
|
|
4670
|
+
actions: (conversation) => {
|
|
4671
|
+
const { team } = context.service.state;
|
|
4672
|
+
if (conversation.group === NAME || team.agents.length === 0 && team.channels.length === 0) {
|
|
4673
|
+
return [];
|
|
4674
|
+
}
|
|
4675
|
+
const w = ChannelViews.words(context.pi);
|
|
4676
|
+
const Forward = ChannelViews.icon(context.pi, "Forward");
|
|
4677
|
+
const agents = team.agents.filter((agent) => !agent.temporary).map((agent) => ({
|
|
4678
|
+
key: `handoff:agent:${agent.id}`,
|
|
4679
|
+
label: agent.name,
|
|
4680
|
+
detail: agent.role.split(`
|
|
4681
|
+
`)[0],
|
|
4682
|
+
group: w.agents,
|
|
4683
|
+
icon: icon(context, { kind: "agent", id: agent.id }, icons),
|
|
4684
|
+
run: () => send(conversation, `@${agent.name}`)
|
|
4685
|
+
}));
|
|
4686
|
+
const channels = team.channels.map((channel) => ({
|
|
4687
|
+
key: `handoff:channel:${channel.id}`,
|
|
4688
|
+
label: `#${channel.name}`,
|
|
4689
|
+
detail: channel.topic,
|
|
4690
|
+
group: w.channels,
|
|
4691
|
+
icon: icon(context, { kind: "channel", id: channel.id }, icons),
|
|
4692
|
+
run: () => send(conversation, `#${channel.name}`)
|
|
4693
|
+
}));
|
|
4694
|
+
return [{ key: "handoff", label: w.handOff, detail: w.handOffDetail, icon: /* @__PURE__ */ React.createElement(Forward, {
|
|
4695
|
+
size: 16
|
|
4696
|
+
}), items: [...agents, ...channels] }];
|
|
4697
|
+
},
|
|
4698
|
+
subscribe: (listener) => context.service.subscribe(listener)
|
|
4699
|
+
};
|
|
4183
4700
|
}
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4701
|
+
HandOffView.composerAddon = composerAddon;
|
|
4702
|
+
})(HandOffView ||= {});
|
|
4703
|
+
|
|
4704
|
+
// web-src/round-rules.ts
|
|
4705
|
+
var ChannelRounds;
|
|
4706
|
+
((ChannelRounds) => {
|
|
4707
|
+
const SHORT = 20;
|
|
4708
|
+
const MIN_PAIRS = 8;
|
|
4709
|
+
const ALIKE = 0.8;
|
|
4710
|
+
const PING_PONG = 4;
|
|
4711
|
+
const NEW = 0.35;
|
|
4712
|
+
const CHANGES = new Set(["edit", "write", "delete", "move"]);
|
|
4713
|
+
function scale(watchedAt, pages, now) {
|
|
4714
|
+
if (watchedAt !== undefined && now - watchedAt < 2 * WATCH_MS) {
|
|
4715
|
+
return 2;
|
|
4195
4716
|
}
|
|
4196
|
-
return
|
|
4197
|
-
`)}
|
|
4198
|
-
`;
|
|
4199
|
-
}
|
|
4200
|
-
ChannelsText.channelMarkdown = channelMarkdown;
|
|
4201
|
-
function firstLine(text) {
|
|
4202
|
-
return text.split(`
|
|
4203
|
-
`)[0];
|
|
4717
|
+
return pages === undefined || pages > 0 ? 1 : 0.5;
|
|
4204
4718
|
}
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
`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.`
|
|
4210
|
-
].join(`
|
|
4211
|
-
`);
|
|
4212
|
-
|
|
4213
|
-
// web-src/more-menu.tsx
|
|
4214
|
-
var MARGIN = 8;
|
|
4215
|
-
function MoreMenu({ pi, label, items }) {
|
|
4216
|
-
const w = ChannelViews.words(pi);
|
|
4217
|
-
const [open, setOpen] = React.useState(false);
|
|
4218
|
-
const anchor = React.useRef({
|
|
4219
|
-
right: 0,
|
|
4220
|
-
below: 0,
|
|
4221
|
-
above: 0,
|
|
4222
|
-
finger: undefined
|
|
4223
|
-
});
|
|
4224
|
-
const root = React.useRef(null);
|
|
4225
|
-
const menu = React.useRef(null);
|
|
4226
|
-
const Ellipsis = ChannelViews.icon(pi, "Ellipsis");
|
|
4227
|
-
const show = React.useCallback((button, at) => {
|
|
4228
|
-
const box = button.getBoundingClientRect();
|
|
4229
|
-
const touch = document.documentElement.hasAttribute("data-touch");
|
|
4230
|
-
const row = root.current?.parentElement?.getBoundingClientRect() ?? box;
|
|
4231
|
-
anchor.current = {
|
|
4232
|
-
right: box.right,
|
|
4233
|
-
below: at?.y ?? box.bottom,
|
|
4234
|
-
above: at?.y ?? box.top,
|
|
4235
|
-
finger: touch && at ? { ...at, around: { top: row.top, bottom: row.bottom } } : undefined
|
|
4236
|
-
};
|
|
4237
|
-
setOpen(true);
|
|
4238
|
-
}, []);
|
|
4239
|
-
React.useLayoutEffect(() => {
|
|
4240
|
-
const element = menu.current;
|
|
4241
|
-
if (!open || !element) {
|
|
4719
|
+
ChannelRounds.scale = scale;
|
|
4720
|
+
function idle(said, progress) {
|
|
4721
|
+
const last = said.at(-1);
|
|
4722
|
+
if (!last) {
|
|
4242
4723
|
return;
|
|
4243
4724
|
}
|
|
4244
|
-
const
|
|
4245
|
-
|
|
4246
|
-
|
|
4725
|
+
const pairs = said.map((item) => pairsOf(item.text));
|
|
4726
|
+
const mine = pairs[pairs.length - 1];
|
|
4727
|
+
if (mine.length >= MIN_PAIRS && pairs.slice(0, -1).some((other) => alike(other, mine) >= ALIKE)) {
|
|
4728
|
+
return "repeat";
|
|
4247
4729
|
}
|
|
4248
|
-
const
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
element.style.top = `${top}px`;
|
|
4252
|
-
element.style.left = `${Math.max(MARGIN, right - width)}px`;
|
|
4253
|
-
}, [open, pi]);
|
|
4254
|
-
React.useEffect(() => {
|
|
4255
|
-
const row = root.current?.parentElement;
|
|
4256
|
-
const button = root.current?.querySelector(".tac-action");
|
|
4257
|
-
if (!row || !button) {
|
|
4258
|
-
return;
|
|
4730
|
+
const recent = said.slice(-3);
|
|
4731
|
+
if (recent.length === 3 && recent.every((item) => units(item.text).join("").length < SHORT)) {
|
|
4732
|
+
return "agree";
|
|
4259
4733
|
}
|
|
4260
|
-
const
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
return () => row.removeEventListener("contextmenu", onContextMenu);
|
|
4266
|
-
}, [show]);
|
|
4267
|
-
React.useEffect(() => {
|
|
4268
|
-
if (!open) {
|
|
4734
|
+
const run = said.slice(-PING_PONG);
|
|
4735
|
+
const authors = new Set(run.map((item) => item.author));
|
|
4736
|
+
const alternate = run.every((item, i) => i === 0 || item.author !== run[i - 1].author);
|
|
4737
|
+
const start = said.length - PING_PONG;
|
|
4738
|
+
if (progress || start <= 0 || authors.size !== 2 || !alternate) {
|
|
4269
4739
|
return;
|
|
4270
4740
|
}
|
|
4271
|
-
const
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
const onKey = (event) => {
|
|
4277
|
-
if (event.key === "Escape") {
|
|
4278
|
-
setOpen(false);
|
|
4741
|
+
const seen = new Set(pairs.slice(0, start).flat());
|
|
4742
|
+
for (const own of pairs.slice(start)) {
|
|
4743
|
+
const fresh = own.filter((pair) => !seen.has(pair)).length;
|
|
4744
|
+
if (own.length === 0 || fresh / own.length >= NEW) {
|
|
4745
|
+
return;
|
|
4279
4746
|
}
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
document.addEventListener("keydown", onKey);
|
|
4283
|
-
return () => {
|
|
4284
|
-
document.removeEventListener("pointerdown", close);
|
|
4285
|
-
document.removeEventListener("keydown", onKey);
|
|
4286
|
-
};
|
|
4287
|
-
}, [open]);
|
|
4288
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
4289
|
-
className: "tac-item-more",
|
|
4290
|
-
ref: root
|
|
4291
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
4292
|
-
type: "button",
|
|
4293
|
-
className: `tac-action${open ? " tac-on" : ""}`,
|
|
4294
|
-
title: w.more,
|
|
4295
|
-
"aria-label": w.more,
|
|
4296
|
-
"aria-haspopup": "menu",
|
|
4297
|
-
"aria-expanded": open,
|
|
4298
|
-
onClick: (event) => {
|
|
4299
|
-
event.stopPropagation();
|
|
4300
|
-
if (open) {
|
|
4301
|
-
setOpen(false);
|
|
4302
|
-
} else {
|
|
4303
|
-
show(event.currentTarget);
|
|
4747
|
+
for (const pair of own) {
|
|
4748
|
+
seen.add(pair);
|
|
4304
4749
|
}
|
|
4305
4750
|
}
|
|
4306
|
-
|
|
4307
|
-
size: 15
|
|
4308
|
-
})), open && /* @__PURE__ */ React.createElement("div", {
|
|
4309
|
-
ref: menu,
|
|
4310
|
-
className: "tac-menu tac-agent-menu",
|
|
4311
|
-
role: "menu",
|
|
4312
|
-
"aria-label": label
|
|
4313
|
-
}, items().filter((section) => section.length > 0).map((section, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
4314
|
-
key: section[0]?.key ?? index
|
|
4315
|
-
}, index > 0 && /* @__PURE__ */ React.createElement("hr", {
|
|
4316
|
-
className: "tac-menu-line"
|
|
4317
|
-
}), section.map((item) => /* @__PURE__ */ React.createElement("button", {
|
|
4318
|
-
key: item.key,
|
|
4319
|
-
type: "button",
|
|
4320
|
-
role: "menuitem",
|
|
4321
|
-
className: item.danger ? "tac-danger" : undefined,
|
|
4322
|
-
disabled: item.disabled,
|
|
4323
|
-
onClick: () => {
|
|
4324
|
-
setOpen(false);
|
|
4325
|
-
item.run();
|
|
4326
|
-
}
|
|
4327
|
-
}, item.icon, /* @__PURE__ */ React.createElement("span", {
|
|
4328
|
-
className: "tac-menu-label"
|
|
4329
|
-
}, item.label)))))));
|
|
4330
|
-
}
|
|
4331
|
-
|
|
4332
|
-
// web-src/agent-menu.tsx
|
|
4333
|
-
async function copy(text) {
|
|
4334
|
-
try {
|
|
4335
|
-
await navigator.clipboard.writeText(text);
|
|
4336
|
-
return true;
|
|
4337
|
-
} catch {
|
|
4338
|
-
return false;
|
|
4751
|
+
return "pingPong";
|
|
4339
4752
|
}
|
|
4340
|
-
|
|
4341
|
-
function
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
link.href = url;
|
|
4345
|
-
link.download = name;
|
|
4346
|
-
link.click();
|
|
4347
|
-
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
4348
|
-
}
|
|
4349
|
-
async function deleteAgent(context, agent) {
|
|
4350
|
-
const w = ChannelViews.words(context.pi);
|
|
4351
|
-
const sure = await context.pi.ui.confirm(ChannelWords.format(w.confirmDeleteAgent, { name: agent.name }), undefined, {
|
|
4352
|
-
confirmLabel: w.delete,
|
|
4353
|
-
danger: true
|
|
4354
|
-
});
|
|
4355
|
-
if (sure) {
|
|
4356
|
-
await context.service.deleteAgent(agent.id);
|
|
4357
|
-
context.sessions.delete(agent.id);
|
|
4753
|
+
ChannelRounds.idle = idle;
|
|
4754
|
+
function day(now) {
|
|
4755
|
+
const date = new Date(now);
|
|
4756
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
4358
4757
|
}
|
|
4359
|
-
|
|
4360
|
-
function
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4758
|
+
ChannelRounds.day = day;
|
|
4759
|
+
function limits(stored) {
|
|
4760
|
+
const given = stored ?? {};
|
|
4761
|
+
const pick = (key) => LIMIT_CHOICES[key].includes(given[key]) ? given[key] : DEFAULT_LIMITS[key];
|
|
4762
|
+
return { answer: pick("answer"), channelDay: pick("channelDay"), allDay: pick("allDay") };
|
|
4763
|
+
}
|
|
4764
|
+
ChannelRounds.limits = limits;
|
|
4765
|
+
function today(stored, now) {
|
|
4766
|
+
const current = day(now);
|
|
4767
|
+
return stored?.day === current ? stored : { day: current, total: 0, channels: {} };
|
|
4768
|
+
}
|
|
4769
|
+
ChannelRounds.today = today;
|
|
4770
|
+
function spend(stored, channelId, tokens, now) {
|
|
4771
|
+
const current = today(stored, now);
|
|
4772
|
+
return { ...current, total: current.total + tokens, channels: { ...current.channels, [channelId]: (current.channels[channelId] ?? 0) + tokens } };
|
|
4773
|
+
}
|
|
4774
|
+
ChannelRounds.spend = spend;
|
|
4775
|
+
function held(spent, limits2, channelId, hops, granted = false) {
|
|
4776
|
+
if (granted) {
|
|
4371
4777
|
return;
|
|
4372
4778
|
}
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4779
|
+
if (limits2.allDay > 0 && spent.total >= limits2.allDay) {
|
|
4780
|
+
return "all";
|
|
4781
|
+
}
|
|
4782
|
+
if (hops > 0 && limits2.channelDay > 0 && (spent.channels[channelId] ?? 0) >= limits2.channelDay) {
|
|
4783
|
+
return "channel";
|
|
4784
|
+
}
|
|
4785
|
+
return;
|
|
4786
|
+
}
|
|
4787
|
+
ChannelRounds.held = held;
|
|
4788
|
+
function changedFiles(entries) {
|
|
4789
|
+
for (const entry of entries) {
|
|
4790
|
+
const message = entry?.message;
|
|
4791
|
+
if (entry?.type !== "message" || message?.role !== "assistant" || !Array.isArray(message.content)) {
|
|
4792
|
+
continue;
|
|
4793
|
+
}
|
|
4794
|
+
for (const part of message.content) {
|
|
4795
|
+
if (part?.type !== "toolCall") {
|
|
4796
|
+
continue;
|
|
4797
|
+
}
|
|
4798
|
+
if (CHANGES.has(String(part.name)) || part.name === "agent_tool" && CHANGES.has(String(part.arguments?.kind))) {
|
|
4799
|
+
return true;
|
|
4800
|
+
}
|
|
4801
|
+
}
|
|
4379
4802
|
}
|
|
4380
|
-
|
|
4381
|
-
}
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4803
|
+
return false;
|
|
4804
|
+
}
|
|
4805
|
+
ChannelRounds.changedFiles = changedFiles;
|
|
4806
|
+
function units(text) {
|
|
4807
|
+
return text.replace(/@[^\s@#,,。::]+/g, " ").toLowerCase().match(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]|[\p{L}\p{N}]+/gu) ?? [];
|
|
4808
|
+
}
|
|
4809
|
+
function pairsOf(text) {
|
|
4810
|
+
const words = units(text);
|
|
4811
|
+
return words.length === 1 ? words : words.slice(1).map((word, i) => `${words[i]} ${word}`);
|
|
4812
|
+
}
|
|
4813
|
+
function alike(a, b) {
|
|
4814
|
+
if (a.length === 0 || b.length === 0) {
|
|
4815
|
+
return 0;
|
|
4390
4816
|
}
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
const sessionId = session?.sessionId ?? (agent.sessionFile ? await service.openAgent(agent.id) : undefined);
|
|
4395
|
-
const { messages } = sessionId ? await pi.server.getMessages(sessionId) : { messages: [] };
|
|
4396
|
-
if (!messages.some((message) => message.role === "assistant")) {
|
|
4397
|
-
pi.ui.notify(ChannelWords.format(w.nothingToExport, { name: agent.name }), "info");
|
|
4398
|
-
return;
|
|
4817
|
+
const left = new Map;
|
|
4818
|
+
for (const pair of a) {
|
|
4819
|
+
left.set(pair, (left.get(pair) ?? 0) + 1);
|
|
4399
4820
|
}
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
pi.ui.notify(ChannelWords.format(w.kept, { name: agent.name }), "info");
|
|
4407
|
-
});
|
|
4408
|
-
const show = (next) => () => setDialog(next);
|
|
4409
|
-
const item = (key, label, glyph, run, options = {}) => ({
|
|
4410
|
-
key,
|
|
4411
|
-
label,
|
|
4412
|
-
icon: icon(glyph),
|
|
4413
|
-
run,
|
|
4414
|
-
...options
|
|
4415
|
-
});
|
|
4416
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(MoreMenu, {
|
|
4417
|
-
pi,
|
|
4418
|
-
label: agent.name,
|
|
4419
|
-
items: () => [
|
|
4420
|
-
[
|
|
4421
|
-
...agent.temporary ? [item("keep", w.keep, "UserPlus", keep)] : [],
|
|
4422
|
-
item("pin", agent.pinned ? w.unpin : w.pin, agent.pinned ? "PinOff" : "Pin", pin)
|
|
4423
|
-
],
|
|
4424
|
-
[item("stop", w.stop, "Square", stop, { disabled: !working && !agent.sessionFile }), item("restart", w.restart, "RotateCcw", restart)],
|
|
4425
|
-
[
|
|
4426
|
-
item("settings", w.agentSettings, "SlidersHorizontal", show("settings")),
|
|
4427
|
-
item("rename", w.rename, "Pencil", show("rename")),
|
|
4428
|
-
item("role", w.editRole, "ScrollText", show("role")),
|
|
4429
|
-
item("move", w.moveTo, "FolderInput", show("move")),
|
|
4430
|
-
item("copy", w.copyCwd, "Copy", copyCwd)
|
|
4431
|
-
],
|
|
4432
|
-
[
|
|
4433
|
-
item("card", w.shareCard, "Contact", show("card")),
|
|
4434
|
-
item("export", w.exportChat, "Download", exportMarkdown),
|
|
4435
|
-
item("join", w.joinChannel, "UserPlus", show("join"))
|
|
4436
|
-
],
|
|
4437
|
-
[item("delete", w.deleteAgent, "Trash2", remove, { danger: true })]
|
|
4438
|
-
]
|
|
4439
|
-
}), dialog === "settings" && /* @__PURE__ */ React.createElement(AgentSettingsDialog, {
|
|
4440
|
-
context,
|
|
4441
|
-
agent,
|
|
4442
|
-
onClose: () => setDialog(undefined)
|
|
4443
|
-
}), dialog === "rename" && /* @__PURE__ */ React.createElement(RenameDialog, {
|
|
4444
|
-
context,
|
|
4445
|
-
agent,
|
|
4446
|
-
onClose: () => setDialog(undefined)
|
|
4447
|
-
}), dialog === "role" && /* @__PURE__ */ React.createElement(RoleDialog, {
|
|
4448
|
-
context,
|
|
4449
|
-
agent,
|
|
4450
|
-
onClose: () => setDialog(undefined)
|
|
4451
|
-
}), dialog === "join" && /* @__PURE__ */ React.createElement(JoinDialog, {
|
|
4452
|
-
context,
|
|
4453
|
-
agent,
|
|
4454
|
-
onClose: () => setDialog(undefined)
|
|
4455
|
-
}), dialog === "card" && /* @__PURE__ */ React.createElement(CardDialog, {
|
|
4456
|
-
context,
|
|
4457
|
-
agent,
|
|
4458
|
-
onClose: () => setDialog(undefined)
|
|
4459
|
-
}), dialog === "move" && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
|
|
4460
|
-
initial: cwd,
|
|
4461
|
-
onClose: () => setDialog(undefined),
|
|
4462
|
-
onPick: async (path) => {
|
|
4463
|
-
setDialog(undefined);
|
|
4464
|
-
if (path !== cwd) {
|
|
4465
|
-
await service.updateAgent(agent.id, { cwd: path }).catch(fail);
|
|
4466
|
-
context.sessions.delete(agent.id);
|
|
4821
|
+
let common = 0;
|
|
4822
|
+
for (const pair of b) {
|
|
4823
|
+
const n = left.get(pair) ?? 0;
|
|
4824
|
+
if (n > 0) {
|
|
4825
|
+
left.set(pair, n - 1);
|
|
4826
|
+
common++;
|
|
4467
4827
|
}
|
|
4468
4828
|
}
|
|
4469
|
-
|
|
4470
|
-
}
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
setBusy(true);
|
|
4477
|
-
setError(undefined);
|
|
4478
|
-
action().then(onClose, (failure) => {
|
|
4479
|
-
setBusy(false);
|
|
4480
|
-
setError(ChannelViews.message(failure));
|
|
4481
|
-
});
|
|
4482
|
-
};
|
|
4483
|
-
return { busy, error, submit };
|
|
4484
|
-
}
|
|
4485
|
-
function AgentSettingsDialog({ context, agent, onClose }) {
|
|
4486
|
-
const { pi, service } = context;
|
|
4487
|
-
const w = ChannelViews.words(pi);
|
|
4488
|
-
const [name, setName] = React.useState(agent.name);
|
|
4489
|
-
const [model, setModel] = React.useState(agent.model ?? "");
|
|
4490
|
-
const [role, setRole] = React.useState(agent.role);
|
|
4491
|
-
const change = {
|
|
4492
|
-
...name.trim() !== agent.name ? { name } : {},
|
|
4493
|
-
...model !== (agent.model ?? "") ? { model } : {},
|
|
4494
|
-
...role.trim() !== agent.role ? { role } : {}
|
|
4495
|
-
};
|
|
4496
|
-
const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, change), onClose);
|
|
4497
|
-
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
4498
|
-
title: `${w.agentSettings} · ${agent.name}`,
|
|
4499
|
-
onClose
|
|
4500
|
-
}, /* @__PURE__ */ React.createElement("form", {
|
|
4501
|
-
className: "tac-dialog",
|
|
4502
|
-
onSubmit: submit
|
|
4503
|
-
}, /* @__PURE__ */ React.createElement("label", {
|
|
4504
|
-
className: "tac-dialog-label"
|
|
4505
|
-
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
4506
|
-
className: "tac-input tac-dialog-input",
|
|
4507
|
-
value: name,
|
|
4508
|
-
maxLength: 32,
|
|
4509
|
-
onChange: (event) => setName(event.target.value)
|
|
4510
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
4511
|
-
className: "tac-dialog-field"
|
|
4512
|
-
}, /* @__PURE__ */ React.createElement("span", null, w.model), /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
|
|
4513
|
-
cwd: agent.cwd,
|
|
4514
|
-
value: model,
|
|
4515
|
-
label: w.model,
|
|
4516
|
-
onChange: setModel
|
|
4517
|
-
})), /* @__PURE__ */ React.createElement("label", {
|
|
4518
|
-
className: "tac-dialog-label"
|
|
4519
|
-
}, w.editRole, /* @__PURE__ */ React.createElement("textarea", {
|
|
4520
|
-
className: "tac-input tac-settings-role",
|
|
4521
|
-
value: role,
|
|
4522
|
-
placeholder: w.rolePlaceholder,
|
|
4523
|
-
onChange: (event) => setRole(event.target.value)
|
|
4524
|
-
})), /* @__PURE__ */ React.createElement("p", {
|
|
4525
|
-
className: "tac-dialog-note"
|
|
4526
|
-
}, w.agentSettingsHint), error && /* @__PURE__ */ React.createElement("div", {
|
|
4527
|
-
className: "tac-error"
|
|
4528
|
-
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4529
|
-
className: "tac-dialog-actions"
|
|
4530
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
4531
|
-
type: "submit",
|
|
4532
|
-
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4533
|
-
disabled: busy || !name.trim() || !role.trim() || Object.keys(change).length === 0
|
|
4534
|
-
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4535
|
-
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4536
|
-
})))));
|
|
4537
|
-
}
|
|
4538
|
-
function RenameDialog({ context, agent, onClose }) {
|
|
4539
|
-
const { pi, service } = context;
|
|
4540
|
-
const w = ChannelViews.words(pi);
|
|
4541
|
-
const [name, setName] = React.useState(agent.name);
|
|
4542
|
-
const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, { name }), onClose);
|
|
4543
|
-
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
4544
|
-
title: w.rename,
|
|
4545
|
-
onClose
|
|
4546
|
-
}, /* @__PURE__ */ React.createElement("form", {
|
|
4547
|
-
className: "tac-dialog",
|
|
4548
|
-
onSubmit: submit
|
|
4549
|
-
}, /* @__PURE__ */ React.createElement("label", {
|
|
4550
|
-
className: "tac-dialog-label"
|
|
4551
|
-
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
4552
|
-
className: "tac-input tac-dialog-input",
|
|
4553
|
-
value: name,
|
|
4554
|
-
maxLength: 32,
|
|
4555
|
-
autoFocus: true,
|
|
4556
|
-
onChange: (event) => setName(event.target.value)
|
|
4557
|
-
})), error && /* @__PURE__ */ React.createElement("div", {
|
|
4558
|
-
className: "tac-error"
|
|
4559
|
-
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4560
|
-
className: "tac-dialog-actions"
|
|
4561
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
4562
|
-
type: "submit",
|
|
4563
|
-
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4564
|
-
disabled: busy || !name.trim() || name.trim() === agent.name
|
|
4565
|
-
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4566
|
-
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4567
|
-
})))));
|
|
4829
|
+
return 2 * common / (a.length + b.length);
|
|
4830
|
+
}
|
|
4831
|
+
})(ChannelRounds ||= {});
|
|
4832
|
+
|
|
4833
|
+
// web-src/limit-settings.tsx
|
|
4834
|
+
function amount(pi, tokens) {
|
|
4835
|
+
return tokens > 0 ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(tokens) : ChannelWords.of(pi.ui.language).noLimit;
|
|
4568
4836
|
}
|
|
4569
|
-
function
|
|
4570
|
-
const
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
onChange: (event) => setRole(event.target.value)
|
|
4589
|
-
}), error && /* @__PURE__ */ React.createElement("div", {
|
|
4590
|
-
className: "tac-error"
|
|
4591
|
-
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4592
|
-
className: "tac-dialog-actions"
|
|
4593
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
4594
|
-
type: "submit",
|
|
4595
|
-
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4596
|
-
disabled: busy || !role.trim() || role.trim() === agent.role
|
|
4597
|
-
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4598
|
-
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4599
|
-
})))));
|
|
4837
|
+
function useLimits(pi) {
|
|
4838
|
+
const read = React.useCallback(async () => ({
|
|
4839
|
+
limits: ChannelRounds.limits(await pi.storage.get(Keys.LIMITS)),
|
|
4840
|
+
...((today) => ({ spent: today.total, channels: today.channels }))(ChannelRounds.today(await pi.storage.get(Keys.SPENT), Date.now()))
|
|
4841
|
+
}), [pi]);
|
|
4842
|
+
const [value, setValue] = React.useState({ limits: ChannelRounds.limits(undefined), spent: 0, channels: {} });
|
|
4843
|
+
React.useEffect(() => {
|
|
4844
|
+
let live = true;
|
|
4845
|
+
const load = () => void read().then((next) => live && setValue(next), () => {
|
|
4846
|
+
return;
|
|
4847
|
+
});
|
|
4848
|
+
load();
|
|
4849
|
+
const stop = pi.storage.onChange((keys) => (keys.includes(Keys.LIMITS) || keys.includes(Keys.SPENT)) && load());
|
|
4850
|
+
return () => {
|
|
4851
|
+
live = false;
|
|
4852
|
+
stop();
|
|
4853
|
+
};
|
|
4854
|
+
}, [pi, read]);
|
|
4855
|
+
return value;
|
|
4600
4856
|
}
|
|
4601
|
-
function
|
|
4602
|
-
const
|
|
4603
|
-
const
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4857
|
+
function limitSettings(pi, service) {
|
|
4858
|
+
const words = () => ChannelWords.of(pi.ui.language);
|
|
4859
|
+
const row = (key) => function Choices() {
|
|
4860
|
+
const { limits } = useLimits(pi);
|
|
4861
|
+
const pick = (value) => void service.setLimits({ [key]: value }).catch((error) => pi.ui.notify(String(error?.message ?? error), "error"));
|
|
4862
|
+
return /* @__PURE__ */ React.createElement("fieldset", {
|
|
4863
|
+
className: "ta-segmented",
|
|
4864
|
+
"aria-label": words()[key === "answer" ? "limitAnswer" : key === "channelDay" ? "limitChannelDay" : "limitAllDay"]
|
|
4865
|
+
}, LIMIT_CHOICES[key].map((value) => /* @__PURE__ */ React.createElement("button", {
|
|
4866
|
+
key: value,
|
|
4867
|
+
type: "button",
|
|
4868
|
+
"aria-pressed": limits[key] === value,
|
|
4869
|
+
className: limits[key] === value ? "ta-on" : "",
|
|
4870
|
+
onClick: () => pick(value)
|
|
4871
|
+
}, amount(pi, value))));
|
|
4872
|
+
};
|
|
4873
|
+
function Spent() {
|
|
4874
|
+
const { spent } = useLimits(pi);
|
|
4875
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
4876
|
+
className: "tac-limit-spent"
|
|
4877
|
+
}, spent > 0 ? amount(pi, spent) : "0");
|
|
4878
|
+
}
|
|
4879
|
+
return {
|
|
4880
|
+
title: () => words().limitsTitle,
|
|
4881
|
+
icon: pi.ui.icons.Coins ?? pi.ui.icons.Gauge,
|
|
4882
|
+
group: "ta",
|
|
4883
|
+
rows: [
|
|
4884
|
+
{ key: "answer", label: () => words().limitAnswer, description: () => words().limitAnswerHint, render: row("answer") },
|
|
4885
|
+
{ key: "channelDay", label: () => words().limitChannelDay, description: () => words().limitChannelDayHint, render: row("channelDay") },
|
|
4886
|
+
{ key: "allDay", label: () => words().limitAllDay, description: () => words().limitAllDayHint, render: row("allDay") },
|
|
4887
|
+
{ key: "spent", label: () => words().limitSpent, render: Spent }
|
|
4888
|
+
]
|
|
4613
4889
|
};
|
|
4614
|
-
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
4615
|
-
title: `${w.joinChannel} · ${agent.name}`,
|
|
4616
|
-
onClose
|
|
4617
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
4618
|
-
className: "tac-dialog"
|
|
4619
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
4620
|
-
className: "tac-pick-list"
|
|
4621
|
-
}, open.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4622
|
-
compact: true,
|
|
4623
|
-
title: w.noChannelToJoin
|
|
4624
|
-
}), open.map((channel) => /* @__PURE__ */ React.createElement("button", {
|
|
4625
|
-
key: channel.id,
|
|
4626
|
-
type: "button",
|
|
4627
|
-
className: "tac-pick",
|
|
4628
|
-
disabled: channel.members.length >= MAX_MEMBERS,
|
|
4629
|
-
onClick: () => join(channel.id, channel.name)
|
|
4630
|
-
}, /* @__PURE__ */ React.createElement(Hash, {
|
|
4631
|
-
size: 16
|
|
4632
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
4633
|
-
className: "tac-pick-text"
|
|
4634
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
4635
|
-
className: "tac-pick-name"
|
|
4636
|
-
}, channel.name), /* @__PURE__ */ React.createElement("span", {
|
|
4637
|
-
className: "tac-pick-role"
|
|
4638
|
-
}, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(channel.members.length) })))))), error && /* @__PURE__ */ React.createElement("div", {
|
|
4639
|
-
className: "tac-error"
|
|
4640
|
-
}, error)));
|
|
4641
4890
|
}
|
|
4642
4891
|
|
|
4643
4892
|
// ../ta-protocol/esm/common/team-protocol.js
|
|
@@ -4928,6 +5177,31 @@ var RoomUtil;
|
|
|
4928
5177
|
}
|
|
4929
5178
|
RoomUtil.rows = rows;
|
|
4930
5179
|
})(RoomUtil ||= {});
|
|
5180
|
+
function MessagePictures({ context, channelId, message, alt }) {
|
|
5181
|
+
const { pi, service } = context;
|
|
5182
|
+
const images = message.images ?? [];
|
|
5183
|
+
const [sources, setSources] = React.useState({});
|
|
5184
|
+
const ids = images.map((image) => image.id).join(",");
|
|
5185
|
+
React.useEffect(() => {
|
|
5186
|
+
let live = true;
|
|
5187
|
+
for (const id of ids ? ids.split(",") : []) {
|
|
5188
|
+
service.picture(channelId, id).then((data) => live && data && setSources((current) => ({ ...current, [id]: data })));
|
|
5189
|
+
}
|
|
5190
|
+
return () => {
|
|
5191
|
+
live = false;
|
|
5192
|
+
};
|
|
5193
|
+
}, [service, channelId, ids]);
|
|
5194
|
+
const ChatImages = pi.ui.ChatImages;
|
|
5195
|
+
if (!images.length || !ChatImages) {
|
|
5196
|
+
return null;
|
|
5197
|
+
}
|
|
5198
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
5199
|
+
className: "tac-pics"
|
|
5200
|
+
}, /* @__PURE__ */ React.createElement(ChatImages, {
|
|
5201
|
+
alt,
|
|
5202
|
+
images: images.map((image) => ({ key: image.id, src: sources[image.id], width: image.w, height: image.h }))
|
|
5203
|
+
}));
|
|
5204
|
+
}
|
|
4931
5205
|
function Mentions({ text, agents }) {
|
|
4932
5206
|
const names = new Set(agents.map((agent) => agent.name.toLowerCase()));
|
|
4933
5207
|
const parts = text.split(/(@[^\s@#,,。::]+)/);
|
|
@@ -5118,19 +5392,11 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5118
5392
|
}
|
|
5119
5393
|
const members = membersOf(state.team, channel);
|
|
5120
5394
|
const agentOf = (id) => state.team.agents.find((agent) => agent.id === id);
|
|
5395
|
+
const reply = ChannelsText.replyOf(channel);
|
|
5396
|
+
const lead = members.find((agent) => !(channel.muted ?? []).includes(agent.id));
|
|
5397
|
+
const placeholder = reply === "all" ? w.placeholderAll : reply === "lead" && lead ? w.placeholderLead : w.placeholder;
|
|
5121
5398
|
const name = (id) => ChannelsText.authorName(state.team, id, { user: w.you, ta: w.ta });
|
|
5122
5399
|
const time = (at) => SidebarUtil.time(at, pi.ui.language);
|
|
5123
|
-
const mention = (agent) => ({
|
|
5124
|
-
key: agent.id,
|
|
5125
|
-
label: agent.name,
|
|
5126
|
-
icon: /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
5127
|
-
agent,
|
|
5128
|
-
faces,
|
|
5129
|
-
size: 20
|
|
5130
|
-
}),
|
|
5131
|
-
detail: agent.id === channel.members[0] ? w.lead : undefined,
|
|
5132
|
-
insert: `@${agent.name} `
|
|
5133
|
-
});
|
|
5134
5400
|
return /* @__PURE__ */ React.createElement("div", {
|
|
5135
5401
|
className: "tac-room-page"
|
|
5136
5402
|
}, /* @__PURE__ */ React.createElement(NoticeBar, {
|
|
@@ -5179,7 +5445,12 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5179
5445
|
className: "tac-msg-col"
|
|
5180
5446
|
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
5181
5447
|
className: "tac-msg-name"
|
|
5182
|
-
}, message.byName ?? w.owner), /* @__PURE__ */ React.createElement(
|
|
5448
|
+
}, message.byName ?? w.owner), /* @__PURE__ */ React.createElement(MessagePictures, {
|
|
5449
|
+
context,
|
|
5450
|
+
channelId: channel.id,
|
|
5451
|
+
message,
|
|
5452
|
+
alt: message.byName ?? w.owner
|
|
5453
|
+
}), message.text && /* @__PURE__ */ React.createElement("div", {
|
|
5183
5454
|
className: "tac-msg-bubble",
|
|
5184
5455
|
title: time(message.at)
|
|
5185
5456
|
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
@@ -5187,7 +5458,12 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5187
5458
|
agents: state.team.agents
|
|
5188
5459
|
})))) : message.author === USER ? /* @__PURE__ */ React.createElement("div", {
|
|
5189
5460
|
className: "ta-message ta-user tac-mine"
|
|
5190
|
-
}, /* @__PURE__ */ React.createElement(
|
|
5461
|
+
}, /* @__PURE__ */ React.createElement(MessagePictures, {
|
|
5462
|
+
context,
|
|
5463
|
+
channelId: channel.id,
|
|
5464
|
+
message,
|
|
5465
|
+
alt: w.you
|
|
5466
|
+
}), message.text && /* @__PURE__ */ React.createElement("div", {
|
|
5191
5467
|
className: "ta-bubble"
|
|
5192
5468
|
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
5193
5469
|
text: message.text,
|
|
@@ -5231,12 +5507,12 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5231
5507
|
}))), ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") })))), /* @__PURE__ */ React.createElement("div", {
|
|
5232
5508
|
className: "tac-chat-bottom"
|
|
5233
5509
|
}, /* @__PURE__ */ React.createElement(Composer, {
|
|
5234
|
-
placeholder: ChannelWords.format(
|
|
5510
|
+
placeholder: ChannelWords.format(placeholder, { channel: channel.name, lead: lead?.name ?? "" }),
|
|
5235
5511
|
draft: channel.id,
|
|
5236
5512
|
mentions: members.map((agent) => ({ name: agent.name, detail: agent.role.split(`
|
|
5237
5513
|
`)[0] })),
|
|
5514
|
+
mentionLabel: w.mentionMember,
|
|
5238
5515
|
actions: [
|
|
5239
|
-
members.map(mention),
|
|
5240
5516
|
[
|
|
5241
5517
|
{
|
|
5242
5518
|
key: "notice",
|
|
@@ -5266,7 +5542,8 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5266
5542
|
}
|
|
5267
5543
|
]
|
|
5268
5544
|
],
|
|
5269
|
-
|
|
5545
|
+
images: { side: 1600, bytes: 1024 * 1024 },
|
|
5546
|
+
onSend: (text, images) => service.post(channel.id, text, images ?? [])
|
|
5270
5547
|
})));
|
|
5271
5548
|
}
|
|
5272
5549
|
|
|
@@ -5512,6 +5789,16 @@ async function editChannelTopic(context, channel) {
|
|
|
5512
5789
|
await context.service.updateChannel(channel.id, { topic });
|
|
5513
5790
|
}
|
|
5514
5791
|
}
|
|
5792
|
+
async function exportChannel(context, channel) {
|
|
5793
|
+
const { pi, service } = context;
|
|
5794
|
+
const w = ChannelViews.words(pi);
|
|
5795
|
+
const messages = await service.messages(channel.id);
|
|
5796
|
+
if (!messages.some((message) => message.text.trim())) {
|
|
5797
|
+
pi.ui.notify(ChannelWords.format(w.noMessagesToExport, { channel: channel.name }), "info");
|
|
5798
|
+
return;
|
|
5799
|
+
}
|
|
5800
|
+
download2(`${channel.name}.md`, ChannelsText.channelMarkdown(service.state.team, channel, messages, { user: w.you, ta: w.ta }));
|
|
5801
|
+
}
|
|
5515
5802
|
function ChannelMenu({ context, channel, working }) {
|
|
5516
5803
|
const { pi, service, ui } = context;
|
|
5517
5804
|
const { fresh } = useUi(ui);
|
|
@@ -5521,6 +5808,7 @@ function ChannelMenu({ context, channel, working }) {
|
|
|
5521
5808
|
Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
|
|
5522
5809
|
};
|
|
5523
5810
|
const unread = fresh.includes(channel.id);
|
|
5811
|
+
const manage = ChannelsUtil.may(service.state.team).manage(channel.id);
|
|
5524
5812
|
const pin = act(() => service.updateChannel(channel.id, { pinned: !channel.pinned }));
|
|
5525
5813
|
const markRead = act(() => ui.set({ fresh: unread ? fresh.filter((id) => id !== channel.id) : [...fresh, channel.id] }));
|
|
5526
5814
|
const rename = act(() => renameChannel(context, channel));
|
|
@@ -5533,14 +5821,7 @@ function ChannelMenu({ context, channel, working }) {
|
|
|
5533
5821
|
await TeamActions.stop(context, working);
|
|
5534
5822
|
pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info");
|
|
5535
5823
|
});
|
|
5536
|
-
const exportMarkdown = act(
|
|
5537
|
-
const messages = await service.messages(channel.id);
|
|
5538
|
-
if (!messages.some((message) => message.text.trim())) {
|
|
5539
|
-
pi.ui.notify(ChannelWords.format(w.noMessagesToExport, { channel: channel.name }), "info");
|
|
5540
|
-
return;
|
|
5541
|
-
}
|
|
5542
|
-
download2(`${channel.name}.md`, ChannelsText.channelMarkdown(service.state.team, channel, messages, { user: w.you, ta: w.ta }));
|
|
5543
|
-
});
|
|
5824
|
+
const exportMarkdown = act(() => exportChannel(context, channel));
|
|
5544
5825
|
const remove = act(() => deleteChannel(context, channel));
|
|
5545
5826
|
const budget = ChannelsUtil.budgetOf(channel);
|
|
5546
5827
|
const budgets = [
|
|
@@ -5568,13 +5849,16 @@ function ChannelMenu({ context, channel, working }) {
|
|
|
5568
5849
|
label: channel.name,
|
|
5569
5850
|
items: () => [
|
|
5570
5851
|
[
|
|
5571
|
-
item("pin", channel.pinned ? w.unpin : w.pin, channel.pinned ? "PinOff" : "Pin", pin),
|
|
5852
|
+
...manage ? [item("pin", channel.pinned ? w.unpin : w.pin, channel.pinned ? "PinOff" : "Pin", pin)] : [],
|
|
5572
5853
|
item("read", unread ? w.markRead : w.markUnread, unread ? "MessageSquareText" : "MessageSquareDot", markRead)
|
|
5573
5854
|
],
|
|
5574
|
-
[
|
|
5575
|
-
|
|
5855
|
+
[
|
|
5856
|
+
...manage ? [item("rename", w.rename, "Pencil", rename), item("topic", w.editTopic, "Text", editTopic)] : [],
|
|
5857
|
+
item("members", w.showMembers, "Users", members)
|
|
5858
|
+
],
|
|
5859
|
+
manage ? budgets.map(budgetItem) : [],
|
|
5576
5860
|
[item("stop", w.stopAnswering, "Square", stop, { disabled: working.length === 0 }), item("export", w.exportChat, "Download", exportMarkdown)],
|
|
5577
|
-
[item("delete", w.deleteChannel, "Trash2", remove, { danger: true })]
|
|
5861
|
+
manage ? [item("delete", w.deleteChannel, "Trash2", remove, { danger: true })] : []
|
|
5578
5862
|
]
|
|
5579
5863
|
});
|
|
5580
5864
|
}
|
|
@@ -5616,7 +5900,6 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5616
5900
|
const [confirming, setConfirming] = React.useState(false);
|
|
5617
5901
|
const [editing, setEditing] = React.useState();
|
|
5618
5902
|
const UserPlus = ChannelViews.icon(pi, "UserPlus");
|
|
5619
|
-
const Contact = ChannelViews.icon(pi, "Contact");
|
|
5620
5903
|
const Crown = ChannelViews.icon(pi, "Crown");
|
|
5621
5904
|
const BellOff = ChannelViews.icon(pi, "BellOff");
|
|
5622
5905
|
const RotateCcw = ChannelViews.icon(pi, "RotateCcw");
|
|
@@ -5624,6 +5907,9 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5624
5907
|
const Trash = ChannelViews.icon(pi, "Trash2");
|
|
5625
5908
|
const Sliders = pi.ui.icons.SlidersHorizontal ?? ChannelViews.icon(pi, "Pencil");
|
|
5626
5909
|
const members = membersOf(team, channel);
|
|
5910
|
+
const may = ChannelsUtil.may(team);
|
|
5911
|
+
const manage = may.manage(channel.id);
|
|
5912
|
+
const edit = may.edit(channel.id);
|
|
5627
5913
|
const models = new Set(members.map((agent) => agent.model ?? ""));
|
|
5628
5914
|
const shared = models.size === 1 ? [...models][0] : undefined;
|
|
5629
5915
|
const muted = channel.muted ?? [];
|
|
@@ -5657,7 +5943,7 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5657
5943
|
className: "tac-members-title"
|
|
5658
5944
|
}, /* @__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", {
|
|
5659
5945
|
className: "tac-members-label"
|
|
5660
|
-
}, /* @__PURE__ */ React.createElement("span", null, w.members, " · ", members.length), /* @__PURE__ */ React.createElement("span", {
|
|
5946
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.members, " · ", members.length), edit && /* @__PURE__ */ React.createElement("span", {
|
|
5661
5947
|
className: "tac-members-model",
|
|
5662
5948
|
title: w.sameModelHint
|
|
5663
5949
|
}, /* @__PURE__ */ React.createElement("span", null, w.sameModel), /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
|
|
@@ -5666,7 +5952,7 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5666
5952
|
label: w.sameModelHint,
|
|
5667
5953
|
disabled: !!busy,
|
|
5668
5954
|
onChange: setModel
|
|
5669
|
-
}))), /* @__PURE__ */ React.createElement("button", {
|
|
5955
|
+
}))), edit && /* @__PURE__ */ React.createElement("button", {
|
|
5670
5956
|
type: "button",
|
|
5671
5957
|
className: "tac-member-main",
|
|
5672
5958
|
onClick: () => ui.set({ adding: true })
|
|
@@ -5678,24 +5964,13 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5678
5964
|
className: "tac-member-text"
|
|
5679
5965
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
5680
5966
|
className: "tac-member-name"
|
|
5681
|
-
}, w.addMembers))),
|
|
5682
|
-
type: "button",
|
|
5683
|
-
className: "tac-member-main",
|
|
5684
|
-
onClick: () => openShareGroup(context, channel)
|
|
5685
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
5686
|
-
className: "tac-member-plus"
|
|
5687
|
-
}, /* @__PURE__ */ React.createElement(Contact, {
|
|
5688
|
-
size: 16
|
|
5689
|
-
})), /* @__PURE__ */ React.createElement("span", {
|
|
5690
|
-
className: "tac-member-text"
|
|
5691
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
5692
|
-
className: "tac-member-name"
|
|
5693
|
-
}, w.inviteFriends))), members.map((agent, index) => {
|
|
5967
|
+
}, w.addMembers))), members.map((agent, index) => {
|
|
5694
5968
|
const lead = index === 0;
|
|
5695
5969
|
const off = muted.includes(agent.id);
|
|
5696
5970
|
const answering = working.includes(agent.id);
|
|
5697
5971
|
const detail = answering ? w.replying : off ? w.muted : agent.role.split(`
|
|
5698
5972
|
`)[0] ?? "";
|
|
5973
|
+
const edits = may.agent(agent.id);
|
|
5699
5974
|
return /* @__PURE__ */ React.createElement("div", {
|
|
5700
5975
|
key: agent.id,
|
|
5701
5976
|
className: `tac-member${off ? " tac-muted" : ""}`
|
|
@@ -5726,9 +6001,9 @@ ${agent.role}`,
|
|
|
5726
6001
|
title: w.temporary
|
|
5727
6002
|
}, w.temporaryTag)), /* @__PURE__ */ React.createElement("span", {
|
|
5728
6003
|
className: `tac-member-detail${answering ? " tac-live" : ""}`
|
|
5729
|
-
}, detail))), /* @__PURE__ */ React.createElement("span", {
|
|
6004
|
+
}, detail))), (edits || manage) && /* @__PURE__ */ React.createElement("span", {
|
|
5730
6005
|
className: "tac-member-actions"
|
|
5731
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
6006
|
+
}, edits && /* @__PURE__ */ React.createElement("button", {
|
|
5732
6007
|
type: "button",
|
|
5733
6008
|
className: "tac-action",
|
|
5734
6009
|
title: w.agentSettings,
|
|
@@ -5737,7 +6012,7 @@ ${agent.role}`,
|
|
|
5737
6012
|
onClick: () => setEditing(agent)
|
|
5738
6013
|
}, /* @__PURE__ */ React.createElement(Sliders, {
|
|
5739
6014
|
size: 15
|
|
5740
|
-
})), agent.temporary && /* @__PURE__ */ React.createElement("button", {
|
|
6015
|
+
})), edits && agent.temporary && /* @__PURE__ */ React.createElement("button", {
|
|
5741
6016
|
type: "button",
|
|
5742
6017
|
className: "tac-action",
|
|
5743
6018
|
title: w.keep,
|
|
@@ -5746,7 +6021,7 @@ ${agent.role}`,
|
|
|
5746
6021
|
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"))
|
|
5747
6022
|
}, /* @__PURE__ */ React.createElement(UserPlus, {
|
|
5748
6023
|
size: 15
|
|
5749
|
-
})), !lead && /* @__PURE__ */ React.createElement("button", {
|
|
6024
|
+
})), manage && !lead && /* @__PURE__ */ React.createElement("button", {
|
|
5750
6025
|
type: "button",
|
|
5751
6026
|
className: "tac-action",
|
|
5752
6027
|
title: w.makeLead,
|
|
@@ -5755,7 +6030,7 @@ ${agent.role}`,
|
|
|
5755
6030
|
onClick: () => change(agent, "lead")
|
|
5756
6031
|
}, /* @__PURE__ */ React.createElement(Crown, {
|
|
5757
6032
|
size: 15
|
|
5758
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
6033
|
+
})), manage && /* @__PURE__ */ React.createElement("button", {
|
|
5759
6034
|
type: "button",
|
|
5760
6035
|
className: `tac-action${off ? " tac-on" : ""}`,
|
|
5761
6036
|
title: off ? w.unmute : w.mute,
|
|
@@ -5765,7 +6040,7 @@ ${agent.role}`,
|
|
|
5765
6040
|
onClick: () => change(agent, off ? "unmute" : "mute")
|
|
5766
6041
|
}, /* @__PURE__ */ React.createElement(BellOff, {
|
|
5767
6042
|
size: 15
|
|
5768
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
6043
|
+
})), edits && /* @__PURE__ */ React.createElement("button", {
|
|
5769
6044
|
type: "button",
|
|
5770
6045
|
className: "tac-action",
|
|
5771
6046
|
title: w.reset,
|
|
@@ -5774,7 +6049,7 @@ ${agent.role}`,
|
|
|
5774
6049
|
onClick: () => reset(agent)
|
|
5775
6050
|
}, /* @__PURE__ */ React.createElement(RotateCcw, {
|
|
5776
6051
|
size: 15
|
|
5777
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
6052
|
+
})), manage && /* @__PURE__ */ React.createElement("button", {
|
|
5778
6053
|
type: "button",
|
|
5779
6054
|
className: "tac-action",
|
|
5780
6055
|
title: members.length === 1 ? w.onlyMember : w.remove,
|
|
@@ -5786,12 +6061,13 @@ ${agent.role}`,
|
|
|
5786
6061
|
}))));
|
|
5787
6062
|
}), /* @__PURE__ */ React.createElement(ChannelSettings, {
|
|
5788
6063
|
context,
|
|
5789
|
-
channel
|
|
6064
|
+
channel,
|
|
6065
|
+
manage
|
|
5790
6066
|
})), editing && /* @__PURE__ */ React.createElement(AgentSettingsDialog, {
|
|
5791
6067
|
context,
|
|
5792
6068
|
agent: editing,
|
|
5793
6069
|
onClose: () => setEditing(undefined)
|
|
5794
|
-
}), /* @__PURE__ */ React.createElement("div", {
|
|
6070
|
+
}), manage && /* @__PURE__ */ React.createElement("div", {
|
|
5795
6071
|
className: "tac-members-foot"
|
|
5796
6072
|
}, confirming ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
|
|
5797
6073
|
className: "tac-members-ask"
|
|
@@ -5814,12 +6090,12 @@ ${agent.role}`,
|
|
|
5814
6090
|
size: 14
|
|
5815
6091
|
}), w.deleteChannel)));
|
|
5816
6092
|
}
|
|
5817
|
-
function ChannelSettings({ context, channel }) {
|
|
6093
|
+
function ChannelSettings({ context, channel, manage }) {
|
|
5818
6094
|
const { pi, service } = context;
|
|
5819
6095
|
const w = ChannelViews.words(pi);
|
|
5820
6096
|
const Chevron = ChannelViews.icon(pi, "ChevronRight");
|
|
5821
6097
|
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
5822
|
-
const row = (label, value, edit) => /* @__PURE__ */ React.createElement("button", {
|
|
6098
|
+
const row = (label, value, edit) => manage ? /* @__PURE__ */ React.createElement("button", {
|
|
5823
6099
|
type: "button",
|
|
5824
6100
|
className: "tac-setting",
|
|
5825
6101
|
onClick: () => edit().catch(fail)
|
|
@@ -5829,10 +6105,16 @@ function ChannelSettings({ context, channel }) {
|
|
|
5829
6105
|
className: "tac-setting-value"
|
|
5830
6106
|
}, value), /* @__PURE__ */ React.createElement(Chevron, {
|
|
5831
6107
|
size: 15
|
|
5832
|
-
}))
|
|
6108
|
+
})) : /* @__PURE__ */ React.createElement("div", {
|
|
6109
|
+
className: "tac-setting"
|
|
6110
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
6111
|
+
className: "tac-setting-label"
|
|
6112
|
+
}, label), /* @__PURE__ */ React.createElement("span", {
|
|
6113
|
+
className: "tac-setting-value"
|
|
6114
|
+
}, value));
|
|
5833
6115
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
5834
6116
|
className: "tac-members-sep"
|
|
5835
|
-
}), row(w.channelName, channel.name, () => renameChannel(context, channel)), row(w.topic, channel.topic ?? w.notSet, () => editChannelTopic(context, channel)), /* @__PURE__ */ React.createElement("div", {
|
|
6117
|
+
}), row(w.channelName, channel.name, () => renameChannel(context, channel)), row(w.topic, channel.topic ?? w.notSet, () => editChannelTopic(context, channel)), manage && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
5836
6118
|
className: "tac-setting"
|
|
5837
6119
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
5838
6120
|
className: "tac-setting-label"
|
|
@@ -5843,7 +6125,7 @@ function ChannelSettings({ context, channel }) {
|
|
|
5843
6125
|
})), /* @__PURE__ */ React.createElement(ChannelLimits, {
|
|
5844
6126
|
context,
|
|
5845
6127
|
channel
|
|
5846
|
-
}));
|
|
6128
|
+
})));
|
|
5847
6129
|
}
|
|
5848
6130
|
function ChannelLimits({ context, channel }) {
|
|
5849
6131
|
const { pi, service } = context;
|
|
@@ -5856,6 +6138,12 @@ function ChannelLimits({ context, channel }) {
|
|
|
5856
6138
|
["normal", w.budgetNormalWord],
|
|
5857
6139
|
["long", w.budgetLongWord]
|
|
5858
6140
|
];
|
|
6141
|
+
const reply = ChannelsText.replyOf(channel);
|
|
6142
|
+
const replies = [
|
|
6143
|
+
["mentioned", w.replyMentionedWord],
|
|
6144
|
+
["lead", w.replyLeadWord],
|
|
6145
|
+
["all", w.replyAllWord]
|
|
6146
|
+
];
|
|
5859
6147
|
const daily = [null, ...LIMIT_CHOICES.channelDay];
|
|
5860
6148
|
const own = channel.dailyLimit ?? null;
|
|
5861
6149
|
const limit = channel.dailyLimit ?? limits.channelDay;
|
|
@@ -5874,6 +6162,8 @@ function ChannelLimits({ context, channel }) {
|
|
|
5874
6162
|
className: "tac-limits"
|
|
5875
6163
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
5876
6164
|
className: "tac-limit-head"
|
|
6165
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.replyHead)), segment(w.replyHead, replies.map(([key]) => key), reply, (key) => replies.find(([other]) => other === key)?.[1] ?? key, (key) => service.updateChannel(channel.id, { reply: key }).catch(fail)), /* @__PURE__ */ React.createElement("div", {
|
|
6166
|
+
className: "tac-limit-head"
|
|
5877
6167
|
}, /* @__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", {
|
|
5878
6168
|
className: "tac-limit-head"
|
|
5879
6169
|
}, /* @__PURE__ */ React.createElement("span", null, w.dailyLimit), /* @__PURE__ */ React.createElement("span", {
|
|
@@ -5893,7 +6183,12 @@ function MemberPicker({ context, team, channel, faces }) {
|
|
|
5893
6183
|
const Check = ChannelViews.icon(pi, "Check");
|
|
5894
6184
|
const UserPlus = ChannelViews.icon(pi, "UserPlus");
|
|
5895
6185
|
const back = () => ui.set({ adding: false });
|
|
5896
|
-
const
|
|
6186
|
+
const friends = useFriends(pi).filter(() => !!pi.rooms && !team.may && channel.by !== "ta" && !channel.shared);
|
|
6187
|
+
const creates = ChannelsUtil.may(team).create;
|
|
6188
|
+
const [pickedFriends, setPickedFriends] = React.useState([]);
|
|
6189
|
+
const toggleFriend = (id) => setPickedFriends(pickedFriends.includes(id) ? pickedFriends.filter((other) => other !== id) : [...pickedFriends, id]);
|
|
6190
|
+
const { busy, error, submit } = useSubmit(() => pickedFriends.length > 0 ? becomeGroup(context, channel, pickedFriends, picked) : service.addMembers(channel.id, picked), back);
|
|
6191
|
+
const count = picked.length + pickedFriends.length;
|
|
5897
6192
|
const others = team.agents.filter((agent) => !channel.members.includes(agent.id));
|
|
5898
6193
|
const shown = others.filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
|
|
5899
6194
|
const toggle = (id) => setPicked(picked.includes(id) ? picked.filter((other) => other !== id) : [...picked, id]);
|
|
@@ -5956,7 +6251,39 @@ function MemberPicker({ context, team, channel, faces }) {
|
|
|
5956
6251
|
size: 12,
|
|
5957
6252
|
strokeWidth: 3
|
|
5958
6253
|
})));
|
|
5959
|
-
}), /* @__PURE__ */ React.createElement("div", {
|
|
6254
|
+
}), friends.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
6255
|
+
className: "tac-members-label"
|
|
6256
|
+
}, w.addFriends), friends.filter((friend) => SidebarUtil.matches(query, friend.name)).map((friend) => {
|
|
6257
|
+
const on = pickedFriends.includes(friend.id);
|
|
6258
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
6259
|
+
key: friend.id,
|
|
6260
|
+
type: "button",
|
|
6261
|
+
className: `tac-member-main tac-pick${on ? " tac-on" : ""}`,
|
|
6262
|
+
"aria-pressed": on,
|
|
6263
|
+
onClick: () => toggleFriend(friend.id)
|
|
6264
|
+
}, pi.ui.Face ? /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
6265
|
+
seed: friend.id,
|
|
6266
|
+
size: 32,
|
|
6267
|
+
look: friend.look
|
|
6268
|
+
}) : /* @__PURE__ */ React.createElement("span", {
|
|
6269
|
+
className: "tac-pick-face"
|
|
6270
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
6271
|
+
className: "tac-member-text"
|
|
6272
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
6273
|
+
className: "tac-member-name"
|
|
6274
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
6275
|
+
className: "tac-member-label"
|
|
6276
|
+
}, friend.name)), /* @__PURE__ */ React.createElement("span", {
|
|
6277
|
+
className: "tac-member-detail"
|
|
6278
|
+
}, w.friend)), /* @__PURE__ */ React.createElement("span", {
|
|
6279
|
+
className: "tac-check"
|
|
6280
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
6281
|
+
size: 12,
|
|
6282
|
+
strokeWidth: 3
|
|
6283
|
+
})));
|
|
6284
|
+
}), pickedFriends.length > 0 && /* @__PURE__ */ React.createElement("div", {
|
|
6285
|
+
className: "tac-members-note"
|
|
6286
|
+
}, w.shareGroupHint)), creates && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
5960
6287
|
className: "tac-members-sep"
|
|
5961
6288
|
}), /* @__PURE__ */ React.createElement("button", {
|
|
5962
6289
|
type: "button",
|
|
@@ -5970,20 +6297,235 @@ function MemberPicker({ context, team, channel, faces }) {
|
|
|
5970
6297
|
className: "tac-member-text"
|
|
5971
6298
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
5972
6299
|
className: "tac-member-name"
|
|
5973
|
-
}, w.newAgent)))), error && /* @__PURE__ */ React.createElement("div", {
|
|
6300
|
+
}, w.newAgent))))), error && /* @__PURE__ */ React.createElement("div", {
|
|
5974
6301
|
className: "tac-empty tac-error"
|
|
5975
6302
|
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
5976
6303
|
className: "tac-members-foot"
|
|
5977
6304
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
5978
6305
|
type: "button",
|
|
5979
6306
|
className: busy ? "tac-button tac-primary tac-wide ta-busy" : "tac-button tac-primary tac-wide",
|
|
5980
|
-
disabled: busy ||
|
|
6307
|
+
disabled: busy || count === 0,
|
|
5981
6308
|
onClick: submit
|
|
5982
|
-
},
|
|
6309
|
+
}, count > 0 ? ChannelWords.format(w.addCount, { count: String(count) }) : w.add, busy && /* @__PURE__ */ React.createElement("span", {
|
|
5983
6310
|
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
5984
6311
|
}))));
|
|
5985
6312
|
}
|
|
5986
6313
|
|
|
6314
|
+
// web-src/partners.tsx
|
|
6315
|
+
class ChannelPartners {
|
|
6316
|
+
context;
|
|
6317
|
+
current = [];
|
|
6318
|
+
signature = "";
|
|
6319
|
+
listeners = new Set;
|
|
6320
|
+
faces = new Map;
|
|
6321
|
+
read = new Set;
|
|
6322
|
+
constructor(context) {
|
|
6323
|
+
this.context = context;
|
|
6324
|
+
}
|
|
6325
|
+
partners = () => this.current;
|
|
6326
|
+
subscribe = (listener) => {
|
|
6327
|
+
this.listeners.add(listener);
|
|
6328
|
+
return () => this.listeners.delete(listener);
|
|
6329
|
+
};
|
|
6330
|
+
start() {
|
|
6331
|
+
const stopService = this.context.service.subscribe(() => this.refresh());
|
|
6332
|
+
const stopUi = this.context.ui.subscribe(() => this.refresh());
|
|
6333
|
+
this.refresh();
|
|
6334
|
+
return () => {
|
|
6335
|
+
stopService();
|
|
6336
|
+
stopUi();
|
|
6337
|
+
};
|
|
6338
|
+
}
|
|
6339
|
+
add() {
|
|
6340
|
+
const { pi, service } = this.context;
|
|
6341
|
+
if (!ChannelsUtil.may(service.state.team).create) {
|
|
6342
|
+
return [];
|
|
6343
|
+
}
|
|
6344
|
+
return [{ key: "agent", label: ChannelViews.words(pi).newAgent, icon: ChannelViews.icon(pi, "Bot"), run: () => newAgent(this.context) }];
|
|
6345
|
+
}
|
|
6346
|
+
async group(members) {
|
|
6347
|
+
if (!members.every((member) => member.extension === NAME && member.kind === "agent")) {
|
|
6348
|
+
return false;
|
|
6349
|
+
}
|
|
6350
|
+
const { service } = this.context;
|
|
6351
|
+
const names = members.map((member) => member.name.replace(/[@#,]/g, "")).join("、");
|
|
6352
|
+
const name = ChannelsUtil.freeName(service.state.team, names.length > MAX_NAME - 3 ? `${names.slice(0, MAX_NAME - 4)}…` : names);
|
|
6353
|
+
const channel = await service.createChannel({ name, members: members.map((member) => member.id) });
|
|
6354
|
+
this.context.showChannel(channel.id);
|
|
6355
|
+
return true;
|
|
6356
|
+
}
|
|
6357
|
+
addon() {
|
|
6358
|
+
const { pi, service } = this.context;
|
|
6359
|
+
const before = (roomId) => ChannelsUtil.ownChannels(service.state.team).find((channel) => channel.shared === roomId);
|
|
6360
|
+
return {
|
|
6361
|
+
tile: (room) => before(room.id) ? { label: ChannelViews.words(pi).sharedBeforeTile, icon: "Clock", status: ChannelViews.words(pi).sharedBefore } : undefined,
|
|
6362
|
+
open: (room) => {
|
|
6363
|
+
const channel = before(room.id);
|
|
6364
|
+
if (channel) {
|
|
6365
|
+
this.context.showChannel(channel.id);
|
|
6366
|
+
}
|
|
6367
|
+
},
|
|
6368
|
+
subscribe: (listener) => service.subscribe(listener)
|
|
6369
|
+
};
|
|
6370
|
+
}
|
|
6371
|
+
refresh() {
|
|
6372
|
+
const { pi, service, ui } = this.context;
|
|
6373
|
+
const { team, messages, working, loaded } = service.state;
|
|
6374
|
+
if (!loaded) {
|
|
6375
|
+
return;
|
|
6376
|
+
}
|
|
6377
|
+
const channels = ChannelsUtil.liveChannels(team);
|
|
6378
|
+
for (const channel of channels) {
|
|
6379
|
+
if (!this.read.has(channel.id)) {
|
|
6380
|
+
this.read.add(channel.id);
|
|
6381
|
+
service.messages(channel.id).catch(() => {
|
|
6382
|
+
return;
|
|
6383
|
+
});
|
|
6384
|
+
}
|
|
6385
|
+
}
|
|
6386
|
+
const agents = ChannelsUtil.standing(team);
|
|
6387
|
+
const { fresh } = ui.state;
|
|
6388
|
+
const language = pi.ui.language;
|
|
6389
|
+
const signature = [
|
|
6390
|
+
language,
|
|
6391
|
+
...agents.map((agent) => [agent.id, agent.name, agent.role, agent.face, agent.sessionFile ?? "", agent.cwd ?? ""].join(":")),
|
|
6392
|
+
...channels.map((channel) => [
|
|
6393
|
+
channel.id,
|
|
6394
|
+
channel.name,
|
|
6395
|
+
channel.topic ?? "",
|
|
6396
|
+
channel.members.join("/"),
|
|
6397
|
+
messages[channel.id]?.at(-1)?.id ?? "",
|
|
6398
|
+
(working[channel.id] ?? []).join("/"),
|
|
6399
|
+
fresh.includes(channel.id) ? 1 : 0
|
|
6400
|
+
].join(":"))
|
|
6401
|
+
].join("|");
|
|
6402
|
+
if (signature === this.signature) {
|
|
6403
|
+
return;
|
|
6404
|
+
}
|
|
6405
|
+
this.signature = signature;
|
|
6406
|
+
const w = ChannelWords.of(language);
|
|
6407
|
+
this.current = [...agents.map((agent) => this.agent(agent)), ...channels.map((channel) => this.channel(channel, w))];
|
|
6408
|
+
for (const listener of this.listeners) {
|
|
6409
|
+
listener();
|
|
6410
|
+
}
|
|
6411
|
+
}
|
|
6412
|
+
agent(agent) {
|
|
6413
|
+
const { pi } = this.context;
|
|
6414
|
+
const w = ChannelViews.words(pi);
|
|
6415
|
+
return {
|
|
6416
|
+
id: agent.id,
|
|
6417
|
+
kind: "agent",
|
|
6418
|
+
name: agent.name,
|
|
6419
|
+
face: this.agentFace(agent.id),
|
|
6420
|
+
icon: ChannelViews.icon(pi, "Bot"),
|
|
6421
|
+
about: agent.role,
|
|
6422
|
+
chat: agent.sessionFile ? { sessionFile: agent.sessionFile } : undefined,
|
|
6423
|
+
location: agent.cwd,
|
|
6424
|
+
open: () => ChannelViews.openAgent(this.context, agent.id),
|
|
6425
|
+
info: () => AgentActions.profile(this.context, agent),
|
|
6426
|
+
menu: () => AgentActions.menu(this.context, agent, this.answering(agent.id)),
|
|
6427
|
+
...ChannelsUtil.may(this.context.service.state.team).agent(agent.id) ? { remove: { key: "delete", label: w.deleteAgent, danger: true, run: () => void deleteAgent(this.context, agent) } } : {}
|
|
6428
|
+
};
|
|
6429
|
+
}
|
|
6430
|
+
channel(channel, w) {
|
|
6431
|
+
const { pi, service, ui } = this.context;
|
|
6432
|
+
const { team, messages, working } = service.state;
|
|
6433
|
+
const busy = working[channel.id] ?? [];
|
|
6434
|
+
const name = (id) => ChannelsText.authorName(team, id, { user: w.you, ta: w.ta });
|
|
6435
|
+
const last = messages[channel.id]?.filter((message) => message.author !== SYSTEM).at(-1);
|
|
6436
|
+
return {
|
|
6437
|
+
id: channel.id,
|
|
6438
|
+
kind: "group",
|
|
6439
|
+
name: channel.name,
|
|
6440
|
+
face: this.channelFace(channel.id),
|
|
6441
|
+
icon: ChannelViews.icon(pi, "Hash"),
|
|
6442
|
+
about: channel.topic ?? membersOf(team, channel).map((agent) => agent.name).join("、"),
|
|
6443
|
+
chat: {
|
|
6444
|
+
last: busy.length > 0 ? ChannelWords.format(w.answeringNow, { name: busy.map(name).join("、") }) : last ? `${name(last.author)}:${(last.images?.length && !last.text ? w.picture : last.text).replace(/\s+/g, " ")}` : undefined,
|
|
6445
|
+
at: SidebarUtil.channelAt(channel, messages[channel.id]),
|
|
6446
|
+
unseen: ui.state.fresh.includes(channel.id),
|
|
6447
|
+
busy: busy.length > 0
|
|
6448
|
+
},
|
|
6449
|
+
open: () => this.context.showChannel(channel.id),
|
|
6450
|
+
info: () => {
|
|
6451
|
+
this.context.showChannel(channel.id);
|
|
6452
|
+
this.context.showMembers();
|
|
6453
|
+
},
|
|
6454
|
+
menu: () => this.channelMenu(channel),
|
|
6455
|
+
...ChannelsUtil.may(service.state.team).manage(channel.id) ? { remove: { key: "delete", label: w.deleteChannel, danger: true, run: () => void deleteChannel(this.context, channel) } } : {}
|
|
6456
|
+
};
|
|
6457
|
+
}
|
|
6458
|
+
answering(id) {
|
|
6459
|
+
return Object.values(this.context.service.state.working).some((ids) => ids.includes(id));
|
|
6460
|
+
}
|
|
6461
|
+
channelMenu(channel) {
|
|
6462
|
+
const { pi, service, ui } = this.context;
|
|
6463
|
+
const w = ChannelViews.words(pi);
|
|
6464
|
+
const icon = (name) => ChannelViews.icon(pi, name);
|
|
6465
|
+
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
6466
|
+
const { fresh } = ui.state;
|
|
6467
|
+
const unread = fresh.includes(channel.id);
|
|
6468
|
+
const working = service.state.working[channel.id] ?? [];
|
|
6469
|
+
return [
|
|
6470
|
+
[
|
|
6471
|
+
{
|
|
6472
|
+
key: "read",
|
|
6473
|
+
label: unread ? w.markRead : w.markUnread,
|
|
6474
|
+
icon: icon(unread ? "MessageSquareText" : "MessageSquareDot"),
|
|
6475
|
+
run: () => ui.set({ fresh: unread ? fresh.filter((id) => id !== channel.id) : [...fresh, channel.id] })
|
|
6476
|
+
}
|
|
6477
|
+
],
|
|
6478
|
+
[
|
|
6479
|
+
{
|
|
6480
|
+
key: "stop",
|
|
6481
|
+
label: w.stopAnswering,
|
|
6482
|
+
icon: icon("Square"),
|
|
6483
|
+
disabled: working.length === 0,
|
|
6484
|
+
run: () => void TeamActions.stop(this.context, working).then(() => pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info")).catch(fail)
|
|
6485
|
+
},
|
|
6486
|
+
{ key: "export", label: w.exportChat, icon: icon("Download"), run: () => void exportChannel(this.context, channel).catch(fail) }
|
|
6487
|
+
]
|
|
6488
|
+
];
|
|
6489
|
+
}
|
|
6490
|
+
agentFace(id) {
|
|
6491
|
+
return this.face(`agent:${id}`, function AgentFace({ size, state: { team, working } }) {
|
|
6492
|
+
const faces = useFaces(team);
|
|
6493
|
+
return /* @__PURE__ */ React.createElement(Face, {
|
|
6494
|
+
face: faces.get(id) ?? 0,
|
|
6495
|
+
size,
|
|
6496
|
+
working: Object.values(working).some((ids) => ids.includes(id))
|
|
6497
|
+
});
|
|
6498
|
+
});
|
|
6499
|
+
}
|
|
6500
|
+
channelFace(id) {
|
|
6501
|
+
return this.face(`channel:${id}`, function ChannelFace({ size, state: { team, working } }) {
|
|
6502
|
+
const faces = useFaces(team);
|
|
6503
|
+
const channel = team.channels.find((each) => each.id === id);
|
|
6504
|
+
return /* @__PURE__ */ React.createElement(RoomFace, {
|
|
6505
|
+
members: channel ? membersOf(team, channel) : [],
|
|
6506
|
+
faces,
|
|
6507
|
+
size,
|
|
6508
|
+
working: working[id] ?? []
|
|
6509
|
+
});
|
|
6510
|
+
});
|
|
6511
|
+
}
|
|
6512
|
+
face(key, Draw) {
|
|
6513
|
+
let face = this.faces.get(key);
|
|
6514
|
+
if (!face) {
|
|
6515
|
+
const { service } = this.context;
|
|
6516
|
+
face = function PartnerFace({ size }) {
|
|
6517
|
+
const state = React.useSyncExternalStore((listener) => service.subscribe(listener), () => service.state);
|
|
6518
|
+
return /* @__PURE__ */ React.createElement(Draw, {
|
|
6519
|
+
size,
|
|
6520
|
+
state
|
|
6521
|
+
});
|
|
6522
|
+
};
|
|
6523
|
+
this.faces.set(key, face);
|
|
6524
|
+
}
|
|
6525
|
+
return face;
|
|
6526
|
+
}
|
|
6527
|
+
}
|
|
6528
|
+
|
|
5987
6529
|
// web-src/sidebar-hooks.ts
|
|
5988
6530
|
var FOLDED_KEY = "ta-channels.folded";
|
|
5989
6531
|
var BY_DIRECTORY_KEY = "ui.membersByDirectory";
|
|
@@ -6386,6 +6928,7 @@ function AgentsSidebar({ context, partners = false }) {
|
|
|
6386
6928
|
const { query, draft, channelId, fresh: unread } = useUi(ui);
|
|
6387
6929
|
const w = ChannelViews.words(pi);
|
|
6388
6930
|
const faces = useFaces(state.team);
|
|
6931
|
+
const may = ChannelsUtil.may(state.team);
|
|
6389
6932
|
const serverCwd = useServerCwd(pi) ?? "";
|
|
6390
6933
|
const shownSession = pi.ui.useSessionId();
|
|
6391
6934
|
const double = pi.ui.useView(DOUBLE_PAGE);
|
|
@@ -6412,7 +6955,7 @@ function AgentsSidebar({ context, partners = false }) {
|
|
|
6412
6955
|
const Empty = pi.ui.Empty;
|
|
6413
6956
|
const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
|
|
6414
6957
|
const { team, working } = state;
|
|
6415
|
-
const own = React.useMemo(() => ChannelsUtil.
|
|
6958
|
+
const own = React.useMemo(() => ChannelsUtil.liveChannels(team), [team]);
|
|
6416
6959
|
const seen = useSeenTasks(pi.storage, tasks);
|
|
6417
6960
|
const said = Object.values(state.messages).reduce((count, list) => count + list.length, 0);
|
|
6418
6961
|
const sessionLines = useSessionLines(context, `${said}:${Object.values(working).flat().join(",")}:${team.agents.length}`);
|
|
@@ -6527,7 +7070,7 @@ function AgentsSidebar({ context, partners = false }) {
|
|
|
6527
7070
|
cwd,
|
|
6528
7071
|
working: !!where
|
|
6529
7072
|
}),
|
|
6530
|
-
swipe: swipePinDelete(pi, !!agent.pinned, (pinned) => context.service.updateAgent(agent.id, { pinned }), () => deleteAgent(context, agent))
|
|
7073
|
+
swipe: may.agent(agent.id) ? swipePinDelete(pi, !!agent.pinned, (pinned) => context.service.updateAgent(agent.id, { pinned }), () => deleteAgent(context, agent)) : undefined
|
|
6531
7074
|
});
|
|
6532
7075
|
};
|
|
6533
7076
|
const chatAgents = partners && lastLines ? agents.filter((agent) => lastLines.has(agent.id)) : [];
|
|
@@ -6686,7 +7229,7 @@ function AgentsSidebar({ context, partners = false }) {
|
|
|
6686
7229
|
channel,
|
|
6687
7230
|
working: busy
|
|
6688
7231
|
}),
|
|
6689
|
-
swipe: swipePinDelete(pi, !!channel.pinned, (pinned) => context.service.updateChannel(channel.id, { pinned }), () => deleteChannel(context, channel))
|
|
7232
|
+
swipe: may.manage(channel.id) ? swipePinDelete(pi, !!channel.pinned, (pinned) => context.service.updateChannel(channel.id, { pinned }), () => deleteChannel(context, channel)) : undefined
|
|
6690
7233
|
});
|
|
6691
7234
|
})), agents.length > 0 && /* @__PURE__ */ React.createElement(Section, {
|
|
6692
7235
|
id: "members",
|
|
@@ -6898,6 +7441,9 @@ var STYLE = `
|
|
|
6898
7441
|
.tac-chat-empty strong { margin-top: 6px; color: var(--ta-text); font-size: calc(16px * var(--ta-font-scale)); }
|
|
6899
7442
|
.tac-chat-hint { margin-top: 4px; font-size: calc(12px * var(--ta-font-scale)); }
|
|
6900
7443
|
.tac-mine { margin: 6px 0 2px; }
|
|
7444
|
+
/* Pictures of a message (ui.ChatImages), no bubble around them, on the side of who sent them. */
|
|
7445
|
+
.tac-pics { margin: 1px 0 3px; }
|
|
7446
|
+
.tac-mine .tac-pics { align-self: flex-end; }
|
|
6901
7447
|
.tac-msg { display: flex; align-items: flex-start; gap: 10px; }
|
|
6902
7448
|
.tac-msg.tac-first { margin-top: 10px; }
|
|
6903
7449
|
.tac-msg-face { display: flex; justify-content: center; width: 28px; flex: none; }
|
|
@@ -7087,6 +7633,7 @@ textarea.tac-input { resize: vertical; min-height: 56px; line-height: 1.5; }
|
|
|
7087
7633
|
.tac-members-label { padding: 10px 10px 6px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
7088
7634
|
.tac-members-head { display: flex; align-items: center; gap: 6px; flex: none; padding: 10px 12px 4px 8px; font-size: calc(13.5px * var(--ta-font-scale)); }
|
|
7089
7635
|
.tac-members-search { flex: none; margin: 6px 16px 2px; }
|
|
7636
|
+
.tac-members-note { padding: 4px 10px 8px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: 1.5; }
|
|
7090
7637
|
.tac-members-sep { height: 1px; margin: 6px 10px; background: var(--ta-border-muted); }
|
|
7091
7638
|
.tac-member { position: relative; display: flex; align-items: center; border-radius: 12px; transition: background 120ms; }
|
|
7092
7639
|
.tac-member:hover, .tac-member:focus-within { background: var(--ta-hover); }
|
|
@@ -7110,6 +7657,10 @@ textarea.tac-input { resize: vertical; min-height: 56px; line-height: 1.5; }
|
|
|
7110
7657
|
.tac-members-scroll > .tac-pick { margin: 1px 0; }
|
|
7111
7658
|
.tac-check { display: grid; place-items: center; width: 18px; height: 18px; flex: none; box-sizing: border-box; border: 1.5px solid var(--ta-border-field); border-radius: 50%; color: var(--ta-main); }
|
|
7112
7659
|
.tac-pick.tac-on .tac-check { border-color: var(--ta-green); background: var(--ta-green); }
|
|
7660
|
+
.tac-setting-model > :last-child { flex: none; width: auto; max-width: 60%; margin-left: auto; }
|
|
7661
|
+
.tac-setting-model .ta-model-field { width: auto; justify-content: flex-end; gap: 4px; height: 28px; padding: 0 2px 0 8px; border: 0; border-radius: 6px; background: none; color: var(--ta-muted); font-size: inherit; }
|
|
7662
|
+
.tac-setting-model .ta-model-field:not(:disabled):hover { background: var(--ta-hover); color: var(--ta-text); }
|
|
7663
|
+
.tac-setting-model .ta-model-field > svg { width: 15px; height: 15px; }
|
|
7113
7664
|
.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); }
|
|
7114
7665
|
.tac-members-ask { flex: 1; min-width: 0; color: var(--ta-body); font-size: calc(12.5px * var(--ta-font-scale)); }
|
|
7115
7666
|
.tac-members-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
@@ -7413,21 +7964,28 @@ function activate(pi) {
|
|
|
7413
7964
|
new ChannelToolLines(context).register();
|
|
7414
7965
|
pi.registerMessageRenderer(HandOff.CARD, HandOffView.card(context));
|
|
7415
7966
|
pi.registerComposerAddon(HandOffView.composerAddon(context));
|
|
7416
|
-
const
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
partners
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7967
|
+
const shared = typeof pi.registerPartners === "function" ? new ChannelPartners(context) : undefined;
|
|
7968
|
+
const stopPartners = shared?.start();
|
|
7969
|
+
if (shared) {
|
|
7970
|
+
pi.registerPartners(shared);
|
|
7971
|
+
pi.registerRoomAddon?.(shared.addon());
|
|
7972
|
+
} else {
|
|
7973
|
+
const partners = !!pi.ui.doubleInChats;
|
|
7974
|
+
pi.registerView("channels", {
|
|
7975
|
+
title: () => partners ? ChannelWords.of(pi.ui.language).partners : ChannelWords.of(pi.ui.language).title,
|
|
7976
|
+
icon: ChannelViews.icon(pi, partners ? "Users" : "Bot"),
|
|
7977
|
+
head: () => /* @__PURE__ */ React.createElement(SidebarHead, {
|
|
7978
|
+
context
|
|
7979
|
+
}),
|
|
7980
|
+
render: () => /* @__PURE__ */ React.createElement(AgentsSidebar, {
|
|
7981
|
+
context,
|
|
7982
|
+
partners
|
|
7983
|
+
}),
|
|
7984
|
+
location: "sidebar",
|
|
7985
|
+
pages: partners ? [CHANNEL_PAGE, AGENT_PAGE] : [DOUBLE_PAGE, CHANNEL_PAGE, AGENT_PAGE],
|
|
7986
|
+
order: 80
|
|
7987
|
+
});
|
|
7988
|
+
}
|
|
7431
7989
|
pi.registerView("channel", {
|
|
7432
7990
|
title: () => {
|
|
7433
7991
|
const channel = service.state.team.channels.find((candidate) => candidate.id === ui.state.channelId);
|
|
@@ -7439,7 +7997,8 @@ function activate(pi) {
|
|
|
7439
7997
|
}),
|
|
7440
7998
|
render: () => /* @__PURE__ */ React.createElement(ChannelRoom, {
|
|
7441
7999
|
context
|
|
7442
|
-
})
|
|
8000
|
+
}),
|
|
8001
|
+
navigation: false
|
|
7443
8002
|
});
|
|
7444
8003
|
pi.registerView("agent", {
|
|
7445
8004
|
title: () => ui.state.draft?.name || ChannelWords.of(pi.ui.language).newAgentName,
|
|
@@ -7449,7 +8008,17 @@ function activate(pi) {
|
|
|
7449
8008
|
}),
|
|
7450
8009
|
render: () => /* @__PURE__ */ React.createElement(NewAgentPage, {
|
|
7451
8010
|
context
|
|
7452
|
-
})
|
|
8011
|
+
}),
|
|
8012
|
+
navigation: false
|
|
8013
|
+
});
|
|
8014
|
+
pi.registerView("agent-info", {
|
|
8015
|
+
title: () => ChannelWords.of(pi.ui.language).profileTitle,
|
|
8016
|
+
icon: ChannelViews.icon(pi, "Bot"),
|
|
8017
|
+
render: () => /* @__PURE__ */ React.createElement(AgentInfoView, {
|
|
8018
|
+
context
|
|
8019
|
+
}),
|
|
8020
|
+
location: "panel",
|
|
8021
|
+
order: 61
|
|
7453
8022
|
});
|
|
7454
8023
|
pi.registerView("members", {
|
|
7455
8024
|
title: () => ChannelWords.of(pi.ui.language).showMembers,
|
|
@@ -7473,6 +8042,7 @@ function activate(pi) {
|
|
|
7473
8042
|
service.load();
|
|
7474
8043
|
return () => {
|
|
7475
8044
|
stopFocus();
|
|
8045
|
+
stopPartners?.();
|
|
7476
8046
|
service.dispose();
|
|
7477
8047
|
removeStyle();
|
|
7478
8048
|
};
|