@celljs/ta-channels 4.21.0 → 4.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/host/index.mjs CHANGED
@@ -37,113 +37,6 @@ var TaLanguageUtil;
37
37
  TaLanguageUtil2.list = list;
38
38
  })(TaLanguageUtil || (TaLanguageUtil = {}));
39
39
 
40
- // ../ta-protocol/esm/common/team-protocol.js
41
- var TA_OWNER = "owner";
42
- var TA_UNDECLARED = "extensions.install";
43
- var TaPermissionUtil;
44
- (function(TaPermissionUtil2) {
45
- function read(pi) {
46
- const given = pi === null || pi === undefined ? undefined : pi.permissions;
47
- const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
48
- const host2 = map(given === null || given === undefined ? undefined : given.host);
49
- const tools = map(given === null || given === undefined ? undefined : given.tools);
50
- return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
51
- }
52
- TaPermissionUtil2.read = read;
53
- function host(manifest, method, kind) {
54
- var _a, _b, _c, _d;
55
- const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
56
- const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
57
- 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;
58
- }
59
- TaPermissionUtil2.host = host;
60
- })(TaPermissionUtil || (TaPermissionUtil = {}));
61
- var action = (id, en, zh, tw, ja, more = {}) => ({
62
- id,
63
- area: id.split(".")[0],
64
- title: { en, "zh-CN": zh, ...tw ? { "zh-TW": tw } : {}, ...ja ? { "ja-JP": ja } : {} },
65
- ...more
66
- });
67
- var TA_ACTIONS = [
68
- action("chat.view", "See conversations", "查看对话", "檢視對話", "会話を確認"),
69
- action("chat.send", "Send in conversations", "在对话里发消息", "在對話裡發訊息", "会話にメッセージを送信"),
70
- action("chat.create", "Start conversations", "新建对话", "新建對話", "新しい会話を開始"),
71
- action("chat.stop", "Stop a reply", "停止回复", "停止回覆", "返信を停止"),
72
- action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话", "改名、歸檔、關閉對話", "会話の名前変更、アーカイブ、クローズ"),
73
- action("chat.share", "Share by a link", "生成分享链接", "生成分享連結", "共有リンクで共有"),
74
- action("agent.view", "See agents", "查看智能体", "檢視智慧體", "エージェントを確認"),
75
- action("agent.use", "Talk with agents", "和智能体对话", "和智慧體對話", "エージェントと対話"),
76
- action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体", "新建、修改、刪除智慧體", "エージェントを作成・変更・削除"),
77
- action("channel.view", "See channels", "查看频道", "檢視頻道", "チャネルを確認"),
78
- action("channel.post", "Post in channels", "在频道里发言", "在頻道里發言", "チャネルに投稿"),
79
- action("channel.manage", "Create and change channels", "新建、管理频道", "新建、管理頻道", "チャネルを作成・管理"),
80
- action("task.view", "See tasks", "查看任务", "檢視任務", "タスクを確認"),
81
- action("task.create", "Hand out tasks", "派任务", "派任務", "タスクを割り当て"),
82
- action("task.manage", "Take over and stop tasks", "接管、停止任务", "接管、停止任務", "タスクを引き継ぎ・停止"),
83
- action("files.read", "Read files", "读文件", "讀檔案", "ファイルを読取", { scoped: true }),
84
- action("files.write", "Change files", "改文件", "改檔案", "ファイルを変更", { scoped: true }),
85
- action("commands.run", "Let Ta run commands", "让 Ta 运行命令", "讓 Ta 執行命令", "Ta にコマンド実行を許可", { scoped: true, risky: true }),
86
- action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
87
- action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
88
- action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
89
- action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更", { grant: "single" }),
90
- action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
91
- action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
92
- action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
93
- action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
94
- action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
95
- action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
96
- action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
97
- action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
98
- action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
99
- action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
100
- action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
101
- ];
102
- var TA_OWNER_ACTIONS = [
103
- action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
104
- action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
105
- ];
106
- var OWNER_AREAS = ["desktop"];
107
- var TaActionUtil;
108
- (function(TaActionUtil2) {
109
- const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
110
- const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
111
- function info(id) {
112
- return byId.get(id);
113
- }
114
- TaActionUtil2.info = info;
115
- function title(id, language) {
116
- var _a;
117
- var _b, _c;
118
- const title2 = (_a = titled.get(id)) === null || _a === undefined ? undefined : _a.title;
119
- if (!title2) {
120
- return id;
121
- }
122
- return TaLanguageUtil.pick(language, {
123
- "zh-CN": title2["zh-CN"],
124
- "zh-TW": (_b = title2["zh-TW"]) !== null && _b !== undefined ? _b : title2["zh-CN"],
125
- "en-US": title2.en,
126
- "ja-JP": (_c = title2["ja-JP"]) !== null && _c !== undefined ? _c : title2.en
127
- });
128
- }
129
- TaActionUtil2.title = title;
130
- function grantable(id) {
131
- const info2 = byId.get(id);
132
- return !!info2 && !OWNER_AREAS.includes(info2.area);
133
- }
134
- TaActionUtil2.grantable = grantable;
135
- function inRoles(id) {
136
- var _a;
137
- return grantable(id) && ((_a = byId.get(id)) === null || _a === undefined ? undefined : _a.grant) !== "single";
138
- }
139
- TaActionUtil2.inRoles = inRoles;
140
- function inside(dir, path) {
141
- const base = dir.replace(/\/+$/, "");
142
- return path === base || path.startsWith(`${base}/`) || base === "";
143
- }
144
- TaActionUtil2.inside = inside;
145
- })(TaActionUtil || (TaActionUtil = {}));
146
-
147
40
  // ../ta-protocol/esm/common/message-protocol.js
148
41
  var TaMessageContext;
