@celljs/ta-channels 4.28.0 → 4.29.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.
@@ -830,33 +830,6 @@ var ChannelsUtil;
830
830
  return { team: next, channel, agents };
831
831
  }
832
832
  ChannelsUtil.setChannelModel = setChannelModel;
833
- function removeAgent(team, ref) {
834
- const agent = findAgent(team, typeof ref === "string" ? ref : "");
835
- if (!agent) {
836
- throw new Error(`No agent is ${String(ref)}.`);
837
- }
838
- const gone = [];
839
- const channels = [];
840
- for (const channel of team.channels) {
841
- if (!channel.members.includes(agent.id)) {
842
- channels.push(channel);
843
- continue;
844
- }
845
- const members = channel.members.filter((id) => id !== agent.id);
846
- if (members.length === 0) {
847
- gone.push(channel);
848
- continue;
849
- }
850
- const muted = channel.muted?.filter((id) => id !== agent.id);
851
- const next = { ...channel, members, muted };
852
- if (!muted?.length) {
853
- delete next.muted;
854
- }
855
- channels.push(next);
856
- }
857
- return { team: { agents: team.agents.filter((other) => other.id !== agent.id), channels }, agent, channels: gone };
858
- }
859
- ChannelsUtil.removeAgent = removeAgent;
860
833
  function agentIds(team, refs) {
861
834
  const ids = [];
862
835
  for (const ref of Array.isArray(refs) ? refs.filter((item) => typeof item === "string") : []) {
@@ -1111,6 +1084,40 @@ var TaAgentSummary;
1111
1084
  }
1112
1085
  TaAgentSummary2.strip = strip;
1113
1086
  })(TaAgentSummary || (TaAgentSummary = {}));
1087
+ var TaPictureNote;
1088
+ (function(TaPictureNote2) {
1089
+ TaPictureNote2.OPEN = "<pictures>";
1090
+ TaPictureNote2.CLOSE = "</pictures>";
1091
+ const BLOCK = /[ \t]*<pictures>([\s\S]*?)(?:<\/pictures>|$)|<p(?:i(?:c(?:t(?:u(?:r(?:es?)?)?)?)?)?)?$/gi;
1092
+ const ROW = /(?:^|\s)[-*]?\s*p(\d+)\s*[::]\s*/gi;
1093
+ function take(text) {
1094
+ const told = new Map;
1095
+ if (!/<p/i.test(text)) {
1096
+ return { said: text, told };
1097
+ }
1098
+ const said = text.replace(BLOCK, (_all, body) => {
1099
+ const rows = [...(body !== null && body !== undefined ? body : "").matchAll(ROW)];
1100
+ rows.forEach((row, index) => {
1101
+ var _a;
1102
+ var _b, _c;
1103
+ const end = (_b = (_a = rows[index + 1]) === null || _a === undefined ? undefined : _a.index) !== null && _b !== undefined ? _b : body === null || body === undefined ? undefined : body.length;
1104
+ const what = body === null || body === undefined ? undefined : body.slice(((_c = row.index) !== null && _c !== undefined ? _c : 0) + row[0].length, end).trim();
1105
+ if (what) {
1106
+ told.set(Number(row[1]), what);
1107
+ }
1108
+ });
1109
+ return "";
1110
+ });
1111
+ return { said: said === text ? text : said.replace(/\n{3,}/g, `
1112
+
1113
+ `).trim(), told };
1114
+ }
1115
+ TaPictureNote2.take = take;
1116
+ function strip(text) {
1117
+ return take(text).said;
1118
+ }
1119
+ TaPictureNote2.strip = strip;
1120
+ })(TaPictureNote || (TaPictureNote = {}));
1114
1121
  var TaSkillUse;
1115
1122
  (function(TaSkillUse2) {
1116
1123
  const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
@@ -1461,7 +1468,8 @@ var TaSaid;
1461
1468
  ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
1462
1469
  ["skill", /<skill name="|<\/skill>/],
1463
1470
  ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
1464
- ["summary", /<\/?(?:conversation_history_summary|summary)>/]
1471
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/],
1472
+ ["pictures described", /<\/?pictures>/]
1465
1473
  ];
1466
1474
  function text(content, joiner = `
1467
1475
  `) {
@@ -1472,7 +1480,7 @@ var TaSaid;
1472
1480
  }
1473
1481
  TaSaid2.text = text;
1474
1482
  function words(role, text2, options = {}) {
1475
- const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
1483
+ const said = role === "user" ? userWords(text2) : TaPictureNote.strip(TaAgentSummary.strip(text2));
1476
1484
  return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
1477
1485
  }
1478
1486
  TaSaid2.words = words;
@@ -1591,6 +1599,17 @@ Switched to voice.`, said: "Switched to voice." },
1591
1599
  { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
1592
1600
  { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
1593
1601
  { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
1602
+ {
1603
+ mark: "pictures described after the answer",
1604
+ role: "assistant",
1605
+ text: `The left one.
1606
+
1607
+ <pictures> p1: two cats on a sofa. p2: a chart of sales, "Q4". </pictures>`,
1608
+ said: "The left one."
1609
+ },
1610
+ { mark: "pictures described as it streams", role: "assistant", text: `The left one.
1611
+ <pictures>
1612
+ p1: two ca`, said: "The left one." },
1594
1613
  { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
1595
1614
  </system-reminder>
1596
1615
  Ready.`, said: "Ready." }
package/host/index.mjs CHANGED
@@ -212,6 +212,40 @@ var TaAgentSummary;
212
212
  }
213
213
  TaAgentSummary2.strip = strip;
214
214
  })(TaAgentSummary || (TaAgentSummary = {}));
