@celljs/ta-share 4.27.0 → 4.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/host/index.mjs CHANGED
@@ -196,7 +196,7 @@ var RELAY_FEEDBACK_LIMITS = {
196
196
  };
197
197
  var RELAY_FEEDBACK_IMAGE = /^data:(image\/(?:jpeg|png|webp));base64,([A-Za-z0-9+/]+={0,2})$/;
198
198
  var RELAY_FEEDBACK_MODES = ["confirm", "auto", "human"];
199
- var RELAY_FEEDBACK_POLICY = { on: true, cooldownMinutes: 10, daily: 5, open: 10, newDays: 7, imageDays: 30 };
199
+ var RELAY_FEEDBACK_POLICY = { on: true, cooldownMinutes: 10, burst: 10, daily: 20, open: 20, newDays: 7, imageDays: 30 };
200
200
  var RELAY_FEEDBACK_PACE = { mode: "confirm", daily: 3, parallel: 2, tokens: 2000000, from: 9, to: 21, rush: ["security"] };
201
201
  var RelayFeedbackPolicyUtil;
202
202
  (function(RelayFeedbackPolicyUtil2) {
@@ -325,6 +325,7 @@ var RelayFeedbackPolicyUtil;
325
325
  return {
326
326
  on: typeof (given === null || given === undefined ? undefined : given.on) === "boolean" ? given.on : base.on,
327
327
  cooldownMinutes: count(given === null || given === undefined ? undefined : given.cooldownMinutes, base.cooldownMinutes, 0, 24 * 60),
328
+ burst: count(given === null || given === undefined ? undefined : given.burst, base.burst, 1, 50),
328
329
  daily: count(given === null || given === undefined ? undefined : given.daily, base.daily, 1, 100),
329
330
  open: count(given === null || given === undefined ? undefined : given.open, base.open, 1, 100),
330
331
  newDays: count(given === null || given === undefined ? undefined : given.newDays, base.newDays, 0, 90),
@@ -558,7 +559,7 @@ var RelayCloseCode;
558
559
  })(RelayCloseCode || (RelayCloseCode = {}));
559
560
  var RELAY_PING = "ping";
560
561
  var RELAY_PONG = "pong";
561
- var RELAY_PING_MS = 25000;
562
+ var RELAY_WAIT = '{"t":"wait"}';
562
563
  var RELAY_PROOF = "ta-relay ready";
563
564
  var RELAY_HUB_MAX_VALUE = 96 * 1024;
564
565
  var RELAY_HUB_MAX_STATE = 3 * 1024 * 1024;
@@ -790,14 +791,205 @@ var RelayDeflate;
790
791
  }
791
792
  })(RelayDeflate || (RelayDeflate = {}));
792
793
 