149
42
  (function(TaMessageContext2) {
@@ -229,6 +122,11 @@ var TaImageNote;
229
122
  var TaImageSize;
230
123
  (function(TaImageSize2) {
231
124
  const JPEG_BYTES = 256 * 1024;
125
+ function type(bytes) {
126
+ const at = (offset, ...values) => values.every((value, index) => bytes[offset + index] === value);
127
+ return at(0, 255, 216, 255) ? "image/jpeg" : at(0, 137, 80, 78, 71) ? "image/png" : at(0, 71, 73, 70, 56) ? "image/gif" : at(0, 82, 73, 70, 70) && at(8, 87, 69, 66, 80) ? "image/webp" : undefined;
128
+ }
129
+ TaImageSize2.type = type;
232
130
  function of(base64) {
233
131
  var _a, _b, _c;
234
132
  let bytes;
@@ -816,6 +714,9 @@ var BUDGETS = {
816
714
  long: { tokens: 3000000, replies: 100 }
817
715
  };
818
716
  var DEFAULT_BUDGET = "normal";
717
+ var REPLIES = ["mentioned", "lead", "all"];
718
+ var DEFAULT_REPLY = "lead";
719
+ var PASS = "PASS";
819
720
  var WRAP_UP_AT = 0.7;
820
721
  var EXTEND_BY = 0.5;
821
722
  var WATCH_MS = 30000;
@@ -833,6 +734,16 @@ var CARD_DAYS = 30;
833
734
  // web-src/channels-util.ts
834
735
  var ChannelsUtil;
835
736
  ((ChannelsUtil) => {
737
+ function may(team) {
738
+ const given = team.may;
739
+ return {
740
+ create: !given || given.create,
741
+ agent: (id) => !given || given.agents.includes(id),
742
+ manage: (id) => !given || given.manage.includes(id),
743
+ edit: (id) => !given || given.edit.includes(id)
744
+ };
745
+ }
746
+ ChannelsUtil.may = may;
836
747
  function newRound() {
837
748
  return { total: 0, tokens: 0, stopped: false };
838
749
  }
@@ -1102,16 +1013,22 @@ var ChannelsUtil;
1102
1013
  delete channel.pinned;
1103
1014
  }
1104
1015
  }
1105
- if (input.budget !== undefined) {
1106
- if (typeof input.budget !== "string" || !(input.budget in BUDGETS)) {
1107
- throw new Error(`The budget of a channel is one of ${Object.keys(BUDGETS).join(", ")}.`);
1016
+ const choose = (key, choices, fallback, what) => {
1017
+ const value = input[key];
1018
+ if (value === undefined) {
1019
+ return;
1108
1020
  }
1109
- if (input.budget === DEFAULT_BUDGET) {
1110
- delete channel.budget;
1021
+ if (typeof value !== "string" || !choices.includes(value)) {
1022
+ throw new Error(`${what} is one of ${choices.join(", ")}.`);
1023
+ }
1024
+ if (value === fallback) {
1025
+ delete channel[key];
1111
1026
  } else {
1112
- channel.budget = input.budget;
1027
+ channel[key] = value;
1113
1028
  }
1114
- }
1029
+ };
1030
+ choose("budget", Object.keys(BUDGETS), DEFAULT_BUDGET, "The budget of a channel");
1031
+ choose("reply", REPLIES, DEFAULT_REPLY, "Who answers what names nobody in a channel");
1115
1032
  if (input.dailyLimit === null) {
1116
1033
  delete channel.dailyLimit;
1117
1034
  } else if (input.dailyLimit !== undefined) {
@@ -1120,6 +1037,12 @@ var ChannelsUtil;
1120
1037
  }
1121
1038
  channel.dailyLimit = input.dailyLimit;
1122
1039
  }
1040
+ if (input.shared !== undefined) {
1041
+ if (typeof input.shared !== "string" || !input.shared) {
1042
+ throw new Error("The group chat a channel became is the id of a room.");
1043
+ }
1044
+ channel.shared = input.shared;
1045
+ }
1123
1046
  return { team: { ...team, channels: team.channels.map((other) => other.id === channel.id ? channel : other) }, channel, before };
1124
1047
  }
1125
1048
  ChannelsUtil.updateChannel = updateChannel;
@@ -1132,6 +1055,10 @@ var ChannelsUtil;
1132
1055
  return team.channels.filter((channel) => channel.by === "ta");
1133
1056
  }
1134
1057
  ChannelsUtil.taskChannels = taskChannels;
1058
+ function liveChannels(team) {
1059
+ return ownChannels(team).filter((channel) => !channel.shared);
1060
+ }
1061
+ ChannelsUtil.liveChannels = liveChannels;
1135
1062
  function ownChannels(team) {
1136
1063
  return team.channels.filter((channel) => channel.by !== "ta");
1137
1064
  }
@@ -1601,18 +1528,38 @@ var ChannelsText;
1601
1528
  }
1602
1529
  ChannelsText.mentions = mentions;
1603
1530
  function targets(team, channel, message) {
1604
- const muted = channel.muted ?? [];
1605
- const members = channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
1531
+ const members = answering(team, channel);
1606
1532
  const named = mentions(message.text, members).filter((id) => id !== message.author);
1607
1533
  if (message.author === SYSTEM) {
1608
1534
  return [];
1609
1535
  }
1610
- if (named.length > 0 || message.author !== USER && message.author !== TA) {
1536
+ if (named.length > 0 || message.author !== TA && message.author !== USER || mentions(message.text, team.agents).length > 0) {
1611
1537
  return named;
1612
1538
  }
1613
- return members.length > 0 ? [members[0].id] : [];
1539
+ const reply = message.author === TA ? "lead" : replyOf(channel);
1540
+ if (reply === "all") {
1541
+ return members.map((agent) => agent.id);
1542
+ }
1543
+ return reply === "lead" && members.length > 0 ? [members[0].id] : [];
1614
1544
  }
1615
1545
  ChannelsText.targets = targets;
1546
+ function replyOf(channel) {
1547
+ return channel?.reply && REPLIES.includes(channel.reply) ? channel.reply : DEFAULT_REPLY;
1548
+ }
1549
+ ChannelsText.replyOf = replyOf;
1550
+ function passes(text) {
1551
+ return text.replace(/[\s.。!!*_`"'“”]/g, "").toUpperCase() === PASS;
1552
+ }
1553
+ ChannelsText.passes = passes;
1554
+ function answering(team, channel) {
1555
+ const muted = channel.muted ?? [];
1556
+ return channel.members.filter((id) => !muted.includes(id)).map((id) => team.agents.find((agent) => agent.id === id)).filter((agent) => !!agent);
1557
+ }
1558
+ function mayPass(team, channel, message, agent) {
1559
+ const members = answering(team, channel);
1560
+ return message.author === USER && replyOf(channel) === "all" && members[0]?.id !== agent.id && mentions(message.text, team.agents).length === 0;
1561
+ }
1562
+ ChannelsText.mayPass = mayPass;
1616
1563
  function authorName(team, author, labels) {
1617
1564
  if (author === SYSTEM) {
1618
1565
  return "channel";
@@ -1647,18 +1594,29 @@ var ChannelsText;
1647
1594
  lines.push("", "Notice of the channel (follow it; keep it with update_channel_notice):", channel.notice.text);
1648
1595
  }
1649
1596
  if (before.length > 0) {
1650
- lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
1597
+ lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${said(item)}`));
1651
1598
  }
1652
1599
  if (options.closing) {
1653
1600
  lines.push("", CLOSING_NOTE);
1654
1601
  }
1602
+ if (mayPass(team, channel, message, agent)) {
1603
+ lines.push("", PASS_NOTE);
1604
+ }
1655
1605
  lines.push("", `${authorName(team, message.author, labels)} to you:`);
1656
1606
  const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels)}`;
1657
1607
  lines.push(TaMessageSource.line(NAME, `#${channel.name}${speaker}`));
1608
+ if (message.images?.length) {
1609
+ lines.push(`(${message.images.length > 1 ? `${message.images.length} pictures` : "A picture"} sent with it, attached.)`);
1610
+ }
1658
1611
  return TaMessageContext.wrap(lines.join(`
1659
1612
  `), message.text);
1660
1613
  }
1661
1614
  ChannelsText.prompt = prompt;
1615
+ function said(message) {
1616
+ const pictures = message.images?.length ? `[${message.images.length > 1 ? `${message.images.length} pictures` : "picture"}]` : "";
1617
+ return [pictures, message.text].filter(Boolean).join(" ");
1618
+ }
1619
+ ChannelsText.said = said;
1662
1620
  function summary(team) {
1663
1621
  if (team.agents.length === 0) {
1664
1622
  return "No agents and no channels yet.";
@@ -1673,7 +1631,7 @@ var ChannelsText;
1673
1631
  ChannelsText.summary = summary;
1674
1632
  function transcript(team, messages) {
1675
1633
  const labels = { user: "user", ta: "Ta" };
1676
- return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${item.text}`).join(`
1634
+ return messages.map((item) => `${authorName(team, item.author, labels)}${item.failed ? " (failed)" : ""}: ${said(item)}`).join(`
1677
1635
 
1678
1636
  `);
1679
1637
  }
@@ -1717,6 +1675,7 @@ var ChannelsText;
1717
1675
  }
1718
1676
  })(ChannelsText ||= {});