215
+ var TaPictureNote;
216
+ (function(TaPictureNote2) {
217
+ TaPictureNote2.OPEN = "<pictures>";
218
+ TaPictureNote2.CLOSE = "</pictures>";
219
+ const BLOCK = /[ \t]*<pictures>([\s\S]*?)(?:<\/pictures>|$)|<p(?:i(?:c(?:t(?:u(?:r(?:es?)?)?)?)?)?)?$/gi;
220
+ const ROW = /(?:^|\s)[-*]?\s*p(\d+)\s*[::]\s*/gi;
221
+ function take(text) {
222
+ const told = new Map;
223
+ if (!/<p/i.test(text)) {
224
+ return { said: text, told };
225
+ }
226
+ const said = text.replace(BLOCK, (_all, body) => {
227
+ const rows = [...(body !== null && body !== undefined ? body : "").matchAll(ROW)];
228
+ rows.forEach((row, index) => {
229
+ var _a;
230
+ var _b, _c;
231
+ const end = (_b = (_a = rows[index + 1]) === null || _a === undefined ? undefined : _a.index) !== null && _b !== undefined ? _b : body === null || body === undefined ? undefined : body.length;
232
+ const what = body === null || body === undefined ? undefined : body.slice(((_c = row.index) !== null && _c !== undefined ? _c : 0) + row[0].length, end).trim();
233
+ if (what) {
234
+ told.set(Number(row[1]), what);
235
+ }
236
+ });
237
+ return "";
238
+ });
239
+ return { said: said === text ? text : said.replace(/\n{3,}/g, `
240
+
241
+ `).trim(), told };
242
+ }
243
+ TaPictureNote2.take = take;
244
+ function strip(text) {
245
+ return take(text).said;
246
+ }
247
+ TaPictureNote2.strip = strip;
248
+ })(TaPictureNote || (TaPictureNote = {}));
215
249
  var TaSkillUse;
