@celljs/ta-share 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.
- package/README.en.md +3 -1
- package/README.md +3 -1
- package/host/index.mjs +501 -3
- package/package.json +4 -4
- package/web/index.js +590 -155
package/README.en.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Cell - Ta Share
|
|
2
2
|
|
|
3
|
+
Links that share; seeing and working the screen of a computer is `@celljs/ta-screen-share`.
|
|
4
|
+
|
|
3
5
|
A pi package that comes with Ta (on by default; Settings → Extensions turns it off): share a conversation, a page or a file by a link, and open or import what others share. Design notes: [docs/design/ta-link.md](../../docs/design/ta-link.md).
|
|
4
6
|
|
|
5
7
|
## Use
|
|
@@ -22,6 +24,6 @@ It works for 1, 7 or 30 days, or until stopped; "opens while this computer is of
|
|
|
22
24
|
|
|
23
25
|
## Parts
|
|
24
26
|
|
|
25
|
-
- **Server side** (`pi.host`, `web-src/host.ts`): `ShareService`. The snapshot of a conversation (`ConversationSnapshot`: the user's messages, the replies and the calls of tools of the branch shown; no thinking, images or cards of extensions; the outputs of tools if asked, 4 KB each) and `Redactor`; links made, listed, stopped and opened by `TaExtensionHost.shares`; imports by `TaExtensionHost.createSession` (ssh:// directories too).
|
|
27
|
+
- **Server side** (`pi.host`, `web-src/host.ts`): `ShareService`. The snapshot of a conversation (`ConversationSnapshot`: the user's messages, the replies and the calls of tools of the branch shown; no thinking, images or cards of extensions; the outputs of tools if asked, 4 KB each; the words as a person reads them, `TaSaid`, without the context, skill files and summaries that are for the model) and `Redactor`; links made, listed, stopped and opened by `TaExtensionHost.shares`; imports by `TaExtensionHost.createSession` (ssh:// directories too).
|
|
26
28
|
- **pi extension** (`web-src/extension.ts`): the tool `share_link`.
|
|
27
29
|
- **Web extension** (`web-src/index.tsx`): the + of the message box, the menu of a conversation (`registerSessionMenu`), the dialog (`ui.custom`), My shares, and a tab of the workbench for links (`registerOpener(…, { specific: true })`).
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Cell - Ta Share
|
|
2
2
|
|
|
3
|
+
分享链接;看和操作一台电脑的屏幕是 `@celljs/ta-screen-share`。
|
|
4
|
+
|
|
3
5
|
Ta 自带的 pi 包(默认开启,可在 设置 → 扩展 关闭):把对话、网页或文件生成链接分享出去,也能打开、导入别人分享的对话。设计记录见 [docs/design/ta-link.md](../../docs/design/ta-link.md)。
|
|
4
6
|
|
|
5
7
|
## 怎么用
|
|
@@ -22,6 +24,6 @@ Ta 自带的 pi 包(默认开启,可在 设置 → 扩展 关闭):把对
|
|
|
22
24
|
|
|
23
25
|
## 组成
|
|
24
26
|
|
|
25
|
-
- **服务端**(`pi.host`,`web-src/host.ts`):`ShareService`。对话快照(`ConversationSnapshot`:当前分支的用户消息、回复文字、工具调用;不含思考、图片、扩展卡片,工具输出可选、每条最多 4 KB
|
|
27
|
+
- **服务端**(`pi.host`,`web-src/host.ts`):`ShareService`。对话快照(`ConversationSnapshot`:当前分支的用户消息、回复文字、工具调用;不含思考、图片、扩展卡片,工具输出可选、每条最多 4 KB;文字是人读到的样子(`TaSaid`),不带给模型看的 context、技能文件和压缩摘要)与脱敏(`Redactor`),经 `TaExtensionHost.shares` 生成、列出、停止、打开链接;导入经 `TaExtensionHost.createSession`(ssh:// 目录同样适用)。
|
|
26
28
|
- **pi 扩展**(`web-src/extension.ts`):工具 `share_link`。
|
|
27
29
|
- **Web 扩展**(`web-src/index.tsx`):输入框 + 菜单、会话菜单(`registerSessionMenu`)、分享弹窗(`ui.custom`)、"我的分享"页、打开链接的工作台标签(`registerOpener(…, { specific: true })`)。
|
package/host/index.mjs
CHANGED
|
@@ -112,6 +112,499 @@ class Redactor {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
// ../ta-protocol/esm/common/message-protocol.js
|
|
116
|
+
var TaMessageContext;
|
|
117
|
+
(function(TaMessageContext2) {
|
|
118
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
119
|
+
function wrap(context, message) {
|
|
120
|
+
return `<context>
|
|
121
|
+
${context}
|
|
122
|
+
</context>
|
|
123
|
+
${message}`;
|
|
124
|
+
}
|
|
125
|
+
TaMessageContext2.wrap = wrap;
|
|
126
|
+
function strip(message) {
|
|
127
|
+
return message.replace(BLOCK, "");
|
|
128
|
+
}
|
|
129
|
+
TaMessageContext2.strip = strip;
|
|
130
|
+
function read(message) {
|
|
131
|
+
var _a;
|
|
132
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
133
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
134
|
+
}
|
|
135
|
+
TaMessageContext2.read = read;
|
|
136
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
137
|
+
var TaMessageSource;
|
|
138
|
+
(function(TaMessageSource2) {
|
|
139
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
140
|
+
const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
141
|
+
function mark(message, from, detail) {
|
|
142
|
+
return marked(message, line(from, detail));
|
|
143
|
+
}
|
|
144
|
+
TaMessageSource2.mark = mark;
|
|
145
|
+
function notice(message, from, detail) {
|
|
146
|
+
return marked(message, line(from, detail, true));
|
|
147
|
+
}
|
|
148
|
+
TaMessageSource2.notice = notice;
|
|
149
|
+
function line(from, detail, notice2 = false) {
|
|
150
|
+
return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
151
|
+
}
|
|
152
|
+
TaMessageSource2.line = line;
|
|
153
|
+
function of(message) {
|
|
154
|
+
const context = TaMessageContext.read(message);
|
|
155
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
156
|
+
return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
|
|
157
|
+
}
|
|
158
|
+
TaMessageSource2.of = of;
|
|
159
|
+
function isNotice(message) {
|
|
160
|
+
var _a;
|
|
161
|
+
return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
|
|
162
|
+
}
|
|
163
|
+
TaMessageSource2.isNotice = isNotice;
|
|
164
|
+
TaMessageSource2.SECTION = "ta-sources";
|
|
165
|
+
TaMessageSource2.PROMPT = [
|
|
166
|
+
"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.",
|
|
167
|
+
"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:",
|
|
168
|
+
"- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
|
|
169
|
+
"- 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).",
|
|
170
|
+
"- Never quote it as the user's words nor answer it as if they had said it."
|
|
171
|
+
].join(`
|
|
172
|
+
`);
|
|
173
|
+
function marked(message, source) {
|
|
174
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
175
|
+
return message;
|
|
176
|
+
}
|
|
177
|
+
const context = TaMessageContext.read(message);
|
|
178
|
+
return TaMessageContext.wrap(context === undefined ? source : `${context}
|
|
179
|
+
${source}`, TaMessageContext.strip(message));
|
|
180
|
+
}
|
|
181
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
182
|
+
var TaImageNote;
|
|
183
|
+
(function(TaImageNote2) {
|
|
184
|
+
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 [^\]]+\.\]$/;
|
|
185
|
+
function strip(text) {
|
|
186
|
+
const lines = text.split(`
|
|
187
|
+
`);
|
|
188
|
+
const kept = lines.filter((line) => !NOTE.test(line.trim()));
|
|
189
|
+
if (kept.length === lines.length) {
|
|
190
|
+
return text;
|
|
191
|
+
}
|
|
192
|
+
return kept.join(`
|
|
193
|
+
`).replace(/\n+$/, "").replace(/^\n+/, "");
|
|
194
|
+
}
|
|
195
|
+
TaImageNote2.strip = strip;
|
|
196
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
197
|
+
var TaImageSize;
|
|
198
|
+
(function(TaImageSize2) {
|
|
199
|
+
const JPEG_BYTES = 256 * 1024;
|
|
200
|
+
function of(base64) {
|
|
201
|
+
var _a, _b, _c;
|
|
202
|
+
let bytes;
|
|
203
|
+
try {
|
|
204
|
+
const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
|
|
205
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
206
|
+
} catch (_d) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
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);
|
|
210
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
211
|
+
}
|
|
212
|
+
TaImageSize2.of = of;
|
|
213
|
+
function u16be(bytes, at) {
|
|
214
|
+
return bytes[at] << 8 | bytes[at + 1];
|
|
215
|
+
}
|
|
216
|
+
function u16le(bytes, at) {
|
|
217
|
+
return bytes[at] | bytes[at + 1] << 8;
|
|
218
|
+
}
|
|
219
|
+
function u24le(bytes, at) {
|
|
220
|
+
return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
|
|
221
|
+
}
|
|
222
|
+
function u32be(bytes, at) {
|
|
223
|
+
return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
224
|
+
}
|
|
225
|
+
function text(bytes, at, length) {
|
|
226
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
227
|
+
}
|
|
228
|
+
function png(bytes) {
|
|
229
|
+
return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
230
|
+
}
|
|
231
|
+
function gif(bytes) {
|
|
232
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
233
|
+
}
|
|
234
|
+
function webp(bytes) {
|
|
235
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
switch (text(bytes, 12, 4)) {
|
|
239
|
+
case "VP8 ":
|
|
240
|
+
return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
|
|
241
|
+
case "VP8L": {
|
|
242
|
+
const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
|
|
243
|
+
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
|
|
244
|
+
}
|
|
245
|
+
case "VP8X":
|
|
246
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
247
|
+
default:
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function jpeg(bytes) {
|
|
252
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
let at = 2;
|
|
256
|
+
while (at + 9 < bytes.length) {
|
|
257
|
+
if (bytes[at] !== 255) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const marker = bytes[at + 1];
|
|
261
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
262
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
263
|
+
}
|
|
264
|
+
at += 2 + u16be(bytes, at + 2);
|
|
265
|
+
}
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
269
|
+
var TaAgentSummary;
|
|
270
|
+
(function(TaAgentSummary2) {
|
|
271
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
272
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
273
|
+
function read(text) {
|
|
274
|
+
if (!START.test(text)) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
|
|
278
|
+
}
|
|
279
|
+
TaAgentSummary2.read = read;
|
|
280
|
+
function strip(text) {
|
|
281
|
+
return text.replace(BLOCK, "");
|
|
282
|
+
}
|
|
283
|
+
TaAgentSummary2.strip = strip;
|
|
284
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
285
|
+
var TaSkillUse;
|
|
286
|
+
(function(TaSkillUse2) {
|
|
287
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
288
|
+
function parse(message) {
|
|
289
|
+
var _a;
|
|
290
|
+
const match = BLOCK.exec(message);
|
|
291
|
+
if (!match) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
295
|
+
}
|
|
296
|
+
TaSkillUse2.parse = parse;
|
|
297
|
+
function command(use) {
|
|
298
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
299
|
+
}
|
|
300
|
+
TaSkillUse2.command = command;
|
|
301
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
302
|
+
var TaTaskNote;
|
|
303
|
+
(function(TaTaskNote2) {
|
|
304
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
305
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
306
|
+
function write(note) {
|
|
307
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
308
|
+
if (note.was !== undefined) {
|
|
309
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
310
|
+
}
|
|
311
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
312
|
+
if (note.status !== undefined) {
|
|
313
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
314
|
+
}
|
|
315
|
+
return `<task_${note.kind} ${attributes.join(" ")}>
|
|
316
|
+
${note.body}
|
|
317
|
+
</task_${note.kind}>`;
|
|
318
|
+
}
|
|
319
|
+
TaTaskNote2.write = write;
|
|
320
|
+
function parse(text) {
|
|
321
|
+
const match = NOTE.exec(text.trim());
|
|
322
|
+
if (!match) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const attributes = {};
|
|
326
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
327
|
+
attributes[name] = unquote(value);
|
|
328
|
+
}
|
|
329
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const { id, title, status, was } = attributes;
|
|
333
|
+
return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
|
|
334
|
+
}
|
|
335
|
+
TaTaskNote2.parse = parse;
|
|
336
|
+
function quote(text) {
|
|
337
|
+
return text.replace(/&/g, "&").replace(/"/g, """).replace(/\n/g, " ");
|
|
338
|
+
}
|
|
339
|
+
function unquote(text) {
|
|
340
|
+
return text.replace(/"/g, '"').replace(/&/g, "&");
|
|
341
|
+
}
|
|
342
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
343
|
+
var TaSecretRef;
|
|
344
|
+
(function(TaSecretRef2) {
|
|
345
|
+
TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
|
|
346
|
+
const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
|
|
347
|
+
const KINDS = [
|
|
348
|
+
[/^PHONE(?:_\d+)?$/, "phone"],
|
|
349
|
+
[/^EMAIL(?:_\d+)?$/, "email"],
|
|
350
|
+
[/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
|
|
351
|
+
[/^BANK_CARD(?:_\d+)?$/, "bankCard"]
|
|
352
|
+
];
|
|
353
|
+
function has(text) {
|
|
354
|
+
return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
|
|
355
|
+
}
|
|
356
|
+
TaSecretRef2.has = has;
|
|
357
|
+
function kind(name) {
|
|
358
|
+
var _a;
|
|
359
|
+
var _b;
|
|
360
|
+
return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
|
|
361
|
+
}
|
|
362
|
+
TaSecretRef2.kind = kind;
|
|
363
|
+
function split(text) {
|
|
364
|
+
if (!has(text)) {
|
|
365
|
+
return [{ text }];
|
|
366
|
+
}
|
|
367
|
+
const parts = [];
|
|
368
|
+
let at = 0;
|
|
369
|
+
for (const match of text.matchAll(REF)) {
|
|
370
|
+
if (match.index > at) {
|
|
371
|
+
parts.push({ text: text.slice(at, match.index) });
|
|
372
|
+
}
|
|
373
|
+
parts.push({ secret: match[1], kind: kind(match[1]) });
|
|
374
|
+
at = match.index + match[0].length;
|
|
375
|
+
}
|
|
376
|
+
if (at < text.length) {
|
|
377
|
+
parts.push({ text: text.slice(at) });
|
|
378
|
+
}
|
|
379
|
+
return parts;
|
|
380
|
+
}
|
|
381
|
+
TaSecretRef2.split = split;
|
|
382
|
+
function plain(text, label) {
|
|
383
|
+
return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
|
|
384
|
+
}
|
|
385
|
+
TaSecretRef2.plain = plain;
|
|
386
|
+
})(TaSecretRef || (TaSecretRef = {}));
|
|
387
|
+
|
|
388
|
+
// ../ta-protocol/esm/common/said-protocol.js
|
|
389
|
+
var TaSaid;
|
|
390
|
+
(function(TaSaid2) {
|
|
391
|
+
const CARD = /^ta-/i;
|
|
392
|
+
const READ = 4000;
|
|
393
|
+
const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
|
|
394
|
+
const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
|
|
395
|
+
const MARKS_ONLY = /^[-*_=|:+\s]+$/;
|
|
396
|
+
const MARKS = [
|
|
397
|
+
["context", /<\/?context>/],
|
|
398
|
+
["source", /\[ta:(?:from|notice|by) /],
|
|
399
|
+
["image note", /\[Image: original \d+x\d+|\[Image converted from /],
|
|
400
|
+
["skill", /<skill name="|<\/skill>/],
|
|
401
|
+
["task note", /<\/?task_(?:update|adopted|renamed)\b/],
|
|
402
|
+
["summary", /<\/?(?:conversation_history_summary|summary)>/]
|
|
403
|
+
];
|
|
404
|
+
function text(content, joiner = `
|
|
405
|
+
`) {
|
|
406
|
+
if (typeof content === "string") {
|
|
407
|
+
return content;
|
|
408
|
+
}
|
|
409
|
+
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) : "";
|
|
410
|
+
}
|
|
411
|
+
TaSaid2.text = text;
|
|
412
|
+
function words(role, text2, options = {}) {
|
|
413
|
+
const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
|
|
414
|
+
return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
|
|
415
|
+
}
|
|
416
|
+
TaSaid2.words = words;
|
|
417
|
+
function of(message, options) {
|
|
418
|
+
return message ? words(message.role, text(message.content), options) : "";
|
|
419
|
+
}
|
|
420
|
+
TaSaid2.of = of;
|
|
421
|
+
function notice(message) {
|
|
422
|
+
return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
|
|
423
|
+
}
|
|
424
|
+
TaSaid2.notice = notice;
|
|
425
|
+
function marksOnly(role, text2) {
|
|
426
|
+
return !!text2.trim() && !line(words(role, text2), { chars: Number.POSITIVE_INFINITY });
|
|
427
|
+
}
|
|
428
|
+
TaSaid2.marksOnly = marksOnly;
|
|
429
|
+
function line(markdown, options) {
|
|
430
|
+
var _a;
|
|
431
|
+
const read = markdown.slice(0, READ);
|
|
432
|
+
const prose = withoutFences(read, () => true, true).trim();
|
|
433
|
+
const lines = plain(prose || codeOf(read)).split(`
|
|
434
|
+
`).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));
|
|
435
|
+
const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
|
|
436
|
+
const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
|
|
437
|
+
`);
|
|
438
|
+
return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
|
|
439
|
+
}
|
|
440
|
+
TaSaid2.line = line;
|
|
441
|
+
function leaks(shown, options = {}) {
|
|
442
|
+
const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
|
|
443
|
+
const lines = shown.split(`
|
|
444
|
+
`);
|
|
445
|
+
if (options.cards !== true && lines.some((part) => {
|
|
446
|
+
var _a;
|
|
447
|
+
var _b;
|
|
448
|
+
return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
|
|
449
|
+
})) {
|
|
450
|
+
found.push("card");
|
|
451
|
+
}
|
|
452
|
+
if (lines.some((part) => TAG_LINE.test(part.trim()))) {
|
|
453
|
+
found.push("tag");
|
|
454
|
+
}
|
|
455
|
+
return found;
|
|
456
|
+
}
|
|
457
|
+
TaSaid2.leaks = leaks;
|
|
458
|
+
const SUMMARY = `<conversation_history_summary>
|
|
459
|
+
<summary>
|
|
460
|
+
1. Primary Request and Intent:
|
|
461
|
+
The user works on the relay.
|
|
462
|
+
</summary>
|
|
463
|
+
</conversation_history_summary>`;
|
|
464
|
+
TaSaid2.SAMPLES = [
|
|
465
|
+
{
|
|
466
|
+
mark: "context and where it came from",
|
|
467
|
+
role: "user",
|
|
468
|
+
text: `<context>
|
|
469
|
+
The channel #ops, its members.
|
|
470
|
+
[ta:from @celljs/ta-channels #ops]
|
|
471
|
+
</context>
|
|
472
|
+
Check the build`,
|
|
473
|
+
said: "Check the build"
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
mark: "a notice, not the user",
|
|
477
|
+
role: "user",
|
|
478
|
+
text: `<context>
|
|
479
|
+
[ta:notice @celljs/ta-call]
|
|
480
|
+
</context>
|
|
481
|
+
The work finished. Its last words: tests pass.`,
|
|
482
|
+
said: "The work finished. Its last words: tests pass."
|
|
483
|
+
},
|
|
484
|
+
{ mark: "one let in", role: "user", text: `<context>
|
|
485
|
+
[ta:by p-7 Alice]
|
|
486
|
+
</context>
|
|
487
|
+
Hello there`, said: "Hello there" },
|
|
488
|
+
{
|
|
489
|
+
mark: "notes of images",
|
|
490
|
+
role: "user",
|
|
491
|
+
text: `Look at this
|
|
492
|
+
[Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
|
|
493
|
+
[Image converted from image/heic to image/png.]`,
|
|
494
|
+
said: "Look at this"
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
mark: "a skill run",
|
|
498
|
+
role: "user",
|
|
499
|
+
text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
|
|
500
|
+
# Ta package
|
|
501
|
+
Steps.
|
|
502
|
+
</skill>
|
|
503
|
+
|
|
504
|
+
Make a card`,
|
|
505
|
+
said: "Make a card"
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
mark: "a note of a task",
|
|
509
|
+
role: "user",
|
|
510
|
+
text: `<task_update id="t1" title="Fix login" status="done">
|
|
511
|
+
All tests pass.
|
|
512
|
+
</task_update>`,
|
|
513
|
+
said: "Fix login"
|
|
514
|
+
},
|
|
515
|
+
{ mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
|
|
516
|
+
Now t2.
|
|
517
|
+
</task_renamed>` },
|
|
518
|
+
{ mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
|
|
519
|
+
Switched to voice.`, said: "Switched to voice." },
|
|
520
|
+
{ mark: "a summary alone", role: "assistant", text: SUMMARY },
|
|
521
|
+
{ mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
|
|
522
|
+
<summary>` },
|
|
523
|
+
{
|
|
524
|
+
mark: "a card after the answer",
|
|
525
|
+
role: "assistant",
|
|
526
|
+
text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
|
|
527
|
+
said: "tests pass"
|
|
528
|
+
},
|
|
529
|
+
{ mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
|
|
530
|
+
{ mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
|
|
531
|
+
{ mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
|
|
532
|
+
{ mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
|
|
533
|
+
</system-reminder>
|
|
534
|
+
Ready.`, said: "Ready." }
|
|
535
|
+
];
|
|
536
|
+
function userWords(text2) {
|
|
537
|
+
const said = TaImageNote.strip(TaMessageContext.strip(text2));
|
|
538
|
+
const skill = TaSkillUse.parse(said);
|
|
539
|
+
if (skill) {
|
|
540
|
+
return TaSkillUse.command(skill);
|
|
541
|
+
}
|
|
542
|
+
const note = TaTaskNote.parse(said);
|
|
543
|
+
if (!note) {
|
|
544
|
+
return said;
|
|
545
|
+
}
|
|
546
|
+
if (note.kind === "renamed") {
|
|
547
|
+
return "";
|
|
548
|
+
}
|
|
549
|
+
return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
|
|
550
|
+
}
|
|
551
|
+
function withoutFences(text2, drop, tags = false) {
|
|
552
|
+
const kept = [];
|
|
553
|
+
let fence;
|
|
554
|
+
let left = false;
|
|
555
|
+
for (const part of text2.split(`
|
|
556
|
+
`)) {
|
|
557
|
+
const open = FENCE.exec(part);
|
|
558
|
+
if (!fence && open) {
|
|
559
|
+
fence = { mark: open[1], dropped: drop(open[2]) };
|
|
560
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
561
|
+
const dropped = fence.dropped;
|
|
562
|
+
fence = undefined;
|
|
563
|
+
if (dropped) {
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
|
|
568
|
+
left = true;
|
|
569
|
+
} else {
|
|
570
|
+
kept.push(part);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return left ? kept.join(`
|
|
574
|
+
`).replace(/\n{3,}/g, `
|
|
575
|
+
|
|
576
|
+
`) : kept.join(`
|
|
577
|
+
`);
|
|
578
|
+
}
|
|
579
|
+
function codeOf(text2) {
|
|
580
|
+
const code = [];
|
|
581
|
+
let fence;
|
|
582
|
+
for (const part of text2.split(`
|
|
583
|
+
`)) {
|
|
584
|
+
const open = FENCE.exec(part);
|
|
585
|
+
if (!fence && open) {
|
|
586
|
+
fence = { mark: open[1], card: CARD.test(open[2]) };
|
|
587
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
588
|
+
fence = undefined;
|
|
589
|
+
} else if (fence && !fence.card) {
|
|
590
|
+
code.push(part);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return code.join(`
|
|
594
|
+
`);
|
|
595
|
+
}
|
|
596
|
+
function closes(part, mark) {
|
|
597
|
+
var _a;
|
|
598
|
+
const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
|
|
599
|
+
return !!close && close[0] === mark[0] && close.length >= mark.length;
|
|
600
|
+
}
|
|
601
|
+
function plain(text2) {
|
|
602
|
+
const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
603
|
+
const words2 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
|
|
604
|
+
return words2 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
605
|
+
}
|
|
606
|
+
})(TaSaid || (TaSaid = {}));
|
|
607
|
+
|
|
115
608
|
// web-src/snapshot.ts
|
|
116
609
|
var MAX_TEXT = 4000;
|
|
117
610
|
var MAX_IMAGE = 1.5 * 1024 * 1024;
|
|
@@ -134,14 +627,19 @@ var ConversationSnapshot;
|
|
|
134
627
|
if (entry.type !== "message" || !message || role !== "user" && role !== "assistant" && role !== "toolResult" && role !== "custom") {
|
|
135
628
|
continue;
|
|
136
629
|
}
|
|
630
|
+
const said = (text) => role === "user" || role === "assistant" ? TaSaid.words(role, text) : text;
|
|
137
631
|
const parts = (content, pictures2 = true) => {
|
|
138
632
|
if (typeof content === "string") {
|
|
139
|
-
|
|
633
|
+
const text = said(content);
|
|
634
|
+
return text ? [{ type: "text", text: redactor.text(text) }] : [];
|
|
140
635
|
}
|
|
141
636
|
const kept = [];
|
|
142
637
|
for (const part of Array.isArray(content) ? content : []) {
|
|
143
|
-
|
|
144
|
-
|
|
638
|
+
const text = part.type === "text" && typeof part.text === "string" ? said(part.text) : undefined;
|
|
639
|
+
if (text !== undefined) {
|
|
640
|
+
if (text) {
|
|
641
|
+
kept.push({ type: "text", text: redactor.text(text) });
|
|
642
|
+
}
|
|
145
643
|
} else if (part.type === "thinking" && typeof part.thinking === "string" && part.thinking.trim()) {
|
|
146
644
|
kept.push({ type: "thinking", thinking: redactor.text(part.thinking) });
|
|
147
645
|
} else if (part.type === "toolCall" && typeof part.name === "string") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-share",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.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.
|
|
31
|
-
"@celljs/ta-relay": "4.
|
|
32
|
-
"@celljs/ta-web": "4.
|
|
30
|
+
"@celljs/ta-protocol": "4.19.0",
|
|
31
|
+
"@celljs/ta-relay": "4.19.0",
|
|
32
|
+
"@celljs/ta-web": "4.19.0",
|
|
33
33
|
"@types/react": "^19.3.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|