@celljs/ta-call 4.17.0 → 4.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -6,4 +6,4 @@ The front of Ta's calls: a light session answers you at once in a call (chat, a
6
6
  - Host: a front session per call, closed as it ends.
7
7
  - pi extension: a front has `tell` (into the conversation called), `side` (a side conversation, same directory and role, as the caller), `stop`, `status` and `look` alone, none of the user's instructions or skills.
8
8
  - A call begins knowing the conversation called: its role, name, how it goes and its last lines (about 1200 characters at most); details are looked up as asked.
9
- - The conversations of calls fold into a folder Calls of the list, to look back at.
9
+ - The conversations of calls fold into a folder Calls of the list, to look back at; archived as any other, the folder pinned stays once they all are, listing the archived when opened.
package/README.md CHANGED
@@ -6,4 +6,4 @@ Ta 的通话前台:通话时由一个轻量会话随时回应你(闲聊、
6
6
  - 服务端(host):每次通话开一个前台会话,通话结束就关掉。
7
7
  - pi 扩展:前台只有 `tell`(插话进被通话的对话)、`side`(开旁路对话,同目录、同角色、按发起人的权限)、`stop`、`status`、`look` 五个工具,不读你的说明文件和技能。
8
8
  - 通话开始时带上被通话对话的角色、名字、现在的状态和最近几轮(最多约 1200 字),之后的细节按需 `look`。
9
- - 通话对话在对话列表里收进"通话"文件夹,可以回看。
9
+ - 通话对话在对话列表里收进"通话"文件夹,可以回看;按对话列表的归档天数归档,置顶的文件夹全部归档后也一直在,点开连归档的一起列出。
@@ -297,6 +297,20 @@ var TA_WEB_SETTINGS = [
297
297
  title: words("Model of tasks", "任务的模型", "任務的模型", "タスクのモデル")
298
298
  },
299
299
  { key: "reduceMotion", type: "boolean", default: false, what: "Fewer animations.", title: words("Reduce motion", "减少动画", "減少動畫", "動きを減らす") },
300
+ {
301
+ key: "diagramStyle",
302
+ type: "enum",
303
+ values: ["clean", "sketch", "colour", "motion"],
304
+ default: "clean",
305
+ what: "How diagrams in replies draw: in the colours of the page, as by hand, a colour to a node, or coming in with flowing lines.",
306
+ title: words("Diagram style", "图表风格", "圖表風格", "図のスタイル"),
307
+ shown: {
308
+ clean: words("clean", "简洁", "簡潔", "シンプル"),
309
+ sketch: words("sketch", "草图", "草圖", "スケッチ"),
310
+ colour: words("colour", "彩色", "彩色", "カラー"),
311
+ motion: words("motion", "动效", "動效", "モーション")
312
+ }
313
+ },
300
314
  {
301
315
  key: "keepAliveMinutes",
302
316
  type: "number",
@@ -365,7 +379,7 @@ var TaAppUtil;
365
379
  // web-src/call-protocol.ts
366
380
  var NAME = "@celljs/ta-call";
367
381
  var CALL_MARK = "[ta-call]";
368
- var CALL_TOOLS = ["tell", "side", "stop", "status", "look"];
382
+ var CALL_TOOLS = ["tell", "side", "stop", "status", "look", "hang_up"];
369
383
 
370
384
  // web-src/extension.ts
371
385
  var NO_SERVER = "Calls need the Ta service: start it with `ta serve`.";
@@ -430,6 +444,13 @@ function activate(pi) {
430
444
  parameters: { type: "object", properties: { within: { type: "string" } } },
431
445
  run: (calls, call, params) => calls.stop(call, typeof params.within === "string" ? params.within : undefined)
432
446
  },
447
+ {
448
+ name: "hang_up",
449
+ label: "Hang up",
450
+ description: "Ends this call once your reply is said, when the user wants it ended: reply with a goodbye of a few words.",
451
+ parameters: { type: "object", properties: {} },
452
+ run: (calls, call) => calls.hangUp(call)
453
+ },
433
454
  {
434
455
  name: "status",
435
456
  label: "How the work goes",
package/host/index.mjs CHANGED
@@ -26,23 +26,47 @@ ${message}`;
26
26
  var TaMessageSource;
27
27
  (function(TaMessageSource2) {
28
28
  TaMessageSource2.DOUBLE = "ta:double";
29
- const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
29
+ const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
30
30
  function mark(message, from, detail) {
31
- if (/^[/!]/.test(message) || of(message)) {
32
- return message;
33
- }
34
- const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
35
- const context = TaMessageContext.read(message);
36
- return TaMessageContext.wrap(context === undefined ? line : `${context}
37
- ${line}`, TaMessageContext.strip(message));
31
+ return marked(message, line(from, detail));
38
32
  }
39
33
  TaMessageSource2.mark = mark;
34
+ function notice(message, from, detail) {
35
+ return marked(message, line(from, detail, true));
36
+ }
37
+ TaMessageSource2.notice = notice;
38
+ function line(from, detail, notice2 = false) {
39
+ return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
40
+ }
41
+ TaMessageSource2.line = line;
40
42
  function of(message) {
41
43
  const context = TaMessageContext.read(message);
42
44
  const match = context === undefined ? null : LINE.exec(context);
43
- return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
45
+ return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
44
46
  }
45
47
  TaMessageSource2.of = of;
48
+ function isNotice(message) {
49
+ var _a;
50
+ return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
51
+ }
52
+ TaMessageSource2.isNotice = isNotice;
53
+ TaMessageSource2.SECTION = "ta-sources";
54
+ TaMessageSource2.PROMPT = [
55
+ "Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
56
+ "One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
57
+ "- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
58
+ "- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
59
+ "- Never quote it as the user's words nor answer it as if they had said it."
60
+ ].join(`
61
+ `);
62
+ function marked(message, source) {
63
+ if (/^[/!]/.test(message) || of(message)) {
64
+ return message;
65
+ }
66
+ const context = TaMessageContext.read(message);
67
+ return TaMessageContext.wrap(context === undefined ? source : `${context}
68
+ ${source}`, TaMessageContext.strip(message));
69
+ }
46
70
  })(TaMessageSource || (TaMessageSource = {}));
47
71
  var TaImageNote;
48
72
  (function(TaImageNote2) {
@@ -205,6 +229,50 @@ ${note.body}
205
229
  return text.replace(/&quot;/g, '"').replace(/&amp;/g, "&");
206
230
  }
207
231
  })(TaTaskNote || (TaTaskNote = {}));
232
+ var TaSecretRef;
233
+ (function(TaSecretRef2) {
234
+ TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
235
+ const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
236
+ const KINDS = [
237
+ [/^PHONE(?:_\d+)?$/, "phone"],
238
+ [/^EMAIL(?:_\d+)?$/, "email"],
239
+ [/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
240
+ [/^BANK_CARD(?:_\d+)?$/, "bankCard"]
241
+ ];
242
+ function has(text) {
243
+ return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
244
+ }
245
+ TaSecretRef2.has = has;
246
+ function kind(name) {
247
+ var _a;
248
+ var _b;
249
+ return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
250
+ }
251
+ TaSecretRef2.kind = kind;
252
+ function split(text) {
253
+ if (!has(text)) {
254
+ return [{ text }];
255
+ }
256
+ const parts = [];
257
+ let at = 0;
258
+ for (const match of text.matchAll(REF)) {
259
+ if (match.index > at) {
260
+ parts.push({ text: text.slice(at, match.index) });
261
+ }
262
+ parts.push({ secret: match[1], kind: kind(match[1]) });
263
+ at = match.index + match[0].length;
264
+ }
265
+ if (at < text.length) {
266
+ parts.push({ text: text.slice(at) });
267
+ }
268
+ return parts;
269
+ }
270
+ TaSecretRef2.split = split;
271
+ function plain(text, label) {
272
+ return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
273
+ }
274
+ TaSecretRef2.plain = plain;
275
+ })(TaSecretRef || (TaSecretRef = {}));
208
276
 
209
277
  // ../ta-protocol/esm/common/ta-extension-host.js
210
278
  var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
@@ -343,13 +411,232 @@ var TaLanguageUtil;
343
411
  TaLanguageUtil2.list = list;
344
412
  })(TaLanguageUtil || (TaLanguageUtil = {}));
345
413
 
414
+ // ../ta-protocol/esm/common/said-protocol.js
415
+ var TaSaid;
416
+ (function(TaSaid2) {
417
+ const CARD = /^ta-/i;
418
+ const READ = 4000;
419
+ const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
420
+ const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
421
+ const MARKS_ONLY = /^[-*_=|:+\s]+$/;
422
+ const MARKS = [
423
+ ["context", /<\/?context>/],
424
+ ["source", /\[ta:(?:from|notice|by) /],
425
+ ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
426
+ ["skill", /<skill name="|<\/skill>/],
427
+ ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
428
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/]
429
+ ];
430
+ function text(content, joiner = `
431
+ `) {
432
+ if (typeof content === "string") {
433
+ return content;
434
+ }
435
+ return Array.isArray(content) ? content.filter((part) => (part === null || part === undefined ? undefined : part.type) === "text" && typeof part.text === "string").map((part) => part.text).join(joiner) : "";
436
+ }
437
+ TaSaid2.text = text;
438
+ function words(role, text2, options = {}) {
439
+ const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
440
+ return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
441
+ }
442
+ TaSaid2.words = words;
443
+ function of(message, options) {
444
+ return message ? words(message.role, text(message.content), options) : "";
445
+ }
446
+ TaSaid2.of = of;
447
+ function notice(message) {
448
+ return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
449
+ }
450
+ TaSaid2.notice = notice;
451
+ function marksOnly(role, text2) {
452
+ return !!text2.trim() && !line(words(role, text2), { chars: Number.POSITIVE_INFINITY });
453
+ }
454
+ TaSaid2.marksOnly = marksOnly;
455
+ function line(markdown, options) {
456
+ var _a;
457
+ const read = markdown.slice(0, READ);
458
+ const prose = withoutFences(read, () => true, true).trim();
459
+ const lines = plain(prose || codeOf(read)).split(`
460
+ `).map((part) => part.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+)/, "").replace(/\*{1,3}|`+|~~|(?<![\p{L}\p{N}])_{1,3}|_{1,3}(?![\p{L}\p{N}])/gu, "").replace(/\s+/g, " ").trim()).filter((part) => part && !MARKS_ONLY.test(part) && !TAG_LINE.test(part));
461
+ const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
462
+ const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
463
+ `);
464
+ return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
465
+ }
466
+ TaSaid2.line = line;
467
+ function leaks(shown, options = {}) {
468
+ const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
469
+ const lines = shown.split(`
470
+ `);
471
+ if (options.cards !== true && lines.some((part) => {
472
+ var _a;
473
+ var _b;
474
+ return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
475
+ })) {
476
+ found.push("card");
477
+ }
478
+ if (lines.some((part) => TAG_LINE.test(part.trim()))) {
479
+ found.push("tag");
480
+ }
481
+ return found;
482
+ }
483
+ TaSaid2.leaks = leaks;
484
+ const SUMMARY = `<conversation_history_summary>
485
+ <summary>
486
+ 1. Primary Request and Intent:
487
+ The user works on the relay.
488
+ </summary>
489
+ </conversation_history_summary>`;
490
+ TaSaid2.SAMPLES = [
491
+ {
492
+ mark: "context and where it came from",
493
+ role: "user",
494
+ text: `<context>
495
+ The channel #ops, its members.
496
+ [ta:from @celljs/ta-channels #ops]
497
+ </context>
498
+ Check the build`,
499
+ said: "Check the build"
500
+ },
501
+ {
502
+ mark: "a notice, not the user",
503
+ role: "user",
504
+ text: `<context>
505
+ [ta:notice @celljs/ta-call]
506
+ </context>
507
+ The work finished. Its last words: tests pass.`,
508
+ said: "The work finished. Its last words: tests pass."
509
+ },
510
+ { mark: "one let in", role: "user", text: `<context>
511
+ [ta:by p-7 Alice]
512
+ </context>
513
+ Hello there`, said: "Hello there" },
514
+ {
515
+ mark: "notes of images",
516
+ role: "user",
517
+ text: `Look at this
518
+ [Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
519
+ [Image converted from image/heic to image/png.]`,
520
+ said: "Look at this"
521
+ },
522
+ {
523
+ mark: "a skill run",
524
+ role: "user",
525
+ text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
526
+ # Ta package
527
+ Steps.
528
+ </skill>
529
+
530
+ Make a card`,
531
+ said: "Make a card"
532
+ },
533
+ {
534
+ mark: "a note of a task",
535
+ role: "user",
536
+ text: `<task_update id="t1" title="Fix login" status="done">
537
+ All tests pass.
538
+ </task_update>`,
539
+ said: "Fix login"
540
+ },
541
+ { mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
542
+ Now t2.
543
+ </task_renamed>` },
544
+ { mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
545
+ Switched to voice.`, said: "Switched to voice." },
546
+ { mark: "a summary alone", role: "assistant", text: SUMMARY },
547
+ { mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
548
+ <summary>` },
549
+ {
550
+ mark: "a card after the answer",
551
+ role: "assistant",
552
+ text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
553
+ said: "tests pass"
554
+ },
555
+ { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
556
+ { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
557
+ { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
558
+ { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
559
+ </system-reminder>
560
+ Ready.`, said: "Ready." }
561
+ ];
562
+ function userWords(text2) {
563
+ const said = TaImageNote.strip(TaMessageContext.strip(text2));
564
+ const skill = TaSkillUse.parse(said);
565
+ if (skill) {
566
+ return TaSkillUse.command(skill);
567
+ }
568
+ const note = TaTaskNote.parse(said);
569
+ if (!note) {
570
+ return said;
571
+ }
572
+ if (note.kind === "renamed") {
573
+ return "";
574
+ }
575
+ return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
576
+ }
577
+ function withoutFences(text2, drop, tags = false) {
578
+ const kept = [];
579
+ let fence;
580
+ let left = false;
581
+ for (const part of text2.split(`
582
+ `)) {
583
+ const open = FENCE.exec(part);
584
+ if (!fence && open) {
585
+ fence = { mark: open[1], dropped: drop(open[2]) };
586
+ } else if (fence && closes(part, fence.mark)) {
587
+ const dropped = fence.dropped;
588
+ fence = undefined;
589
+ if (dropped) {
590
+ continue;
591
+ }
592
+ }
593
+ if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
594
+ left = true;
595
+ } else {
596
+ kept.push(part);
597
+ }
598
+ }
599
+ return left ? kept.join(`
600
+ `).replace(/\n{3,}/g, `
601
+
602
+ `) : kept.join(`
603
+ `);
604
+ }
605
+ function codeOf(text2) {
606
+ const code = [];
607
+ let fence;
608
+ for (const part of text2.split(`
609
+ `)) {
610
+ const open = FENCE.exec(part);
611
+ if (!fence && open) {
612
+ fence = { mark: open[1], card: CARD.test(open[2]) };
613
+ } else if (fence && closes(part, fence.mark)) {
614
+ fence = undefined;
615
+ } else if (fence && !fence.card) {
616
+ code.push(part);
617
+ }
618
+ }
619
+ return code.join(`
620
+ `);
621
+ }
622
+ function closes(part, mark) {
623
+ var _a;
624
+ const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
625
+ return !!close && close[0] === mark[0] && close.length >= mark.length;
626
+ }
627
+ function plain(text2) {
628
+ const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
629
+ const words2 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
630
+ return words2 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
631
+ }
632
+ })(TaSaid || (TaSaid = {}));
633
+
346
634
  // web-src/call-util.ts