216
250
  (function(TaSkillUse2) {
217
251
  const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
@@ -689,6 +723,7 @@ var LIMIT_CHOICES = {
689
723
  channelDay: [2000000, 5000000, 20000000, 0],
690
724
  allDay: [5000000, 20000000, 0]
691
725
  };
726
+ var REMOVED_DAYS = 30;
692
727
  var NAME = "@celljs/ta-channels";
693
728
  var AGENT_MARK = "one of the agents of Ta";
694
729
  var MEMBER_CHANGES = ["lead", "remove", "mute", "unmute"];
@@ -1161,33 +1196,6 @@ var ChannelsUtil;
1161
1196
  return { team: next, channel, agents };
1162
1197
  }
1163
1198
  ChannelsUtil.setChannelModel = setChannelModel;
1164
- function removeAgent(team, ref) {
1165
- const agent = findAgent(team, typeof ref === "string" ? ref : "");
1166
- if (!agent) {
1167
- throw new Error(`No agent is ${String(ref)}.`);
1168
- }
1169
- const gone = [];
1170
- const channels = [];
1171
- for (const channel of team.channels) {
1172
- if (!channel.members.includes(agent.id)) {
1173
- channels.push(channel);
1174
- continue;
1175
- }
1176
- const members = channel.members.filter((id) => id !== agent.id);
1177
- if (members.length === 0) {
1178
- gone.push(channel);
1179
- continue;
1180
- }
1181
- const muted = channel.muted?.filter((id) => id !== agent.id);
1182
- const next = { ...channel, members, muted };
1183
- if (!muted?.length) {
1184
- delete next.muted;
1185
- }
1186
- channels.push(next);
1187
- }
1188
- return { team: { agents: team.agents.filter((other) => other.id !== agent.id), channels }, agent, channels: gone };
1189
- }
1190
- ChannelsUtil.removeAgent = removeAgent;
1191
1199
  function agentIds(team, refs) {
1192
1200
  const ids = [];
1193
1201
  for (const ref of Array.isArray(refs) ? refs.filter((item) => typeof item === "string") : []) {
@@ -1293,7 +1301,8 @@ var TaSaid;
1293
1301
  ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
1294
1302
  ["skill", /<skill name="|<\/skill>/],
1295
1303
  ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
1296
- ["summary", /<\/?(?:conversation_history_summary|summary)>/]
1304
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/],
1305
+ ["pictures described", /<\/?pictures>/]
1297
1306
  ];
1298
1307
  function text(content, joiner = `
1299
1308
  `) {
@@ -1304,7 +1313,7 @@ var TaSaid;
1304
1313
  }
1305
1314
  TaSaid2.text = text;
1306
1315
  function words(role, text2, options = {}) {
1307
- const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
1316
+ const said = role === "user" ? userWords(text2) : TaPictureNote.strip(TaAgentSummary.strip(text2));
1308
1317
  return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
1309
1318
  }
1310
1319
  TaSaid2.words = words;
@@ -1423,6 +1432,17 @@ Switched to voice.`, said: "Switched to voice." },
1423
1432
  { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
1424
1433
  { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
1425
1434
  { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
1435
+ {
1436
+ mark: "pictures described after the answer",
1437
+ role: "assistant",
1438
+ text: `The left one.
1439
+
1440
+ <pictures> p1: two cats on a sofa. p2: a chart of sales, "Q4". </pictures>`,
1441
+ said: "The left one."
1442
+ },
1443
+ { mark: "pictures described as it streams", role: "assistant", text: `The left one.
1444
+ <pictures>
1445
+ p1: two ca`, said: "The left one." },
1426
1446
  { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
1427
1447
  </system-reminder>
1428
1448
  Ready.`, said: "Ready." }
@@ -1792,6 +1812,85 @@ ${brief.trim()}`;
1792
1812
  HandOff.result = result;
1793
1813
  })(HandOff ||= {});
1794
1814
 
1815
+ // web-src/removed-agents.ts
1816
+ var RemovedAgentsUtil;
1817
+ ((RemovedAgentsUtil) => {
1818
+ function remove(team, ref, at = Date.now()) {
1819
+ const agent = ChannelsUtil.findAgent(team, typeof ref === "string" ? ref : "");
1820
+ if (!agent) {
1821
+ throw new Error(`No agent is ${String(ref)}.`);
1822
+ }
1823
+ const gone = [];
1824
+ const channels = [];
1825
+ for (const channel of team.channels) {
1826
+ if (!channel.members.includes(agent.id)) {
1827
+ channels.push(channel);
1828
+ continue;
1829
+ }
1830
+ const members = channel.members.filter((id) => id !== agent.id);
1831
+ if (members.length === 0) {
1832
+ gone.push(channel);
1833
+ continue;
1834
+ }
1835
+ const muted = channel.muted?.filter((id) => id !== agent.id);
1836
+ const next = { ...channel, members, muted };
1837
+ if (!muted?.length) {
1838
+ delete next.muted;
1839
+ }
1840
+ channels.push(next);
1841
+ }
1842
+ const kept = {
1843
+ agent,
1844
+ at,
1845
+ channels: channels.filter((channel) => team.channels.some((before) => before.id === channel.id && before.members.includes(agent.id))).map((channel) => channel.id),
1846
+ gone
1847
+ };
1848
+ return {
1849
+ team: { ...team, agents: team.agents.filter((other) => other.id !== agent.id), channels, removed: [...team.removed ?? [], kept] },
1850
+ agent,
1851
+ channels: gone
1852
+ };
1853
+ }
1854
+ RemovedAgentsUtil.remove = remove;
1855
+ function restore(team, ref) {
1856
+ const kept = (team.removed ?? []).find((one) => one.agent.id === ref);
1857
+ if (!kept) {
1858
+ throw new Error(`No removed agent is ${String(ref)}.`);
1859
+ }
1860
+ const agent = { ...kept.agent, name: ChannelsUtil.freeName(team, kept.agent.name) };
1861
+ const channels = team.channels.map((channel) => kept.channels.includes(channel.id) && !channel.members.includes(agent.id) && channel.members.length < MAX_MEMBERS ? { ...channel, members: [...channel.members, agent.id] } : channel);
1862
+ const back = [];
1863
+ for (const channel of kept.gone) {
1864
+ let name = channel.name;
1865
+ for (let count = 2;ChannelsUtil.findChannel({ ...team, channels: [...channels, ...back] }, name); count++) {
1866
+ name = `${channel.name}-${count}`;
1867
+ }
1868
+ back.push({ ...channel, name });
1869
+ }
1870
+ const removed = (team.removed ?? []).filter((one) => one !== kept);
1871
+ const next = { ...team, agents: [...team.agents, agent], channels: [...channels, ...back], removed };
1872
+ if (!removed.length) {
1873
+ delete next.removed;
1874
+ }
1875
+ return { team: next, agent, channels: back };
1876
+ }
1877
+ RemovedAgentsUtil.restore = restore;
1878
+ function forget(team, now) {
1879
+ const since = now - REMOVED_DAYS * 24 * 60 * 60000;
1880
+ const old = (team.removed ?? []).filter((one) => one.at < since);
1881
+ if (!old.length) {
1882
+ return { team, channels: [] };
1883
+ }
1884
+ const removed = (team.removed ?? []).filter((one) => one.at >= since);
1885
+ const next = { ...team, removed };
1886
+ if (!removed.length) {
1887
+ delete next.removed;
1888
+ }
1889
+ return { team: next, channels: old.flatMap((one) => one.gone) };
1890
+ }
1891
+ RemovedAgentsUtil.forget = forget;
1892
+ })(RemovedAgentsUtil ||= {});
1893
+
1795
1894
  // web-src/round-rules.ts
1796
1895
  var ChannelRounds;
1797
1896
  ((ChannelRounds) => {
@@ -2304,6 +2403,51 @@ var TaAppUtil;
2304
2403
  })(TaAppUtil || (TaAppUtil = {}));
2305
2404
  // ../ta-protocol/esm/common/auth-protocol.js
2306
2405
  var TaAuthServer = Symbol("TaAuthServer");
2406
+ // ../ta-protocol/esm/common/call-moves.js
2407
+ var TaCallMoves;
2408
+ (function(TaCallMoves2) {
2409
+ TaCallMoves2.TEXT = 'You can move as asked, as a person on a sofa does: wave, make a heart with your hands, clap, laugh behind your hand, stand up and dance (you turn around once as you dance: it is the move for turning around or spinning) or stand up and stretch. Asked for one of them or one close to it: say in a few words that you do it, naming the move as it is ("给你比个心", "挥挥手", "我站起来跳支舞,转个圈给你看"), one move a reply; they see it as you say it, a dance or a stretch once you finish. Asked for any other move (jumping, walking about, lying down, turning around twice): say plainly that you cannot do it on this call and offer one you can; never say you do a move you do not.';
2410
+ const MOVES = [
2411
+ [
2412
+ "dance",
2413
+ /跳舞|跳个舞|跳支舞|跳一支|跳一段|跳给你看|看我跳|转(?:个|一|两|几|三)?圈|转一转|转个身|转身|旋转|ダンス|踊|回って|\b(?:danc(?:e|ing)|spin(?:ning)?|twirl\w*|turn(?:ing)? around)\b/i
2414
+ ],
2415
+ ["stretch", /伸(?:个|一个|一下)?懒腰|伸展|活动一下|起来走走|ストレッチ|\bstretch\w*\b/i],
2416
+ ["heart", /比(?:个|一个|颗)?(?:爱)?心|笔芯|ハート|\b(?:(?:make|making|made) (?:you )?a heart|heart (?:sign|hands?))\b/i],
2417
+ ["wave", /挥(?:挥|一挥|一下|个)?手|招(?:招|个|一下)?手|摆摆手|手を振|\bwav(?:e|es|ing)\b/i],
2418
+ ["clap", /鼓(?:个|鼓|一下)?掌|拍(?:拍|个|一下)?手|拍掌|拍手|\b(?:clap\w*|applau\w*)\b/i],
2419
+ ["laugh", /笑一个|笑一下|笑一笑|笑给你看|大笑|\blaugh(?:s|ing)?\b/i]
2420
+ ];
2421
+ const STAND = ["stretch", /站起来|站起身|起身|立ち上が|\b(?:stand(?:ing)? up|get(?:ting)? up)\b/i];
2422
+ const NOT = /不会|不能|没法|没办法|做不了|做不到|跳不了|不行|不太方便|不(?=跳|转|比|挥|鼓|拍|伸|站|笑)|できない|無理|\b(?:can'?t|cannot|unable|won'?t|not able|don'?t)\b/i;
2423
+ const CLAUSES = /[,,、;;::]|\bbut\b/i;
2424
+ const STANDING = new Set(["dance", "stretch"]);
2425
+ function named(sentence) {
2426
+ var _a;
2427
+ const clauses = (sentence !== null && sentence !== undefined ? sentence : "").split(CLAUSES).filter((clause) => !NOT.test(clause));
2428
+ return (_a = first(clauses, MOVES)) !== null && _a !== undefined ? _a : first(clauses, [STAND]);
2429
+ }
2430
+ TaCallMoves2.named = named;
2431
+ function first(clauses, moves) {
2432
+ for (const clause of clauses) {
2433
+ let best;
2434
+ for (const [move, test] of moves) {
2435
+ const at = clause.search(test);
2436
+ if (at >= 0 && (!best || at < best.at)) {
2437
+ best = { move, at };
2438
+ }
2439
+ }
2440
+ if (best) {
2441
+ return best.move;
2442
+ }
2443
+ }
2444
+ return;
2445
+ }
2446
+ function standing(move) {
2447
+ return !!move && STANDING.has(move);
2448
+ }
2449
+ TaCallMoves2.standing = standing;
2450
+ })(TaCallMoves || (TaCallMoves = {}));
2307
2451
  // ../ta-protocol/esm/common/call-scene.js
2308
2452
  var TaCallSceneUtil;
2309
2453
  (function(TaCallSceneUtil2) {
@@ -2321,9 +2465,22 @@ var TaCallSceneUtil;
2321
2465
  const view = scene.view ? `, ${VIEWS[scene.view]}` : "";
2322
2466
  const you = "They see you as a lifelike person made by AI, who says your words with face and expressions: they watch you as you talk.";
2323
2467
  const them = !scene.camera ? "Their camera is off: you cannot see them; never act as if you could." : sees ? "Their camera is on: what they say may come with a picture of them now." : "Their camera is on, but no picture of it reaches you: you cannot see them.";
2324
- return `Video call${from}${view}. ${you} ${them}`;
2468
+ return `Video call${from}${view}. ${you} ${TaCallMoves.TEXT}${moves(scene.moves)} ${them}`;
2325
2469
  }
2326
2470
  TaCallSceneUtil2.text = text;
2471
+ function moves(list) {
2472
+ if (!(list === null || list === undefined ? undefined : list.length)) {
2473
+ return "";
2474
+ }
2475
+ const said = (move2) => `${move2.name} (${move2.words.slice(0, 3).map((word) => `"${word}"`).join(", ")})`;
2476
+ const as = list.filter((move2) => !move2.after);
2477
+ const after = list.filter((move2) => move2.after);
2478
+ return [
2479
+ " The user gave you moves of your own too, which you make as you say their words, as below; they count among those you can do.",
2480
+ as.length ? ` As you say it: ${as.map(said).join("; ")}.` : "",
2481
+ after.length ? ` Once you said you will, as you listen: ${after.map(said).join("; ")}; you sit down again as they speak.` : ""
2482
+ ].join("");
2483
+ }
2327
2484
  function minutes(scene, now) {
2328
2485
  return Math.max(0, Math.floor((now - scene.since) / 60000));
2329
2486
  }
@@ -2350,8 +2507,14 @@ var TaCallSceneUtil;
2350
2507
  }
2351
2508
  TaCallSceneUtil2.next = next;
2352
2509
  function key(scene) {
2353
- var _a, _b;
2354
- return [scene.video ? "video" : "voice", scene.camera ? "camera" : "", (_a = scene.view) !== null && _a !== undefined ? _a : "", (_b = scene.device) !== null && _b !== undefined ? _b : ""].join(":");
2510
+ var _a, _b, _c;
2511
+ return [
2512
+ scene.video ? "video" : "voice",
2513
+ scene.camera ? "camera" : "",
2514
+ (_a = scene.view) !== null && _a !== undefined ? _a : "",
2515
+ (_b = scene.device) !== null && _b !== undefined ? _b : "",
2516
+ ((_c = scene.moves) !== null && _c !== undefined ? _c : []).map((move2) => move2.name).join(",")
2517
+ ].join(":");
2355
2518
  }
2356
2519
  TaCallSceneUtil2.key = key;
2357
2520
  function of(value) {
@@ -2361,16 +2524,28 @@ var TaCallSceneUtil;
2361
2524
  }
2362
2525
  const view = typeof scene.view === "string" && Object.keys(VIEWS).includes(scene.view) ? scene.view : undefined;
2363
2526
  const device = scene.device === "phone" || scene.device === "tablet" || scene.device === "computer" ? scene.device : undefined;
2527
+ const moves2 = Array.isArray(scene.moves) ? scene.moves.flatMap((move2) => TaCallSceneUtil2.move(move2)).slice(0, MOVES) : [];
2364
2528
  return {
2365
2529
  video: scene.video,
2366
2530
  ...scene.camera === true ? { camera: true } : {},
2367
2531
  ...view ? { view } : {},
2368
2532
  ...device ? { device } : {},
2369
- since: scene.since
2533
+ since: scene.since,
2534
+ ...scene.video && moves2.length ? { moves: moves2 } : {}
2370
2535
  };
2371
2536
  }
2372
2537
  TaCallSceneUtil2.of = of;
2538
+ function move(value) {
2539
+ const move2 = value;
2540
+ if (!move2 || typeof move2.name !== "string" || !move2.name.trim() || !Array.isArray(move2.words)) {
2541
+ return [];
2542
+ }
2543
+ const words2 = move2.words.filter((word) => typeof word === "string" && !!word.trim()).map((word) => word.slice(0, 24)).slice(0, 3);
2544
+ return words2.length ? [{ name: move2.name.slice(0, 32), ...move2.after === true ? { after: true } : {}, words: words2 }] : [];
2545
+ }
2546
+ TaCallSceneUtil2.move = move;
2373
2547
  })(TaCallSceneUtil || (TaCallSceneUtil = {}));
2548
+ var MOVES = 40;
2374
2549
  // ../ta-protocol/esm/common/confine-protocol.js
2375
2550
  var TA_CONFINED_MARK = "[ta:confined]";
2376
2551
  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+)*)*`;
@@ -3148,7 +3323,10 @@ var TaPermissionUtil;
3148
3323
  function host(manifest, method, kind) {
3149
3324
  var _a, _b, _c, _d;
3150
3325
  const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
3151
- const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
3326
+ const own = (key) => {
3327
+ var _a2;
3328
+ return (_a2 = Object.getOwnPropertyDescriptor(host2, key)) === null || _a2 === undefined ? undefined : _a2.value;
3329
+ };
3152
3330
  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;
3153
3331
  }
3154
3332
  TaPermissionUtil2.host = host;
@@ -3305,6 +3483,120 @@ var TaExcludedFiles;
3305
3483
  TaExcludedFiles2.filter = filter;
3306
3484
  })(TaExcludedFiles || (TaExcludedFiles = {}));
