@celljs/ta-channels 4.28.0 → 4.30.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,121 @@ 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/boundary-protocol.js
2407
+ var TA_BOUNDARY_KINDS = ["general", "work", "private", "guest"];
2408
+ var TA_GENERAL_BOUNDARY = Object.freeze({ kind: "general" });
2409
+ var TaBoundaryUtil;
2410
+ (function(TaBoundaryUtil2) {
2411
+ async function of(host, location) {
2412
+ if (!host.boundaries || !location) {
2413
+ return TA_GENERAL_BOUNDARY;
2414
+ }
2415
+ try {
2416
+ return await host.boundaries.of(location);
2417
+ } catch (_a) {
2418
+ return TA_GENERAL_BOUNDARY;
2419
+ }
2420
+ }
2421
+ TaBoundaryUtil2.of = of;
2422
+ async function ofAll(host, locations) {
2423
+ const found = new Map;
2424
+ for (const location of new Set(locations)) {
2425
+ found.set(location, await of(host, location));
2426
+ }
2427
+ return found;
2428
+ }
2429
+ TaBoundaryUtil2.ofAll = ofAll;
2430
+ function key(boundary) {
2431
+ var _a;
2432
+ return boundary.kind === "general" ? "general" : `${boundary.kind}:${(_a = boundary.root) !== null && _a !== undefined ? _a : ""}`;
2433
+ }
2434
+ TaBoundaryUtil2.key = key;
2435
+ function canSee(from, of2) {
2436
+ if (from.kind === "guest" || of2.kind === "guest") {
2437
+ return false;
2438
+ }
2439
+ if (of2.kind === "general") {
2440
+ return from.kind !== "private";
2441
+ }
2442
+ return key(from) === key(of2);
2443
+ }
2444
+ TaBoundaryUtil2.canSee = canSee;
2445
+ function profile(boundary, general, notes) {
2446
+ const own = (notes === null || notes === undefined ? undefined : notes.trim()) || undefined;
2447
+ const all = (general === null || general === undefined ? undefined : general.trim()) || undefined;
2448
+ switch (boundary.kind) {
2449
+ case "general":
2450
+ return all ? { general: all } : {};
2451
+ case "work":
2452
+ return { ...all ? { general: all } : {}, ...own ? { notes: own } : {} };
2453
+ case "private":
2454
+ return own ? { notes: own } : {};
2455
+ default:
2456
+ return {};
2457
+ }
2458
+ }
2459
+ TaBoundaryUtil2.profile = profile;
2460
+ function valid(value) {
2461
+ const boundary = value;
2462
+ if (!boundary || typeof boundary !== "object" || !TA_BOUNDARY_KINDS.includes(boundary.kind)) {
2463
+ return TA_GENERAL_BOUNDARY;
2464
+ }
2465
+ if (boundary.kind === "general") {
2466
+ return TA_GENERAL_BOUNDARY;
2467
+ }
2468
+ return {
2469
+ kind: boundary.kind,
2470
+ ...typeof boundary.root === "string" && boundary.root ? { root: boundary.root } : {},
2471
+ ...typeof boundary.name === "string" && boundary.name.trim() ? { name: boundary.name.trim() } : {}
2472
+ };
2473
+ }
2474
+ TaBoundaryUtil2.valid = valid;
2475
+ })(TaBoundaryUtil || (TaBoundaryUtil = {}));
2476
+ // ../ta-protocol/esm/common/call-moves.js
2477
+ var TaCallMoves;
2478
+ (function(TaCallMoves2) {
2479
+ 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.';
2480
+ const MOVES = [
2481
+ [
2482
+ "dance",
2483
+ /跳舞|跳个舞|跳支舞|跳一支|跳一段|跳给你看|看我跳|转(?:个|一|两|几|三)?圈|转一转|转个身|转身|旋转|ダンス|踊|回って|\b(?:danc(?:e|ing)|spin(?:ning)?|twirl\w*|turn(?:ing)? around)\b/i
2484
+ ],
2485
+ ["stretch", /伸(?:个|一个|一下)?懒腰|伸展|活动一下|起来走走|ストレッチ|\bstretch\w*\b/i],
2486
+ ["heart", /比(?:个|一个|颗)?(?:爱)?心|笔芯|ハート|\b(?:(?:make|making|made) (?:you )?a heart|heart (?:sign|hands?))\b/i],
2487
+ ["wave", /挥(?:挥|一挥|一下|个)?手|招(?:招|个|一下)?手|摆摆手|手を振|\bwav(?:e|es|ing)\b/i],
2488
+ ["clap", /鼓(?:个|鼓|一下)?掌|拍(?:拍|个|一下)?手|拍掌|拍手|\b(?:clap\w*|applau\w*)\b/i],
2489
+ ["laugh", /笑一个|笑一下|笑一笑|笑给你看|大笑|\blaugh(?:s|ing)?\b/i]
2490
+ ];
2491
+ const STAND = ["stretch", /站起来|站起身|起身|立ち上が|\b(?:stand(?:ing)? up|get(?:ting)? up)\b/i];
2492
+ const NOT = /不会|不能|没法|没办法|做不了|做不到|跳不了|不行|不太方便|不(?=跳|转|比|挥|鼓|拍|伸|站|笑)|できない|無理|\b(?:can'?t|cannot|unable|won'?t|not able|don'?t)\b/i;
2493
+ const CLAUSES = /[,,、;;::]|\bbut\b/i;
2494
+ const STANDING = new Set(["dance", "stretch"]);
2495
+ function named(sentence) {
2496
+ var _a;
2497
+ const clauses = (sentence !== null && sentence !== undefined ? sentence : "").split(CLAUSES).filter((clause) => !NOT.test(clause));
2498
+ return (_a = first(clauses, MOVES)) !== null && _a !== undefined ? _a : first(clauses, [STAND]);
2499
+ }
2500
+ TaCallMoves2.named = named;
2501
+ function first(clauses, moves) {
2502
+ for (const clause of clauses) {
2503
+ let best;
2504
+ for (const [move, test] of moves) {
2505
+ const at = clause.search(test);
2506
+ if (at >= 0 && (!best || at < best.at)) {
2507
+ best = { move, at };
2508
+ }
2509
+ }
2510
+ if (best) {
2511
+ return best.move;
2512
+ }
2513
+ }
2514
+ return;
2515
+ }
2516
+ function standing(move) {
2517
+ return !!move && STANDING.has(move);
2518
+ }
2519
+ TaCallMoves2.standing = standing;
2520
+ })(TaCallMoves || (TaCallMoves = {}));
2307
2521
  // ../ta-protocol/esm/common/call-scene.js
2308
2522
  var TaCallSceneUtil;
2309
2523
  (function(TaCallSceneUtil2) {
@@ -2321,9 +2535,22 @@ var TaCallSceneUtil;
2321
2535
  const view = scene.view ? `, ${VIEWS[scene.view]}` : "";
2322
2536
  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
2537
  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}`;
2538
+ return `Video call${from}${view}. ${you} ${TaCallMoves.TEXT}${moves(scene.moves)} ${them}`;
2325
2539
  }
2326
2540
  TaCallSceneUtil2.text = text;
2541
+ function moves(list) {
2542
+ if (!(list === null || list === undefined ? undefined : list.length)) {
2543
+ return "";
2544
+ }
2545
+ const said = (move2) => `${move2.name} (${move2.words.slice(0, 3).map((word) => `"${word}"`).join(", ")})`;
2546
+ const as = list.filter((move2) => !move2.after);
2547
+ const after = list.filter((move2) => move2.after);
2548
+ return [
2549
+ " 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.",
2550
+ as.length ? ` As you say it: ${as.map(said).join("; ")}.` : "",
2551
+ after.length ? ` Once you said you will, as you listen: ${after.map(said).join("; ")}; you sit down again as they speak.` : ""
2552
+ ].join("");
2553
+ }
2327
2554
  function minutes(scene, now) {
2328
2555
  return Math.max(0, Math.floor((now - scene.since) / 60000));
2329
2556
  }
@@ -2350,8 +2577,14 @@ var TaCallSceneUtil;
2350
2577
  }
2351
2578
  TaCallSceneUtil2.next = next;
2352
2579
  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(":");
2580
+ var _a, _b, _c;
2581
+ return [
2582
+ scene.video ? "video" : "voice",
2583
+ scene.camera ? "camera" : "",
2584
+ (_a = scene.view) !== null && _a !== undefined ? _a : "",
2585
+ (_b = scene.device) !== null && _b !== undefined ? _b : "",
2586
+ ((_c = scene.moves) !== null && _c !== undefined ? _c : []).map((move2) => move2.name).join(",")
2587
+ ].join(":");
2355
2588
  }
2356
2589
  TaCallSceneUtil2.key = key;
2357
2590
  function of(value) {
@@ -2361,16 +2594,28 @@ var TaCallSceneUtil;
2361
2594
  }
2362
2595
  const view = typeof scene.view === "string" && Object.keys(VIEWS).includes(scene.view) ? scene.view : undefined;
2363
2596
  const device = scene.device === "phone" || scene.device === "tablet" || scene.device === "computer" ? scene.device : undefined;
2597
+ const moves2 = Array.isArray(scene.moves) ? scene.moves.flatMap((move2) => TaCallSceneUtil2.move(move2)).slice(0, MOVES) : [];
2364
2598
  return {
2365
2599
  video: scene.video,
2366
2600
  ...scene.camera === true ? { camera: true } : {},
2367
2601
  ...view ? { view } : {},
2368
2602
  ...device ? { device } : {},
2369
- since: scene.since
2603
+ since: scene.since,
2604
+ ...scene.video && moves2.length ? { moves: moves2 } : {}
2370
2605
  };
2371
2606
  }
2372
2607
  TaCallSceneUtil2.of = of;
2608
+ function move(value) {
2609
+ const move2 = value;
2610
+ if (!move2 || typeof move2.name !== "string" || !move2.name.trim() || !Array.isArray(move2.words)) {
2611
+ return [];
2612
+ }
2613
+ const words2 = move2.words.filter((word) => typeof word === "string" && !!word.trim()).map((word) => word.slice(0, 24)).slice(0, 3);
2614
+ return words2.length ? [{ name: move2.name.slice(0, 32), ...move2.after === true ? { after: true } : {}, words: words2 }] : [];
2615
+ }
2616
+ TaCallSceneUtil2.move = move;
2373
2617
  })(TaCallSceneUtil || (TaCallSceneUtil = {}));
2618
+ var MOVES = 40;
2374
2619
  // ../ta-protocol/esm/common/confine-protocol.js
2375
2620
  var TA_CONFINED_MARK = "[ta:confined]";
2376
2621
  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+)*)*`;
@@ -2840,6 +3085,167 @@ var TaLocation;
2840
3085
  return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
2841
3086
  }
2842
3087
  })(TaLocation || (TaLocation = {}));