347
635
  var LOOK_CHARS = 1500;
348
636
  var ENTRY_CHARS = 600;
349
637
  var SEED_CHARS = 1200;
350
638
  var ROLE_CHARS = 800;
351
639
  var LAST_ENTRIES = 12;
352
- var NEWS = "[news]";
353
640
  var QUIET = "-";
354
641
  var FAST = /(mini|flash|haiku|lite|nano|turbo|small|fast|air)\b/i;
355
642
  var CallUtil;
@@ -364,11 +651,12 @@ var CallUtil;
364
651
  "- What needs files, commands, code, research or anything the work does: tell the work (into what it does now, or after it); for something apart from it, open a side conversation with side. Then say in a few words that you did. You cannot do it yourself.",
365
652
  "- Asked how the work goes or about any detail of it: status, then look with a question for the detail; answer from what they return, never guess.",
366
653
  "- When the user wants what the work or a side conversation does stopped: stop.",
654
+ "- When the user wants the call to end (hang up, bye): hang_up, then say goodbye in a few words; the call ends once it is said. Never tell them to hang up themselves.",
367
655
  "- To change Ta itself (its settings, the captions of this call, pin a conversation, turn an extension on or off): app_run yourself, at once, then say in a few words it is done.",
368
- "- When the work waits for the user to decide: read them the question (app_run asks.list), and answer it with what they say (app_run asks.answer); never decide for them.",
369
- "- What only the screen has (what the user looks at, a page of an extension): app_look, app_go, app_do; to show them where something is, with here: true.",
656
+ "- When the work waits for the user to decide: read them the question (app_run asks.list), and answer it with what they say (app_run asks.answer: Ta asks them to agree on their screen, tell them so); never decide for them.",
657
+ "- What only the screen has, or what the user asks you to do on their screen (open a page, press a button, find something they look at): app_look, app_go, app_do on their own screen, the one in front of them, as their shadow; say in a few words what you do as you do it. The call goes on while their screen shows something else.",
370
658
  "- A message that starts with [sent] went to the work already: acknowledge it in a few words.",
