@celljs/ta-channels 4.17.0 → 4.19.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.
@@ -92,6 +92,255 @@ var TaAskUtil;
92
92
  }
93
93
  })(TaAskUtil || (TaAskUtil = {}));
94
94
 
95
+ // ../ta-relay/esm/common/relay-faces.js
96
+ var FACE_COUNT = 25;
97
+ var BLUE = "#4285F4";
98
+ var RED = "#EA4335";
99
+ var YELLOW = "#FBBC05";
100
+ var GREEN = "#34A853";
101
+ var MINT = "#5CC27F";
102
+ var ORANGE = "#EE7B3B";
103
+ var VIOLET = "#8C5CF0";
104
+ var CREAM = "#F1DFC0";
105
+ var TEAL = "#26B0A9";
106
+ var PINK = "#F27BA6";
107
+ var LILAC = "#B49CF5";
108
+ var SKY = "#45B5E8";
109
+ var INDIGO = "#5C6BC0";
110
+ var MIST = "#DCE3F0";
111
+ var INK = "#202124";
112
+ var WHITE = "#FFFFFF";
113
+ var CHEEK = "rgba(255, 160, 185, 0.55)";
114
+ var EDGE = "rgba(0, 0, 0, 0.14)";
115
+ var CHEEK_DEEP = "rgba(120, 10, 30, 0.35)";
116
+ var CHEEK_WARM = "rgba(234, 67, 53, 0.4)";
117
+ var LOOKS = [
118
+ { color: MINT, eye: "#1D3B27", cheek: CHEEK, eyeY: 21, gap: 8 },
119
+ { color: BLUE, eye: WHITE, cheek: CHEEK, eyeY: 23, gap: 8 },
120
+ { color: RED, eye: WHITE, cheek: CHEEK_DEEP, eyeY: 22, gap: 8 },
121
+ { color: CREAM, eye: "#4A3420", cheek: "rgba(240, 120, 120, 0.5)", accent: "#DDBF8E", eyeY: 22, gap: 7.6 },
122
+ { color: GREEN, eye: WHITE, cheek: CHEEK, eyeY: 19, gap: 7.2 },
123
+ { color: INDIGO, eye: WHITE, cheek: CHEEK, eyeY: 20, gap: 7.4 },
124
+ { color: YELLOW, eye: INK, cheek: CHEEK_WARM, accent: "#F29900", eyeY: 24, gap: 8.4 },
125
+ { color: VIOLET, eye: "#22134A", cheek: CHEEK, eyeY: 20, gap: 8 },
126
+ { color: MIST, eye: "#2B3245", cheek: CHEEK, eyeY: 19, gap: 7.6 },
127
+ { color: SKY, eye: WHITE, cheek: CHEEK, eyeY: 21, gap: 6.4 },
128
+ { color: ORANGE, eye: "#3D1C08", cheek: CHEEK, accent: GREEN, eyeY: 22, gap: 8.6, brows: true },
129
+ { color: WHITE, eye: WHITE, cheek: CHEEK, accent: INK, mouth: INK, eyeY: 22, gap: 10 },
130
+ { color: TEAL, eye: WHITE, cheek: CHEEK, accent: "#1B8A84", eyeY: 22.5, gap: 8.4 },
131
+ { color: PINK, eye: "#4A1428", cheek: "rgba(160, 20, 70, 0.3)", eyeY: 24, gap: 7.4 },
132
+ { color: LILAC, eye: "#2A1A5E", cheek: CHEEK, eyeY: 25, gap: 8 },
133
+ { color: YELLOW, eye: INK, cheek: CHEEK_WARM, eyeY: 25, gap: 7.4 },
134
+ { color: BLUE, eye: WHITE, cheek: CHEEK, eyeY: 19.5, gap: 8 },
135
+ { color: CREAM, eye: "#4A3420", cheek: "rgba(240, 120, 120, 0.5)", eyeY: 23.5, gap: 8 },
136
+ { color: GREEN, eye: WHITE, cheek: CHEEK, eyeY: 21, gap: 8 },
137
+ { color: PINK, eye: "#4A1428", cheek: "rgba(160, 20, 70, 0.3)", eyeY: 19.5, gap: 8.4 },
138
+ { color: RED, eye: WHITE, cheek: CHEEK_DEEP, accent: "#B3261E", eyeY: 20, gap: 8.4 },
139
+ { color: SKY, eye: WHITE, cheek: CHEEK, eyeY: 23.5, gap: 8 },
140
+ { color: VIOLET, eye: WHITE, cheek: CHEEK, accent: "#6B3FD4", eyeY: 22, gap: 8 },
141
+ { color: TEAL, eye: WHITE, cheek: CHEEK, accent: "#1B8A84", eyeY: 25, gap: 7.6 },
142
+ { color: MINT, eye: "#1D3B27", cheek: CHEEK, accent: "#4AAE6C", eyeY: 22.5, gap: 9 }
143
+ ];
144
+ function corners(count, radius, cx, cy, inner) {
145
+ const points = [];
146
+ const steps = inner ? count * 2 : count;
147
+ for (let index = 0;index < steps; index++) {
148
+ const r = inner && index % 2 === 1 ? inner : radius;
149
+ const angle = -Math.PI / 2 + index * 2 * Math.PI / steps;
150
+ points.push(`${(cx + r * Math.cos(angle)).toFixed(2)},${(cy + r * Math.sin(angle)).toFixed(2)}`);
151
+ }
152
+ return points.join(" ");
153
+ }
154
+ var PENTAGON = corners(5, 13.5, 20, 21.5);
155
+ var HEXAGON = corners(6, 14, 20, 20);
156
+ var STAR = corners(5, 15.5, 20, 21.5, 8.6);
157
+ function node(tag, attrs, children) {
158
+ return children ? { tag, attrs, children } : { tag, attrs };
159
+ }
160
+ function rounded(points, color, width = 5) {
161
+ return node("polygon", { points, fill: color, stroke: color, "stroke-width": width, "stroke-linejoin": "round" });
162
+ }
163
+ function shape(face, look) {
164
+ const { color, accent = color } = look;
165
+ switch (face) {
166
+ case 1:
167
+ return node("g", {}, [
168
+ rounded("7.5,6.5 17,12 8.5,18", color, 4),
169
+ rounded("32.5,6.5 23,12 31.5,18", color, 4),
170
+ node("ellipse", { cx: 20, cy: 23, rx: 14.5, ry: 12.5, fill: color })
171
+ ]);
172
+ case 2:
173
+ return rounded(PENTAGON, color);
174
+ case 3:
175
+ return node("g", {}, [
176
+ node("circle", { cx: 9.5, cy: 10.5, r: 5.5, fill: color }),
177
+ node("circle", { cx: 30.5, cy: 10.5, r: 5.5, fill: color }),
178
+ node("circle", { cx: 9.5, cy: 10.5, r: 2.6, fill: accent }),
179
+ node("circle", { cx: 30.5, cy: 10.5, r: 2.6, fill: accent }),
180
+ node("ellipse", { cx: 20, cy: 22.5, rx: 14.5, ry: 13, fill: color })
181
+ ]);
182
+ case 4:
183
+ return node("rect", { x: 8.5, y: 4, width: 23, height: 32, rx: 11.5, fill: color });
184
+ case 5:
185
+ return rounded("20,5.5 34.5,20 20,34.5 5.5,20", color, 5.5);
186
+ case 6:
187
+ return node("g", {}, [
188
+ node("ellipse", { cx: 20, cy: 11, rx: 3.2, ry: 3.6, fill: accent }),
189
+ node("path", { d: "M20 12.5c9.2 0 15.5 5.6 15.5 12.4 0 6.4-6.9 10.1-15.5 10.1S4.5 31.3 4.5 24.9C4.5 18.1 10.8 12.5 20 12.5Z", fill: color })
190
+ ]);
191
+ case 7:
192
+ return rounded(HEXAGON, color);
193
+ case 8:
194
+ return node("path", {
195
+ d: "M8 19a12 12 0 0 1 24 0v14l-4-3-4 3-4-3-4 3-4-3-4 3Z",
196
+ fill: color,
197
+ stroke: EDGE,
198
+ "stroke-width": 0.8,
199
+ "stroke-linejoin": "round"
200
+ });
201
+ case 9:
202
+ return rounded(STAR, color, 4.5);
203
+ case 10:
204
+ return node("g", {}, [
205
+ node("rect", { x: 18.6, y: 4.5, width: 2.8, height: 7, rx: 1.4, fill: accent }),
206
+ node("ellipse", { cx: 12.5, cy: 23, rx: 8.5, ry: 11, fill: color }),
207
+ node("ellipse", { cx: 27.5, cy: 23, rx: 8.5, ry: 11, fill: color }),
208
+ node("ellipse", { cx: 20, cy: 22.5, rx: 9.5, ry: 12, fill: color })
209
+ ]);
210
+ case 11:
211
+ return node("g", {}, [
212
+ node("circle", { cx: 9.5, cy: 10, r: 5, fill: accent }),
213
+ node("circle", { cx: 30.5, cy: 10, r: 5, fill: accent }),
214
+ node("ellipse", { cx: 20, cy: 22.5, rx: 14.5, ry: 13, fill: color, stroke: EDGE, "stroke-width": 0.8 }),
215
+ node("ellipse", { cx: 14.6, cy: 22, rx: 3.6, ry: 4.4, transform: "rotate(20 14.6 22)", fill: accent }),
216
+ node("ellipse", { cx: 25.4, cy: 22, rx: 3.6, ry: 4.4, transform: "rotate(-20 25.4 22)", fill: accent })
217
+ ]);
218
+ case 12:
219
+ return node("g", {}, [
220
+ node("rect", { x: 19.1, y: 6, width: 1.8, height: 7, fill: accent }),
221
+ node("circle", { cx: 20, cy: 5, r: 2.2, fill: accent }),
222
+ node("rect", { x: 5.5, y: 12, width: 29, height: 22.5, rx: 6.5, fill: color })
223
+ ]);
224
+ case 13:
225
+ return node("path", { d: "M20 4.5c2 0 13 11.6 13 20.2 0 6.4-5.8 10.8-13 10.8S7 31.1 7 24.7C7 16.1 18 4.5 20 4.5Z", fill: color });
226
+ case 14:
227
+ return node("g", {}, [
228
+ node("ellipse", { cx: 14, cy: 10.5, rx: 3.6, ry: 8, transform: "rotate(-8 14 10.5)", fill: color }),
229
+ node("ellipse", { cx: 26, cy: 10.5, rx: 3.6, ry: 8, transform: "rotate(8 26 10.5)", fill: color }),
230
+ node("ellipse", { cx: 20, cy: 25, rx: 14, ry: 11, fill: color })
231
+ ]);
232
+ case 15:
233
+ return rounded("20,7 35,33 5,33", color, 6);
234
+ case 16:
235
+ return node("path", {
236
+ d: "M20 6.5l12 4.2v8.4c0 7.4-4.9 12.6-12 15.9-7.1-3.3-12-8.5-12-15.9v-8.4Z",
237
+ fill: color,
238
+ stroke: color,
239
+ "stroke-width": 3,
240
+ "stroke-linejoin": "round"
241
+ });
242
+ case 17:
243
+ return rounded("20,7 32.5,17.5 32.5,33 7.5,33 7.5,17.5", color, 4.5);
244
+ case 18:
245
+ return rounded("14,9 26,9 32.5,32 7.5,32", color, 6);
246
+ case 19:
247
+ return node("rect", { x: 4.5, y: 10.5, width: 31, height: 19.5, rx: 9.75, fill: color });
248
+ case 20:
249
+ return node("g", {}, [
250
+ node("rect", { x: 14, y: 5.5, width: 12, height: 4.5, rx: 1.6, fill: accent }),
251
+ node("rect", { x: 14, y: 30.5, width: 12, height: 4.5, rx: 1.6, fill: accent }),
252
+ node("ellipse", { cx: 20, cy: 20.25, rx: 15, ry: 12.25, fill: color })
253
+ ]);
254
+ case 21:
255
+ return node("g", {}, [
256
+ node("circle", { cx: 13.5, cy: 21.5, r: 7, fill: color }),
257
+ node("circle", { cx: 21.5, cy: 16.5, r: 9, fill: color }),
258
+ node("circle", { cx: 28.5, cy: 22.5, r: 6.5, fill: color }),
259
+ node("rect", { x: 5.5, y: 21, width: 29, height: 12, rx: 6, fill: color })
260
+ ]);
261
+ case 22:
262
+ return node("g", {}, [
263
+ node("rect", { x: 12.5, y: 5.5, width: 15, height: 5.5, rx: 2, fill: accent }),
264
+ node("rect", { x: 7.5, y: 9.5, width: 25, height: 25.5, rx: 6.5, fill: color })
265
+ ]);
266
+ case 23:
267
+ return node("g", {}, [
268
+ node("rect", { x: 18.8, y: 3.5, width: 2.4, height: 6, rx: 1.2, fill: accent }),
269
+ node("circle", { cx: 20, cy: 13, r: 6.5, fill: color }),
270
+ node("circle", { cx: 20, cy: 25, r: 11.5, fill: color })
271
+ ]);
272
+ case 24:
273
+ return node("g", {}, [
274
+ node("circle", { cx: 12, cy: 13, r: 5.5, fill: color }),
275
+ node("circle", { cx: 28, cy: 13, r: 5.5, fill: color }),
276
+ node("circle", { cx: 12, cy: 13, r: 2.2, fill: accent }),
277
+ node("circle", { cx: 28, cy: 13, r: 2.2, fill: accent }),
278
+ node("ellipse", { cx: 20, cy: 23.5, rx: 15.5, ry: 11.5, fill: color })
279
+ ]);
280
+ default:
281
+ return node("circle", { cx: 20, cy: 21, r: 14.5, fill: color });
282
+ }
283
+ }
284
+ var FaceUtil;
285
+ (function(FaceUtil2) {
286
+ function of(seed) {
287
+ let hash = 0;
288
+ for (const char of seed) {
289
+ hash = hash * 31 + char.charCodeAt(0) | 0;
290
+ }
291
+ return Math.abs(hash) % FACE_COUNT;
292
+ }
293
+ FaceUtil2.of = of;
294
+ function pick(face, seed = "") {
295
+ return face !== undefined && face >= 0 && face < FACE_COUNT ? Math.floor(face) : of(seed);
296
+ }
297
+ FaceUtil2.pick = pick;
298
+ function color(face) {
299
+ var _a;
300
+ return ((_a = LOOKS[face]) !== null && _a !== undefined ? _a : LOOKS[0]).color;
301
+ }
302
+ FaceUtil2.color = color;
303
+ function art(face) {
304
+ var _a, _b;
305
+ const look = (_a = LOOKS[face]) !== null && _a !== undefined ? _a : LOOKS[0];
306
+ const half = look.gap / 2;
307
+ const eyeW = 4.1;
308
+ const eyeH = 4.9;
309
+ const top = look.eyeY - eyeH / 2;
310
+ const cheekY = look.eyeY + 3.6;
311
+ const cheekX = half + 2.2;
312
+ const mouthY = look.eyeY + 3.4;
313
+ const features = [
314
+ node("g", { fill: look.cheek }, [
315
+ node("ellipse", { cx: 20 - cheekX, cy: cheekY, rx: 2.2, ry: 1.25 }),
316
+ node("ellipse", { cx: 20 + cheekX, cy: cheekY, rx: 2.2, ry: 1.25 })
317
+ ])
318
+ ];
319
+ if (look.brows) {
320
+ features.push(node("path", {
321
+ d: `M${20 - half - 3.4} ${top - 2.6}l3.6 1.6M${20 + half + 3.4} ${top - 2.6}l-3.6 1.6`,
322
+ stroke: look.eye,
323
+ "stroke-width": 1.4,
324
+ "stroke-linecap": "round",
325
+ fill: "none"
326
+ }));
327
+ }
328
+ features.push(node("g", { class: "ta-face-eyes", fill: look.eye }, [
329
+ node("rect", { x: 20 - half - eyeW / 2, y: top, width: eyeW, height: eyeH, rx: eyeW / 2 }),
330
+ node("rect", { x: 20 + half - eyeW / 2, y: top, width: eyeW, height: eyeH, rx: eyeW / 2 })
331
+ ]), node("path", {
332
+ d: `M18.1 ${mouthY}q.95 1.25 1.9 0q.95 1.25 1.9 0`,
333
+ fill: "none",
334
+ stroke: (_b = look.mouth) !== null && _b !== undefined ? _b : look.eye,
335
+ "stroke-width": 1.1,
336
+ "stroke-linecap": "round",
337
+ "stroke-linejoin": "round"
338
+ }));
339
+ return node("g", { class: "ta-face-body" }, [shape(face, look), node("g", { class: "ta-face-look" }, features)]);
340
+ }
341
+ FaceUtil2.art = art;
342
+ })(FaceUtil || (FaceUtil = {}));
343
+
95
344
  // web-src/channels-model.ts