794
+ // ../ta-relay/esm/common/relay-direct.js
795
+ var RELAY_DIRECT_MARK = "\x01ta-direct ";
796
+ var RELAY_DIRECT_TIMEOUT_MS = 15000;
797
+ var RELAY_DIRECT_GATHER_MS = 3000;
798
+ var RELAY_DIRECT_PIECE = 16 * 1024;
799
+ var RelayDirectUtil;
800
+ (function(RelayDirectUtil2) {
801
+ function control(text2) {
802
+ if (!text2.startsWith(RELAY_DIRECT_MARK)) {
803
+ return;
804
+ }
805
+ try {
806
+ const message = JSON.parse(text2.slice(RELAY_DIRECT_MARK.length));
807
+ return message && typeof message === "object" && typeof message.t === "string" ? message : undefined;
808
+ } catch (_a) {
809
+ return;
810
+ }
811
+ }
812
+ RelayDirectUtil2.control = control;
813
+ function text(message) {
814
+ return RELAY_DIRECT_MARK + JSON.stringify(message);
815
+ }
816
+ RelayDirectUtil2.text = text;
817
+ function stun(list) {
818
+ const found = (Array.isArray(list) ? list : []).filter((each) => typeof each === "string" && /^stuns?:[^\s]+$/.test(each));
819
+ return [...new Set(found)].slice(0, 4);
820
+ }
821
+ RelayDirectUtil2.stun = stun;
822
+ function pieces(frame) {
823
+ const out = [];
824
+ for (let at = 0;at < frame.length || at === 0; at += RELAY_DIRECT_PIECE) {
825
+ const end = at + RELAY_DIRECT_PIECE >= frame.length;
826
+ out.push((end ? "." : "+") + frame.slice(at, at + RELAY_DIRECT_PIECE));
827
+ if (end) {
828
+ break;
829
+ }
830
+ }
831
+ return out;
832
+ }
833
+ RelayDirectUtil2.pieces = pieces;
834
+
835
+ class Joiner {
836
+ constructor(max = 32 * 1024 * 1024) {
837
+ this.max = max;
838
+ this.parts = [];
839
+ this.size = 0;
840
+ }
841
+ take(piece) {
842
+ const kind = piece[0];
843
+ if (kind !== "+" && kind !== ".") {
844
+ throw new Error("Not a piece of a frame.");
845
+ }
846
+ this.size += piece.length - 1;
847
+ if (this.size > this.max) {
848
+ throw new Error("A frame too large.");
849
+ }
850
+ this.parts.push(piece.slice(1));
851
+ if (kind === "+") {
852
+ return;
853
+ }
854
+ const frame = this.parts.join("");
855
+ this.parts = [];
856
+ this.size = 0;
857
+ return frame;
858
+ }
859
+ }
860
+ RelayDirectUtil2.Joiner = Joiner;
861
+ })(RelayDirectUtil || (RelayDirectUtil = {}));
862
+
863
+ // ../ta-relay/esm/common/relay-direct-link.js
864
+ class RelayDirectLink {
865
+ constructor(options, hooks, rtc) {
866
+ this.hooks = hooks;
867
+ this.joiner = new RelayDirectUtil.Joiner;
868
+ this.early = [];
869
+ this.closed = false;
870
+ this.sending = false;
871
+ this.taking = false;
872
+ this.pc = new rtc({ iceServers: options.stun.map((urls) => ({ urls })) });
873
+ this.channel = this.pc.createDataChannel("ta", { ordered: true });
874
+ this.channel.onopen = () => {
875
+ if (!this.closed) {
876
+ clearTimeout(this.timer);
877
+ this.hooks.moved();
878
+ }
879
+ };
880
+ this.channel.onmessage = (event) => this.piece(String(event.data));
881
+ this.channel.onclose = () => this.gone();
882
+ this.pc.onconnectionstatechange = () => {
883
+ if (this.pc.connectionState === "failed" || this.pc.connectionState === "closed") {
884
+ this.gone();
885
+ }
886
+ };
887
+ this.timer = setTimeout(() => this.close(), RELAY_DIRECT_TIMEOUT_MS);
888
+ }
889
+ static available(rtc = globalThis.RTCPeerConnection) {
890
+ return typeof rtc === "function";
891
+ }
892
+ async offer() {
893
+ var _a;
894
+ try {
895
+ await this.pc.setLocalDescription(await this.pc.createOffer());
896
+ await this.gathered();
897
+ const sdp = (_a = this.pc.localDescription) === null || _a === undefined ? undefined : _a.sdp;
898
+ if (sdp && !this.closed) {
899
+ this.hooks.control({ t: "offer", sdp });
900
+ }
901
+ } catch (_b) {
902
+ this.close();
903
+ }
904
+ }
905
+ async control(message) {
906
+ if (this.closed) {
907
+ return;
908
+ }
909
+ if (message.t === "answer") {
910
+ await this.pc.setRemoteDescription({ type: "answer", sdp: message.sdp }).catch(() => this.close());
911
+ } else if (message.t === "switch") {
912
+ this.taking = true;
913
+ for (const frame of this.early.splice(0)) {
914
+ this.hooks.frame(frame);
915
+ }
916
+ } else if (message.t === "off") {
917
+ this.close();
918
+ }
919
+ }
920
+ send(frame) {
921
+ for (const piece of RelayDirectUtil.pieces(frame)) {
922
+ this.channel.send(piece);
923
+ }
924
+ }
925
+ close() {
926
+ if (this.closed) {
927
+ return;
928
+ }
929
+ this.closed = true;
930
+ clearTimeout(this.timer);
931
+ this.channel.onclose = null;
932
+ try {
933
+ this.channel.close();
934
+ this.pc.close();
935
+ } catch (_a) {}
936
+ }
937
+ piece(piece) {
938
+ let frame;
939
+ try {
940
+ frame = this.joiner.take(piece);
941
+ } catch (_a) {
942
+ this.gone();
943
+ return;
944
+ }
945
+ if (frame === undefined || this.closed) {
946
+ return;
947
+ }
948
+ if (this.taking) {
949
+ this.hooks.frame(frame);
950
+ } else {
951
+ this.early.push(frame);
952
+ }
953
+ }
954
+ gone() {
955
+ if (this.closed) {
956
+ return;
957
+ }
958
+ const moved = this.sending || this.taking;
959
+ this.close();
960
+ if (moved) {
961
+ this.hooks.lost();
962
+ }
963
+ }
964
+ gathered() {
965
+ if (this.pc.iceGatheringState === "complete") {
966
+ return Promise.resolve();
967
+ }
968
+ return new Promise((resolve) => {
969
+ const timer = setTimeout(resolve, RELAY_DIRECT_GATHER_MS);
970
+ this.pc.onicegatheringstatechange = () => {
971
+ if (this.pc.iceGatheringState === "complete") {
972
+ clearTimeout(timer);
973
+ resolve();
974
+ }
975
+ };
976
+ });
977
+ }
978
+ }
979
+
793
980
  // ../ta-relay/esm/common/relay-pairing.js