3088
+ // ../ta-protocol/esm/common/metrics-protocol.js
3089
+ var TA_METRICS_BOUNDS = [10, 50, 200, 1000, 5000, 30000];
3090
+ var NOT_RUNS = new Set(["turn", "section", "tooldef"]);
3091
+ var TaMetricsUtil;
3092
+ (function(TaMetricsUtil2) {
3093
+ TaMetricsUtil2.DAY = /^\d{4}-\d{2}-\d{2}$/;
3094
+ TaMetricsUtil2.KEEP_DAYS = 90;
3095
+ TaMetricsUtil2.MAX_DAYS = 365;
3096
+ TaMetricsUtil2.MAX_MB = 20;
3097
+ function limits(ta) {
3098
+ const set = ta && typeof ta === "object" ? ta : {};
3099
+ const days = Number(set.metricsKeepDays);
3100
+ const mb = Number(set.metricsMaxMB);
3101
+ return {
3102
+ keepDays: Number.isFinite(days) && days >= 1 ? Math.min(TaMetricsUtil2.MAX_DAYS, Math.floor(days)) : TaMetricsUtil2.KEEP_DAYS,
3103
+ maxBytes: Math.round((Number.isFinite(mb) && mb > 0 ? Math.min(1024, Math.max(1, mb)) : TaMetricsUtil2.MAX_MB) * 1024 * 1024)
3104
+ };
3105
+ }
3106
+ TaMetricsUtil2.limits = limits;
3107
+ function toRemove(days, limits2, today, otherBytes = 0) {
3108
+ const { since } = span({ days: limits2.keepDays, until: today });
3109
+ const sorted = [...days].sort((a, b) => a.day.localeCompare(b.day));
3110
+ const out = [];
3111
+ let total = otherBytes + sorted.reduce((sum, one) => sum + one.bytes, 0);
3112
+ for (const one of sorted) {
3113
+ if (one.day === today) {
3114
+ break;
3115
+ }
3116
+ if (one.day < since || total > limits2.maxBytes) {
3117
+ out.push(one.day);
3118
+ total -= one.bytes;
3119
+ }
3120
+ }
3121
+ return out;
3122
+ }
3123
+ TaMetricsUtil2.toRemove = toRemove;
3124
+ function bucket(ms) {
3125
+ const bounds = TA_METRICS_BOUNDS;
3126
+ let i = 0;
3127
+ while (i < bounds.length && ms >= bounds[i]) {
3128
+ i++;
3129
+ }
3130
+ return i;
3131
+ }
3132
+ TaMetricsUtil2.bucket = bucket;
3133
+ function quantile(buckets, q) {
3134
+ var _a;
3135
+ const total = (_a = buckets === null || buckets === undefined ? undefined : buckets.reduce((sum, n) => sum + n, 0)) !== null && _a !== undefined ? _a : 0;
3136
+ if (!buckets || total === 0) {
3137
+ return;
3138
+ }
3139
+ const bounds = TA_METRICS_BOUNDS;
3140
+ const rank = q * total;
3141
+ let seen = 0;
3142
+ for (let i = 0;i < buckets.length; i++) {
3143
+ const n = buckets[i];
3144
+ if (n > 0 && seen + n >= rank) {
3145
+ if (i >= bounds.length) {
3146
+ return bounds[bounds.length - 1];
3147
+ }
3148
+ const low = i === 0 ? 0 : bounds[i - 1];
3149
+ return Math.round(low + (bounds[i] - low) * ((rank - seen) / n));
3150
+ }
3151
+ seen += n;
3152
+ }
3153
+ return bounds[bounds.length - 1];
3154
+ }
3155
+ TaMetricsUtil2.quantile = quantile;
3156
+ function add(into, stat) {
3157
+ var _a, _b, _c, _d;
3158
+ into.n += stat.n || 0;
3159
+ if (stat.err) {
3160
+ into.err = ((_a = into.err) !== null && _a !== undefined ? _a : 0) + stat.err;
3161
+ }
3162
+ if (stat.abort) {
3163
+ into.abort = ((_b = into.abort) !== null && _b !== undefined ? _b : 0) + stat.abort;
3164
+ }
3165
+ if (stat.ms) {
3166
+ (_c = into.ms) !== null && _c !== undefined || (into.ms = new Array(TA_METRICS_BOUNDS.length + 1).fill(0));
3167
+ const ms = into.ms;
3168
+ stat.ms.forEach((n, i) => {
3169
+ if (i < ms.length) {
3170
+ ms[i] += n || 0;
3171
+ }
3172
+ });
3173
+ }
3174
+ if (stat.chars !== undefined) {
3175
+ into.chars = Math.max((_d = into.chars) !== null && _d !== undefined ? _d : 0, stat.chars);
3176
+ }
3177
+ return into;
3178
+ }
3179
+ TaMetricsUtil2.add = add;
3180
+ function day(at) {
3181
+ const date = new Date(at);
3182
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
3183
+ }
3184
+ TaMetricsUtil2.day = day;
3185
+ function span(query = {}, now = Date.now()) {
3186
+ const until = typeof query.until === "string" && TaMetricsUtil2.DAY.test(query.until) ? query.until : day(now);
3187
+ if (typeof query.since === "string" && TaMetricsUtil2.DAY.test(query.since)) {
3188
+ return { since: query.since, until };
3189
+ }
3190
+ const days = Math.min(TaMetricsUtil2.MAX_DAYS, Math.max(1, Math.floor(Number(query.days) || 7)));
3191
+ const last = new Date(`${until}T12:00:00`);
3192
+ last.setDate(last.getDate() - (days - 1));
3193
+ return { since: day(last.getTime()), until };
3194
+ }
3195
+ TaMetricsUtil2.span = span;
3196
+ function report(days, since, until, packages) {
3197
+ var _a, _b;
3198
+ const only = (packages === null || packages === undefined ? undefined : packages.length) ? new Set(packages) : undefined;
3199
+ const merged = new Map;
3200
+ for (const one of days) {
3201
+ for (const [name, pkg] of Object.entries((_a = one.packages) !== null && _a !== undefined ? _a : {})) {
3202
+ if (only && !only.has(name)) {
3203
+ continue;
3204
+ }
3205
+ let items = merged.get(name);
3206
+ if (!items) {
3207
+ items = new Map;
3208
+ merged.set(name, items);
3209
+ }
3210
+ for (const [item, stat] of Object.entries((_b = pkg === null || pkg === undefined ? undefined : pkg.items) !== null && _b !== undefined ? _b : {})) {
3211
+ let into = items.get(item);
3212
+ if (!into) {
3213
+ into = { n: 0 };
3214
+ items.set(item, into);
3215
+ }
3216
+ add(into, stat);
3217
+ }
3218
+ }
3219
+ }
3220
+ const rows = [...merged].map(([name, items]) => {
3221
+ var _a2, _b2;
3222
+ const all = { n: 0 };
3223
+ const list = [...items].map(([item, stat]) => {
3224
+ var _a3, _b3;
3225
+ if (!NOT_RUNS.has(item.slice(0, item.indexOf(":")))) {
3226
+ add(all, { ...stat, chars: undefined });
3227
+ }
3228
+ const p50 = quantile(stat.ms, 0.5);
3229
+ const p952 = quantile(stat.ms, 0.95);
3230
+ return {
3231
+ item,
3232
+ n: stat.n,
3233
+ err: (_a3 = stat.err) !== null && _a3 !== undefined ? _a3 : 0,
3234
+ abort: (_b3 = stat.abort) !== null && _b3 !== undefined ? _b3 : 0,
3235
+ ...p50 !== undefined ? { p50 } : {},
3236
+ ...p952 !== undefined ? { p95: p952 } : {},
3237
+ ...stat.chars !== undefined ? { chars: stat.chars } : {}
3238
+ };
3239
+ });
3240
+ list.sort((a, b) => b.err - a.err || b.n - a.n || a.item.localeCompare(b.item));
3241
+ const p95 = quantile(all.ms, 0.95);
3242
+ return { name, n: all.n, err: (_a2 = all.err) !== null && _a2 !== undefined ? _a2 : 0, abort: (_b2 = all.abort) !== null && _b2 !== undefined ? _b2 : 0, ...p95 !== undefined ? { p95 } : {}, items: list };
3243
+ });
3244
+ rows.sort((a, b) => Math.sign(b.err) - Math.sign(a.err) || b.n - a.n || a.name.localeCompare(b.name));
3245
+ return { since, until, days: days.map((one) => one.day).sort(), packages: rows };
3246
+ }
3247
+ TaMetricsUtil2.report = report;
3248
+ })(TaMetricsUtil || (TaMetricsUtil = {}));
2843
3249
  // ../ta-protocol/esm/common/package-protocol.js