96
345
  var NAME = "@celljs/ta-channels";
97
346
  var AGENT_MARK = "one of the agents of Ta";
@@ -114,7 +363,7 @@ var MAX_HOPS = 3;
114
363
  var MAX_REPLIES = 8;
115
364
  var MAX_AGENT_REPLIES = 2;
116
365
  var MAX_MESSAGES = 200;
117
- var FACES = 16;
366
+ var FACES = FACE_COUNT;
118
367
  var MAX_MEMBERS = 12;
119
368
  var CONTEXT_MESSAGES = 12;
120
369
  var MAX_NAME = 32;
@@ -549,6 +798,279 @@ var TaLanguageUtil;
549
798
  TaLanguageUtil2.list = list;
550
799
  })(TaLanguageUtil || (TaLanguageUtil = {}));
551
800
 
801
+ // ../ta-protocol/esm/common/message-protocol.js
802
+ var TaMessageContext;
803
+ (function(TaMessageContext2) {
804
+ const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
805
+ function wrap(context, message) {
806
+ return `<context>
807
+ ${context}
808
+ </context>
809
+ ${message}`;
810
+ }
811
+ TaMessageContext2.wrap = wrap;
812
+ function strip(message) {
813
+ return message.replace(BLOCK, "");
814
+ }
815
+ TaMessageContext2.strip = strip;
816
+ function read(message) {
817
+ var _a;
818
+ const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
819
+ return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
820
+ }
821
+ TaMessageContext2.read = read;
822
+ })(TaMessageContext || (TaMessageContext = {}));
823
+ var TaMessageSource;
824
+ (function(TaMessageSource2) {
825
+ TaMessageSource2.DOUBLE = "ta:double";
826
+ const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
827
+ function mark(message, from, detail) {
828
+ return marked(message, line(from, detail));
829
+ }
830
+ TaMessageSource2.mark = mark;
831
+ function notice(message, from, detail) {
832
+ return marked(message, line(from, detail, true));
833
+ }
834
+ TaMessageSource2.notice = notice;
835
+ function line(from, detail, notice2 = false) {
836
+ return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
837
+ }
838
+ TaMessageSource2.line = line;
839
+ function of(message) {
840
+ const context = TaMessageContext.read(message);
841
+ const match = context === undefined ? null : LINE.exec(context);
842
+ return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
843
+ }
844
+ TaMessageSource2.of = of;
845
+ function isNotice(message) {
846
+ var _a;
847
+ return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
848
+ }
849
+ TaMessageSource2.isNotice = isNotice;
850
+ TaMessageSource2.SECTION = "ta-sources";
851
+ TaMessageSource2.PROMPT = [
852
+ "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.",
853
+ "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:",
854
+ "- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
855
+ "- 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).",
856
+ "- Never quote it as the user's words nor answer it as if they had said it."
857
+ ].join(`
858
+ `);
859
+ function marked(message, source) {
860
+ if (/^[/!]/.test(message) || of(message)) {
861
+ return message;
862
+ }
863
+ const context = TaMessageContext.read(message);
864
+ return TaMessageContext.wrap(context === undefined ? source : `${context}
865
+ ${source}`, TaMessageContext.strip(message));
866
+ }
867
+ })(TaMessageSource || (TaMessageSource = {}));
868
+ var TaImageNote;
869
+ (function(TaImageNote2) {
870
+ const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
871
+ function strip(text) {
872
+ const lines = text.split(`
873
+ `);
874
+ const kept = lines.filter((line) => !NOTE.test(line.trim()));
875
+ if (kept.length === lines.length) {
876
+ return text;
877
+ }
878
+ return kept.join(`
879
+ `).replace(/\n+$/, "").replace(/^\n+/, "");
880
+ }
881
+ TaImageNote2.strip = strip;
882
+ })(TaImageNote || (TaImageNote = {}));
883
+ var TaImageSize;
884
+ (function(TaImageSize2) {
885
+ const JPEG_BYTES = 256 * 1024;
886
+ function of(base64) {
887
+ var _a, _b, _c;
888
+ let bytes;
889
+ try {
890
+ const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
891
+ bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
892
+ } catch (_d) {
893
+ return;
894
+ }
895
+ const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
896
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
897
+ }
898
+ TaImageSize2.of = of;
899
+ function u16be(bytes, at) {
900
+ return bytes[at] << 8 | bytes[at + 1];
901
+ }
902
+ function u16le(bytes, at) {
903
+ return bytes[at] | bytes[at + 1] << 8;
904
+ }
905
+ function u24le(bytes, at) {
906
+ return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
907
+ }
908
+ function u32be(bytes, at) {
909
+ return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
910
+ }
911
+ function text(bytes, at, length) {
912
+ return String.fromCharCode(...bytes.subarray(at, at + length));
913
+ }
914
+ function png(bytes) {
915
+ return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
916
+ }
917
+ function gif(bytes) {
918
+ return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
919
+ }
920
+ function webp(bytes) {
921
+ if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
922
+ return;
923
+ }
924
+ switch (text(bytes, 12, 4)) {
925
+ case "VP8 ":
926
+ return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
927
+ case "VP8L": {
928
+ const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
929
+ return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
930
+ }
931
+ case "VP8X":
932
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
933
+ default:
934
+ return;
935
+ }
936
+ }
937
+ function jpeg(bytes) {
938
+ if (bytes[0] !== 255 || bytes[1] !== 216) {
939
+ return;
940
+ }
941
+ let at = 2;
942
+ while (at + 9 < bytes.length) {
943
+ if (bytes[at] !== 255) {
944
+ return;
945
+ }
946
+ const marker = bytes[at + 1];
947
+ if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
948
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
949
+ }
950
+ at += 2 + u16be(bytes, at + 2);
951
+ }
952
+ return;
953
+ }
954
+ })(TaImageSize || (TaImageSize = {}));
955
+ var TaAgentSummary;
956
+ (function(TaAgentSummary2) {
957
+ const START = /^\s*<conversation_history_summary>/;
958
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
959
+ function read(text) {
960
+ if (!START.test(text)) {
961
+ return;
962
+ }
963
+ return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
964
+ }
965
+ TaAgentSummary2.read = read;
966
+ function strip(text) {
967
+ return text.replace(BLOCK, "");
968
+ }
969
+ TaAgentSummary2.strip = strip;
970
+ })(TaAgentSummary || (TaAgentSummary = {}));
971
+ var TaSkillUse;
972
+ (function(TaSkillUse2) {
973
+ const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
974
+ function parse(message) {
975
+ var _a;
976
+ const match = BLOCK.exec(message);
977
+ if (!match) {
978
+ return;
979
+ }
980
+ return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
981
+ }
982
+ TaSkillUse2.parse = parse;
983
+ function command(use) {
984
+ return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
985
+ }
986
+ TaSkillUse2.command = command;
987
+ })(TaSkillUse || (TaSkillUse = {}));
988
+ var TaTaskNote;
989
+ (function(TaTaskNote2) {
990
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
991
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
992
+ function write(note) {
993
+ const attributes = [`id="${quote(note.id)}"`];
994
+ if (note.was !== undefined) {
995
+ attributes.push(`was="${quote(note.was)}"`);
996
+ }
997
+ attributes.push(`title="${quote(note.title)}"`);
998
+ if (note.status !== undefined) {
999
+ attributes.push(`status="${quote(note.status)}"`);
1000
+ }
1001
+ return `<task_${note.kind} ${attributes.join(" ")}>
1002
+ ${note.body}
1003
+ </task_${note.kind}>`;
1004
+ }
1005
+ TaTaskNote2.write = write;
1006
+ function parse(text) {
1007
+ const match = NOTE.exec(text.trim());
1008
+ if (!match) {
1009
+ return;
1010
+ }
1011
+ const attributes = {};
1012
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
1013
+ attributes[name] = unquote(value);
1014
+ }
1015
+ if (!attributes.id || attributes.title === undefined) {
1016
+ return;
1017
+ }
1018
+ const { id, title, status, was } = attributes;
1019
+ return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
1020
+ }
1021
+ TaTaskNote2.parse = parse;
1022
+ function quote(text) {
1023
+ return text.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/\n/g, " ");
1024
+ }
1025
+ function unquote(text) {
1026
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, "&");
1027
+ }
1028
+ })(TaTaskNote || (TaTaskNote = {}));
1029
+ var TaSecretRef;
1030
+ (function(TaSecretRef2) {
1031
+ TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
1032
+ const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
1033
+ const KINDS = [
1034
+ [/^PHONE(?:_\d+)?$/, "phone"],
1035
+ [/^EMAIL(?:_\d+)?$/, "email"],
1036
+ [/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
1037
+ [/^BANK_CARD(?:_\d+)?$/, "bankCard"]
1038
+ ];
1039
+ function has(text) {
1040
+ return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
1041
+ }
1042
+ TaSecretRef2.has = has;
1043
+ function kind(name) {
1044
+ var _a;
1045
+ var _b;
1046
+ return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
1047
+ }
1048
+ TaSecretRef2.kind = kind;
1049
+ function split(text) {
1050
+ if (!has(text)) {
1051
+ return [{ text }];
1052
+ }
1053
+ const parts = [];
1054
+ let at = 0;
1055
+ for (const match of text.matchAll(REF)) {
1056
+ if (match.index > at) {
1057
+ parts.push({ text: text.slice(at, match.index) });
1058
+ }
1059
+ parts.push({ secret: match[1], kind: kind(match[1]) });
1060
+ at = match.index + match[0].length;
1061
+ }
1062
+ if (at < text.length) {
1063
+ parts.push({ text: text.slice(at) });
1064
+ }
1065
+ return parts;
1066
+ }
1067
+ TaSecretRef2.split = split;
1068
+ function plain(text, label) {
1069
+ return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
1070
+ }
1071
+ TaSecretRef2.plain = plain;
1072
+ })(TaSecretRef || (TaSecretRef = {}));
1073
+
552
1074
  // web-src/handoff.ts
553
1075
  var HandOff;
554
1076
  ((HandOff) => {
@@ -594,10 +1116,7 @@ var HandOff;
594
1116
  "en-US": `Hand this over to ${to}`,
595
1117
  "ja-JP": `これを ${to} に引き継ぐ`
596
1118
  });
597
- return `<context>
598
- ${context}
599
- </context>
600
- ${line}`;
1119
+ return TaMessageContext.wrap(context, line);
601
1120
  }