3307
3485
  var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
3486
+ // web-src/agent-usage.ts
3487
+ import { open } from "node:fs/promises";
3488
+ var DAY_MS = 24 * 60 * 60000;
3489
+ var USAGE_DAYS = 30;
3490
+ var TAIL_BYTES = 256 * 1024;
3491
+ var AgentUsageUtil;
3492
+ ((AgentUsageUtil) => {
3493
+ async function read(team, messagesOf, now) {
3494
+ const messages = new Map;
3495
+ for (const channel of team.channels) {
3496
+ messages.set(channel.id, await messagesOf(channel.id));
3497
+ }
3498
+ const sessionTimes = new Map;
3499
+ for (const agent of team.agents) {
3500
+ const at = agent.sessionFile ? await lastAskedIn(agent.sessionFile) : undefined;
3501
+ if (agent.sessionFile && at) {
3502
+ sessionTimes.set(agent.sessionFile, at);
3503
+ }
3504
+ }
3505
+ return usage(team, messages, sessionTimes, now);
3506
+ }
3507
+ AgentUsageUtil.read = read;
3508
+ async function lastAskedIn(file) {
3509
+ const handle = await open(file, "r").catch(() => {
3510
+ return;
3511
+ });
3512
+ if (!handle) {
3513
+ return;
3514
+ }
3515
+ try {
3516
+ const { size } = await handle.stat();
3517
+ const length = Math.min(size, TAIL_BYTES);
3518
+ const buffer = new Uint8Array(length);
3519
+ await handle.read(buffer, 0, length, size - length);
3520
+ return lastAskedAt(new TextDecoder().decode(buffer));
3521
+ } finally {
3522
+ await handle.close();
3523
+ }
3524
+ }
3525
+ function lastAskedAt(lines) {
3526
+ const all = lines.split(`
3527
+ `);
3528
+ for (let index = all.length - 1;index >= 0; index--) {
3529
+ const line = all[index];
3530
+ if (!line.includes('"user"')) {
3531
+ continue;
3532
+ }
3533
+ try {
3534
+ const entry = JSON.parse(line);
3535
+ if (entry.type === "message" && entry.message?.role === "user" && entry.timestamp) {
3536
+ const at = Date.parse(entry.timestamp);
3537
+ if (Number.isFinite(at)) {
3538
+ return at;
3539
+ }
3540
+ }
3541
+ } catch {}
3542
+ }
3543
+ return;
3544
+ }
3545
+ AgentUsageUtil.lastAskedAt = lastAskedAt;
3546
+ function usage(team, messages, sessionTimes, now) {
3547
+ const since = now - USAGE_DAYS * DAY_MS;
3548
+ const named = new Map;
3549
+ const answers = new Map;
3550
+ const answeredAt = new Map;
3551
+ for (const list of messages.values()) {
3552
+ for (const message of list) {
3553
+ if (message.at < since || message.notice) {
3554
+ continue;
3555
+ }
3556
+ for (const id of ChannelsText.mentions(message.text, team.agents)) {
3557
+ if (id !== message.author) {
3558
+ named.set(id, (named.get(id) ?? 0) + 1);
3559
+ }
3560
+ }
3561
+ if (!message.failed && team.agents.some((agent) => agent.id === message.author)) {
3562
+ answers.set(message.author, (answers.get(message.author) ?? 0) + 1);
3563
+ }
3564
+ }
3565
+ for (const message of list) {
3566
+ if (!message.failed && message.at > (answeredAt.get(message.author) ?? 0)) {
3567
+ answeredAt.set(message.author, message.at);
3568
+ }
3569
+ }
3570
+ }
3571
+ return team.agents.map((agent) => {
3572
+ const channels = team.channels.filter((channel) => channel.members.includes(agent.id)).map((channel) => {
3573
+ const list = messages.get(channel.id) ?? [];
3574
+ const last2 = list.reduce((at, message) => Math.max(at, message.at), 0);
3575
+ return {
3576
+ id: channel.id,
3577
+ name: channel.name,
3578
+ messages: list.filter((message) => message.at >= since).length,
3579
+ ...last2 ? { lastAt: last2 } : {}
3580
+ };
3581
+ });
3582
+ const session = agent.sessionFile ? sessionTimes.get(agent.sessionFile) : undefined;
3583
+ const last = Math.max(session ?? 0, answeredAt.get(agent.id) ?? 0);
3584
+ return {
3585
+ id: agent.id,
3586
+ name: agent.name,
3587
+ role: agent.role,
3588
+ ...agent.temporary ? { temporary: true } : {},
3589
+ createdAt: agent.createdAt,
3590
+ ...last ? { lastUsedAt: last } : {},
3591
+ named: named.get(agent.id) ?? 0,
3592
+ answers: answers.get(agent.id) ?? 0,
3593
+ channels
3594
+ };
3595
+ });
3596
+ }
3597
+ AgentUsageUtil.usage = usage;
3598
+ })(AgentUsageUtil ||= {});
3599
+
3308
3600
  // web-src/channel-pictures.ts