2844
3250
  var TaPackageServer = Symbol("TaPackageServer");
2845
3251
  var TaPackageTextUtil;
@@ -3148,7 +3554,10 @@ var TaPermissionUtil;
3148
3554
  function host(manifest, method, kind) {
3149
3555
  var _a, _b, _c, _d;
3150
3556
  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;
3557
+ const own = (key) => {
3558
+ var _a2;
3559
+ return (_a2 = Object.getOwnPropertyDescriptor(host2, key)) === null || _a2 === undefined ? undefined : _a2.value;
3560
+ };
3152
3561
  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
3562
  }
3154
3563
  TaPermissionUtil2.host = host;
@@ -3305,6 +3714,120 @@ var TaExcludedFiles;
3305
3714
  TaExcludedFiles2.filter = filter;
3306
3715
  })(TaExcludedFiles || (TaExcludedFiles = {}));
3307
3716
  var TA_UPLOAD_PART_BYTES = 4 * 1024 * 1024;
3717
+ // web-src/agent-usage.ts
3718
+ import { open } from "node:fs/promises";
3719
+ var DAY_MS = 24 * 60 * 60000;
3720
+ var USAGE_DAYS = 30;
3721
+ var TAIL_BYTES = 256 * 1024;
3722
+ var AgentUsageUtil;
3723
+ ((AgentUsageUtil) => {
3724
+ async function read(team, messagesOf, now) {
3725
+ const messages = new Map;
3726
+ for (const channel of team.channels) {
3727
+ messages.set(channel.id, await messagesOf(channel.id));
3728
+ }
3729
+ const sessionTimes = new Map;
3730
+ for (const agent of team.agents) {
3731
+ const at = agent.sessionFile ? await lastAskedIn(agent.sessionFile) : undefined;
3732
+ if (agent.sessionFile && at) {
3733
+ sessionTimes.set(agent.sessionFile, at);
3734
+ }
3735
+ }
3736
+ return usage(team, messages, sessionTimes, now);
3737
+ }
3738
+ AgentUsageUtil.read = read;
3739
+ async function lastAskedIn(file) {
3740
+ const handle = await open(file, "r").catch(() => {
3741
+ return;
3742
+ });
3743
+ if (!handle) {
3744
+ return;
3745
+ }
3746
+ try {
3747
+ const { size } = await handle.stat();
3748
+ const length = Math.min(size, TAIL_BYTES);
3749
+ const buffer = new Uint8Array(length);
3750
+ await handle.read(buffer, 0, length, size - length);
3751
+ return lastAskedAt(new TextDecoder().decode(buffer));
3752
+ } finally {
3753
+ await handle.close();
3754
+ }
3755
+ }
3756
+ function lastAskedAt(lines) {
3757
+ const all = lines.split(`
3758
+ `);
3759
+ for (let index = all.length - 1;index >= 0; index--) {
3760
+ const line = all[index];
3761
+ if (!line.includes('"user"')) {
3762
+ continue;
3763
+ }
3764
+ try {
3765
+ const entry = JSON.parse(line);
3766
+ if (entry.type === "message" && entry.message?.role === "user" && entry.timestamp) {
3767
+ const at = Date.parse(entry.timestamp);
3768
+ if (Number.isFinite(at)) {
3769
+ return at;
3770
+ }
3771
+ }
3772
+ } catch {}
3773
+ }
3774
+ return;
3775
+ }
3776
+ AgentUsageUtil.lastAskedAt = lastAskedAt;
3777
+ function usage(team, messages, sessionTimes, now) {
3778
+ const since = now - USAGE_DAYS * DAY_MS;
3779
+ const named = new Map;
3780
+ const answers = new Map;
3781
+ const answeredAt = new Map;
3782
+ for (const list of messages.values()) {
3783
+ for (const message of list) {
3784
+ if (message.at < since || message.notice) {
3785
+ continue;
3786
+ }
3787
+ for (const id of ChannelsText.mentions(message.text, team.agents)) {
3788
+ if (id !== message.author) {
3789
+ named.set(id, (named.get(id) ?? 0) + 1);
3790
+ }
3791
+ }
3792
+ if (!message.failed && team.agents.some((agent) => agent.id === message.author)) {
3793
+ answers.set(message.author, (answers.get(message.author) ?? 0) + 1);
3794
+ }
3795
+ }
3796
+ for (const message of list) {
3797
+ if (!message.failed && message.at > (answeredAt.get(message.author) ?? 0)) {
3798
+ answeredAt.set(message.author, message.at);
3799
+ }
3800
+ }
3801
+ }
3802
+ return team.agents.map((agent) => {
3803
+ const channels = team.channels.filter((channel) => channel.members.includes(agent.id)).map((channel) => {
3804
+ const list = messages.get(channel.id) ?? [];
3805
+ const last2 = list.reduce((at, message) => Math.max(at, message.at), 0);
3806
+ return {
3807
+ id: channel.id,
3808
+ name: channel.name,
3809
+ messages: list.filter((message) => message.at >= since).length,
3810
+ ...last2 ? { lastAt: last2 } : {}
3811
+ };
3812
+ });
3813
+ const session = agent.sessionFile ? sessionTimes.get(agent.sessionFile) : undefined;
3814
+ const last = Math.max(session ?? 0, answeredAt.get(agent.id) ?? 0);
3815
+ return {
3816
+ id: agent.id,
3817
+ name: agent.name,
3818
+ role: agent.role,
3819
+ ...agent.temporary ? { temporary: true } : {},
3820
+ createdAt: agent.createdAt,
3821
+ ...last ? { lastUsedAt: last } : {},
3822
+ named: named.get(agent.id) ?? 0,
3823
+ answers: answers.get(agent.id) ?? 0,
3824
+ channels
3825
+ };
3826
+ });
3827
+ }
3828
+ AgentUsageUtil.usage = usage;
3829
+ })(AgentUsageUtil ||= {});
3830
+
3308
3831
  // web-src/channel-pictures.ts