371
- `- A message that starts with ${NEWS} is news of the work, not the user speaking: when the user should hear it (a result, a failure, a question for them), say it in one short sentence as you would on the phone, the answer first; else answer ${QUIET} alone.`,
659
+ `- A message marked [ta:notice] is news of the work, not the user speaking: when the user should hear it (a result, a failure, a question for them), say it in one short sentence as you would on the phone, the answer first; else answer ${QUIET} alone. What the user says comes first: when they spoke after news, answer them, and add the news in a few words only if they should hear it and it was not said yet.`,
372
660
  ...seed ? ["", seedText(seed, target.double)] : []
373
661
  ].join(`
374
662
  `);
@@ -420,20 +708,25 @@ ${text}`;
420
708
  return at < 0 ? undefined : role2.slice(at + CALL_MARK.length).trim().split(/\s/)[0] || undefined;
421
709
  }
422
710
  CallUtil.callOf = callOf;
423
- function name(language, called) {
711
+ function name(language, called, said2) {
424
712
  const call = TaLanguageUtil.pick(language, { "zh-CN": "通话", "zh-TW": "通話", "en-US": "Call", "ja-JP": "通話" });
425
- const other = called ? flat(called).slice(0, 40) : "";
426
- return other ? `${call} · ${other}` : call;
713
+ const opening = said2 ? firstSentence(said2) : "";
714
+ const other = called ? flat(called).slice(0, opening ? 20 : 40) : "";
715
+ return [call, other, opening].filter(Boolean).join(" · ");
427
716
  }
428
717
  CallUtil.name = name;
718
+ function firstSentence(text) {
719
+ const [first = ""] = flat(text).split(/(?<=[。!?;!?;])|(?<=\.)\s/);
720
+ return first.replace(/[\s。!?;,、!?;,.]+$/, "").slice(0, 30);
721
+ }
429
722
  function news(lines) {
430
- return [NEWS, ...lines].join(`
431
- `);
723
+ return TaMessageSource.notice(lines.join(`
724
+ `), NAME);
432
725
  }
433
726
  CallUtil.news = news;
434
727
  function toSay(reply) {
435
728
  const said2 = reply?.trim();
436
- return said2 && said2 !== QUIET && !said2.startsWith(NEWS) ? said2 : undefined;
729
+ return said2 && said2 !== QUIET ? said2 : undefined;
437
730
  }
438
731
  CallUtil.toSay = toSay;
439
732
  function ended(name2, how) {
@@ -455,12 +748,16 @@ ${text}`;
455
748
  return sent ? `[sent] ${text}` : text;