602
1121
  HandOff.ask = ask;
603
1122
  function asked(text) {
@@ -635,12 +1154,9 @@ ${line}`;
635
1154
  origin.sessionFile ? `That conversation is pi's session file ${origin.sessionFile}${origin.cwd ? `, working in ${origin.cwd}` : ""}: read it only when the brief is not enough.` : ""
636
1155
  ].filter(Boolean).join(`
637
1156
  `);
638
- return `<context>
639
- ${context}
640
- </context>
641
- ${head}
1157
+ return TaMessageContext.wrap(context, `${head}
642
1158
 
643
- ${brief.trim()}`;
1159
+ ${brief.trim()}`);
644
1160
  }
645
1161
  HandOff.message = message;
646
1162
  function channelText(origin, brief, language) {
@@ -788,6 +1304,226 @@ var TeamAsk;
788
1304
  TeamAsk.allow = allow;
789
1305
  })(TeamAsk ||= {});
790
1306
 
1307
+ // ../ta-protocol/esm/common/said-protocol.js
1308
+ var TaSaid;
1309
+ (function(TaSaid2) {
1310
+ const CARD = /^ta-/i;
1311
+ const READ = 4000;
1312
+ const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
1313
+ const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
1314
+ const MARKS_ONLY = /^[-*_=|:+\s]+$/;
1315
+ const MARKS = [
1316
+ ["context", /<\/?context>/],
1317
+ ["source", /\[ta:(?:from|notice|by) /],
1318
+ ["image note", /\[Image: original \d+x\d+|\[Image converted from /],
1319
+ ["skill", /<skill name="|<\/skill>/],
1320
+ ["task note", /<\/?task_(?:update|adopted|renamed)\b/],
1321
+ ["summary", /<\/?(?:conversation_history_summary|summary)>/]
1322
+ ];
1323
+ function text(content, joiner = `
1324
+ `) {
1325
+ if (typeof content === "string") {
1326
+ return content;
1327
+ }
1328
+ 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) : "";
1329
+ }
1330
+ TaSaid2.text = text;
1331
+ function words(role, text2, options = {}) {
1332
+ const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
1333
+ return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
1334
+ }
1335
+ TaSaid2.words = words;
1336
+ function of(message, options) {
1337
+ return message ? words(message.role, text(message.content), options) : "";
1338
+ }
1339
+ TaSaid2.of = of;
1340
+ function notice(message) {
1341
+ return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
1342
+ }
1343
+ TaSaid2.notice = notice;
1344
+ function marksOnly(role, text2) {
1345
+ return !!text2.trim() && !line(words(role, text2), { chars: Number.POSITIVE_INFINITY });
1346
+ }
1347
+ TaSaid2.marksOnly = marksOnly;
1348
+ function line(markdown, options) {
1349
+ var _a;
1350
+ const read = markdown.slice(0, READ);
1351
+ const prose = withoutFences(read, () => true, true).trim();
1352
+ const lines = plain(prose || codeOf(read)).split(`
1353
+ `).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));
1354
+ const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
1355
+ const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
1356
+ `);
1357
+ return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
1358
+ }
1359
+ TaSaid2.line = line;
1360
+ function leaks(shown, options = {}) {
1361
+ const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
1362
+ const lines = shown.split(`
1363
+ `);
1364
+ if (options.cards !== true && lines.some((part) => {
1365
+ var _a;
1366
+ var _b;
1367
+ return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
1368
+ })) {
1369
+ found.push("card");
1370
+ }
1371
+ if (lines.some((part) => TAG_LINE.test(part.trim()))) {
1372
+ found.push("tag");
1373
+ }
1374
+ return found;
1375
+ }
1376
+ TaSaid2.leaks = leaks;
1377
+ const SUMMARY = `<conversation_history_summary>
1378
+ <summary>
1379
+ 1. Primary Request and Intent:
1380
+ The user works on the relay.
1381
+ </summary>
1382
+ </conversation_history_summary>`;
1383
+ TaSaid2.SAMPLES = [
1384
+ {
1385
+ mark: "context and where it came from",
1386
+ role: "user",
1387
+ text: `<context>
1388
+ The channel #ops, its members.
1389
+ [ta:from @celljs/ta-channels #ops]
1390
+ </context>
1391
+ Check the build`,
1392
+ said: "Check the build"
1393
+ },
1394
+ {
1395
+ mark: "a notice, not the user",
1396
+ role: "user",
1397
+ text: `<context>
1398
+ [ta:notice @celljs/ta-call]
1399
+ </context>
1400
+ The work finished. Its last words: tests pass.`,
1401
+ said: "The work finished. Its last words: tests pass."
1402
+ },
1403
+ { mark: "one let in", role: "user", text: `<context>
1404
+ [ta:by p-7 Alice]
1405
+ </context>
1406
+ Hello there`, said: "Hello there" },
1407
+ {
1408
+ mark: "notes of images",
1409
+ role: "user",
1410
+ text: `Look at this
1411
+ [Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
1412
+ [Image converted from image/heic to image/png.]`,
1413
+ said: "Look at this"
1414
+ },
1415
+ {
1416
+ mark: "a skill run",
1417
+ role: "user",
1418
+ text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
1419
+ # Ta package
1420
+ Steps.
1421
+ </skill>
1422
+
1423
+ Make a card`,
1424
+ said: "Make a card"
1425
+ },
1426
+ {
1427
+ mark: "a note of a task",
1428
+ role: "user",
1429
+ text: `<task_update id="t1" title="Fix login" status="done">
1430
+ All tests pass.
1431
+ </task_update>`,
1432
+ said: "Fix login"
1433
+ },
1434
+ { mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
1435
+ Now t2.
1436
+ </task_renamed>` },
1437
+ { mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
1438
+ Switched to voice.`, said: "Switched to voice." },
1439
+ { mark: "a summary alone", role: "assistant", text: SUMMARY },
1440
+ { mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
1441
+ <summary>` },
1442
+ {
1443
+ mark: "a card after the answer",
1444
+ role: "assistant",
1445
+ text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
1446
+ said: "tests pass"
1447
+ },
1448
+ { mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
1449
+ { mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
1450
+ { mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
1451
+ { mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
1452
+ </system-reminder>
1453
+ Ready.`, said: "Ready." }
1454
+ ];
1455
+ function userWords(text2) {
1456
+ const said = TaImageNote.strip(TaMessageContext.strip(text2));
1457
+ const skill = TaSkillUse.parse(said);
1458
+ if (skill) {
1459
+ return TaSkillUse.command(skill);
1460
+ }
1461
+ const note = TaTaskNote.parse(said);
1462
+ if (!note) {
1463
+ return said;
1464
+ }
1465
+ if (note.kind === "renamed") {
1466
+ return "";
1467
+ }
1468
+ return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
1469
+ }
1470
+ function withoutFences(text2, drop, tags = false) {
1471
+ const kept = [];
1472
+ let fence;
1473
+ let left = false;
1474
+ for (const part of text2.split(`
1475
+ `)) {
1476
+ const open = FENCE.exec(part);
1477
+ if (!fence && open) {
1478
+ fence = { mark: open[1], dropped: drop(open[2]) };
1479
+ } else if (fence && closes(part, fence.mark)) {
1480
+ const dropped = fence.dropped;
1481
+ fence = undefined;
1482
+ if (dropped) {
1483
+ continue;
1484
+ }
1485
+ }
1486
+ if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
1487
+ left = true;
1488
+ } else {
1489
+ kept.push(part);
1490
+ }
1491
+ }
1492
+ return left ? kept.join(`
1493
+ `).replace(/\n{3,}/g, `
1494
+
1495
+ `) : kept.join(`
1496
+ `);
1497
+ }
1498
+ function codeOf(text2) {
1499
+ const code = [];
1500
+ let fence;
1501
+ for (const part of text2.split(`
1502
+ `)) {
1503
+ const open = FENCE.exec(part);
1504
+ if (!fence && open) {
1505
+ fence = { mark: open[1], card: CARD.test(open[2]) };
1506
+ } else if (fence && closes(part, fence.mark)) {
1507
+ fence = undefined;
1508
+ } else if (fence && !fence.card) {
1509
+ code.push(part);
1510
+ }
1511
+ }
1512
+ return code.join(`
1513
+ `);
1514
+ }
1515
+ function closes(part, mark) {
1516
+ var _a;
1517
+ const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
1518
+ return !!close && close[0] === mark[0] && close.length >= mark.length;
1519
+ }
1520
+ function plain(text2) {
1521
+ const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
1522
+ const words2 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
1523
+ return words2 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
1524
+ }
1525
+ })(TaSaid || (TaSaid = {}));
1526
+
791
1527
  // web-src/channels-text.ts
792
1528
  var ChannelsText;
793
1529
  ((ChannelsText) => {
@@ -846,7 +1582,7 @@ var ChannelsText;
846
1582
  return [
847
1583
  `You are ${agent.name}, ${AGENT_MARK}. Your role: ${agent.role}`,
848
1584
  "You work with the user, Ta and other agents in channels. A message for you starts with a <context> block: the channel, its members, the recent messages and who speaks to you; answer what follows the block.",
849
- "Do the part of the work your role covers with your tools, then answer in a few sentences: your answer is posted to the channel as it is.",
1585
+ "Do the part of the work your role covers with your tools, then answer: your answer is posted to the channel as it is.",
850
1586
  "To hand work to another member, write @ and their name in your answer; name nobody when the work is done or you need the user.",
851
1587
  NOTICE_RULE
852
1588
  ].join(`
@@ -865,13 +1601,10 @@ var ChannelsText;
865
1601
  lines.push("", "Recent messages:", ...before.map((item) => `${authorName(team, item.author, labels)}: ${item.text}`));
866
1602
  }
867
1603
  lines.push("", `${authorName(team, message.author, labels)} to you:`);
868
- const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels).replace(/[\]\n]/g, " ")}`;
869
- lines.push(`[ta:from ${NAME} #${channel.name}${speaker}]`);
870
- return `<context>
871
- ${lines.join(`
872
- `)}
873
- </context>
874
- ${message.text}`;
1604
+ const speaker = message.author === USER ? "" : ` · ${authorName(team, message.author, labels)}`;
1605
+ lines.push(TaMessageSource.line(NAME, `#${channel.name}${speaker}`));
1606
+ return TaMessageContext.wrap(lines.join(`
1607
+ `), message.text);
875
1608
  }
876
1609
  ChannelsText.prompt = prompt;
877
1610
  function summary(team) {
@@ -900,7 +1633,7 @@ ${message.text}`;
900
1633
  if (role !== "user" && role !== "assistant") {
901
1634
  continue;
902
1635
  }
903
- const text = (typeof content === "string" ? content : Array.isArray(content) ? content.map((block) => block?.type === "text" ? String(block.text ?? "") : "").join("") : "").replace(/^<context>\n?[\s\S]*?\n?<\/context>\n?/, "").trim();
1636
+ const text = TaSaid.words(role, TaSaid.text(content, ""));
904
1637
  if (text) {
905
1638
  parts.push("", `## ${role === "user" ? labels.user : agent.name}`, "", text);
906
1639
  }