3309
3832
  import { randomBytes } from "node:crypto";
3310
3833
  import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
@@ -3432,7 +3955,8 @@ var TeamViewUtil;
3432
3955
  }
3433
3956
  return manages ? channel : channelAs(channel);
3434
3957
  });
3435
- return { ...value, agents, channels, may };
3958
+ const { removed: _removed, ...rest } = value;
3959
+ return { ...rest, agents, channels, may };
3436
3960
  }
3437
3961
  TeamViewUtil.team = team;
3438
3962
  function agentAs(agent, edits, own) {
@@ -3570,9 +4094,9 @@ class TeamStore {
3570
4094
  }
3571
4095
  async openSession(agent) {
3572
4096
  if (agent.sessionFile) {
3573
- const open = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
3574
- if (open) {
3575
- return open.sessionId;
4097
+ const open2 = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
4098
+ if (open2) {
4099
+ return open2.sessionId;
3576
4100
  }
3577
4101
  }
3578
4102
  const cwd = agent.cwd ?? (await this.host.getServerInfo()).cwd;
@@ -3595,10 +4119,10 @@ class TeamStore {
3595
4119
  return sessionId;
3596
4120
  }
3597
4121
  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) {
4122
+ const open2 = agent.model && agent.sessionFile && (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
4123
+ if (open2 && agent.model && open2.model !== agent.model) {
3600
4124
  const slash = agent.model.indexOf("/");
3601
- await this.host.setModel(open.sessionId, agent.model.slice(0, slash), agent.model.slice(slash + 1));
4125
+ await this.host.setModel(open2.sessionId, agent.model.slice(0, slash), agent.model.slice(slash + 1));
3602
4126
  }
3603
4127
  }
3604
4128
  async settled(sessionId, before, poll) {
@@ -3756,6 +4280,30 @@ class TeamStore {
3756
4280
  set(key, value) {
3757
4281
  return this.host.setExtensionData(NAME, key, value);
3758
4282
  }
4283
+ listAgents() {
4284
+ const faces = ChannelsUtil.faces(this.team.agents);
4285
+ return this.team.agents.map((agent) => ({
4286
+ id: agent.id,
4287
+ name: agent.name,
4288
+ role: agent.role,
4289
+ mark: agent.mark,
4290
+ face: faces.get(agent.id) ?? 0,
4291
+ ...agent.cwd ? { cwd: agent.cwd } : {},
4292
+ ...agent.model ? { model: agent.model } : {},
4293
+ ...agent.temporary ? { temporary: true } : {}
4294
+ }));
4295
+ }
4296
+ listChannels() {
4297
+ return this.team.channels.map((channel) => ({
4298
+ id: channel.id,
4299
+ name: channel.name,
4300
+ ...channel.topic ? { topic: channel.topic } : {},
4301
+ members: channel.members
4302
+ }));
4303
+ }
4304
+ async agentUsage(now = Date.now()) {
4305
+ return AgentUsageUtil.read(this.team, (id) => this.messagesOf(id), now);
4306
+ }
3759
4307
  }
3760
4308
 
3761
4309
  // web-src/team-answers.ts
@@ -3965,9 +4513,9 @@ class TeamService extends TeamAnswers {
3965
4513
  }
3966
4514
  await this.saveTeam(team);
3967
4515
  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(() => {
4516
+ const open2 = (await this.host.listSessions()).find((session) => session.sessionFile === agent.sessionFile);
4517
+ if (open2) {
4518
+ await this.host.setSessionName(open2.sessionId, agent.name).catch(() => {
3971
4519
  return;
3972
4520
  });
3973
4521
  }
@@ -4016,9 +4564,15 @@ class TeamService extends TeamAnswers {
4016
4564
  return { agent, sessionId };
4017
4565
  }
4018
4566
  async deleteAgent(ref) {
4019
- const { team, agent, channels } = ChannelsUtil.removeAgent(this.team, ref);
4567
+ const now = Date.now();
4568
+ const removed = RemovedAgentsUtil.remove(this.team, ref, now);
4569
+ const { team, channels: old } = RemovedAgentsUtil.forget(removed.team, now);
4570
+ const { agent, channels } = removed;
4020
4571
  await this.saveTeam(team);
4021
4572
  for (const channel of channels) {
4573
+ await this.forget(channel, true);
4574
+ }
4575
+ for (const channel of old) {
4022
4576
  await this.forget(channel);
4023
4577
  }
4024
4578
  this.queue = { ...this.queue, jobs: this.queue.jobs.filter((job) => job.agentId !== agent.id) };
@@ -4028,11 +4582,18 @@ class TeamService extends TeamAnswers {
4028
4582
  }
4029
4583
  return agent;
4030
4584
  }
4031
- async forget(channel) {
4032
- await this.pictures.forget(channel.id);
4585
+ async restoreAgent(ref) {
4586
+ const { team, agent } = RemovedAgentsUtil.restore(this.team, ref);
4587
+ await this.saveTeam(team);
4588
+ return agent;
4589
+ }
4590
+ async forget(channel, keep = false) {
4033
4591
  this.messages.delete(channel.id);
4034
4592
  this.reading.delete(channel.id);
4035
- await this.set(Keys.messages(channel.id), null);
4593
+ if (!keep) {
4594
+ await this.pictures.forget(channel.id);
4595
+ await this.set(Keys.messages(channel.id), null);
4596
+ }
4036
4597
  const { [channel.id]: _gone, ...working } = this.working;
4037
4598
  this.working = working;
4038
4599
  await this.set(Keys.WORKING, working);
@@ -4093,19 +4654,6 @@ class TeamService extends TeamAnswers {
4093
4654
  await this.focus(channel.id);
4094
4655
  return { kind: "channel", id: channel.id, name: channel.name };
4095
4656
  }
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
4657
  async request(request) {
4110
4658
  if (this.disposed) {
4111
4659
  throw new Error("The team has stopped; the extension may have been turned off.");
@@ -4131,6 +4679,8 @@ class TeamService extends TeamAnswers {
4131
4679
  return this.setChannelModel(request);
4132
4680
  case "deleteAgent":
4133
4681
  return this.deleteAgent(request.agent);
4682
+ case "restoreAgent":
4683
+ return this.restoreAgent(request.agent);
4134
4684
  case "post":
4135
4685
  return (await this.post(String(request.channel ?? ""), USER, String(request.text ?? ""), await this.posterOf(request))).message;
4136
4686
  case "picture":
@@ -4323,14 +4873,6 @@ class TeamService extends TeamAnswers {
4323
4873
  resolve(waiting.replies);
4324
4874
  }
4325
4875
  }
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
4876
  }
4335
4877
 
4336
4878
  // 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.30.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.30.0",
31
+ "@celljs/ta-relay": "4.30.0",
32
+ "@celljs/ta-web": "4.30.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",