456
749
  }
457
750
  CallUtil.said = said;
458
- function model(models, chosen, current) {
459
- if (chosen && models.includes(chosen)) {
751
+ function model(models, chosen, current, agents = []) {
752
+ const own = models.filter((model2) => !agents.includes(model2));
753
+ if (chosen && own.includes(chosen)) {
460
754
  return chosen;
461
755
  }
756
+ const fast = own.filter((model2) => FAST.test(model2.split("/").slice(1).join("/")));
757
+ if (current && agents.includes(current)) {
758
+ return fast[0] ?? own[0];
759
+ }
462
760
  const provider = current?.split("/")[0];
463
- const fast = models.filter((model2) => FAST.test(model2.split("/").slice(1).join("/")));
464
761
  return fast.find((model2) => model2.split("/")[0] === provider) ?? current;
465
762
  }
466
763
  CallUtil.model = model;
@@ -470,12 +767,12 @@ ${text}`;
470
767
  const message = raw;
471
768
  const parts = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content ?? [];
472
769
  if (message.role === "user") {
473
- const text = TaMessageContext.strip(texts(parts)).trim();
770
+ const text = TaSaid.words("user", texts(parts));
474
771
  if (text) {
475
772
  lines.push({ role: "user", text: short(text) });
476
773
  }
477
774
  } else if (message.role === "assistant") {
478
- const text = texts(parts).trim();
775
+ const text = TaSaid.words("assistant", texts(parts));
479
776
  if (text) {
480
777
  lines.push({ role: "assistant", text: short(text) });
481
778
  }
@@ -597,7 +894,8 @@ class CallHost {
597
894
  news: [],
598
895
  outbox: [],
599
896
  waiters: [],
600
- turns: Promise.resolve()
897
+ turns: Promise.resolve(),
898
+ spoken: 0
601
899
  });
602
900
  this.watch();
603
901
  return { callId: id };
@@ -605,9 +903,18 @@ class CallHost {
605
903
  async say(callId, text, sent = false) {
606
904
  const call = this.call(callId);
607
905
  call.used = this.options.now();
906
+ call.spoken++;
907
+ call.outbox.length = 0;
908
+ if (!call.titled && text.trim()) {
909
+ call.titled = true;
910
+ const name = CallUtil.name(call.target.language, call.target.double ? undefined : call.seed.name, text);
911
+ this.host.setSessionName(call.front, name).catch(() => {
912
+ return;
913
+ });
914
+ }
608
915
  const reply = await this.turn(call, CallUtil.said(text, sent));
609
916
  call.used = this.options.now();
610
- return reply;
917
+ return { ...reply ? { text: reply } : {}, ...call.ending ? { end: true } : {} };
611
918
  }
612
919
  next(callId) {
613
920
  const call = this.calls.get(callId);
@@ -680,6 +987,10 @@ class CallHost {
680
987
  await this.as(call, () => this.host.prompt(sessionId, { clientMessageId: randomUUID(), message: TaMessageSource.mark(CallUtil.side(text, call.seed.name), NAME) }));
681
988
  return `Opened the side conversation "${name}": it works on it now, news comes when it ends.`;
682
989
  }
990
+ hangUp(call) {
991
+ call.ending = true;
992
+ return "The call ends once your reply is said: say goodbye in a few words.";
993
+ }
683
994
  async stop(call, within) {
684
995
  const sessionId = within ? (await this.named(call, within))?.sessionId : call.target.sessionId;
685
996
  if (!sessionId) {
@@ -763,9 +1074,10 @@ class CallHost {
763
1074
  if (!news.length || !this.calls.has(call.id)) {
764
1075
  return;
765
1076
  }
1077
+ const spoken = call.spoken;
766
1078
  this.turn(call, CallUtil.news(news)).then((reply) => {
767
1079
  const said = CallUtil.toSay(reply);
768
- if (!said || !this.calls.has(call.id)) {
1080
+ if (!said || !this.calls.has(call.id) || call.spoken !== spoken) {
769
1081
  return;
770
1082
  }
771
1083
  const waiter = call.waiters[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-call",
3
- "version": "4.17.0",
3
+ "version": "4.18.0",
4
4
  "description": "A pi package for Ta: in a call, a front that talks at once, whatever the work does, hands the work to the conversation and looks up any detail of it when asked",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -27,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.17.0",
31
- "@celljs/ta-web": "4.17.0",
30
+ "@celljs/ta-protocol": "4.18.0",
31
+ "@celljs/ta-web": "4.18.0",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
package/web/index.js CHANGED
@@ -66,23 +66,47 @@ ${message}`;
66
66
  var TaMessageSource;
67
67
  (function(TaMessageSource2) {
68
68
  TaMessageSource2.DOUBLE = "ta:double";
69
- const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
69
+ const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
70
70
  function mark(message, from, detail) {
71
- if (/^[/!]/.test(message) || of(message)) {
72
- return message;
73
- }
74
- const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
75
- const context = TaMessageContext.read(message);
76
- return TaMessageContext.wrap(context === undefined ? line : `${context}
77
- ${line}`, TaMessageContext.strip(message));
71
+ return marked(message, line(from, detail));
78
72
  }
79
73
  TaMessageSource2.mark = mark;
74
+ function notice(message, from, detail) {
75
+ return marked(message, line(from, detail, true));
76
+ }
77
+ TaMessageSource2.notice = notice;
78
+ function line(from, detail, notice2 = false) {
79
+ return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
80
+ }
81
+ TaMessageSource2.line = line;
80
82
  function of(message) {
81
83
  const context = TaMessageContext.read(message);
82
84
  const match = context === undefined ? null : LINE.exec(context);
83
- return match ? { from: match[1], ...match[2] ? { detail: match[2].trim() } : {} } : undefined;
85
+ return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
84
86
  }
85
87
  TaMessageSource2.of = of;
88
+ function isNotice(message) {
89
+ var _a;
90
+ return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
91
+ }
92
+ TaMessageSource2.isNotice = isNotice;
93
+ TaMessageSource2.SECTION = "ta-sources";
94
+ TaMessageSource2.PROMPT = [
95
+ "Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
96
+ "One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
97
+ "- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
98
+ "- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
99
+ "- Never quote it as the user's words nor answer it as if they had said it."
100
+ ].join(`
101
+ `);
102
+ function marked(message, source) {
103
+ if (/^[/!]/.test(message) || of(message)) {
104
+ return message;
105
+ }
106
+ const context = TaMessageContext.read(message);
107
+ return TaMessageContext.wrap(context === undefined ? source : `${context}
108
+ ${source}`, TaMessageContext.strip(message));
109
+ }
86
110
  })(TaMessageSource || (TaMessageSource = {}));
87
111
  var TaImageNote;
88
112
  (function(TaImageNote2) {
@@ -245,6 +269,270 @@ ${note.body}
245
269
  return text.replace(/&quot;/g, '"').replace(/&amp;/g, "&");
246
270
  }
247
271
  })(TaTaskNote || (TaTaskNote = {}));
272
+ var TaSecretRef;
273
+ (function(TaSecretRef2) {
274
+ TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
275
+ const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
276
+ const KINDS = [
277
+ [/^PHONE(?:_\d+)?$/, "phone"],
278
+ [/^EMAIL(?:_\d+)?$/, "email"],
279
+ [/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
280
+ [/^BANK_CARD(?:_\d+)?$/, "bankCard"]
281
+ ];
282
+ function has(text) {
283
+ return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
284
+ }
285
+ TaSecretRef2.has = has;
286
+ function kind(name) {
287
+ var _a;
288
+ var _b;
289
+ return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
290
+ }
291
+ TaSecretRef2.kind = kind;
292
+ function split(text) {
293
+ if (!has(text)) {
294
+ return [{ text }];
295
+ }
296
+ const parts = [];
297
+ let at = 0;
298
+ for (const match of text.matchAll(REF)) {
299
+ if (match.index > at) {
300
+ parts.push({ text: text.slice(at, match.index) });
301
+ }
302
+ parts.push({ secret: match[1], kind: kind(match[1]) });
303
+ at = match.index + match[0].length;
304
+ }
305
+ if (at < text.length) {
306
+ parts.push({ text: text.slice(at) });
307
+ }
308
+ return parts;
309
+ }
310
+ TaSecretRef2.split = split;
311
+ function plain(text, label) {
312
+ return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
313
+ }
314
+ TaSecretRef2.plain = plain;
315
+ })(TaSecretRef || (TaSecretRef = {}));
316
+
317
+ // ../ta-protocol/esm/common/said-protocol.js
318
+ var TaSaid;
319
+ (function(TaSaid2) {
320
+ const CARD = /^ta-/i;
321
+ const READ = 4000;
322
+ const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
323
+ const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
324
+ const MARKS_ONLY = /^[-*_=|:+\s]+$/;
325
+ const MARKS = [
326
+ ["context", /<\/?context>/],
327
+ ["source", /\[ta:(?:from|notice|by) /],
328
+ ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
329
+ ["skill", /<skill name="|<\/skill>/],
330
+ ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
331
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/]
332
+ ];
333
+ function text(content, joiner = `
334
+ `) {
335
+ if (typeof content === "string") {
336
+ return content;
337
+ }
338
+ return Array.isArray(content) ? content.filter((part) => (part === null || part === undefined ? undefined : part.type) === "text" && typeof part.text === "string").map((part) => part.text).join(joiner) : "";
339
+ }
340
+ TaSaid2.text = text;
341
+ function words(role, text2, options = {}) {
342
+ const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
343
+ return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
344
+ }
345
+ TaSaid2.words = words;
346
+ function of(message, options) {
347
+ return message ? words(message.role, text(message.content), options) : "";
348
+ }
349
+ TaSaid2.of = of;
350
+ function notice(message) {
351
+ return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
352
+ }
353
+ TaSaid2.notice = notice;
354
+ function marksOnly(role, text2) {
355
+ return !!text2.trim() && !line(words(role, text2), { chars: Number.POSITIVE_INFINITY });
356
+ }
357
+ TaSaid2.marksOnly = marksOnly;
358
+ function line(markdown, options) {
359
+ var _a;
360
+ const read = markdown.slice(0, READ);
361
+ const prose = withoutFences(read, () => true, true).trim();
362
+ const lines = plain(prose || codeOf(read)).split(`
363
+ `).map((part) => part.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+)/, "").replace(/\*{1,3}|`+|~~|(?<![\p{L}\p{N}])_{1,3}|_{1,3}(?![\p{L}\p{N}])/gu, "").replace(/\s+/g, " ").trim()).filter((part) => part && !MARKS_ONLY.test(part) && !TAG_LINE.test(part));
364
+ const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
365
+ const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
366
+ `);
367
+ return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
368
+ }
369
+ TaSaid2.line = line;
370
+ function leaks(shown, options = {}) {
371
+ const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
372
+ const lines = shown.split(`
373
+ `);
374
+ if (options.cards !== true && lines.some((part) => {
375
+ var _a;
376
+ var _b;
377
+ return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
378
+ })) {
379
+ found.push("card");
380
+ }
381
+ if (lines.some((part) => TAG_LINE.test(part.trim()))) {
382
+ found.push("tag");
383
+ }
384
+ return found;
385
+ }
386
+ TaSaid2.leaks = leaks;
387
+ const SUMMARY = `<conversation_history_summary>
388
+ <summary>
389
+ 1. Primary Request and Intent:
390
+ The user works on the relay.
391
+ </summary>
392
+ </conversation_history_summary>`;
393
+ TaSaid2.SAMPLES = [
394
+ {
395
+ mark: "context and where it came from",
396
+ role: "user",
397
+ text: `<context>
398
+ The channel #ops, its members.
399
+ [ta:from @celljs/ta-channels #ops]
400
+ </context>
401
+ Check the build`,
402
+ said: "Check the build"
403
+ },
404
+ {
405
+ mark: "a notice, not the user",
406
+ role: "user",
407
+ text: `<context>
408
+ [ta:notice @celljs/ta-call]
409
+ </context>
410
+ The work finished. Its last words: tests pass.`,
411
+ said: "The work finished. Its last words: tests pass."
412
+ },
413
+ { mark: "one let in", role: "user", text: `<context>
414
+ [ta:by p-7 Alice]
415
+ </context>
416
+ Hello there`, said: "Hello there" },
417
+ {
418
+ mark: "notes of images",
419
+ role: "user",
420
+ text: `Look at this
421
+ [Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
422
+ [Image converted from image/heic to image/png.]`,
423
+ said: "Look at this"
424
+ },
425
+ {
426
+ mark: "a skill run",
427
+ role: "user",
428
+ text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
429
+ # Ta package
430
+ Steps.
431
+ </skill>
432
+
433
+ Make a card`,
434
+ said: "Make a card"
435
+ },
436
+ {
437
+ mark: "a note of a task",
438
+ role: "user",
439
+ text: `<task_update id="t1" title="Fix login" status="done">
440
+ All tests pass.
441
+ </task_update>`,
442
+ said: "Fix login"
443
+ },
444
+ { mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
445
+ Now t2.
446
+ </task_renamed>` },
447
+ { mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
448
+ Switched to voice.`, said: "Switched to voice." },
449
+ { mark: "a summary alone", role: "assistant", text: SUMMARY },
450
+ { mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
451
+ <summary>` },
452
+ {
453
+ mark: "a card after the answer",
454
+ role: "assistant",
455
+ text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
456
+ said: "tests pass"
457
+ },
458
+ { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
459
+ { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
460
+ { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
461
+ { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
462
+ </system-reminder>
463
+ Ready.`, said: "Ready." }
464
+ ];
465
+ function userWords(text2) {
466
+ const said = TaImageNote.strip(TaMessageContext.strip(text2));
467
+ const skill = TaSkillUse.parse(said);
468
+ if (skill) {
469
+ return TaSkillUse.command(skill);
470
+ }
471
+ const note = TaTaskNote.parse(said);
472
+ if (!note) {
473
+ return said;
474
+ }
475
+ if (note.kind === "renamed") {
476
+ return "";
477
+ }
478
+ return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
479
+ }
480
+ function withoutFences(text2, drop, tags = false) {
481
+ const kept = [];
482
+ let fence;
483
+ let left = false;
484
+ for (const part of text2.split(`
485
+ `)) {
486
+ const open = FENCE.exec(part);
487
+ if (!fence && open) {
488
+ fence = { mark: open[1], dropped: drop(open[2]) };
489
+ } else if (fence && closes(part, fence.mark)) {
490
+ const dropped = fence.dropped;
491
+ fence = undefined;
492
+ if (dropped) {
493
+ continue;
494
+ }
495
+ }
496
+ if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
497
+ left = true;
498
+ } else {
499
+ kept.push(part);
500
+ }
501
+ }
502
+ return left ? kept.join(`
503
+ `).replace(/\n{3,}/g, `
504
+
505
+ `) : kept.join(`
506
+ `);
507
+ }
508
+ function codeOf(text2) {
509
+ const code = [];
510
+ let fence;
511
+ for (const part of text2.split(`
512
+ `)) {
513
+ const open = FENCE.exec(part);
514
+ if (!fence && open) {
515
+ fence = { mark: open[1], card: CARD.test(open[2]) };
516
+ } else if (fence && closes(part, fence.mark)) {
517
+ fence = undefined;
518
+ } else if (fence && !fence.card) {
519
+ code.push(part);
520
+ }
521
+ }
522
+ return code.join(`
523
+ `);
524
+ }
525
+ function closes(part, mark) {
526
+ var _a;
527
+ const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
528
+ return !!close && close[0] === mark[0] && close.length >= mark.length;
529
+ }
530
+ function plain(text2) {
531
+ const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
532
+ const words2 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
533
+ return words2 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
534
+ }
535
+ })(TaSaid || (TaSaid = {}));
248
536
 
249
537
  // web-src/call-util.ts
250
538
  var LOOK_CHARS = 1500;
@@ -252,7 +540,6 @@ var ENTRY_CHARS = 600;
252
540
  var SEED_CHARS = 1200;
253
541
  var ROLE_CHARS = 800;
254
542
  var LAST_ENTRIES = 12;
255
- var NEWS = "[news]";
256
543
  var QUIET = "-";
257
544
  var FAST = /(mini|flash|haiku|lite|nano|turbo|small|fast|air)\b/i;
258
545
  var CallUtil;
@@ -267,11 +554,12 @@ var CallUtil;
267
554
  "- What needs files, commands, code, research or anything the work does: tell the work (into what it does now, or after it); for something apart from it, open a side conversation with side. Then say in a few words that you did. You cannot do it yourself.",
268
555
  "- Asked how the work goes or about any detail of it: status, then look with a question for the detail; answer from what they return, never guess.",
269
556
  "- When the user wants what the work or a side conversation does stopped: stop.",
557
+ "- When the user wants the call to end (hang up, bye): hang_up, then say goodbye in a few words; the call ends once it is said. Never tell them to hang up themselves.",
270
558
  "- To change Ta itself (its settings, the captions of this call, pin a conversation, turn an extension on or off): app_run yourself, at once, then say in a few words it is done.",
271
- "- When the work waits for the user to decide: read them the question (app_run asks.list), and answer it with what they say (app_run asks.answer); never decide for them.",
272
- "- What only the screen has (what the user looks at, a page of an extension): app_look, app_go, app_do; to show them where something is, with here: true.",
559
+ "- When the work waits for the user to decide: read them the question (app_run asks.list), and answer it with what they say (app_run asks.answer: Ta asks them to agree on their screen, tell them so); never decide for them.",
560
+ "- What only the screen has, or what the user asks you to do on their screen (open a page, press a button, find something they look at): app_look, app_go, app_do on their own screen, the one in front of them, as their shadow; say in a few words what you do as you do it. The call goes on while their screen shows something else.",
273
561
  "- A message that starts with [sent] went to the work already: acknowledge it in a few words.",
274
- `- A message that starts with ${NEWS} is news of the work, not the user speaking: when the user should hear it (a result, a failure, a question for them), say it in one short sentence as you would on the phone, the answer first; else answer ${QUIET} alone.`,
562
+ `- A message marked [ta:notice] is news of the work, not the user speaking: when the user should hear it (a result, a failure, a question for them), say it in one short sentence as you would on the phone, the answer first; else answer ${QUIET} alone. What the user says comes first: when they spoke after news, answer them, and add the news in a few words only if they should hear it and it was not said yet.`,
275
563
  ...seed ? ["", seedText(seed, target.double)] : []
276
564
  ].join(`
277
565
  `);
@@ -323,20 +611,25 @@ ${text}`;
323
611
  return at < 0 ? undefined : role2.slice(at + CALL_MARK.length).trim().split(/\s/)[0] || undefined;
324
612
  }
325
613
  CallUtil.callOf = callOf;
326
- function name(language, called) {
614
+ function name(language, called, said2) {
327
615
  const call = TaLanguageUtil.pick(language, { "zh-CN": "通话", "zh-TW": "通話", "en-US": "Call", "ja-JP": "通話" });
328
- const other = called ? flat(called).slice(0, 40) : "";
329
- return other ? `${call} · ${other}` : call;
616
+ const opening = said2 ? firstSentence(said2) : "";
617
+ const other = called ? flat(called).slice(0, opening ? 20 : 40) : "";
618
+ return [call, other, opening].filter(Boolean).join(" · ");
330
619
  }
331
620
  CallUtil.name = name;
621
+ function firstSentence(text) {
622
+ const [first = ""] = flat(text).split(/(?<=[。!?;!?;])|(?<=\.)\s/);
623
+ return first.replace(/[\s。!?;,、!?;,.]+$/, "").slice(0, 30);
624
+ }
332
625
  function news(lines) {
333
- return [NEWS, ...lines].join(`
334
- `);
626
+ return TaMessageSource.notice(lines.join(`
627
+ `), NAME);
335
628
  }
336
629
  CallUtil.news = news;
337
630
  function toSay(reply) {
338
631
  const said2 = reply?.trim();
339
- return said2 && said2 !== QUIET && !said2.startsWith(NEWS) ? said2 : undefined;
632
+ return said2 && said2 !== QUIET ? said2 : undefined;
340
633
  }
341
634
  CallUtil.toSay = toSay;
342
635
  function ended(name2, how) {
@@ -358,12 +651,16 @@ ${text}`;
358
651
  return sent ? `[sent] ${text}` : text;
359
652
  }
360
653
  CallUtil.said = said;
361
- function model(models, chosen, current) {
362
- if (chosen && models.includes(chosen)) {
654
+ function model(models, chosen, current, agents = []) {
655
+ const own = models.filter((model2) => !agents.includes(model2));
656
+ if (chosen && own.includes(chosen)) {
363
657
  return chosen;
364
658
  }
659
+ const fast = own.filter((model2) => FAST.test(model2.split("/").slice(1).join("/")));
660
+ if (current && agents.includes(current)) {
661
+ return fast[0] ?? own[0];
662
+ }
365
663
  const provider = current?.split("/")[0];
366
- const fast = models.filter((model2) => FAST.test(model2.split("/").slice(1).join("/")));
367
664
  return fast.find((model2) => model2.split("/")[0] === provider) ?? current;
368
665
  }
369
666
  CallUtil.model = model;
@@ -373,12 +670,12 @@ ${text}`;
373
670
  const message = raw;
374
671
  const parts = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content ?? [];
375
672
  if (message.role === "user") {
376
- const text = TaMessageContext.strip(texts(parts)).trim();
673
+ const text = TaSaid.words("user", texts(parts));
377
674
  if (text) {
378
675
  lines.push({ role: "user", text: short(text) });
379
676
  }
380
677
  } else if (message.role === "assistant") {
381
- const text = texts(parts).trim();
678
+ const text = TaSaid.words("assistant", texts(parts));
382
679
  if (text) {
383
680
  lines.push({ role: "assistant", text: short(text) });
384
681
  }
@@ -501,8 +798,14 @@ function activate(pi) {
501
798
  open: async (target) => {
502
799
  const model = await modelFor(pi, target.cwd);
503
800
  const { callId } = await pi.callHost("open", target, model);
801
+ let ending = false;
504
802
  return {
505
- say: (text, options) => pi.callHost("say", callId, text, options?.sent === true),
803
+ say: async (text, options) => {
804
+ const reply = await pi.callHost("say", callId, text, options?.sent === true);
805
+ ending ||= reply.end === true;
806
+ return reply.text;
807
+ },
808
+ ending: () => ending,
506
809
  next: () => pi.callHost("next", callId),
507
810
  close: () => void pi.callHost("close", callId).catch(() => {
508
811
  return;
@@ -511,7 +814,9 @@ function activate(pi) {
511
814
  }
512
815
  });
513
816
  const words = () => CallWords.of(pi.ui.language);
514
- pi.registerChatIcon?.({ icon: (chat) => chat.group === NAME ? { icon: pi.ui.icons.Phone, folder: words().settings } : undefined });
817
+ pi.registerChatIcon?.({
818
+ icon: (chat) => chat.group === NAME ? { icon: pi.ui.icons.Phone, folder: words().settings, quiet: true } : undefined
819
+ });
515
820
  pi.registerSettings({
516
821
  title: () => words().settings,
517
822
  icon: pi.ui.icons.Phone,
@@ -529,7 +834,7 @@ async function modelFor(pi, cwd) {
529
834
  return;
530
835
  })]);
531
836
  const current = settings?.project.model ?? settings?.user.model;
532
- return CallUtil.model(settings?.models ?? [], chosen ?? "", current);
837
+ return CallUtil.model(settings?.models ?? [], chosen ?? "", current, settings?.agents);
533
838
  }
534
839
  function ModelRow({ pi }) {
535
840
  const [value, setValue] = React.useState("");
@@ -541,6 +846,7 @@ function ModelRow({ pi }) {
541
846
  value,
542
847
  defaultLabel: CallWords.of(pi.ui.language).fast,
543
848
  label: CallWords.of(pi.ui.language).model,
849
+ noAgents: true,
544
850
  onChange: (next) => {
545
851
  setValue(next);
546
852
  pi.storage.set(MODEL, next || null);