1719
1677
  var CLOSING_NOTE = "This discussion has spent most of what the user allows it before they look in: conclude now. Hand on only if the work cannot go on without that member; the lead sums up what was concluded and what the user is to decide.";
1678
+ var PASS_NOTE = `The user named nobody, and every member got this message: answer only if your role has something of its own to add; the lead answers for the channel. Else answer exactly ${PASS}, which is not posted.`;
1720
1679
  var NOTICE_RULE = [
1721
1680
  "A channel may have a notice, in the <context> block: what its members decided, agreed and are to do. Follow it.",
1722
1681
  `When the talk settles a decision or a convention, or adds, assigns or finishes a to-do, update it with update_channel_notice: the whole notice, short, under the headings ### ${NOTICE_HEADINGS.zh.join(" / ")} (### ${NOTICE_HEADINGS.en.join(" / ")} in English), in the language of the channel, to-dos as - [ ] or - [x] with who does them. The lead keeps it most; leave it for small talk.`
@@ -2323,6 +2282,53 @@ var TaAppUtil;
2323
2282
  })(TaAppUtil || (TaAppUtil = {}));
2324
2283
  // ../ta-protocol/esm/common/auth-protocol.js
2325
2284
  var TaAuthServer = Symbol("TaAuthServer");
2285
+ // ../ta-protocol/esm/common/confine-protocol.js
2286
+ var TA_CONFINED_MARK = "[ta:confined]";
2287
+ var AT = String.raw`(?:^|[;&|(\`]|\$\()\s*(?:sudo\s+|env\s+(?:\S+=\S*\s+)*|npx\s+|bunx\s+|pnpm\s+(?:exec|dlx)\s+|yarn\s+dlx\s+|exec\s+|xargs\s+(?:-\S+\s+)*)*`;
2288
+ var command = (names) => new RegExp(`${AT}(?:${names})(?=\\s|$|[;&|)])`, "m");
2289
+ var BLOCKED = [
2290
+ [/\bgit\b[^\n;&|]*\s(?:push|send-email|request-pull)\b/, "pushing: the user puts the work out once they looked at it"],
2291
+ [/\bgit\b[^\n;&|]*\sremote\s+(?:add|set-url|rename|remove|rm)\b/, "changing the remotes"],
2292
+ [/\bgit\b[^\n;&|]*\sconfig\b[^\n;&|]*(?:credential|url\.|core\.sshcommand|core\.hookspath)/i, "changing how git reaches others"],
2293
+ [/\b(?:publish|unpublish|deprecate)\b/, "publishing"],
2294
+ [
2295
+ command("wrangler|vercel|netlify|flyctl|fly|firebase|heroku|gh|aws|gcloud|az|kubectl|helm|terraform|pulumi|docker|podman|eas|fastlane|xcrun\\s+altool|twine"),
2296
+ "deploying, or the tools of a cloud"
2297
+ ],
2298
+ [command("ssh|scp|sftp|rsync|nc|ncat|netcat|telnet|ftp|socat"), "reaching other machines"],
2299
+ [
2300
+ /\b(?:curl|wget|http|https|Invoke-WebRequest|Invoke-RestMethod|iwr|irm)\b[^\n;&|]*(?:\s-[a-zA-Z]*[dFT]\b|\s--(?:data|upload|form|post|put|json)|\s-X\s*(?:POST|PUT|PATCH|DELETE)|\s-Method\s+(?:Post|Put|Patch|Delete)|\s-Body\b|\s-InFile\b)/i,
2301
+ "sending data out"
2302
+ ],
2303
+ [
2304
+ /(?:~|\$HOME|\$\{HOME\}|\$env:USERPROFILE|\/Users\/[^/\s]+|\/home\/[^/\s]+|\/root)[\\/]\.(?:ssh|aws|gnupg|netrc|npmrc|yarnrc|pypirc|zshenv|zshrc|zprofile|bashrc|bash_profile|profile|docker|kube|ta|codebuddy|claude|cursor|config[\\/](?:gh|gcloud|hub))\b/i,
2305
+ "the user's secrets and settings"
2306
+ ],
2307
+ [/\bsecurity\s+(?:find|dump|export)-/, "the keychain"],
2308
+ [command("printenv|env|set|export\\s+-p|declare\\s+-x|Get-ChildItem\\s+env:|gci\\s+env:|dir\\s+env:"), "printing the environment (it holds tokens)"],
2309
+ [command("sudo|su|doas|osascript|launchctl|crontab|defaults\\s+write|schtasks|reg"), "acting as the system"],
2310
+ [/\brm\s+-[a-zA-Z]*[rR][a-zA-Z]*\s+(?:-[a-zA-Z]+\s+)*(?:\/|~|\$HOME|\$\{HOME\})(?:\s|$|\/\s|\/\*)/, "deleting outside its directory"]
2311
+ ];
2312
+ var TaConfineUtil;
2313
+ (function(TaConfineUtil2) {
2314
+ TaConfineUtil2.FILE_TOOLS = ["read", "edit", "write", "grep", "find", "ls"];
2315
+ TaConfineUtil2.COMMAND_TOOLS = ["bash", "powershell"];
2316
+ function confine(role) {
2317
+ return role.includes(TA_CONFINED_MARK) ? role : `${TA_CONFINED_MARK}
2318
+ ${role}`;
2319
+ }
2320
+ TaConfineUtil2.confine = confine;
2321
+ function confined(systemPrompt) {
2322
+ return TaHostUtil.marked(systemPrompt, TA_CONFINED_MARK);
2323
+ }
2324
+ TaConfineUtil2.confined = confined;
2325
+ function blocked(commandText) {
2326
+ var _a;
2327
+ const text = String(commandText !== null && commandText !== undefined ? commandText : "");
2328
+ return (_a = BLOCKED.find(([pattern]) => pattern.test(text))) === null || _a === undefined ? undefined : _a[1];
2329
+ }
2330
+ TaConfineUtil2.blocked = blocked;
2331
+ })(TaConfineUtil || (TaConfineUtil = {}));
2326
2332
  // ../ta-protocol/esm/common/deployment-protocol.js
