@celljs/ta-channels 4.22.0 → 4.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -0
- package/README.md +1 -1
- package/extension/index.mjs +69 -13
- package/host/index.mjs +342 -140
- package/package.json +4 -4
- package/web/index.js +2256 -1657
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) {
|
|
@@ -1355,8 +1379,9 @@ var JA = {
|
|
|
1355
1379
|
topic: "トピック",
|
|
1356
1380
|
members: "メンバー",
|
|
1357
1381
|
addMembers: "メンバーを追加",
|
|
1358
|
-
|
|
1359
|
-
|
|
1382
|
+
mentionMember: "メンバー",
|
|
1383
|
+
makeExtension: "保存",
|
|
1384
|
+
makeExtensionDetail: "ここで決めたやり方をワンタップで再利用できるように保存",
|
|
1360
1385
|
makeExtensionAsk: "このグループチャットで作成された事項を拡張機能にする(ta-package スキルで)、将来は 1 クリックで再利用可能",
|
|
1361
1386
|
add: "追加",
|
|
1362
1387
|
allMembers: "すべてのエージェントがこのグループチャットに既に含まれています",
|
|
@@ -1366,6 +1391,7 @@ var JA = {
|
|
|
1366
1391
|
back: "戻る",
|
|
1367
1392
|
send: "送信",
|
|
1368
1393
|
you: "あなた",
|
|
1394
|
+
picture: "[画像]",
|
|
1369
1395
|
owner: "オーナー",
|
|
1370
1396
|
ta: "Ta",
|
|
1371
1397
|
lead: "リーダー",
|
|
@@ -1376,6 +1402,8 @@ var JA = {
|
|
|
1376
1402
|
pick: "グループチャットを選択",
|
|
1377
1403
|
quiet: "まだメッセージがありません。@ で指定したエージェントが答えます。",
|
|
1378
1404
|
placeholder: "{channel} に送信;@ でメンバーを指定",
|
|
1405
|
+
placeholderLead: "{channel} に送信;@ なしは{lead}が回答",
|
|
1406
|
+
placeholderAll: "{channel} に送信;誰でも回答できます",
|
|
1379
1407
|
answering: "{name} が回答中",
|
|
1380
1408
|
failed: "回答がありません",
|
|
1381
1409
|
mention: "@{name}",
|
|
@@ -1402,6 +1430,10 @@ var JA = {
|
|
|
1402
1430
|
budgetShortWord: "短い",
|
|
1403
1431
|
budgetNormalWord: "標準",
|
|
1404
1432
|
budgetLongWord: "長い",
|
|
1433
|
+
replyHead: "@ なしのとき",
|
|
1434
|
+
replyMentionedWord: "@ のみ",
|
|
1435
|
+
replyLeadWord: "リーダー",
|
|
1436
|
+
replyAllWord: "全員",
|
|
1405
1437
|
dailyLimit: "1日の上限",
|
|
1406
1438
|
dailySpent: "今日 {spent}",
|
|
1407
1439
|
dailySpentOf: "今日 {spent} / {limit}",
|
|
@@ -1568,6 +1600,11 @@ var JA = {
|
|
|
1568
1600
|
shareCard: "カードを共有…",
|
|
1569
1601
|
cardTitle: "{name} のカード",
|
|
1570
1602
|
cardKind: "エージェントカード",
|
|
1603
|
+
profileTitle: "エージェントのプロフィール",
|
|
1604
|
+
noAgentOpen: "エージェントとの会話を開くと、ここにプロフィールが表示されます",
|
|
1605
|
+
sendMessage: "メッセージ",
|
|
1606
|
+
workDir: "作業ディレクトリ",
|
|
1607
|
+
deleteAgentLong: "エージェントを削除",
|
|
1571
1608
|
cardGets: "相手は自分のエージェントとして追加し、自分のプロジェクトに合わせて役割を調整します",
|
|
1572
1609
|
cardHint: "役割のみ(秘密のように見えるものは除去)、ディレクトリと会話は含まれません。リンクは 30 日間有効で、このコンピューターがオフでも開けます。",
|
|
1573
1610
|
cardRedacted: "役割に {n} 箇所の秘密のように見えるものが除去されました。",
|
|
@@ -1597,8 +1634,9 @@ var ZH = {
|
|
|
1597
1634
|
topic: "主题",
|
|
1598
1635
|
members: "成员",
|
|
1599
1636
|
addMembers: "添加成员",
|
|
1600
|
-
|
|
1601
|
-
|
|
1637
|
+
mentionMember: "成员",
|
|
1638
|
+
makeExtension: "存下来",
|
|
1639
|
+
makeExtensionDetail: "把这里商量出的做法存成以后一键再用的",
|
|
1602
1640
|
makeExtensionAsk: "把这个群聊里商量和做成的事做成扩展(用 ta-package 技能),以后一键就能再用",
|
|
1603
1641
|
add: "添加",
|
|
1604
1642
|
allMembers: "所有智能体都已在这个群聊里",
|
|
@@ -1608,6 +1646,7 @@ var ZH = {
|
|
|
1608
1646
|
back: "返回",
|
|
1609
1647
|
send: "发送",
|
|
1610
1648
|
you: "你",
|
|
1649
|
+
picture: "[图片]",
|
|
1611
1650
|
owner: "所有者",
|
|
1612
1651
|
ta: "Ta",
|
|
1613
1652
|
lead: "负责人",
|
|
@@ -1618,6 +1657,8 @@ var ZH = {
|
|
|
1618
1657
|
pick: "选一个群聊",
|
|
1619
1658
|
quiet: "还没有消息。@ 哪个智能体,它就会回答。",
|
|
1620
1659
|
placeholder: "发到 {channel};@ 点名成员",
|
|
1660
|
+
placeholderLead: "发到 {channel};不 @ 时{lead}来答",
|
|
1661
|
+
placeholderAll: "发到 {channel};大家都可以接话",
|
|
1621
1662
|
answering: "{name} 正在回答",
|
|
1622
1663
|
failed: "没有回答",
|
|
1623
1664
|
mention: "@{name}",
|
|
@@ -1644,6 +1685,10 @@ var ZH = {
|
|
|
1644
1685
|
budgetShortWord: "简短",
|
|
1645
1686
|
budgetNormalWord: "标准",
|
|
1646
1687
|
budgetLongWord: "深入",
|
|
1688
|
+
replyHead: "没 @ 时谁接话",
|
|
1689
|
+
replyMentionedWord: "只回 @",
|
|
1690
|
+
replyLeadWord: "负责人接",
|
|
1691
|
+
replyAllWord: "大家都接",
|
|
1647
1692
|
dailyLimit: "每天上限",
|
|
1648
1693
|
dailySpent: "今天 {spent}",
|
|
1649
1694
|
dailySpentOf: "今天 {spent} / {limit}",
|
|
@@ -1810,6 +1855,11 @@ var ZH = {
|
|
|
1810
1855
|
shareCard: "分享名片…",
|
|
1811
1856
|
cardTitle: "{name} 的名片",
|
|
1812
1857
|
cardKind: "智能体名片",
|
|
1858
|
+
profileTitle: "智能体资料",
|
|
1859
|
+
noAgentOpen: "打开和智能体的对话后,这里显示它的资料",
|
|
1860
|
+
sendMessage: "发消息",
|
|
1861
|
+
workDir: "工作目录",
|
|
1862
|
+
deleteAgentLong: "删除智能体",
|
|
1813
1863
|
cardGets: "对方把它加为自己的智能体,并按自己的项目调整职责",
|
|
1814
1864
|
cardHint: "只带上职责(隐去疑似密钥),不带工作目录和对话。链接 30 天内有效,你的电脑关机也能打开。",
|
|
1815
1865
|
cardRedacted: "职责里有 {n} 处疑似密钥已隐去。",
|
|
@@ -1839,8 +1889,9 @@ var ZH_TW = {
|
|
|
1839
1889
|
topic: "主題",
|
|
1840
1890
|
members: "成員",
|
|
1841
1891
|
addMembers: "新增成員",
|
|
1842
|
-
|
|
1843
|
-
|
|
1892
|
+
mentionMember: "成員",
|
|
1893
|
+
makeExtension: "存下來",
|
|
1894
|
+
makeExtensionDetail: "把這裡商量出的做法存成以後一鍵再用的",
|
|
1844
1895
|
makeExtensionAsk: "把這個群聊里商量和做成的事做成擴充功能(用 ta-package 技能),以後一鍵就能再用",
|
|
1845
1896
|
add: "新增",
|
|
1846
1897
|
allMembers: "所有智慧體都已在這個群聊里",
|
|
@@ -1850,6 +1901,7 @@ var ZH_TW = {
|
|
|
1850
1901
|
back: "返回",
|
|
1851
1902
|
send: "傳送",
|
|
1852
1903
|
you: "你",
|
|
1904
|
+
picture: "[圖片]",
|
|
1853
1905
|
owner: "所有者",
|
|
1854
1906
|
ta: "Ta",
|
|
1855
1907
|
lead: "負責人",
|
|
@@ -1860,6 +1912,8 @@ var ZH_TW = {
|
|
|
1860
1912
|
pick: "選一個群聊",
|
|
1861
1913
|
quiet: "還沒有訊息。@ 哪個智慧體,它就會回答。",
|
|
1862
1914
|
placeholder: "發到 {channel};@ 點名成員",
|
|
1915
|
+
placeholderLead: "發到 {channel};不 @ 時{lead}來答",
|
|
1916
|
+
placeholderAll: "發到 {channel};大家都可以接話",
|
|
1863
1917
|
answering: "{name} 正在回答",
|
|
1864
1918
|
failed: "沒有回答",
|
|
1865
1919
|
mention: "@{name}",
|
|
@@ -1886,6 +1940,10 @@ var ZH_TW = {
|
|
|
1886
1940
|
budgetShortWord: "簡短",
|
|
1887
1941
|
budgetNormalWord: "標準",
|
|
1888
1942
|
budgetLongWord: "深入",
|
|
1943
|
+
replyHead: "沒 @ 時誰接話",
|
|
1944
|
+
replyMentionedWord: "只回 @",
|
|
1945
|
+
replyLeadWord: "負責人接",
|
|
1946
|
+
replyAllWord: "大家都接",
|
|
1889
1947
|
dailyLimit: "每天上限",
|
|
1890
1948
|
dailySpent: "今天 {spent}",
|
|
1891
1949
|
dailySpentOf: "今天 {spent} / {limit}",
|
|
@@ -2052,6 +2110,11 @@ var ZH_TW = {
|
|
|
2052
2110
|
shareCard: "分享名片…",
|
|
2053
2111
|
cardTitle: "{name} 的名片",
|
|
2054
2112
|
cardKind: "智慧體名片",
|
|
2113
|
+
profileTitle: "智慧體資料",
|
|
2114
|
+
noAgentOpen: "開啟與智慧體的對話後,這裡顯示它的資料",
|
|
2115
|
+
sendMessage: "發訊息",
|
|
2116
|
+
workDir: "工作目錄",
|
|
2117
|
+
deleteAgentLong: "刪除智慧體",
|
|
2055
2118
|
cardGets: "對方把它加為自己的智慧體,並按自己的專案調整職責",
|
|
2056
2119
|
cardHint: "只帶上職責(隱去疑似金鑰),不帶工作目錄和對話。連結 30 天內有效,你的電腦關機也能開啟。",
|
|
2057
2120
|
cardRedacted: "職責裡有 {n} 處疑似金鑰已隱去。",
|
|
@@ -2081,8 +2144,9 @@ var EN = {
|
|
|
2081
2144
|
topic: "Topic",
|
|
2082
2145
|
members: "Members",
|
|
2083
2146
|
addMembers: "Add members",
|
|
2084
|
-
|
|
2085
|
-
|
|
2147
|
+
mentionMember: "Member",
|
|
2148
|
+
makeExtension: "Keep",
|
|
2149
|
+
makeExtensionDetail: "Make what was worked out here a one-tap thing to use again",
|
|
2086
2150
|
makeExtensionAsk: "Make what this group chat worked out an extension, with the ta-package skill, to do it again in a click",
|
|
2087
2151
|
add: "Add",
|
|
2088
2152
|
allMembers: "Every agent is in this group chat already",
|
|
@@ -2092,6 +2156,7 @@ var EN = {
|
|
|
2092
2156
|
back: "Back",
|
|
2093
2157
|
send: "Send",
|
|
2094
2158
|
you: "You",
|
|
2159
|
+
picture: "[Picture]",
|
|
2095
2160
|
owner: "Owner",
|
|
2096
2161
|
ta: "Ta",
|
|
2097
2162
|
lead: "Lead",
|
|
@@ -2102,6 +2167,8 @@ var EN = {
|
|
|
2102
2167
|
pick: "Pick a group chat",
|
|
2103
2168
|
quiet: "Nothing said yet. Mention an agent with @ to have it answer.",
|
|
2104
2169
|
placeholder: "Message {channel}; @ names a member",
|
|
2170
|
+
placeholderLead: "Message {channel}; {lead} answers without @",
|
|
2171
|
+
placeholderAll: "Message {channel}; anyone may answer",
|
|
2105
2172
|
answering: "{name} is answering",
|
|
2106
2173
|
failed: "did not answer",
|
|
2107
2174
|
mention: "Mention {name}",
|
|
@@ -2128,6 +2195,10 @@ var EN = {
|
|
|
2128
2195
|
budgetShortWord: "Short",
|
|
2129
2196
|
budgetNormalWord: "Normal",
|
|
2130
2197
|
budgetLongWord: "Long",
|
|
2198
|
+
replyHead: "Without @",
|
|
2199
|
+
replyMentionedWord: "Only @",
|
|
2200
|
+
replyLeadWord: "The lead",
|
|
2201
|
+
replyAllWord: "Everyone",
|
|
2131
2202
|
dailyLimit: "A day",
|
|
2132
2203
|
dailySpent: "today {spent}",
|
|
2133
2204
|
dailySpentOf: "today {spent} / {limit}",
|
|
@@ -2294,6 +2365,11 @@ var EN = {
|
|
|
2294
2365
|
shareCard: "Share card…",
|
|
2295
2366
|
cardTitle: "{name}'s card",
|
|
2296
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",
|
|
2297
2373
|
cardGets: "They add it as an agent of their own, fitted to their project",
|
|
2298
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.",
|
|
2299
2375
|
cardRedacted: "{n} places that looked like secrets were taken out.",
|
|
@@ -2324,13 +2400,13 @@ var ChannelWords;
|
|
|
2324
2400
|
var DOUBLE_PAGE = "assistant/assistant";
|
|
2325
2401
|
var CHANNEL_PAGE = `${NAME}/channel`;
|
|
2326
2402
|
var MEMBERS_VIEW = `${NAME}/members`;
|
|
2403
|
+
var AGENT_INFO_VIEW = `${NAME}/agent-info`;
|
|
2327
2404
|
var ROOM_INFO_VIEW = "@celljs/ta-rooms/members";
|
|
2328
2405
|
var CHANNEL_KEY = "ta-channels.channel";
|
|
2329
2406
|
|
|
2330
2407
|
class ChannelsUiStore {
|
|
2331
2408
|
current = {
|
|
2332
2409
|
query: "",
|
|
2333
|
-
fresh: [],
|
|
2334
2410
|
adding: false,
|
|
2335
2411
|
editing: false,
|
|
2336
2412
|
creating: false,
|
|
@@ -2406,6 +2482,19 @@ function useChannels(service) {
|
|
|
2406
2482
|
}, [service]);
|
|
2407
2483
|
return state;
|
|
2408
2484
|
}
|
|
2485
|
+
function useChannelUnseen(context, channelId) {
|
|
2486
|
+
const { seen, service } = context;
|
|
2487
|
+
const subscribe = React.useCallback((listener) => {
|
|
2488
|
+
const stopSeen = seen.subscribe(listener);
|
|
2489
|
+
const stopService = service.subscribe(listener);
|
|
2490
|
+
return () => {
|
|
2491
|
+
stopSeen();
|
|
2492
|
+
stopService();
|
|
2493
|
+
};
|
|
2494
|
+
}, [seen, service]);
|
|
2495
|
+
const read = () => seen.unseen(channelId, service.state.messages[channelId], (service.state.working[channelId] ?? []).length > 0);
|
|
2496
|
+
return React.useSyncExternalStore(subscribe, read, read);
|
|
2497
|
+
}
|
|
2409
2498
|
function useUi(ui) {
|
|
2410
2499
|
return React.useSyncExternalStore((listener) => ui.subscribe(listener), () => ui.state);
|
|
2411
2500
|
}
|
|
@@ -2831,1749 +2920,2128 @@ function registerCardOpener(context) {
|
|
|
2831
2920
|
}, { specific: true });
|
|
2832
2921
|
}
|
|
2833
2922
|
|
|
2834
|
-
//
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2923
|
+
// ../ta-protocol/esm/common/said-protocol.js
|
|
2924
|
+
var TaSaid;
|
|
2925
|
+
(function(TaSaid2) {
|
|
2926
|
+
const CARD = /^ta-/i;
|
|
2927
|
+
const READ = 4000;
|
|
2928
|
+
const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
|
|
2929
|
+
const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
|
|
2930
|
+
const MARKS_ONLY = /^[-*_=|:+\s]+$/;
|
|
2931
|
+
const MARKS = [
|
|
2932
|
+
["context", /<\/?context>/],
|
|
2933
|
+
["source", /\[ta:(?:from|notice|by) /],
|
|
2934
|
+
["image note", /\[Image: original \d+x\d+|\[Image converted from /],
|
|
2935
|
+
["skill", /<skill name="|<\/skill>/],
|
|
2936
|
+
["task note", /<\/?task_(?:update|adopted|renamed)\b/],
|
|
2937
|
+
["summary", /<\/?(?:conversation_history_summary|summary)>/]
|
|
2938
|
+
];
|
|
2939
|
+
function text(content, joiner = `
|
|
2940
|
+
`) {
|
|
2941
|
+
if (typeof content === "string") {
|
|
2942
|
+
return content;
|
|
2943
|
+
}
|
|
2944
|
+
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) : "";
|
|
2847
2945
|
}
|
|
2848
|
-
|
|
2849
|
-
|
|
2946
|
+
TaSaid2.text = text;
|
|
2947
|
+
function words(role, text2, options = {}) {
|
|
2948
|
+
const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
|
|
2949
|
+
return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
|
|
2850
2950
|
}
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
return
|
|
2951
|
+
TaSaid2.words = words;
|
|
2952
|
+
function of(message, options) {
|
|
2953
|
+
return message ? words(message.role, text(message.content), options) : "";
|
|
2854
2954
|
}
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
return ()
|
|
2955
|
+
TaSaid2.of = of;
|
|
2956
|
+
function notice(message) {
|
|
2957
|
+
return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
|
|
2858
2958
|
}
|
|
2859
|
-
|
|
2860
|
-
|
|
2959
|
+
TaSaid2.notice = notice;
|
|
2960
|
+
function marksOnly(role, text2) {
|
|
2961
|
+
return !!text2.trim() && !line(words(role, text2), { chars: Number.POSITIVE_INFINITY });
|
|
2861
2962
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2963
|
+
TaSaid2.marksOnly = marksOnly;
|
|
2964
|
+
function line(markdown, options) {
|
|
2965
|
+
var _a;
|
|
2966
|
+
const read = markdown.slice(0, READ);
|
|
2967
|
+
const prose = withoutFences(read, () => true, true).trim();
|
|
2968
|
+
const lines = plain(prose || codeOf(read)).split(`
|
|
2969
|
+
`).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));
|
|
2970
|
+
const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
|
|
2971
|
+
const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
|
|
2972
|
+
`);
|
|
2973
|
+
return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
|
|
2974
|
+
}
|
|
2975
|
+
TaSaid2.line = line;
|
|
2976
|
+
function leaks(shown, options = {}) {
|
|
2977
|
+
const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
|
|
2978
|
+
const lines = shown.split(`
|
|
2979
|
+
`);
|
|
2980
|
+
if (options.cards !== true && lines.some((part) => {
|
|
2981
|
+
var _a;
|
|
2982
|
+
var _b;
|
|
2983
|
+
return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
|
|
2984
|
+
})) {
|
|
2985
|
+
found.push("card");
|
|
2869
2986
|
}
|
|
2870
|
-
|
|
2987
|
+
if (lines.some((part) => TAG_LINE.test(part.trim()))) {
|
|
2988
|
+
found.push("tag");
|
|
2989
|
+
}
|
|
2990
|
+
return found;
|
|
2871
2991
|
}
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2992
|
+
TaSaid2.leaks = leaks;
|
|
2993
|
+
const SUMMARY = `<conversation_history_summary>
|
|
2994
|
+
<summary>
|
|
2995
|
+
1. Primary Request and Intent:
|
|
2996
|
+
The user works on the relay.
|
|
2997
|
+
</summary>
|
|
2998
|
+
</conversation_history_summary>`;
|
|
2999
|
+
TaSaid2.SAMPLES = [
|
|
3000
|
+
{
|
|
3001
|
+
mark: "context and where it came from",
|
|
3002
|
+
role: "user",
|
|
3003
|
+
text: `<context>
|
|
3004
|
+
The channel #ops, its members.
|
|
3005
|
+
[ta:from @celljs/ta-channels #ops]
|
|
3006
|
+
</context>
|
|
3007
|
+
Check the build`,
|
|
3008
|
+
said: "Check the build"
|
|
3009
|
+
},
|
|
3010
|
+
{
|
|
3011
|
+
mark: "a notice, not the user",
|
|
3012
|
+
role: "user",
|
|
3013
|
+
text: `<context>
|
|
3014
|
+
[ta:notice @celljs/ta-call]
|
|
3015
|
+
</context>
|
|
3016
|
+
The work finished. Its last words: tests pass.`,
|
|
3017
|
+
said: "The work finished. Its last words: tests pass."
|
|
3018
|
+
},
|
|
3019
|
+
{ mark: "one let in", role: "user", text: `<context>
|
|
3020
|
+
[ta:by p-7 Alice]
|
|
3021
|
+
</context>
|
|
3022
|
+
Hello there`, said: "Hello there" },
|
|
3023
|
+
{
|
|
3024
|
+
mark: "notes of images",
|
|
3025
|
+
role: "user",
|
|
3026
|
+
text: `Look at this
|
|
3027
|
+
[Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
|
|
3028
|
+
[Image converted from image/heic to image/png.]`,
|
|
3029
|
+
said: "Look at this"
|
|
3030
|
+
},
|
|
3031
|
+
{
|
|
3032
|
+
mark: "a skill run",
|
|
3033
|
+
role: "user",
|
|
3034
|
+
text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
|
|
3035
|
+
# Ta package
|
|
3036
|
+
Steps.
|
|
3037
|
+
</skill>
|
|
3038
|
+
|
|
3039
|
+
Make a card`,
|
|
3040
|
+
said: "Make a card"
|
|
3041
|
+
},
|
|
3042
|
+
{
|
|
3043
|
+
mark: "a note of a task",
|
|
3044
|
+
role: "user",
|
|
3045
|
+
text: `<task_update id="t1" title="Fix login" status="done">
|
|
3046
|
+
All tests pass.
|
|
3047
|
+
</task_update>`,
|
|
3048
|
+
said: "Fix login"
|
|
3049
|
+
},
|
|
3050
|
+
{ mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
|
|
3051
|
+
Now t2.
|
|
3052
|
+
</task_renamed>` },
|
|
3053
|
+
{ mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
|
|
3054
|
+
Switched to voice.`, said: "Switched to voice." },
|
|
3055
|
+
{ mark: "a summary alone", role: "assistant", text: SUMMARY },
|
|
3056
|
+
{ mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
|
|
3057
|
+
<summary>` },
|
|
3058
|
+
{
|
|
3059
|
+
mark: "a card after the answer",
|
|
3060
|
+
role: "assistant",
|
|
3061
|
+
text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
|
|
3062
|
+
said: "tests pass"
|
|
3063
|
+
},
|
|
3064
|
+
{ mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
|
|
3065
|
+
{ mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
|
|
3066
|
+
{ mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
|
|
3067
|
+
{ mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
|
|
3068
|
+
</system-reminder>
|
|
3069
|
+
Ready.`, said: "Ready." }
|
|
3070
|
+
];
|
|
3071
|
+
function userWords(text2) {
|
|
3072
|
+
const said = TaImageNote.strip(TaMessageContext.strip(text2));
|
|
3073
|
+
const skill = TaSkillUse.parse(said);
|
|
3074
|
+
if (skill) {
|
|
3075
|
+
return TaSkillUse.command(skill);
|
|
2876
3076
|
}
|
|
2877
|
-
const
|
|
2878
|
-
|
|
2879
|
-
|
|
3077
|
+
const note = TaTaskNote.parse(said);
|
|
3078
|
+
if (!note) {
|
|
3079
|
+
return said;
|
|
3080
|
+
}
|
|
3081
|
+
if (note.kind === "renamed") {
|
|
3082
|
+
return "";
|
|
3083
|
+
}
|
|
3084
|
+
return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
|
|
2880
3085
|
}
|
|
2881
|
-
|
|
2882
|
-
const
|
|
2883
|
-
|
|
2884
|
-
|
|
3086
|
+
function withoutFences(text2, drop, tags = false) {
|
|
3087
|
+
const kept = [];
|
|
3088
|
+
let fence;
|
|
3089
|
+
let left = false;
|
|
3090
|
+
for (const part of text2.split(`
|
|
3091
|
+
`)) {
|
|
3092
|
+
const open = FENCE.exec(part);
|
|
3093
|
+
if (!fence && open) {
|
|
3094
|
+
fence = { mark: open[1], dropped: drop(open[2]) };
|
|
3095
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
3096
|
+
const dropped = fence.dropped;
|
|
3097
|
+
fence = undefined;
|
|
3098
|
+
if (dropped) {
|
|
3099
|
+
continue;
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
|
|
3103
|
+
left = true;
|
|
3104
|
+
} else {
|
|
3105
|
+
kept.push(part);
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
return left ? kept.join(`
|
|
3109
|
+
`).replace(/\n{3,}/g, `
|
|
3110
|
+
|
|
3111
|
+
`) : kept.join(`
|
|
3112
|
+
`);
|
|
2885
3113
|
}
|
|
2886
|
-
|
|
2887
|
-
const
|
|
2888
|
-
|
|
2889
|
-
|
|
3114
|
+
function codeOf(text2) {
|
|
3115
|
+
const code = [];
|
|
3116
|
+
let fence;
|
|
3117
|
+
for (const part of text2.split(`
|
|
3118
|
+
`)) {
|
|
3119
|
+
const open = FENCE.exec(part);
|
|
3120
|
+
if (!fence && open) {
|
|
3121
|
+
fence = { mark: open[1], card: CARD.test(open[2]) };
|
|
3122
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
3123
|
+
fence = undefined;
|
|
3124
|
+
} else if (fence && !fence.card) {
|
|
3125
|
+
code.push(part);
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
return code.join(`
|
|
3129
|
+
`);
|
|
2890
3130
|
}
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
return
|
|
2895
|
-
}
|
|
2896
|
-
async changeMember(channelId, agentId, change) {
|
|
2897
|
-
const channel = await this.send({ kind: "changeMember", channel: channelId, agent: agentId, change });
|
|
2898
|
-
await this.load(true);
|
|
2899
|
-
return channel;
|
|
2900
|
-
}
|
|
2901
|
-
async updateChannel(channelId, change) {
|
|
2902
|
-
const channel = await this.send({ kind: "updateChannel", channel: channelId, ...change });
|
|
2903
|
-
await this.load(true);
|
|
2904
|
-
return channel;
|
|
2905
|
-
}
|
|
2906
|
-
async deleteChannel(channelId) {
|
|
2907
|
-
await this.deleting(channelId, async () => {
|
|
2908
|
-
await this.send({ kind: "deleteChannel", channel: channelId });
|
|
2909
|
-
const { [channelId]: _gone, ...messages } = this.current.messages;
|
|
2910
|
-
this.update({ messages });
|
|
2911
|
-
await this.load(true);
|
|
2912
|
-
});
|
|
2913
|
-
}
|
|
2914
|
-
async resetAgent(agentId) {
|
|
2915
|
-
const agent = await this.send({ kind: "resetAgent", agent: agentId });
|
|
2916
|
-
await this.load(true);
|
|
2917
|
-
return agent;
|
|
3131
|
+
function closes(part, mark) {
|
|
3132
|
+
var _a;
|
|
3133
|
+
const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
|
|
3134
|
+
return !!close && close[0] === mark[0] && close.length >= mark.length;
|
|
2918
3135
|
}
|
|
2919
|
-
|
|
2920
|
-
const
|
|
2921
|
-
|
|
2922
|
-
return
|
|
3136
|
+
function plain(text2) {
|
|
3137
|
+
const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
3138
|
+
const words2 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
|
|
3139
|
+
return words2 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
2923
3140
|
}
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
3141
|
+
})(TaSaid || (TaSaid = {}));
|
|
3142
|
+
|
|
3143
|
+
// web-src/channels-text.ts
|
|
3144
|
+
var ChannelsText;
|
|
3145
|
+
((ChannelsText) => {
|
|
3146
|
+
function markMentions(text, agents) {
|
|
3147
|
+
if (agents.length === 0) {
|
|
3148
|
+
return text;
|
|
3149
|
+
}
|
|
3150
|
+
const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
3151
|
+
const pattern = new RegExp(`(?<![*A-Za-z0-9_])@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
|
|
3152
|
+
return text.split(/(```[\s\S]*?(?:```|$)|`[^`\n]*`)/).map((part, index) => index % 2 === 1 ? part : part.replace(pattern, "**$&**")).join("");
|
|
2928
3153
|
}
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
}
|
|
3154
|
+
ChannelsText.markMentions = markMentions;
|
|
3155
|
+
function mentions(text, agents) {
|
|
3156
|
+
if (agents.length === 0) {
|
|
3157
|
+
return [];
|
|
3158
|
+
}
|
|
3159
|
+
const names = [...agents].sort((a, b) => b.name.length - a.name.length).map((agent) => agent.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
3160
|
+
const pattern = new RegExp(`@(${names.join("|")})(?![A-Za-z0-9_-])`, "gi");
|
|
3161
|
+
const found = [];
|
|
3162
|
+
for (const match of text.matchAll(pattern)) {
|
|
3163
|
+
const agent = agents.find((candidate) => candidate.name.toLowerCase() === match[1].toLowerCase());
|
|
3164
|
+
if (agent && !found.includes(agent.id)) {
|
|
3165
|
+
found.push(agent.id);
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
return found;
|
|
2934
3169
|
}
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
3170
|
+
ChannelsText.mentions = mentions;
|
|
3171
|
+
function targets(team, channel, message) {
|
|
3172
|
+
const members = answering(team, channel);
|
|
3173
|
+
const named = mentions(message.text, members).filter((id) => id !== message.author);
|
|
3174
|
+
if (message.author === SYSTEM) {
|
|
3175
|
+
return [];
|
|
3176
|
+
}
|
|
3177
|
+
if (named.length > 0 || message.author !== TA && message.author !== USER || mentions(message.text, team.agents).length > 0) {
|
|
3178
|
+
return named;
|
|
3179
|
+
}
|
|
3180
|
+
const reply = message.author === TA ? "lead" : replyOf(channel);
|
|
3181
|
+
if (reply === "all") {
|
|
3182
|
+
return members.map((agent) => agent.id);
|
|
2941
3183
|
}
|
|
3184
|
+
return reply === "lead" && members.length > 0 ? [members[0].id] : [];
|
|
2942
3185
|
}
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
return
|
|
3186
|
+
ChannelsText.targets = targets;
|
|
3187
|
+
function replyOf(channel) {
|
|
3188
|
+
return channel?.reply && REPLIES.includes(channel.reply) ? channel.reply : DEFAULT_REPLY;
|
|
2946
3189
|
}
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
return channel;
|
|
3190
|
+
ChannelsText.replyOf = replyOf;
|
|
3191
|
+
function passes(text) {
|
|
3192
|
+
return text.replace(/[\s.。!!*_`"'“”]/g, "").toUpperCase() === PASS;
|
|
2951
3193
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
3194
|
+
ChannelsText.passes = passes;
|
|
3195
|
+
function answering(team, channel) {
|
|
3196
|
+
const muted = channel.muted ?? [];
|
|
3197
|
+
return channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
|
|
2954
3198
|
}
|
|
2955
|
-
|
|
2956
|
-
|
|
3199
|
+
function mayPass(team, channel, message, agent) {
|
|
3200
|
+
const members = answering(team, channel);
|
|
3201
|
+
return message.author === USER && replyOf(channel) === "all" && members[0]?.id !== agent.id && mentions(message.text, team.agents).length === 0;
|
|
2957
3202
|
}
|
|
2958
|
-
|
|
2959
|
-
|
|
3203
|
+
ChannelsText.mayPass = mayPass;
|
|
3204
|
+
function authorName(team, author, labels) {
|
|
3205
|
+
if (author === SYSTEM) {
|
|
3206
|
+
return "channel";
|
|
3207
|
+
}
|
|
3208
|
+
if (author === USER) {
|
|
3209
|
+
return labels.user;
|
|
3210
|
+
}
|
|
3211
|
+
if (author === TA) {
|
|
3212
|
+
return labels.ta;
|
|
3213
|
+
}
|
|
3214
|
+
return team.agents.find((agent) => agent.id === author)?.name ?? author;
|
|
2960
3215
|
}
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
3216
|
+
ChannelsText.authorName = authorName;
|
|
3217
|
+
function systemPrompt(agent) {
|
|
3218
|
+
return [
|
|
3219
|
+
`You are ${agent.name}, ${AGENT_MARK}. Your role: ${agent.role}`,
|
|
3220
|
+
"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.",
|
|
3221
|
+
"Do the part of the work your role covers with your tools, then answer: your answer is posted to the channel as it is.",
|
|
3222
|
+
"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.",
|
|
3223
|
+
"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.",
|
|
3224
|
+
NOTICE_RULE
|
|
3225
|
+
].join(`
|
|
3226
|
+
`);
|
|
2965
3227
|
}
|
|
2966
|
-
|
|
2967
|
-
|
|
3228
|
+
ChannelsText.systemPrompt = systemPrompt;
|
|
3229
|
+
function prompt(team, channel, history, message, agent, options = {}) {
|
|
3230
|
+
const labels = { user: "user", ta: "Ta" };
|
|
3231
|
+
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)}`);
|
|
3232
|
+
const before = history.filter((item) => item.id !== message.id && !item.failed && !item.notice).slice(-CONTEXT_MESSAGES);
|
|
3233
|
+
const lines = [`[#${channel.name}]${channel.topic ? ` ${channel.topic}` : ""}`, "Members:", ...members.map((line) => `- ${line}`)];
|
|
3234
|
+
if (channel.notice) {
|
|
3235
|
+
lines.push("", "Notice of the channel (follow it; keep it with update_channel_notice):", channel.notice.text);
|
|
3236
|
+
}
|
|
3237
|
+
if (before.length > 0) {
|
|
3238
|
+
lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${said(item)}`));
|
|
3239
|
+
}
|
|
3240
|
+
if (options.closing) {
|
|
3241
|
+
lines.push("", CLOSING_NOTE);
|
|
3242
|
+
}
|
|
3243
|
+
if (mayPass(team, channel, message, agent)) {
|
|
3244
|
+
lines.push("", PASS_NOTE);
|
|
3245
|
+
}
|
|
3246
|
+
lines.push("", `${authorName(team, message.author, labels)} to you:`);
|
|
3247
|
+
const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels)}`;
|
|
3248
|
+
lines.push(TaMessageSource.line(NAME, `#${channel.name}${speaker}`));
|
|
3249
|
+
if (message.images?.length) {
|
|
3250
|
+
lines.push(`(${message.images.length > 1 ? `${message.images.length} pictures` : "A picture"} sent with it, attached.)`);
|
|
3251
|
+
}
|
|
3252
|
+
return TaMessageContext.wrap(lines.join(`
|
|
3253
|
+
`), message.text);
|
|
2968
3254
|
}
|
|
2969
|
-
|
|
2970
|
-
|
|
3255
|
+
ChannelsText.prompt = prompt;
|
|
3256
|
+
function said(message) {
|
|
3257
|
+
const pictures = message.images?.length ? `[${message.images.length > 1 ? `${message.images.length} pictures` : "picture"}]` : "";
|
|
3258
|
+
return [pictures, message.text].filter(Boolean).join(" ");
|
|
2971
3259
|
}
|
|
2972
|
-
|
|
2973
|
-
|
|
3260
|
+
ChannelsText.said = said;
|
|
3261
|
+
function summary(team) {
|
|
3262
|
+
if (team.agents.length === 0) {
|
|
3263
|
+
return "No agents and no channels yet.";
|
|
3264
|
+
}
|
|
3265
|
+
const name = (id) => team.agents.find((agent) => agent.id === id)?.name ?? id;
|
|
3266
|
+
const agents = team.agents.map((agent) => `- @${agent.name}: ${firstLine(agent.role)}`);
|
|
3267
|
+
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 ? `
|
|
3268
|
+
notice: ${channel.notice.text.replace(/\s+/g, " ").slice(0, 300)}` : ""}`);
|
|
3269
|
+
return ["Agents:", ...agents, "", "Channels:", ...channels.length > 0 ? channels : ["none yet"]].join(`
|
|
3270
|
+
`);
|
|
2974
3271
|
}
|
|
2975
|
-
|
|
2976
|
-
|
|
3272
|
+
ChannelsText.summary = summary;
|
|
3273
|
+
function transcript(team, messages) {
|
|
3274
|
+
const labels = { user: "user", ta: "Ta" };
|
|
3275
|
+
return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${said(item)}`).join(`
|
|
3276
|
+
|
|
3277
|
+
`);
|
|
2977
3278
|
}
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
reads.push(this.storage.get(Keys.FOCUS).then(async (focus) => {
|
|
2990
|
-
if (focus) {
|
|
2991
|
-
await this.load(true);
|
|
2992
|
-
for (const listener of this.focusListeners) {
|
|
2993
|
-
listener(focus.channelId);
|
|
2994
|
-
}
|
|
2995
|
-
}
|
|
2996
|
-
}));
|
|
3279
|
+
ChannelsText.transcript = transcript;
|
|
3280
|
+
function markdown(agent, messages, labels) {
|
|
3281
|
+
const parts = [`# ${agent.name}`, "", `> ${firstLine(agent.role)}`];
|
|
3282
|
+
for (const message of messages) {
|
|
3283
|
+
const { role, content } = message ?? {};
|
|
3284
|
+
if (role !== "user" && role !== "assistant") {
|
|
3285
|
+
continue;
|
|
3286
|
+
}
|
|
3287
|
+
const text = TaSaid.words(role, TaSaid.text(content, ""));
|
|
3288
|
+
if (text) {
|
|
3289
|
+
parts.push("", `## ${role === "user" ? labels.user : agent.name}`, "", text);
|
|
2997
3290
|
}
|
|
2998
3291
|
}
|
|
2999
|
-
|
|
3292
|
+
return `${parts.join(`
|
|
3293
|
+
`)}
|
|
3294
|
+
`;
|
|
3000
3295
|
}
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3296
|
+
ChannelsText.markdown = markdown;
|
|
3297
|
+
function channelMarkdown(team, channel, messages, labels) {
|
|
3298
|
+
const parts = [`# #${channel.name}`];
|
|
3299
|
+
if (channel.topic) {
|
|
3300
|
+
parts.push("", `> ${firstLine(channel.topic)}`);
|
|
3005
3301
|
}
|
|
3302
|
+
for (const message of messages) {
|
|
3303
|
+
const text = message.text.trim();
|
|
3304
|
+
if (text && message.author !== SYSTEM) {
|
|
3305
|
+
parts.push("", `## ${authorName(team, message.author, labels)}${message.failed ? " (failed)" : ""}`, "", text);
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
return `${parts.join(`
|
|
3309
|
+
`)}
|
|
3310
|
+
`;
|
|
3006
3311
|
}
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
const [friends, setFriends] = React.useState([]);
|
|
3012
|
-
React.useEffect(() => {
|
|
3013
|
-
let live = true;
|
|
3014
|
-
pi.rooms?.listFriends().then((list) => live && setFriends(list.filter((friend) => friend.status === "friend")), () => {
|
|
3015
|
-
return;
|
|
3016
|
-
});
|
|
3017
|
-
return () => {
|
|
3018
|
-
live = false;
|
|
3019
|
-
};
|
|
3020
|
-
}, [pi]);
|
|
3021
|
-
return friends;
|
|
3022
|
-
}
|
|
3023
|
-
async function createShared(context, title, friends, agents) {
|
|
3024
|
-
const { pi } = context;
|
|
3025
|
-
const rooms = pi.rooms;
|
|
3026
|
-
if (!rooms) {
|
|
3027
|
-
throw new Error(ChannelViews.words(pi).sharedNeedsRooms);
|
|
3028
|
-
}
|
|
3029
|
-
const room = await rooms.createRoom({ kind: ROOMS_KIND, title });
|
|
3030
|
-
await rooms.inviteFriends(room.id, friends);
|
|
3031
|
-
for (const agent of agents) {
|
|
3032
|
-
await pi.packages.callPackageHost(ROOMS_PACKAGE, "doubles", [{ kind: "invite", room: room.id, agent }]).catch((error) => {
|
|
3033
|
-
pi.ui.notify(ChannelViews.message(error), "error");
|
|
3034
|
-
});
|
|
3312
|
+
ChannelsText.channelMarkdown = channelMarkdown;
|
|
3313
|
+
function firstLine(text) {
|
|
3314
|
+
return text.split(`
|
|
3315
|
+
`)[0];
|
|
3035
3316
|
}
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
const members = [...channel.members, ...agents.filter((id) => !channel.members.includes(id))];
|
|
3045
|
-
const room = await createShared(context, channel.name, friends, members);
|
|
3046
|
-
await context.service.updateChannel(channel.id, { shared: room });
|
|
3047
|
-
pi.ui.notify(ChannelWords.format(ChannelViews.words(pi).sharedMade, { name: channel.name }), "info");
|
|
3048
|
-
}
|
|
3317
|
+
})(ChannelsText ||= {});
|
|
3318
|
+
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.";
|
|
3319
|
+
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.`;
|
|
3320
|
+
var NOTICE_RULE = [
|
|
3321
|
+
"A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
|
|
3322
|
+
`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.`
|
|
3323
|
+
].join(`
|
|
3324
|
+
`);
|
|
3049
3325
|
|
|
3050
|
-
// web-src/
|
|
3051
|
-
var
|
|
3052
|
-
|
|
3053
|
-
function newAgent(context) {
|
|
3054
|
-
const { pi, service, ui } = context;
|
|
3055
|
-
if (!ui.state.draft) {
|
|
3056
|
-
const team = service.state.team;
|
|
3057
|
-
const name = ChannelsUtil.freeName(team, ChannelViews.words(pi).newAgentName);
|
|
3058
|
-
ui.set({ draft: { name, face: ChannelsUtil.freeFaceFor(team.agents, ChannelsUtil.newId("draft")) } });
|
|
3059
|
-
}
|
|
3060
|
-
pi.ui.showView(AGENT_PAGE);
|
|
3061
|
-
}
|
|
3062
|
-
function Identity({ context, onClose }) {
|
|
3063
|
-
const { pi, ui } = context;
|
|
3064
|
-
const { draft } = useUi(ui);
|
|
3326
|
+
// web-src/more-menu.tsx
|
|
3327
|
+
var MARGIN = 8;
|
|
3328
|
+
function MoreMenu({ pi, label, items }) {
|
|
3065
3329
|
const w = ChannelViews.words(pi);
|
|
3066
|
-
const
|
|
3067
|
-
const
|
|
3068
|
-
|
|
3069
|
-
|
|
3330
|
+
const [open, setOpen] = React.useState(false);
|
|
3331
|
+
const anchor = React.useRef({
|
|
3332
|
+
right: 0,
|
|
3333
|
+
below: 0,
|
|
3334
|
+
above: 0,
|
|
3335
|
+
finger: undefined
|
|
3336
|
+
});
|
|
3337
|
+
const root = React.useRef(null);
|
|
3338
|
+
const menu = React.useRef(null);
|
|
3339
|
+
const Ellipsis = ChannelViews.icon(pi, "Ellipsis");
|
|
3340
|
+
const show = React.useCallback((button, at) => {
|
|
3341
|
+
const box = button.getBoundingClientRect();
|
|
3342
|
+
const touch = document.documentElement.hasAttribute("data-touch");
|
|
3343
|
+
const row = root.current?.parentElement?.getBoundingClientRect() ?? box;
|
|
3344
|
+
anchor.current = {
|
|
3345
|
+
right: box.right,
|
|
3346
|
+
below: at?.y ?? box.bottom,
|
|
3347
|
+
above: at?.y ?? box.top,
|
|
3348
|
+
finger: touch && at ? { ...at, around: { top: row.top, bottom: row.bottom } } : undefined
|
|
3349
|
+
};
|
|
3350
|
+
setOpen(true);
|
|
3351
|
+
}, []);
|
|
3352
|
+
React.useLayoutEffect(() => {
|
|
3353
|
+
const element = menu.current;
|
|
3354
|
+
if (!open || !element) {
|
|
3355
|
+
return;
|
|
3356
|
+
}
|
|
3357
|
+
const { right, below, above, finger } = anchor.current;
|
|
3358
|
+
if (finger) {
|
|
3359
|
+
return pi.ui.attachMenu(element, finger, () => setOpen(false));
|
|
3360
|
+
}
|
|
3361
|
+
const width = element.offsetWidth;
|
|
3362
|
+
const height = element.offsetHeight;
|
|
3363
|
+
const top = below + 4 + height <= window.innerHeight - MARGIN ? below + 4 : Math.max(MARGIN, above - 4 - height);
|
|
3364
|
+
element.style.top = `${top}px`;
|
|
3365
|
+
element.style.left = `${Math.max(MARGIN, right - width)}px`;
|
|
3366
|
+
}, [open, pi]);
|
|
3367
|
+
React.useEffect(() => {
|
|
3368
|
+
const row = root.current?.parentElement;
|
|
3369
|
+
const button = root.current?.querySelector(".tac-action");
|
|
3370
|
+
if (!row || !button) {
|
|
3371
|
+
return;
|
|
3372
|
+
}
|
|
3373
|
+
const onContextMenu = (event) => {
|
|
3374
|
+
event.preventDefault();
|
|
3375
|
+
show(button, event.clientX || event.clientY ? { x: event.clientX, y: event.clientY } : undefined);
|
|
3376
|
+
};
|
|
3377
|
+
row.addEventListener("contextmenu", onContextMenu);
|
|
3378
|
+
return () => row.removeEventListener("contextmenu", onContextMenu);
|
|
3379
|
+
}, [show]);
|
|
3070
3380
|
React.useEffect(() => {
|
|
3381
|
+
if (!open) {
|
|
3382
|
+
return;
|
|
3383
|
+
}
|
|
3071
3384
|
const close = (event) => {
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3385
|
+
if (!root.current?.contains(event.target)) {
|
|
3386
|
+
setOpen(false);
|
|
3387
|
+
}
|
|
3388
|
+
};
|
|
3389
|
+
const onKey = (event) => {
|
|
3390
|
+
if (event.key === "Escape") {
|
|
3391
|
+
setOpen(false);
|
|
3075
3392
|
}
|
|
3076
3393
|
};
|
|
3077
|
-
const onKey = (event) => event.key === "Escape" && onClose();
|
|
3078
3394
|
document.addEventListener("pointerdown", close);
|
|
3079
3395
|
document.addEventListener("keydown", onKey);
|
|
3080
3396
|
return () => {
|
|
3081
3397
|
document.removeEventListener("pointerdown", close);
|
|
3082
3398
|
document.removeEventListener("keydown", onKey);
|
|
3083
3399
|
};
|
|
3084
|
-
}, [
|
|
3085
|
-
if (!draft) {
|
|
3086
|
-
return null;
|
|
3087
|
-
}
|
|
3088
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
3089
|
-
className: "tac-identity",
|
|
3090
|
-
ref,
|
|
3091
|
-
role: "dialog",
|
|
3092
|
-
"aria-label": w.editAgent
|
|
3093
|
-
}, /* @__PURE__ */ React.createElement("label", {
|
|
3094
|
-
className: "tac-identity-label"
|
|
3095
|
-
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
3096
|
-
className: "tac-input",
|
|
3097
|
-
value: draft.name,
|
|
3098
|
-
maxLength: 40,
|
|
3099
|
-
ref: name,
|
|
3100
|
-
onChange: (event) => ui.set({ draft: { ...draft, name: event.target.value } }),
|
|
3101
|
-
onKeyDown: (event) => event.key === "Enter" && onClose()
|
|
3102
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
3103
|
-
className: "tac-identity-label"
|
|
3104
|
-
}, w.avatar), /* @__PURE__ */ React.createElement("div", {
|
|
3105
|
-
className: "tac-faces"
|
|
3106
|
-
}, Array.from({ length: FACES }, (_, face) => /* @__PURE__ */ React.createElement("button", {
|
|
3107
|
-
key: face,
|
|
3108
|
-
type: "button",
|
|
3109
|
-
"aria-pressed": draft.face === face,
|
|
3110
|
-
className: `tac-face-pick${draft.face === face ? " tac-on" : ""}`,
|
|
3111
|
-
onClick: () => ui.set({ draft: { ...draft, face } })
|
|
3112
|
-
}, /* @__PURE__ */ React.createElement(Face, {
|
|
3113
|
-
face,
|
|
3114
|
-
size: 30
|
|
3115
|
-
})))));
|
|
3116
|
-
}
|
|
3117
|
-
function NewAgentHead({ context }) {
|
|
3118
|
-
const { pi, ui } = context;
|
|
3119
|
-
const { draft, editing } = useUi(ui);
|
|
3120
|
-
const w = ChannelViews.words(pi);
|
|
3121
|
-
const Down = ChannelViews.icon(pi, "ChevronDown");
|
|
3122
|
-
if (!draft) {
|
|
3123
|
-
return null;
|
|
3124
|
-
}
|
|
3400
|
+
}, [open]);
|
|
3125
3401
|
return /* @__PURE__ */ React.createElement("div", {
|
|
3126
|
-
className: "tac-
|
|
3127
|
-
|
|
3128
|
-
className: "tac-new-title"
|
|
3402
|
+
className: "tac-item-more",
|
|
3403
|
+
ref: root
|
|
3129
3404
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
3130
3405
|
type: "button",
|
|
3131
|
-
className:
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3406
|
+
className: `tac-action${open ? " tac-on" : ""}`,
|
|
3407
|
+
title: w.more,
|
|
3408
|
+
"aria-label": w.more,
|
|
3409
|
+
"aria-haspopup": "menu",
|
|
3410
|
+
"aria-expanded": open,
|
|
3411
|
+
onClick: (event) => {
|
|
3412
|
+
event.stopPropagation();
|
|
3413
|
+
if (open) {
|
|
3414
|
+
setOpen(false);
|
|
3415
|
+
} else {
|
|
3416
|
+
show(event.currentTarget);
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
}, /* @__PURE__ */ React.createElement(Ellipsis, {
|
|
3420
|
+
size: 15
|
|
3421
|
+
})), open && /* @__PURE__ */ React.createElement("div", {
|
|
3422
|
+
ref: menu,
|
|
3423
|
+
className: "tac-menu tac-agent-menu",
|
|
3424
|
+
role: "menu",
|
|
3425
|
+
"aria-label": label
|
|
3426
|
+
}, items().filter((section) => section.length > 0).map((section, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
3427
|
+
key: section[0]?.key ?? index
|
|
3428
|
+
}, index > 0 && /* @__PURE__ */ React.createElement("hr", {
|
|
3429
|
+
className: "tac-menu-line"
|
|
3430
|
+
}), section.map((item) => /* @__PURE__ */ React.createElement("button", {
|
|
3431
|
+
key: item.key,
|
|
3144
3432
|
type: "button",
|
|
3145
|
-
|
|
3433
|
+
role: "menuitem",
|
|
3434
|
+
className: item.danger ? "tac-danger" : undefined,
|
|
3435
|
+
disabled: item.disabled,
|
|
3146
3436
|
onClick: () => {
|
|
3147
|
-
|
|
3148
|
-
|
|
3437
|
+
setOpen(false);
|
|
3438
|
+
item.run();
|
|
3149
3439
|
}
|
|
3150
|
-
},
|
|
3440
|
+
}, item.icon, /* @__PURE__ */ React.createElement("span", {
|
|
3441
|
+
className: "tac-menu-label"
|
|
3442
|
+
}, item.label)))))));
|
|
3151
3443
|
}
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3444
|
+
|
|
3445
|
+
// web-src/agent-menu.tsx
|
|
3446
|
+
async function copy(text) {
|
|
3447
|
+
try {
|
|
3448
|
+
await navigator.clipboard.writeText(text);
|
|
3449
|
+
return true;
|
|
3450
|
+
} catch {
|
|
3451
|
+
return false;
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
function download(name, text) {
|
|
3455
|
+
const url = URL.createObjectURL(new Blob([text], { type: "text/markdown;charset=utf-8" }));
|
|
3456
|
+
const link = document.createElement("a");
|
|
3457
|
+
link.href = url;
|
|
3458
|
+
link.download = name;
|
|
3459
|
+
link.click();
|
|
3460
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
3461
|
+
}
|
|
3462
|
+
async function deleteAgent(context, agent) {
|
|
3463
|
+
const w = ChannelViews.words(context.pi);
|
|
3464
|
+
const sure = await context.pi.ui.confirm(ChannelWords.format(w.confirmDeleteAgent, { name: agent.name }), undefined, {
|
|
3465
|
+
confirmLabel: w.delete,
|
|
3466
|
+
danger: true
|
|
3467
|
+
});
|
|
3468
|
+
if (sure) {
|
|
3469
|
+
await context.service.deleteAgent(agent.id);
|
|
3470
|
+
context.sessions.delete(agent.id);
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
var AgentActions;
|
|
3474
|
+
((AgentActions) => {
|
|
3475
|
+
function fail(context, error) {
|
|
3476
|
+
context.pi.ui.notify(ChannelViews.message(error), "error");
|
|
3477
|
+
}
|
|
3478
|
+
function run(context, action) {
|
|
3479
|
+
return () => {
|
|
3480
|
+
Promise.resolve().then(action).catch((error) => fail(context, error));
|
|
3481
|
+
};
|
|
3482
|
+
}
|
|
3483
|
+
AgentActions.run = run;
|
|
3484
|
+
async function openSession(context, agent) {
|
|
3485
|
+
if (!agent.sessionFile) {
|
|
3162
3486
|
return;
|
|
3163
3487
|
}
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3488
|
+
return (await context.pi.server.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
|
|
3489
|
+
}
|
|
3490
|
+
async function stop(context, agent) {
|
|
3491
|
+
const session = await openSession(context, agent);
|
|
3492
|
+
if (session) {
|
|
3493
|
+
await context.pi.server.abort(session.sessionId);
|
|
3167
3494
|
}
|
|
3168
|
-
|
|
3169
|
-
if (!draft) {
|
|
3170
|
-
return null;
|
|
3495
|
+
context.pi.ui.notify(ChannelWords.format(ChannelViews.words(context.pi).stoppedAgent, { name: agent.name }), "info");
|
|
3171
3496
|
}
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
pi.ui.notify(ChannelViews.
|
|
3497
|
+
AgentActions.stop = stop;
|
|
3498
|
+
async function restart(context, agent) {
|
|
3499
|
+
await context.service.resetAgent(agent.id);
|
|
3500
|
+
context.sessions.delete(agent.id);
|
|
3501
|
+
context.pi.ui.notify(ChannelWords.format(ChannelViews.words(context.pi).resetDone, { name: agent.name }), "info");
|
|
3502
|
+
}
|
|
3503
|
+
AgentActions.restart = restart;
|
|
3504
|
+
async function copyCwd(context, cwd) {
|
|
3505
|
+
if (await copy(cwd)) {
|
|
3506
|
+
context.pi.ui.notify(ChannelWords.format(ChannelViews.words(context.pi).copied, { path: cwd }), "info");
|
|
3182
3507
|
}
|
|
3183
|
-
}
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
}
|
|
3212
|
-
|
|
3213
|
-
function
|
|
3508
|
+
}
|
|
3509
|
+
AgentActions.copyCwd = copyCwd;
|
|
3510
|
+
async function exportChat(context, agent) {
|
|
3511
|
+
const { pi, service } = context;
|
|
3512
|
+
const w = ChannelViews.words(pi);
|
|
3513
|
+
const session = await openSession(context, agent);
|
|
3514
|
+
const sessionId = session?.sessionId ?? (agent.sessionFile ? await service.openAgent(agent.id) : undefined);
|
|
3515
|
+
const { messages } = sessionId ? await pi.server.getMessages(sessionId) : { messages: [] };
|
|
3516
|
+
if (!messages.some((message) => message.role === "assistant")) {
|
|
3517
|
+
pi.ui.notify(ChannelWords.format(w.nothingToExport, { name: agent.name }), "info");
|
|
3518
|
+
return;
|
|
3519
|
+
}
|
|
3520
|
+
download(`${agent.name}.md`, ChannelsText.markdown(agent, messages, { user: w.you }));
|
|
3521
|
+
}
|
|
3522
|
+
AgentActions.exportChat = exportChat;
|
|
3523
|
+
function show(context, Dialog, agent) {
|
|
3524
|
+
context.pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(Dialog, {
|
|
3525
|
+
context,
|
|
3526
|
+
agent,
|
|
3527
|
+
onClose: close
|
|
3528
|
+
}));
|
|
3529
|
+
}
|
|
3530
|
+
function shareCard(context, agent) {
|
|
3531
|
+
show(context, CardDialog, agent);
|
|
3532
|
+
}
|
|
3533
|
+
AgentActions.shareCard = shareCard;
|
|
3534
|
+
function joinChannel(context, agent) {
|
|
3535
|
+
show(context, JoinDialog, agent);
|
|
3536
|
+
}
|
|
3537
|
+
AgentActions.joinChannel = joinChannel;
|
|
3538
|
+
async function profile(context, agent) {
|
|
3539
|
+
await ChannelViews.openAgent(context, agent.id);
|
|
3540
|
+
await context.pi.ui.showView(AGENT_INFO_VIEW);
|
|
3541
|
+
}
|
|
3542
|
+
AgentActions.profile = profile;
|
|
3543
|
+
function menu(context, agent, working) {
|
|
3544
|
+
const w = ChannelViews.words(context.pi);
|
|
3545
|
+
const edits = ChannelsUtil.may(context.service.state.team).agent(agent.id);
|
|
3546
|
+
const icon = (name) => ChannelViews.icon(context.pi, name);
|
|
3547
|
+
return [
|
|
3548
|
+
[
|
|
3549
|
+
{ key: "stop", label: w.stop, icon: icon("Square"), disabled: !working && !agent.sessionFile, run: run(context, () => stop(context, agent)) },
|
|
3550
|
+
...edits ? [{ key: "restart", label: w.restart, icon: icon("RotateCcw"), run: run(context, () => restart(context, agent)) }] : []
|
|
3551
|
+
],
|
|
3552
|
+
[
|
|
3553
|
+
...edits ? [{ key: "card", label: w.shareCard, icon: icon("Contact"), run: () => shareCard(context, agent) }] : [],
|
|
3554
|
+
...edits ? [{ key: "join", label: w.joinChannel, icon: icon("UserPlus"), run: () => joinChannel(context, agent) }] : [],
|
|
3555
|
+
{ key: "export", label: w.exportChat, icon: icon("Download"), run: run(context, () => exportChat(context, agent)) }
|
|
3556
|
+
]
|
|
3557
|
+
];
|
|
3558
|
+
}
|
|
3559
|
+
AgentActions.menu = menu;
|
|
3560
|
+
})(AgentActions ||= {});
|
|
3561
|
+
function AgentMenu({ context, agent, cwd, working }) {
|
|
3214
3562
|
const { pi, service } = context;
|
|
3215
|
-
const { team } = useChannels(service);
|
|
3216
|
-
const faces = useFaces(team);
|
|
3217
3563
|
const w = ChannelViews.words(pi);
|
|
3218
|
-
const
|
|
3219
|
-
const
|
|
3220
|
-
const
|
|
3221
|
-
const
|
|
3222
|
-
const
|
|
3223
|
-
const
|
|
3224
|
-
const
|
|
3225
|
-
const
|
|
3226
|
-
const
|
|
3564
|
+
const [dialog, setDialog] = React.useState();
|
|
3565
|
+
const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
|
|
3566
|
+
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
3567
|
+
const act = (action) => AgentActions.run(context, action);
|
|
3568
|
+
const stop = act(() => AgentActions.stop(context, agent));
|
|
3569
|
+
const restart = act(() => AgentActions.restart(context, agent));
|
|
3570
|
+
const copyCwd = act(() => AgentActions.copyCwd(context, cwd));
|
|
3571
|
+
const exportMarkdown = act(() => AgentActions.exportChat(context, agent));
|
|
3572
|
+
const remove = act(() => deleteAgent(context, agent));
|
|
3573
|
+
const pin = act(() => service.updateAgent(agent.id, { pinned: !agent.pinned }));
|
|
3574
|
+
const keep = act(async () => {
|
|
3575
|
+
await service.updateAgent(agent.id, { keep: true });
|
|
3576
|
+
pi.ui.notify(ChannelWords.format(w.kept, { name: agent.name }), "info");
|
|
3577
|
+
});
|
|
3578
|
+
const show = (next) => () => setDialog(next);
|
|
3579
|
+
const edits = ChannelsUtil.may(service.state.team).agent(agent.id);
|
|
3580
|
+
const item = (key, label, glyph, run, options = {}) => ({
|
|
3581
|
+
key,
|
|
3582
|
+
label,
|
|
3583
|
+
icon: icon(glyph),
|
|
3584
|
+
run,
|
|
3585
|
+
...options
|
|
3586
|
+
});
|
|
3587
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(MoreMenu, {
|
|
3588
|
+
pi,
|
|
3589
|
+
label: agent.name,
|
|
3590
|
+
items: () => [
|
|
3591
|
+
edits ? [
|
|
3592
|
+
...agent.temporary ? [item("keep", w.keep, "UserPlus", keep)] : [],
|
|
3593
|
+
item("pin", agent.pinned ? w.unpin : w.pin, agent.pinned ? "PinOff" : "Pin", pin)
|
|
3594
|
+
] : [],
|
|
3595
|
+
[
|
|
3596
|
+
item("stop", w.stop, "Square", stop, { disabled: !working && !agent.sessionFile }),
|
|
3597
|
+
...edits ? [item("restart", w.restart, "RotateCcw", restart)] : []
|
|
3598
|
+
],
|
|
3599
|
+
edits ? [
|
|
3600
|
+
item("settings", w.agentSettings, "SlidersHorizontal", show("settings")),
|
|
3601
|
+
item("rename", w.rename, "Pencil", show("rename")),
|
|
3602
|
+
item("role", w.editRole, "ScrollText", show("role")),
|
|
3603
|
+
item("move", w.moveTo, "FolderInput", show("move")),
|
|
3604
|
+
item("copy", w.copyCwd, "Copy", copyCwd)
|
|
3605
|
+
] : [],
|
|
3606
|
+
[
|
|
3607
|
+
...edits ? [item("card", w.shareCard, "Contact", show("card"))] : [],
|
|
3608
|
+
item("export", w.exportChat, "Download", exportMarkdown),
|
|
3609
|
+
...edits ? [item("join", w.joinChannel, "UserPlus", show("join"))] : []
|
|
3610
|
+
],
|
|
3611
|
+
edits ? [item("delete", w.deleteAgent, "Trash2", remove, { danger: true })] : []
|
|
3612
|
+
]
|
|
3613
|
+
}), dialog === "settings" && /* @__PURE__ */ React.createElement(AgentSettingsDialog, {
|
|
3614
|
+
context,
|
|
3615
|
+
agent,
|
|
3616
|
+
onClose: () => setDialog(undefined)
|
|
3617
|
+
}), dialog === "rename" && /* @__PURE__ */ React.createElement(RenameDialog, {
|
|
3618
|
+
context,
|
|
3619
|
+
agent,
|
|
3620
|
+
onClose: () => setDialog(undefined)
|
|
3621
|
+
}), dialog === "role" && /* @__PURE__ */ React.createElement(RoleDialog, {
|
|
3622
|
+
context,
|
|
3623
|
+
agent,
|
|
3624
|
+
onClose: () => setDialog(undefined)
|
|
3625
|
+
}), dialog === "join" && /* @__PURE__ */ React.createElement(JoinDialog, {
|
|
3626
|
+
context,
|
|
3627
|
+
agent,
|
|
3628
|
+
onClose: () => setDialog(undefined)
|
|
3629
|
+
}), dialog === "card" && /* @__PURE__ */ React.createElement(CardDialog, {
|
|
3630
|
+
context,
|
|
3631
|
+
agent,
|
|
3632
|
+
onClose: () => setDialog(undefined)
|
|
3633
|
+
}), dialog === "move" && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
|
|
3634
|
+
initial: cwd,
|
|
3635
|
+
onClose: () => setDialog(undefined),
|
|
3636
|
+
onPick: async (path) => {
|
|
3637
|
+
setDialog(undefined);
|
|
3638
|
+
if (path !== cwd) {
|
|
3639
|
+
await service.updateAgent(agent.id, { cwd: path }).catch(fail);
|
|
3640
|
+
context.sessions.delete(agent.id);
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
}));
|
|
3644
|
+
}
|
|
3645
|
+
function useSave(action, onClose) {
|
|
3227
3646
|
const [busy, setBusy] = React.useState(false);
|
|
3228
3647
|
const [error, setError] = React.useState();
|
|
3229
|
-
const
|
|
3230
|
-
const shown = team.agents.filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
|
|
3231
|
-
const full = picked.length >= MAX_MEMBERS;
|
|
3232
|
-
const toggle = (agent) => setPicked(picked.includes(agent.id) ? picked.filter((id) => id !== agent.id) : full ? picked : [...picked, agent.id]);
|
|
3233
|
-
const create = (event) => {
|
|
3648
|
+
const submit = (event) => {
|
|
3234
3649
|
event.preventDefault();
|
|
3235
3650
|
setBusy(true);
|
|
3236
3651
|
setError(undefined);
|
|
3237
|
-
|
|
3238
|
-
createShared(context, name.trim(), pickedFriends, picked).then(onClose, (failure) => {
|
|
3239
|
-
setBusy(false);
|
|
3240
|
-
setError(ChannelViews.message(failure));
|
|
3241
|
-
});
|
|
3242
|
-
return;
|
|
3243
|
-
}
|
|
3244
|
-
service.createChannel({ name, members: picked }).then((channel) => {
|
|
3245
|
-
onClose();
|
|
3246
|
-
context.showChannel(channel.id);
|
|
3247
|
-
}, (failure) => {
|
|
3652
|
+
action().then(onClose, (failure) => {
|
|
3248
3653
|
setBusy(false);
|
|
3249
3654
|
setError(ChannelViews.message(failure));
|
|
3250
3655
|
});
|
|
3251
3656
|
};
|
|
3252
|
-
return
|
|
3253
|
-
|
|
3657
|
+
return { busy, error, submit };
|
|
3658
|
+
}
|
|
3659
|
+
function AgentSettingsDialog({ context, agent, onClose }) {
|
|
3660
|
+
const { pi, service } = context;
|
|
3661
|
+
const w = ChannelViews.words(pi);
|
|
3662
|
+
const [name, setName] = React.useState(agent.name);
|
|
3663
|
+
const [model, setModel] = React.useState(agent.model ?? "");
|
|
3664
|
+
const [role, setRole] = React.useState(agent.role);
|
|
3665
|
+
const change = {
|
|
3666
|
+
...name.trim() !== agent.name ? { name } : {},
|
|
3667
|
+
...model !== (agent.model ?? "") ? { model } : {},
|
|
3668
|
+
...role.trim() !== agent.role ? { role } : {}
|
|
3669
|
+
};
|
|
3670
|
+
const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, change), onClose);
|
|
3671
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3672
|
+
title: `${w.agentSettings} · ${agent.name}`,
|
|
3254
3673
|
onClose
|
|
3255
3674
|
}, /* @__PURE__ */ React.createElement("form", {
|
|
3256
3675
|
className: "tac-dialog",
|
|
3257
|
-
onSubmit:
|
|
3676
|
+
onSubmit: submit
|
|
3258
3677
|
}, /* @__PURE__ */ React.createElement("label", {
|
|
3259
3678
|
className: "tac-dialog-label"
|
|
3260
3679
|
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
3261
3680
|
className: "tac-input tac-dialog-input",
|
|
3262
3681
|
value: name,
|
|
3263
|
-
|
|
3264
|
-
maxLength: 40,
|
|
3265
|
-
autoFocus: true,
|
|
3682
|
+
maxLength: 32,
|
|
3266
3683
|
onChange: (event) => setName(event.target.value)
|
|
3267
3684
|
})), /* @__PURE__ */ React.createElement("div", {
|
|
3685
|
+
className: "tac-dialog-field"
|
|
3686
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.model), /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
|
|
3687
|
+
cwd: agent.cwd,
|
|
3688
|
+
value: model,
|
|
3689
|
+
label: w.model,
|
|
3690
|
+
onChange: setModel
|
|
3691
|
+
})), /* @__PURE__ */ React.createElement("label", {
|
|
3268
3692
|
className: "tac-dialog-label"
|
|
3269
|
-
},
|
|
3270
|
-
className: "tac-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
}), /* @__PURE__ */ React.createElement("input", {
|
|
3276
|
-
value: query,
|
|
3277
|
-
placeholder: ChannelWords.format(w.searchAgents, { max: String(MAX_MEMBERS) }),
|
|
3278
|
-
"aria-label": w.search,
|
|
3279
|
-
onChange: (event) => setQuery(event.target.value)
|
|
3280
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
3281
|
-
className: "tac-pick-list"
|
|
3282
|
-
}, team.agents.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3283
|
-
compact: true,
|
|
3284
|
-
title: w.noAgents,
|
|
3285
|
-
hint: w.noAgentsHint
|
|
3286
|
-
}), team.agents.length > 0 && shown.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3287
|
-
compact: true,
|
|
3288
|
-
title: w.noMatch
|
|
3289
|
-
}), shown.map((agent) => {
|
|
3290
|
-
const on = picked.includes(agent.id);
|
|
3291
|
-
return /* @__PURE__ */ React.createElement("button", {
|
|
3292
|
-
key: agent.id,
|
|
3293
|
-
type: "button",
|
|
3294
|
-
"aria-pressed": on,
|
|
3295
|
-
disabled: !on && full,
|
|
3296
|
-
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
3297
|
-
onClick: () => toggle(agent)
|
|
3298
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
3299
|
-
className: "tac-check"
|
|
3300
|
-
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
3301
|
-
size: 13,
|
|
3302
|
-
strokeWidth: 3
|
|
3303
|
-
})), /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
3304
|
-
agent,
|
|
3305
|
-
faces,
|
|
3306
|
-
size: 30
|
|
3307
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
3308
|
-
className: "tac-pick-text"
|
|
3309
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
3310
|
-
className: "tac-pick-name"
|
|
3311
|
-
}, agent.name, picked[0] === agent.id && /* @__PURE__ */ React.createElement("span", {
|
|
3312
|
-
className: "tac-msg-lead"
|
|
3313
|
-
}, w.lead)), /* @__PURE__ */ React.createElement("span", {
|
|
3314
|
-
className: "tac-pick-role"
|
|
3315
|
-
}, agent.role.split(`
|
|
3316
|
-
`)[0])));
|
|
3317
|
-
})), friends.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
3318
|
-
className: "tac-dialog-label"
|
|
3319
|
-
}, /* @__PURE__ */ React.createElement("span", null, w.addFriends), shared && /* @__PURE__ */ React.createElement("span", {
|
|
3320
|
-
className: "tac-dialog-count"
|
|
3321
|
-
}, pickedFriends.length)), /* @__PURE__ */ React.createElement("div", {
|
|
3322
|
-
className: "tac-pick-list"
|
|
3323
|
-
}, friends.map((friend) => {
|
|
3324
|
-
const on = pickedFriends.includes(friend.id);
|
|
3325
|
-
return /* @__PURE__ */ React.createElement("button", {
|
|
3326
|
-
key: friend.id,
|
|
3327
|
-
type: "button",
|
|
3328
|
-
"aria-pressed": on,
|
|
3329
|
-
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
3330
|
-
onClick: () => toggleFriend(friend)
|
|
3331
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
3332
|
-
className: "tac-check"
|
|
3333
|
-
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
3334
|
-
size: 13,
|
|
3335
|
-
strokeWidth: 3
|
|
3336
|
-
})), pi.ui.Face ? /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
3337
|
-
seed: friend.id,
|
|
3338
|
-
size: 30,
|
|
3339
|
-
look: friend.look
|
|
3340
|
-
}) : /* @__PURE__ */ React.createElement("span", {
|
|
3341
|
-
className: "tac-pick-face"
|
|
3342
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
3343
|
-
className: "tac-pick-text"
|
|
3344
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
3345
|
-
className: "tac-pick-name"
|
|
3346
|
-
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
3347
|
-
className: "tac-pick-role"
|
|
3348
|
-
}, w.friend)));
|
|
3349
|
-
}))), (picked.length > 0 || shared) && /* @__PURE__ */ React.createElement("div", {
|
|
3693
|
+
}, w.editRole, /* @__PURE__ */ React.createElement("textarea", {
|
|
3694
|
+
className: "tac-input tac-settings-role",
|
|
3695
|
+
value: role,
|
|
3696
|
+
placeholder: w.rolePlaceholder,
|
|
3697
|
+
onChange: (event) => setRole(event.target.value)
|
|
3698
|
+
})), /* @__PURE__ */ React.createElement("p", {
|
|
3350
3699
|
className: "tac-dialog-note"
|
|
3351
|
-
},
|
|
3352
|
-
className: "tac-
|
|
3700
|
+
}, w.agentSettingsHint), error && /* @__PURE__ */ React.createElement("div", {
|
|
3701
|
+
className: "tac-error"
|
|
3353
3702
|
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
3354
3703
|
className: "tac-dialog-actions"
|
|
3355
3704
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
3356
3705
|
type: "submit",
|
|
3357
3706
|
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
3358
|
-
disabled: busy || !name.trim() ||
|
|
3359
|
-
}, w.
|
|
3707
|
+
disabled: busy || !name.trim() || !role.trim() || Object.keys(change).length === 0
|
|
3708
|
+
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
3360
3709
|
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
3361
3710
|
})))));
|
|
3362
3711
|
}
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
(
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3712
|
+
function RenameDialog({ context, agent, onClose }) {
|
|
3713
|
+
const { pi, service } = context;
|
|
3714
|
+
const w = ChannelViews.words(pi);
|
|
3715
|
+
const [name, setName] = React.useState(agent.name);
|
|
3716
|
+
const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, { name }), onClose);
|
|
3717
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3718
|
+
title: w.rename,
|
|
3719
|
+
onClose
|
|
3720
|
+
}, /* @__PURE__ */ React.createElement("form", {
|
|
3721
|
+
className: "tac-dialog",
|
|
3722
|
+
onSubmit: submit
|
|
3723
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
3724
|
+
className: "tac-dialog-label"
|
|
3725
|
+
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
3726
|
+
className: "tac-input tac-dialog-input",
|
|
3727
|
+
value: name,
|
|
3728
|
+
maxLength: 32,
|
|
3729
|
+
autoFocus: true,
|
|
3730
|
+
onChange: (event) => setName(event.target.value)
|
|
3731
|
+
})), error && /* @__PURE__ */ React.createElement("div", {
|
|
3732
|
+
className: "tac-error"
|
|
3733
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
3734
|
+
className: "tac-dialog-actions"
|
|
3735
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
3736
|
+
type: "submit",
|
|
3737
|
+
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
3738
|
+
disabled: busy || !name.trim() || name.trim() === agent.name
|
|
3739
|
+
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
3740
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
3741
|
+
})))));
|
|
3742
|
+
}
|
|
3743
|
+
function RoleDialog({ context, agent, onClose }) {
|
|
3744
|
+
const { pi, service } = context;
|
|
3745
|
+
const w = ChannelViews.words(pi);
|
|
3746
|
+
const [role, setRole] = React.useState(agent.role);
|
|
3747
|
+
const { busy, error, submit } = useSave(() => service.updateAgent(agent.id, { role }), onClose);
|
|
3748
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3749
|
+
title: `${w.editRole} · ${agent.name}`,
|
|
3750
|
+
onClose
|
|
3751
|
+
}, /* @__PURE__ */ React.createElement("form", {
|
|
3752
|
+
className: "tac-dialog",
|
|
3753
|
+
onSubmit: submit
|
|
3754
|
+
}, /* @__PURE__ */ React.createElement("p", {
|
|
3755
|
+
className: "tac-dialog-note"
|
|
3756
|
+
}, w.roleHint), /* @__PURE__ */ React.createElement("textarea", {
|
|
3757
|
+
className: "tac-input tac-role-input",
|
|
3758
|
+
value: role,
|
|
3759
|
+
placeholder: w.rolePlaceholder,
|
|
3760
|
+
"aria-label": w.editRole,
|
|
3761
|
+
autoFocus: true,
|
|
3762
|
+
onChange: (event) => setRole(event.target.value)
|
|
3763
|
+
}), error && /* @__PURE__ */ React.createElement("div", {
|
|
3764
|
+
className: "tac-error"
|
|
3765
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
3766
|
+
className: "tac-dialog-actions"
|
|
3767
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
3768
|
+
type: "submit",
|
|
3769
|
+
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
3770
|
+
disabled: busy || !role.trim() || role.trim() === agent.role
|
|
3771
|
+
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
3772
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
3773
|
+
})))));
|
|
3774
|
+
}
|
|
3775
|
+
function JoinDialog({ context, agent, onClose }) {
|
|
3776
|
+
const { pi, service } = context;
|
|
3777
|
+
const { team } = useChannels(service);
|
|
3778
|
+
const w = ChannelViews.words(pi);
|
|
3779
|
+
const Hash = ChannelViews.icon(pi, "Hash");
|
|
3780
|
+
const [error, setError] = React.useState();
|
|
3781
|
+
const open = team.channels.filter((channel) => !channel.members.includes(agent.id));
|
|
3782
|
+
const join = (channelId, name) => {
|
|
3783
|
+
service.addMembers(channelId, [agent.id]).then(() => {
|
|
3784
|
+
onClose();
|
|
3785
|
+
pi.ui.notify(ChannelWords.format(w.joined, { name: agent.name, channel: name }), "info");
|
|
3786
|
+
}, (failure) => setError(ChannelViews.message(failure)));
|
|
3384
3787
|
};
|
|
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
|
-
|
|
3788
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
3789
|
+
title: `${w.joinChannel} · ${agent.name}`,
|
|
3790
|
+
onClose
|
|
3791
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3792
|
+
className: "tac-dialog"
|
|
3793
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3794
|
+
className: "tac-pick-list"
|
|
3795
|
+
}, open.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3796
|
+
compact: true,
|
|
3797
|
+
title: w.noChannelToJoin
|
|
3798
|
+
}), open.map((channel) => /* @__PURE__ */ React.createElement("button", {
|
|
3799
|
+
key: channel.id,
|
|
3800
|
+
type: "button",
|
|
3801
|
+
className: "tac-pick",
|
|
3802
|
+
disabled: channel.members.length >= MAX_MEMBERS,
|
|
3803
|
+
onClick: () => join(channel.id, channel.name)
|
|
3804
|
+
}, /* @__PURE__ */ React.createElement(Hash, {
|
|
3805
|
+
size: 16
|
|
3806
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
3807
|
+
className: "tac-pick-text"
|
|
3808
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3809
|
+
className: "tac-pick-name"
|
|
3810
|
+
}, channel.name), /* @__PURE__ */ React.createElement("span", {
|
|
3811
|
+
className: "tac-pick-role"
|
|
3812
|
+
}, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(channel.members.length) })))))), error && /* @__PURE__ */ React.createElement("div", {
|
|
3813
|
+
className: "tac-error"
|
|
3814
|
+
}, error)));
|
|
3815
|
+
}
|
|
3816
|
+
function useShownAgent(context) {
|
|
3817
|
+
const { pi, service } = context;
|
|
3818
|
+
const { team } = useChannels(service);
|
|
3819
|
+
const sessionId = pi.ui.useSessionId();
|
|
3820
|
+
const sessions = pi.ui.useSessions();
|
|
3821
|
+
const channelPage = !!pi.ui.useView(CHANNEL_PAGE)?.shown;
|
|
3822
|
+
if (channelPage || !sessionId) {
|
|
3823
|
+
return;
|
|
3410
3824
|
}
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3825
|
+
const file = sessions.find((session) => session.sessionId === sessionId)?.sessionFile;
|
|
3826
|
+
return team.agents.find((agent) => !!file && agent.sessionFile === file || context.sessions.get(agent.id) === sessionId);
|
|
3827
|
+
}
|
|
3828
|
+
function AgentInfoView({ context }) {
|
|
3829
|
+
const { pi, service } = context;
|
|
3830
|
+
const { team, working, loaded } = useChannels(service);
|
|
3831
|
+
const w = ChannelViews.words(pi);
|
|
3832
|
+
const [dialog, setDialog] = React.useState();
|
|
3833
|
+
const serverCwd = useServerCwd(pi);
|
|
3834
|
+
const faces = useFaces(team);
|
|
3835
|
+
const agent = useShownAgent(context);
|
|
3836
|
+
if (!agent) {
|
|
3837
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
3838
|
+
className: "tac-view tac-members"
|
|
3839
|
+
}, loaded && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
3840
|
+
title: w.noAgentOpen
|
|
3841
|
+
}));
|
|
3414
3842
|
}
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
index = end < 0 ? lines.length : end;
|
|
3843
|
+
const edits = ChannelsUtil.may(team).agent(agent.id);
|
|
3844
|
+
const busy = Object.values(working).some((ids) => ids.includes(agent.id));
|
|
3845
|
+
const cwd = agent.cwd ?? serverCwd ?? "";
|
|
3846
|
+
const Chevron = ChannelViews.icon(pi, "ChevronRight");
|
|
3847
|
+
const Trash = ChannelViews.icon(pi, "Trash2");
|
|
3848
|
+
const HostTag = pi.ui.HostTag;
|
|
3849
|
+
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
3850
|
+
const act = (action2) => AgentActions.run(context, action2);
|
|
3851
|
+
const rename = act(async () => {
|
|
3852
|
+
const name = await pi.ui.input(w.rename, w.name, { value: agent.name });
|
|
3853
|
+
if (name !== undefined && name.trim() && name.trim() !== agent.name) {
|
|
3854
|
+
await service.updateAgent(agent.id, { name });
|
|
3428
3855
|
}
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
"zh-TW": `(交接自「${title}」)`,
|
|
3457
|
-
"en-US": `(Handed over from “${title}”)`,
|
|
3458
|
-
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
3459
|
-
})}
|
|
3460
|
-
|
|
3461
|
-
${brief.trim()}`;
|
|
3462
|
-
}
|
|
3463
|
-
HandOff.channelText = channelText;
|
|
3464
|
-
function serverLanguage(env = typeof process === "undefined" ? {} : process.env) {
|
|
3465
|
-
return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
|
|
3466
|
-
}
|
|
3467
|
-
HandOff.serverLanguage = serverLanguage;
|
|
3468
|
-
function result(target) {
|
|
3469
|
-
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.`;
|
|
3470
|
-
}
|
|
3471
|
-
HandOff.result = result;
|
|
3472
|
-
})(HandOff ||= {});
|
|
3473
|
-
|
|
3474
|
-
// web-src/handoff-view.tsx
|
|
3475
|
-
var HandOffViewUtil;
|
|
3476
|
-
((HandOffViewUtil) => {
|
|
3477
|
-
function members(team, target) {
|
|
3478
|
-
if (target.kind === "agent") {
|
|
3479
|
-
const agent = team.agents.find((candidate) => candidate.id === target.id);
|
|
3480
|
-
return agent ? [agent] : [];
|
|
3481
|
-
}
|
|
3482
|
-
const channel = team.channels.find((candidate) => candidate.id === target.id);
|
|
3483
|
-
return channel ? membersOf(team, channel) : [];
|
|
3484
|
-
}
|
|
3485
|
-
HandOffViewUtil.members = members;
|
|
3486
|
-
})(HandOffViewUtil ||= {});
|
|
3487
|
-
function useTeam(context) {
|
|
3488
|
-
return React.useSyncExternalStore((listener) => context.service.subscribe(listener), () => context.service.state).team;
|
|
3489
|
-
}
|
|
3490
|
-
function HandOffCard({ context, message }) {
|
|
3491
|
-
const card = message.details;
|
|
3492
|
-
const team = useTeam(context);
|
|
3493
|
-
const faces = useFaces(team);
|
|
3494
|
-
if (!card?.target) {
|
|
3495
|
-
return null;
|
|
3496
|
-
}
|
|
3497
|
-
const w = ChannelViews.words(context.pi);
|
|
3498
|
-
const members = HandOffViewUtil.members(team, card.target);
|
|
3499
|
-
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);
|
|
3856
|
+
});
|
|
3857
|
+
const row = (label, value, edit) => edit && edits ? /* @__PURE__ */ React.createElement("button", {
|
|
3858
|
+
type: "button",
|
|
3859
|
+
className: "tac-setting",
|
|
3860
|
+
onClick: edit
|
|
3861
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3862
|
+
className: "tac-setting-label"
|
|
3863
|
+
}, label), /* @__PURE__ */ React.createElement("span", {
|
|
3864
|
+
className: "tac-setting-value"
|
|
3865
|
+
}, value), /* @__PURE__ */ React.createElement(Chevron, {
|
|
3866
|
+
size: 15
|
|
3867
|
+
})) : /* @__PURE__ */ React.createElement("div", {
|
|
3868
|
+
className: "tac-setting"
|
|
3869
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3870
|
+
className: "tac-setting-label"
|
|
3871
|
+
}, label), /* @__PURE__ */ React.createElement("span", {
|
|
3872
|
+
className: "tac-setting-value"
|
|
3873
|
+
}, value));
|
|
3874
|
+
const action = (label, run) => /* @__PURE__ */ React.createElement("button", {
|
|
3875
|
+
type: "button",
|
|
3876
|
+
className: "tac-setting",
|
|
3877
|
+
onClick: run
|
|
3878
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3879
|
+
className: "tac-setting-label"
|
|
3880
|
+
}, label), /* @__PURE__ */ React.createElement(Chevron, {
|
|
3881
|
+
size: 15
|
|
3882
|
+
}));
|
|
3500
3883
|
return /* @__PURE__ */ React.createElement("div", {
|
|
3501
|
-
className: "tac-
|
|
3884
|
+
className: "tac-view tac-members"
|
|
3502
3885
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
3503
|
-
className: "tac-
|
|
3504
|
-
},
|
|
3505
|
-
members
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3886
|
+
className: "tac-members-scroll"
|
|
3887
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
3888
|
+
className: "tac-members-top"
|
|
3889
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
3890
|
+
face: faces.get(agent.id) ?? agent.face ?? 0,
|
|
3891
|
+
size: 44,
|
|
3892
|
+
working: busy
|
|
3509
3893
|
}), /* @__PURE__ */ React.createElement("span", {
|
|
3510
|
-
className: "tac-
|
|
3511
|
-
},
|
|
3894
|
+
className: "tac-members-title"
|
|
3895
|
+
}, /* @__PURE__ */ React.createElement("strong", null, agent.name), /* @__PURE__ */ React.createElement("span", null, agent.role.split(`
|
|
3896
|
+
`)[0] || w.agentTag))), /* @__PURE__ */ React.createElement("div", {
|
|
3897
|
+
className: "tac-members-sep"
|
|
3898
|
+
}), row(w.name, agent.name, rename), /* @__PURE__ */ React.createElement("div", {
|
|
3899
|
+
className: "tac-setting tac-setting-model"
|
|
3900
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
3901
|
+
className: "tac-setting-label"
|
|
3902
|
+
}, w.model), edits ? /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
|
|
3903
|
+
cwd: agent.cwd,
|
|
3904
|
+
value: agent.model ?? "",
|
|
3905
|
+
label: w.model,
|
|
3906
|
+
onChange: (model) => void service.updateAgent(agent.id, { model }).catch(fail)
|
|
3907
|
+
}) : /* @__PURE__ */ React.createElement("span", {
|
|
3908
|
+
className: "tac-setting-value"
|
|
3909
|
+
}, agent.model || "—")), row(w.editRole, agent.role.split(`
|
|
3910
|
+
`)[0], () => setDialog("role")), row(w.workDir, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(HostTag, {
|
|
3911
|
+
location: cwd
|
|
3912
|
+
}), cwd && SidebarUtil.folder(cwd)), () => setDialog("move")), /* @__PURE__ */ React.createElement("div", {
|
|
3913
|
+
className: "tac-members-sep"
|
|
3914
|
+
}), 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", {
|
|
3915
|
+
className: "tac-members-foot"
|
|
3916
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
3512
3917
|
type: "button",
|
|
3513
|
-
className: "tac-link",
|
|
3514
|
-
onClick:
|
|
3515
|
-
},
|
|
3516
|
-
|
|
3517
|
-
},
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
(
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
let node2 = icons.get(key);
|
|
3531
|
-
if (!node2) {
|
|
3532
|
-
const Face2 = () => {
|
|
3533
|
-
const team = useTeam(context);
|
|
3534
|
-
const faces = useFaces(team);
|
|
3535
|
-
const members = HandOffViewUtil.members(team, target);
|
|
3536
|
-
return members.length ? /* @__PURE__ */ React.createElement(RoomFace, {
|
|
3537
|
-
members,
|
|
3538
|
-
faces,
|
|
3539
|
-
size: 16,
|
|
3540
|
-
working: []
|
|
3541
|
-
}) : null;
|
|
3542
|
-
};
|
|
3543
|
-
node2 = /* @__PURE__ */ React.createElement(Face2, null);
|
|
3544
|
-
icons.set(key, node2);
|
|
3918
|
+
className: "tac-link tac-danger",
|
|
3919
|
+
onClick: act(() => deleteAgent(context, agent))
|
|
3920
|
+
}, /* @__PURE__ */ React.createElement(Trash, {
|
|
3921
|
+
size: 14
|
|
3922
|
+
}), w.deleteAgentLong)), dialog === "role" && /* @__PURE__ */ React.createElement(RoleDialog, {
|
|
3923
|
+
context,
|
|
3924
|
+
agent,
|
|
3925
|
+
onClose: () => setDialog(undefined)
|
|
3926
|
+
}), dialog === "move" && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
|
|
3927
|
+
initial: cwd,
|
|
3928
|
+
onClose: () => setDialog(undefined),
|
|
3929
|
+
onPick: async (path) => {
|
|
3930
|
+
setDialog(undefined);
|
|
3931
|
+
if (path !== cwd) {
|
|
3932
|
+
await service.updateAgent(agent.id, { cwd: path }).catch(fail);
|
|
3933
|
+
context.sessions.delete(agent.id);
|
|
3934
|
+
}
|
|
3545
3935
|
}
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
function composerAddon(context) {
|
|
3549
|
-
const icons = new Map;
|
|
3550
|
-
const send = (conversation, to) => void context.pi.server.prompt(conversation.sessionId, {
|
|
3551
|
-
clientMessageId: ChannelsUtil.newId("handoff-ask"),
|
|
3552
|
-
message: HandOff.ask(context.pi.ui.language, to),
|
|
3553
|
-
streamingBehavior: "followUp"
|
|
3554
|
-
}).catch((error) => context.pi.ui.notify(ChannelViews.message(error), "error"));
|
|
3555
|
-
return {
|
|
3556
|
-
actions: (conversation) => {
|
|
3557
|
-
const { team } = context.service.state;
|
|
3558
|
-
if (conversation.group === NAME || team.agents.length === 0 && team.channels.length === 0) {
|
|
3559
|
-
return [];
|
|
3560
|
-
}
|
|
3561
|
-
const w = ChannelViews.words(context.pi);
|
|
3562
|
-
const Forward = ChannelViews.icon(context.pi, "Forward");
|
|
3563
|
-
const agents = team.agents.filter((agent) => !agent.temporary).map((agent) => ({
|
|
3564
|
-
key: `handoff:agent:${agent.id}`,
|
|
3565
|
-
label: agent.name,
|
|
3566
|
-
detail: agent.role.split(`
|
|
3567
|
-
`)[0],
|
|
3568
|
-
group: w.agents,
|
|
3569
|
-
icon: icon(context, { kind: "agent", id: agent.id }, icons),
|
|
3570
|
-
run: () => send(conversation, `@${agent.name}`)
|
|
3571
|
-
}));
|
|
3572
|
-
const channels = team.channels.map((channel) => ({
|
|
3573
|
-
key: `handoff:channel:${channel.id}`,
|
|
3574
|
-
label: `#${channel.name}`,
|
|
3575
|
-
detail: channel.topic,
|
|
3576
|
-
group: w.channels,
|
|
3577
|
-
icon: icon(context, { kind: "channel", id: channel.id }, icons),
|
|
3578
|
-
run: () => send(conversation, `#${channel.name}`)
|
|
3579
|
-
}));
|
|
3580
|
-
return [{ key: "handoff", label: w.handOff, detail: w.handOffDetail, icon: /* @__PURE__ */ React.createElement(Forward, {
|
|
3581
|
-
size: 16
|
|
3582
|
-
}), items: [...agents, ...channels] }];
|
|
3583
|
-
},
|
|
3584
|
-
subscribe: (listener) => context.service.subscribe(listener)
|
|
3585
|
-
};
|
|
3586
|
-
}
|
|
3587
|
-
HandOffView.composerAddon = composerAddon;
|
|
3588
|
-
})(HandOffView ||= {});
|
|
3936
|
+
}));
|
|
3937
|
+
}
|
|
3589
3938
|
|
|
3590
|
-
// web-src/
|
|
3591
|
-
var
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
const NEW = 0.35;
|
|
3598
|
-
const CHANGES = new Set(["edit", "write", "delete", "move"]);
|
|
3599
|
-
function scale(watchedAt, pages, now) {
|
|
3600
|
-
if (watchedAt !== undefined && now - watchedAt < 2 * WATCH_MS) {
|
|
3601
|
-
return 2;
|
|
3939
|
+
// web-src/channel-seen.ts
|
|
3940
|
+
var CHANNELS_SEEN_KEY = "ui.channelsSeen";
|
|
3941
|
+
var ChannelSeenUtil;
|
|
3942
|
+
((ChannelSeenUtil) => {
|
|
3943
|
+
function parse(value) {
|
|
3944
|
+
if (!value || typeof value !== "object") {
|
|
3945
|
+
return;
|
|
3602
3946
|
}
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
ChannelRounds.scale = scale;
|
|
3606
|
-
function idle(said, progress) {
|
|
3607
|
-
const last = said.at(-1);
|
|
3608
|
-
if (!last) {
|
|
3947
|
+
const { since, at, unread } = value;
|
|
3948
|
+
if (typeof since !== "number" || !at || typeof at !== "object") {
|
|
3609
3949
|
return;
|
|
3610
3950
|
}
|
|
3611
|
-
const
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3951
|
+
const marks = unread && typeof unread === "object" ? times(unread) : {};
|
|
3952
|
+
return Object.keys(marks).length ? { since, at: times(at), unread: marks } : { since, at: times(at) };
|
|
3953
|
+
}
|
|
3954
|
+
ChannelSeenUtil.parse = parse;
|
|
3955
|
+
function merge(a, b) {
|
|
3956
|
+
const since = Math.max(a.since, b.since);
|
|
3957
|
+
const at = later(a.at, b.at);
|
|
3958
|
+
const unread = stillUnread(later(a.unread ?? {}, b.unread ?? {}), at, since);
|
|
3959
|
+
for (const [id, time] of Object.entries(at)) {
|
|
3960
|
+
if (time <= since) {
|
|
3961
|
+
delete at[id];
|
|
3962
|
+
}
|
|
3615
3963
|
}
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
return "agree";
|
|
3964
|
+
if (since === a.since && same(at, a.at) && same(unread ?? {}, a.unread ?? {})) {
|
|
3965
|
+
return a;
|
|
3619
3966
|
}
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3967
|
+
return unread ? { since, at, unread } : { since, at };
|
|
3968
|
+
}
|
|
3969
|
+
ChannelSeenUtil.merge = merge;
|
|
3970
|
+
function lastAt(messages) {
|
|
3971
|
+
const last = messages?.filter((message) => message.author !== SYSTEM).at(-1);
|
|
3972
|
+
return last && last.author !== USER ? last.at : undefined;
|
|
3973
|
+
}
|
|
3974
|
+
ChannelSeenUtil.lastAt = lastAt;
|
|
3975
|
+
function unseen(seen, channelId, messages, working) {
|
|
3976
|
+
if (!seen || seen.since <= 0 || working) {
|
|
3977
|
+
return false;
|
|
3978
|
+
}
|
|
3979
|
+
const since = seen.at[channelId] ?? seen.since;
|
|
3980
|
+
const said = lastAt(messages);
|
|
3981
|
+
return said !== undefined && said > since || (seen.unread?.[channelId] ?? 0) > since;
|
|
3982
|
+
}
|
|
3983
|
+
ChannelSeenUtil.unseen = unseen;
|
|
3984
|
+
function look(seen, channelId, at) {
|
|
3985
|
+
const before = seen.at[channelId] ?? seen.since;
|
|
3986
|
+
const mark = seen.unread?.[channelId] ?? 0;
|
|
3987
|
+
if (before >= at && mark <= before) {
|
|
3625
3988
|
return;
|
|
3626
3989
|
}
|
|
3627
|
-
const
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3990
|
+
const times2 = { ...seen.at, [channelId]: Math.max(at, mark) };
|
|
3991
|
+
const unread = stillUnread(seen.unread ?? {}, times2, seen.since);
|
|
3992
|
+
return unread ? { since: seen.since, at: times2, unread } : { since: seen.since, at: times2 };
|
|
3993
|
+
}
|
|
3994
|
+
ChannelSeenUtil.look = look;
|
|
3995
|
+
function markUnread(seen, channelId, now) {
|
|
3996
|
+
const mark = Math.max(now, seen.at[channelId] ?? seen.since) + 1;
|
|
3997
|
+
return { ...seen, unread: { ...seen.unread, [channelId]: mark } };
|
|
3998
|
+
}
|
|
3999
|
+
ChannelSeenUtil.markUnread = markUnread;
|
|
4000
|
+
function times(record) {
|
|
4001
|
+
return Object.fromEntries(Object.entries(record).filter((entry) => typeof entry[1] === "number"));
|
|
4002
|
+
}
|
|
4003
|
+
function later(a, b) {
|
|
4004
|
+
const out = { ...a };
|
|
4005
|
+
for (const [id, time] of Object.entries(b)) {
|
|
4006
|
+
if (time > (out[id] ?? 0)) {
|
|
4007
|
+
out[id] = time;
|
|
3635
4008
|
}
|
|
3636
4009
|
}
|
|
3637
|
-
return
|
|
4010
|
+
return out;
|
|
3638
4011
|
}
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
4012
|
+
function stillUnread(unread, at, since) {
|
|
4013
|
+
const kept = Object.entries(unread).filter(([id, mark]) => mark > (at[id] ?? since));
|
|
4014
|
+
return kept.length ? Object.fromEntries(kept) : undefined;
|
|
3643
4015
|
}
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
const pick = (key) => LIMIT_CHOICES[key].includes(given[key]) ? given[key] : DEFAULT_LIMITS[key];
|
|
3648
|
-
return { answer: pick("answer"), channelDay: pick("channelDay"), allDay: pick("allDay") };
|
|
4016
|
+
function same(a, b) {
|
|
4017
|
+
const left = Object.entries(a);
|
|
4018
|
+
return left.length === Object.keys(b).length && left.every(([id, time]) => b[id] === time);
|
|
3649
4019
|
}
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
4020
|
+
})(ChannelSeenUtil ||= {});
|
|
4021
|
+
|
|
4022
|
+
class ChannelSeenBook {
|
|
4023
|
+
storage;
|
|
4024
|
+
current;
|
|
4025
|
+
listeners = new Set;
|
|
4026
|
+
constructor(storage) {
|
|
4027
|
+
this.storage = storage;
|
|
3654
4028
|
}
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
const current = today(stored, now);
|
|
3658
|
-
return { ...current, total: current.total + tokens, channels: { ...current.channels, [channelId]: (current.channels[channelId] ?? 0) + tokens } };
|
|
4029
|
+
get state() {
|
|
4030
|
+
return this.current;
|
|
3659
4031
|
}
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
4032
|
+
subscribe(listener) {
|
|
4033
|
+
this.listeners.add(listener);
|
|
4034
|
+
return () => this.listeners.delete(listener);
|
|
4035
|
+
}
|
|
4036
|
+
start() {
|
|
4037
|
+
this.keep();
|
|
4038
|
+
return this.storage.onChange((keys) => keys.includes(CHANNELS_SEEN_KEY) && void this.keep());
|
|
4039
|
+
}
|
|
4040
|
+
unseen(channelId, messages, working) {
|
|
4041
|
+
return ChannelSeenUtil.unseen(this.current, channelId, messages, working);
|
|
4042
|
+
}
|
|
4043
|
+
look(channelId, at) {
|
|
4044
|
+
const next = this.current && ChannelSeenUtil.look(this.current, channelId, at);
|
|
4045
|
+
if (next) {
|
|
4046
|
+
this.put(next);
|
|
4047
|
+
this.keep();
|
|
3664
4048
|
}
|
|
3665
|
-
|
|
3666
|
-
|
|
4049
|
+
}
|
|
4050
|
+
mark(channelId, unread, lastAt) {
|
|
4051
|
+
if (!this.current) {
|
|
4052
|
+
return;
|
|
3667
4053
|
}
|
|
3668
|
-
if (
|
|
3669
|
-
|
|
4054
|
+
if (!unread) {
|
|
4055
|
+
this.look(channelId, Math.max(Date.now(), lastAt ?? 0));
|
|
4056
|
+
return;
|
|
3670
4057
|
}
|
|
3671
|
-
|
|
4058
|
+
this.put(ChannelSeenUtil.markUnread(this.current, channelId, Date.now()));
|
|
4059
|
+
this.keep();
|
|
3672
4060
|
}
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
for (const
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
4061
|
+
put(next) {
|
|
4062
|
+
this.current = next;
|
|
4063
|
+
for (const listener of this.listeners) {
|
|
4064
|
+
listener();
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
4067
|
+
async keep() {
|
|
4068
|
+
try {
|
|
4069
|
+
const kept = ChannelSeenUtil.parse(await this.storage.get(CHANNELS_SEEN_KEY));
|
|
4070
|
+
const local = this.current;
|
|
4071
|
+
const next = kept ? local ? ChannelSeenUtil.merge(local, kept) : kept : local ?? { since: Date.now(), at: {} };
|
|
4072
|
+
if (next !== local) {
|
|
4073
|
+
this.put(next);
|
|
3679
4074
|
}
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
continue;
|
|
3683
|
-
}
|
|
3684
|
-
if (CHANGES.has(String(part.name)) || part.name === "agent_tool" && CHANGES.has(String(part.arguments?.kind))) {
|
|
3685
|
-
return true;
|
|
3686
|
-
}
|
|
4075
|
+
if (!kept || ChannelSeenUtil.merge(kept, next) !== kept) {
|
|
4076
|
+
await this.storage.set(CHANNELS_SEEN_KEY, next);
|
|
3687
4077
|
}
|
|
4078
|
+
} catch {}
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
|
|
4082
|
+
// web-src/channels.ts
|
|
4083
|
+
class ChannelsClient {
|
|
4084
|
+
storage;
|
|
4085
|
+
send;
|
|
4086
|
+
current = { team: ChannelsUtil.emptyTeam(), messages: {}, working: {}, answered: {}, loaded: false, deleting: [] };
|
|
4087
|
+
listeners = new Set;
|
|
4088
|
+
focusListeners = new Set;
|
|
4089
|
+
loading;
|
|
4090
|
+
pictures = new Map;
|
|
4091
|
+
unlisten;
|
|
4092
|
+
constructor(storage, send) {
|
|
4093
|
+
this.storage = storage;
|
|
4094
|
+
this.send = send;
|
|
4095
|
+
this.unlisten = storage.onChange((keys) => void this.changed(keys));
|
|
4096
|
+
}
|
|
4097
|
+
get state() {
|
|
4098
|
+
return this.current;
|
|
4099
|
+
}
|
|
4100
|
+
subscribe(listener) {
|
|
4101
|
+
this.listeners.add(listener);
|
|
4102
|
+
return () => this.listeners.delete(listener);
|
|
4103
|
+
}
|
|
4104
|
+
onFocus(listener) {
|
|
4105
|
+
this.focusListeners.add(listener);
|
|
4106
|
+
return () => this.focusListeners.delete(listener);
|
|
4107
|
+
}
|
|
4108
|
+
dispose() {
|
|
4109
|
+
this.unlisten();
|
|
4110
|
+
}
|
|
4111
|
+
load(again = false) {
|
|
4112
|
+
if (!this.loading || again) {
|
|
4113
|
+
this.loading = Promise.all([
|
|
4114
|
+
this.storage.get(Keys.TEAM),
|
|
4115
|
+
this.storage.get(Keys.WORKING),
|
|
4116
|
+
this.storage.get(Keys.ANSWERED)
|
|
4117
|
+
]).then(([team, working, answered]) => this.update({ team: team ?? ChannelsUtil.emptyTeam(), working: working ?? {}, answered: answered ?? {}, loaded: true }));
|
|
3688
4118
|
}
|
|
3689
|
-
return
|
|
4119
|
+
return this.loading;
|
|
3690
4120
|
}
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
4121
|
+
async messages(channelId, again = false) {
|
|
4122
|
+
const known = this.current.messages[channelId];
|
|
4123
|
+
if (known && !again) {
|
|
4124
|
+
return known;
|
|
4125
|
+
}
|
|
4126
|
+
const messages = await this.storage.get(Keys.messages(channelId)) ?? [];
|
|
4127
|
+
this.update({ messages: { ...this.current.messages, [channelId]: messages } });
|
|
4128
|
+
return messages;
|
|
3694
4129
|
}
|
|
3695
|
-
|
|
3696
|
-
const
|
|
3697
|
-
|
|
4130
|
+
async createAgent(input) {
|
|
4131
|
+
const agent = await this.send({ kind: "createAgent", ...input });
|
|
4132
|
+
await this.load(true);
|
|
4133
|
+
return agent;
|
|
3698
4134
|
}
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
4135
|
+
async createChannel(input) {
|
|
4136
|
+
const channel = await this.send({ kind: "createChannel", ...input });
|
|
4137
|
+
await this.load(true);
|
|
4138
|
+
return channel;
|
|
4139
|
+
}
|
|
4140
|
+
async addMembers(channelId, members) {
|
|
4141
|
+
const channel = await this.send({ kind: "addMembers", channel: channelId, members });
|
|
4142
|
+
await this.load(true);
|
|
4143
|
+
return channel;
|
|
4144
|
+
}
|
|
4145
|
+
async changeMember(channelId, agentId, change) {
|
|
4146
|
+
const channel = await this.send({ kind: "changeMember", channel: channelId, agent: agentId, change });
|
|
4147
|
+
await this.load(true);
|
|
4148
|
+
return channel;
|
|
4149
|
+
}
|
|
4150
|
+
async updateChannel(channelId, change) {
|
|
4151
|
+
const channel = await this.send({ kind: "updateChannel", channel: channelId, ...change });
|
|
4152
|
+
await this.load(true);
|
|
4153
|
+
return channel;
|
|
4154
|
+
}
|
|
4155
|
+
async deleteChannel(channelId) {
|
|
4156
|
+
await this.deleting(channelId, async () => {
|
|
4157
|
+
await this.send({ kind: "deleteChannel", channel: channelId });
|
|
4158
|
+
const { [channelId]: _gone, ...messages } = this.current.messages;
|
|
4159
|
+
this.update({ messages });
|
|
4160
|
+
await this.load(true);
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
async resetAgent(agentId) {
|
|
4164
|
+
const agent = await this.send({ kind: "resetAgent", agent: agentId });
|
|
4165
|
+
await this.load(true);
|
|
4166
|
+
return agent;
|
|
4167
|
+
}
|
|
4168
|
+
async updateAgent(agentId, change) {
|
|
4169
|
+
const agent = await this.send({ kind: "updateAgent", agent: agentId, ...change });
|
|
4170
|
+
await this.load(true);
|
|
4171
|
+
return agent;
|
|
4172
|
+
}
|
|
4173
|
+
async setChannelModel(channelId, model) {
|
|
4174
|
+
const channel = await this.send({ kind: "setChannelModel", channel: channelId, model });
|
|
4175
|
+
await this.load(true);
|
|
4176
|
+
return channel;
|
|
4177
|
+
}
|
|
4178
|
+
async deleteAgent(agentId) {
|
|
4179
|
+
await this.deleting(agentId, async () => {
|
|
4180
|
+
await this.send({ kind: "deleteAgent", agent: agentId });
|
|
4181
|
+
await this.load(true);
|
|
4182
|
+
});
|
|
4183
|
+
}
|
|
4184
|
+
async deleting(id, action) {
|
|
4185
|
+
this.update({ deleting: [...this.current.deleting, id] });
|
|
4186
|
+
try {
|
|
4187
|
+
await action();
|
|
4188
|
+
} finally {
|
|
4189
|
+
this.update({ deleting: this.current.deleting.filter((other) => other !== id) });
|
|
3702
4190
|
}
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
4191
|
+
}
|
|
4192
|
+
async openAgent(agentId) {
|
|
4193
|
+
const { sessionId } = await this.send({ kind: "openAgent", agent: agentId });
|
|
4194
|
+
return sessionId;
|
|
4195
|
+
}
|
|
4196
|
+
async setNotice(channelId, text) {
|
|
4197
|
+
const channel = await this.send({ kind: "setNotice", channel: channelId, text });
|
|
4198
|
+
await this.load(true);
|
|
4199
|
+
return channel;
|
|
4200
|
+
}
|
|
4201
|
+
shareAgent(agentId, color) {
|
|
4202
|
+
return this.send({ kind: "shareAgent", agent: agentId, ...color ? { color } : {} });
|
|
4203
|
+
}
|
|
4204
|
+
async stopCard(agentId) {
|
|
4205
|
+
return await this.send({ kind: "stopCard", agent: agentId });
|
|
4206
|
+
}
|
|
4207
|
+
openCard(link, password) {
|
|
4208
|
+
return this.send({ kind: "openCard", link, ...password ? { password } : {} });
|
|
4209
|
+
}
|
|
4210
|
+
async addFromCard(link, cwd, password) {
|
|
4211
|
+
const added = await this.send({ kind: "addFromCard", link, cwd, ...password ? { password } : {} });
|
|
4212
|
+
await this.load(true);
|
|
4213
|
+
return added;
|
|
4214
|
+
}
|
|
4215
|
+
async post(channelId, text, images = []) {
|
|
4216
|
+
await this.send({
|
|
4217
|
+
kind: "post",
|
|
4218
|
+
channel: channelId,
|
|
4219
|
+
text,
|
|
4220
|
+
...images.length ? { images: images.map(({ data, mimeType, width, height }) => ({ data, mimeType, width, height })) } : {}
|
|
4221
|
+
});
|
|
4222
|
+
}
|
|
4223
|
+
picture(channelId, id) {
|
|
4224
|
+
const key = `${channelId}:${id}`;
|
|
4225
|
+
let read = this.pictures.get(key);
|
|
4226
|
+
if (!read) {
|
|
4227
|
+
read = this.send({ kind: "picture", channel: channelId, id }).then((data) => typeof data === "string" ? data : "", () => "");
|
|
4228
|
+
this.pictures.set(key, read);
|
|
4229
|
+
for (const old of this.pictures.keys()) {
|
|
4230
|
+
if (this.pictures.size <= 60) {
|
|
4231
|
+
break;
|
|
4232
|
+
}
|
|
4233
|
+
this.pictures.delete(old);
|
|
4234
|
+
}
|
|
3706
4235
|
}
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
4236
|
+
return read;
|
|
4237
|
+
}
|
|
4238
|
+
async resumeRound(channelId, messageId, how) {
|
|
4239
|
+
await this.send({ kind: "resumeRound", channel: channelId, message: messageId, how });
|
|
4240
|
+
}
|
|
4241
|
+
async setLimits(limits) {
|
|
4242
|
+
await this.send({ kind: "setLimits", limits });
|
|
4243
|
+
}
|
|
4244
|
+
async watch(channelId) {
|
|
4245
|
+
await this.send({ kind: "watch", channel: channelId });
|
|
4246
|
+
}
|
|
4247
|
+
async changed(keys) {
|
|
4248
|
+
const reads = [];
|
|
4249
|
+
for (const key of keys) {
|
|
4250
|
+
if (key === Keys.TEAM || key === Keys.WORKING || key === Keys.ANSWERED) {
|
|
4251
|
+
reads.push(this.load(true));
|
|
4252
|
+
} else if (key.startsWith(Keys.MESSAGES)) {
|
|
4253
|
+
const channelId = key.slice(Keys.MESSAGES.length);
|
|
4254
|
+
if (this.current.messages[channelId]) {
|
|
4255
|
+
reads.push(this.messages(channelId, true));
|
|
4256
|
+
}
|
|
4257
|
+
} else if (key === Keys.FOCUS) {
|
|
4258
|
+
reads.push(this.storage.get(Keys.FOCUS).then(async (focus) => {
|
|
4259
|
+
if (focus) {
|
|
4260
|
+
await this.load(true);
|
|
4261
|
+
for (const listener of this.focusListeners) {
|
|
4262
|
+
listener(focus.channelId);
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
}));
|
|
3713
4266
|
}
|
|
3714
4267
|
}
|
|
3715
|
-
|
|
4268
|
+
await Promise.all(reads).catch((error) => console.error(error));
|
|
4269
|
+
}
|
|
4270
|
+
update(change) {
|
|
4271
|
+
this.current = { ...this.current, ...change };
|
|
4272
|
+
for (const listener of this.listeners) {
|
|
4273
|
+
listener(this.current);
|
|
4274
|
+
}
|
|
3716
4275
|
}
|
|
3717
|
-
})(ChannelRounds ||= {});
|
|
3718
|
-
|
|
3719
|
-
// web-src/limit-settings.tsx
|
|
3720
|
-
function amount(pi, tokens) {
|
|
3721
|
-
return tokens > 0 ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(tokens) : ChannelWords.of(pi.ui.language).noLimit;
|
|
3722
4276
|
}
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
}), [pi]);
|
|
3728
|
-
const [value, setValue] = React.useState({ limits: ChannelRounds.limits(undefined), spent: 0, channels: {} });
|
|
4277
|
+
|
|
4278
|
+
// web-src/shared-group.tsx
|
|
4279
|
+
function useFriends(pi) {
|
|
4280
|
+
const [friends, setFriends] = React.useState([]);
|
|
3729
4281
|
React.useEffect(() => {
|
|
3730
4282
|
let live = true;
|
|
3731
|
-
|
|
4283
|
+
pi.rooms?.listFriends().then((list) => live && setFriends(list.filter((friend) => friend.status === "friend")), () => {
|
|
3732
4284
|
return;
|
|
3733
4285
|
});
|
|
3734
|
-
load();
|
|
3735
|
-
const stop = pi.storage.onChange((keys) => (keys.includes(Keys.LIMITS) || keys.includes(Keys.SPENT)) && load());
|
|
3736
4286
|
return () => {
|
|
3737
4287
|
live = false;
|
|
3738
|
-
stop();
|
|
3739
4288
|
};
|
|
3740
|
-
}, [pi
|
|
3741
|
-
return
|
|
4289
|
+
}, [pi]);
|
|
4290
|
+
return friends;
|
|
3742
4291
|
}
|
|
3743
|
-
function
|
|
3744
|
-
const
|
|
3745
|
-
const
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
return /* @__PURE__ */ React.createElement("fieldset", {
|
|
3749
|
-
className: "ta-segmented",
|
|
3750
|
-
"aria-label": words()[key === "answer" ? "limitAnswer" : key === "channelDay" ? "limitChannelDay" : "limitAllDay"]
|
|
3751
|
-
}, LIMIT_CHOICES[key].map((value) => /* @__PURE__ */ React.createElement("button", {
|
|
3752
|
-
key: value,
|
|
3753
|
-
type: "button",
|
|
3754
|
-
"aria-pressed": limits[key] === value,
|
|
3755
|
-
className: limits[key] === value ? "ta-on" : "",
|
|
3756
|
-
onClick: () => pick(value)
|
|
3757
|
-
}, amount(pi, value))));
|
|
3758
|
-
};
|
|
3759
|
-
function Spent() {
|
|
3760
|
-
const { spent } = useLimits(pi);
|
|
3761
|
-
return /* @__PURE__ */ React.createElement("span", {
|
|
3762
|
-
className: "tac-limit-spent"
|
|
3763
|
-
}, spent > 0 ? amount(pi, spent) : "0");
|
|
4292
|
+
async function createShared(context, title, friends, agents) {
|
|
4293
|
+
const { pi } = context;
|
|
4294
|
+
const rooms = pi.rooms;
|
|
4295
|
+
if (!rooms) {
|
|
4296
|
+
throw new Error(ChannelViews.words(pi).sharedNeedsRooms);
|
|
3764
4297
|
}
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
4298
|
+
const room = await rooms.createRoom({ kind: ROOMS_KIND, title });
|
|
4299
|
+
await rooms.inviteFriends(room.id, friends);
|
|
4300
|
+
for (const agent of agents) {
|
|
4301
|
+
await pi.packages.callPackageHost(ROOMS_PACKAGE, "doubles", [{ kind: "invite", room: room.id, agent }]).catch((error) => {
|
|
4302
|
+
pi.ui.notify(ChannelViews.message(error), "error");
|
|
4303
|
+
});
|
|
4304
|
+
}
|
|
4305
|
+
const { link } = await rooms.invite(room.id);
|
|
4306
|
+
await pi.openLink?.(link);
|
|
4307
|
+
return room.id;
|
|
4308
|
+
}
|
|
4309
|
+
var ROOMS_PACKAGE = "@celljs/ta-rooms";
|
|
4310
|
+
var ROOMS_KIND = "ta-rooms";
|
|
4311
|
+
async function becomeGroup(context, channel, friends, agents) {
|
|
4312
|
+
const { pi } = context;
|
|
4313
|
+
const members = [...channel.members, ...agents.filter((id) => !channel.members.includes(id))];
|
|
4314
|
+
const room = await createShared(context, channel.name, friends, members);
|
|
4315
|
+
await context.service.updateChannel(channel.id, { shared: room });
|
|
4316
|
+
pi.ui.notify(ChannelWords.format(ChannelViews.words(pi).sharedMade, { name: channel.name }), "info");
|
|
3776
4317
|
}
|
|
3777
4318
|
|
|
3778
|
-
//
|
|
3779
|
-
var
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
const
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
["context", /<\/?context>/],
|
|
3788
|
-
["source", /\[ta:(?:from|notice|by) /],
|
|
3789
|
-
["image note", /\[Image: original \d+x\d+|\[Image converted from /],
|
|
3790
|
-
["skill", /<skill name="|<\/skill>/],
|
|
3791
|
-
["task note", /<\/?task_(?:update|adopted|renamed)\b/],
|
|
3792
|
-
["summary", /<\/?(?:conversation_history_summary|summary)>/]
|
|
3793
|
-
];
|
|
3794
|
-
function text(content, joiner = `
|
|
3795
|
-
`) {
|
|
3796
|
-
if (typeof content === "string") {
|
|
3797
|
-
return content;
|
|
3798
|
-
}
|
|
3799
|
-
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) : "";
|
|
3800
|
-
}
|
|
3801
|
-
TaSaid2.text = text;
|
|
3802
|
-
function words(role, text2, options = {}) {
|
|
3803
|
-
const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
|
|
3804
|
-
return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
|
|
3805
|
-
}
|
|
3806
|
-
TaSaid2.words = words;
|
|
3807
|
-
function of(message, options) {
|
|
3808
|
-
return message ? words(message.role, text(message.content), options) : "";
|
|
3809
|
-
}
|
|
3810
|
-
TaSaid2.of = of;
|
|
3811
|
-
function notice(message) {
|
|
3812
|
-
return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
|
|
4319
|
+
// web-src/create.tsx
|
|
4320
|
+
var noBack = (_open, _close) => false;
|
|
4321
|
+
var AGENT_PAGE = `${NAME}/agent`;
|
|
4322
|
+
function newAgent(context) {
|
|
4323
|
+
const { pi, service, ui } = context;
|
|
4324
|
+
if (!ui.state.draft) {
|
|
4325
|
+
const team = service.state.team;
|
|
4326
|
+
const name = ChannelsUtil.freeName(team, ChannelViews.words(pi).newAgentName);
|
|
4327
|
+
ui.set({ draft: { name, face: ChannelsUtil.freeFaceFor(team.agents, ChannelsUtil.newId("draft")) } });
|
|
3813
4328
|
}
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
4329
|
+
pi.ui.showView(AGENT_PAGE);
|
|
4330
|
+
}
|
|
4331
|
+
function Identity({ context, onClose }) {
|
|
4332
|
+
const { pi, ui } = context;
|
|
4333
|
+
const { draft } = useUi(ui);
|
|
4334
|
+
const w = ChannelViews.words(pi);
|
|
4335
|
+
const ref = React.useRef(null);
|
|
4336
|
+
const name = React.useRef(null);
|
|
4337
|
+
React.useEffect(() => name.current?.select(), []);
|
|
4338
|
+
(pi.ui.useBackLayer ?? noBack)(true, onClose);
|
|
4339
|
+
React.useEffect(() => {
|
|
4340
|
+
const close = (event) => {
|
|
4341
|
+
const target = event.target;
|
|
4342
|
+
if (!ref.current?.contains(target) && !target.closest?.(".tac-identity-open")) {
|
|
4343
|
+
onClose();
|
|
4344
|
+
}
|
|
4345
|
+
};
|
|
4346
|
+
const onKey = (event) => event.key === "Escape" && onClose();
|
|
4347
|
+
document.addEventListener("pointerdown", close);
|
|
4348
|
+
document.addEventListener("keydown", onKey);
|
|
4349
|
+
return () => {
|
|
4350
|
+
document.removeEventListener("pointerdown", close);
|
|
4351
|
+
document.removeEventListener("keydown", onKey);
|
|
4352
|
+
};
|
|
4353
|
+
}, [onClose]);
|
|
4354
|
+
if (!draft) {
|
|
4355
|
+
return null;
|
|
3817
4356
|
}
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
4357
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4358
|
+
className: "tac-identity",
|
|
4359
|
+
ref,
|
|
4360
|
+
role: "dialog",
|
|
4361
|
+
"aria-label": w.editAgent
|
|
4362
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
4363
|
+
className: "tac-identity-label"
|
|
4364
|
+
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
4365
|
+
className: "tac-input",
|
|
4366
|
+
value: draft.name,
|
|
4367
|
+
maxLength: 40,
|
|
4368
|
+
ref: name,
|
|
4369
|
+
onChange: (event) => ui.set({ draft: { ...draft, name: event.target.value } }),
|
|
4370
|
+
onKeyDown: (event) => event.key === "Enter" && onClose()
|
|
4371
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
4372
|
+
className: "tac-identity-label"
|
|
4373
|
+
}, w.avatar), /* @__PURE__ */ React.createElement("div", {
|
|
4374
|
+
className: "tac-faces"
|
|
4375
|
+
}, Array.from({ length: FACES }, (_, face) => /* @__PURE__ */ React.createElement("button", {
|
|
4376
|
+
key: face,
|
|
4377
|
+
type: "button",
|
|
4378
|
+
"aria-pressed": draft.face === face,
|
|
4379
|
+
className: `tac-face-pick${draft.face === face ? " tac-on" : ""}`,
|
|
4380
|
+
onClick: () => ui.set({ draft: { ...draft, face } })
|
|
4381
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
4382
|
+
face,
|
|
4383
|
+
size: 30
|
|
4384
|
+
})))));
|
|
4385
|
+
}
|
|
4386
|
+
function NewAgentHead({ context }) {
|
|
4387
|
+
const { pi, ui } = context;
|
|
4388
|
+
const { draft, editing } = useUi(ui);
|
|
4389
|
+
const w = ChannelViews.words(pi);
|
|
4390
|
+
const Down = ChannelViews.icon(pi, "ChevronDown");
|
|
4391
|
+
if (!draft) {
|
|
4392
|
+
return null;
|
|
3829
4393
|
}
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
4394
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4395
|
+
className: "tac-new-head"
|
|
4396
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4397
|
+
className: "tac-new-title"
|
|
4398
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
4399
|
+
type: "button",
|
|
4400
|
+
className: "tac-new-trigger tac-identity-open",
|
|
4401
|
+
"aria-expanded": editing,
|
|
4402
|
+
title: w.editAgent,
|
|
4403
|
+
onClick: () => ui.set({ editing: !editing })
|
|
4404
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
4405
|
+
face: draft.face,
|
|
4406
|
+
size: 20
|
|
4407
|
+
}), /* @__PURE__ */ React.createElement("span", null, draft.name || w.newAgentName), /* @__PURE__ */ React.createElement(Down, {
|
|
4408
|
+
size: 14
|
|
4409
|
+
})), editing && /* @__PURE__ */ React.createElement(Identity, {
|
|
4410
|
+
context,
|
|
4411
|
+
onClose: () => ui.set({ editing: false })
|
|
4412
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
4413
|
+
type: "button",
|
|
4414
|
+
className: "tac-button tac-quiet",
|
|
4415
|
+
onClick: () => {
|
|
4416
|
+
ui.set({ draft: undefined, editing: false });
|
|
4417
|
+
pi.ui.showView("");
|
|
3841
4418
|
}
|
|
3842
|
-
|
|
3843
|
-
|
|
4419
|
+
}, w.cancel));
|
|
4420
|
+
}
|
|
4421
|
+
function NewAgentPage({ context }) {
|
|
4422
|
+
const { pi, service, ui } = context;
|
|
4423
|
+
const { draft } = useUi(ui);
|
|
4424
|
+
const { loaded } = useChannels(service);
|
|
4425
|
+
const w = ChannelViews.words(pi);
|
|
4426
|
+
const Pencil = ChannelViews.icon(pi, "Pencil");
|
|
4427
|
+
const Composer = pi.ui.Composer;
|
|
4428
|
+
const first = React.useRef(true);
|
|
4429
|
+
React.useEffect(() => {
|
|
4430
|
+
if (!loaded || !first.current) {
|
|
4431
|
+
return;
|
|
3844
4432
|
}
|
|
3845
|
-
|
|
4433
|
+
first.current = false;
|
|
4434
|
+
if (!ui.state.draft) {
|
|
4435
|
+
newAgent(context);
|
|
4436
|
+
}
|
|
4437
|
+
}, [loaded, ui, context]);
|
|
4438
|
+
if (!draft) {
|
|
4439
|
+
return null;
|
|
3846
4440
|
}
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
{
|
|
3856
|
-
|
|
3857
|
-
role: "user",
|
|
3858
|
-
text: `<context>
|
|
3859
|
-
The channel #ops, its members.
|
|
3860
|
-
[ta:from @celljs/ta-channels #ops]
|
|
3861
|
-
</context>
|
|
3862
|
-
Check the build`,
|
|
3863
|
-
said: "Check the build"
|
|
3864
|
-
},
|
|
3865
|
-
{
|
|
3866
|
-
mark: "a notice, not the user",
|
|
3867
|
-
role: "user",
|
|
3868
|
-
text: `<context>
|
|
3869
|
-
[ta:notice @celljs/ta-call]
|
|
3870
|
-
</context>
|
|
3871
|
-
The work finished. Its last words: tests pass.`,
|
|
3872
|
-
said: "The work finished. Its last words: tests pass."
|
|
3873
|
-
},
|
|
3874
|
-
{ mark: "one let in", role: "user", text: `<context>
|
|
3875
|
-
[ta:by p-7 Alice]
|
|
3876
|
-
</context>
|
|
3877
|
-
Hello there`, said: "Hello there" },
|
|
3878
|
-
{
|
|
3879
|
-
mark: "notes of images",
|
|
3880
|
-
role: "user",
|
|
3881
|
-
text: `Look at this
|
|
3882
|
-
[Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
|
|
3883
|
-
[Image converted from image/heic to image/png.]`,
|
|
3884
|
-
said: "Look at this"
|
|
3885
|
-
},
|
|
3886
|
-
{
|
|
3887
|
-
mark: "a skill run",
|
|
3888
|
-
role: "user",
|
|
3889
|
-
text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
|
|
3890
|
-
# Ta package
|
|
3891
|
-
Steps.
|
|
3892
|
-
</skill>
|
|
3893
|
-
|
|
3894
|
-
Make a card`,
|
|
3895
|
-
said: "Make a card"
|
|
3896
|
-
},
|
|
3897
|
-
{
|
|
3898
|
-
mark: "a note of a task",
|
|
3899
|
-
role: "user",
|
|
3900
|
-
text: `<task_update id="t1" title="Fix login" status="done">
|
|
3901
|
-
All tests pass.
|
|
3902
|
-
</task_update>`,
|
|
3903
|
-
said: "Fix login"
|
|
3904
|
-
},
|
|
3905
|
-
{ mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
|
|
3906
|
-
Now t2.
|
|
3907
|
-
</task_renamed>` },
|
|
3908
|
-
{ mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
|
|
3909
|
-
Switched to voice.`, said: "Switched to voice." },
|
|
3910
|
-
{ mark: "a summary alone", role: "assistant", text: SUMMARY },
|
|
3911
|
-
{ mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
|
|
3912
|
-
<summary>` },
|
|
3913
|
-
{
|
|
3914
|
-
mark: "a card after the answer",
|
|
3915
|
-
role: "assistant",
|
|
3916
|
-
text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
|
|
3917
|
-
said: "tests pass"
|
|
3918
|
-
},
|
|
3919
|
-
{ mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
|
|
3920
|
-
{ mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
|
|
3921
|
-
{ mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
|
|
3922
|
-
{ mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
|
|
3923
|
-
</system-reminder>
|
|
3924
|
-
Ready.`, said: "Ready." }
|
|
3925
|
-
];
|
|
3926
|
-
function userWords(text2) {
|
|
3927
|
-
const said = TaImageNote.strip(TaMessageContext.strip(text2));
|
|
3928
|
-
const skill = TaSkillUse.parse(said);
|
|
3929
|
-
if (skill) {
|
|
3930
|
-
return TaSkillUse.command(skill);
|
|
3931
|
-
}
|
|
3932
|
-
const note = TaTaskNote.parse(said);
|
|
3933
|
-
if (!note) {
|
|
3934
|
-
return said;
|
|
3935
|
-
}
|
|
3936
|
-
if (note.kind === "renamed") {
|
|
3937
|
-
return "";
|
|
3938
|
-
}
|
|
3939
|
-
return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
|
|
3940
|
-
}
|
|
3941
|
-
function withoutFences(text2, drop, tags = false) {
|
|
3942
|
-
const kept = [];
|
|
3943
|
-
let fence;
|
|
3944
|
-
let left = false;
|
|
3945
|
-
for (const part of text2.split(`
|
|
3946
|
-
`)) {
|
|
3947
|
-
const open = FENCE.exec(part);
|
|
3948
|
-
if (!fence && open) {
|
|
3949
|
-
fence = { mark: open[1], dropped: drop(open[2]) };
|
|
3950
|
-
} else if (fence && closes(part, fence.mark)) {
|
|
3951
|
-
const dropped = fence.dropped;
|
|
3952
|
-
fence = undefined;
|
|
3953
|
-
if (dropped) {
|
|
3954
|
-
continue;
|
|
3955
|
-
}
|
|
3956
|
-
}
|
|
3957
|
-
if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
|
|
3958
|
-
left = true;
|
|
3959
|
-
} else {
|
|
3960
|
-
kept.push(part);
|
|
3961
|
-
}
|
|
4441
|
+
const send = async (text) => {
|
|
4442
|
+
const agent = await service.createAgent({ name: draft.name, role: DEFAULT_ROLE, face: draft.face, cwd: draft.cwd });
|
|
4443
|
+
ui.set({ draft: undefined, editing: false });
|
|
4444
|
+
try {
|
|
4445
|
+
const sessionId = await service.openAgent(agent.id);
|
|
4446
|
+
context.sessions.set(agent.id, sessionId);
|
|
4447
|
+
await pi.switchSession(sessionId);
|
|
4448
|
+
await pi.sendUserMessage(text);
|
|
4449
|
+
} catch (error) {
|
|
4450
|
+
pi.ui.notify(ChannelViews.message(error), "error");
|
|
3962
4451
|
}
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
}
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
4452
|
+
};
|
|
4453
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4454
|
+
className: "tac-new-page"
|
|
4455
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4456
|
+
className: "tac-new-col"
|
|
4457
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
4458
|
+
face: draft.face,
|
|
4459
|
+
size: 88
|
|
4460
|
+
}), /* @__PURE__ */ React.createElement("h2", {
|
|
4461
|
+
className: "tac-new-name"
|
|
4462
|
+
}, /* @__PURE__ */ React.createElement("span", null, draft.name || w.newAgentName), /* @__PURE__ */ React.createElement("button", {
|
|
4463
|
+
type: "button",
|
|
4464
|
+
className: "tac-action tac-identity-open",
|
|
4465
|
+
title: w.editAgent,
|
|
4466
|
+
"aria-label": w.editAgent,
|
|
4467
|
+
onClick: () => ui.set({ editing: !ui.state.editing })
|
|
4468
|
+
}, /* @__PURE__ */ React.createElement(Pencil, {
|
|
4469
|
+
size: 14
|
|
4470
|
+
}))), /* @__PURE__ */ React.createElement("p", {
|
|
4471
|
+
className: "tac-new-hint"
|
|
4472
|
+
}, w.newAgentHint), /* @__PURE__ */ React.createElement("div", {
|
|
4473
|
+
className: "tac-new-box"
|
|
4474
|
+
}, /* @__PURE__ */ React.createElement(Composer, {
|
|
4475
|
+
placeholder: ChannelWords.format(w.agentPlaceholder, { name: draft.name || w.newAgentName }),
|
|
4476
|
+
onSend: send,
|
|
4477
|
+
cwd: draft.cwd,
|
|
4478
|
+
onPickCwd: (cwd) => ui.set({ draft: { ...draft, cwd } }),
|
|
4479
|
+
draft: "new-agent"
|
|
4480
|
+
}))));
|
|
4481
|
+
}
|
|
4482
|
+
function NewChannelDialog({ context, onClose }) {
|
|
4483
|
+
const { pi, service } = context;
|
|
4484
|
+
const { team } = useChannels(service);
|
|
4485
|
+
const faces = useFaces(team);
|
|
4486
|
+
const w = ChannelViews.words(pi);
|
|
4487
|
+
const Search = ChannelViews.icon(pi, "Search");
|
|
4488
|
+
const Check = ChannelViews.icon(pi, "Check");
|
|
4489
|
+
const [name, setName] = React.useState("");
|
|
4490
|
+
const [query, setQuery] = React.useState("");
|
|
4491
|
+
const [picked, setPicked] = React.useState([]);
|
|
4492
|
+
const friends = useFriends(pi);
|
|
4493
|
+
const [pickedFriends, setPickedFriends] = React.useState([]);
|
|
4494
|
+
const shared = pickedFriends.length > 0;
|
|
4495
|
+
const toggleFriend = (friend) => setPickedFriends(pickedFriends.includes(friend.id) ? pickedFriends.filter((id) => id !== friend.id) : [...pickedFriends, friend.id]);
|
|
4496
|
+
const [busy, setBusy] = React.useState(false);
|
|
4497
|
+
const [error, setError] = React.useState();
|
|
4498
|
+
const Dialog = pi.ui.Dialog;
|
|
4499
|
+
const shown = team.agents.filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
|
|
4500
|
+
const full = picked.length >= MAX_MEMBERS;
|
|
4501
|
+
const toggle = (agent) => setPicked(picked.includes(agent.id) ? picked.filter((id) => id !== agent.id) : full ? picked : [...picked, agent.id]);
|
|
4502
|
+
const create = (event) => {
|
|
4503
|
+
event.preventDefault();
|
|
4504
|
+
setBusy(true);
|
|
4505
|
+
setError(undefined);
|
|
4506
|
+
if (shared) {
|
|
4507
|
+
createShared(context, name.trim(), pickedFriends, picked).then(onClose, (failure) => {
|
|
4508
|
+
setBusy(false);
|
|
4509
|
+
setError(ChannelViews.message(failure));
|
|
4510
|
+
});
|
|
4511
|
+
return;
|
|
3982
4512
|
}
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
}
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
4513
|
+
service.createChannel({ name, members: picked }).then((channel) => {
|
|
4514
|
+
onClose();
|
|
4515
|
+
context.showChannel(channel.id);
|
|
4516
|
+
}, (failure) => {
|
|
4517
|
+
setBusy(false);
|
|
4518
|
+
setError(ChannelViews.message(failure));
|
|
4519
|
+
});
|
|
4520
|
+
};
|
|
4521
|
+
return /* @__PURE__ */ React.createElement(Dialog, {
|
|
4522
|
+
title: w.newChannel,
|
|
4523
|
+
onClose
|
|
4524
|
+
}, /* @__PURE__ */ React.createElement("form", {
|
|
4525
|
+
className: "tac-dialog",
|
|
4526
|
+
onSubmit: create
|
|
4527
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
4528
|
+
className: "tac-dialog-label"
|
|
4529
|
+
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
4530
|
+
className: "tac-input tac-dialog-input",
|
|
4531
|
+
value: name,
|
|
4532
|
+
placeholder: w.channelNamePlaceholder,
|
|
4533
|
+
maxLength: 40,
|
|
4534
|
+
autoFocus: true,
|
|
4535
|
+
onChange: (event) => setName(event.target.value)
|
|
4536
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
4537
|
+
className: "tac-dialog-label"
|
|
4538
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.addAgents), /* @__PURE__ */ React.createElement("span", {
|
|
4539
|
+
className: "tac-dialog-count"
|
|
4540
|
+
}, picked.length, "/", MAX_MEMBERS)), /* @__PURE__ */ React.createElement("label", {
|
|
4541
|
+
className: "tac-dialog-search"
|
|
4542
|
+
}, /* @__PURE__ */ React.createElement(Search, {
|
|
4543
|
+
size: 15
|
|
4544
|
+
}), /* @__PURE__ */ React.createElement("input", {
|
|
4545
|
+
value: query,
|
|
4546
|
+
placeholder: ChannelWords.format(w.searchAgents, { max: String(MAX_MEMBERS) }),
|
|
4547
|
+
"aria-label": w.search,
|
|
4548
|
+
onChange: (event) => setQuery(event.target.value)
|
|
4549
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
4550
|
+
className: "tac-pick-list"
|
|
4551
|
+
}, team.agents.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4552
|
+
compact: true,
|
|
4553
|
+
title: w.noAgents,
|
|
4554
|
+
hint: w.noAgentsHint
|
|
4555
|
+
}), team.agents.length > 0 && shown.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4556
|
+
compact: true,
|
|
4557
|
+
title: w.noMatch
|
|
4558
|
+
}), shown.map((agent) => {
|
|
4559
|
+
const on = picked.includes(agent.id);
|
|
4560
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
4561
|
+
key: agent.id,
|
|
4562
|
+
type: "button",
|
|
4563
|
+
"aria-pressed": on,
|
|
4564
|
+
disabled: !on && full,
|
|
4565
|
+
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
4566
|
+
onClick: () => toggle(agent)
|
|
4567
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4568
|
+
className: "tac-check"
|
|
4569
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
4570
|
+
size: 13,
|
|
4571
|
+
strokeWidth: 3
|
|
4572
|
+
})), /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
4573
|
+
agent,
|
|
4574
|
+
faces,
|
|
4575
|
+
size: 30
|
|
4576
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
4577
|
+
className: "tac-pick-text"
|
|
4578
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4579
|
+
className: "tac-pick-name"
|
|
4580
|
+
}, agent.name, picked[0] === agent.id && /* @__PURE__ */ React.createElement("span", {
|
|
4581
|
+
className: "tac-msg-lead"
|
|
4582
|
+
}, w.lead)), /* @__PURE__ */ React.createElement("span", {
|
|
4583
|
+
className: "tac-pick-role"
|
|
4584
|
+
}, agent.role.split(`
|
|
4585
|
+
`)[0])));
|
|
4586
|
+
})), friends.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
4587
|
+
className: "tac-dialog-label"
|
|
4588
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.addFriends), shared && /* @__PURE__ */ React.createElement("span", {
|
|
4589
|
+
className: "tac-dialog-count"
|
|
4590
|
+
}, pickedFriends.length)), /* @__PURE__ */ React.createElement("div", {
|
|
4591
|
+
className: "tac-pick-list"
|
|
4592
|
+
}, friends.map((friend) => {
|
|
4593
|
+
const on = pickedFriends.includes(friend.id);
|
|
4594
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
4595
|
+
key: friend.id,
|
|
4596
|
+
type: "button",
|
|
4597
|
+
"aria-pressed": on,
|
|
4598
|
+
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
4599
|
+
onClick: () => toggleFriend(friend)
|
|
4600
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4601
|
+
className: "tac-check"
|
|
4602
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
4603
|
+
size: 13,
|
|
4604
|
+
strokeWidth: 3
|
|
4605
|
+
})), pi.ui.Face ? /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
4606
|
+
seed: friend.id,
|
|
4607
|
+
size: 30,
|
|
4608
|
+
look: friend.look
|
|
4609
|
+
}) : /* @__PURE__ */ React.createElement("span", {
|
|
4610
|
+
className: "tac-pick-face"
|
|
4611
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
4612
|
+
className: "tac-pick-text"
|
|
4613
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4614
|
+
className: "tac-pick-name"
|
|
4615
|
+
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
4616
|
+
className: "tac-pick-role"
|
|
4617
|
+
}, w.friend)));
|
|
4618
|
+
}))), (picked.length > 0 || shared) && /* @__PURE__ */ React.createElement("div", {
|
|
4619
|
+
className: "tac-dialog-note"
|
|
4620
|
+
}, shared ? w.sharedHint : w.membersHint), error && /* @__PURE__ */ React.createElement("div", {
|
|
4621
|
+
className: "tac-empty tac-error"
|
|
4622
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4623
|
+
className: "tac-dialog-actions"
|
|
4624
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
4625
|
+
type: "submit",
|
|
4626
|
+
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4627
|
+
disabled: busy || !name.trim() || picked.length === 0 && !shared
|
|
4628
|
+
}, w.create, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4629
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4630
|
+
})))));
|
|
4631
|
+
}
|
|
3997
4632
|
|
|
3998
|
-
// web-src/
|
|
3999
|
-
var
|
|
4000
|
-
((
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
for (const match of text.matchAll(pattern)) {
|
|
4018
|
-
const agent = agents.find((candidate) => candidate.name.toLowerCase() === match[1].toLowerCase());
|
|
4019
|
-
if (agent && !found.includes(agent.id)) {
|
|
4020
|
-
found.push(agent.id);
|
|
4021
|
-
}
|
|
4022
|
-
}
|
|
4023
|
-
return found;
|
|
4024
|
-
}
|
|
4025
|
-
ChannelsText.mentions = mentions;
|
|
4026
|
-
function targets(team, channel, message) {
|
|
4027
|
-
const muted = channel.muted ?? [];
|
|
4028
|
-
const members = channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
|
|
4029
|
-
const named = mentions(message.text, members).filter((id) => id !== message.author);
|
|
4030
|
-
if (message.author === SYSTEM) {
|
|
4031
|
-
return [];
|
|
4032
|
-
}
|
|
4033
|
-
if (named.length > 0 || message.author !== TA) {
|
|
4034
|
-
return named;
|
|
4035
|
-
}
|
|
4036
|
-
return members.length > 0 ? [members[0].id] : [];
|
|
4037
|
-
}
|
|
4038
|
-
ChannelsText.targets = targets;
|
|
4039
|
-
function authorName(team, author, labels) {
|
|
4040
|
-
if (author === SYSTEM) {
|
|
4041
|
-
return "channel";
|
|
4042
|
-
}
|
|
4043
|
-
if (author === USER) {
|
|
4044
|
-
return labels.user;
|
|
4045
|
-
}
|
|
4046
|
-
if (author === TA) {
|
|
4047
|
-
return labels.ta;
|
|
4633
|
+
// web-src/handoff.ts
|
|
4634
|
+
var HandOff;
|
|
4635
|
+
((HandOff) => {
|
|
4636
|
+
HandOff.TOOL = "hand_off";
|
|
4637
|
+
HandOff.CARD = "ta-channels-handoff";
|
|
4638
|
+
HandOff.BLOCK = "ta-handoff";
|
|
4639
|
+
const MARK = /\[ta-handoff:([^\]\s]+)\]/;
|
|
4640
|
+
HandOff.DEFINITION = {
|
|
4641
|
+
name: HandOff.TOOL,
|
|
4642
|
+
label: "Hand off",
|
|
4643
|
+
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.",
|
|
4644
|
+
promptSnippet: "Hand the work over to one of the user's agents or channels",
|
|
4645
|
+
parameters: {
|
|
4646
|
+
type: "object",
|
|
4647
|
+
properties: {
|
|
4648
|
+
to: { type: "string", description: "@name of an agent or #name of a channel." },
|
|
4649
|
+
brief: { type: "string", description: "Complete in itself: the receiver sees only this." }
|
|
4650
|
+
},
|
|
4651
|
+
required: ["to", "brief"]
|
|
4048
4652
|
}
|
|
4049
|
-
|
|
4653
|
+
};
|
|
4654
|
+
function ref(target) {
|
|
4655
|
+
return `${target.kind === "agent" ? "@" : "#"}${target.name}`;
|
|
4050
4656
|
}
|
|
4051
|
-
|
|
4052
|
-
function
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4657
|
+
HandOff.ref = ref;
|
|
4658
|
+
function ask(language, to) {
|
|
4659
|
+
const fence = "```";
|
|
4660
|
+
const context = [
|
|
4661
|
+
`[ta-handoff:${to}]`,
|
|
4662
|
+
`The user hands the work of this conversation over to ${to}, which does not see this conversation.`,
|
|
4663
|
+
`- 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.`,
|
|
4664
|
+
`- With the tool ${HandOff.TOOL}, call it with to "${to}" and the brief, then say in one line that it went.`,
|
|
4665
|
+
`- 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):`,
|
|
4666
|
+
`${fence}${HandOff.BLOCK}`,
|
|
4667
|
+
"<the brief>",
|
|
4668
|
+
fence,
|
|
4669
|
+
`- When the conversation holds nothing to hand over yet, say so and ask what ${to} should do.`
|
|
4060
4670
|
].join(`
|
|
4061
4671
|
`);
|
|
4672
|
+
const line = TaLanguageUtil.pick(language, {
|
|
4673
|
+
"zh-CN": `把这件事交给 ${to}`,
|
|
4674
|
+
"zh-TW": `把這件事交給 ${to}`,
|
|
4675
|
+
"en-US": `Hand this over to ${to}`,
|
|
4676
|
+
"ja-JP": `これを ${to} に引き継ぐ`
|
|
4677
|
+
});
|
|
4678
|
+
return TaMessageContext.wrap(context, line);
|
|
4062
4679
|
}
|
|
4063
|
-
|
|
4064
|
-
function
|
|
4065
|
-
|
|
4066
|
-
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)}`);
|
|
4067
|
-
const before = history.filter((item) => item.id !== message.id && !item.failed && !item.notice).slice(-CONTEXT_MESSAGES);
|
|
4068
|
-
const lines = [`[#${channel.name}]${channel.topic ? ` ${channel.topic}` : ""}`, "Members:", ...members.map((line) => `- ${line}`)];
|
|
4069
|
-
if (channel.notice) {
|
|
4070
|
-
lines.push("", "Notice of the channel (follow it; keep it with update_channel_notice):", channel.notice.text);
|
|
4071
|
-
}
|
|
4072
|
-
if (before.length > 0) {
|
|
4073
|
-
lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
|
|
4074
|
-
}
|
|
4075
|
-
if (options.closing) {
|
|
4076
|
-
lines.push("", CLOSING_NOTE);
|
|
4077
|
-
}
|
|
4078
|
-
lines.push("", `${authorName(team, message.author, labels)} to you:`);
|
|
4079
|
-
const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels)}`;
|
|
4080
|
-
lines.push(TaMessageSource.line(NAME, `#${channel.name}${speaker}`));
|
|
4081
|
-
return TaMessageContext.wrap(lines.join(`
|
|
4082
|
-
`), message.text);
|
|
4680
|
+
HandOff.ask = ask;
|
|
4681
|
+
function asked(text) {
|
|
4682
|
+
return MARK.exec(text)?.[1];
|
|
4083
4683
|
}
|
|
4084
|
-
|
|
4085
|
-
function
|
|
4086
|
-
|
|
4087
|
-
|
|
4684
|
+
HandOff.asked = asked;
|
|
4685
|
+
function find(text) {
|
|
4686
|
+
const lines = text.split(/\r?\n/);
|
|
4687
|
+
let found;
|
|
4688
|
+
for (let index = 0;index < lines.length; index++) {
|
|
4689
|
+
const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
|
|
4690
|
+
if (open?.[2] !== HandOff.BLOCK) {
|
|
4691
|
+
continue;
|
|
4692
|
+
}
|
|
4693
|
+
const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
|
|
4694
|
+
const end = lines.findIndex((line, at) => at > index && close.test(line));
|
|
4695
|
+
found = lines.slice(index + 1, end < 0 ? lines.length : end);
|
|
4696
|
+
index = end < 0 ? lines.length : end;
|
|
4088
4697
|
}
|
|
4089
|
-
const
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4698
|
+
const brief = found?.join(`
|
|
4699
|
+
`).trim();
|
|
4700
|
+
return brief || undefined;
|
|
4701
|
+
}
|
|
4702
|
+
HandOff.find = find;
|
|
4703
|
+
function message(origin, brief, language) {
|
|
4704
|
+
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
4705
|
+
const head = TaLanguageUtil.pick(language, {
|
|
4706
|
+
"zh-CN": `(交接自“${title}”)`,
|
|
4707
|
+
"zh-TW": `(交接自「${title}」)`,
|
|
4708
|
+
"en-US": `(Handed over from “${title}”)`,
|
|
4709
|
+
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
4710
|
+
});
|
|
4711
|
+
const context = [
|
|
4712
|
+
"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.",
|
|
4713
|
+
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.` : ""
|
|
4714
|
+
].filter(Boolean).join(`
|
|
4094
4715
|
`);
|
|
4716
|
+
return TaMessageContext.wrap(context, `${head}
|
|
4717
|
+
|
|
4718
|
+
${brief.trim()}`);
|
|
4095
4719
|
}
|
|
4096
|
-
|
|
4097
|
-
function
|
|
4098
|
-
const
|
|
4099
|
-
return
|
|
4720
|
+
HandOff.message = message;
|
|
4721
|
+
function channelText(origin, brief, language) {
|
|
4722
|
+
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
4723
|
+
return `${TaLanguageUtil.pick(language, {
|
|
4724
|
+
"zh-CN": `(交接自“${title}”)`,
|
|
4725
|
+
"zh-TW": `(交接自「${title}」)`,
|
|
4726
|
+
"en-US": `(Handed over from “${title}”)`,
|
|
4727
|
+
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
4728
|
+
})}
|
|
4100
4729
|
|
|
4101
|
-
|
|
4730
|
+
${brief.trim()}`;
|
|
4102
4731
|
}
|
|
4103
|
-
|
|
4104
|
-
function
|
|
4105
|
-
|
|
4106
|
-
for (const message of messages) {
|
|
4107
|
-
const { role, content } = message ?? {};
|
|
4108
|
-
if (role !== "user" && role !== "assistant") {
|
|
4109
|
-
continue;
|
|
4110
|
-
}
|
|
4111
|
-
const text = TaSaid.words(role, TaSaid.text(content, ""));
|
|
4112
|
-
if (text) {
|
|
4113
|
-
parts.push("", `## ${role === "user" ? labels.user : agent.name}`, "", text);
|
|
4114
|
-
}
|
|
4115
|
-
}
|
|
4116
|
-
return `${parts.join(`
|
|
4117
|
-
`)}
|
|
4118
|
-
`;
|
|
4732
|
+
HandOff.channelText = channelText;
|
|
4733
|
+
function serverLanguage(env = typeof process === "undefined" ? {} : process.env) {
|
|
4734
|
+
return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
|
|
4119
4735
|
}
|
|
4120
|
-
|
|
4121
|
-
function
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4736
|
+
HandOff.serverLanguage = serverLanguage;
|
|
4737
|
+
function result(target) {
|
|
4738
|
+
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.`;
|
|
4739
|
+
}
|
|
4740
|
+
HandOff.result = result;
|
|
4741
|
+
})(HandOff ||= {});
|
|
4742
|
+
|
|
4743
|
+
// web-src/handoff-view.tsx
|
|
4744
|
+
var HandOffViewUtil;
|
|
4745
|
+
((HandOffViewUtil) => {
|
|
4746
|
+
function members(team, target) {
|
|
4747
|
+
if (target.kind === "agent") {
|
|
4748
|
+
const agent = team.agents.find((candidate) => candidate.id === target.id);
|
|
4749
|
+
return agent ? [agent] : [];
|
|
4131
4750
|
}
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
`;
|
|
4751
|
+
const channel = team.channels.find((candidate) => candidate.id === target.id);
|
|
4752
|
+
return channel ? membersOf(team, channel) : [];
|
|
4135
4753
|
}
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4754
|
+
HandOffViewUtil.members = members;
|
|
4755
|
+
})(HandOffViewUtil ||= {});
|
|
4756
|
+
function useTeam(context) {
|
|
4757
|
+
return React.useSyncExternalStore((listener) => context.service.subscribe(listener), () => context.service.state).team;
|
|
4758
|
+
}
|
|
4759
|
+
function HandOffCard({ context, message }) {
|
|
4760
|
+
const card = message.details;
|
|
4761
|
+
const team = useTeam(context);
|
|
4762
|
+
const faces = useFaces(team);
|
|
4763
|
+
if (!card?.target) {
|
|
4764
|
+
return null;
|
|
4140
4765
|
}
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
"A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
|
|
4145
|
-
`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.`
|
|
4146
|
-
].join(`
|
|
4147
|
-
`);
|
|
4148
|
-
|
|
4149
|
-
// web-src/more-menu.tsx
|
|
4150
|
-
var MARGIN = 8;
|
|
4151
|
-
function MoreMenu({ pi, label, items }) {
|
|
4152
|
-
const w = ChannelViews.words(pi);
|
|
4153
|
-
const [open, setOpen] = React.useState(false);
|
|
4154
|
-
const anchor = React.useRef({
|
|
4155
|
-
right: 0,
|
|
4156
|
-
below: 0,
|
|
4157
|
-
above: 0,
|
|
4158
|
-
finger: undefined
|
|
4159
|
-
});
|
|
4160
|
-
const root = React.useRef(null);
|
|
4161
|
-
const menu = React.useRef(null);
|
|
4162
|
-
const Ellipsis = ChannelViews.icon(pi, "Ellipsis");
|
|
4163
|
-
const show = React.useCallback((button, at) => {
|
|
4164
|
-
const box = button.getBoundingClientRect();
|
|
4165
|
-
const touch = document.documentElement.hasAttribute("data-touch");
|
|
4166
|
-
const row = root.current?.parentElement?.getBoundingClientRect() ?? box;
|
|
4167
|
-
anchor.current = {
|
|
4168
|
-
right: box.right,
|
|
4169
|
-
below: at?.y ?? box.bottom,
|
|
4170
|
-
above: at?.y ?? box.top,
|
|
4171
|
-
finger: touch && at ? { ...at, around: { top: row.top, bottom: row.bottom } } : undefined
|
|
4172
|
-
};
|
|
4173
|
-
setOpen(true);
|
|
4174
|
-
}, []);
|
|
4175
|
-
React.useLayoutEffect(() => {
|
|
4176
|
-
const element = menu.current;
|
|
4177
|
-
if (!open || !element) {
|
|
4178
|
-
return;
|
|
4179
|
-
}
|
|
4180
|
-
const { right, below, above, finger } = anchor.current;
|
|
4181
|
-
if (finger) {
|
|
4182
|
-
return pi.ui.attachMenu(element, finger, () => setOpen(false));
|
|
4183
|
-
}
|
|
4184
|
-
const width = element.offsetWidth;
|
|
4185
|
-
const height = element.offsetHeight;
|
|
4186
|
-
const top = below + 4 + height <= window.innerHeight - MARGIN ? below + 4 : Math.max(MARGIN, above - 4 - height);
|
|
4187
|
-
element.style.top = `${top}px`;
|
|
4188
|
-
element.style.left = `${Math.max(MARGIN, right - width)}px`;
|
|
4189
|
-
}, [open, pi]);
|
|
4190
|
-
React.useEffect(() => {
|
|
4191
|
-
const row = root.current?.parentElement;
|
|
4192
|
-
const button = root.current?.querySelector(".tac-action");
|
|
4193
|
-
if (!row || !button) {
|
|
4194
|
-
return;
|
|
4195
|
-
}
|
|
4196
|
-
const onContextMenu = (event) => {
|
|
4197
|
-
event.preventDefault();
|
|
4198
|
-
show(button, event.clientX || event.clientY ? { x: event.clientX, y: event.clientY } : undefined);
|
|
4199
|
-
};
|
|
4200
|
-
row.addEventListener("contextmenu", onContextMenu);
|
|
4201
|
-
return () => row.removeEventListener("contextmenu", onContextMenu);
|
|
4202
|
-
}, [show]);
|
|
4203
|
-
React.useEffect(() => {
|
|
4204
|
-
if (!open) {
|
|
4205
|
-
return;
|
|
4206
|
-
}
|
|
4207
|
-
const close = (event) => {
|
|
4208
|
-
if (!root.current?.contains(event.target)) {
|
|
4209
|
-
setOpen(false);
|
|
4210
|
-
}
|
|
4211
|
-
};
|
|
4212
|
-
const onKey = (event) => {
|
|
4213
|
-
if (event.key === "Escape") {
|
|
4214
|
-
setOpen(false);
|
|
4215
|
-
}
|
|
4216
|
-
};
|
|
4217
|
-
document.addEventListener("pointerdown", close);
|
|
4218
|
-
document.addEventListener("keydown", onKey);
|
|
4219
|
-
return () => {
|
|
4220
|
-
document.removeEventListener("pointerdown", close);
|
|
4221
|
-
document.removeEventListener("keydown", onKey);
|
|
4222
|
-
};
|
|
4223
|
-
}, [open]);
|
|
4766
|
+
const w = ChannelViews.words(context.pi);
|
|
4767
|
+
const members = HandOffViewUtil.members(team, card.target);
|
|
4768
|
+
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);
|
|
4224
4769
|
return /* @__PURE__ */ React.createElement("div", {
|
|
4225
|
-
className: "tac-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
if (open) {
|
|
4237
|
-
setOpen(false);
|
|
4238
|
-
} else {
|
|
4239
|
-
show(event.currentTarget);
|
|
4240
|
-
}
|
|
4241
|
-
}
|
|
4242
|
-
}, /* @__PURE__ */ React.createElement(Ellipsis, {
|
|
4243
|
-
size: 15
|
|
4244
|
-
})), open && /* @__PURE__ */ React.createElement("div", {
|
|
4245
|
-
ref: menu,
|
|
4246
|
-
className: "tac-menu tac-agent-menu",
|
|
4247
|
-
role: "menu",
|
|
4248
|
-
"aria-label": label
|
|
4249
|
-
}, items().filter((section) => section.length > 0).map((section, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
4250
|
-
key: section[0]?.key ?? index
|
|
4251
|
-
}, index > 0 && /* @__PURE__ */ React.createElement("hr", {
|
|
4252
|
-
className: "tac-menu-line"
|
|
4253
|
-
}), section.map((item) => /* @__PURE__ */ React.createElement("button", {
|
|
4254
|
-
key: item.key,
|
|
4770
|
+
className: "tac-handoff"
|
|
4771
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4772
|
+
className: "tac-handoff-head"
|
|
4773
|
+
}, members.length > 0 && /* @__PURE__ */ React.createElement(RoomFace, {
|
|
4774
|
+
members,
|
|
4775
|
+
faces,
|
|
4776
|
+
size: 20,
|
|
4777
|
+
working: []
|
|
4778
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
4779
|
+
className: "tac-handoff-title"
|
|
4780
|
+
}, w.handedTo.replace("{to}", HandOff.ref(card.target))), members.length > 0 && /* @__PURE__ */ React.createElement("button", {
|
|
4255
4781
|
type: "button",
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
item.run();
|
|
4262
|
-
}
|
|
4263
|
-
}, item.icon, /* @__PURE__ */ React.createElement("span", {
|
|
4264
|
-
className: "tac-menu-label"
|
|
4265
|
-
}, item.label)))))));
|
|
4782
|
+
className: "tac-link",
|
|
4783
|
+
onClick: open
|
|
4784
|
+
}, w.handOffOpen)), /* @__PURE__ */ React.createElement("div", {
|
|
4785
|
+
className: "tac-handoff-brief"
|
|
4786
|
+
}, card.brief));
|
|
4266
4787
|
}
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
return false;
|
|
4788
|
+
var HandOffView;
|
|
4789
|
+
((HandOffView) => {
|
|
4790
|
+
function card(context) {
|
|
4791
|
+
return ({ message }) => /* @__PURE__ */ React.createElement(HandOffCard, {
|
|
4792
|
+
context,
|
|
4793
|
+
message
|
|
4794
|
+
});
|
|
4275
4795
|
}
|
|
4276
|
-
|
|
4277
|
-
function
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4796
|
+
HandOffView.card = card;
|
|
4797
|
+
function icon(context, target, icons) {
|
|
4798
|
+
const key = `${target.kind}:${target.id}`;
|
|
4799
|
+
let node2 = icons.get(key);
|
|
4800
|
+
if (!node2) {
|
|
4801
|
+
const Face2 = () => {
|
|
4802
|
+
const team = useTeam(context);
|
|
4803
|
+
const faces = useFaces(team);
|
|
4804
|
+
const members = HandOffViewUtil.members(team, target);
|
|
4805
|
+
return members.length ? /* @__PURE__ */ React.createElement(RoomFace, {
|
|
4806
|
+
members,
|
|
4807
|
+
faces,
|
|
4808
|
+
size: 16,
|
|
4809
|
+
working: []
|
|
4810
|
+
}) : null;
|
|
4811
|
+
};
|
|
4812
|
+
node2 = /* @__PURE__ */ React.createElement(Face2, null);
|
|
4813
|
+
icons.set(key, node2);
|
|
4814
|
+
}
|
|
4815
|
+
return node2;
|
|
4816
|
+
}
|
|
4817
|
+
function composerAddon(context) {
|
|
4818
|
+
const icons = new Map;
|
|
4819
|
+
const send = (conversation, to) => void context.pi.server.prompt(conversation.sessionId, {
|
|
4820
|
+
clientMessageId: ChannelsUtil.newId("handoff-ask"),
|
|
4821
|
+
message: HandOff.ask(context.pi.ui.language, to),
|
|
4822
|
+
streamingBehavior: "followUp"
|
|
4823
|
+
}).catch((error) => context.pi.ui.notify(ChannelViews.message(error), "error"));
|
|
4824
|
+
return {
|
|
4825
|
+
actions: (conversation) => {
|
|
4826
|
+
const { team } = context.service.state;
|
|
4827
|
+
if (conversation.group === NAME || team.agents.length === 0 && team.channels.length === 0) {
|
|
4828
|
+
return [];
|
|
4829
|
+
}
|
|
4830
|
+
const w = ChannelViews.words(context.pi);
|
|
4831
|
+
const Forward = ChannelViews.icon(context.pi, "Forward");
|
|
4832
|
+
const agents = team.agents.filter((agent) => !agent.temporary).map((agent) => ({
|
|
4833
|
+
key: `handoff:agent:${agent.id}`,
|
|
4834
|
+
label: agent.name,
|
|
4835
|
+
detail: agent.role.split(`
|
|
4836
|
+
`)[0],
|
|
4837
|
+
group: w.agents,
|
|
4838
|
+
icon: icon(context, { kind: "agent", id: agent.id }, icons),
|
|
4839
|
+
run: () => send(conversation, `@${agent.name}`)
|
|
4840
|
+
}));
|
|
4841
|
+
const channels = team.channels.map((channel) => ({
|
|
4842
|
+
key: `handoff:channel:${channel.id}`,
|
|
4843
|
+
label: `#${channel.name}`,
|
|
4844
|
+
detail: channel.topic,
|
|
4845
|
+
group: w.channels,
|
|
4846
|
+
icon: icon(context, { kind: "channel", id: channel.id }, icons),
|
|
4847
|
+
run: () => send(conversation, `#${channel.name}`)
|
|
4848
|
+
}));
|
|
4849
|
+
return [{ key: "handoff", label: w.handOff, detail: w.handOffDetail, icon: /* @__PURE__ */ React.createElement(Forward, {
|
|
4850
|
+
size: 16
|
|
4851
|
+
}), items: [...agents, ...channels] }];
|
|
4852
|
+
},
|
|
4853
|
+
subscribe: (listener) => context.service.subscribe(listener)
|
|
4854
|
+
};
|
|
4855
|
+
}
|
|
4856
|
+
HandOffView.composerAddon = composerAddon;
|
|
4857
|
+
})(HandOffView ||= {});
|
|
4858
|
+
|
|
4859
|
+
// web-src/round-rules.ts
|
|
4860
|
+
var ChannelRounds;
|
|
4861
|
+
((ChannelRounds) => {
|
|
4862
|
+
const SHORT = 20;
|
|
4863
|
+
const MIN_PAIRS = 8;
|
|
4864
|
+
const ALIKE = 0.8;
|
|
4865
|
+
const PING_PONG = 4;
|
|
4866
|
+
const NEW = 0.35;
|
|
4867
|
+
const CHANGES = new Set(["edit", "write", "delete", "move"]);
|
|
4868
|
+
function scale(watchedAt, pages, now) {
|
|
4869
|
+
if (watchedAt !== undefined && now - watchedAt < 2 * WATCH_MS) {
|
|
4870
|
+
return 2;
|
|
4871
|
+
}
|
|
4872
|
+
return pages === undefined || pages > 0 ? 1 : 0.5;
|
|
4294
4873
|
}
|
|
4295
|
-
|
|
4296
|
-
function
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
const [dialog, setDialog] = React.useState();
|
|
4300
|
-
const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
|
|
4301
|
-
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
4302
|
-
const act = (action) => () => {
|
|
4303
|
-
Promise.resolve().then(action).catch(fail);
|
|
4304
|
-
};
|
|
4305
|
-
const openSession = async () => {
|
|
4306
|
-
if (!agent.sessionFile) {
|
|
4874
|
+
ChannelRounds.scale = scale;
|
|
4875
|
+
function idle(said, progress) {
|
|
4876
|
+
const last = said.at(-1);
|
|
4877
|
+
if (!last) {
|
|
4307
4878
|
return;
|
|
4308
4879
|
}
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
if (session) {
|
|
4314
|
-
await pi.server.abort(session.sessionId);
|
|
4880
|
+
const pairs = said.map((item) => pairsOf(item.text));
|
|
4881
|
+
const mine = pairs[pairs.length - 1];
|
|
4882
|
+
if (mine.length >= MIN_PAIRS && pairs.slice(0, -1).some((other) => alike(other, mine) >= ALIKE)) {
|
|
4883
|
+
return "repeat";
|
|
4315
4884
|
}
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
await service.resetAgent(agent.id);
|
|
4320
|
-
context.sessions.delete(agent.id);
|
|
4321
|
-
pi.ui.notify(ChannelWords.format(w.resetDone, { name: agent.name }), "info");
|
|
4322
|
-
});
|
|
4323
|
-
const copyCwd = act(async () => {
|
|
4324
|
-
if (await copy(cwd)) {
|
|
4325
|
-
pi.ui.notify(ChannelWords.format(w.copied, { path: cwd }), "info");
|
|
4885
|
+
const recent = said.slice(-3);
|
|
4886
|
+
if (recent.length === 3 && recent.every((item) => units(item.text).join("").length < SHORT)) {
|
|
4887
|
+
return "agree";
|
|
4326
4888
|
}
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
const
|
|
4330
|
-
const
|
|
4331
|
-
|
|
4332
|
-
if (!messages.some((message) => message.role === "assistant")) {
|
|
4333
|
-
pi.ui.notify(ChannelWords.format(w.nothingToExport, { name: agent.name }), "info");
|
|
4889
|
+
const run = said.slice(-PING_PONG);
|
|
4890
|
+
const authors = new Set(run.map((item) => item.author));
|
|
4891
|
+
const alternate = run.every((item, i) => i === 0 || item.author !== run[i - 1].author);
|
|
4892
|
+
const start = said.length - PING_PONG;
|
|
4893
|
+
if (progress || start <= 0 || authors.size !== 2 || !alternate) {
|
|
4334
4894
|
return;
|
|
4335
4895
|
}
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
const show = (next) => () => setDialog(next);
|
|
4345
|
-
const item = (key, label, glyph, run, options = {}) => ({
|
|
4346
|
-
key,
|
|
4347
|
-
label,
|
|
4348
|
-
icon: icon(glyph),
|
|
4349
|
-
run,
|
|
4350
|
-
...options
|
|
4351
|
-
});
|
|
4352
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(MoreMenu, {
|
|
4353
|
-
pi,
|
|
4354
|
-
label: agent.name,
|
|
4355
|
-
items: () => [
|
|
4356
|
-
[
|
|
4357
|
-
...agent.temporary ? [item("keep", w.keep, "UserPlus", keep)] : [],
|
|
4358
|
-
item("pin", agent.pinned ? w.unpin : w.pin, agent.pinned ? "PinOff" : "Pin", pin)
|
|
4359
|
-
],
|
|
4360
|
-
[item("stop", w.stop, "Square", stop, { disabled: !working && !agent.sessionFile }), item("restart", w.restart, "RotateCcw", restart)],
|
|
4361
|
-
[
|
|
4362
|
-
item("settings", w.agentSettings, "SlidersHorizontal", show("settings")),
|
|
4363
|
-
item("rename", w.rename, "Pencil", show("rename")),
|
|
4364
|
-
item("role", w.editRole, "ScrollText", show("role")),
|
|
4365
|
-
item("move", w.moveTo, "FolderInput", show("move")),
|
|
4366
|
-
item("copy", w.copyCwd, "Copy", copyCwd)
|
|
4367
|
-
],
|
|
4368
|
-
[
|
|
4369
|
-
item("card", w.shareCard, "Contact", show("card")),
|
|
4370
|
-
item("export", w.exportChat, "Download", exportMarkdown),
|
|
4371
|
-
item("join", w.joinChannel, "UserPlus", show("join"))
|
|
4372
|
-
],
|
|
4373
|
-
[item("delete", w.deleteAgent, "Trash2", remove, { danger: true })]
|
|
4374
|
-
]
|
|
4375
|
-
}), dialog === "settings" && /* @__PURE__ */ React.createElement(AgentSettingsDialog, {
|
|
4376
|
-
context,
|
|
4377
|
-
agent,
|
|
4378
|
-
onClose: () => setDialog(undefined)
|
|
4379
|
-
}), dialog === "rename" && /* @__PURE__ */ React.createElement(RenameDialog, {
|
|
4380
|
-
context,
|
|
4381
|
-
agent,
|
|
4382
|
-
onClose: () => setDialog(undefined)
|
|
4383
|
-
}), dialog === "role" && /* @__PURE__ */ React.createElement(RoleDialog, {
|
|
4384
|
-
context,
|
|
4385
|
-
agent,
|
|
4386
|
-
onClose: () => setDialog(undefined)
|
|
4387
|
-
}), dialog === "join" && /* @__PURE__ */ React.createElement(JoinDialog, {
|
|
4388
|
-
context,
|
|
4389
|
-
agent,
|
|
4390
|
-
onClose: () => setDialog(undefined)
|
|
4391
|
-
}), dialog === "card" && /* @__PURE__ */ React.createElement(CardDialog, {
|
|
4392
|
-
context,
|
|
4393
|
-
agent,
|
|
4394
|
-
onClose: () => setDialog(undefined)
|
|
4395
|
-
}), dialog === "move" && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
|
|
4396
|
-
initial: cwd,
|
|
4397
|
-
onClose: () => setDialog(undefined),
|
|
4398
|
-
onPick: async (path) => {
|
|
4399
|
-
setDialog(undefined);
|
|
4400
|
-
if (path !== cwd) {
|
|
4401
|
-
await service.updateAgent(agent.id, { cwd: path }).catch(fail);
|
|
4402
|
-
context.sessions.delete(agent.id);
|
|
4896
|
+
const seen = new Set(pairs.slice(0, start).flat());
|
|
4897
|
+
for (const own of pairs.slice(start)) {
|
|
4898
|
+
const fresh = own.filter((pair) => !seen.has(pair)).length;
|
|
4899
|
+
if (own.length === 0 || fresh / own.length >= NEW) {
|
|
4900
|
+
return;
|
|
4901
|
+
}
|
|
4902
|
+
for (const pair of own) {
|
|
4903
|
+
seen.add(pair);
|
|
4403
4904
|
}
|
|
4404
4905
|
}
|
|
4405
|
-
|
|
4406
|
-
}
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
}
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
}
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
maxLength: 32,
|
|
4491
|
-
autoFocus: true,
|
|
4492
|
-
onChange: (event) => setName(event.target.value)
|
|
4493
|
-
})), error && /* @__PURE__ */ React.createElement("div", {
|
|
4494
|
-
className: "tac-error"
|
|
4495
|
-
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4496
|
-
className: "tac-dialog-actions"
|
|
4497
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
4498
|
-
type: "submit",
|
|
4499
|
-
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4500
|
-
disabled: busy || !name.trim() || name.trim() === agent.name
|
|
4501
|
-
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4502
|
-
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4503
|
-
})))));
|
|
4906
|
+
return "pingPong";
|
|
4907
|
+
}
|
|
4908
|
+
ChannelRounds.idle = idle;
|
|
4909
|
+
function day(now) {
|
|
4910
|
+
const date = new Date(now);
|
|
4911
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
4912
|
+
}
|
|
4913
|
+
ChannelRounds.day = day;
|
|
4914
|
+
function limits(stored) {
|
|
4915
|
+
const given = stored ?? {};
|
|
4916
|
+
const pick = (key) => LIMIT_CHOICES[key].includes(given[key]) ? given[key] : DEFAULT_LIMITS[key];
|
|
4917
|
+
return { answer: pick("answer"), channelDay: pick("channelDay"), allDay: pick("allDay") };
|
|
4918
|
+
}
|
|
4919
|
+
ChannelRounds.limits = limits;
|
|
4920
|
+
function today(stored, now) {
|
|
4921
|
+
const current = day(now);
|
|
4922
|
+
return stored?.day === current ? stored : { day: current, total: 0, channels: {} };
|
|
4923
|
+
}
|
|
4924
|
+
ChannelRounds.today = today;
|
|
4925
|
+
function spend(stored, channelId, tokens, now) {
|
|
4926
|
+
const current = today(stored, now);
|
|
4927
|
+
return { ...current, total: current.total + tokens, channels: { ...current.channels, [channelId]: (current.channels[channelId] ?? 0) + tokens } };
|
|
4928
|
+
}
|
|
4929
|
+
ChannelRounds.spend = spend;
|
|
4930
|
+
function held(spent, limits2, channelId, hops, granted = false) {
|
|
4931
|
+
if (granted) {
|
|
4932
|
+
return;
|
|
4933
|
+
}
|
|
4934
|
+
if (limits2.allDay > 0 && spent.total >= limits2.allDay) {
|
|
4935
|
+
return "all";
|
|
4936
|
+
}
|
|
4937
|
+
if (hops > 0 && limits2.channelDay > 0 && (spent.channels[channelId] ?? 0) >= limits2.channelDay) {
|
|
4938
|
+
return "channel";
|
|
4939
|
+
}
|
|
4940
|
+
return;
|
|
4941
|
+
}
|
|
4942
|
+
ChannelRounds.held = held;
|
|
4943
|
+
function changedFiles(entries) {
|
|
4944
|
+
for (const entry of entries) {
|
|
4945
|
+
const message = entry?.message;
|
|
4946
|
+
if (entry?.type !== "message" || message?.role !== "assistant" || !Array.isArray(message.content)) {
|
|
4947
|
+
continue;
|
|
4948
|
+
}
|
|
4949
|
+
for (const part of message.content) {
|
|
4950
|
+
if (part?.type !== "toolCall") {
|
|
4951
|
+
continue;
|
|
4952
|
+
}
|
|
4953
|
+
if (CHANGES.has(String(part.name)) || part.name === "agent_tool" && CHANGES.has(String(part.arguments?.kind))) {
|
|
4954
|
+
return true;
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
}
|
|
4958
|
+
return false;
|
|
4959
|
+
}
|
|
4960
|
+
ChannelRounds.changedFiles = changedFiles;
|
|
4961
|
+
function units(text) {
|
|
4962
|
+
return text.replace(/@[^\s@#,,。::]+/g, " ").toLowerCase().match(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]|[\p{L}\p{N}]+/gu) ?? [];
|
|
4963
|
+
}
|
|
4964
|
+
function pairsOf(text) {
|
|
4965
|
+
const words = units(text);
|
|
4966
|
+
return words.length === 1 ? words : words.slice(1).map((word, i) => `${words[i]} ${word}`);
|
|
4967
|
+
}
|
|
4968
|
+
function alike(a, b) {
|
|
4969
|
+
if (a.length === 0 || b.length === 0) {
|
|
4970
|
+
return 0;
|
|
4971
|
+
}
|
|
4972
|
+
const left = new Map;
|
|
4973
|
+
for (const pair of a) {
|
|
4974
|
+
left.set(pair, (left.get(pair) ?? 0) + 1);
|
|
4975
|
+
}
|
|
4976
|
+
let common = 0;
|
|
4977
|
+
for (const pair of b) {
|
|
4978
|
+
const n = left.get(pair) ?? 0;
|
|
4979
|
+
if (n > 0) {
|
|
4980
|
+
left.set(pair, n - 1);
|
|
4981
|
+
common++;
|
|
4982
|
+
}
|
|
4983
|
+
}
|
|
4984
|
+
return 2 * common / (a.length + b.length);
|
|
4985
|
+
}
|
|
4986
|
+
})(ChannelRounds ||= {});
|
|
4987
|
+
|
|
4988
|
+
// web-src/limit-settings.tsx
|
|
4989
|
+
function amount(pi, tokens) {
|
|
4990
|
+
return tokens > 0 ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(tokens) : ChannelWords.of(pi.ui.language).noLimit;
|
|
4504
4991
|
}
|
|
4505
|
-
function
|
|
4506
|
-
const
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
onChange: (event) => setRole(event.target.value)
|
|
4525
|
-
}), error && /* @__PURE__ */ React.createElement("div", {
|
|
4526
|
-
className: "tac-error"
|
|
4527
|
-
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4528
|
-
className: "tac-dialog-actions"
|
|
4529
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
4530
|
-
type: "submit",
|
|
4531
|
-
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4532
|
-
disabled: busy || !role.trim() || role.trim() === agent.role
|
|
4533
|
-
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4534
|
-
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4535
|
-
})))));
|
|
4992
|
+
function useLimits(pi) {
|
|
4993
|
+
const read = React.useCallback(async () => ({
|
|
4994
|
+
limits: ChannelRounds.limits(await pi.storage.get(Keys.LIMITS)),
|
|
4995
|
+
...((today) => ({ spent: today.total, channels: today.channels }))(ChannelRounds.today(await pi.storage.get(Keys.SPENT), Date.now()))
|
|
4996
|
+
}), [pi]);
|
|
4997
|
+
const [value, setValue] = React.useState({ limits: ChannelRounds.limits(undefined), spent: 0, channels: {} });
|
|
4998
|
+
React.useEffect(() => {
|
|
4999
|
+
let live = true;
|
|
5000
|
+
const load = () => void read().then((next) => live && setValue(next), () => {
|
|
5001
|
+
return;
|
|
5002
|
+
});
|
|
5003
|
+
load();
|
|
5004
|
+
const stop = pi.storage.onChange((keys) => (keys.includes(Keys.LIMITS) || keys.includes(Keys.SPENT)) && load());
|
|
5005
|
+
return () => {
|
|
5006
|
+
live = false;
|
|
5007
|
+
stop();
|
|
5008
|
+
};
|
|
5009
|
+
}, [pi, read]);
|
|
5010
|
+
return value;
|
|
4536
5011
|
}
|
|
4537
|
-
function
|
|
4538
|
-
const
|
|
4539
|
-
const
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
5012
|
+
function limitSettings(pi, service) {
|
|
5013
|
+
const words = () => ChannelWords.of(pi.ui.language);
|
|
5014
|
+
const row = (key) => function Choices() {
|
|
5015
|
+
const { limits } = useLimits(pi);
|
|
5016
|
+
const pick = (value) => void service.setLimits({ [key]: value }).catch((error) => pi.ui.notify(String(error?.message ?? error), "error"));
|
|
5017
|
+
return /* @__PURE__ */ React.createElement("fieldset", {
|
|
5018
|
+
className: "ta-segmented",
|
|
5019
|
+
"aria-label": words()[key === "answer" ? "limitAnswer" : key === "channelDay" ? "limitChannelDay" : "limitAllDay"]
|
|
5020
|
+
}, LIMIT_CHOICES[key].map((value) => /* @__PURE__ */ React.createElement("button", {
|
|
5021
|
+
key: value,
|
|
5022
|
+
type: "button",
|
|
5023
|
+
"aria-pressed": limits[key] === value,
|
|
5024
|
+
className: limits[key] === value ? "ta-on" : "",
|
|
5025
|
+
onClick: () => pick(value)
|
|
5026
|
+
}, amount(pi, value))));
|
|
5027
|
+
};
|
|
5028
|
+
function Spent() {
|
|
5029
|
+
const { spent } = useLimits(pi);
|
|
5030
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
5031
|
+
className: "tac-limit-spent"
|
|
5032
|
+
}, spent > 0 ? amount(pi, spent) : "0");
|
|
5033
|
+
}
|
|
5034
|
+
return {
|
|
5035
|
+
title: () => words().limitsTitle,
|
|
5036
|
+
icon: pi.ui.icons.Coins ?? pi.ui.icons.Gauge,
|
|
5037
|
+
group: "ta",
|
|
5038
|
+
rows: [
|
|
5039
|
+
{ key: "answer", label: () => words().limitAnswer, description: () => words().limitAnswerHint, render: row("answer") },
|
|
5040
|
+
{ key: "channelDay", label: () => words().limitChannelDay, description: () => words().limitChannelDayHint, render: row("channelDay") },
|
|
5041
|
+
{ key: "allDay", label: () => words().limitAllDay, description: () => words().limitAllDayHint, render: row("allDay") },
|
|
5042
|
+
{ key: "spent", label: () => words().limitSpent, render: Spent }
|
|
5043
|
+
]
|
|
4549
5044
|
};
|
|
4550
|
-
return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
|
|
4551
|
-
title: `${w.joinChannel} · ${agent.name}`,
|
|
4552
|
-
onClose
|
|
4553
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
4554
|
-
className: "tac-dialog"
|
|
4555
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
4556
|
-
className: "tac-pick-list"
|
|
4557
|
-
}, open.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4558
|
-
compact: true,
|
|
4559
|
-
title: w.noChannelToJoin
|
|
4560
|
-
}), open.map((channel) => /* @__PURE__ */ React.createElement("button", {
|
|
4561
|
-
key: channel.id,
|
|
4562
|
-
type: "button",
|
|
4563
|
-
className: "tac-pick",
|
|
4564
|
-
disabled: channel.members.length >= MAX_MEMBERS,
|
|
4565
|
-
onClick: () => join(channel.id, channel.name)
|
|
4566
|
-
}, /* @__PURE__ */ React.createElement(Hash, {
|
|
4567
|
-
size: 16
|
|
4568
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
4569
|
-
className: "tac-pick-text"
|
|
4570
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
4571
|
-
className: "tac-pick-name"
|
|
4572
|
-
}, channel.name), /* @__PURE__ */ React.createElement("span", {
|
|
4573
|
-
className: "tac-pick-role"
|
|
4574
|
-
}, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(channel.members.length) })))))), error && /* @__PURE__ */ React.createElement("div", {
|
|
4575
|
-
className: "tac-error"
|
|
4576
|
-
}, error)));
|
|
4577
5045
|
}
|
|
4578
5046
|
|
|
4579
5047
|
// ../ta-protocol/esm/common/team-protocol.js
|
|
@@ -4864,6 +5332,31 @@ var RoomUtil;
|
|
|
4864
5332
|
}
|
|
4865
5333
|
RoomUtil.rows = rows;
|
|
4866
5334
|
})(RoomUtil ||= {});
|
|
5335
|
+
function MessagePictures({ context, channelId, message, alt }) {
|
|
5336
|
+
const { pi, service } = context;
|
|
5337
|
+
const images = message.images ?? [];
|
|
5338
|
+
const [sources, setSources] = React.useState({});
|
|
5339
|
+
const ids = images.map((image) => image.id).join(",");
|
|
5340
|
+
React.useEffect(() => {
|
|
5341
|
+
let live = true;
|
|
5342
|
+
for (const id of ids ? ids.split(",") : []) {
|
|
5343
|
+
service.picture(channelId, id).then((data) => live && data && setSources((current) => ({ ...current, [id]: data })));
|
|
5344
|
+
}
|
|
5345
|
+
return () => {
|
|
5346
|
+
live = false;
|
|
5347
|
+
};
|
|
5348
|
+
}, [service, channelId, ids]);
|
|
5349
|
+
const ChatImages = pi.ui.ChatImages;
|
|
5350
|
+
if (!images.length || !ChatImages) {
|
|
5351
|
+
return null;
|
|
5352
|
+
}
|
|
5353
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
5354
|
+
className: "tac-pics"
|
|
5355
|
+
}, /* @__PURE__ */ React.createElement(ChatImages, {
|
|
5356
|
+
alt,
|
|
5357
|
+
images: images.map((image) => ({ key: image.id, src: sources[image.id], width: image.w, height: image.h }))
|
|
5358
|
+
}));
|
|
5359
|
+
}
|
|
4867
5360
|
function Mentions({ text, agents }) {
|
|
4868
5361
|
const names = new Set(agents.map((agent) => agent.name.toLowerCase()));
|
|
4869
5362
|
const parts = text.split(/(@[^\s@#,,。::]+)/);
|
|
@@ -5023,6 +5516,19 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5023
5516
|
service.messages(channelId);
|
|
5024
5517
|
}
|
|
5025
5518
|
}, [service, channelId]);
|
|
5519
|
+
const page = pi.ui.useView(CHANNEL_PAGE);
|
|
5520
|
+
const inFront = !!channelId && (!!fixed || !!page?.shown);
|
|
5521
|
+
const lastAt = ChannelSeenUtil.lastAt(messages);
|
|
5522
|
+
const resting = working.length === 0;
|
|
5523
|
+
React.useEffect(() => {
|
|
5524
|
+
if (!channelId || !inFront || !resting) {
|
|
5525
|
+
return;
|
|
5526
|
+
}
|
|
5527
|
+
const look = () => document.visibilityState === "visible" && context.seen.look(channelId, Math.max(Date.now(), lastAt ?? 0));
|
|
5528
|
+
look();
|
|
5529
|
+
document.addEventListener("visibilitychange", look);
|
|
5530
|
+
return () => document.removeEventListener("visibilitychange", look);
|
|
5531
|
+
}, [context, channelId, inFront, resting, lastAt]);
|
|
5026
5532
|
React.useEffect(() => {
|
|
5027
5533
|
if (!channelId) {
|
|
5028
5534
|
return;
|
|
@@ -5054,19 +5560,11 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5054
5560
|
}
|
|
5055
5561
|
const members = membersOf(state.team, channel);
|
|
5056
5562
|
const agentOf = (id) => state.team.agents.find((agent) => agent.id === id);
|
|
5563
|
+
const reply = ChannelsText.replyOf(channel);
|
|
5564
|
+
const lead = members.find((agent) => !(channel.muted ?? []).includes(agent.id));
|
|
5565
|
+
const placeholder = reply === "all" ? w.placeholderAll : reply === "lead" && lead ? w.placeholderLead : w.placeholder;
|
|
5057
5566
|
const name = (id) => ChannelsText.authorName(state.team, id, { user: w.you, ta: w.ta });
|
|
5058
5567
|
const time = (at) => SidebarUtil.time(at, pi.ui.language);
|
|
5059
|
-
const mention = (agent) => ({
|
|
5060
|
-
key: agent.id,
|
|
5061
|
-
label: agent.name,
|
|
5062
|
-
icon: /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
5063
|
-
agent,
|
|
5064
|
-
faces,
|
|
5065
|
-
size: 20
|
|
5066
|
-
}),
|
|
5067
|
-
detail: agent.id === channel.members[0] ? w.lead : undefined,
|
|
5068
|
-
insert: `@${agent.name} `
|
|
5069
|
-
});
|
|
5070
5568
|
return /* @__PURE__ */ React.createElement("div", {
|
|
5071
5569
|
className: "tac-room-page"
|
|
5072
5570
|
}, /* @__PURE__ */ React.createElement(NoticeBar, {
|
|
@@ -5115,7 +5613,12 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5115
5613
|
className: "tac-msg-col"
|
|
5116
5614
|
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
5117
5615
|
className: "tac-msg-name"
|
|
5118
|
-
}, message.byName ?? w.owner), /* @__PURE__ */ React.createElement(
|
|
5616
|
+
}, message.byName ?? w.owner), /* @__PURE__ */ React.createElement(MessagePictures, {
|
|
5617
|
+
context,
|
|
5618
|
+
channelId: channel.id,
|
|
5619
|
+
message,
|
|
5620
|
+
alt: message.byName ?? w.owner
|
|
5621
|
+
}), message.text && /* @__PURE__ */ React.createElement("div", {
|
|
5119
5622
|
className: "tac-msg-bubble",
|
|
5120
5623
|
title: time(message.at)
|
|
5121
5624
|
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
@@ -5123,7 +5626,12 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5123
5626
|
agents: state.team.agents
|
|
5124
5627
|
})))) : message.author === USER ? /* @__PURE__ */ React.createElement("div", {
|
|
5125
5628
|
className: "ta-message ta-user tac-mine"
|
|
5126
|
-
}, /* @__PURE__ */ React.createElement(
|
|
5629
|
+
}, /* @__PURE__ */ React.createElement(MessagePictures, {
|
|
5630
|
+
context,
|
|
5631
|
+
channelId: channel.id,
|
|
5632
|
+
message,
|
|
5633
|
+
alt: w.you
|
|
5634
|
+
}), message.text && /* @__PURE__ */ React.createElement("div", {
|
|
5127
5635
|
className: "ta-bubble"
|
|
5128
5636
|
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
5129
5637
|
text: message.text,
|
|
@@ -5167,12 +5675,12 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5167
5675
|
}))), ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") })))), /* @__PURE__ */ React.createElement("div", {
|
|
5168
5676
|
className: "tac-chat-bottom"
|
|
5169
5677
|
}, /* @__PURE__ */ React.createElement(Composer, {
|
|
5170
|
-
placeholder: ChannelWords.format(
|
|
5678
|
+
placeholder: ChannelWords.format(placeholder, { channel: channel.name, lead: lead?.name ?? "" }),
|
|
5171
5679
|
draft: channel.id,
|
|
5172
5680
|
mentions: members.map((agent) => ({ name: agent.name, detail: agent.role.split(`
|
|
5173
5681
|
`)[0] })),
|
|
5682
|
+
mentionLabel: w.mentionMember,
|
|
5174
5683
|
actions: [
|
|
5175
|
-
members.map(mention),
|
|
5176
5684
|
[
|
|
5177
5685
|
{
|
|
5178
5686
|
key: "notice",
|
|
@@ -5202,7 +5710,8 @@ function ChannelRoom({ context, channelId: fixed }) {
|
|
|
5202
5710
|
}
|
|
5203
5711
|
]
|
|
5204
5712
|
],
|
|
5205
|
-
|
|
5713
|
+
images: { side: 1600, bytes: 1024 * 1024 },
|
|
5714
|
+
onSend: (text, images) => service.post(channel.id, text, images ?? [])
|
|
5206
5715
|
})));
|
|
5207
5716
|
}
|
|
5208
5717
|
|
|
@@ -5448,17 +5957,27 @@ async function editChannelTopic(context, channel) {
|
|
|
5448
5957
|
await context.service.updateChannel(channel.id, { topic });
|
|
5449
5958
|
}
|
|
5450
5959
|
}
|
|
5960
|
+
async function exportChannel(context, channel) {
|
|
5961
|
+
const { pi, service } = context;
|
|
5962
|
+
const w = ChannelViews.words(pi);
|
|
5963
|
+
const messages = await service.messages(channel.id);
|
|
5964
|
+
if (!messages.some((message) => message.text.trim())) {
|
|
5965
|
+
pi.ui.notify(ChannelWords.format(w.noMessagesToExport, { channel: channel.name }), "info");
|
|
5966
|
+
return;
|
|
5967
|
+
}
|
|
5968
|
+
download2(`${channel.name}.md`, ChannelsText.channelMarkdown(service.state.team, channel, messages, { user: w.you, ta: w.ta }));
|
|
5969
|
+
}
|
|
5451
5970
|
function ChannelMenu({ context, channel, working }) {
|
|
5452
|
-
const { pi, service
|
|
5453
|
-
const
|
|
5971
|
+
const { pi, service } = context;
|
|
5972
|
+
const unread = useChannelUnseen(context, channel.id);
|
|
5454
5973
|
const w = ChannelViews.words(pi);
|
|
5455
5974
|
const icon = (name) => ChannelViews.maybeIcon(pi, name, null, 15);
|
|
5456
5975
|
const act = (action2) => () => {
|
|
5457
5976
|
Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
|
|
5458
5977
|
};
|
|
5459
|
-
const
|
|
5978
|
+
const manage = ChannelsUtil.may(service.state.team).manage(channel.id);
|
|
5460
5979
|
const pin = act(() => service.updateChannel(channel.id, { pinned: !channel.pinned }));
|
|
5461
|
-
const markRead = act(() =>
|
|
5980
|
+
const markRead = act(() => context.seen.mark(channel.id, !unread, ChannelSeenUtil.lastAt(service.state.messages[channel.id])));
|
|
5462
5981
|
const rename = act(() => renameChannel(context, channel));
|
|
5463
5982
|
const editTopic = act(() => editChannelTopic(context, channel));
|
|
5464
5983
|
const members = act(() => {
|
|
@@ -5469,14 +5988,7 @@ function ChannelMenu({ context, channel, working }) {
|
|
|
5469
5988
|
await TeamActions.stop(context, working);
|
|
5470
5989
|
pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info");
|
|
5471
5990
|
});
|
|
5472
|
-
const exportMarkdown = act(
|
|
5473
|
-
const messages = await service.messages(channel.id);
|
|
5474
|
-
if (!messages.some((message) => message.text.trim())) {
|
|
5475
|
-
pi.ui.notify(ChannelWords.format(w.noMessagesToExport, { channel: channel.name }), "info");
|
|
5476
|
-
return;
|
|
5477
|
-
}
|
|
5478
|
-
download2(`${channel.name}.md`, ChannelsText.channelMarkdown(service.state.team, channel, messages, { user: w.you, ta: w.ta }));
|
|
5479
|
-
});
|
|
5991
|
+
const exportMarkdown = act(() => exportChannel(context, channel));
|
|
5480
5992
|
const remove = act(() => deleteChannel(context, channel));
|
|
5481
5993
|
const budget = ChannelsUtil.budgetOf(channel);
|
|
5482
5994
|
const budgets = [
|
|
@@ -5504,13 +6016,16 @@ function ChannelMenu({ context, channel, working }) {
|
|
|
5504
6016
|
label: channel.name,
|
|
5505
6017
|
items: () => [
|
|
5506
6018
|
[
|
|
5507
|
-
item("pin", channel.pinned ? w.unpin : w.pin, channel.pinned ? "PinOff" : "Pin", pin),
|
|
6019
|
+
...manage ? [item("pin", channel.pinned ? w.unpin : w.pin, channel.pinned ? "PinOff" : "Pin", pin)] : [],
|
|
5508
6020
|
item("read", unread ? w.markRead : w.markUnread, unread ? "MessageSquareText" : "MessageSquareDot", markRead)
|
|
5509
6021
|
],
|
|
5510
|
-
[
|
|
5511
|
-
|
|
6022
|
+
[
|
|
6023
|
+
...manage ? [item("rename", w.rename, "Pencil", rename), item("topic", w.editTopic, "Text", editTopic)] : [],
|
|
6024
|
+
item("members", w.showMembers, "Users", members)
|
|
6025
|
+
],
|
|
6026
|
+
manage ? budgets.map(budgetItem) : [],
|
|
5512
6027
|
[item("stop", w.stopAnswering, "Square", stop, { disabled: working.length === 0 }), item("export", w.exportChat, "Download", exportMarkdown)],
|
|
5513
|
-
[item("delete", w.deleteChannel, "Trash2", remove, { danger: true })]
|
|
6028
|
+
manage ? [item("delete", w.deleteChannel, "Trash2", remove, { danger: true })] : []
|
|
5514
6029
|
]
|
|
5515
6030
|
});
|
|
5516
6031
|
}
|
|
@@ -5559,6 +6074,9 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5559
6074
|
const Trash = ChannelViews.icon(pi, "Trash2");
|
|
5560
6075
|
const Sliders = pi.ui.icons.SlidersHorizontal ?? ChannelViews.icon(pi, "Pencil");
|
|
5561
6076
|
const members = membersOf(team, channel);
|
|
6077
|
+
const may = ChannelsUtil.may(team);
|
|
6078
|
+
const manage = may.manage(channel.id);
|
|
6079
|
+
const edit = may.edit(channel.id);
|
|
5562
6080
|
const models = new Set(members.map((agent) => agent.model ?? ""));
|
|
5563
6081
|
const shared = models.size === 1 ? [...models][0] : undefined;
|
|
5564
6082
|
const muted = channel.muted ?? [];
|
|
@@ -5592,7 +6110,7 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5592
6110
|
className: "tac-members-title"
|
|
5593
6111
|
}, /* @__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", {
|
|
5594
6112
|
className: "tac-members-label"
|
|
5595
|
-
}, /* @__PURE__ */ React.createElement("span", null, w.members, " · ", members.length), /* @__PURE__ */ React.createElement("span", {
|
|
6113
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.members, " · ", members.length), edit && /* @__PURE__ */ React.createElement("span", {
|
|
5596
6114
|
className: "tac-members-model",
|
|
5597
6115
|
title: w.sameModelHint
|
|
5598
6116
|
}, /* @__PURE__ */ React.createElement("span", null, w.sameModel), /* @__PURE__ */ React.createElement(pi.ui.ModelPicker, {
|
|
@@ -5601,7 +6119,7 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5601
6119
|
label: w.sameModelHint,
|
|
5602
6120
|
disabled: !!busy,
|
|
5603
6121
|
onChange: setModel
|
|
5604
|
-
}))), /* @__PURE__ */ React.createElement("button", {
|
|
6122
|
+
}))), edit && /* @__PURE__ */ React.createElement("button", {
|
|
5605
6123
|
type: "button",
|
|
5606
6124
|
className: "tac-member-main",
|
|
5607
6125
|
onClick: () => ui.set({ adding: true })
|
|
@@ -5619,6 +6137,7 @@ function MemberList({ context, team, channel, faces, working }) {
|
|
|
5619
6137
|
const answering = working.includes(agent.id);
|
|
5620
6138
|
const detail = answering ? w.replying : off ? w.muted : agent.role.split(`
|
|
5621
6139
|
`)[0] ?? "";
|
|
6140
|
+
const edits = may.agent(agent.id);
|
|
5622
6141
|
return /* @__PURE__ */ React.createElement("div", {
|
|
5623
6142
|
key: agent.id,
|
|
5624
6143
|
className: `tac-member${off ? " tac-muted" : ""}`
|
|
@@ -5649,9 +6168,9 @@ ${agent.role}`,
|
|
|
5649
6168
|
title: w.temporary
|
|
5650
6169
|
}, w.temporaryTag)), /* @__PURE__ */ React.createElement("span", {
|
|
5651
6170
|
className: `tac-member-detail${answering ? " tac-live" : ""}`
|
|
5652
|
-
}, detail))), /* @__PURE__ */ React.createElement("span", {
|
|
6171
|
+
}, detail))), (edits || manage) && /* @__PURE__ */ React.createElement("span", {
|
|
5653
6172
|
className: "tac-member-actions"
|
|
5654
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
6173
|
+
}, edits && /* @__PURE__ */ React.createElement("button", {
|
|
5655
6174
|
type: "button",
|
|
5656
6175
|
className: "tac-action",
|
|
5657
6176
|
title: w.agentSettings,
|
|
@@ -5660,7 +6179,7 @@ ${agent.role}`,
|
|
|
5660
6179
|
onClick: () => setEditing(agent)
|
|
5661
6180
|
}, /* @__PURE__ */ React.createElement(Sliders, {
|
|
5662
6181
|
size: 15
|
|
5663
|
-
})), agent.temporary && /* @__PURE__ */ React.createElement("button", {
|
|
6182
|
+
})), edits && agent.temporary && /* @__PURE__ */ React.createElement("button", {
|
|
5664
6183
|
type: "button",
|
|
5665
6184
|
className: "tac-action",
|
|
5666
6185
|
title: w.keep,
|
|
@@ -5669,7 +6188,7 @@ ${agent.role}`,
|
|
|
5669
6188
|
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"))
|
|
5670
6189
|
}, /* @__PURE__ */ React.createElement(UserPlus, {
|
|
5671
6190
|
size: 15
|
|
5672
|
-
})), !lead && /* @__PURE__ */ React.createElement("button", {
|
|
6191
|
+
})), manage && !lead && /* @__PURE__ */ React.createElement("button", {
|
|
5673
6192
|
type: "button",
|
|
5674
6193
|
className: "tac-action",
|
|
5675
6194
|
title: w.makeLead,
|
|
@@ -5678,7 +6197,7 @@ ${agent.role}`,
|
|
|
5678
6197
|
onClick: () => change(agent, "lead")
|
|
5679
6198
|
}, /* @__PURE__ */ React.createElement(Crown, {
|
|
5680
6199
|
size: 15
|
|
5681
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
6200
|
+
})), manage && /* @__PURE__ */ React.createElement("button", {
|
|
5682
6201
|
type: "button",
|
|
5683
6202
|
className: `tac-action${off ? " tac-on" : ""}`,
|
|
5684
6203
|
title: off ? w.unmute : w.mute,
|
|
@@ -5688,7 +6207,7 @@ ${agent.role}`,
|
|
|
5688
6207
|
onClick: () => change(agent, off ? "unmute" : "mute")
|
|
5689
6208
|
}, /* @__PURE__ */ React.createElement(BellOff, {
|
|
5690
6209
|
size: 15
|
|
5691
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
6210
|
+
})), edits && /* @__PURE__ */ React.createElement("button", {
|
|
5692
6211
|
type: "button",
|
|
5693
6212
|
className: "tac-action",
|
|
5694
6213
|
title: w.reset,
|
|
@@ -5697,7 +6216,7 @@ ${agent.role}`,
|
|
|
5697
6216
|
onClick: () => reset(agent)
|
|
5698
6217
|
}, /* @__PURE__ */ React.createElement(RotateCcw, {
|
|
5699
6218
|
size: 15
|
|
5700
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
6219
|
+
})), manage && /* @__PURE__ */ React.createElement("button", {
|
|
5701
6220
|
type: "button",
|
|
5702
6221
|
className: "tac-action",
|
|
5703
6222
|
title: members.length === 1 ? w.onlyMember : w.remove,
|
|
@@ -5709,12 +6228,13 @@ ${agent.role}`,
|
|
|
5709
6228
|
}))));
|
|
5710
6229
|
}), /* @__PURE__ */ React.createElement(ChannelSettings, {
|
|
5711
6230
|
context,
|
|
5712
|
-
channel
|
|
6231
|
+
channel,
|
|
6232
|
+
manage
|
|
5713
6233
|
})), editing && /* @__PURE__ */ React.createElement(AgentSettingsDialog, {
|
|
5714
6234
|
context,
|
|
5715
6235
|
agent: editing,
|
|
5716
6236
|
onClose: () => setEditing(undefined)
|
|
5717
|
-
}), /* @__PURE__ */ React.createElement("div", {
|
|
6237
|
+
}), manage && /* @__PURE__ */ React.createElement("div", {
|
|
5718
6238
|
className: "tac-members-foot"
|
|
5719
6239
|
}, confirming ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
|
|
5720
6240
|
className: "tac-members-ask"
|
|
@@ -5737,12 +6257,12 @@ ${agent.role}`,
|
|
|
5737
6257
|
size: 14
|
|
5738
6258
|
}), w.deleteChannel)));
|
|
5739
6259
|
}
|
|
5740
|
-
function ChannelSettings({ context, channel }) {
|
|
6260
|
+
function ChannelSettings({ context, channel, manage }) {
|
|
5741
6261
|
const { pi, service } = context;
|
|
5742
6262
|
const w = ChannelViews.words(pi);
|
|
5743
6263
|
const Chevron = ChannelViews.icon(pi, "ChevronRight");
|
|
5744
6264
|
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
5745
|
-
const row = (label, value, edit) => /* @__PURE__ */ React.createElement("button", {
|
|
6265
|
+
const row = (label, value, edit) => manage ? /* @__PURE__ */ React.createElement("button", {
|
|
5746
6266
|
type: "button",
|
|
5747
6267
|
className: "tac-setting",
|
|
5748
6268
|
onClick: () => edit().catch(fail)
|
|
@@ -5752,10 +6272,16 @@ function ChannelSettings({ context, channel }) {
|
|
|
5752
6272
|
className: "tac-setting-value"
|
|
5753
6273
|
}, value), /* @__PURE__ */ React.createElement(Chevron, {
|
|
5754
6274
|
size: 15
|
|
5755
|
-
}))
|
|
6275
|
+
})) : /* @__PURE__ */ React.createElement("div", {
|
|
6276
|
+
className: "tac-setting"
|
|
6277
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
6278
|
+
className: "tac-setting-label"
|
|
6279
|
+
}, label), /* @__PURE__ */ React.createElement("span", {
|
|
6280
|
+
className: "tac-setting-value"
|
|
6281
|
+
}, value));
|
|
5756
6282
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
5757
6283
|
className: "tac-members-sep"
|
|
5758
|
-
}), row(w.channelName, channel.name, () => renameChannel(context, channel)), row(w.topic, channel.topic ?? w.notSet, () => editChannelTopic(context, channel)), /* @__PURE__ */ React.createElement("div", {
|
|
6284
|
+
}), 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", {
|
|
5759
6285
|
className: "tac-setting"
|
|
5760
6286
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
5761
6287
|
className: "tac-setting-label"
|
|
@@ -5766,7 +6292,7 @@ function ChannelSettings({ context, channel }) {
|
|
|
5766
6292
|
})), /* @__PURE__ */ React.createElement(ChannelLimits, {
|
|
5767
6293
|
context,
|
|
5768
6294
|
channel
|
|
5769
|
-
}));
|
|
6295
|
+
})));
|
|
5770
6296
|
}
|
|
5771
6297
|
function ChannelLimits({ context, channel }) {
|
|
5772
6298
|
const { pi, service } = context;
|
|
@@ -5779,6 +6305,12 @@ function ChannelLimits({ context, channel }) {
|
|
|
5779
6305
|
["normal", w.budgetNormalWord],
|
|
5780
6306
|
["long", w.budgetLongWord]
|
|
5781
6307
|
];
|
|
6308
|
+
const reply = ChannelsText.replyOf(channel);
|
|
6309
|
+
const replies = [
|
|
6310
|
+
["mentioned", w.replyMentionedWord],
|
|
6311
|
+
["lead", w.replyLeadWord],
|
|
6312
|
+
["all", w.replyAllWord]
|
|
6313
|
+
];
|
|
5782
6314
|
const daily = [null, ...LIMIT_CHOICES.channelDay];
|
|
5783
6315
|
const own = channel.dailyLimit ?? null;
|
|
5784
6316
|
const limit = channel.dailyLimit ?? limits.channelDay;
|
|
@@ -5797,6 +6329,8 @@ function ChannelLimits({ context, channel }) {
|
|
|
5797
6329
|
className: "tac-limits"
|
|
5798
6330
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
5799
6331
|
className: "tac-limit-head"
|
|
6332
|
+
}, /* @__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", {
|
|
6333
|
+
className: "tac-limit-head"
|
|
5800
6334
|
}, /* @__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", {
|
|
5801
6335
|
className: "tac-limit-head"
|
|
5802
6336
|
}, /* @__PURE__ */ React.createElement("span", null, w.dailyLimit), /* @__PURE__ */ React.createElement("span", {
|
|
@@ -5816,7 +6350,8 @@ function MemberPicker({ context, team, channel, faces }) {
|
|
|
5816
6350
|
const Check = ChannelViews.icon(pi, "Check");
|
|
5817
6351
|
const UserPlus = ChannelViews.icon(pi, "UserPlus");
|
|
5818
6352
|
const back = () => ui.set({ adding: false });
|
|
5819
|
-
const friends = useFriends(pi).filter(() => !!pi.rooms && channel.by !== "ta" && !channel.shared);
|
|
6353
|
+
const friends = useFriends(pi).filter(() => !!pi.rooms && !team.may && channel.by !== "ta" && !channel.shared);
|
|
6354
|
+
const creates = ChannelsUtil.may(team).create;
|
|
5820
6355
|
const [pickedFriends, setPickedFriends] = React.useState([]);
|
|
5821
6356
|
const toggleFriend = (id) => setPickedFriends(pickedFriends.includes(id) ? pickedFriends.filter((other) => other !== id) : [...pickedFriends, id]);
|
|
5822
6357
|
const { busy, error, submit } = useSubmit(() => pickedFriends.length > 0 ? becomeGroup(context, channel, pickedFriends, picked) : service.addMembers(channel.id, picked), back);
|
|
@@ -5915,7 +6450,7 @@ function MemberPicker({ context, team, channel, faces }) {
|
|
|
5915
6450
|
})));
|
|
5916
6451
|
}), pickedFriends.length > 0 && /* @__PURE__ */ React.createElement("div", {
|
|
5917
6452
|
className: "tac-members-note"
|
|
5918
|
-
}, w.shareGroupHint)), /* @__PURE__ */ React.createElement("div", {
|
|
6453
|
+
}, w.shareGroupHint)), creates && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
5919
6454
|
className: "tac-members-sep"
|
|
5920
6455
|
}), /* @__PURE__ */ React.createElement("button", {
|
|
5921
6456
|
type: "button",
|
|
@@ -5929,7 +6464,7 @@ function MemberPicker({ context, team, channel, faces }) {
|
|
|
5929
6464
|
className: "tac-member-text"
|
|
5930
6465
|
}, /* @__PURE__ */ React.createElement("span", {
|
|
5931
6466
|
className: "tac-member-name"
|
|
5932
|
-
}, w.newAgent)))), error && /* @__PURE__ */ React.createElement("div", {
|
|
6467
|
+
}, w.newAgent))))), error && /* @__PURE__ */ React.createElement("div", {
|
|
5933
6468
|
className: "tac-empty tac-error"
|
|
5934
6469
|
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
5935
6470
|
className: "tac-members-foot"
|
|
@@ -5962,14 +6497,19 @@ class ChannelPartners {
|
|
|
5962
6497
|
start() {
|
|
5963
6498
|
const stopService = this.context.service.subscribe(() => this.refresh());
|
|
5964
6499
|
const stopUi = this.context.ui.subscribe(() => this.refresh());
|
|
6500
|
+
const stopSeen = this.context.seen.subscribe(() => this.refresh());
|
|
5965
6501
|
this.refresh();
|
|
5966
6502
|
return () => {
|
|
5967
6503
|
stopService();
|
|
5968
6504
|
stopUi();
|
|
6505
|
+
stopSeen();
|
|
5969
6506
|
};
|
|
5970
6507
|
}
|
|
5971
6508
|
add() {
|
|
5972
|
-
const { pi } = this.context;
|
|
6509
|
+
const { pi, service } = this.context;
|
|
6510
|
+
if (!ChannelsUtil.may(service.state.team).create) {
|
|
6511
|
+
return [];
|
|
6512
|
+
}
|
|
5973
6513
|
return [{ key: "agent", label: ChannelViews.words(pi).newAgent, icon: ChannelViews.icon(pi, "Bot"), run: () => newAgent(this.context) }];
|
|
5974
6514
|
}
|
|
5975
6515
|
async group(members) {
|
|
@@ -5998,8 +6538,8 @@ class ChannelPartners {
|
|
|
5998
6538
|
};
|
|
5999
6539
|
}
|
|
6000
6540
|
refresh() {
|
|
6001
|
-
const { pi, service,
|
|
6002
|
-
const { team, messages, working, loaded } = service.state;
|
|
6541
|
+
const { pi, service, seen } = this.context;
|
|
6542
|
+
const { team, messages, working, answered, loaded } = service.state;
|
|
6003
6543
|
if (!loaded) {
|
|
6004
6544
|
return;
|
|
6005
6545
|
}
|
|
@@ -6013,11 +6553,10 @@ class ChannelPartners {
|
|
|
6013
6553
|
}
|
|
6014
6554
|
}
|
|
6015
6555
|
const agents = ChannelsUtil.standing(team);
|
|
6016
|
-
const { fresh } = ui.state;
|
|
6017
6556
|
const language = pi.ui.language;
|
|
6018
6557
|
const signature = [
|
|
6019
6558
|
language,
|
|
6020
|
-
...agents.map((agent) => [agent.id, agent.name, agent.role, agent.face, agent.sessionFile ?? "", agent.cwd ?? ""].join(":")),
|
|
6559
|
+
...agents.map((agent) => [agent.id, agent.name, agent.role, agent.face, agent.sessionFile ?? "", agent.cwd ?? "", answered[agent.id] ?? ""].join(":")),
|
|
6021
6560
|
...channels.map((channel) => [
|
|
6022
6561
|
channel.id,
|
|
6023
6562
|
channel.name,
|
|
@@ -6025,7 +6564,7 @@ class ChannelPartners {
|
|
|
6025
6564
|
channel.members.join("/"),
|
|
6026
6565
|
messages[channel.id]?.at(-1)?.id ?? "",
|
|
6027
6566
|
(working[channel.id] ?? []).join("/"),
|
|
6028
|
-
|
|
6567
|
+
seen.unseen(channel.id, messages[channel.id], (working[channel.id] ?? []).length > 0) ? 1 : 0
|
|
6029
6568
|
].join(":"))
|
|
6030
6569
|
].join("|");
|
|
6031
6570
|
if (signature === this.signature) {
|
|
@@ -6048,14 +6587,16 @@ class ChannelPartners {
|
|
|
6048
6587
|
face: this.agentFace(agent.id),
|
|
6049
6588
|
icon: ChannelViews.icon(pi, "Bot"),
|
|
6050
6589
|
about: agent.role,
|
|
6051
|
-
chat: agent.sessionFile ? { sessionFile: agent.sessionFile } : undefined,
|
|
6590
|
+
chat: agent.sessionFile ? { sessionFile: agent.sessionFile, seenAt: this.context.service.state.answered[agent.id] } : undefined,
|
|
6052
6591
|
location: agent.cwd,
|
|
6053
6592
|
open: () => ChannelViews.openAgent(this.context, agent.id),
|
|
6054
|
-
|
|
6593
|
+
info: () => AgentActions.profile(this.context, agent),
|
|
6594
|
+
menu: () => AgentActions.menu(this.context, agent, this.answering(agent.id)),
|
|
6595
|
+
...ChannelsUtil.may(this.context.service.state.team).agent(agent.id) ? { remove: { key: "delete", label: w.deleteAgent, danger: true, run: () => void deleteAgent(this.context, agent) } } : {}
|
|
6055
6596
|
};
|
|
6056
6597
|
}
|
|
6057
6598
|
channel(channel, w) {
|
|
6058
|
-
const { pi, service,
|
|
6599
|
+
const { pi, service, seen } = this.context;
|
|
6059
6600
|
const { team, messages, working } = service.state;
|
|
6060
6601
|
const busy = working[channel.id] ?? [];
|
|
6061
6602
|
const name = (id) => ChannelsText.authorName(team, id, { user: w.you, ta: w.ta });
|
|
@@ -6068,15 +6609,52 @@ class ChannelPartners {
|
|
|
6068
6609
|
icon: ChannelViews.icon(pi, "Hash"),
|
|
6069
6610
|
about: channel.topic ?? membersOf(team, channel).map((agent) => agent.name).join("、"),
|
|
6070
6611
|
chat: {
|
|
6071
|
-
last: busy.length > 0 ? ChannelWords.format(w.answeringNow, { name: busy.map(name).join("、") }) : last ? `${name(last.author)}:${last.text.replace(/\s+/g, " ")}` : undefined,
|
|
6612
|
+
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,
|
|
6072
6613
|
at: SidebarUtil.channelAt(channel, messages[channel.id]),
|
|
6073
|
-
unseen:
|
|
6614
|
+
unseen: seen.unseen(channel.id, messages[channel.id], busy.length > 0),
|
|
6074
6615
|
busy: busy.length > 0
|
|
6075
6616
|
},
|
|
6076
6617
|
open: () => this.context.showChannel(channel.id),
|
|
6077
|
-
|
|
6618
|
+
info: () => {
|
|
6619
|
+
this.context.showChannel(channel.id);
|
|
6620
|
+
this.context.showMembers();
|
|
6621
|
+
},
|
|
6622
|
+
menu: () => this.channelMenu(channel),
|
|
6623
|
+
...ChannelsUtil.may(service.state.team).manage(channel.id) ? { remove: { key: "delete", label: w.deleteChannel, danger: true, run: () => void deleteChannel(this.context, channel) } } : {}
|
|
6078
6624
|
};
|
|
6079
6625
|
}
|
|
6626
|
+
answering(id) {
|
|
6627
|
+
return Object.values(this.context.service.state.working).some((ids) => ids.includes(id));
|
|
6628
|
+
}
|
|
6629
|
+
channelMenu(channel) {
|
|
6630
|
+
const { pi, service, seen } = this.context;
|
|
6631
|
+
const w = ChannelViews.words(pi);
|
|
6632
|
+
const icon = (name) => ChannelViews.icon(pi, name);
|
|
6633
|
+
const fail = (error) => pi.ui.notify(ChannelViews.message(error), "error");
|
|
6634
|
+
const messages = service.state.messages[channel.id];
|
|
6635
|
+
const working = service.state.working[channel.id] ?? [];
|
|
6636
|
+
const unread = seen.unseen(channel.id, messages, working.length > 0);
|
|
6637
|
+
return [
|
|
6638
|
+
[
|
|
6639
|
+
{
|
|
6640
|
+
key: "read",
|
|
6641
|
+
label: unread ? w.markRead : w.markUnread,
|
|
6642
|
+
icon: icon(unread ? "MessageSquareText" : "MessageSquareDot"),
|
|
6643
|
+
run: () => seen.mark(channel.id, !unread, ChannelSeenUtil.lastAt(messages))
|
|
6644
|
+
}
|
|
6645
|
+
],
|
|
6646
|
+
[
|
|
6647
|
+
{
|
|
6648
|
+
key: "stop",
|
|
6649
|
+
label: w.stopAnswering,
|
|
6650
|
+
icon: icon("Square"),
|
|
6651
|
+
disabled: working.length === 0,
|
|
6652
|
+
run: () => void TeamActions.stop(this.context, working).then(() => pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info")).catch(fail)
|
|
6653
|
+
},
|
|
6654
|
+
{ key: "export", label: w.exportChat, icon: icon("Download"), run: () => void exportChannel(this.context, channel).catch(fail) }
|
|
6655
|
+
]
|
|
6656
|
+
];
|
|
6657
|
+
}
|
|
6080
6658
|
agentFace(id) {
|
|
6081
6659
|
return this.face(`agent:${id}`, function AgentFace({ size, state: { team, working } }) {
|
|
6082
6660
|
const faces = useFaces(team);
|
|
@@ -6515,9 +7093,12 @@ var NO_HOME_ITEMS = [];
|
|
|
6515
7093
|
function AgentsSidebar({ context, partners = false }) {
|
|
6516
7094
|
const { pi, service, ui } = context;
|
|
6517
7095
|
const state = useChannels(service);
|
|
6518
|
-
const { query, draft, channelId
|
|
7096
|
+
const { query, draft, channelId } = useUi(ui);
|
|
7097
|
+
const channelsSeen = React.useSyncExternalStore((listener) => context.seen.subscribe(listener), () => context.seen.state);
|
|
7098
|
+
const unread = (id) => ChannelSeenUtil.unseen(channelsSeen, id, state.messages[id], (state.working[id] ?? []).length > 0);
|
|
6519
7099
|
const w = ChannelViews.words(pi);
|
|
6520
7100
|
const faces = useFaces(state.team);
|
|
7101
|
+
const may = ChannelsUtil.may(state.team);
|
|
6521
7102
|
const serverCwd = useServerCwd(pi) ?? "";
|
|
6522
7103
|
const shownSession = pi.ui.useSessionId();
|
|
6523
7104
|
const double = pi.ui.useView(DOUBLE_PAGE);
|
|
@@ -6659,7 +7240,7 @@ function AgentsSidebar({ context, partners = false }) {
|
|
|
6659
7240
|
cwd,
|
|
6660
7241
|
working: !!where
|
|
6661
7242
|
}),
|
|
6662
|
-
swipe: swipePinDelete(pi, !!agent.pinned, (pinned) => context.service.updateAgent(agent.id, { pinned }), () => deleteAgent(context, agent))
|
|
7243
|
+
swipe: may.agent(agent.id) ? swipePinDelete(pi, !!agent.pinned, (pinned) => context.service.updateAgent(agent.id, { pinned }), () => deleteAgent(context, agent)) : undefined
|
|
6663
7244
|
});
|
|
6664
7245
|
};
|
|
6665
7246
|
const chatAgents = partners && lastLines ? agents.filter((agent) => lastLines.has(agent.id)) : [];
|
|
@@ -6763,7 +7344,7 @@ function AgentsSidebar({ context, partners = false }) {
|
|
|
6763
7344
|
count: channels.length + groupItems.length + chatAgents.length,
|
|
6764
7345
|
folded,
|
|
6765
7346
|
onFold: fold,
|
|
6766
|
-
alert: channels.some((channel) => unread
|
|
7347
|
+
alert: channels.some((channel) => unread(channel.id)) || groupItems.some((item) => item.unseen)
|
|
6767
7348
|
}, SidebarUtil.byTime([
|
|
6768
7349
|
...channels.map((channel) => ({
|
|
6769
7350
|
channel,
|
|
@@ -6807,7 +7388,7 @@ function AgentsSidebar({ context, partners = false }) {
|
|
|
6807
7388
|
}),
|
|
6808
7389
|
preview,
|
|
6809
7390
|
live: busy.length > 0,
|
|
6810
|
-
dot: busy.length > 0 ? "running" : unread
|
|
7391
|
+
dot: busy.length > 0 ? "running" : unread(channel.id) ? "attention" : undefined,
|
|
6811
7392
|
time: SidebarUtil.time(last?.at ?? channel.createdAt, pi.ui.language),
|
|
6812
7393
|
hint: channel.topic ? `#${channel.name} · ${channel.topic}` : `#${channel.name}`,
|
|
6813
7394
|
selected: !!channelPage?.shown && channelId === channel.id,
|
|
@@ -6818,7 +7399,7 @@ function AgentsSidebar({ context, partners = false }) {
|
|
|
6818
7399
|
channel,
|
|
6819
7400
|
working: busy
|
|
6820
7401
|
}),
|
|
6821
|
-
swipe: swipePinDelete(pi, !!channel.pinned, (pinned) => context.service.updateChannel(channel.id, { pinned }), () => deleteChannel(context, channel))
|
|
7402
|
+
swipe: may.manage(channel.id) ? swipePinDelete(pi, !!channel.pinned, (pinned) => context.service.updateChannel(channel.id, { pinned }), () => deleteChannel(context, channel)) : undefined
|
|
6822
7403
|
});
|
|
6823
7404
|
})), agents.length > 0 && /* @__PURE__ */ React.createElement(Section, {
|
|
6824
7405
|
id: "members",
|
|
@@ -7030,6 +7611,9 @@ var STYLE = `
|
|
|
7030
7611
|
.tac-chat-empty strong { margin-top: 6px; color: var(--ta-text); font-size: calc(16px * var(--ta-font-scale)); }
|
|
7031
7612
|
.tac-chat-hint { margin-top: 4px; font-size: calc(12px * var(--ta-font-scale)); }
|
|
7032
7613
|
.tac-mine { margin: 6px 0 2px; }
|
|
7614
|
+
/* Pictures of a message (ui.ChatImages), no bubble around them, on the side of who sent them. */
|
|
7615
|
+
.tac-pics { margin: 1px 0 3px; }
|
|
7616
|
+
.tac-mine .tac-pics { align-self: flex-end; }
|
|
7033
7617
|
.tac-msg { display: flex; align-items: flex-start; gap: 10px; }
|
|
7034
7618
|
.tac-msg.tac-first { margin-top: 10px; }
|
|
7035
7619
|
.tac-msg-face { display: flex; justify-content: center; width: 28px; flex: none; }
|
|
@@ -7243,6 +7827,10 @@ textarea.tac-input { resize: vertical; min-height: 56px; line-height: 1.5; }
|
|
|
7243
7827
|
.tac-members-scroll > .tac-pick { margin: 1px 0; }
|
|
7244
7828
|
.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); }
|
|
7245
7829
|
.tac-pick.tac-on .tac-check { border-color: var(--ta-green); background: var(--ta-green); }
|
|
7830
|
+
.tac-setting-model > :last-child { flex: none; width: auto; max-width: 60%; margin-left: auto; }
|
|
7831
|
+
.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; }
|
|
7832
|
+
.tac-setting-model .ta-model-field:not(:disabled):hover { background: var(--ta-hover); color: var(--ta-text); }
|
|
7833
|
+
.tac-setting-model .ta-model-field > svg { width: 15px; height: 15px; }
|
|
7246
7834
|
.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); }
|
|
7247
7835
|
.tac-members-ask { flex: 1; min-width: 0; color: var(--ta-body); font-size: calc(12.5px * var(--ta-font-scale)); }
|
|
7248
7836
|
.tac-members-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
@@ -7519,13 +8107,16 @@ function activate(pi) {
|
|
|
7519
8107
|
const removeStyle = injectStyle();
|
|
7520
8108
|
const service = new ChannelsClient(pi.storage, (request) => pi.callHost("request", request));
|
|
7521
8109
|
const ui = new ChannelsUiStore;
|
|
8110
|
+
const seen = new ChannelSeenBook(pi.storage);
|
|
8111
|
+
const stopSeen = seen.start();
|
|
7522
8112
|
const context = {
|
|
7523
8113
|
pi,
|
|
7524
8114
|
service,
|
|
7525
8115
|
ui,
|
|
8116
|
+
seen,
|
|
7526
8117
|
sessions: new Map,
|
|
7527
8118
|
showChannel: (channelId) => {
|
|
7528
|
-
ui.set({ channelId, adding: false
|
|
8119
|
+
ui.set({ channelId, adding: false });
|
|
7529
8120
|
pi.ui.showView(CHANNEL_PAGE);
|
|
7530
8121
|
},
|
|
7531
8122
|
showMembers: (adding = false) => {
|
|
@@ -7579,7 +8170,8 @@ function activate(pi) {
|
|
|
7579
8170
|
}),
|
|
7580
8171
|
render: () => /* @__PURE__ */ React.createElement(ChannelRoom, {
|
|
7581
8172
|
context
|
|
7582
|
-
})
|
|
8173
|
+
}),
|
|
8174
|
+
navigation: false
|
|
7583
8175
|
});
|
|
7584
8176
|
pi.registerView("agent", {
|
|
7585
8177
|
title: () => ui.state.draft?.name || ChannelWords.of(pi.ui.language).newAgentName,
|
|
@@ -7589,7 +8181,18 @@ function activate(pi) {
|
|
|
7589
8181
|
}),
|
|
7590
8182
|
render: () => /* @__PURE__ */ React.createElement(NewAgentPage, {
|
|
7591
8183
|
context
|
|
7592
|
-
})
|
|
8184
|
+
}),
|
|
8185
|
+
navigation: false
|
|
8186
|
+
});
|
|
8187
|
+
pi.registerView("agent-info", {
|
|
8188
|
+
title: () => ChannelWords.of(pi.ui.language).profileTitle,
|
|
8189
|
+
icon: ChannelViews.icon(pi, "Bot"),
|
|
8190
|
+
render: () => /* @__PURE__ */ React.createElement(AgentInfoView, {
|
|
8191
|
+
context
|
|
8192
|
+
}),
|
|
8193
|
+
location: "panel",
|
|
8194
|
+
navigation: false,
|
|
8195
|
+
order: 61
|
|
7593
8196
|
});
|
|
7594
8197
|
pi.registerView("members", {
|
|
7595
8198
|
title: () => ChannelWords.of(pi.ui.language).showMembers,
|
|
@@ -7598,6 +8201,7 @@ function activate(pi) {
|
|
|
7598
8201
|
context
|
|
7599
8202
|
}),
|
|
7600
8203
|
location: "panel",
|
|
8204
|
+
navigation: false,
|
|
7601
8205
|
order: 60
|
|
7602
8206
|
});
|
|
7603
8207
|
registerCardOpener(context);
|
|
@@ -7605,14 +8209,9 @@ function activate(pi) {
|
|
|
7605
8209
|
context,
|
|
7606
8210
|
...props
|
|
7607
8211
|
}));
|
|
7608
|
-
const stopFocus = service.onFocus((channelId) => {
|
|
7609
|
-
if (!ui.state.fresh.includes(channelId)) {
|
|
7610
|
-
ui.set({ fresh: [...ui.state.fresh, channelId] });
|
|
7611
|
-
}
|
|
7612
|
-
});
|
|
7613
8212
|
service.load();
|
|
7614
8213
|
return () => {
|
|
7615
|
-
|
|
8214
|
+
stopSeen();
|
|
7616
8215
|
stopPartners?.();
|
|
7617
8216
|
service.dispose();
|
|
7618
8217
|
removeStyle();
|