@celljs/ta-channels 4.34.0 → 4.35.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 +2 -2
- package/README.md +2 -2
- package/extension/index.mjs +9 -45
- package/host/index.mjs +62 -44
- package/package.json +4 -4
- package/web/index.js +1559 -1556
package/web/index.js
CHANGED
|
@@ -1100,8 +1100,9 @@ var ChannelsUtil;
|
|
|
1100
1100
|
}
|
|
1101
1101
|
ChannelsUtil.updateChannel = updateChannel;
|
|
1102
1102
|
function standing(team) {
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1103
|
+
const inTeams = new Set(taskChannels(team).flatMap((channel) => channel.members));
|
|
1104
|
+
const inOwn = new Set(team.channels.filter((channel) => channel.by !== "ta").flatMap((channel) => channel.members));
|
|
1105
|
+
return team.agents.filter((agent) => !agent.temporary || !inTeams.has(agent.id) || inOwn.has(agent.id));
|
|
1105
1106
|
}
|
|
1106
1107
|
ChannelsUtil.standing = standing;
|
|
1107
1108
|
function taskChannels(team) {
|
|
@@ -4366,1685 +4367,1687 @@ class ChannelsClient {
|
|
|
4366
4367
|
}
|
|
4367
4368
|
}
|
|
4368
4369
|
|
|
4369
|
-
//
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4370
|
+
// ../ta-protocol/esm/common/team-protocol.js
|
|
4371
|
+
var TA_OWNER = "owner";
|
|
4372
|
+
var TA_UNDECLARED = "extensions.install";
|
|
4373
|
+
var TaPermissionUtil;
|
|
4374
|
+
(function(TaPermissionUtil2) {
|
|
4375
|
+
function read(pi) {
|
|
4376
|
+
const given = pi === null || pi === undefined ? undefined : pi.permissions;
|
|
4377
|
+
const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
|
|
4378
|
+
const host2 = map(given === null || given === undefined ? undefined : given.host);
|
|
4379
|
+
const tools = map(given === null || given === undefined ? undefined : given.tools);
|
|
4380
|
+
return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
|
|
4381
|
+
}
|
|
4382
|
+
TaPermissionUtil2.read = read;
|
|
4383
|
+
function host(manifest, method, kind) {
|
|
4384
|
+
var _a, _b, _c, _d;
|
|
4385
|
+
const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
|
|
4386
|
+
const own = (key) => {
|
|
4387
|
+
var _a2;
|
|
4388
|
+
return (_a2 = Object.getOwnPropertyDescriptor(host2, key)) === null || _a2 === undefined ? undefined : _a2.value;
|
|
4379
4389
|
};
|
|
4380
|
-
|
|
4381
|
-
return friends;
|
|
4382
|
-
}
|
|
4383
|
-
async function createShared(context, title, friends, agents) {
|
|
4384
|
-
const { pi } = context;
|
|
4385
|
-
const rooms = pi.rooms;
|
|
4386
|
-
if (!rooms) {
|
|
4387
|
-
throw new Error(ChannelViews.words(pi).sharedNeedsRooms);
|
|
4390
|
+
return (_d = (_c = (_b = kind ? own(`${method}:${kind}`) : undefined) !== null && _b !== undefined ? _b : own(method)) !== null && _c !== undefined ? _c : own("*")) !== null && _d !== undefined ? _d : TA_UNDECLARED;
|
|
4388
4391
|
}
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4392
|
+
TaPermissionUtil2.host = host;
|
|
4393
|
+
})(TaPermissionUtil || (TaPermissionUtil = {}));
|
|
4394
|
+
var action = (id, en, zh, tw, ja, more = {}) => ({
|
|
4395
|
+
id,
|
|
4396
|
+
area: id.split(".")[0],
|
|
4397
|
+
title: { en, "zh-CN": zh, ...tw ? { "zh-TW": tw } : {}, ...ja ? { "ja-JP": ja } : {} },
|
|
4398
|
+
...more
|
|
4399
|
+
});
|
|
4400
|
+
var TA_ACTIONS = [
|
|
4401
|
+
action("chat.view", "See conversations", "查看对话", "檢視對話", "会話を確認"),
|
|
4402
|
+
action("chat.send", "Send in conversations", "在对话里发消息", "在對話裡發訊息", "会話にメッセージを送信"),
|
|
4403
|
+
action("chat.create", "Start conversations", "新建对话", "新建對話", "新しい会話を開始"),
|
|
4404
|
+
action("chat.stop", "Stop a reply", "停止回复", "停止回覆", "返信を停止"),
|
|
4405
|
+
action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话", "改名、歸檔、關閉對話", "会話の名前変更、アーカイブ、クローズ"),
|
|
4406
|
+
action("chat.share", "Share by a link", "生成分享链接", "生成分享連結", "共有リンクで共有"),
|
|
4407
|
+
action("agent.view", "See agents", "查看智能体", "檢視智慧體", "エージェントを確認"),
|
|
4408
|
+
action("agent.use", "Talk with agents", "和智能体对话", "和智慧體對話", "エージェントと対話"),
|
|
4409
|
+
action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体", "新建、修改、刪除智慧體", "エージェントを作成・変更・削除"),
|
|
4410
|
+
action("channel.view", "See channels", "查看频道", "檢視頻道", "チャネルを確認"),
|
|
4411
|
+
action("channel.post", "Post in channels", "在频道里发言", "在頻道里發言", "チャネルに投稿"),
|
|
4412
|
+
action("channel.manage", "Create and change channels", "新建、管理频道", "新建、管理頻道", "チャネルを作成・管理"),
|
|
4413
|
+
action("task.view", "See tasks", "查看任务", "檢視任務", "タスクを確認"),
|
|
4414
|
+
action("task.create", "Hand out tasks", "派任务", "派任務", "タスクを割り当て"),
|
|
4415
|
+
action("task.manage", "Take over and stop tasks", "接管、停止任务", "接管、停止任務", "タスクを引き継ぎ・停止"),
|
|
4416
|
+
action("files.read", "Read files", "读文件", "讀檔案", "ファイルを読取", { scoped: true }),
|
|
4417
|
+
action("files.write", "Change files", "改文件", "改檔案", "ファイルを変更", { scoped: true }),
|
|
4418
|
+
action("commands.run", "Let Ta run commands", "让 Ta 运行命令", "讓 Ta 執行命令", "Ta にコマンド実行を許可", { scoped: true, risky: true }),
|
|
4419
|
+
action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
|
|
4420
|
+
action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
|
|
4421
|
+
action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
|
|
4422
|
+
action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更", { grant: "single" }),
|
|
4423
|
+
action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
|
|
4424
|
+
action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
|
|
4425
|
+
action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
|
|
4426
|
+
action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
|
|
4427
|
+
action("extensions.trust", "Decide how far others' extensions reach", "决定别人的扩展能用到哪一步", "決定別人的擴充功能能用到哪一步", "他の人の拡張機能に許す範囲を決める", { risky: true }),
|
|
4428
|
+
action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
|
|
4429
|
+
action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
|
|
4430
|
+
action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
|
|
4431
|
+
action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
|
|
4432
|
+
action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
|
|
4433
|
+
action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
|
|
4434
|
+
action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
|
|
4435
|
+
];
|
|
4436
|
+
var TA_OWNER_ACTIONS = [
|
|
4437
|
+
action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
|
|
4438
|
+
action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
|
|
4439
|
+
];
|
|
4440
|
+
var OWNER_AREAS = ["desktop"];
|
|
4441
|
+
var TaActionUtil;
|
|
4442
|
+
(function(TaActionUtil2) {
|
|
4443
|
+
const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
|
|
4444
|
+
const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
|
|
4445
|
+
function info(id) {
|
|
4446
|
+
return byId.get(id);
|
|
4447
|
+
}
|
|
4448
|
+
TaActionUtil2.info = info;
|
|
4449
|
+
function title(id, language) {
|
|
4450
|
+
var _a;
|
|
4451
|
+
var _b, _c;
|
|
4452
|
+
const title2 = (_a = titled.get(id)) === null || _a === undefined ? undefined : _a.title;
|
|
4453
|
+
if (!title2) {
|
|
4454
|
+
return id;
|
|
4455
|
+
}
|
|
4456
|
+
return TaLanguageUtil.pick(language, {
|
|
4457
|
+
"zh-CN": title2["zh-CN"],
|
|
4458
|
+
"zh-TW": (_b = title2["zh-TW"]) !== null && _b !== undefined ? _b : title2["zh-CN"],
|
|
4459
|
+
"en-US": title2.en,
|
|
4460
|
+
"ja-JP": (_c = title2["ja-JP"]) !== null && _c !== undefined ? _c : title2.en
|
|
4394
4461
|
});
|
|
4395
4462
|
}
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4463
|
+
TaActionUtil2.title = title;
|
|
4464
|
+
function grantable(id) {
|
|
4465
|
+
const info2 = byId.get(id);
|
|
4466
|
+
return !!info2 && !OWNER_AREAS.includes(info2.area);
|
|
4467
|
+
}
|
|
4468
|
+
TaActionUtil2.grantable = grantable;
|
|
4469
|
+
function inRoles(id) {
|
|
4470
|
+
var _a;
|
|
4471
|
+
return grantable(id) && ((_a = byId.get(id)) === null || _a === undefined ? undefined : _a.grant) !== "single";
|
|
4472
|
+
}
|
|
4473
|
+
TaActionUtil2.inRoles = inRoles;
|
|
4474
|
+
function inside(dir, path) {
|
|
4475
|
+
const base = dir.replace(/\/+$/, "");
|
|
4476
|
+
return path === base || path.startsWith(`${base}/`) || base === "";
|
|
4477
|
+
}
|
|
4478
|
+
TaActionUtil2.inside = inside;
|
|
4479
|
+
})(TaActionUtil || (TaActionUtil = {}));
|
|
4409
4480
|
|
|
4410
|
-
// web-src/
|
|
4411
|
-
var
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4481
|
+
// web-src/notice-util.ts
|
|
4482
|
+
var NoticeUtil;
|
|
4483
|
+
((NoticeUtil) => {
|
|
4484
|
+
const PARTS = {
|
|
4485
|
+
决定: "decisions",
|
|
4486
|
+
decisions: "decisions",
|
|
4487
|
+
约定: "conventions",
|
|
4488
|
+
conventions: "conventions",
|
|
4489
|
+
待办: "todo",
|
|
4490
|
+
"to do": "todo",
|
|
4491
|
+
todo: "todo",
|
|
4492
|
+
"to-do": "todo"
|
|
4493
|
+
};
|
|
4494
|
+
function counts(text) {
|
|
4495
|
+
const counts2 = { decisions: 0, conventions: 0, todo: 0, done: 0 };
|
|
4496
|
+
let part;
|
|
4497
|
+
for (const line of text.split(/\r?\n/)) {
|
|
4498
|
+
const heading = /^\s*#{1,6}\s+(.+?)\s*#*\s*$/.exec(line) ?? /^\s*\*\*(.+?)\*\*\s*[::]?\s*$/.exec(line);
|
|
4499
|
+
if (heading) {
|
|
4500
|
+
part = PARTS[heading[1].replace(/[::]$/, "").trim().toLowerCase()];
|
|
4501
|
+
continue;
|
|
4502
|
+
}
|
|
4503
|
+
const item = /^\s*(?:[-*+]|\d+[.)])\s+(\[( |x|X)\]\s+)?\S/.exec(line);
|
|
4504
|
+
if (!part || !item) {
|
|
4505
|
+
continue;
|
|
4506
|
+
}
|
|
4507
|
+
if (part === "todo" && item[2] && item[2] !== " ") {
|
|
4508
|
+
counts2.done++;
|
|
4509
|
+
} else {
|
|
4510
|
+
counts2[part]++;
|
|
4511
|
+
}
|
|
4512
|
+
}
|
|
4513
|
+
return counts2;
|
|
4419
4514
|
}
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4515
|
+
NoticeUtil.counts = counts;
|
|
4516
|
+
function firstLine(text) {
|
|
4517
|
+
for (const line of text.split(/\r?\n/)) {
|
|
4518
|
+
const item = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+)$/.exec(line);
|
|
4519
|
+
if (item) {
|
|
4520
|
+
return item[1].replace(/[*_`~]+/g, "").trim();
|
|
4521
|
+
}
|
|
4522
|
+
}
|
|
4523
|
+
return text.split(/\r?\n/).find((line) => line.trim() && !/^\s*#/.test(line))?.trim() ?? "";
|
|
4524
|
+
}
|
|
4525
|
+
NoticeUtil.firstLine = firstLine;
|
|
4526
|
+
})(NoticeUtil ||= {});
|
|
4527
|
+
|
|
4528
|
+
// web-src/notice.tsx
|
|
4529
|
+
var NoticeView;
|
|
4530
|
+
((NoticeView) => {
|
|
4531
|
+
function display(text) {
|
|
4532
|
+
return text.replace(/^(\s*[-*+]\s+)\[ \]\s+/gm, "$1☐ ").replace(/^(\s*[-*+]\s+)\[[xX]\]\s+/gm, "$1☑ ");
|
|
4533
|
+
}
|
|
4534
|
+
NoticeView.display = display;
|
|
4535
|
+
function counts(text, language) {
|
|
4536
|
+
const w = ChannelWords.of(language);
|
|
4537
|
+
const counts2 = NoticeUtil.counts(text);
|
|
4538
|
+
if (counts2.decisions + counts2.conventions + counts2.todo === 0) {
|
|
4539
|
+
return NoticeUtil.firstLine(text);
|
|
4540
|
+
}
|
|
4541
|
+
const values = { decisions: String(counts2.decisions), conventions: String(counts2.conventions), todo: String(counts2.todo) };
|
|
4542
|
+
return ChannelWords.format(w.noticeCounts, values).split(" · ").filter((_, at) => [counts2.decisions, counts2.conventions, counts2.todo][at] > 0).join(" · ");
|
|
4543
|
+
}
|
|
4544
|
+
NoticeView.counts = counts;
|
|
4545
|
+
})(NoticeView ||= {});
|
|
4546
|
+
function NoticeBar({
|
|
4547
|
+
context,
|
|
4548
|
+
channel,
|
|
4549
|
+
state,
|
|
4550
|
+
onState
|
|
4551
|
+
}) {
|
|
4552
|
+
const { pi, service } = context;
|
|
4553
|
+
const { team } = useChannels(service);
|
|
4425
4554
|
const w = ChannelViews.words(pi);
|
|
4426
|
-
const
|
|
4427
|
-
const
|
|
4428
|
-
|
|
4429
|
-
|
|
4555
|
+
const notice = channel.notice;
|
|
4556
|
+
const [draft, setDraft] = React.useState("");
|
|
4557
|
+
const [busy, setBusy] = React.useState(false);
|
|
4558
|
+
const [error, setError] = React.useState();
|
|
4430
4559
|
React.useEffect(() => {
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
const onKey = (event) => event.key === "Escape" && onClose();
|
|
4438
|
-
document.addEventListener("pointerdown", close);
|
|
4439
|
-
document.addEventListener("keydown", onKey);
|
|
4440
|
-
return () => {
|
|
4441
|
-
document.removeEventListener("pointerdown", close);
|
|
4442
|
-
document.removeEventListener("keydown", onKey);
|
|
4443
|
-
};
|
|
4444
|
-
}, [onClose]);
|
|
4445
|
-
if (!draft) {
|
|
4560
|
+
if (state.editing) {
|
|
4561
|
+
setDraft(notice?.text ?? w.noticeTemplate);
|
|
4562
|
+
setError(undefined);
|
|
4563
|
+
}
|
|
4564
|
+
}, [state.editing]);
|
|
4565
|
+
if (!notice && !state.editing) {
|
|
4446
4566
|
return null;
|
|
4447
4567
|
}
|
|
4568
|
+
const Megaphone = ChannelViews.icon(pi, "Megaphone");
|
|
4569
|
+
const Chevron = ChannelViews.icon(pi, "ChevronDown");
|
|
4570
|
+
const Markdown = pi.ui.Markdown;
|
|
4571
|
+
const save = (event) => {
|
|
4572
|
+
event.preventDefault();
|
|
4573
|
+
setBusy(true);
|
|
4574
|
+
setError(undefined);
|
|
4575
|
+
service.setNotice(channel.id, draft).then(() => {
|
|
4576
|
+
setBusy(false);
|
|
4577
|
+
onState({ open: true, editing: false });
|
|
4578
|
+
}, (failure) => {
|
|
4579
|
+
setBusy(false);
|
|
4580
|
+
setError(ChannelViews.message(failure));
|
|
4581
|
+
});
|
|
4582
|
+
};
|
|
4583
|
+
const open = state.open || state.editing;
|
|
4448
4584
|
return /* @__PURE__ */ React.createElement("div", {
|
|
4449
|
-
className: "tac-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
"
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4585
|
+
className: "tac-notice-bar",
|
|
4586
|
+
"data-open": open ? "" : undefined
|
|
4587
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
4588
|
+
type: "button",
|
|
4589
|
+
className: "tac-notice-head",
|
|
4590
|
+
"aria-expanded": open,
|
|
4591
|
+
title: open ? w.noticeHide : w.noticeShow,
|
|
4592
|
+
onClick: () => onState({ open: !open, editing: false })
|
|
4593
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
4594
|
+
className: "tac-notice-icon"
|
|
4595
|
+
}, /* @__PURE__ */ React.createElement(Megaphone, {
|
|
4596
|
+
size: 13,
|
|
4597
|
+
strokeWidth: 2
|
|
4598
|
+
})), /* @__PURE__ */ React.createElement("strong", null, w.notice), /* @__PURE__ */ React.createElement("span", {
|
|
4599
|
+
className: "tac-notice-sum"
|
|
4600
|
+
}, notice ? NoticeView.counts(notice.text, pi.ui.language) : w.noticeEmpty), /* @__PURE__ */ React.createElement("span", {
|
|
4601
|
+
className: "tac-notice-chevron"
|
|
4602
|
+
}, /* @__PURE__ */ React.createElement(Chevron, {
|
|
4603
|
+
size: 15
|
|
4604
|
+
}))), open && !state.editing && notice && /* @__PURE__ */ React.createElement("div", {
|
|
4605
|
+
className: "tac-notice-body"
|
|
4606
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4607
|
+
className: "tac-notice-text"
|
|
4608
|
+
}, /* @__PURE__ */ React.createElement(Markdown, {
|
|
4609
|
+
text: NoticeView.display(notice.text)
|
|
4462
4610
|
})), /* @__PURE__ */ React.createElement("div", {
|
|
4463
|
-
className: "tac-
|
|
4464
|
-
},
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4611
|
+
className: "tac-notice-foot"
|
|
4612
|
+
}, /* @__PURE__ */ React.createElement("span", null, ChannelWords.format(w.noticeBy, {
|
|
4613
|
+
name: ChannelsText.authorName(team, notice.by, { user: w.you, ta: w.ta }),
|
|
4614
|
+
time: SidebarUtil.time(notice.at, pi.ui.language)
|
|
4615
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
4468
4616
|
type: "button",
|
|
4469
|
-
"
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4617
|
+
className: "tac-button tac-quiet",
|
|
4618
|
+
onClick: () => onState({ open: true, editing: true })
|
|
4619
|
+
}, w.noticeEdit))), state.editing && /* @__PURE__ */ React.createElement("form", {
|
|
4620
|
+
className: "tac-notice-body tac-notice-form",
|
|
4621
|
+
onSubmit: save
|
|
4622
|
+
}, /* @__PURE__ */ React.createElement("p", {
|
|
4623
|
+
className: "tac-dialog-note"
|
|
4624
|
+
}, w.noticeHint), /* @__PURE__ */ React.createElement("textarea", {
|
|
4625
|
+
className: "tac-input tac-notice-input",
|
|
4626
|
+
value: draft,
|
|
4627
|
+
"aria-label": w.noticeEdit,
|
|
4628
|
+
autoFocus: true,
|
|
4629
|
+
onChange: (event) => setDraft(event.target.value)
|
|
4630
|
+
}), error && /* @__PURE__ */ React.createElement("div", {
|
|
4631
|
+
className: "tac-error"
|
|
4632
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4633
|
+
className: "tac-notice-actions"
|
|
4634
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
4635
|
+
type: "button",
|
|
4636
|
+
className: "tac-button tac-quiet",
|
|
4637
|
+
onClick: () => onState({ open: !!notice, editing: false })
|
|
4638
|
+
}, w.cancel), /* @__PURE__ */ React.createElement("button", {
|
|
4639
|
+
type: "submit",
|
|
4640
|
+
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4641
|
+
disabled: busy || draft.trim() === (notice?.text ?? "")
|
|
4642
|
+
}, w.save, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4643
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4475
4644
|
})))));
|
|
4476
4645
|
}
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4646
|
+
|
|
4647
|
+
// web-src/room.tsx
|
|
4648
|
+
var RUN_MS = 5 * 60 * 1000;
|
|
4649
|
+
var PAUSE_MS = 15 * 60 * 1000;
|
|
4650
|
+
var RoomUtil;
|
|
4651
|
+
((RoomUtil) => {
|
|
4652
|
+
function rows(messages) {
|
|
4653
|
+
return messages.map((message, index) => {
|
|
4654
|
+
const before = messages[index - 1];
|
|
4655
|
+
const separator = !before || message.at - before.at > PAUSE_MS;
|
|
4656
|
+
const first = separator || before.author !== message.author || before.by !== message.by || before.author === SYSTEM || !!before.notice || message.at - before.at > RUN_MS;
|
|
4657
|
+
return { message, first, separator };
|
|
4658
|
+
});
|
|
4659
|
+
}
|
|
4660
|
+
RoomUtil.rows = rows;
|
|
4661
|
+
function choice(agent, text) {
|
|
4662
|
+
return `@${agent.name} ${TaMessageContext.strip(text)}`;
|
|
4663
|
+
}
|
|
4664
|
+
RoomUtil.choice = choice;
|
|
4665
|
+
function answer(messages, message, agent) {
|
|
4666
|
+
const said = messages.slice(messages.indexOf(message) + 1).find((later) => later.author === USER && !later.notice);
|
|
4667
|
+
if (!said) {
|
|
4668
|
+
return;
|
|
4669
|
+
}
|
|
4670
|
+
const named = `@${agent.name} `;
|
|
4671
|
+
return said.text.startsWith(named) ? said.text.slice(named.length) : said.text;
|
|
4672
|
+
}
|
|
4673
|
+
RoomUtil.answer = answer;
|
|
4674
|
+
})(RoomUtil ||= {});
|
|
4675
|
+
function AgentText({ context, channelId, agent, text, answer }) {
|
|
4676
|
+
const { pi, service } = context;
|
|
4677
|
+
const send = React.useCallback((said) => service.post(channelId, RoomUtil.choice(agent, said)), [service, channelId, agent.name]);
|
|
4678
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
|
|
4679
|
+
text,
|
|
4680
|
+
send,
|
|
4681
|
+
answer
|
|
4682
|
+
});
|
|
4683
|
+
}
|
|
4684
|
+
function MessagePictures({ context, channelId, message, alt }) {
|
|
4685
|
+
const { pi, service } = context;
|
|
4686
|
+
const images = message.images ?? [];
|
|
4687
|
+
const [sources, setSources] = React.useState({});
|
|
4688
|
+
const ids = images.map((image) => image.id).join(",");
|
|
4689
|
+
React.useEffect(() => {
|
|
4690
|
+
let live = true;
|
|
4691
|
+
for (const id of ids ? ids.split(",") : []) {
|
|
4692
|
+
service.picture(channelId, id).then((data) => live && data && setSources((current) => ({ ...current, [id]: data })));
|
|
4693
|
+
}
|
|
4694
|
+
return () => {
|
|
4695
|
+
live = false;
|
|
4696
|
+
};
|
|
4697
|
+
}, [service, channelId, ids]);
|
|
4698
|
+
const ChatImages = pi.ui.ChatImages;
|
|
4699
|
+
if (!images.length || !ChatImages) {
|
|
4483
4700
|
return null;
|
|
4484
4701
|
}
|
|
4485
4702
|
return /* @__PURE__ */ React.createElement("div", {
|
|
4486
|
-
className: "tac-
|
|
4703
|
+
className: "tac-pics"
|
|
4704
|
+
}, /* @__PURE__ */ React.createElement(ChatImages, {
|
|
4705
|
+
alt,
|
|
4706
|
+
images: images.map((image) => ({ key: image.id, src: sources[image.id], width: image.w, height: image.h }))
|
|
4707
|
+
}));
|
|
4708
|
+
}
|
|
4709
|
+
function Mentions({ text, agents }) {
|
|
4710
|
+
const names = new Set(agents.map((agent) => agent.name.toLowerCase()));
|
|
4711
|
+
const parts = text.split(/(@[^\s@#,,。::]+)/);
|
|
4712
|
+
return /* @__PURE__ */ React.createElement("span", null, parts.map((part, index) => part.startsWith("@") && names.has(part.slice(1).toLowerCase()) ? /* @__PURE__ */ React.createElement("span", {
|
|
4713
|
+
key: index,
|
|
4714
|
+
className: "tac-mention"
|
|
4715
|
+
}, part) : part));
|
|
4716
|
+
}
|
|
4717
|
+
function StopLine({
|
|
4718
|
+
context,
|
|
4719
|
+
channel,
|
|
4720
|
+
message,
|
|
4721
|
+
later,
|
|
4722
|
+
agents
|
|
4723
|
+
}) {
|
|
4724
|
+
const { pi, service } = context;
|
|
4725
|
+
const w = ChannelViews.words(pi);
|
|
4726
|
+
const [busy, setBusy] = React.useState(false);
|
|
4727
|
+
const stop = message.stop;
|
|
4728
|
+
const lead = agents.find((agent) => agent.id === channel.members.find((id) => !(channel.muted ?? []).includes(id)));
|
|
4729
|
+
const replies = String(stop?.replies ?? 0);
|
|
4730
|
+
const tokens = stop?.tokens ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(stop.tokens) : "";
|
|
4731
|
+
const stats = stop ? ChannelWords.format(tokens ? w.stoppedStats : w.stoppedReplies, { replies, tokens }) : "";
|
|
4732
|
+
const resumed = stop?.resumed === "continue" ? w.wentOn : stop?.resumed === "wrapUp" ? w.summedUp : "";
|
|
4733
|
+
const why = stop?.daily === "all" ? w.dailyAll : stop?.daily === "channel" ? w.dailyChannel : stop?.idle === "repeat" ? w.idleRepeat : stop?.idle === "agree" ? w.idleAgree : stop?.idle === "pingPong" ? w.idlePingPong : w.stopped;
|
|
4734
|
+
const extended = stop?.extended ? w.extendedOnce : "";
|
|
4735
|
+
const go = (how) => {
|
|
4736
|
+
setBusy(true);
|
|
4737
|
+
service.resumeRound(channel.id, message.id, how).catch((error) => pi.ui.notify(ChannelViews.message(error), "error")).finally(() => setBusy(false));
|
|
4738
|
+
};
|
|
4739
|
+
const open = !!stop?.pending.length && !stop.resumed && !later;
|
|
4740
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4741
|
+
className: "tac-stop",
|
|
4742
|
+
role: "note"
|
|
4487
4743
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
4488
|
-
className: "tac-
|
|
4744
|
+
className: "tac-notice"
|
|
4745
|
+
}, why), /* @__PURE__ */ React.createElement("div", {
|
|
4746
|
+
className: "tac-stop-meta"
|
|
4747
|
+
}, [stats, extended, resumed].filter(Boolean).join(" · ")), open && /* @__PURE__ */ React.createElement("div", {
|
|
4748
|
+
className: "tac-stop-actions"
|
|
4489
4749
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
4490
4750
|
type: "button",
|
|
4491
|
-
className: "tac-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
}, /* @__PURE__ */ React.createElement(Face, {
|
|
4496
|
-
face: draft.face,
|
|
4497
|
-
size: 20
|
|
4498
|
-
}), /* @__PURE__ */ React.createElement("span", null, draft.name || w.newAgentName), /* @__PURE__ */ React.createElement(Down, {
|
|
4499
|
-
size: 14
|
|
4500
|
-
})), editing && /* @__PURE__ */ React.createElement(Identity, {
|
|
4501
|
-
context,
|
|
4502
|
-
onClose: () => ui.set({ editing: false })
|
|
4503
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
4751
|
+
className: "tac-stop-button",
|
|
4752
|
+
disabled: busy,
|
|
4753
|
+
onClick: () => go("continue")
|
|
4754
|
+
}, w.keepGoing), lead && /* @__PURE__ */ React.createElement("button", {
|
|
4504
4755
|
type: "button",
|
|
4505
|
-
className: "tac-button
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
}
|
|
4510
|
-
}, w.cancel));
|
|
4756
|
+
className: "tac-stop-button",
|
|
4757
|
+
disabled: busy,
|
|
4758
|
+
onClick: () => go("wrapUp")
|
|
4759
|
+
}, ChannelWords.format(w.wrapUp, { name: `@${lead.name}` }))));
|
|
4511
4760
|
}
|
|
4512
|
-
function
|
|
4761
|
+
function ChannelHead({ context }) {
|
|
4513
4762
|
const { pi, service, ui } = context;
|
|
4514
|
-
const
|
|
4515
|
-
const {
|
|
4763
|
+
const state = useChannels(service);
|
|
4764
|
+
const { channelId } = useUi(ui);
|
|
4765
|
+
const faces = useFaces(state.team);
|
|
4516
4766
|
const w = ChannelViews.words(pi);
|
|
4517
|
-
const
|
|
4518
|
-
const
|
|
4519
|
-
const
|
|
4767
|
+
const shown = !!pi.ui.useView(MEMBERS_VIEW)?.shown;
|
|
4768
|
+
const roomInfo = !!pi.ui.useView(ROOM_INFO_VIEW)?.shown;
|
|
4769
|
+
const follow = React.useRef(roomInfo);
|
|
4770
|
+
follow.current = roomInfo;
|
|
4520
4771
|
React.useEffect(() => {
|
|
4521
|
-
if (
|
|
4522
|
-
|
|
4523
|
-
}
|
|
4524
|
-
first.current = false;
|
|
4525
|
-
if (!ui.state.draft) {
|
|
4526
|
-
newAgent(context);
|
|
4772
|
+
if (channelId && follow.current) {
|
|
4773
|
+
context.showMembers();
|
|
4527
4774
|
}
|
|
4528
|
-
}, [
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
try {
|
|
4536
|
-
const sessionId = await service.openAgent(agent.id);
|
|
4537
|
-
context.sessions.set(agent.id, sessionId);
|
|
4538
|
-
await pi.switchSession(sessionId);
|
|
4539
|
-
await pi.sendUserMessage(text);
|
|
4540
|
-
} catch (error) {
|
|
4541
|
-
pi.ui.notify(ChannelViews.message(error), "error");
|
|
4542
|
-
}
|
|
4543
|
-
};
|
|
4775
|
+
}, [channelId, context]);
|
|
4776
|
+
const channel = state.team.channels.find((candidate) => candidate.id === channelId);
|
|
4777
|
+
if (!channel) {
|
|
4778
|
+
return null;
|
|
4779
|
+
}
|
|
4780
|
+
const members = membersOf(state.team, channel);
|
|
4781
|
+
const working = state.working[channel.id] ?? [];
|
|
4544
4782
|
return /* @__PURE__ */ React.createElement("div", {
|
|
4545
|
-
className: "tac-
|
|
4783
|
+
className: "tac-head"
|
|
4546
4784
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
4547
|
-
className: "tac-
|
|
4548
|
-
}, /* @__PURE__ */ React.createElement(
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
}, /* @__PURE__ */ React.createElement("span", null, draft.name || w.newAgentName), /* @__PURE__ */ React.createElement("button", {
|
|
4785
|
+
className: "tac-head-title"
|
|
4786
|
+
}, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", {
|
|
4787
|
+
className: "tac-head-count"
|
|
4788
|
+
}, ChannelWords.format(w.memberCount, { count: String(members.length) })), channel.topic && /* @__PURE__ */ React.createElement("span", {
|
|
4789
|
+
className: "tac-head-topic"
|
|
4790
|
+
}, channel.topic)), /* @__PURE__ */ React.createElement("button", {
|
|
4554
4791
|
type: "button",
|
|
4555
|
-
className:
|
|
4556
|
-
title: w.
|
|
4557
|
-
"aria-label": w.
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
className: "tac-
|
|
4563
|
-
},
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
}))));
|
|
4792
|
+
className: `tac-head-members${shown ? " tac-on" : ""}`,
|
|
4793
|
+
title: w.showMembers,
|
|
4794
|
+
"aria-label": w.showMembers,
|
|
4795
|
+
"aria-pressed": shown,
|
|
4796
|
+
onClick: () => context.showMembers()
|
|
4797
|
+
}, members.slice(0, 5).map((agent) => /* @__PURE__ */ React.createElement("span", {
|
|
4798
|
+
key: agent.id,
|
|
4799
|
+
className: "tac-head-face"
|
|
4800
|
+
}, /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
4801
|
+
agent,
|
|
4802
|
+
faces,
|
|
4803
|
+
size: 24,
|
|
4804
|
+
working: working.includes(agent.id)
|
|
4805
|
+
}))), members.length > 5 && /* @__PURE__ */ React.createElement("span", {
|
|
4806
|
+
className: "tac-head-more"
|
|
4807
|
+
}, "+", members.length - 5)));
|
|
4572
4808
|
}
|
|
4573
|
-
function
|
|
4809
|
+
function ChannelSceneHead({ context, channelId }) {
|
|
4574
4810
|
const { pi, service } = context;
|
|
4575
|
-
const
|
|
4576
|
-
const faces = useFaces(team);
|
|
4811
|
+
const state = useChannels(service);
|
|
4812
|
+
const faces = useFaces(state.team);
|
|
4577
4813
|
const w = ChannelViews.words(pi);
|
|
4578
|
-
const
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
const
|
|
4583
|
-
const
|
|
4584
|
-
const
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4814
|
+
const channel = state.team.channels.find((candidate) => candidate.id === channelId);
|
|
4815
|
+
if (!channel) {
|
|
4816
|
+
return null;
|
|
4817
|
+
}
|
|
4818
|
+
const members = membersOf(state.team, channel);
|
|
4819
|
+
const working = state.working[channel.id] ?? [];
|
|
4820
|
+
const External = ChannelViews.icon(pi, "ExternalLink");
|
|
4821
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4822
|
+
className: "tac-scene-head"
|
|
4823
|
+
}, /* @__PURE__ */ React.createElement(RoomFace, {
|
|
4824
|
+
members,
|
|
4825
|
+
faces,
|
|
4826
|
+
size: 26,
|
|
4827
|
+
working
|
|
4828
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
4829
|
+
className: "tac-scene-title"
|
|
4830
|
+
}, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", null, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(members.length) }))), /* @__PURE__ */ React.createElement("button", {
|
|
4831
|
+
type: "button",
|
|
4832
|
+
className: "tac-button tac-scene-main",
|
|
4833
|
+
title: w.openInMainHint,
|
|
4834
|
+
onClick: () => context.showChannel(channel.id)
|
|
4835
|
+
}, /* @__PURE__ */ React.createElement(External, {
|
|
4836
|
+
size: 13
|
|
4837
|
+
}), w.openInMain));
|
|
4838
|
+
}
|
|
4839
|
+
var mePromise;
|
|
4840
|
+
function useMe(pi) {
|
|
4841
|
+
const [me, setMe] = React.useState(TA_OWNER);
|
|
4842
|
+
React.useEffect(() => {
|
|
4843
|
+
mePromise ??= pi.server.getServerInfo().then((info) => info.member?.id ?? TA_OWNER, () => TA_OWNER);
|
|
4844
|
+
let live = true;
|
|
4845
|
+
mePromise.then((id) => live && setMe(id));
|
|
4846
|
+
return () => {
|
|
4847
|
+
live = false;
|
|
4848
|
+
};
|
|
4849
|
+
}, [pi]);
|
|
4850
|
+
return me;
|
|
4851
|
+
}
|
|
4852
|
+
function ChannelRoom({ context, channelId: fixed }) {
|
|
4853
|
+
const { pi, service, ui } = context;
|
|
4854
|
+
const me = useMe(pi);
|
|
4855
|
+
const state = useChannels(service);
|
|
4856
|
+
const shown = useUi(ui).channelId;
|
|
4857
|
+
const channelId = fixed ?? shown;
|
|
4858
|
+
const faces = useFaces(state.team);
|
|
4859
|
+
const w = ChannelViews.words(pi);
|
|
4860
|
+
const channel = state.team.channels.find((candidate) => candidate.id === channelId);
|
|
4861
|
+
const messages = channel ? state.messages[channel.id] : undefined;
|
|
4862
|
+
const working = channel ? state.working[channel.id] ?? [] : [];
|
|
4863
|
+
React.useEffect(() => {
|
|
4864
|
+
if (channelId) {
|
|
4865
|
+
service.messages(channelId);
|
|
4866
|
+
}
|
|
4867
|
+
}, [service, channelId]);
|
|
4868
|
+
const page = pi.ui.useView(CHANNEL_PAGE);
|
|
4869
|
+
const inFront = !!channelId && (!!fixed || !!page?.shown);
|
|
4870
|
+
const lastAt = ChannelSeenUtil.lastAt(messages);
|
|
4871
|
+
const resting = working.length === 0;
|
|
4872
|
+
React.useEffect(() => {
|
|
4873
|
+
if (!channelId || !inFront || !resting) {
|
|
4602
4874
|
return;
|
|
4603
4875
|
}
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4876
|
+
const look = () => document.visibilityState === "visible" && context.seen.look(channelId, Math.max(Date.now(), lastAt ?? 0));
|
|
4877
|
+
look();
|
|
4878
|
+
document.addEventListener("visibilitychange", look);
|
|
4879
|
+
return () => document.removeEventListener("visibilitychange", look);
|
|
4880
|
+
}, [context, channelId, inFront, resting, lastAt]);
|
|
4881
|
+
React.useEffect(() => {
|
|
4882
|
+
if (!channelId) {
|
|
4883
|
+
return;
|
|
4884
|
+
}
|
|
4885
|
+
const watch = () => document.visibilityState === "visible" && void service.watch(channelId).catch(() => {
|
|
4886
|
+
return;
|
|
4610
4887
|
});
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
},
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
className: "tac-dialog-search"
|
|
4633
|
-
}, /* @__PURE__ */ React.createElement(Search, {
|
|
4634
|
-
size: 15
|
|
4635
|
-
}), /* @__PURE__ */ React.createElement("input", {
|
|
4636
|
-
value: query,
|
|
4637
|
-
placeholder: ChannelWords.format(w.searchAgents, { max: String(MAX_MEMBERS) }),
|
|
4638
|
-
"aria-label": w.search,
|
|
4639
|
-
onChange: (event) => setQuery(event.target.value)
|
|
4640
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
4641
|
-
className: "tac-pick-list"
|
|
4642
|
-
}, team.agents.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4643
|
-
compact: true,
|
|
4644
|
-
title: w.noAgents,
|
|
4645
|
-
hint: w.noAgentsHint
|
|
4646
|
-
}), team.agents.length > 0 && shown.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4647
|
-
compact: true,
|
|
4648
|
-
title: w.noMatch
|
|
4649
|
-
}), shown.map((agent) => {
|
|
4650
|
-
const on = picked.includes(agent.id);
|
|
4651
|
-
return /* @__PURE__ */ React.createElement("button", {
|
|
4652
|
-
key: agent.id,
|
|
4653
|
-
type: "button",
|
|
4654
|
-
"aria-pressed": on,
|
|
4655
|
-
disabled: !on && full,
|
|
4656
|
-
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
4657
|
-
onClick: () => toggle(agent)
|
|
4658
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
4659
|
-
className: "tac-check"
|
|
4660
|
-
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
4661
|
-
size: 13,
|
|
4662
|
-
strokeWidth: 3
|
|
4663
|
-
})), /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
4664
|
-
agent,
|
|
4665
|
-
faces,
|
|
4666
|
-
size: 30
|
|
4667
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
4668
|
-
className: "tac-pick-text"
|
|
4669
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
4670
|
-
className: "tac-pick-name"
|
|
4671
|
-
}, agent.name, picked[0] === agent.id && /* @__PURE__ */ React.createElement("span", {
|
|
4672
|
-
className: "tac-msg-lead"
|
|
4673
|
-
}, w.lead)), /* @__PURE__ */ React.createElement("span", {
|
|
4674
|
-
className: "tac-pick-role"
|
|
4675
|
-
}, agent.role.split(`
|
|
4676
|
-
`)[0])));
|
|
4677
|
-
})), friends.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
4678
|
-
className: "tac-dialog-label"
|
|
4679
|
-
}, /* @__PURE__ */ React.createElement("span", null, w.addFriends), shared && /* @__PURE__ */ React.createElement("span", {
|
|
4680
|
-
className: "tac-dialog-count"
|
|
4681
|
-
}, pickedFriends.length)), /* @__PURE__ */ React.createElement("div", {
|
|
4682
|
-
className: "tac-pick-list"
|
|
4683
|
-
}, friends.map((friend) => {
|
|
4684
|
-
const on = pickedFriends.includes(friend.id);
|
|
4685
|
-
return /* @__PURE__ */ React.createElement("button", {
|
|
4686
|
-
key: friend.id,
|
|
4687
|
-
type: "button",
|
|
4688
|
-
"aria-pressed": on,
|
|
4689
|
-
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
4690
|
-
onClick: () => toggleFriend(friend)
|
|
4691
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
4692
|
-
className: "tac-check"
|
|
4693
|
-
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
4694
|
-
size: 13,
|
|
4695
|
-
strokeWidth: 3
|
|
4696
|
-
})), pi.ui.Face ? /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
4697
|
-
seed: friend.id,
|
|
4698
|
-
size: 30,
|
|
4699
|
-
look: friend.look
|
|
4700
|
-
}) : /* @__PURE__ */ React.createElement("span", {
|
|
4701
|
-
className: "tac-pick-face"
|
|
4702
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
4703
|
-
className: "tac-pick-text"
|
|
4704
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
4705
|
-
className: "tac-pick-name"
|
|
4706
|
-
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
4707
|
-
className: "tac-pick-role"
|
|
4708
|
-
}, w.friend)));
|
|
4709
|
-
}))), (picked.length > 0 || shared) && /* @__PURE__ */ React.createElement("div", {
|
|
4710
|
-
className: "tac-dialog-note"
|
|
4711
|
-
}, shared ? w.sharedHint : w.membersHint), error && /* @__PURE__ */ React.createElement("div", {
|
|
4712
|
-
className: "tac-empty tac-error"
|
|
4713
|
-
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
4714
|
-
className: "tac-dialog-actions"
|
|
4715
|
-
}, /* @__PURE__ */ React.createElement("button", {
|
|
4716
|
-
type: "submit",
|
|
4717
|
-
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
4718
|
-
disabled: busy || !name.trim() || picked.length === 0 && !shared
|
|
4719
|
-
}, w.create, busy && /* @__PURE__ */ React.createElement("span", {
|
|
4720
|
-
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
4721
|
-
})))));
|
|
4722
|
-
}
|
|
4723
|
-
|
|
4724
|
-
// web-src/handoff.ts
|
|
4725
|
-
var HandOff;
|
|
4726
|
-
((HandOff) => {
|
|
4727
|
-
HandOff.TOOL = "hand_off";
|
|
4728
|
-
HandOff.CARD = "ta-channels-handoff";
|
|
4729
|
-
HandOff.BLOCK = "ta-handoff";
|
|
4730
|
-
const MARK = /\[ta-handoff:([^\]\s]+)\]/;
|
|
4731
|
-
HandOff.DEFINITION = {
|
|
4732
|
-
name: HandOff.TOOL,
|
|
4733
|
-
label: "Hand off",
|
|
4734
|
-
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.",
|
|
4735
|
-
promptSnippet: "Hand the work over to one of the user's agents or channels",
|
|
4736
|
-
parameters: {
|
|
4737
|
-
type: "object",
|
|
4738
|
-
properties: {
|
|
4739
|
-
to: { type: "string", description: "@name of an agent or #name of a channel." },
|
|
4740
|
-
brief: { type: "string", description: "Complete in itself: the receiver sees only this." }
|
|
4741
|
-
},
|
|
4742
|
-
required: ["to", "brief"]
|
|
4743
|
-
}
|
|
4744
|
-
};
|
|
4745
|
-
function ref(target) {
|
|
4746
|
-
return `${target.kind === "agent" ? "@" : "#"}${target.name}`;
|
|
4747
|
-
}
|
|
4748
|
-
HandOff.ref = ref;
|
|
4749
|
-
function ask(language, to) {
|
|
4750
|
-
const fence = "```";
|
|
4751
|
-
const context = [
|
|
4752
|
-
`[ta-handoff:${to}]`,
|
|
4753
|
-
`The user hands the work of this conversation over to ${to}, which does not see this conversation.`,
|
|
4754
|
-
`- 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.`,
|
|
4755
|
-
`- With the tool ${HandOff.TOOL}, call it with to "${to}" and the brief, then say in one line that it went.`,
|
|
4756
|
-
`- 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):`,
|
|
4757
|
-
`${fence}${HandOff.BLOCK}`,
|
|
4758
|
-
"<the brief>",
|
|
4759
|
-
fence,
|
|
4760
|
-
`- When the conversation holds nothing to hand over yet, say so and ask what ${to} should do.`
|
|
4761
|
-
].join(`
|
|
4762
|
-
`);
|
|
4763
|
-
const line = TaLanguageUtil.pick(language, {
|
|
4764
|
-
"zh-CN": `把这件事交给 ${to}`,
|
|
4765
|
-
"zh-TW": `把這件事交給 ${to}`,
|
|
4766
|
-
"en-US": `Hand this over to ${to}`,
|
|
4767
|
-
"ja-JP": `これを ${to} に引き継ぐ`
|
|
4768
|
-
});
|
|
4769
|
-
return TaMessageContext.wrap(context, line);
|
|
4770
|
-
}
|
|
4771
|
-
HandOff.ask = ask;
|
|
4772
|
-
function asked(text) {
|
|
4773
|
-
return MARK.exec(text)?.[1];
|
|
4774
|
-
}
|
|
4775
|
-
HandOff.asked = asked;
|
|
4776
|
-
function find(text) {
|
|
4777
|
-
const lines = text.split(/\r?\n/);
|
|
4778
|
-
let found;
|
|
4779
|
-
for (let index = 0;index < lines.length; index++) {
|
|
4780
|
-
const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
|
|
4781
|
-
if (open?.[2] !== HandOff.BLOCK) {
|
|
4782
|
-
continue;
|
|
4783
|
-
}
|
|
4784
|
-
const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
|
|
4785
|
-
const end = lines.findIndex((line, at) => at > index && close.test(line));
|
|
4786
|
-
found = lines.slice(index + 1, end < 0 ? lines.length : end);
|
|
4787
|
-
index = end < 0 ? lines.length : end;
|
|
4788
|
-
}
|
|
4789
|
-
const brief = found?.join(`
|
|
4790
|
-
`).trim();
|
|
4791
|
-
return brief || undefined;
|
|
4792
|
-
}
|
|
4793
|
-
HandOff.find = find;
|
|
4794
|
-
function message(origin, brief, language) {
|
|
4795
|
-
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
4796
|
-
const head = TaLanguageUtil.pick(language, {
|
|
4797
|
-
"zh-CN": `(交接自“${title}”)`,
|
|
4798
|
-
"zh-TW": `(交接自「${title}」)`,
|
|
4799
|
-
"en-US": `(Handed over from “${title}”)`,
|
|
4800
|
-
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
4801
|
-
});
|
|
4802
|
-
const context = [
|
|
4803
|
-
"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.",
|
|
4804
|
-
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.` : ""
|
|
4805
|
-
].filter(Boolean).join(`
|
|
4806
|
-
`);
|
|
4807
|
-
return TaMessageContext.wrap(context, `${head}
|
|
4808
|
-
|
|
4809
|
-
${brief.trim()}`);
|
|
4810
|
-
}
|
|
4811
|
-
HandOff.message = message;
|
|
4812
|
-
function channelText(origin, brief, language) {
|
|
4813
|
-
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
4814
|
-
return `${TaLanguageUtil.pick(language, {
|
|
4815
|
-
"zh-CN": `(交接自“${title}”)`,
|
|
4816
|
-
"zh-TW": `(交接自「${title}」)`,
|
|
4817
|
-
"en-US": `(Handed over from “${title}”)`,
|
|
4818
|
-
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
4819
|
-
})}
|
|
4820
|
-
|
|
4821
|
-
${brief.trim()}`;
|
|
4822
|
-
}
|
|
4823
|
-
HandOff.channelText = channelText;
|
|
4824
|
-
function serverLanguage(env = typeof process === "undefined" ? {} : process.env) {
|
|
4825
|
-
return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
|
|
4826
|
-
}
|
|
4827
|
-
HandOff.serverLanguage = serverLanguage;
|
|
4828
|
-
function result(target) {
|
|
4829
|
-
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.`;
|
|
4830
|
-
}
|
|
4831
|
-
HandOff.result = result;
|
|
4832
|
-
})(HandOff ||= {});
|
|
4833
|
-
|
|
4834
|
-
// web-src/handoff-view.tsx
|
|
4835
|
-
var HandOffViewUtil;
|
|
4836
|
-
((HandOffViewUtil) => {
|
|
4837
|
-
function members(team, target) {
|
|
4838
|
-
if (target.kind === "agent") {
|
|
4839
|
-
const agent = team.agents.find((candidate) => candidate.id === target.id);
|
|
4840
|
-
return agent ? [agent] : [];
|
|
4841
|
-
}
|
|
4842
|
-
const channel = team.channels.find((candidate) => candidate.id === target.id);
|
|
4843
|
-
return channel ? membersOf(team, channel) : [];
|
|
4844
|
-
}
|
|
4845
|
-
HandOffViewUtil.members = members;
|
|
4846
|
-
})(HandOffViewUtil ||= {});
|
|
4847
|
-
function useTeam(context) {
|
|
4848
|
-
return React.useSyncExternalStore((listener) => context.service.subscribe(listener), () => context.service.state).team;
|
|
4849
|
-
}
|
|
4850
|
-
function HandOffCard({ context, message }) {
|
|
4851
|
-
const card = message.details;
|
|
4852
|
-
const team = useTeam(context);
|
|
4853
|
-
const faces = useFaces(team);
|
|
4854
|
-
if (!card?.target) {
|
|
4855
|
-
return null;
|
|
4888
|
+
watch();
|
|
4889
|
+
const timer = setInterval(watch, WATCH_MS);
|
|
4890
|
+
document.addEventListener("visibilitychange", watch);
|
|
4891
|
+
return () => {
|
|
4892
|
+
clearInterval(timer);
|
|
4893
|
+
document.removeEventListener("visibilitychange", watch);
|
|
4894
|
+
};
|
|
4895
|
+
}, [service, channelId]);
|
|
4896
|
+
const sent = React.useMemo(() => messages?.filter((message) => message.author === USER).length ?? 0, [messages]);
|
|
4897
|
+
const list = pi.ui.useChatScroll(sent, channelId);
|
|
4898
|
+
const [notice, setNotice] = React.useState({ open: false, editing: false });
|
|
4899
|
+
React.useEffect(() => setNotice({ open: false, editing: false }), [channelId]);
|
|
4900
|
+
const Markdown = pi.ui.Markdown;
|
|
4901
|
+
const Composer = pi.ui.Composer;
|
|
4902
|
+
const Avatar = pi.ui.Avatar;
|
|
4903
|
+
if (!channel) {
|
|
4904
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
4905
|
+
className: "tac-room-page"
|
|
4906
|
+
}, state.loaded && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
4907
|
+
title: w.pick
|
|
4908
|
+
}));
|
|
4856
4909
|
}
|
|
4857
|
-
const
|
|
4858
|
-
const
|
|
4859
|
-
const
|
|
4910
|
+
const members = membersOf(state.team, channel);
|
|
4911
|
+
const agentOf = (id) => state.team.agents.find((agent) => agent.id === id);
|
|
4912
|
+
const reply = ChannelsText.replyOf(channel);
|
|
4913
|
+
const lead = members.find((agent) => !(channel.muted ?? []).includes(agent.id));
|
|
4914
|
+
const placeholder = reply === "all" ? w.placeholderAll : reply === "lead" && lead ? w.placeholderLead : w.placeholder;
|
|
4915
|
+
const name = (id) => ChannelsText.authorName(state.team, id, { user: w.you, ta: w.ta });
|
|
4916
|
+
const time = (at) => SidebarUtil.time(at, pi.ui.language);
|
|
4860
4917
|
return /* @__PURE__ */ React.createElement("div", {
|
|
4861
|
-
className: "tac-
|
|
4918
|
+
className: "tac-room-page"
|
|
4919
|
+
}, /* @__PURE__ */ React.createElement(NoticeBar, {
|
|
4920
|
+
context,
|
|
4921
|
+
channel,
|
|
4922
|
+
state: notice,
|
|
4923
|
+
onState: setNotice
|
|
4924
|
+
}), /* @__PURE__ */ React.createElement("div", {
|
|
4925
|
+
className: "tac-chat ta-conversation",
|
|
4926
|
+
ref: list
|
|
4862
4927
|
}, /* @__PURE__ */ React.createElement("div", {
|
|
4863
|
-
className: "tac-
|
|
4864
|
-
},
|
|
4928
|
+
className: "tac-chat-col"
|
|
4929
|
+
}, messages && messages.length === 0 && /* @__PURE__ */ React.createElement("div", {
|
|
4930
|
+
className: "tac-chat-empty"
|
|
4931
|
+
}, /* @__PURE__ */ React.createElement(RoomFace, {
|
|
4865
4932
|
members,
|
|
4866
4933
|
faces,
|
|
4867
|
-
size:
|
|
4868
|
-
working
|
|
4869
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
4870
|
-
className: "tac-
|
|
4871
|
-
}, w.
|
|
4934
|
+
size: 56,
|
|
4935
|
+
working
|
|
4936
|
+
}), /* @__PURE__ */ React.createElement("strong", null, channel.name), channel.topic && /* @__PURE__ */ React.createElement("span", null, channel.topic), /* @__PURE__ */ React.createElement("span", {
|
|
4937
|
+
className: "tac-chat-hint"
|
|
4938
|
+
}, w.quiet)), messages && RoomUtil.rows(messages).map(({ message, first, separator }) => /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
4939
|
+
key: message.id
|
|
4940
|
+
}, separator && /* @__PURE__ */ React.createElement("div", {
|
|
4941
|
+
className: "tac-chat-time"
|
|
4942
|
+
}, time(message.at)), message.author === SYSTEM ? /* @__PURE__ */ React.createElement(StopLine, {
|
|
4943
|
+
context,
|
|
4944
|
+
channel,
|
|
4945
|
+
message,
|
|
4946
|
+
agents: state.team.agents,
|
|
4947
|
+
later: messages.some((other) => other.at > message.at && (other.author === USER || other.author === TA))
|
|
4948
|
+
}) : message.notice ? /* @__PURE__ */ React.createElement("button", {
|
|
4872
4949
|
type: "button",
|
|
4873
|
-
className: "tac-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
}
|
|
4879
|
-
|
|
4880
|
-
(
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
}
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4950
|
+
className: "tac-notice tac-notice-line",
|
|
4951
|
+
disabled: !channel.notice,
|
|
4952
|
+
onClick: () => setNotice({ open: true, editing: false })
|
|
4953
|
+
}, ChannelWords.format(message.notice === "cleared" ? w.noticeCleared : w.noticeUpdated, { name: name(message.author) })) : message.author === USER && (message.by ?? TA_OWNER) !== me ? /* @__PURE__ */ React.createElement("div", {
|
|
4954
|
+
className: `tac-msg${first ? " tac-first" : ""}`
|
|
4955
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4956
|
+
className: "tac-msg-face"
|
|
4957
|
+
}, first && pi.ui.Face && /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
4958
|
+
seed: message.by ?? TA_OWNER,
|
|
4959
|
+
double: (message.by ?? TA_OWNER) === TA_OWNER,
|
|
4960
|
+
size: 28
|
|
4961
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
4962
|
+
className: "tac-msg-col"
|
|
4963
|
+
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
4964
|
+
className: "tac-msg-name"
|
|
4965
|
+
}, message.byName ?? w.owner), /* @__PURE__ */ React.createElement(MessagePictures, {
|
|
4966
|
+
context,
|
|
4967
|
+
channelId: channel.id,
|
|
4968
|
+
message,
|
|
4969
|
+
alt: message.byName ?? w.owner
|
|
4970
|
+
}), message.text && /* @__PURE__ */ React.createElement("div", {
|
|
4971
|
+
className: "tac-msg-bubble",
|
|
4972
|
+
title: time(message.at)
|
|
4973
|
+
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
4974
|
+
text: message.text,
|
|
4975
|
+
agents: state.team.agents
|
|
4976
|
+
})))) : message.author === USER ? /* @__PURE__ */ React.createElement("div", {
|
|
4977
|
+
className: "ta-message ta-user tac-mine"
|
|
4978
|
+
}, /* @__PURE__ */ React.createElement(MessagePictures, {
|
|
4979
|
+
context,
|
|
4980
|
+
channelId: channel.id,
|
|
4981
|
+
message,
|
|
4982
|
+
alt: w.you
|
|
4983
|
+
}), message.text && /* @__PURE__ */ React.createElement("div", {
|
|
4984
|
+
className: "ta-bubble"
|
|
4985
|
+
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
4986
|
+
text: message.text,
|
|
4987
|
+
agents: state.team.agents
|
|
4988
|
+
}))) : /* @__PURE__ */ React.createElement("div", {
|
|
4989
|
+
className: `tac-msg${first ? " tac-first" : ""}`
|
|
4990
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
4991
|
+
className: "tac-msg-face"
|
|
4992
|
+
}, first && (message.author === TA ? /* @__PURE__ */ React.createElement(Avatar, {
|
|
4993
|
+
size: 28
|
|
4994
|
+
}) : /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
4995
|
+
agent: agentOf(message.author),
|
|
4996
|
+
faces,
|
|
4997
|
+
size: 28,
|
|
4998
|
+
working: working.includes(message.author)
|
|
4999
|
+
}))), /* @__PURE__ */ React.createElement("div", {
|
|
5000
|
+
className: "tac-msg-col"
|
|
5001
|
+
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
5002
|
+
className: "tac-msg-name"
|
|
5003
|
+
}, name(message.author), message.author === channel.members[0] && /* @__PURE__ */ React.createElement("span", {
|
|
5004
|
+
className: "tac-msg-lead"
|
|
5005
|
+
}, w.lead)), /* @__PURE__ */ React.createElement("div", {
|
|
5006
|
+
className: `tac-msg-bubble${message.failed ? " tac-failed" : ""}`,
|
|
5007
|
+
title: time(message.at)
|
|
5008
|
+
}, message.failed && /* @__PURE__ */ React.createElement("div", {
|
|
5009
|
+
className: "tac-msg-failed"
|
|
5010
|
+
}, w.failed), message.overBudget && /* @__PURE__ */ React.createElement("div", {
|
|
5011
|
+
className: "tac-msg-over"
|
|
5012
|
+
}, w.overBudget), agentOf(message.author) ? /* @__PURE__ */ React.createElement(AgentText, {
|
|
5013
|
+
context,
|
|
5014
|
+
channelId: channel.id,
|
|
5015
|
+
agent: agentOf(message.author),
|
|
5016
|
+
text: ChannelsText.markMentions(message.text, state.team.agents),
|
|
5017
|
+
answer: RoomUtil.answer(messages, message, agentOf(message.author))
|
|
5018
|
+
}) : /* @__PURE__ */ React.createElement(Markdown, {
|
|
5019
|
+
text: ChannelsText.markMentions(message.text, state.team.agents)
|
|
5020
|
+
})))))), working.length > 0 && /* @__PURE__ */ React.createElement("div", {
|
|
5021
|
+
className: "tac-live",
|
|
5022
|
+
role: "status"
|
|
5023
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
5024
|
+
className: "tac-live-faces"
|
|
5025
|
+
}, working.map((id) => /* @__PURE__ */ React.createElement(Face, {
|
|
5026
|
+
key: id,
|
|
5027
|
+
face: faces.get(id) ?? 0,
|
|
5028
|
+
size: 18,
|
|
5029
|
+
working: true
|
|
5030
|
+
}))), ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") })))), /* @__PURE__ */ React.createElement("div", {
|
|
5031
|
+
className: "tac-chat-bottom"
|
|
5032
|
+
}, /* @__PURE__ */ React.createElement(Composer, {
|
|
5033
|
+
placeholder: ChannelWords.format(placeholder, { channel: channel.name, lead: lead?.name ?? "" }),
|
|
5034
|
+
draft: channel.id,
|
|
5035
|
+
mentions: members.map((agent) => ({ name: agent.name, detail: agent.role.split(`
|
|
5036
|
+
`)[0] })),
|
|
5037
|
+
mentionLabel: w.mentionMember,
|
|
5038
|
+
actions: [
|
|
5039
|
+
[
|
|
5040
|
+
{
|
|
5041
|
+
key: "notice",
|
|
5042
|
+
label: w.noticeEdit,
|
|
5043
|
+
icon: ChannelViews.maybeIcon(pi, "Megaphone", null, 16),
|
|
5044
|
+
run: () => setNotice({ open: true, editing: true })
|
|
5045
|
+
},
|
|
5046
|
+
{
|
|
5047
|
+
key: "add",
|
|
5048
|
+
label: w.addMembers,
|
|
5049
|
+
icon: ChannelViews.maybeIcon(pi, "UserPlus", null, 16),
|
|
5050
|
+
run: () => {
|
|
5051
|
+
if (fixed) {
|
|
5052
|
+
ui.set({ channelId: fixed });
|
|
5053
|
+
}
|
|
5054
|
+
context.showMembers(true);
|
|
5055
|
+
}
|
|
4920
5056
|
}
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
key:
|
|
4925
|
-
label:
|
|
4926
|
-
detail:
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
group: w.channels,
|
|
4937
|
-
icon: icon(context, { kind: "channel", id: channel.id }, icons),
|
|
4938
|
-
run: () => send(conversation, `#${channel.name}`)
|
|
4939
|
-
}));
|
|
4940
|
-
return [{ key: "handoff", label: w.handOff, detail: w.handOffDetail, icon: /* @__PURE__ */ React.createElement(Forward, {
|
|
4941
|
-
size: 16
|
|
4942
|
-
}), items: [...agents, ...channels] }];
|
|
4943
|
-
},
|
|
4944
|
-
subscribe: (listener) => context.service.subscribe(listener)
|
|
4945
|
-
};
|
|
4946
|
-
}
|
|
4947
|
-
HandOffView.composerAddon = composerAddon;
|
|
4948
|
-
})(HandOffView ||= {});
|
|
5057
|
+
],
|
|
5058
|
+
[
|
|
5059
|
+
{
|
|
5060
|
+
key: "make-extension",
|
|
5061
|
+
label: w.makeExtension,
|
|
5062
|
+
detail: w.makeExtensionDetail,
|
|
5063
|
+
icon: ChannelViews.maybeIcon(pi, "Sparkles", null, 16),
|
|
5064
|
+
run: () => void service.post(channel.id, w.makeExtensionAsk).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"))
|
|
5065
|
+
}
|
|
5066
|
+
]
|
|
5067
|
+
],
|
|
5068
|
+
images: { side: 1600, bytes: 1024 * 1024 },
|
|
5069
|
+
onSend: (text, images) => service.post(channel.id, text, images ?? [])
|
|
5070
|
+
})));
|
|
5071
|
+
}
|
|
4949
5072
|
|
|
4950
|
-
// web-src/
|
|
4951
|
-
var
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
}
|
|
4963
|
-
return pages === undefined || pages > 0 ? 1 : 0.5;
|
|
5073
|
+
// web-src/tasks.tsx
|
|
5074
|
+
var BUILDING_MS = 60 * 1000;
|
|
5075
|
+
|
|
5076
|
+
class ChannelTaskSource {
|
|
5077
|
+
context;
|
|
5078
|
+
shown = new Map;
|
|
5079
|
+
list = [];
|
|
5080
|
+
listeners = new Set;
|
|
5081
|
+
reading = new Set;
|
|
5082
|
+
stop;
|
|
5083
|
+
constructor(context) {
|
|
5084
|
+
this.context = context;
|
|
4964
5085
|
}
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
const mine = pairs[pairs.length - 1];
|
|
4973
|
-
if (mine.length >= MIN_PAIRS && pairs.slice(0, -1).some((other) => alike(other, mine) >= ALIKE)) {
|
|
4974
|
-
return "repeat";
|
|
4975
|
-
}
|
|
4976
|
-
const recent = said.slice(-3);
|
|
4977
|
-
if (recent.length === 3 && recent.every((item) => units(item.text).join("").length < SHORT)) {
|
|
4978
|
-
return "agree";
|
|
4979
|
-
}
|
|
4980
|
-
const run = said.slice(-PING_PONG);
|
|
4981
|
-
const authors = new Set(run.map((item) => item.author));
|
|
4982
|
-
const alternate = run.every((item, i) => i === 0 || item.author !== run[i - 1].author);
|
|
4983
|
-
const start = said.length - PING_PONG;
|
|
4984
|
-
if (progress || start <= 0 || authors.size !== 2 || !alternate) {
|
|
4985
|
-
return;
|
|
5086
|
+
tasks() {
|
|
5087
|
+
return this.list;
|
|
5088
|
+
}
|
|
5089
|
+
subscribe(listener) {
|
|
5090
|
+
if (this.listeners.size === 0) {
|
|
5091
|
+
this.stop = this.context.service.subscribe((state) => this.build(state));
|
|
5092
|
+
this.build(this.context.service.state);
|
|
4986
5093
|
}
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
if (
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
for (const pair of own) {
|
|
4994
|
-
seen.add(pair);
|
|
5094
|
+
this.listeners.add(listener);
|
|
5095
|
+
return () => {
|
|
5096
|
+
this.listeners.delete(listener);
|
|
5097
|
+
if (this.listeners.size === 0) {
|
|
5098
|
+
this.stop?.();
|
|
5099
|
+
this.stop = undefined;
|
|
4995
5100
|
}
|
|
4996
|
-
}
|
|
4997
|
-
return "pingPong";
|
|
4998
|
-
}
|
|
4999
|
-
ChannelRounds.idle = idle;
|
|
5000
|
-
function day(now) {
|
|
5001
|
-
const date = new Date(now);
|
|
5002
|
-
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
5101
|
+
};
|
|
5003
5102
|
}
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
const pick = (key) => LIMIT_CHOICES[key].includes(given[key]) ? given[key] : DEFAULT_LIMITS[key];
|
|
5008
|
-
return { answer: pick("answer"), channelDay: pick("channelDay"), allDay: pick("allDay") };
|
|
5103
|
+
refresh() {
|
|
5104
|
+
this.shown.clear();
|
|
5105
|
+
this.build(this.context.service.state);
|
|
5009
5106
|
}
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
const
|
|
5013
|
-
|
|
5107
|
+
build(state) {
|
|
5108
|
+
const { team } = state;
|
|
5109
|
+
const faces = ChannelsUtil.faces(team.agents);
|
|
5110
|
+
const next = new Map;
|
|
5111
|
+
const channels = ChannelsUtil.taskChannels(team);
|
|
5112
|
+
let changed = channels.length !== this.list.length;
|
|
5113
|
+
const list = channels.map((channel, index) => {
|
|
5114
|
+
const messages = state.messages[channel.id];
|
|
5115
|
+
if (!messages) {
|
|
5116
|
+
this.read(channel.id);
|
|
5117
|
+
}
|
|
5118
|
+
const members = membersOf(team, channel);
|
|
5119
|
+
const working = state.working[channel.id] ?? [];
|
|
5120
|
+
const { status, detail, endedAt } = this.status(state, channel, messages, working);
|
|
5121
|
+
const signature = members.map((agent) => `${agent.id}:${faces.get(agent.id)}:${working.includes(agent.id) ? 1 : 0}`).join(",");
|
|
5122
|
+
const before = this.shown.get(channel.id);
|
|
5123
|
+
const shown = before && before.channel === channel && before.faces === signature && before.status === status && before.detail === detail && before.endedAt === endedAt ? before : {
|
|
5124
|
+
channel,
|
|
5125
|
+
members,
|
|
5126
|
+
faces: signature,
|
|
5127
|
+
status,
|
|
5128
|
+
detail,
|
|
5129
|
+
endedAt,
|
|
5130
|
+
entry: this.entry(channel, members, faces, working, status, detail, endedAt)
|
|
5131
|
+
};
|
|
5132
|
+
next.set(channel.id, shown);
|
|
5133
|
+
changed ||= shown.entry !== this.list[index];
|
|
5134
|
+
return shown.entry;
|
|
5135
|
+
});
|
|
5136
|
+
this.shown = next;
|
|
5137
|
+
if (!changed) {
|
|
5138
|
+
return;
|
|
5139
|
+
}
|
|
5140
|
+
this.list = list;
|
|
5141
|
+
for (const listener of this.listeners) {
|
|
5142
|
+
listener();
|
|
5143
|
+
}
|
|
5014
5144
|
}
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5145
|
+
read(channelId) {
|
|
5146
|
+
if (!this.reading.has(channelId)) {
|
|
5147
|
+
this.reading.add(channelId);
|
|
5148
|
+
this.context.service.messages(channelId).catch(() => this.reading.delete(channelId));
|
|
5149
|
+
}
|
|
5019
5150
|
}
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5151
|
+
status(state, channel, messages, working) {
|
|
5152
|
+
const w = ChannelViews.words(this.context.pi);
|
|
5153
|
+
const name = (id) => ChannelsText.authorName(state.team, id, { user: w.you, ta: w.ta });
|
|
5154
|
+
if (working.length > 0) {
|
|
5155
|
+
return { status: "running", detail: ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") }) };
|
|
5024
5156
|
}
|
|
5025
|
-
|
|
5026
|
-
|
|
5157
|
+
const last = messages?.at(-1);
|
|
5158
|
+
if (!last) {
|
|
5159
|
+
const building = Date.now() - channel.createdAt < BUILDING_MS;
|
|
5160
|
+
return building ? { status: "running", detail: w.building } : { status: "done", detail: channel.topic || w.noMessages, endedAt: channel.createdAt };
|
|
5027
5161
|
}
|
|
5028
|
-
if (
|
|
5029
|
-
return "
|
|
5162
|
+
if (last.author === SYSTEM) {
|
|
5163
|
+
return { status: "waiting", detail: w.yourTurn };
|
|
5030
5164
|
}
|
|
5031
|
-
|
|
5165
|
+
const said = `${name(last.author)}:${last.text.replace(/\s+/g, " ").slice(0, 120)}`;
|
|
5166
|
+
return { status: last.failed ? "failed" : "done", detail: said, endedAt: last.at };
|
|
5032
5167
|
}
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5168
|
+
entry(channel, members, faces, working, status, detail, endedAt) {
|
|
5169
|
+
return {
|
|
5170
|
+
id: channel.id,
|
|
5171
|
+
title: taskTitle(channel),
|
|
5172
|
+
status,
|
|
5173
|
+
detail,
|
|
5174
|
+
startedAt: channel.createdAt,
|
|
5175
|
+
endedAt: status === "running" || status === "waiting" ? undefined : endedAt,
|
|
5176
|
+
origin: channel.origin,
|
|
5177
|
+
icon: ({ size }) => /* @__PURE__ */ React.createElement(RoomFace, {
|
|
5178
|
+
members,
|
|
5179
|
+
faces,
|
|
5180
|
+
size,
|
|
5181
|
+
working
|
|
5182
|
+
}),
|
|
5183
|
+
open: () => openScene(this.context, channel),
|
|
5184
|
+
show: () => this.context.showChannel(channel.id),
|
|
5185
|
+
menu: () => taskMenu(this.context, channel, working),
|
|
5186
|
+
remove: () => deleteTeam(this.context, channel),
|
|
5187
|
+
removeHint: ChannelWords.format(ChannelViews.words(this.context.pi).deleteTaskHint, { channel: channel.name })
|
|
5188
|
+
};
|
|
5189
|
+
}
|
|
5190
|
+
}
|
|
5191
|
+
function taskTitle(channel) {
|
|
5192
|
+
return channel.name;
|
|
5193
|
+
}
|
|
5194
|
+
async function deleteTeam(context, channel) {
|
|
5195
|
+
await context.service.deleteChannel(channel.id);
|
|
5196
|
+
context.pi.ui.closeEditor(`channel:${channel.id}`);
|
|
5197
|
+
}
|
|
5198
|
+
function openScene(context, channel) {
|
|
5199
|
+
context.pi.ui.openEditor({
|
|
5200
|
+
id: `channel:${channel.id}`,
|
|
5201
|
+
title: channel.name,
|
|
5202
|
+
icon: ChannelViews.icon(context.pi, "Hash"),
|
|
5203
|
+
render: () => /* @__PURE__ */ React.createElement("div", {
|
|
5204
|
+
className: "tac-scene"
|
|
5205
|
+
}, /* @__PURE__ */ React.createElement(ChannelSceneHead, {
|
|
5206
|
+
context,
|
|
5207
|
+
channelId: channel.id
|
|
5208
|
+
}), /* @__PURE__ */ React.createElement(ChannelRoom, {
|
|
5209
|
+
context,
|
|
5210
|
+
channelId: channel.id
|
|
5211
|
+
}))
|
|
5212
|
+
});
|
|
5213
|
+
}
|
|
5214
|
+
function taskMenu(context, channel, working) {
|
|
5215
|
+
const { pi, service } = context;
|
|
5216
|
+
const w = ChannelViews.words(pi);
|
|
5217
|
+
const icon = (name) => ChannelViews.icon(pi, name);
|
|
5218
|
+
const act = (action2) => () => {
|
|
5219
|
+
Promise.resolve().then(action2).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"));
|
|
5220
|
+
};
|
|
5221
|
+
const temporary = membersOf(service.state.team, channel).filter((agent) => agent.temporary);
|
|
5222
|
+
return [
|
|
5223
|
+
working.length > 0 ? [
|
|
5224
|
+
{
|
|
5225
|
+
key: "stop",
|
|
5226
|
+
label: w.stopAnswering,
|
|
5227
|
+
icon: icon("Square"),
|
|
5228
|
+
run: act(async () => {
|
|
5229
|
+
await TeamActions.stop(context, working);
|
|
5230
|
+
pi.ui.notify(ChannelWords.format(w.stoppedChannel, { channel: channel.name }), "info");
|
|
5231
|
+
})
|
|
5039
5232
|
}
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5233
|
+
] : [],
|
|
5234
|
+
[
|
|
5235
|
+
{ key: "main", label: w.openInMain, icon: icon("ExternalLink"), run: () => context.showChannel(channel.id) },
|
|
5236
|
+
...temporary.length > 0 ? [
|
|
5237
|
+
{
|
|
5238
|
+
key: "keep",
|
|
5239
|
+
label: w.keepMembers,
|
|
5240
|
+
icon: icon("UserPlus"),
|
|
5241
|
+
run: act(async () => {
|
|
5242
|
+
await TeamActions.keep(context, temporary);
|
|
5243
|
+
pi.ui.notify(ChannelWords.format(w.keptMembers, { names: temporary.map((agent) => `@${agent.name}`).join("、") }), "info");
|
|
5244
|
+
})
|
|
5046
5245
|
}
|
|
5246
|
+
] : []
|
|
5247
|
+
],
|
|
5248
|
+
[
|
|
5249
|
+
{
|
|
5250
|
+
key: "delete",
|
|
5251
|
+
label: w.deleteTask,
|
|
5252
|
+
icon: icon("Trash2"),
|
|
5253
|
+
danger: true,
|
|
5254
|
+
run: act(() => pi.ui.removeTasks([
|
|
5255
|
+
{
|
|
5256
|
+
title: taskTitle(channel),
|
|
5257
|
+
removeHint: ChannelWords.format(w.deleteTaskHint, { channel: channel.name }),
|
|
5258
|
+
remove: () => deleteTeam(context, channel)
|
|
5259
|
+
}
|
|
5260
|
+
]))
|
|
5047
5261
|
}
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
const
|
|
5057
|
-
|
|
5262
|
+
]
|
|
5263
|
+
];
|
|
5264
|
+
}
|
|
5265
|
+
var TeamActions;
|
|
5266
|
+
((TeamActions) => {
|
|
5267
|
+
async function stop(context, agentIds) {
|
|
5268
|
+
const { pi, service } = context;
|
|
5269
|
+
const files = new Set(service.state.team.agents.filter((agent) => agentIds.includes(agent.id) && agent.sessionFile).map((agent) => agent.sessionFile));
|
|
5270
|
+
const sessions = (await pi.server.listSessions()).filter((session) => session.sessionFile && files.has(session.sessionFile));
|
|
5271
|
+
await Promise.all(sessions.map((session) => pi.server.abort(session.sessionId)));
|
|
5058
5272
|
}
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
const left = new Map;
|
|
5064
|
-
for (const pair of a) {
|
|
5065
|
-
left.set(pair, (left.get(pair) ?? 0) + 1);
|
|
5066
|
-
}
|
|
5067
|
-
let common = 0;
|
|
5068
|
-
for (const pair of b) {
|
|
5069
|
-
const n = left.get(pair) ?? 0;
|
|
5070
|
-
if (n > 0) {
|
|
5071
|
-
left.set(pair, n - 1);
|
|
5072
|
-
common++;
|
|
5073
|
-
}
|
|
5273
|
+
TeamActions.stop = stop;
|
|
5274
|
+
async function keep(context, agents) {
|
|
5275
|
+
for (const agent of agents) {
|
|
5276
|
+
await context.service.updateAgent(agent.id, { keep: true });
|
|
5074
5277
|
}
|
|
5075
|
-
return 2 * common / (a.length + b.length);
|
|
5076
5278
|
}
|
|
5077
|
-
|
|
5279
|
+
TeamActions.keep = keep;
|
|
5280
|
+
})(TeamActions ||= {});
|
|
5078
5281
|
|
|
5079
|
-
// web-src/
|
|
5080
|
-
function
|
|
5081
|
-
|
|
5082
|
-
}
|
|
5083
|
-
function useLimits(pi) {
|
|
5084
|
-
const read = React.useCallback(async () => ({
|
|
5085
|
-
limits: ChannelRounds.limits(await pi.storage.get(Keys.LIMITS)),
|
|
5086
|
-
...((today) => ({ spent: today.total, channels: today.channels }))(ChannelRounds.today(await pi.storage.get(Keys.SPENT), Date.now()))
|
|
5087
|
-
}), [pi]);
|
|
5088
|
-
const [value, setValue] = React.useState({ limits: ChannelRounds.limits(undefined), spent: 0, channels: {} });
|
|
5282
|
+
// web-src/shared-group.tsx
|
|
5283
|
+
function useFriends(pi) {
|
|
5284
|
+
const [friends, setFriends] = React.useState([]);
|
|
5089
5285
|
React.useEffect(() => {
|
|
5090
5286
|
let live = true;
|
|
5091
|
-
|
|
5287
|
+
pi.rooms?.listFriends().then((list) => live && setFriends(list.filter((friend) => friend.status === "friend")), () => {
|
|
5092
5288
|
return;
|
|
5093
5289
|
});
|
|
5094
|
-
load();
|
|
5095
|
-
const stop = pi.storage.onChange((keys) => (keys.includes(Keys.LIMITS) || keys.includes(Keys.SPENT)) && load());
|
|
5096
5290
|
return () => {
|
|
5097
5291
|
live = false;
|
|
5098
|
-
stop();
|
|
5099
5292
|
};
|
|
5100
|
-
}, [pi
|
|
5101
|
-
return
|
|
5293
|
+
}, [pi]);
|
|
5294
|
+
return friends;
|
|
5102
5295
|
}
|
|
5103
|
-
function
|
|
5104
|
-
const
|
|
5105
|
-
const
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
return /* @__PURE__ */ React.createElement("fieldset", {
|
|
5109
|
-
className: "ta-segmented",
|
|
5110
|
-
"aria-label": words()[key === "answer" ? "limitAnswer" : key === "channelDay" ? "limitChannelDay" : "limitAllDay"]
|
|
5111
|
-
}, LIMIT_CHOICES[key].map((value) => /* @__PURE__ */ React.createElement("button", {
|
|
5112
|
-
key: value,
|
|
5113
|
-
type: "button",
|
|
5114
|
-
"aria-pressed": limits[key] === value,
|
|
5115
|
-
className: limits[key] === value ? "ta-on" : "",
|
|
5116
|
-
onClick: () => pick(value)
|
|
5117
|
-
}, amount(pi, value))));
|
|
5118
|
-
};
|
|
5119
|
-
function Spent() {
|
|
5120
|
-
const { spent } = useLimits(pi);
|
|
5121
|
-
return /* @__PURE__ */ React.createElement("span", {
|
|
5122
|
-
className: "tac-limit-spent"
|
|
5123
|
-
}, spent > 0 ? amount(pi, spent) : "0");
|
|
5296
|
+
async function createShared(context, title, friends, agents) {
|
|
5297
|
+
const { pi } = context;
|
|
5298
|
+
const rooms = pi.rooms;
|
|
5299
|
+
if (!rooms) {
|
|
5300
|
+
throw new Error(ChannelViews.words(pi).sharedNeedsRooms);
|
|
5124
5301
|
}
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5302
|
+
const room = await rooms.createRoom({ kind: ROOMS_KIND, title });
|
|
5303
|
+
await rooms.inviteFriends(room.id, friends);
|
|
5304
|
+
await TeamActions.keep(context, context.service.state.team.agents.filter((agent) => agent.temporary && agents.includes(agent.id)));
|
|
5305
|
+
for (const agent of agents) {
|
|
5306
|
+
await pi.packages.callPackageHost(ROOMS_PACKAGE, "doubles", [{ kind: "invite", room: room.id, agent }]).catch((error) => {
|
|
5307
|
+
pi.ui.notify(ChannelViews.message(error), "error");
|
|
5308
|
+
});
|
|
5309
|
+
}
|
|
5310
|
+
const { link } = await rooms.invite(room.id);
|
|
5311
|
+
await pi.openLink?.(link);
|
|
5312
|
+
return room.id;
|
|
5313
|
+
}
|
|
5314
|
+
var ROOMS_PACKAGE = "@celljs/ta-rooms";
|
|
5315
|
+
var ROOMS_KIND = "ta-rooms";
|
|
5316
|
+
async function becomeGroup(context, channel, friends, agents) {
|
|
5317
|
+
const { pi } = context;
|
|
5318
|
+
const members = [...channel.members, ...agents.filter((id) => !channel.members.includes(id))];
|
|
5319
|
+
const room = await createShared(context, channel.name, friends, members);
|
|
5320
|
+
await context.service.updateChannel(channel.id, { shared: room });
|
|
5321
|
+
pi.ui.notify(ChannelWords.format(ChannelViews.words(pi).sharedMade, { name: channel.name }), "info");
|
|
5136
5322
|
}
|
|
5137
5323
|
|
|
5138
|
-
//
|
|
5139
|
-
var
|
|
5140
|
-
var
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
const
|
|
5145
|
-
const
|
|
5146
|
-
|
|
5147
|
-
const tools = map(given === null || given === undefined ? undefined : given.tools);
|
|
5148
|
-
return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
|
|
5324
|
+
// web-src/create.tsx
|
|
5325
|
+
var noBack = (_open, _close) => false;
|
|
5326
|
+
var AGENT_PAGE = `${NAME}/agent`;
|
|
5327
|
+
function newAgent(context) {
|
|
5328
|
+
const { pi, service, ui } = context;
|
|
5329
|
+
if (!ui.state.draft) {
|
|
5330
|
+
const team = service.state.team;
|
|
5331
|
+
const name = ChannelsUtil.freeName(team, ChannelViews.words(pi).newAgentName);
|
|
5332
|
+
ui.set({ draft: { name, face: ChannelsUtil.freeFaceFor(team.agents, ChannelsUtil.newId("draft")) } });
|
|
5149
5333
|
}
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5334
|
+
pi.ui.showView(AGENT_PAGE);
|
|
5335
|
+
}
|
|
5336
|
+
function Identity({ context, onClose }) {
|
|
5337
|
+
const { pi, ui } = context;
|
|
5338
|
+
const { draft } = useUi(ui);
|
|
5339
|
+
const w = ChannelViews.words(pi);
|
|
5340
|
+
const ref = React.useRef(null);
|
|
5341
|
+
const name = React.useRef(null);
|
|
5342
|
+
React.useEffect(() => name.current?.select(), []);
|
|
5343
|
+
(pi.ui.useBackLayer ?? noBack)(true, onClose);
|
|
5344
|
+
React.useEffect(() => {
|
|
5345
|
+
const close = (event) => {
|
|
5346
|
+
const target = event.target;
|
|
5347
|
+
if (!ref.current?.contains(target) && !target.closest?.(".tac-identity-open")) {
|
|
5348
|
+
onClose();
|
|
5349
|
+
}
|
|
5157
5350
|
};
|
|
5158
|
-
|
|
5351
|
+
const onKey = (event) => event.key === "Escape" && onClose();
|
|
5352
|
+
document.addEventListener("pointerdown", close);
|
|
5353
|
+
document.addEventListener("keydown", onKey);
|
|
5354
|
+
return () => {
|
|
5355
|
+
document.removeEventListener("pointerdown", close);
|
|
5356
|
+
document.removeEventListener("keydown", onKey);
|
|
5357
|
+
};
|
|
5358
|
+
}, [onClose]);
|
|
5359
|
+
if (!draft) {
|
|
5360
|
+
return null;
|
|
5159
5361
|
}
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
}
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
|
|
5197
|
-
action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
|
|
5198
|
-
action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
|
|
5199
|
-
action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
|
|
5200
|
-
action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
|
|
5201
|
-
action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
|
|
5202
|
-
];
|
|
5203
|
-
var TA_OWNER_ACTIONS = [
|
|
5204
|
-
action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
|
|
5205
|
-
action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
|
|
5206
|
-
];
|
|
5207
|
-
var OWNER_AREAS = ["desktop"];
|
|
5208
|
-
var TaActionUtil;
|
|
5209
|
-
(function(TaActionUtil2) {
|
|
5210
|
-
const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
|
|
5211
|
-
const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
|
|
5212
|
-
function info(id) {
|
|
5213
|
-
return byId.get(id);
|
|
5362
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
5363
|
+
className: "tac-identity",
|
|
5364
|
+
ref,
|
|
5365
|
+
role: "dialog",
|
|
5366
|
+
"aria-label": w.editAgent
|
|
5367
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
5368
|
+
className: "tac-identity-label"
|
|
5369
|
+
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
5370
|
+
className: "tac-input",
|
|
5371
|
+
value: draft.name,
|
|
5372
|
+
maxLength: 40,
|
|
5373
|
+
ref: name,
|
|
5374
|
+
onChange: (event) => ui.set({ draft: { ...draft, name: event.target.value } }),
|
|
5375
|
+
onKeyDown: (event) => event.key === "Enter" && onClose()
|
|
5376
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
5377
|
+
className: "tac-identity-label"
|
|
5378
|
+
}, w.avatar), /* @__PURE__ */ React.createElement("div", {
|
|
5379
|
+
className: "tac-faces"
|
|
5380
|
+
}, Array.from({ length: FACES }, (_, face) => /* @__PURE__ */ React.createElement("button", {
|
|
5381
|
+
key: face,
|
|
5382
|
+
type: "button",
|
|
5383
|
+
"aria-pressed": draft.face === face,
|
|
5384
|
+
className: `tac-face-pick${draft.face === face ? " tac-on" : ""}`,
|
|
5385
|
+
onClick: () => ui.set({ draft: { ...draft, face } })
|
|
5386
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
5387
|
+
face,
|
|
5388
|
+
size: 30
|
|
5389
|
+
})))));
|
|
5390
|
+
}
|
|
5391
|
+
function NewAgentHead({ context }) {
|
|
5392
|
+
const { pi, ui } = context;
|
|
5393
|
+
const { draft, editing } = useUi(ui);
|
|
5394
|
+
const w = ChannelViews.words(pi);
|
|
5395
|
+
const Down = ChannelViews.icon(pi, "ChevronDown");
|
|
5396
|
+
if (!draft) {
|
|
5397
|
+
return null;
|
|
5214
5398
|
}
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5399
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
5400
|
+
className: "tac-new-head"
|
|
5401
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
5402
|
+
className: "tac-new-title"
|
|
5403
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
5404
|
+
type: "button",
|
|
5405
|
+
className: "tac-new-trigger tac-identity-open",
|
|
5406
|
+
"aria-expanded": editing,
|
|
5407
|
+
title: w.editAgent,
|
|
5408
|
+
onClick: () => ui.set({ editing: !editing })
|
|
5409
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
5410
|
+
face: draft.face,
|
|
5411
|
+
size: 20
|
|
5412
|
+
}), /* @__PURE__ */ React.createElement("span", null, draft.name || w.newAgentName), /* @__PURE__ */ React.createElement(Down, {
|
|
5413
|
+
size: 14
|
|
5414
|
+
})), editing && /* @__PURE__ */ React.createElement(Identity, {
|
|
5415
|
+
context,
|
|
5416
|
+
onClose: () => ui.set({ editing: false })
|
|
5417
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
5418
|
+
type: "button",
|
|
5419
|
+
className: "tac-button tac-quiet",
|
|
5420
|
+
onClick: () => {
|
|
5421
|
+
ui.set({ draft: undefined, editing: false });
|
|
5422
|
+
pi.ui.showView("");
|
|
5222
5423
|
}
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
return
|
|
5424
|
+
}, w.cancel));
|
|
5425
|
+
}
|
|
5426
|
+
function NewAgentPage({ context }) {
|
|
5427
|
+
const { pi, service, ui } = context;
|
|
5428
|
+
const { draft } = useUi(ui);
|
|
5429
|
+
const { loaded } = useChannels(service);
|
|
5430
|
+
const w = ChannelViews.words(pi);
|
|
5431
|
+
const Pencil = ChannelViews.icon(pi, "Pencil");
|
|
5432
|
+
const Composer = pi.ui.Composer;
|
|
5433
|
+
const first = React.useRef(true);
|
|
5434
|
+
React.useEffect(() => {
|
|
5435
|
+
if (!loaded || !first.current) {
|
|
5436
|
+
return;
|
|
5437
|
+
}
|
|
5438
|
+
first.current = false;
|
|
5439
|
+
if (!ui.state.draft) {
|
|
5440
|
+
newAgent(context);
|
|
5441
|
+
}
|
|
5442
|
+
}, [loaded, ui, context]);
|
|
5443
|
+
if (!draft) {
|
|
5444
|
+
return null;
|
|
5244
5445
|
}
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
(
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
conventions: "conventions",
|
|
5256
|
-
待办: "todo",
|
|
5257
|
-
"to do": "todo",
|
|
5258
|
-
todo: "todo",
|
|
5259
|
-
"to-do": "todo"
|
|
5260
|
-
};
|
|
5261
|
-
function counts(text) {
|
|
5262
|
-
const counts2 = { decisions: 0, conventions: 0, todo: 0, done: 0 };
|
|
5263
|
-
let part;
|
|
5264
|
-
for (const line of text.split(/\r?\n/)) {
|
|
5265
|
-
const heading = /^\s*#{1,6}\s+(.+?)\s*#*\s*$/.exec(line) ?? /^\s*\*\*(.+?)\*\*\s*[::]?\s*$/.exec(line);
|
|
5266
|
-
if (heading) {
|
|
5267
|
-
part = PARTS[heading[1].replace(/[::]$/, "").trim().toLowerCase()];
|
|
5268
|
-
continue;
|
|
5269
|
-
}
|
|
5270
|
-
const item = /^\s*(?:[-*+]|\d+[.)])\s+(\[( |x|X)\]\s+)?\S/.exec(line);
|
|
5271
|
-
if (!part || !item) {
|
|
5272
|
-
continue;
|
|
5273
|
-
}
|
|
5274
|
-
if (part === "todo" && item[2] && item[2] !== " ") {
|
|
5275
|
-
counts2.done++;
|
|
5276
|
-
} else {
|
|
5277
|
-
counts2[part]++;
|
|
5278
|
-
}
|
|
5279
|
-
}
|
|
5280
|
-
return counts2;
|
|
5281
|
-
}
|
|
5282
|
-
NoticeUtil.counts = counts;
|
|
5283
|
-
function firstLine(text) {
|
|
5284
|
-
for (const line of text.split(/\r?\n/)) {
|
|
5285
|
-
const item = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?(.+)$/.exec(line);
|
|
5286
|
-
if (item) {
|
|
5287
|
-
return item[1].replace(/[*_`~]+/g, "").trim();
|
|
5288
|
-
}
|
|
5289
|
-
}
|
|
5290
|
-
return text.split(/\r?\n/).find((line) => line.trim() && !/^\s*#/.test(line))?.trim() ?? "";
|
|
5291
|
-
}
|
|
5292
|
-
NoticeUtil.firstLine = firstLine;
|
|
5293
|
-
})(NoticeUtil ||= {});
|
|
5294
|
-
|
|
5295
|
-
// web-src/notice.tsx
|
|
5296
|
-
var NoticeView;
|
|
5297
|
-
((NoticeView) => {
|
|
5298
|
-
function display(text) {
|
|
5299
|
-
return text.replace(/^(\s*[-*+]\s+)\[ \]\s+/gm, "$1☐ ").replace(/^(\s*[-*+]\s+)\[[xX]\]\s+/gm, "$1☑ ");
|
|
5300
|
-
}
|
|
5301
|
-
NoticeView.display = display;
|
|
5302
|
-
function counts(text, language) {
|
|
5303
|
-
const w = ChannelWords.of(language);
|
|
5304
|
-
const counts2 = NoticeUtil.counts(text);
|
|
5305
|
-
if (counts2.decisions + counts2.conventions + counts2.todo === 0) {
|
|
5306
|
-
return NoticeUtil.firstLine(text);
|
|
5446
|
+
const send = async (text) => {
|
|
5447
|
+
const agent = await service.createAgent({ name: draft.name, role: DEFAULT_ROLE, face: draft.face, cwd: draft.cwd });
|
|
5448
|
+
ui.set({ draft: undefined, editing: false });
|
|
5449
|
+
try {
|
|
5450
|
+
const sessionId = await service.openAgent(agent.id);
|
|
5451
|
+
context.sessions.set(agent.id, sessionId);
|
|
5452
|
+
await pi.switchSession(sessionId);
|
|
5453
|
+
await pi.sendUserMessage(text);
|
|
5454
|
+
} catch (error) {
|
|
5455
|
+
pi.ui.notify(ChannelViews.message(error), "error");
|
|
5307
5456
|
}
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
}) {
|
|
5457
|
+
};
|
|
5458
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
5459
|
+
className: "tac-new-page"
|
|
5460
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
5461
|
+
className: "tac-new-col"
|
|
5462
|
+
}, /* @__PURE__ */ React.createElement(Face, {
|
|
5463
|
+
face: draft.face,
|
|
5464
|
+
size: 88
|
|
5465
|
+
}), /* @__PURE__ */ React.createElement("h2", {
|
|
5466
|
+
className: "tac-new-name"
|
|
5467
|
+
}, /* @__PURE__ */ React.createElement("span", null, draft.name || w.newAgentName), /* @__PURE__ */ React.createElement("button", {
|
|
5468
|
+
type: "button",
|
|
5469
|
+
className: "tac-action tac-identity-open",
|
|
5470
|
+
title: w.editAgent,
|
|
5471
|
+
"aria-label": w.editAgent,
|
|
5472
|
+
onClick: () => ui.set({ editing: !ui.state.editing })
|
|
5473
|
+
}, /* @__PURE__ */ React.createElement(Pencil, {
|
|
5474
|
+
size: 14
|
|
5475
|
+
}))), /* @__PURE__ */ React.createElement("p", {
|
|
5476
|
+
className: "tac-new-hint"
|
|
5477
|
+
}, w.newAgentHint), /* @__PURE__ */ React.createElement("div", {
|
|
5478
|
+
className: "tac-new-box"
|
|
5479
|
+
}, /* @__PURE__ */ React.createElement(Composer, {
|
|
5480
|
+
placeholder: ChannelWords.format(w.agentPlaceholder, { name: draft.name || w.newAgentName }),
|
|
5481
|
+
onSend: send,
|
|
5482
|
+
cwd: draft.cwd,
|
|
5483
|
+
onPickCwd: (cwd) => ui.set({ draft: { ...draft, cwd } }),
|
|
5484
|
+
draft: "new-agent"
|
|
5485
|
+
}))));
|
|
5486
|
+
}
|
|
5487
|
+
function NewChannelDialog({ context, onClose }) {
|
|
5319
5488
|
const { pi, service } = context;
|
|
5320
5489
|
const { team } = useChannels(service);
|
|
5490
|
+
const faces = useFaces(team);
|
|
5321
5491
|
const w = ChannelViews.words(pi);
|
|
5322
|
-
const
|
|
5323
|
-
const
|
|
5492
|
+
const Search = ChannelViews.icon(pi, "Search");
|
|
5493
|
+
const Check = ChannelViews.icon(pi, "Check");
|
|
5494
|
+
const [name, setName] = React.useState("");
|
|
5495
|
+
const [query, setQuery] = React.useState("");
|
|
5496
|
+
const [picked, setPicked] = React.useState([]);
|
|
5497
|
+
const friends = useFriends(pi);
|
|
5498
|
+
const [pickedFriends, setPickedFriends] = React.useState([]);
|
|
5499
|
+
const shared = pickedFriends.length > 0;
|
|
5500
|
+
const toggleFriend = (friend) => setPickedFriends(pickedFriends.includes(friend.id) ? pickedFriends.filter((id) => id !== friend.id) : [...pickedFriends, friend.id]);
|
|
5324
5501
|
const [busy, setBusy] = React.useState(false);
|
|
5325
5502
|
const [error, setError] = React.useState();
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
}, [state.editing]);
|
|
5332
|
-
if (!notice && !state.editing) {
|
|
5333
|
-
return null;
|
|
5334
|
-
}
|
|
5335
|
-
const Megaphone = ChannelViews.icon(pi, "Megaphone");
|
|
5336
|
-
const Chevron = ChannelViews.icon(pi, "ChevronDown");
|
|
5337
|
-
const Markdown = pi.ui.Markdown;
|
|
5338
|
-
const save = (event) => {
|
|
5503
|
+
const Dialog = pi.ui.Dialog;
|
|
5504
|
+
const shown = team.agents.filter((agent) => SidebarUtil.matches(query, agent.name, agent.role));
|
|
5505
|
+
const full = picked.length >= MAX_MEMBERS;
|
|
5506
|
+
const toggle = (agent) => setPicked(picked.includes(agent.id) ? picked.filter((id) => id !== agent.id) : full ? picked : [...picked, agent.id]);
|
|
5507
|
+
const create = (event) => {
|
|
5339
5508
|
event.preventDefault();
|
|
5340
5509
|
setBusy(true);
|
|
5341
5510
|
setError(undefined);
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5511
|
+
if (shared) {
|
|
5512
|
+
createShared(context, name.trim(), pickedFriends, picked).then(onClose, (failure) => {
|
|
5513
|
+
setBusy(false);
|
|
5514
|
+
setError(ChannelViews.message(failure));
|
|
5515
|
+
});
|
|
5516
|
+
return;
|
|
5517
|
+
}
|
|
5518
|
+
service.createChannel({ name, members: picked }).then((channel) => {
|
|
5519
|
+
onClose();
|
|
5520
|
+
context.showChannel(channel.id);
|
|
5345
5521
|
}, (failure) => {
|
|
5346
5522
|
setBusy(false);
|
|
5347
5523
|
setError(ChannelViews.message(failure));
|
|
5348
5524
|
});
|
|
5349
5525
|
};
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
"
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
})), /* @__PURE__ */ React.createElement("
|
|
5366
|
-
className: "tac-
|
|
5367
|
-
},
|
|
5368
|
-
className: "tac-
|
|
5369
|
-
}, /* @__PURE__ */ React.createElement(
|
|
5526
|
+
return /* @__PURE__ */ React.createElement(Dialog, {
|
|
5527
|
+
title: w.newChannel,
|
|
5528
|
+
onClose
|
|
5529
|
+
}, /* @__PURE__ */ React.createElement("form", {
|
|
5530
|
+
className: "tac-dialog",
|
|
5531
|
+
onSubmit: create
|
|
5532
|
+
}, /* @__PURE__ */ React.createElement("label", {
|
|
5533
|
+
className: "tac-dialog-label"
|
|
5534
|
+
}, w.name, /* @__PURE__ */ React.createElement("input", {
|
|
5535
|
+
className: "tac-input tac-dialog-input",
|
|
5536
|
+
value: name,
|
|
5537
|
+
placeholder: w.channelNamePlaceholder,
|
|
5538
|
+
maxLength: 40,
|
|
5539
|
+
autoFocus: true,
|
|
5540
|
+
onChange: (event) => setName(event.target.value)
|
|
5541
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
5542
|
+
className: "tac-dialog-label"
|
|
5543
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.addAgents), /* @__PURE__ */ React.createElement("span", {
|
|
5544
|
+
className: "tac-dialog-count"
|
|
5545
|
+
}, picked.length, "/", MAX_MEMBERS)), /* @__PURE__ */ React.createElement("label", {
|
|
5546
|
+
className: "tac-dialog-search"
|
|
5547
|
+
}, /* @__PURE__ */ React.createElement(Search, {
|
|
5370
5548
|
size: 15
|
|
5371
|
-
})
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
text: NoticeView.display(notice.text)
|
|
5549
|
+
}), /* @__PURE__ */ React.createElement("input", {
|
|
5550
|
+
value: query,
|
|
5551
|
+
placeholder: ChannelWords.format(w.searchAgents, { max: String(MAX_MEMBERS) }),
|
|
5552
|
+
"aria-label": w.search,
|
|
5553
|
+
onChange: (event) => setQuery(event.target.value)
|
|
5377
5554
|
})), /* @__PURE__ */ React.createElement("div", {
|
|
5378
|
-
className: "tac-
|
|
5379
|
-
}, /* @__PURE__ */ React.createElement(
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
},
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
}
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
}
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
}
|
|
5451
|
-
|
|
5452
|
-
const { pi, service } = context;
|
|
5453
|
-
const images = message.images ?? [];
|
|
5454
|
-
const [sources, setSources] = React.useState({});
|
|
5455
|
-
const ids = images.map((image) => image.id).join(",");
|
|
5456
|
-
React.useEffect(() => {
|
|
5457
|
-
let live = true;
|
|
5458
|
-
for (const id of ids ? ids.split(",") : []) {
|
|
5459
|
-
service.picture(channelId, id).then((data) => live && data && setSources((current) => ({ ...current, [id]: data })));
|
|
5460
|
-
}
|
|
5461
|
-
return () => {
|
|
5462
|
-
live = false;
|
|
5463
|
-
};
|
|
5464
|
-
}, [service, channelId, ids]);
|
|
5465
|
-
const ChatImages = pi.ui.ChatImages;
|
|
5466
|
-
if (!images.length || !ChatImages) {
|
|
5467
|
-
return null;
|
|
5468
|
-
}
|
|
5469
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
5470
|
-
className: "tac-pics"
|
|
5471
|
-
}, /* @__PURE__ */ React.createElement(ChatImages, {
|
|
5472
|
-
alt,
|
|
5473
|
-
images: images.map((image) => ({ key: image.id, src: sources[image.id], width: image.w, height: image.h }))
|
|
5474
|
-
}));
|
|
5475
|
-
}
|
|
5476
|
-
function Mentions({ text, agents }) {
|
|
5477
|
-
const names = new Set(agents.map((agent) => agent.name.toLowerCase()));
|
|
5478
|
-
const parts = text.split(/(@[^\s@#,,。::]+)/);
|
|
5479
|
-
return /* @__PURE__ */ React.createElement("span", null, parts.map((part, index) => part.startsWith("@") && names.has(part.slice(1).toLowerCase()) ? /* @__PURE__ */ React.createElement("span", {
|
|
5480
|
-
key: index,
|
|
5481
|
-
className: "tac-mention"
|
|
5482
|
-
}, part) : part));
|
|
5483
|
-
}
|
|
5484
|
-
function StopLine({
|
|
5485
|
-
context,
|
|
5486
|
-
channel,
|
|
5487
|
-
message,
|
|
5488
|
-
later,
|
|
5489
|
-
agents
|
|
5490
|
-
}) {
|
|
5491
|
-
const { pi, service } = context;
|
|
5492
|
-
const w = ChannelViews.words(pi);
|
|
5493
|
-
const [busy, setBusy] = React.useState(false);
|
|
5494
|
-
const stop = message.stop;
|
|
5495
|
-
const lead = agents.find((agent) => agent.id === channel.members.find((id) => !(channel.muted ?? []).includes(id)));
|
|
5496
|
-
const replies = String(stop?.replies ?? 0);
|
|
5497
|
-
const tokens = stop?.tokens ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(stop.tokens) : "";
|
|
5498
|
-
const stats = stop ? ChannelWords.format(tokens ? w.stoppedStats : w.stoppedReplies, { replies, tokens }) : "";
|
|
5499
|
-
const resumed = stop?.resumed === "continue" ? w.wentOn : stop?.resumed === "wrapUp" ? w.summedUp : "";
|
|
5500
|
-
const why = stop?.daily === "all" ? w.dailyAll : stop?.daily === "channel" ? w.dailyChannel : stop?.idle === "repeat" ? w.idleRepeat : stop?.idle === "agree" ? w.idleAgree : stop?.idle === "pingPong" ? w.idlePingPong : w.stopped;
|
|
5501
|
-
const extended = stop?.extended ? w.extendedOnce : "";
|
|
5502
|
-
const go = (how) => {
|
|
5503
|
-
setBusy(true);
|
|
5504
|
-
service.resumeRound(channel.id, message.id, how).catch((error) => pi.ui.notify(ChannelViews.message(error), "error")).finally(() => setBusy(false));
|
|
5505
|
-
};
|
|
5506
|
-
const open = !!stop?.pending.length && !stop.resumed && !later;
|
|
5507
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
5508
|
-
className: "tac-stop",
|
|
5509
|
-
role: "note"
|
|
5510
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
5511
|
-
className: "tac-notice"
|
|
5512
|
-
}, why), /* @__PURE__ */ React.createElement("div", {
|
|
5513
|
-
className: "tac-stop-meta"
|
|
5514
|
-
}, [stats, extended, resumed].filter(Boolean).join(" · ")), open && /* @__PURE__ */ React.createElement("div", {
|
|
5515
|
-
className: "tac-stop-actions"
|
|
5555
|
+
className: "tac-pick-list"
|
|
5556
|
+
}, team.agents.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
5557
|
+
compact: true,
|
|
5558
|
+
title: w.noAgents,
|
|
5559
|
+
hint: w.noAgentsHint
|
|
5560
|
+
}), team.agents.length > 0 && shown.length === 0 && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
5561
|
+
compact: true,
|
|
5562
|
+
title: w.noMatch
|
|
5563
|
+
}), shown.map((agent) => {
|
|
5564
|
+
const on = picked.includes(agent.id);
|
|
5565
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
5566
|
+
key: agent.id,
|
|
5567
|
+
type: "button",
|
|
5568
|
+
"aria-pressed": on,
|
|
5569
|
+
disabled: !on && full,
|
|
5570
|
+
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
5571
|
+
onClick: () => toggle(agent)
|
|
5572
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
5573
|
+
className: "tac-check"
|
|
5574
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
5575
|
+
size: 13,
|
|
5576
|
+
strokeWidth: 3
|
|
5577
|
+
})), /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
5578
|
+
agent,
|
|
5579
|
+
faces,
|
|
5580
|
+
size: 30
|
|
5581
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
5582
|
+
className: "tac-pick-text"
|
|
5583
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
5584
|
+
className: "tac-pick-name"
|
|
5585
|
+
}, agent.name, picked[0] === agent.id && /* @__PURE__ */ React.createElement("span", {
|
|
5586
|
+
className: "tac-msg-lead"
|
|
5587
|
+
}, w.lead)), /* @__PURE__ */ React.createElement("span", {
|
|
5588
|
+
className: "tac-pick-role"
|
|
5589
|
+
}, agent.role.split(`
|
|
5590
|
+
`)[0])));
|
|
5591
|
+
})), friends.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
5592
|
+
className: "tac-dialog-label"
|
|
5593
|
+
}, /* @__PURE__ */ React.createElement("span", null, w.addFriends), shared && /* @__PURE__ */ React.createElement("span", {
|
|
5594
|
+
className: "tac-dialog-count"
|
|
5595
|
+
}, pickedFriends.length)), /* @__PURE__ */ React.createElement("div", {
|
|
5596
|
+
className: "tac-pick-list"
|
|
5597
|
+
}, friends.map((friend) => {
|
|
5598
|
+
const on = pickedFriends.includes(friend.id);
|
|
5599
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
5600
|
+
key: friend.id,
|
|
5601
|
+
type: "button",
|
|
5602
|
+
"aria-pressed": on,
|
|
5603
|
+
className: `tac-pick${on ? " tac-on" : ""}`,
|
|
5604
|
+
onClick: () => toggleFriend(friend)
|
|
5605
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
5606
|
+
className: "tac-check"
|
|
5607
|
+
}, on && /* @__PURE__ */ React.createElement(Check, {
|
|
5608
|
+
size: 13,
|
|
5609
|
+
strokeWidth: 3
|
|
5610
|
+
})), pi.ui.Face ? /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
5611
|
+
seed: friend.id,
|
|
5612
|
+
size: 30,
|
|
5613
|
+
look: friend.look
|
|
5614
|
+
}) : /* @__PURE__ */ React.createElement("span", {
|
|
5615
|
+
className: "tac-pick-face"
|
|
5616
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
5617
|
+
className: "tac-pick-text"
|
|
5618
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
5619
|
+
className: "tac-pick-name"
|
|
5620
|
+
}, friend.name), /* @__PURE__ */ React.createElement("span", {
|
|
5621
|
+
className: "tac-pick-role"
|
|
5622
|
+
}, w.friend)));
|
|
5623
|
+
}))), (picked.length > 0 || shared) && /* @__PURE__ */ React.createElement("div", {
|
|
5624
|
+
className: "tac-dialog-note"
|
|
5625
|
+
}, shared ? w.sharedHint : w.membersHint), error && /* @__PURE__ */ React.createElement("div", {
|
|
5626
|
+
className: "tac-empty tac-error"
|
|
5627
|
+
}, error), /* @__PURE__ */ React.createElement("div", {
|
|
5628
|
+
className: "tac-dialog-actions"
|
|
5516
5629
|
}, /* @__PURE__ */ React.createElement("button", {
|
|
5517
|
-
type: "
|
|
5518
|
-
className: "tac-
|
|
5519
|
-
disabled: busy
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
className: "tac-stop-button",
|
|
5524
|
-
disabled: busy,
|
|
5525
|
-
onClick: () => go("wrapUp")
|
|
5526
|
-
}, ChannelWords.format(w.wrapUp, { name: `@${lead.name}` }))));
|
|
5630
|
+
type: "submit",
|
|
5631
|
+
className: busy ? "tac-button tac-primary ta-busy" : "tac-button tac-primary",
|
|
5632
|
+
disabled: busy || !name.trim() || picked.length === 0 && !shared
|
|
5633
|
+
}, w.create, busy && /* @__PURE__ */ React.createElement("span", {
|
|
5634
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
5635
|
+
})))));
|
|
5527
5636
|
}
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
const
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5637
|
+
|
|
5638
|
+
// web-src/handoff.ts
|
|
5639
|
+
var HandOff;
|
|
5640
|
+
((HandOff) => {
|
|
5641
|
+
HandOff.TOOL = "hand_off";
|
|
5642
|
+
HandOff.CARD = "ta-channels-handoff";
|
|
5643
|
+
HandOff.BLOCK = "ta-handoff";
|
|
5644
|
+
const MARK = /\[ta-handoff:([^\]\s]+)\]/;
|
|
5645
|
+
HandOff.DEFINITION = {
|
|
5646
|
+
name: HandOff.TOOL,
|
|
5647
|
+
label: "Hand off",
|
|
5648
|
+
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.",
|
|
5649
|
+
promptSnippet: "Hand the work over to one of the user's agents or channels",
|
|
5650
|
+
parameters: {
|
|
5651
|
+
type: "object",
|
|
5652
|
+
properties: {
|
|
5653
|
+
to: { type: "string", description: "@name of an agent or #name of a channel." },
|
|
5654
|
+
brief: { type: "string", description: "Complete in itself: the receiver sees only this." }
|
|
5655
|
+
},
|
|
5656
|
+
required: ["to", "brief"]
|
|
5541
5657
|
}
|
|
5542
|
-
}
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
return null;
|
|
5658
|
+
};
|
|
5659
|
+
function ref(target) {
|
|
5660
|
+
return `${target.kind === "agent" ? "@" : "#"}${target.name}`;
|
|
5546
5661
|
}
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
}, /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
5568
|
-
agent,
|
|
5569
|
-
faces,
|
|
5570
|
-
size: 24,
|
|
5571
|
-
working: working.includes(agent.id)
|
|
5572
|
-
}))), members.length > 5 && /* @__PURE__ */ React.createElement("span", {
|
|
5573
|
-
className: "tac-head-more"
|
|
5574
|
-
}, "+", members.length - 5)));
|
|
5575
|
-
}
|
|
5576
|
-
function ChannelSceneHead({ context, channelId }) {
|
|
5577
|
-
const { pi, service } = context;
|
|
5578
|
-
const state = useChannels(service);
|
|
5579
|
-
const faces = useFaces(state.team);
|
|
5580
|
-
const w = ChannelViews.words(pi);
|
|
5581
|
-
const channel = state.team.channels.find((candidate) => candidate.id === channelId);
|
|
5582
|
-
if (!channel) {
|
|
5583
|
-
return null;
|
|
5584
|
-
}
|
|
5585
|
-
const members = membersOf(state.team, channel);
|
|
5586
|
-
const working = state.working[channel.id] ?? [];
|
|
5587
|
-
const External = ChannelViews.icon(pi, "ExternalLink");
|
|
5588
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
5589
|
-
className: "tac-scene-head"
|
|
5590
|
-
}, /* @__PURE__ */ React.createElement(RoomFace, {
|
|
5591
|
-
members,
|
|
5592
|
-
faces,
|
|
5593
|
-
size: 26,
|
|
5594
|
-
working
|
|
5595
|
-
}), /* @__PURE__ */ React.createElement("div", {
|
|
5596
|
-
className: "tac-scene-title"
|
|
5597
|
-
}, /* @__PURE__ */ React.createElement("strong", null, channel.name), /* @__PURE__ */ React.createElement("span", null, channel.topic ?? ChannelWords.format(w.memberCount, { count: String(members.length) }))), /* @__PURE__ */ React.createElement("button", {
|
|
5598
|
-
type: "button",
|
|
5599
|
-
className: "tac-button tac-scene-main",
|
|
5600
|
-
title: w.openInMainHint,
|
|
5601
|
-
onClick: () => context.showChannel(channel.id)
|
|
5602
|
-
}, /* @__PURE__ */ React.createElement(External, {
|
|
5603
|
-
size: 13
|
|
5604
|
-
}), w.openInMain));
|
|
5605
|
-
}
|
|
5606
|
-
var mePromise;
|
|
5607
|
-
function useMe(pi) {
|
|
5608
|
-
const [me, setMe] = React.useState(TA_OWNER);
|
|
5609
|
-
React.useEffect(() => {
|
|
5610
|
-
mePromise ??= pi.server.getServerInfo().then((info) => info.member?.id ?? TA_OWNER, () => TA_OWNER);
|
|
5611
|
-
let live = true;
|
|
5612
|
-
mePromise.then((id) => live && setMe(id));
|
|
5613
|
-
return () => {
|
|
5614
|
-
live = false;
|
|
5615
|
-
};
|
|
5616
|
-
}, [pi]);
|
|
5617
|
-
return me;
|
|
5618
|
-
}
|
|
5619
|
-
function ChannelRoom({ context, channelId: fixed }) {
|
|
5620
|
-
const { pi, service, ui } = context;
|
|
5621
|
-
const me = useMe(pi);
|
|
5622
|
-
const state = useChannels(service);
|
|
5623
|
-
const shown = useUi(ui).channelId;
|
|
5624
|
-
const channelId = fixed ?? shown;
|
|
5625
|
-
const faces = useFaces(state.team);
|
|
5626
|
-
const w = ChannelViews.words(pi);
|
|
5627
|
-
const channel = state.team.channels.find((candidate) => candidate.id === channelId);
|
|
5628
|
-
const messages = channel ? state.messages[channel.id] : undefined;
|
|
5629
|
-
const working = channel ? state.working[channel.id] ?? [] : [];
|
|
5630
|
-
React.useEffect(() => {
|
|
5631
|
-
if (channelId) {
|
|
5632
|
-
service.messages(channelId);
|
|
5633
|
-
}
|
|
5634
|
-
}, [service, channelId]);
|
|
5635
|
-
const page = pi.ui.useView(CHANNEL_PAGE);
|
|
5636
|
-
const inFront = !!channelId && (!!fixed || !!page?.shown);
|
|
5637
|
-
const lastAt = ChannelSeenUtil.lastAt(messages);
|
|
5638
|
-
const resting = working.length === 0;
|
|
5639
|
-
React.useEffect(() => {
|
|
5640
|
-
if (!channelId || !inFront || !resting) {
|
|
5641
|
-
return;
|
|
5642
|
-
}
|
|
5643
|
-
const look = () => document.visibilityState === "visible" && context.seen.look(channelId, Math.max(Date.now(), lastAt ?? 0));
|
|
5644
|
-
look();
|
|
5645
|
-
document.addEventListener("visibilitychange", look);
|
|
5646
|
-
return () => document.removeEventListener("visibilitychange", look);
|
|
5647
|
-
}, [context, channelId, inFront, resting, lastAt]);
|
|
5648
|
-
React.useEffect(() => {
|
|
5649
|
-
if (!channelId) {
|
|
5650
|
-
return;
|
|
5651
|
-
}
|
|
5652
|
-
const watch = () => document.visibilityState === "visible" && void service.watch(channelId).catch(() => {
|
|
5653
|
-
return;
|
|
5662
|
+
HandOff.ref = ref;
|
|
5663
|
+
function ask(language, to) {
|
|
5664
|
+
const fence = "```";
|
|
5665
|
+
const context = [
|
|
5666
|
+
`[ta-handoff:${to}]`,
|
|
5667
|
+
`The user hands the work of this conversation over to ${to}, which does not see this conversation.`,
|
|
5668
|
+
`- 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.`,
|
|
5669
|
+
`- With the tool ${HandOff.TOOL}, call it with to "${to}" and the brief, then say in one line that it went.`,
|
|
5670
|
+
`- 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):`,
|
|
5671
|
+
`${fence}${HandOff.BLOCK}`,
|
|
5672
|
+
"<the brief>",
|
|
5673
|
+
fence,
|
|
5674
|
+
`- When the conversation holds nothing to hand over yet, say so and ask what ${to} should do.`
|
|
5675
|
+
].join(`
|
|
5676
|
+
`);
|
|
5677
|
+
const line = TaLanguageUtil.pick(language, {
|
|
5678
|
+
"zh-CN": `把这件事交给 ${to}`,
|
|
5679
|
+
"zh-TW": `把這件事交給 ${to}`,
|
|
5680
|
+
"en-US": `Hand this over to ${to}`,
|
|
5681
|
+
"ja-JP": `これを ${to} に引き継ぐ`
|
|
5654
5682
|
});
|
|
5655
|
-
|
|
5656
|
-
const timer = setInterval(watch, WATCH_MS);
|
|
5657
|
-
document.addEventListener("visibilitychange", watch);
|
|
5658
|
-
return () => {
|
|
5659
|
-
clearInterval(timer);
|
|
5660
|
-
document.removeEventListener("visibilitychange", watch);
|
|
5661
|
-
};
|
|
5662
|
-
}, [service, channelId]);
|
|
5663
|
-
const sent = React.useMemo(() => messages?.filter((message) => message.author === USER).length ?? 0, [messages]);
|
|
5664
|
-
const list = pi.ui.useChatScroll(sent, channelId);
|
|
5665
|
-
const [notice, setNotice] = React.useState({ open: false, editing: false });
|
|
5666
|
-
React.useEffect(() => setNotice({ open: false, editing: false }), [channelId]);
|
|
5667
|
-
const Markdown = pi.ui.Markdown;
|
|
5668
|
-
const Composer = pi.ui.Composer;
|
|
5669
|
-
const Avatar = pi.ui.Avatar;
|
|
5670
|
-
if (!channel) {
|
|
5671
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
5672
|
-
className: "tac-room-page"
|
|
5673
|
-
}, state.loaded && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
5674
|
-
title: w.pick
|
|
5675
|
-
}));
|
|
5683
|
+
return TaMessageContext.wrap(context, line);
|
|
5676
5684
|
}
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
}
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
later: messages.some((other) => other.at > message.at && (other.author === USER || other.author === TA))
|
|
5715
|
-
}) : message.notice ? /* @__PURE__ */ React.createElement("button", {
|
|
5716
|
-
type: "button",
|
|
5717
|
-
className: "tac-notice tac-notice-line",
|
|
5718
|
-
disabled: !channel.notice,
|
|
5719
|
-
onClick: () => setNotice({ open: true, editing: false })
|
|
5720
|
-
}, ChannelWords.format(message.notice === "cleared" ? w.noticeCleared : w.noticeUpdated, { name: name(message.author) })) : message.author === USER && (message.by ?? TA_OWNER) !== me ? /* @__PURE__ */ React.createElement("div", {
|
|
5721
|
-
className: `tac-msg${first ? " tac-first" : ""}`
|
|
5722
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
5723
|
-
className: "tac-msg-face"
|
|
5724
|
-
}, first && pi.ui.Face && /* @__PURE__ */ React.createElement(pi.ui.Face, {
|
|
5725
|
-
seed: message.by ?? TA_OWNER,
|
|
5726
|
-
double: (message.by ?? TA_OWNER) === TA_OWNER,
|
|
5727
|
-
size: 28
|
|
5728
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
5729
|
-
className: "tac-msg-col"
|
|
5730
|
-
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
5731
|
-
className: "tac-msg-name"
|
|
5732
|
-
}, message.byName ?? w.owner), /* @__PURE__ */ React.createElement(MessagePictures, {
|
|
5733
|
-
context,
|
|
5734
|
-
channelId: channel.id,
|
|
5735
|
-
message,
|
|
5736
|
-
alt: message.byName ?? w.owner
|
|
5737
|
-
}), message.text && /* @__PURE__ */ React.createElement("div", {
|
|
5738
|
-
className: "tac-msg-bubble",
|
|
5739
|
-
title: time(message.at)
|
|
5740
|
-
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
5741
|
-
text: message.text,
|
|
5742
|
-
agents: state.team.agents
|
|
5743
|
-
})))) : message.author === USER ? /* @__PURE__ */ React.createElement("div", {
|
|
5744
|
-
className: "ta-message ta-user tac-mine"
|
|
5745
|
-
}, /* @__PURE__ */ React.createElement(MessagePictures, {
|
|
5746
|
-
context,
|
|
5747
|
-
channelId: channel.id,
|
|
5748
|
-
message,
|
|
5749
|
-
alt: w.you
|
|
5750
|
-
}), message.text && /* @__PURE__ */ React.createElement("div", {
|
|
5751
|
-
className: "ta-bubble"
|
|
5752
|
-
}, /* @__PURE__ */ React.createElement(Mentions, {
|
|
5753
|
-
text: message.text,
|
|
5754
|
-
agents: state.team.agents
|
|
5755
|
-
}))) : /* @__PURE__ */ React.createElement("div", {
|
|
5756
|
-
className: `tac-msg${first ? " tac-first" : ""}`
|
|
5757
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
5758
|
-
className: "tac-msg-face"
|
|
5759
|
-
}, first && (message.author === TA ? /* @__PURE__ */ React.createElement(Avatar, {
|
|
5760
|
-
size: 28
|
|
5761
|
-
}) : /* @__PURE__ */ React.createElement(AgentAvatar, {
|
|
5762
|
-
agent: agentOf(message.author),
|
|
5763
|
-
faces,
|
|
5764
|
-
size: 28,
|
|
5765
|
-
working: working.includes(message.author)
|
|
5766
|
-
}))), /* @__PURE__ */ React.createElement("div", {
|
|
5767
|
-
className: "tac-msg-col"
|
|
5768
|
-
}, first && /* @__PURE__ */ React.createElement("div", {
|
|
5769
|
-
className: "tac-msg-name"
|
|
5770
|
-
}, name(message.author), message.author === channel.members[0] && /* @__PURE__ */ React.createElement("span", {
|
|
5771
|
-
className: "tac-msg-lead"
|
|
5772
|
-
}, w.lead)), /* @__PURE__ */ React.createElement("div", {
|
|
5773
|
-
className: `tac-msg-bubble${message.failed ? " tac-failed" : ""}`,
|
|
5774
|
-
title: time(message.at)
|
|
5775
|
-
}, message.failed && /* @__PURE__ */ React.createElement("div", {
|
|
5776
|
-
className: "tac-msg-failed"
|
|
5777
|
-
}, w.failed), message.overBudget && /* @__PURE__ */ React.createElement("div", {
|
|
5778
|
-
className: "tac-msg-over"
|
|
5779
|
-
}, w.overBudget), agentOf(message.author) ? /* @__PURE__ */ React.createElement(AgentText, {
|
|
5780
|
-
context,
|
|
5781
|
-
channelId: channel.id,
|
|
5782
|
-
agent: agentOf(message.author),
|
|
5783
|
-
text: ChannelsText.markMentions(message.text, state.team.agents),
|
|
5784
|
-
answer: RoomUtil.answer(messages, message, agentOf(message.author))
|
|
5785
|
-
}) : /* @__PURE__ */ React.createElement(Markdown, {
|
|
5786
|
-
text: ChannelsText.markMentions(message.text, state.team.agents)
|
|
5787
|
-
})))))), working.length > 0 && /* @__PURE__ */ React.createElement("div", {
|
|
5788
|
-
className: "tac-live",
|
|
5789
|
-
role: "status"
|
|
5790
|
-
}, /* @__PURE__ */ React.createElement("span", {
|
|
5791
|
-
className: "tac-live-faces"
|
|
5792
|
-
}, working.map((id) => /* @__PURE__ */ React.createElement(Face, {
|
|
5793
|
-
key: id,
|
|
5794
|
-
face: faces.get(id) ?? 0,
|
|
5795
|
-
size: 18,
|
|
5796
|
-
working: true
|
|
5797
|
-
}))), ChannelWords.format(w.answeringNow, { name: working.map(name).join("、") })))), /* @__PURE__ */ React.createElement("div", {
|
|
5798
|
-
className: "tac-chat-bottom"
|
|
5799
|
-
}, /* @__PURE__ */ React.createElement(Composer, {
|
|
5800
|
-
placeholder: ChannelWords.format(placeholder, { channel: channel.name, lead: lead?.name ?? "" }),
|
|
5801
|
-
draft: channel.id,
|
|
5802
|
-
mentions: members.map((agent) => ({ name: agent.name, detail: agent.role.split(`
|
|
5803
|
-
`)[0] })),
|
|
5804
|
-
mentionLabel: w.mentionMember,
|
|
5805
|
-
actions: [
|
|
5806
|
-
[
|
|
5807
|
-
{
|
|
5808
|
-
key: "notice",
|
|
5809
|
-
label: w.noticeEdit,
|
|
5810
|
-
icon: ChannelViews.maybeIcon(pi, "Megaphone", null, 16),
|
|
5811
|
-
run: () => setNotice({ open: true, editing: true })
|
|
5812
|
-
},
|
|
5813
|
-
{
|
|
5814
|
-
key: "add",
|
|
5815
|
-
label: w.addMembers,
|
|
5816
|
-
icon: ChannelViews.maybeIcon(pi, "UserPlus", null, 16),
|
|
5817
|
-
run: () => {
|
|
5818
|
-
if (fixed) {
|
|
5819
|
-
ui.set({ channelId: fixed });
|
|
5820
|
-
}
|
|
5821
|
-
context.showMembers(true);
|
|
5822
|
-
}
|
|
5823
|
-
}
|
|
5824
|
-
],
|
|
5825
|
-
[
|
|
5826
|
-
{
|
|
5827
|
-
key: "make-extension",
|
|
5828
|
-
label: w.makeExtension,
|
|
5829
|
-
detail: w.makeExtensionDetail,
|
|
5830
|
-
icon: ChannelViews.maybeIcon(pi, "Sparkles", null, 16),
|
|
5831
|
-
run: () => void service.post(channel.id, w.makeExtensionAsk).catch((error) => pi.ui.notify(ChannelViews.message(error), "error"))
|
|
5832
|
-
}
|
|
5833
|
-
]
|
|
5834
|
-
],
|
|
5835
|
-
images: { side: 1600, bytes: 1024 * 1024 },
|
|
5836
|
-
onSend: (text, images) => service.post(channel.id, text, images ?? [])
|
|
5837
|
-
})));
|
|
5838
|
-
}
|
|
5685
|
+
HandOff.ask = ask;
|
|
5686
|
+
function asked(text) {
|
|
5687
|
+
return MARK.exec(text)?.[1];
|
|
5688
|
+
}
|
|
5689
|
+
HandOff.asked = asked;
|
|
5690
|
+
function find(text) {
|
|
5691
|
+
const lines = text.split(/\r?\n/);
|
|
5692
|
+
let found;
|
|
5693
|
+
for (let index = 0;index < lines.length; index++) {
|
|
5694
|
+
const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
|
|
5695
|
+
if (open?.[2] !== HandOff.BLOCK) {
|
|
5696
|
+
continue;
|
|
5697
|
+
}
|
|
5698
|
+
const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
|
|
5699
|
+
const end = lines.findIndex((line, at) => at > index && close.test(line));
|
|
5700
|
+
found = lines.slice(index + 1, end < 0 ? lines.length : end);
|
|
5701
|
+
index = end < 0 ? lines.length : end;
|
|
5702
|
+
}
|
|
5703
|
+
const brief = found?.join(`
|
|
5704
|
+
`).trim();
|
|
5705
|
+
return brief || undefined;
|
|
5706
|
+
}
|
|
5707
|
+
HandOff.find = find;
|
|
5708
|
+
function message(origin, brief, language) {
|
|
5709
|
+
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
5710
|
+
const head = TaLanguageUtil.pick(language, {
|
|
5711
|
+
"zh-CN": `(交接自“${title}”)`,
|
|
5712
|
+
"zh-TW": `(交接自「${title}」)`,
|
|
5713
|
+
"en-US": `(Handed over from “${title}”)`,
|
|
5714
|
+
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
5715
|
+
});
|
|
5716
|
+
const context = [
|
|
5717
|
+
"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.",
|
|
5718
|
+
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.` : ""
|
|
5719
|
+
].filter(Boolean).join(`
|
|
5720
|
+
`);
|
|
5721
|
+
return TaMessageContext.wrap(context, `${head}
|
|
5839
5722
|
|
|
5840
|
-
|
|
5841
|
-
|
|
5723
|
+
${brief.trim()}`);
|
|
5724
|
+
}
|
|
5725
|
+
HandOff.message = message;
|
|
5726
|
+
function channelText(origin, brief, language) {
|
|
5727
|
+
const title = origin.title?.trim() || TaLanguageUtil.pick(language, { "zh-CN": "一个对话", "zh-TW": "一個對話", "en-US": "a conversation", "ja-JP": "ある会話" });
|
|
5728
|
+
return `${TaLanguageUtil.pick(language, {
|
|
5729
|
+
"zh-CN": `(交接自“${title}”)`,
|
|
5730
|
+
"zh-TW": `(交接自「${title}」)`,
|
|
5731
|
+
"en-US": `(Handed over from “${title}”)`,
|
|
5732
|
+
"ja-JP": `(“${title}” から引き継ぎました)`
|
|
5733
|
+
})}
|
|
5842
5734
|
|
|
5843
|
-
|
|
5844
|
-
context;
|
|
5845
|
-
shown = new Map;
|
|
5846
|
-
list = [];
|
|
5847
|
-
listeners = new Set;
|
|
5848
|
-
reading = new Set;
|
|
5849
|
-
stop;
|
|
5850
|
-
constructor(context) {
|
|
5851
|
-
this.context = context;
|
|
5735
|
+
${brief.trim()}`;
|
|
5852
5736
|
}
|
|
5853
|
-
|
|
5854
|
-
|
|
5737
|
+
HandOff.channelText = channelText;
|
|
5738
|
+
function serverLanguage(env = typeof process === "undefined" ? {} : process.env) {
|
|
5739
|
+
return TaLanguageUtil.of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "");
|
|
5855
5740
|
}
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5741
|
+
HandOff.serverLanguage = serverLanguage;
|
|
5742
|
+
function result(target) {
|
|
5743
|
+
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.`;
|
|
5744
|
+
}
|
|
5745
|
+
HandOff.result = result;
|
|
5746
|
+
})(HandOff ||= {});
|
|
5747
|
+
|
|
5748
|
+
// web-src/handoff-view.tsx
|
|
5749
|
+
var HandOffViewUtil;
|
|
5750
|
+
((HandOffViewUtil) => {
|
|
5751
|
+
function members(team, target) {
|
|
5752
|
+
if (target.kind === "agent") {
|
|
5753
|
+
const agent = team.agents.find((candidate) => candidate.id === target.id);
|
|
5754
|
+
return agent ? [agent] : [];
|
|
5860
5755
|
}
|
|
5861
|
-
|
|
5862
|
-
return ()
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5756
|
+
const channel = team.channels.find((candidate) => candidate.id === target.id);
|
|
5757
|
+
return channel ? membersOf(team, channel) : [];
|
|
5758
|
+
}
|
|
5759
|
+
HandOffViewUtil.members = members;
|
|
5760
|
+
})(HandOffViewUtil ||= {});
|
|
5761
|
+
function useTeam(context) {
|
|
5762
|
+
return React.useSyncExternalStore((listener) => context.service.subscribe(listener), () => context.service.state).team;
|
|
5763
|
+
}
|
|
5764
|
+
function HandOffCard({ context, message }) {
|
|
5765
|
+
const card = message.details;
|
|
5766
|
+
const team = useTeam(context);
|
|
5767
|
+
const faces = useFaces(team);
|
|
5768
|
+
if (!card?.target) {
|
|
5769
|
+
return null;
|
|
5770
|
+
}
|
|
5771
|
+
const w = ChannelViews.words(context.pi);
|
|
5772
|
+
const members = HandOffViewUtil.members(team, card.target);
|
|
5773
|
+
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);
|
|
5774
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
5775
|
+
className: "tac-handoff"
|
|
5776
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
5777
|
+
className: "tac-handoff-head"
|
|
5778
|
+
}, members.length > 0 && /* @__PURE__ */ React.createElement(RoomFace, {
|
|
5779
|
+
members,
|
|
5780
|
+
faces,
|
|
5781
|
+
size: 20,
|
|
5782
|
+
working: []
|
|
5783
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
5784
|
+
className: "tac-handoff-title"
|
|
5785
|
+
}, w.handedTo.replace("{to}", HandOff.ref(card.target))), members.length > 0 && /* @__PURE__ */ React.createElement("button", {
|
|
5786
|
+
type: "button",
|
|
5787
|
+
className: "tac-link",
|
|
5788
|
+
onClick: open
|
|
5789
|
+
}, w.handOffOpen)), /* @__PURE__ */ React.createElement("div", {
|
|
5790
|
+
className: "tac-handoff-brief"
|
|
5791
|
+
}, card.brief));
|
|
5792
|
+
}
|
|
5793
|
+
var HandOffView;
|
|
5794
|
+
((HandOffView) => {
|
|
5795
|
+
function card(context) {
|
|
5796
|
+
return ({ message }) => /* @__PURE__ */ React.createElement(HandOffCard, {
|
|
5797
|
+
context,
|
|
5798
|
+
message
|
|
5799
|
+
});
|
|
5800
|
+
}
|
|
5801
|
+
HandOffView.card = card;
|
|
5802
|
+
function icon(context, target, icons) {
|
|
5803
|
+
const key = `${target.kind}:${target.id}`;
|
|
5804
|
+
let node2 = icons.get(key);
|
|
5805
|
+
if (!node2) {
|
|
5806
|
+
const Face2 = () => {
|
|
5807
|
+
const team = useTeam(context);
|
|
5808
|
+
const faces = useFaces(team);
|
|
5809
|
+
const members = HandOffViewUtil.members(team, target);
|
|
5810
|
+
return members.length ? /* @__PURE__ */ React.createElement(RoomFace, {
|
|
5811
|
+
members,
|
|
5812
|
+
faces,
|
|
5813
|
+
size: 16,
|
|
5814
|
+
working: []
|
|
5815
|
+
}) : null;
|
|
5816
|
+
};
|
|
5817
|
+
node2 = /* @__PURE__ */ React.createElement(Face2, null);
|
|
5818
|
+
icons.set(key, node2);
|
|
5819
|
+
}
|
|
5820
|
+
return node2;
|
|
5821
|
+
}
|
|
5822
|
+
function composerAddon(context) {
|
|
5823
|
+
const icons = new Map;
|
|
5824
|
+
const send = (conversation, to) => void context.pi.server.prompt(conversation.sessionId, {
|
|
5825
|
+
clientMessageId: ChannelsUtil.newId("handoff-ask"),
|
|
5826
|
+
message: HandOff.ask(context.pi.ui.language, to),
|
|
5827
|
+
streamingBehavior: "followUp"
|
|
5828
|
+
}).catch((error) => context.pi.ui.notify(ChannelViews.message(error), "error"));
|
|
5829
|
+
return {
|
|
5830
|
+
actions: (conversation) => {
|
|
5831
|
+
const { team } = context.service.state;
|
|
5832
|
+
if (conversation.group === NAME || team.agents.length === 0 && team.channels.length === 0) {
|
|
5833
|
+
return [];
|
|
5834
|
+
}
|
|
5835
|
+
const w = ChannelViews.words(context.pi);
|
|
5836
|
+
const Forward = ChannelViews.icon(context.pi, "Forward");
|
|
5837
|
+
const agents = ChannelsUtil.standing(team).map((agent) => ({
|
|
5838
|
+
key: `handoff:agent:${agent.id}`,
|
|
5839
|
+
label: agent.name,
|
|
5840
|
+
detail: agent.role.split(`
|
|
5841
|
+
`)[0],
|
|
5842
|
+
group: w.agents,
|
|
5843
|
+
icon: icon(context, { kind: "agent", id: agent.id }, icons),
|
|
5844
|
+
run: () => send(conversation, `@${agent.name}`)
|
|
5845
|
+
}));
|
|
5846
|
+
const channels = team.channels.map((channel) => ({
|
|
5847
|
+
key: `handoff:channel:${channel.id}`,
|
|
5848
|
+
label: `#${channel.name}`,
|
|
5849
|
+
detail: channel.topic,
|
|
5850
|
+
group: w.channels,
|
|
5851
|
+
icon: icon(context, { kind: "channel", id: channel.id }, icons),
|
|
5852
|
+
run: () => send(conversation, `#${channel.name}`)
|
|
5853
|
+
}));
|
|
5854
|
+
return [{ key: "handoff", label: w.handOff, detail: w.handOffDetail, icon: /* @__PURE__ */ React.createElement(Forward, {
|
|
5855
|
+
size: 16
|
|
5856
|
+
}), items: [...agents, ...channels] }];
|
|
5857
|
+
},
|
|
5858
|
+
subscribe: (listener) => context.service.subscribe(listener)
|
|
5868
5859
|
};
|
|
5869
5860
|
}
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5861
|
+
HandOffView.composerAddon = composerAddon;
|
|
5862
|
+
})(HandOffView ||= {});
|
|
5863
|
+
|
|
5864
|
+
// web-src/round-rules.ts
|
|
5865
|
+
var ChannelRounds;
|
|
5866
|
+
((ChannelRounds) => {
|
|
5867
|
+
const SHORT = 20;
|
|
5868
|
+
const MIN_PAIRS = 8;
|
|
5869
|
+
const ALIKE = 0.8;
|
|
5870
|
+
const PING_PONG = 4;
|
|
5871
|
+
const NEW = 0.35;
|
|
5872
|
+
const CHANGES = new Set(["edit", "write", "delete", "move"]);
|
|
5873
|
+
function scale(watchedAt, pages, now) {
|
|
5874
|
+
if (watchedAt !== undefined && now - watchedAt < 2 * WATCH_MS) {
|
|
5875
|
+
return 2;
|
|
5876
|
+
}
|
|
5877
|
+
return pages === undefined || pages > 0 ? 1 : 0.5;
|
|
5873
5878
|
}
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
const
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
const
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5879
|
+
ChannelRounds.scale = scale;
|
|
5880
|
+
function idle(said, progress) {
|
|
5881
|
+
const last = said.at(-1);
|
|
5882
|
+
if (!last) {
|
|
5883
|
+
return;
|
|
5884
|
+
}
|
|
5885
|
+
const pairs = said.map((item) => pairsOf(item.text));
|
|
5886
|
+
const mine = pairs[pairs.length - 1];
|
|
5887
|
+
if (mine.length >= MIN_PAIRS && pairs.slice(0, -1).some((other) => alike(other, mine) >= ALIKE)) {
|
|
5888
|
+
return "repeat";
|
|
5889
|
+
}
|
|
5890
|
+
const recent = said.slice(-3);
|
|
5891
|
+
if (recent.length === 3 && recent.every((item) => units(item.text).join("").length < SHORT)) {
|
|
5892
|
+
return "agree";
|
|
5893
|
+
}
|
|
5894
|
+
const run = said.slice(-PING_PONG);
|
|
5895
|
+
const authors = new Set(run.map((item) => item.author));
|
|
5896
|
+
const alternate = run.every((item, i) => i === 0 || item.author !== run[i - 1].author);
|
|
5897
|
+
const start = said.length - PING_PONG;
|
|
5898
|
+
if (progress || start <= 0 || authors.size !== 2 || !alternate) {
|
|
5899
|
+
return;
|
|
5900
|
+
}
|
|
5901
|
+
const seen = new Set(pairs.slice(0, start).flat());
|
|
5902
|
+
for (const own of pairs.slice(start)) {
|
|
5903
|
+
const fresh = own.filter((pair) => !seen.has(pair)).length;
|
|
5904
|
+
if (own.length === 0 || fresh / own.length >= NEW) {
|
|
5905
|
+
return;
|
|
5884
5906
|
}
|
|
5885
|
-
const
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5907
|
+
for (const pair of own) {
|
|
5908
|
+
seen.add(pair);
|
|
5909
|
+
}
|
|
5910
|
+
}
|
|
5911
|
+
return "pingPong";
|
|
5912
|
+
}
|
|
5913
|
+
ChannelRounds.idle = idle;
|
|
5914
|
+
function day(now) {
|
|
5915
|
+
const date = new Date(now);
|
|
5916
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
5917
|
+
}
|
|
5918
|
+
ChannelRounds.day = day;
|
|
5919
|
+
function limits(stored) {
|
|
5920
|
+
const given = stored ?? {};
|
|
5921
|
+
const pick = (key) => LIMIT_CHOICES[key].includes(given[key]) ? given[key] : DEFAULT_LIMITS[key];
|
|
5922
|
+
return { answer: pick("answer"), channelDay: pick("channelDay"), allDay: pick("allDay") };
|
|
5923
|
+
}
|
|
5924
|
+
ChannelRounds.limits = limits;
|
|
5925
|
+
function today(stored, now) {
|
|
5926
|
+
const current = day(now);
|
|
5927
|
+
return stored?.day === current ? stored : { day: current, total: 0, channels: {} };
|
|
5928
|
+
}
|
|
5929
|
+
ChannelRounds.today = today;
|
|
5930
|
+
function spend(stored, channelId, tokens, now) {
|
|
5931
|
+
const current = today(stored, now);
|
|
5932
|
+
return { ...current, total: current.total + tokens, channels: { ...current.channels, [channelId]: (current.channels[channelId] ?? 0) + tokens } };
|
|
5933
|
+
}
|
|
5934
|
+
ChannelRounds.spend = spend;
|
|
5935
|
+
function held(spent, limits2, channelId, hops, granted = false) {
|
|
5936
|
+
if (granted) {
|
|
5905
5937
|
return;
|
|
5906
5938
|
}
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5939
|
+
if (limits2.allDay > 0 && spent.total >= limits2.allDay) {
|
|
5940
|
+
return "all";
|
|
5941
|
+
}
|
|
5942
|
+
if (hops > 0 && limits2.channelDay > 0 && (spent.channels[channelId] ?? 0) >= limits2.channelDay) {
|
|
5943
|
+
return "channel";
|
|
5910
5944
|
}
|
|
5945
|
+
return;
|
|
5911
5946
|
}
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5947
|
+
ChannelRounds.held = held;
|
|
5948
|
+
function changedFiles(entries) {
|
|
5949
|
+
for (const entry of entries) {
|
|
5950
|
+
const message = entry?.message;
|
|
5951
|
+
if (entry?.type !== "message" || message?.role !== "assistant" || !Array.isArray(message.content)) {
|
|
5952
|
+
continue;
|
|
5953
|
+
}
|
|
5954
|
+
for (const part of message.content) {
|
|
5955
|
+
if (part?.type !== "toolCall") {
|
|
5956
|
+
continue;
|
|
5957
|
+
}
|
|
5958
|
+
if (CHANGES.has(String(part.name)) || part.name === "agent_tool" && CHANGES.has(String(part.arguments?.kind))) {
|
|
5959
|
+
return true;
|
|
5960
|
+
}
|
|
5961
|
+
}
|
|
5916
5962
|
}
|
|
5963
|
+
return false;
|
|
5917
5964
|
}
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5965
|
+
ChannelRounds.changedFiles = changedFiles;
|
|
5966
|
+
function units(text) {
|
|
5967
|
+
return text.replace(/@[^\s@#,,。::]+/g, " ").toLowerCase().match(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]|[\p{L}\p{N}]+/gu) ?? [];
|
|
5968
|
+
}
|
|
5969
|
+
function pairsOf(text) {
|
|
5970
|
+
const words = units(text);
|
|
5971
|
+
return words.length === 1 ? words : words.slice(1).map((word, i) => `${words[i]} ${word}`);
|
|
5972
|
+
}
|
|
5973
|
+
function alike(a, b) {
|
|
5974
|
+
if (a.length === 0 || b.length === 0) {
|
|
5975
|
+
return 0;
|
|
5923
5976
|
}
|
|
5924
|
-
const
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
return building ? { status: "running", detail: w.building } : { status: "done", detail: channel.topic || w.noMessages, endedAt: channel.createdAt };
|
|
5977
|
+
const left = new Map;
|
|
5978
|
+
for (const pair of a) {
|
|
5979
|
+
left.set(pair, (left.get(pair) ?? 0) + 1);
|
|
5928
5980
|
}
|
|
5929
|
-
|
|
5930
|
-
|
|
5981
|
+
let common = 0;
|
|
5982
|
+
for (const pair of b) {
|
|
5983
|
+
const n = left.get(pair) ?? 0;
|
|
5984
|
+
if (n > 0) {
|
|
5985
|
+
left.set(pair, n - 1);
|
|
5986
|
+
common++;
|
|
5987
|
+
}
|
|
5931
5988
|
}
|
|
5932
|
-
|
|
5933
|
-
return { status: last.failed ? "failed" : "done", detail: said, endedAt: last.at };
|
|
5934
|
-
}
|
|
5935
|
-
entry(channel, members, faces, working, status, detail, endedAt) {
|
|
5936
|
-
return {
|
|
5937
|
-
id: channel.id,
|
|
5938
|
-
title: taskTitle(channel),
|
|
5939
|
-
status,
|
|
5940
|
-
detail,
|
|
5941
|
-
startedAt: channel.createdAt,
|
|
5942
|
-
endedAt: status === "running" || status === "waiting" ? undefined : endedAt,
|
|
5943
|
-
origin: channel.origin,
|
|
5944
|
-
icon: ({ size }) => /* @__PURE__ */ React.createElement(RoomFace, {
|
|
5945
|
-
members,
|
|
5946
|
-
faces,
|
|
5947
|
-
size,
|
|
5948
|
-
working
|
|
5949
|
-
}),
|
|
5950
|
-
open: () => openScene(this.context, channel),
|
|
5951
|
-
show: () => this.context.showChannel(channel.id),
|
|
5952
|
-
menu: () => taskMenu(this.context, channel, working),
|
|
5953
|
-
remove: () => deleteTeam(this.context, channel),
|
|
5954
|
-
removeHint: ChannelWords.format(ChannelViews.words(this.context.pi).deleteTaskHint, { channel: channel.name })
|
|
5955
|
-
};
|
|
5989
|
+
return 2 * common / (a.length + b.length);
|
|
5956
5990
|
}
|
|
5991
|
+
})(ChannelRounds ||= {});
|
|
5992
|
+
|
|
5993
|
+
// web-src/limit-settings.tsx
|
|
5994
|
+
function amount(pi, tokens) {
|
|
5995
|
+
return tokens > 0 ? new Intl.NumberFormat(pi.ui.language, { notation: "compact", maximumFractionDigits: 1 }).format(tokens) : ChannelWords.of(pi.ui.language).noLimit;
|
|
5957
5996
|
}
|
|
5958
|
-
function
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
channelId: channel.id
|
|
5978
|
-
}))
|
|
5979
|
-
});
|
|
5997
|
+
function useLimits(pi) {
|
|
5998
|
+
const read = React.useCallback(async () => ({
|
|
5999
|
+
limits: ChannelRounds.limits(await pi.storage.get(Keys.LIMITS)),
|
|
6000
|
+
...((today) => ({ spent: today.total, channels: today.channels }))(ChannelRounds.today(await pi.storage.get(Keys.SPENT), Date.now()))
|
|
6001
|
+
}), [pi]);
|
|
6002
|
+
const [value, setValue] = React.useState({ limits: ChannelRounds.limits(undefined), spent: 0, channels: {} });
|
|
6003
|
+
React.useEffect(() => {
|
|
6004
|
+
let live = true;
|
|
6005
|
+
const load = () => void read().then((next) => live && setValue(next), () => {
|
|
6006
|
+
return;
|
|
6007
|
+
});
|
|
6008
|
+
load();
|
|
6009
|
+
const stop = pi.storage.onChange((keys) => (keys.includes(Keys.LIMITS) || keys.includes(Keys.SPENT)) && load());
|
|
6010
|
+
return () => {
|
|
6011
|
+
live = false;
|
|
6012
|
+
stop();
|
|
6013
|
+
};
|
|
6014
|
+
}, [pi, read]);
|
|
6015
|
+
return value;
|
|
5980
6016
|
}
|
|
5981
|
-
function
|
|
5982
|
-
const
|
|
5983
|
-
const
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
6017
|
+
function limitSettings(pi, service) {
|
|
6018
|
+
const words = () => ChannelWords.of(pi.ui.language);
|
|
6019
|
+
const row = (key) => function Choices() {
|
|
6020
|
+
const { limits } = useLimits(pi);
|
|
6021
|
+
const pick = (value) => void service.setLimits({ [key]: value }).catch((error) => pi.ui.notify(String(error?.message ?? error), "error"));
|
|
6022
|
+
return /* @__PURE__ */ React.createElement("fieldset", {
|
|
6023
|
+
className: "ta-segmented",
|
|
6024
|
+
"aria-label": words()[key === "answer" ? "limitAnswer" : key === "channelDay" ? "limitChannelDay" : "limitAllDay"]
|
|
6025
|
+
}, LIMIT_CHOICES[key].map((value) => /* @__PURE__ */ React.createElement("button", {
|
|
6026
|
+
key: value,
|
|
6027
|
+
type: "button",
|
|
6028
|
+
"aria-pressed": limits[key] === value,
|
|
6029
|
+
className: limits[key] === value ? "ta-on" : "",
|
|
6030
|
+
onClick: () => pick(value)
|
|
6031
|
+
}, amount(pi, value))));
|
|
5987
6032
|
};
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
}
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
{ key: "
|
|
6003
|
-
...temporary.length > 0 ? [
|
|
6004
|
-
{
|
|
6005
|
-
key: "keep",
|
|
6006
|
-
label: w.keepMembers,
|
|
6007
|
-
icon: icon("UserPlus"),
|
|
6008
|
-
run: act(async () => {
|
|
6009
|
-
await TeamActions.keep(context, temporary);
|
|
6010
|
-
pi.ui.notify(ChannelWords.format(w.keptMembers, { names: temporary.map((agent) => `@${agent.name}`).join("、") }), "info");
|
|
6011
|
-
})
|
|
6012
|
-
}
|
|
6013
|
-
] : []
|
|
6014
|
-
],
|
|
6015
|
-
[
|
|
6016
|
-
{
|
|
6017
|
-
key: "delete",
|
|
6018
|
-
label: w.deleteTask,
|
|
6019
|
-
icon: icon("Trash2"),
|
|
6020
|
-
danger: true,
|
|
6021
|
-
run: act(() => pi.ui.removeTasks([
|
|
6022
|
-
{
|
|
6023
|
-
title: taskTitle(channel),
|
|
6024
|
-
removeHint: ChannelWords.format(w.deleteTaskHint, { channel: channel.name }),
|
|
6025
|
-
remove: () => deleteTeam(context, channel)
|
|
6026
|
-
}
|
|
6027
|
-
]))
|
|
6028
|
-
}
|
|
6033
|
+
function Spent() {
|
|
6034
|
+
const { spent } = useLimits(pi);
|
|
6035
|
+
return /* @__PURE__ */ React.createElement("span", {
|
|
6036
|
+
className: "tac-limit-spent"
|
|
6037
|
+
}, spent > 0 ? amount(pi, spent) : "0");
|
|
6038
|
+
}
|
|
6039
|
+
return {
|
|
6040
|
+
title: () => words().limitsTitle,
|
|
6041
|
+
icon: pi.ui.icons.Coins ?? pi.ui.icons.Gauge,
|
|
6042
|
+
group: "ta",
|
|
6043
|
+
rows: [
|
|
6044
|
+
{ key: "answer", label: () => words().limitAnswer, description: () => words().limitAnswerHint, render: row("answer") },
|
|
6045
|
+
{ key: "channelDay", label: () => words().limitChannelDay, description: () => words().limitChannelDayHint, render: row("channelDay") },
|
|
6046
|
+
{ key: "allDay", label: () => words().limitAllDay, description: () => words().limitAllDayHint, render: row("allDay") },
|
|
6047
|
+
{ key: "spent", label: () => words().limitSpent, render: Spent }
|
|
6029
6048
|
]
|
|
6030
|
-
|
|
6049
|
+
};
|
|
6031
6050
|
}
|
|
6032
|
-
var TeamActions;
|
|
6033
|
-
((TeamActions) => {
|
|
6034
|
-
async function stop(context, agentIds) {
|
|
6035
|
-
const { pi, service } = context;
|
|
6036
|
-
const files = new Set(service.state.team.agents.filter((agent) => agentIds.includes(agent.id) && agent.sessionFile).map((agent) => agent.sessionFile));
|
|
6037
|
-
const sessions = (await pi.server.listSessions()).filter((session) => session.sessionFile && files.has(session.sessionFile));
|
|
6038
|
-
await Promise.all(sessions.map((session) => pi.server.abort(session.sessionId)));
|
|
6039
|
-
}
|
|
6040
|
-
TeamActions.stop = stop;
|
|
6041
|
-
async function keep(context, agents) {
|
|
6042
|
-
for (const agent of agents) {
|
|
6043
|
-
await context.service.updateAgent(agent.id, { keep: true });
|
|
6044
|
-
}
|
|
6045
|
-
}
|
|
6046
|
-
TeamActions.keep = keep;
|
|
6047
|
-
})(TeamActions ||= {});
|
|
6048
6051
|
|
|
6049
6052
|
// web-src/channel-menu.tsx
|
|
6050
6053
|
function download2(name, text) {
|