981
+ var MAX_ROUTES = 8;
794
982
  var RelayPairingUtil;
795
983
  (function(RelayPairingUtil2) {
796
984
  function link(pairing) {
985
+ var _a;
797
986
  const fragment = new URLSearchParams({ v: "1", h: pairing.host, d: pairing.device, k: pairing.key });
798
987
  if (pairing.name) {
799
988
  fragment.set("n", pairing.name);
800
989
  }
990
+ for (const relay of (_a = pairing.relays) !== null && _a !== undefined ? _a : []) {
991
+ fragment.append("r", relay);
992
+ }
801
993
  return `${pairing.relay}${RELAY_PAIR_PATH}#${fragment}`;
802
994
  }
803
995
  RelayPairingUtil2.link = link;
@@ -812,9 +1004,28 @@ var RelayPairingUtil;
812
1004
  if (!/^https?:$/.test(url.protocol) || url.pathname !== RELAY_PAIR_PATH || fragment.get("v") !== "1" || !RELAY_ID.test(host) || !RELAY_ID.test(device) || !/^[A-Za-z0-9_-]{43}$/.test(key)) {
813
1005
  throw new Error("Not a pairing link of Ta.");
814
1006
  }
815
- return { relay: url.origin, host, device, key, name: (_a = fragment.get("n")) !== null && _a !== undefined ? _a : undefined };
1007
+ const relays = routes(fragment.getAll("r"));
1008
+ return { relay: url.origin, host, device, key, name: (_a = fragment.get("n")) !== null && _a !== undefined ? _a : undefined, ...relays.length ? { relays } : {} };
816
1009
  }
817
1010
  RelayPairingUtil2.parse = parse;
1011
+ function routes(list) {
1012
+ const found = [];
1013
+ for (const each of Array.isArray(list) ? list : []) {
1014
+ try {
1015
+ const url = new URL(String(each));
1016
+ if (/^https?:$/.test(url.protocol) && !found.includes(url.origin)) {
1017
+ found.push(url.origin);
1018
+ }
1019
+ } catch (_a) {}
1020
+ }
1021
+ return found.slice(0, MAX_ROUTES);
1022
+ }
1023
+ RelayPairingUtil2.routes = routes;
1024
+ function ways(pairing) {
1025
+ var _a;
1026
+ return routes([...(_a = pairing.relays) !== null && _a !== undefined ? _a : [], pairing.relay]);
1027
+ }
1028
+ RelayPairingUtil2.ways = ways;
818
1029
  function websocketUrl(relay, path) {
819
1030
  return relay.replace(/^http/, "ws") + path;
820
1031
  }
@@ -827,6 +1038,8 @@ var OPEN = 1;
827
1038
  var CLOSING = 2;
828
1039
  var CLOSED = 3;
829
1040
  var HELLO_MS = 15000;
1041
+ var WAIT_MS = 60000;
1042
+ var DEVICE_PING_MS = 1e4;
830
1043
 
831
1044
  class RelaySocket {
832
1045
  constructor(pairing, options = {}) {
@@ -837,6 +1050,7 @@ class RelaySocket {
837
1050
  this.onmessage = null;
838
1051
  this.onclose = null;
839
1052
  this.onerror = null;
1053
+ this.onwait = null;
840
1054
  this.state = CONNECTING;
841
1055
  this.nonce = RelayBytes.random(16);
842
1056
  this.ponged = false;
@@ -851,10 +1065,11 @@ class RelaySocket {
851
1065
  v: 1,
852
1066
  device: pairing.device,
853
1067
  nonce: RelayBytes.toBase64(this.nonce),
854
- ...RelayDeflate.supported() ? { z: 1 } : {}
1068
+ ...RelayDeflate.supported() ? { z: 1 } : {},
1069
+ ...options.wait ? { w: 1 } : {}
855
1070
  };
856
1071
  this.socket.send(JSON.stringify(hello));
857
- this.pingTimer = setInterval(() => this.ping(), (_a2 = options.pingMs) !== null && _a2 !== undefined ? _a2 : RELAY_PING_MS);
1072
+ this.pingTimer = setInterval(() => this.ping(), (_a2 = options.pingMs) !== null && _a2 !== undefined ? _a2 : DEVICE_PING_MS);
858
1073
  };
859
1074
  this.socket.onmessage = (message) => {
860
1075
  const text = String(message.data);
@@ -877,11 +1092,55 @@ class RelaySocket {
877
1092
  get closeCode() {
878
1093
  return this.code;
879
1094
  }
1095
+ get path() {
1096
+ var _a;
1097
+ return ((_a = this.link) === null || _a === undefined ? undefined : _a.sending) ? "direct" : "relay";
1098
+ }
880
1099
  send(text) {
881
1100
  if (this.state !== OPEN || !this.cipher) {
882
1101
  throw new Error("The connection is not open.");
883
1102
  }
884
- this.cipher.seal(text).then((frame) => this.socket.readyState === OPEN && this.socket.send(frame));
1103
+ this.cipher.seal(text).then((frame) => this.transmit(frame));
1104
+ }
1105
+ direct(options) {
1106
+ var _a;
1107
+ const rtc = (_a = this.options.rtc) !== null && _a !== undefined ? _a : globalThis.RTCPeerConnection;
1108
+ if (this.link || this.state !== OPEN || !RelayDirectLink.available(rtc) || !options.stun) {
1109
+ return;
1110
+ }
1111
+ this.link = new RelayDirectLink(options, {
1112
+ control: (message) => this.control(message),
1113
+ moved: () => {
1114
+ var _a2;
1115
+ (_a2 = this.cipher) === null || _a2 === undefined || _a2.seal(RelayDirectUtil.text({ t: "switch" })).then((frame) => {
1116
+ this.transmit(frame);
1117
+ if (this.link) {
1118
+ this.link.sending = true;
1119
+ }
1120
+ });
1121
+ },
1122
+ frame: (frame) => {
1123
+ this.receiving = this.receiving.then(() => this.receive(frame));
1124
+ },
1125
+ lost: () => this.drop(RelayCloseCode.TIMEOUT, "The direct connection was lost.")
1126
+ }, rtc);
1127
+ this.link.offer();
1128
+ }
1129
+ transmit(frame) {
1130
+ var _a;
1131
+ if ((_a = this.link) === null || _a === undefined ? undefined : _a.sending) {
1132
+ try {
1133
+ this.link.send(frame);
1134
+ } catch (_b) {
1135
+ this.drop(RelayCloseCode.TIMEOUT, "The direct connection was lost.");
1136
+ }
1137
+ } else if (this.socket.readyState === OPEN) {
1138
+ this.socket.send(frame);
1139
+ }
1140
+ }
1141
+ control(message) {
1142
+ var _a;
1143
+ (_a = this.cipher) === null || _a === undefined || _a.seal(RelayDirectUtil.text(message)).then((frame) => this.transmit(frame));
885
1144
  }
886
1145
  close(code = 1000, reason = "") {
887
1146
  if (this.state === CLOSED) {
@@ -891,7 +1150,8 @@ class RelaySocket {
891
1150
  this.socket.close(code, reason);
892
1151
  }
893
1152
  async receive(text) {
894
- var _a, _b;
1153
+ var _a, _b, _c, _d, _e, _f;
1154
+ var _g;
895
1155
  if (this.cipher) {
896
1156
  if (this.options.proveFirst && text.startsWith("{")) {
897
1157
  this.drop(RelaySocket.REFUSED, RelaySocket.refusal(text));
@@ -899,12 +1159,23 @@ class RelaySocket {
899
1159
  }
900
1160
  try {
901
1161
  const data = await this.cipher.open(text);
902
- (_a = this.onmessage) === null || _a === undefined || _a.call(this, { data });
903
- } catch (_c) {
1162
+ const direct = RelayDirectUtil.control(data);
1163
+ if (direct) {
1164
+ await ((_a = this.link) === null || _a === undefined ? undefined : _a.control(direct));
1165
+ return;
1166
+ }
1167
+ (_b = this.onmessage) === null || _b === undefined || _b.call(this, { data });
1168
+ } catch (_h) {
904
1169
  this.close(4400, "A message did not open.");
905
1170
  }
906
1171
  return;
907
1172
  }
1173
+ if (text === RELAY_WAIT && this.options.wait) {
1174
+ clearTimeout(this.helloTimer);
1175
+ this.helloTimer = setTimeout(() => this.drop(RelayCloseCode.HOST_OFFLINE, "The host did not come back."), (_g = this.options.waitMs) !== null && _g !== undefined ? _g : WAIT_MS);
1176
+ (_c = this.onwait) === null || _c === undefined || _c.call(this);
1177
+ return;
1178
+ }
908
1179
  try {
909
1180
  const welcome = JSON.parse(text);
910
1181
  if (welcome.t !== "ready") {
@@ -921,8 +1192,12 @@ class RelaySocket {
921
1192
  this.cipher = cipher;
922
1193
  clearTimeout(this.helloTimer);
923
1194
  this.state = OPEN;
924
- (_b = this.onopen) === null || _b === undefined || _b.call(this);
925
- } catch (_d) {
1195
+ (_d = this.onopen) === null || _d === undefined || _d.call(this);
1196
+ const direct = this.state === OPEN ? (_f = (_e = this.options).direct) === null || _f === undefined ? undefined : _f.call(_e) : undefined;
1197
+ if (direct) {
1198
+ this.direct(direct);
1199
+ }
1200
+ } catch (_j) {
926
1201
  this.drop(RelaySocket.REFUSED, "The host refused this device.");
927
1202
  }
928
1203
  }
@@ -949,15 +1224,16 @@ class RelaySocket {
949
1224
  this.finish(code, reason);
950
1225
  }
951
1226
  finish(code, reason) {
952
- var _a;
1227
+ var _a, _b;
953
1228
  if (this.state === CLOSED) {
954
1229
  return;
955
1230
  }
956
1231
  clearTimeout(this.helloTimer);
957
1232
  clearInterval(this.pingTimer);
1233
+ (_a = this.link) === null || _a === undefined || _a.close();
958
1234
  this.state = CLOSED;
959
1235
  this.code = code;
960
- (_a = this.onclose) === null || _a === undefined || _a.call(this, { code, reason });
1236
+ (_b = this.onclose) === null || _b === undefined || _b.call(this, { code, reason });
961
1237
  }
962
1238
  }
963
1239
  RelaySocket.CONNECTING = CONNECTING;
@@ -2208,6 +2484,40 @@ var TaAgentSummary;
2208
2484
  }
2209
2485
  TaAgentSummary2.strip = strip;
2210
2486
  })(TaAgentSummary || (TaAgentSummary = {}));
2487
+ var TaPictureNote;
2488
+ (function(TaPictureNote2) {
2489
+ TaPictureNote2.OPEN = "<pictures>";
2490
+ TaPictureNote2.CLOSE = "</pictures>";
2491
+ const BLOCK = /[ \t]*<pictures>([\s\S]*?)(?:<\/pictures>|$)|<p(?:i(?:c(?:t(?:u(?:r(?:es?)?)?)?)?)?)?$/gi;
2492
+ const ROW = /(?:^|\s)[-*]?\s*p(\d+)\s*[::]\s*/gi;
2493
+ function take(text) {
2494
+ const told = new Map;
2495
+ if (!/<p/i.test(text)) {
2496
+ return { said: text, told };
2497
+ }
2498
+ const said = text.replace(BLOCK, (_all, body) => {
2499
+ const rows = [...(body !== null && body !== undefined ? body : "").matchAll(ROW)];
2500
+ rows.forEach((row, index) => {
2501
+ var _a;
2502
+ var _b, _c;
2503
+ const end = (_b = (_a = rows[index + 1]) === null || _a === undefined ? undefined : _a.index) !== null && _b !== undefined ? _b : body === null || body === undefined ? undefined : body.length;
2504
+ const what = body === null || body === undefined ? undefined : body.slice(((_c = row.index) !== null && _c !== undefined ? _c : 0) + row[0].length, end).trim();
2505
+ if (what) {
2506
+ told.set(Number(row[1]), what);
2507
+ }
2508
+ });
2509
+ return "";
2510
+ });
2511
+ return { said: said === text ? text : said.replace(/\n{3,}/g, `
2512
+
2513
+ `).trim(), told };
2514
+ }
2515
+ TaPictureNote2.take = take;
2516
+ function strip(text) {
2517
+ return take(text).said;
2518
+ }
2519
+ TaPictureNote2.strip = strip;
2520
+ })(TaPictureNote || (TaPictureNote = {}));
2211
2521
  var TaSkillUse;
2212
2522
  (function(TaSkillUse2) {
2213
2523
  const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
@@ -2325,7 +2635,8 @@ var TaSaid;
2325
2635
  ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
2326
2636
  ["skill", /<skill name="|<\/skill>/],
2327
2637
  ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
2328
- ["summary", /<\/?(?:conversation_history_summary|summary)>/]
2638
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/],
2639
+ ["pictures described", /<\/?pictures>/]
2329
2640
  ];
2330
2641
  function text(content, joiner = `
2331
2642
  `) {
@@ -2336,7 +2647,7 @@ var TaSaid;
2336
2647
  }
2337
2648
  TaSaid2.text = text;
2338
2649
  function words(role, text2, options = {}) {
2339
- const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
2650
+ const said = role === "user" ? userWords(text2) : TaPictureNote.strip(TaAgentSummary.strip(text2));
2340
2651
  return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
2341
2652
  }
2342
2653
  TaSaid2.words = words;
@@ -2455,6 +2766,17 @@ Switched to voice.`, said: "Switched to voice." },
2455
2766
  { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
2456
2767
  { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
2457
2768
  { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
2769
+ {
2770
+ mark: "pictures described after the answer",
2771
+ role: "assistant",
2772
+ text: `The left one.
2773
+
2774
+ <pictures> p1: two cats on a sofa. p2: a chart of sales, "Q4". </pictures>`,
2775
+ said: "The left one."
2776
+ },
2777
+ { mark: "pictures described as it streams", role: "assistant", text: `The left one.
2778
+ <pictures>
2779
+ p1: two ca`, said: "The left one." },
2458
2780
  { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
2459
2781
  </system-reminder>
2460
2782
  Ready.`, said: "Ready." }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-share",
3
- "version": "4.27.0",
3
+ "version": "4.29.0",
4
4
  "description": "A pi package for Ta: share a conversation, a page or a file by a link, public, with a password or for yourself, end to end through the relay; open and import what others share",
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.27.0",
31
- "@celljs/ta-relay": "4.27.0",
32
- "@celljs/ta-web": "4.27.0",
30
+ "@celljs/ta-protocol": "4.29.0",
31
+ "@celljs/ta-relay": "4.29.0",
32
+ "@celljs/ta-web": "4.29.0",
33
33
  "@types/react": "^19.3.0"
34
34
  },
35
35
  "publishConfig": {
package/web/index.js CHANGED
@@ -1535,6 +1535,40 @@ var TaAgentSummary;
1535
1535
  }
1536
1536
  TaAgentSummary2.strip = strip;
1537
1537
  })(TaAgentSummary || (TaAgentSummary = {}));
1538
+ var TaPictureNote;
1539
+ (function(TaPictureNote2) {
1540
+ TaPictureNote2.OPEN = "<pictures>";
1541
+ TaPictureNote2.CLOSE = "</pictures>";
1542
+ const BLOCK = /[ \t]*<pictures>([\s\S]*?)(?:<\/pictures>|$)|<p(?:i(?:c(?:t(?:u(?:r(?:es?)?)?)?)?)?)?$/gi;
1543
+ const ROW = /(?:^|\s)[-*]?\s*p(\d+)\s*[::]\s*/gi;
1544
+ function take(text) {
1545
+ const told = new Map;
1546
+ if (!/<p/i.test(text)) {
1547
+ return { said: text, told };
1548
+ }
1549
+ const said = text.replace(BLOCK, (_all, body) => {
1550
+ const rows = [...(body !== null && body !== undefined ? body : "").matchAll(ROW)];
1551
+ rows.forEach((row, index) => {
1552
+ var _a;
1553
+ var _b, _c;
1554
+ const end = (_b = (_a = rows[index + 1]) === null || _a === undefined ? undefined : _a.index) !== null && _b !== undefined ? _b : body === null || body === undefined ? undefined : body.length;
1555
+ const what = body === null || body === undefined ? undefined : body.slice(((_c = row.index) !== null && _c !== undefined ? _c : 0) + row[0].length, end).trim();
1556
+ if (what) {
1557
+ told.set(Number(row[1]), what);
1558
+ }
1559
+ });
1560
+ return "";
1561
+ });
1562
+ return { said: said === text ? text : said.replace(/\n{3,}/g, `
1563
+
1564
+ `).trim(), told };
1565
+ }
1566
+ TaPictureNote2.take = take;
1567
+ function strip(text) {
1568
+ return take(text).said;
1569
+ }
1570
+ TaPictureNote2.strip = strip;
1571
+ })(TaPictureNote || (TaPictureNote = {}));
1538
1572
  var TaSkillUse;
1539
1573
  (function(TaSkillUse2) {
1540
1574
  const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
@@ -1652,7 +1686,8 @@ var TaSaid;
1652
1686
  ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
1653
1687
  ["skill", /<skill name="|<\/skill>/],
1654
1688
  ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
1655
- ["summary", /<\/?(?:conversation_history_summary|summary)>/]
1689
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/],
1690
+ ["pictures described", /<\/?pictures>/]
1656
1691
  ];
1657
1692
  function text(content, joiner = `
1658
1693
  `) {
@@ -1663,7 +1698,7 @@ var TaSaid;
1663
1698
  }
1664
1699
  TaSaid2.text = text;
1665
1700
  function words(role, text2, options = {}) {
1666
- const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
1701
+ const said = role === "user" ? userWords(text2) : TaPictureNote.strip(TaAgentSummary.strip(text2));
1667
1702
  return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
1668
1703
  }
1669
1704
  TaSaid2.words = words;
@@ -1782,6 +1817,17 @@ Switched to voice.`, said: "Switched to voice." },
1782
1817
  { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
1783
1818
  { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
1784
1819
  { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
1820
+ {
1821
+ mark: "pictures described after the answer",
1822
+ role: "assistant",
1823
+ text: `The left one.
1824
+
1825
+ <pictures> p1: two cats on a sofa. p2: a chart of sales, "Q4". </pictures>`,
1826
+ said: "The left one."
1827
+ },
1828
+ { mark: "pictures described as it streams", role: "assistant", text: `The left one.
1829
+ <pictures>
1830
+ p1: two ca`, said: "The left one." },
1785
1831
  { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
1786
1832
  </system-reminder>
1787
1833
  Ready.`, said: "Ready." }