2327
2333
  var TA_WELL_KNOWN_PATH = "/.well-known/ta";
2328
2334
 
@@ -2874,6 +2880,7 @@ var TaRemoteServer = Symbol("TaRemoteServer");
2874
2880
  // ../ta-protocol/esm/common/room-protocol.js
2875
2881
  var TaRoomServer = Symbol("TaRoomServer");
2876
2882
  var TA_PICTURE = { key: "picture:", maxChars: 16 * 1024 };
2883
+ var TA_CHAT_KEY = "chat:";
2877
2884
  var TaRoomWatchUtil;
2878
2885
  (function(TaRoomWatchUtil2) {
2879
2886
  function of(messages, state) {
@@ -2901,6 +2908,9 @@ var TaRoomWatchUtil;
2901
2908
  if (event.type === "message") {
2902
2909
  return watch.messages;
2903
2910
  }
2911
+ if (event.type === "chat") {
2912
+ return watch.messages || watch.state.some((prefix) => TA_CHAT_KEY.startsWith(prefix) || prefix.startsWith(TA_CHAT_KEY));
2913
+ }
2904
2914
  if (event.type === "state") {
2905
2915
  return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
2906
2916
  }
@@ -2957,13 +2967,119 @@ var TaServer = Symbol("TaServer");
2957
2967
  var TaClient = Symbol("TaClient");
2958
2968
  var TaSlashCommandUtil;
2959
2969
  (function(TaSlashCommandUtil2) {
2960
- function description(command, language) {
2970
+ function description(command2, language) {
2961
2971
  var _a, _b;
2962
- const { descriptions } = command;
2963
- return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
2972
+ const { descriptions } = command2;
2973
+ return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command2.description;
2964
2974
  }
2965
2975
  TaSlashCommandUtil2.description = description;
2966
2976
  })(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
2977
+ // ../ta-protocol/esm/common/team-protocol.js
2978
+ var TA_OWNER = "owner";
2979
+ var TA_UNDECLARED = "extensions.install";
2980
+ var TaPermissionUtil;
2981
+ (function(TaPermissionUtil2) {
2982
+ function read(pi) {
2983
+ const given = pi === null || pi === undefined ? undefined : pi.permissions;
2984
+ const map = (value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string")) : undefined;
2985
+ const host2 = map(given === null || given === undefined ? undefined : given.host);
2986
+ const tools = map(given === null || given === undefined ? undefined : given.tools);
2987
+ return { ...host2 ? { host: host2 } : {}, ...tools ? { tools } : {} };
2988
+ }
2989
+ TaPermissionUtil2.read = read;
2990
+ function host(manifest, method, kind) {
2991
+ var _a, _b, _c, _d;
2992
+ const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
2993
+ const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
2994
+ 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;
2995
+ }
2996
+ TaPermissionUtil2.host = host;
2997
+ })(TaPermissionUtil || (TaPermissionUtil = {}));
2998
+ var action = (id, en, zh, tw, ja, more = {}) => ({
2999
+ id,
3000
+ area: id.split(".")[0],
3001
+ title: { en, "zh-CN": zh, ...tw ? { "zh-TW": tw } : {}, ...ja ? { "ja-JP": ja } : {} },
3002
+ ...more
3003
+ });
3004
+ var TA_ACTIONS = [
3005
+ action("chat.view", "See conversations", "查看对话", "檢視對話", "会話を確認"),
3006
+ action("chat.send", "Send in conversations", "在对话里发消息", "在對話裡發訊息", "会話にメッセージを送信"),
3007
+ action("chat.create", "Start conversations", "新建对话", "新建對話", "新しい会話を開始"),
3008
+ action("chat.stop", "Stop a reply", "停止回复", "停止回覆", "返信を停止"),
3009
+ action("chat.manage", "Rename, archive and close conversations", "改名、归档、关闭对话", "改名、歸檔、關閉對話", "会話の名前変更、アーカイブ、クローズ"),
3010
+ action("chat.share", "Share by a link", "生成分享链接", "生成分享連結", "共有リンクで共有"),
3011
+ action("agent.view", "See agents", "查看智能体", "檢視智慧體", "エージェントを確認"),
3012
+ action("agent.use", "Talk with agents", "和智能体对话", "和智慧體對話", "エージェントと対話"),
3013
+ action("agent.edit", "Create, change and remove agents", "新建、修改、删除智能体", "新建、修改、刪除智慧體", "エージェントを作成・変更・削除"),
3014
+ action("channel.view", "See channels", "查看频道", "檢視頻道", "チャネルを確認"),
3015
+ action("channel.post", "Post in channels", "在频道里发言", "在頻道里發言", "チャネルに投稿"),
3016
+ action("channel.manage", "Create and change channels", "新建、管理频道", "新建、管理頻道", "チャネルを作成・管理"),
3017
+ action("task.view", "See tasks", "查看任务", "檢視任務", "タスクを確認"),
3018
+ action("task.create", "Hand out tasks", "派任务", "派任務", "タスクを割り当て"),
3019
+ action("task.manage", "Take over and stop tasks", "接管、停止任务", "接管、停止任務", "タスクを引き継ぎ・停止"),
3020
+ action("files.read", "Read files", "读文件", "讀檔案", "ファイルを読取", { scoped: true }),
3021
+ action("files.write", "Change files", "改文件", "改檔案", "ファイルを変更", { scoped: true }),
3022
+ action("commands.run", "Let Ta run commands", "让 Ta 运行命令", "讓 Ta 執行命令", "Ta にコマンド実行を許可", { scoped: true, risky: true }),
3023
+ action("commands.terminal", "Open terminals", "打开终端", "開啟終端機", "ターミナルを開く", { scoped: true, risky: true }),
3024
+ action("hosts.use", "Use remote hosts", "使用远程主机", "使用遠端主機", "リモートホストを使用", { risky: true }),
3025
+ action("models.use", "Use the models", "使用模型", "使用模型", "モデルを使用"),
3026
+ action("models.manage", "Sign in to models", "登录和更换模型账号", "登入和更換模型帳號", "モデルアカウントにサインイン・変更", { grant: "single" }),
3027
+ action("cron.view", "See scheduled tasks", "查看定时任务", "檢視定時任務", "スケジュールタスクを確認"),
3028
+ action("cron.manage", "Change scheduled tasks", "管理定时任务", "管理定時任務", "スケジュールタスクを管理"),
3029
+ action("extensions.use", "Use extensions", "使用扩展", "使用擴充功能", "拡張機能を使用"),
3030
+ action("extensions.install", "Install and turn off extensions", "安装、停用扩展", "安裝、停用擴充功能", "拡張機能をインストール・無効化"),
3031
+ action("settings.view", "See settings", "查看设置", "檢視設定", "設定を確認"),
3032
+ action("settings.manage", "Change settings", "修改设置", "修改設定", "設定を変更"),
3033
+ action("members.view", "See members", "查看成员", "檢視成員", "メンバーを確認"),
3034
+ action("members.invite", "Invite people", "邀请别人", "邀請別人", "メンバーを招待"),
3035
+ action("members.approve", "Answer requests", "处理申请", "處理申請", "リクエストに対応"),
3036
+ action("members.roles", "Change roles and members", "管理角色和成员", "管理角色和成員", "ロールとメンバーを管理"),
3037
+ action("audit.view", "See the record", "查看记录", "檢視記錄", "レコードを確認")
3038
+ ];
3039
+ var TA_OWNER_ACTIONS = [
3040
+ action("desktop.view", "See remote desktops", "查看远程桌面", "檢視遠端桌面", "リモートデスクトップを見る", { risky: true }),
3041
+ action("desktop.control", "Work remote desktops", "操作远程桌面", "操作遠端桌面", "リモートデスクトップを操作", { risky: true })
3042
+ ];
3043
+ var OWNER_AREAS = ["desktop"];
3044
+ var TaActionUtil;
3045
+ (function(TaActionUtil2) {
3046
+ const byId = new Map(TA_ACTIONS.map((one) => [one.id, one]));
3047
+ const titled = new Map([...TA_ACTIONS, ...TA_OWNER_ACTIONS].map((one) => [one.id, one]));
3048
+ function info(id) {
3049
+ return byId.get(id);
3050
+ }
3051
+ TaActionUtil2.info = info;
3052
+ function title(id, language) {
3053
+ var _a;
3054
+ var _b, _c;
3055
+ const title2 = (_a = titled.get(id)) === null || _a === undefined ? undefined : _a.title;
3056
+ if (!title2) {
3057
+ return id;
3058
+ }
3059
+ return TaLanguageUtil.pick(language, {
3060
+ "zh-CN": title2["zh-CN"],
3061
+ "zh-TW": (_b = title2["zh-TW"]) !== null && _b !== undefined ? _b : title2["zh-CN"],
3062
+ "en-US": title2.en,
3063
+ "ja-JP": (_c = title2["ja-JP"]) !== null && _c !== undefined ? _c : title2.en
3064
+ });
3065
+ }
3066
+ TaActionUtil2.title = title;
3067
+ function grantable(id) {
3068
+ const info2 = byId.get(id);
3069
+ return !!info2 && !OWNER_AREAS.includes(info2.area);
3070
+ }
3071
+ TaActionUtil2.grantable = grantable;
3072
+ function inRoles(id) {
3073
+ var _a;
3074
+ return grantable(id) && ((_a = byId.get(id)) === null || _a === undefined ? undefined : _a.grant) !== "single";
3075
+ }
3076
+ TaActionUtil2.inRoles = inRoles;
3077
+ function inside(dir, path) {
3078
+ const base = dir.replace(/\/+$/, "");
3079
+ return path === base || path.startsWith(`${base}/`) || base === "";
3080
+ }
3081
+ TaActionUtil2.inside = inside;
3082
+ })(TaActionUtil || (TaActionUtil = {}));
2967
3083
  // ../ta-protocol/esm/common/usage-protocol.js
2968
3084
  var TaUsageServer = Symbol("TaUsageServer");
2969
3085
  // ../ta-protocol/esm/common/voice-protocol.js
@@ -3031,12 +3147,100 @@ var TaExcludedFiles;
3031
3147
  TaExcludedFiles2.filter = filter;
3032
3148
  })(TaExcludedFiles || (TaExcludedFiles = {}));
3033
3149
  var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
3150
+ // web-src/channel-pictures.ts
3151
+ import { randomBytes } from "node:crypto";
3152
+ import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
3153
+ import { join } from "node:path";
3154
+ var CHANNEL_IMAGES = 9;
3155
+ var CHANNEL_IMAGE_BYTES = 2 * 1024 * 1024;
3156
+ var EXTENSIONS = { "image/jpeg": "jpg", "image/png": "png", "image/gif": "gif", "image/webp": "webp" };
3157
+ var SAFE_ID = /^[A-Za-z0-9_-]{1,80}$/;
3158
+ var PICTURE_ID = /^[a-f0-9]{24}$/;
3159
+
3160
+ class ChannelPictures {
3161
+ agentDir;
3162
+ constructor(agentDir) {
3163
+ this.agentDir = agentDir;
3164
+ }
3165
+ root() {
3166
+ const dir = this.agentDir();
3167
+ return dir ? join(dir, "ta-channels", "pictures") : undefined;
3168
+ }
3169
+ file(channel, image) {
3170
+ const root = this.root();
3171
+ const extension = EXTENSIONS[image.type];
3172
+ return root && SAFE_ID.test(channel) && PICTURE_ID.test(image.id) && extension ? join(root, channel, `${image.id}.${extension}`) : undefined;
3173
+ }
3174
+ async put(channel, inputs) {
3175
+ if (!Array.isArray(inputs) || !inputs.length) {
3176
+ return [];
3177
+ }
3178
+ if (inputs.length > CHANNEL_IMAGES) {
3179
+ throw new Error(`At most ${CHANNEL_IMAGES} pictures at once.`);
3180
+ }
3181
+ const images = [];
3182
+ for (const input of inputs) {
3183
+ const bytes = new Uint8Array(Buffer.from(String(input?.data ?? ""), "base64"));
3184
+ const type = TaImageSize.type(bytes);
3185
+ if (!type || bytes.length > CHANNEL_IMAGE_BYTES) {
3186
+ throw new Error("Not a picture, or too large.");
3187
+ }
3188
+ const size = TaImageSize.of(String(input?.data)) ?? { width: Number(input?.width) || 1, height: Number(input?.height) || 1 };
3189
+ const image = { id: randomBytes(12).toString("hex"), type, w: size.width, h: size.height };
3190
+ const file = this.file(channel, image);
3191
+ if (!file) {
3192
+ throw new Error("The pictures cannot be kept here.");
3193
+ }
3194
+ await mkdir(join(file, ".."), { recursive: true });
3195
+ await writeFile(file, bytes);
3196
+ images.push(image);
3197
+ }
3198
+ return images;
3199
+ }
3200
+ async read(channel, image) {
3201
+ const file = this.file(channel, image);
3202
+ const bytes = file ? await readFile(file).catch(() => {
3203
+ return;
3204
+ }) : undefined;
3205
+ return bytes?.toString("base64");
3206
+ }
3207
+ async images(channel, images) {
3208
+ const read = [];
3209
+ for (const image of images ?? []) {
3210
+ const data = await this.read(channel, image);
3211
+ if (data) {
3212
+ read.push({ type: "image", data, mimeType: image.type });
3213
+ }
3214
+ }
3215
+ return read;
3216
+ }
3217
+ async keepOnly(channel, named) {
3218
+ const root = this.root();
3219
+ if (!root || !SAFE_ID.test(channel)) {
3220
+ return;
3221
+ }
3222
+ const ids = new Set(named.map((image) => image.id));
3223
+ for (const name of await readdir(join(root, channel)).catch(() => [])) {
3224
+ if (!ids.has(name.replace(/\.[a-z]+$/, ""))) {
3225
+ await rm(join(root, channel, name), { force: true });
3226
+ }
3227
+ }
3228
+ }
3229
+ async forget(channel) {
3230
+ const root = this.root();
3231
+ if (root && SAFE_ID.test(channel)) {
3232
+ await rm(join(root, channel), { recursive: true, force: true });
3233
+ }
3234
+ }
3235
+ }
3236
+
3034
3237
  // web-src/team-view.ts
3035
3238
  var TeamViewUtil;
3036
3239
  ((TeamViewUtil) => {
3037
3240
  function visible(team2, can) {
3038
3241
  const channels = new Set(team2.channels.filter((channel) => can("channel", channel.id)).map((channel) => channel.id));
3039
- const agents = new Set(team2.agents.filter((agent) => can("agent", agent.id)).map((agent) => agent.id));
3242
+ const own = new Set(team2.agents.filter((agent) => can("agent", agent.id)).map((agent) => agent.id));
3243
+ const agents = new Set(own);
3040
3244
  for (const channel of team2.channels) {
3041
3245
  if (channels.has(channel.id)) {
3042
3246
  for (const member of channel.members) {
@@ -3044,20 +3248,50 @@ var TeamViewUtil;
3044
3248
  }
3045
3249
  }
3046
3250
  }
3047
- return { agents, channels };
3251
+ return { agents, channels, own };
3048
3252
  }
3049
3253
  TeamViewUtil.visible = visible;
3050
- function team(value, visible2) {
3254
+ function team(value, visible2, can) {
3051
3255
  if (!value) {
3052
3256
  return value;
3053
3257
  }
3258
+ const may = { create: can("agent.edit"), agents: [], manage: [], edit: [] };
3259
+ const agents = value.agents.filter((agent) => visible2.agents.has(agent.id)).map((agent) => {
3260
+ const edits = can("agent.edit", { kind: "agent", id: agent.id });
3261
+ if (edits) {
3262
+ may.agents.push(agent.id);
3263
+ }
3264
+ return agentAs(agent, edits, visible2.own.has(agent.id));
3265
+ });
3266
+ const channels = value.channels.filter((channel) => visible2.channels.has(channel.id)).map((channel) => {
3267
+ const resource = { kind: "channel", id: channel.id };
3268
+ const manages = can("channel.manage", resource);
3269
+ if (manages) {
3270
+ may.manage.push(channel.id);
3271
+ }
3272
+ if (can("agent.edit", resource)) {
3273
+ may.edit.push(channel.id);
3274
+ }
3275
+ return manages ? channel : channelAs(channel);
3276
+ });
3277
+ return { ...value, agents, channels, may };
3278
+ }
3279
+ TeamViewUtil.team = team;
3280
+ function agentAs(agent, edits, own) {
3281
+ const { model, cwd, sessionFile, ...rest } = agent;
3054
3282
  return {
3055
- ...value,
3056
- agents: value.agents.filter((agent) => visible2.agents.has(agent.id)),
3057
- channels: value.channels.filter((channel) => visible2.channels.has(channel.id))
3283
+ ...rest,
3284
+ ...edits && model !== undefined ? { model } : {},
3285
+ ...own && cwd !== undefined ? { cwd } : {},
3286
+ ...own && sessionFile !== undefined ? { sessionFile } : {}
3058
3287
  };
3059
3288
  }
3060
- TeamViewUtil.team = team;
3289
+ function channelAs(channel) {
3290
+ const rest = { ...channel };
3291
+ delete rest.budget;
3292
+ delete rest.dailyLimit;
3293
+ return rest;
3294
+ }
3061
3295
  function byId(value, seen) {
3062
3296
  if (!value || typeof value !== "object" || Array.isArray(value)) {
3063
3297
  return value;
@@ -3084,6 +3318,7 @@ class TeamStore {
3084
3318
  watched = new Map;
3085
3319
  options;
3086
3320
  disposed = false;
3321
+ pictures = new ChannelPictures(() => this.host.agentDir);
3087
3322
  constructor(host, options = {}) {
3088
3323
  this.host = host;
3089
3324
  this.options = { pollMs: 300, timeoutMs: 15 * 60 * 1000, ...options };
@@ -3243,9 +3478,13 @@ class TeamStore {
3243
3478
  return message;
3244
3479
  }
3245
3480
  await this.messagesOf(channelId);
3246
- const messages = ChannelsUtil.append(this.messages.get(channelId) ?? [], message);
3481
+ const before = this.messages.get(channelId) ?? [];
3482
+ const messages = ChannelsUtil.append(before, message);
3247
3483
  this.messages.set(channelId, messages);
3248
3484
  await this.set(Keys.messages(channelId), messages);
3485
+ if (before.length >= messages.length && before.some((item) => item.images?.length && !messages.includes(item))) {
3486
+ await this.pictures.keepOnly(channelId, messages.flatMap((item) => item.images ?? []));
3487
+ }
3249
3488
  return message;
3250
3489
  }
3251
3490
  async replace(channelId, message) {
@@ -3253,6 +3492,23 @@ class TeamStore {
3253
3492
  this.messages.set(channelId, messages);
3254
3493
  await this.set(Keys.messages(channelId), messages);
3255
3494
  }
3495
+ poster() {
3496
+ const principal = this.host.team?.current();
3497
+ if (!principal || principal === TA_OWNER) {
3498
+ return {};
3499
+ }
3500
+ return { by: principal, byName: this.host.team?.describe(principal)?.name ?? principal };
3501
+ }
3502
+ async posterOf(request) {
3503
+ const channel = ChannelsUtil.findChannel(this.team, String(request.channel ?? ""));
3504
+ const images = channel ? await this.pictures.put(channel.id, request.images) : [];
3505
+ return { ...this.poster(), ...images.length ? { images } : {} };
3506
+ }
3507
+ async picture(channelId, id) {
3508
+ const image = (await this.messagesOf(channelId)).flatMap((item) => item.images ?? []).find((each) => each.id === id);
3509
+ const data = image && await this.pictures.read(channelId, image);
3510
+ return image && data ? `data:${image.type};base64,${data}` : "";
3511
+ }
3256
3512
  async saveTeam(team) {
3257
3513
  this.team = team;
3258
3514
  this.linkSessions();
@@ -3269,7 +3525,7 @@ class TeamStore {
3269
3525
  view: (principal, key, value) => {
3270
3526
  const visible = TeamViewUtil.visible(this.team, (kind, id) => can(principal, kind, id));
3271
3527
  if (key === Keys.TEAM) {
3272
- return TeamViewUtil.team(value, visible);
3528
+ return TeamViewUtil.team(value, visible, (action2, resource) => team.can(principal, action2, resource));
3273
3529
  }
3274
3530
  if (key.startsWith(Keys.MESSAGES)) {
3275
3531
  return visible.channels.has(key.slice(Keys.MESSAGES.length)) ? value : undefined;
@@ -3371,6 +3627,10 @@ class TeamAnswers extends TeamStore {
3371
3627
  await this.setAnswered(agentId, Date.now());
3372
3628
  await this.setWorking(channel.id, agentId, false);
3373
3629
  }
3630
+ const agent = this.team.agents.find((candidate) => candidate.id === agentId);
3631
+ if (!failed && !over && agent && ChannelsText.passes(text) && ChannelsText.mayPass(this.team, channel, message, agent)) {
3632
+ return { tokens, changed };
3633
+ }
3374
3634
  const posted = await this.append(channel.id, {
3375
3635
  id: ChannelsUtil.newId("message"),
3376
3636
  author: agentId,
@@ -3394,7 +3654,8 @@ class TeamAnswers extends TeamStore {
3394
3654
  const history = await this.messagesOf(channel.id);
3395
3655
  const input = {
3396
3656
  clientMessageId: `${message.id}:${agent.id}`,
3397
- message: ChannelsText.prompt(this.team, channel, history, message, agent, { closing })
3657
+ message: ChannelsText.prompt(this.team, channel, history, message, agent, { closing }),
3658
+ ...message.images?.length ? { images: await this.pictures.images(channel.id, message.images) } : {}
3398
3659
  };
3399
3660
  await this.host.prompt(sessionId, input);
3400
3661
  const cap = (await this.limits()).answer;
@@ -3610,6 +3871,7 @@ class TeamService extends TeamAnswers {
3610
3871
  return agent;
3611
3872
  }
3612
3873
  async forget(channel) {
3874
+ await this.pictures.forget(channel.id);
3613
3875
  this.messages.delete(channel.id);
3614
3876
  this.reading.delete(channel.id);
3615
3877
  await this.set(Keys.messages(channel.id), null);
@@ -3632,20 +3894,13 @@ class TeamService extends TeamAnswers {
3632
3894
  async focus(channelId) {
3633
3895
  await this.set(Keys.FOCUS, { channelId, at: Date.now() });
3634
3896
  }
3635
- poster() {
3636
- const principal = this.host.team?.current();
3637
- if (!principal || principal === TA_OWNER) {
3638
- return {};
3639
- }
3640
- return { by: principal, byName: this.host.team?.describe(principal)?.name ?? principal };
3641
- }
3642
3897
  async post(channelRef, author, text, poster = {}) {
3643
3898
  const channel = ChannelsUtil.findChannel(this.team, channelRef);
3644
3899
  if (!channel) {
3645
3900
  const known = this.team.channels.map((other) => `#${other.name}`).join(", ") || "none yet";
3646
3901
  throw new Error(`No channel is named ${channelRef}. The channels: ${known}.`);
3647
3902
  }
3648
- if (!text.trim()) {
3903
+ if (!text.trim() && !poster.images?.length) {
3649
3904
  throw new Error("The message is empty.");
3650
3905
  }
3651
3906
  const message = await this.append(channel.id, { id: ChannelsUtil.newId("message"), author, text: text.trim(), at: Date.now(), ...poster });
@@ -3719,7 +3974,9 @@ class TeamService extends TeamAnswers {
3719
3974
  case "deleteAgent":
3720
3975
  return this.deleteAgent(request.agent);
3721
3976
  case "post":
3722
- return (await this.post(String(request.channel ?? ""), USER, String(request.text ?? ""), this.poster())).message;
3977
+ return (await this.post(String(request.channel ?? ""), USER, String(request.text ?? ""), await this.posterOf(request))).message;
3978
+ case "picture":
3979
+ return this.picture(String(request.channel ?? ""), String(request.id ?? ""));
3723
3980
  case "resumeRound":
3724
3981
  return this.resumeRound(request.channel, request.message, request.how, this.poster());
3725
3982
  case "watch":
@@ -3840,7 +4097,9 @@ class TeamService extends TeamAnswers {
3840
4097
  if (answered.changed) {
3841
4098
  this.progressed(channel.id, job.round);
3842
4099
  }
3843
- this.checkIdle(job.round, reply);
4100
+ if (reply) {
4101
+ this.checkIdle(job.round, reply);
4102
+ }
3844
4103
  }
3845
4104
  if (this.disposed) {
3846
4105
  return;