3309
3601
  import { randomBytes } from "node:crypto";
3310
3602
  import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
@@ -3432,7 +3724,8 @@ var TeamViewUtil;
3432
3724
  }
3433
3725
  return manages ? channel : channelAs(channel);
3434
3726
  });
3435
- return { ...value, agents, channels, may };
3727
+ const { removed: _removed, ...rest } = value;
3728
+ return { ...rest, agents, channels, may };
3436
3729
  }
3437
3730
  TeamViewUtil.team = team;
3438
3731
  function agentAs(agent, edits, own) {
@@ -3570,9 +3863,9 @@ class TeamStore {
3570
3863
  }
3571
3864
  async openSession(agent) {
3572
3865
  if (agent.sessionFile) {
3573
- const open = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
3574
- if (open) {
3575
- return open.sessionId;
3866
+ const open2 = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
3867
+ if (open2) {
3868
+ return open2.sessionId;
3576
3869
  }
3577
3870
  }
3578
3871
  const cwd = agent.cwd ?? (await this.host.getServerInfo()).cwd;
@@ -3595,10 +3888,10 @@ class TeamStore {
3595
3888
  return sessionId;
3596
3889
  }
3597
3890
  async switchModel(agent) {
3598
- const open = agent.model && agent.sessionFile && (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
3599
- if (open && agent.model && open.model !== agent.model) {
3891
+ const open2 = agent.model && agent.sessionFile && (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
3892
+ if (open2 && agent.model && open2.model !== agent.model) {
3600
3893
  const slash = agent.model.indexOf("/");
3601
- await this.host.setModel(open.sessionId, agent.model.slice(0, slash), agent.model.slice(slash + 1));
3894
+ await this.host.setModel(open2.sessionId, agent.model.slice(0, slash), agent.model.slice(slash + 1));
3602
3895
  }
3603
3896
  }
3604
3897
  async settled(sessionId, before, poll) {
@@ -3756,6 +4049,30 @@ class TeamStore {
3756
4049
  set(key, value) {
3757
4050
  return this.host.setExtensionData(NAME, key, value);
3758
4051
  }
4052
+ listAgents() {
4053
+ const faces = ChannelsUtil.faces(this.team.agents);
4054
+ return this.team.agents.map((agent) => ({
4055
+ id: agent.id,
4056
+ name: agent.name,
4057
+ role: agent.role,
4058
+ mark: agent.mark,
4059
+ face: faces.get(agent.id) ?? 0,
4060
+ ...agent.cwd ? { cwd: agent.cwd } : {},
4061
+ ...agent.model ? { model: agent.model } : {},
4062
+ ...agent.temporary ? { temporary: true } : {}
4063
+ }));
4064
+ }
4065
+ listChannels() {
4066
+ return this.team.channels.map((channel) => ({
4067
+ id: channel.id,
4068
+ name: channel.name,
4069
+ ...channel.topic ? { topic: channel.topic } : {},
4070
+ members: channel.members
4071
+ }));
4072
+ }
4073
+ async agentUsage(now = Date.now()) {
4074
+ return AgentUsageUtil.read(this.team, (id) => this.messagesOf(id), now);
4075
+ }
3759
4076
  }
3760
4077
 
3761
4078
  // web-src/team-answers.ts
@@ -3965,9 +4282,9 @@ class TeamService extends TeamAnswers {
3965
4282
  }
3966
4283
  await this.saveTeam(team);
3967
4284
  if (agent.name !== before.name && agent.sessionFile) {
3968
- const open = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
3969
- if (open) {
3970
- await this.host.setSessionName(open.sessionId, agent.name).catch(() => {
4285
+ const open2 = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
4286
+ if (open2) {
4287
+ await this.host.setSessionName(open2.sessionId, agent.name).catch(() => {
3971
4288
  return;
3972
4289
  });
3973
4290
  }
@@ -4016,9 +4333,15 @@ class TeamService extends TeamAnswers {
4016
4333
  return { agent, sessionId };
4017
4334
  }
4018
4335
  async deleteAgent(ref) {
4019
- const { team, agent, channels } = ChannelsUtil.removeAgent(this.team, ref);
4336
+ const now = Date.now();
4337
+ const removed = RemovedAgentsUtil.remove(this.team, ref, now);
4338
+ const { team, channels: old } = RemovedAgentsUtil.forget(removed.team, now);
4339
+ const { agent, channels } = removed;
4020
4340
  await this.saveTeam(team);
4021
4341
  for (const channel of channels) {
4342
+ await this.forget(channel, true);
4343
+ }
4344
+ for (const channel of old) {
4022
4345
  await this.forget(channel);
4023
4346
  }
4024
4347
  this.queue = { ...this.queue, jobs: this.queue.jobs.filter((job) => job.agentId !== agent.id) };
@@ -4028,11 +4351,18 @@ class TeamService extends TeamAnswers {
4028
4351
  }
4029
4352
  return agent;
4030
4353
  }
4031
- async forget(channel) {
4032
- await this.pictures.forget(channel.id);
4354
+ async restoreAgent(ref) {
4355
+ const { team, agent } = RemovedAgentsUtil.restore(this.team, ref);
4356
+ await this.saveTeam(team);
4357
+ return agent;
4358
+ }
4359
+ async forget(channel, keep = false) {
4033
4360
  this.messages.delete(channel.id);
4034
4361
  this.reading.delete(channel.id);
4035
- await this.set(Keys.messages(channel.id), null);
4362
+ if (!keep) {
4363
+ await this.pictures.forget(channel.id);
4364
+ await this.set(Keys.messages(channel.id), null);
4365
+ }
4036
4366
  const { [channel.id]: _gone, ...working } = this.working;
4037
4367
  this.working = working;
4038
4368
  await this.set(Keys.WORKING, working);
@@ -4093,19 +4423,6 @@ class TeamService extends TeamAnswers {
4093
4423
  await this.focus(channel.id);
4094
4424
  return { kind: "channel", id: channel.id, name: channel.name };
4095
4425
  }
4096
- listAgents() {
4097
- const faces = ChannelsUtil.faces(this.team.agents);
4098
- return this.team.agents.map((agent) => ({
4099
- id: agent.id,
4100
- name: agent.name,
4101
- role: agent.role,
4102
- mark: agent.mark,
4103
- face: faces.get(agent.id) ?? 0,
4104
- ...agent.cwd ? { cwd: agent.cwd } : {},
4105
- ...agent.model ? { model: agent.model } : {},
4106
- ...agent.temporary ? { temporary: true } : {}
4107
- }));
4108
- }
4109
4426
  async request(request) {
4110
4427
  if (this.disposed) {
4111
4428
  throw new Error("The team has stopped; the extension may have been turned off.");
@@ -4131,6 +4448,8 @@ class TeamService extends TeamAnswers {
4131
4448
  return this.setChannelModel(request);
4132
4449
  case "deleteAgent":
4133
4450
  return this.deleteAgent(request.agent);
4451
+ case "restoreAgent":
4452
+ return this.restoreAgent(request.agent);
4134
4453
  case "post":
4135
4454
  return (await this.post(String(request.channel ?? ""), USER, String(request.text ?? ""), await this.posterOf(request))).message;
4136
4455
  case "picture":
@@ -4323,14 +4642,6 @@ class TeamService extends TeamAnswers {
4323
4642
  resolve(waiting.replies);
4324
4643
  }
4325
4644
  }
4326
- listChannels() {
4327
- return this.team.channels.map((channel) => ({
4328
- id: channel.id,
4329
- name: channel.name,
4330
- ...channel.topic ? { topic: channel.topic } : {},
4331
- members: channel.members
4332
- }));
4333
- }
4334
4645
  }
4335
4646
 
4336
4647
  // web-src/host.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-channels",
3
- "version": "4.28.0",
3
+ "version": "4.29.0",
4
4
  "description": "A pi package for Ta: agents with roles of their own and channels where the user, Ta and the agents talk; Ta builds the team for what the user wants",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -27,9 +27,9 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.28.0",
31
- "@celljs/ta-relay": "4.28.0",
32
- "@celljs/ta-web": "4.28.0",
30
+ "@celljs/ta-protocol": "4.29.0",
31
+ "@celljs/ta-relay": "4.29.0",
32
+ "@celljs/ta-web": "4.29.0",
33
33
  "@types/react": "^19.3.0"
34
34
  },
35
35
  "publishConfig": {
package/web/index.js CHANGED
@@ -234,6 +234,40 @@ var TaAgentSummary;
234
234
  }
235
235
  TaAgentSummary2.strip = strip;
236
236
  })(TaAgentSummary || (TaAgentSummary = {}));
237
+ var TaPictureNote;
238
+ (function(TaPictureNote2) {
239
+ TaPictureNote2.OPEN = "<pictures>";
240
+ TaPictureNote2.CLOSE = "</pictures>";
241
+ const BLOCK = /[ \t]*<pictures>([\s\S]*?)(?:<\/pictures>|$)|<p(?:i(?:c(?:t(?:u(?:r(?:es?)?)?)?)?)?)?$/gi;
242
+ const ROW = /(?:^|\s)[-*]?\s*p(\d+)\s*[::]\s*/gi;
243
+ function take(text) {
244
+ const told = new Map;
245
+ if (!/<p/i.test(text)) {
246
+ return { said: text, told };
247
+ }
248
+ const said = text.replace(BLOCK, (_all, body) => {
249
+ const rows = [...(body !== null && body !== undefined ? body : "").matchAll(ROW)];
250
+ rows.forEach((row, index) => {
251
+ var _a;
252
+ var _b, _c;
253
+ const end = (_b = (_a = rows[index + 1]) === null || _a === undefined ? undefined : _a.index) !== null && _b !== undefined ? _b : body === null || body === undefined ? undefined : body.length;
254
+ const what = body === null || body === undefined ? undefined : body.slice(((_c = row.index) !== null && _c !== undefined ? _c : 0) + row[0].length, end).trim();
255
+ if (what) {
256
+ told.set(Number(row[1]), what);
257
+ }
258
+ });
259
+ return "";
260
+ });
261
+ return { said: said === text ? text : said.replace(/\n{3,}/g, `
262
+
263
+ `).trim(), told };
264
+ }
265
+ TaPictureNote2.take = take;
266
+ function strip(text) {
267
+ return take(text).said;
268
+ }
269
+ TaPictureNote2.strip = strip;
270
+ })(TaPictureNote || (TaPictureNote = {}));
237
271
  var TaSkillUse;
238
272
  (function(TaSkillUse2) {
239
273
  const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
@@ -1180,33 +1214,6 @@ var ChannelsUtil;
1180
1214
  return { team: next, channel, agents };
1181
1215
  }
1182
1216
  ChannelsUtil.setChannelModel = setChannelModel;
1183
- function removeAgent(team, ref) {
1184
- const agent = findAgent(team, typeof ref === "string" ? ref : "");
1185
- if (!agent) {
1186
- throw new Error(`No agent is ${String(ref)}.`);
1187
- }
1188
- const gone = [];
1189
- const channels = [];
1190
- for (const channel of team.channels) {
1191
- if (!channel.members.includes(agent.id)) {
1192
- channels.push(channel);
1193
- continue;
1194
- }
1195
- const members = channel.members.filter((id) => id !== agent.id);
1196
- if (members.length === 0) {
1197
- gone.push(channel);
1198
- continue;
1199
- }
1200
- const muted = channel.muted?.filter((id) => id !== agent.id);
1201
- const next = { ...channel, members, muted };
1202
- if (!muted?.length) {
1203
- delete next.muted;
1204
- }
1205
- channels.push(next);
1206
- }
1207
- return { team: { agents: team.agents.filter((other) => other.id !== agent.id), channels }, agent, channels: gone };
1208
- }
1209
- ChannelsUtil.removeAgent = removeAgent;
1210
1217
  function agentIds(team, refs) {
1211
1218
  const ids = [];
1212
1219
  for (const ref of Array.isArray(refs) ? refs.filter((item) => typeof item === "string") : []) {
@@ -2934,7 +2941,8 @@ var TaSaid;
2934
2941
  ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
2935
2942
  ["skill", /<skill name="|<\/skill>/],
2936
2943
  ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
2937
- ["summary", /<\/?(?:conversation_history_summary|summary)>/]
2944
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/],
2945
+ ["pictures described", /<\/?pictures>/]
2938
2946
  ];
2939
2947
  function text(content, joiner = `
2940
2948
  `) {
@@ -2945,7 +2953,7 @@ var TaSaid;
2945
2953
  }
2946
2954
  TaSaid2.text = text;
2947
2955
  function words(role, text2, options = {}) {
2948
- const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
2956
+ const said = role === "user" ? userWords(text2) : TaPictureNote.strip(TaAgentSummary.strip(text2));
2949
2957
  return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
2950
2958
  }
2951
2959
  TaSaid2.words = words;
@@ -3064,6 +3072,17 @@ Switched to voice.`, said: "Switched to voice." },
3064
3072
  { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
3065
3073
  { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
3066
3074
  { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
3075
+ {
3076
+ mark: "pictures described after the answer",
3077
+ role: "assistant",
3078
+ text: `The left one.
3079
+
3080
+ <pictures> p1: two cats on a sofa. p2: a chart of sales, "Q4". </pictures>`,
3081
+ said: "The left one."
3082
+ },
3083
+ { mark: "pictures described as it streams", role: "assistant", text: `The left one.
3084
+ <pictures>
3085
+ p1: two ca`, said: "The left one." },
3067
3086
  { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
3068
3087
  </system-reminder>
3069
3088
  Ready.`, said: "Ready." }
@@ -3850,7 +3869,7 @@ function AgentInfoView({ context }) {
3850
3869
  const act = (action2) => AgentActions.run(context, action2);
3851
3870
  const rename = act(async () => {
3852
3871
  const name = await pi.ui.input(w.rename, w.name, { value: agent.name });
3853
- if (name !== undefined && name.trim() && name.trim() !== agent.name) {
3872
+ if (name?.trim() && name.trim() !== agent.name) {
3854
3873
  await service.updateAgent(agent.id, { name });
3855
3874
  }
3856
3875
  });
@@ -4175,6 +4194,11 @@ class ChannelsClient {
4175
4194
  await this.load(true);
4176
4195
  return channel;
4177
4196
  }
4197
+ async restoreAgent(agentId) {
4198
+ const agent = await this.send({ kind: "restoreAgent", agent: agentId });
4199
+ await this.load(true);
4200
+ return agent;
4201
+ }
4178
4202
  async deleteAgent(agentId) {
4179
4203
  await this.deleting(agentId, async () => {
4180
4204
  await this.send({ kind: "deleteAgent", agent: agentId });
@@ -5060,7 +5084,10 @@ var TaPermissionUtil;
5060
5084
  function host(manifest, method, kind) {
5061
5085
  var _a, _b, _c, _d;
5062
5086
  const host2 = (_a = manifest === null || manifest === undefined ? undefined : manifest.host) !== null && _a !== undefined ? _a : {};
5063
- const own = (key) => Object.prototype.hasOwnProperty.call(host2, key) ? host2[key] : undefined;
5087
+ const own = (key) => {
5088
+ var _a2;
5089
+ return (_a2 = Object.getOwnPropertyDescriptor(host2, key)) === null || _a2 === undefined ? undefined : _a2.value;
5090
+ };
5064
5091
  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;
5065
5092
  }
5066
5093
  TaPermissionUtil2.host = host;
@@ -5331,7 +5358,29 @@ var RoomUtil;
5331
5358
  });
5332
5359
  }
5333
5360
  RoomUtil.rows = rows;
5361
+ function choice(agent, text) {
5362
+ return `@${agent.name} ${text}`;
5363
+ }
5364
+ RoomUtil.choice = choice;
5365
+ function answer(messages, message, agent) {
5366
+ const said = messages.slice(messages.indexOf(message) + 1).find((later) => later.author === USER && !later.notice);
5367
+ if (!said) {
5368
+ return;
5369
+ }
5370
+ const named = `@${agent.name} `;
5371
+ return said.text.startsWith(named) ? said.text.slice(named.length) : said.text;
5372
+ }
5373
+ RoomUtil.answer = answer;
5334
5374
  })(RoomUtil ||= {});
5375
+ function AgentText({ context, channelId, agent, text, answer }) {
5376
+ const { pi, service } = context;
5377
+ const send = React.useCallback((said) => service.post(channelId, RoomUtil.choice(agent, said)), [service, channelId, agent.name]);
5378
+ return /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
5379
+ text,
5380
+ send,
5381
+ answer
5382
+ });
5383
+ }
5335
5384
  function MessagePictures({ context, channelId, message, alt }) {
5336
5385
  const { pi, service } = context;
5337
5386
  const images = message.images ?? [];
@@ -5660,7 +5709,13 @@ function ChannelRoom({ context, channelId: fixed }) {
5660
5709
  className: "tac-msg-failed"
5661
5710
  }, w.failed), message.overBudget && /* @__PURE__ */ React.createElement("div", {
5662
5711
  className: "tac-msg-over"
5663
- }, w.overBudget), /* @__PURE__ */ React.createElement(Markdown, {
5712
+ }, w.overBudget), agentOf(message.author) ? /* @__PURE__ */ React.createElement(AgentText, {
5713
+ context,
5714
+ channelId: channel.id,
5715
+ agent: agentOf(message.author),
5716
+ text: ChannelsText.markMentions(message.text, state.team.agents),
5717
+ answer: RoomUtil.answer(messages, message, agentOf(message.author))
5718
+ }) : /* @__PURE__ */ React.createElement(Markdown, {
5664
5719
  text: ChannelsText.markMentions(message.text, state.team.agents)
5665
5720
  })))))), working.length > 0 && /* @__PURE__ */ React.createElement("div", {
5666
5721
  className: "tac-live",