@celljs/ta-notify 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 +2 -2
- package/README.md +2 -2
- package/extension/index.mjs +508 -17
- package/host/index.mjs +497 -16
- package/package.json +3 -3
- package/web/index.js +497 -16
package/README.en.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A pi package that comes with Ta (on by default; turn it off in Settings → Extensions of the web client): notifications. While you are elsewhere in Ta, in another app, or with Ta in the background, it tells you which conversation answered, failed or waits for your decision, as a messenger does.
|
|
4
4
|
|
|
5
|
-
- **A turn ends**: the first two lines of its last answer (the error when it failed). A turn you stopped says nothing.
|
|
5
|
+
- **A turn ends**: the first two lines of its last answer (the error when it failed). A turn you stopped says nothing. A notice says words only: inner marks such as the summary an agent compacts its context to (`<conversation_history_summary>`) are left out, and a message of that summary alone is no answer.
|
|
6
6
|
- **It waits for you**: a dialog of an extension waits for your answer (pi's `ui_prompt_start`), told by its title.
|
|
7
7
|
- **A turn ends asking**: a turn another package marked as waiting for you to decide (`TA_ASK_ENTRY`, as a card of choices of Glance) is told as asking, by its question. What `notify_user` asks is marked so too, and the list of chats keeps showing it until you answer.
|
|
8
8
|
- **Ta asks you**: Ta has a tool `notify_user({ message, options?, kind? })`, for a decision only you can make, something that blocks it, or a long job you asked to hear about; `options` are up to 4 short answers, buttons on the notice, one tapped sent to that conversation as your message (once, even when a computer and a phone tap at the same time). A turn that used it says nothing more when it ends. The question and its answers also stay in the conversation as a card (the model does not read it), to tap on any device.
|
|
@@ -15,7 +15,7 @@ Settings → Notifications:
|
|
|
15
15
|
- **Notices of the system**: Allow turns on those of the browser. Ta Desktop needs no Allow: the app shows them itself, also while its window is closed, minimized or behind another (as long as it runs in the Dock or the tray). Pushes to the phone app while it is closed or the phone locked are not set up yet (they need APNs); meanwhile the dots of the list tell once the app is open.
|
|
16
16
|
- **Muted conversations**: Mute on a banner of an answer or a failure adds one; they tell you only when they need you. Unmute them here.
|
|
17
17
|
|
|
18
|
-
Sessions another package opened for a role of its own (an agent of a channel, a run of a schedule) say nothing when a turn ends, their package telling you in its own way; they still tell you when they ask or a dialog waits.
|
|
18
|
+
Sessions another package opened for a role of its own (an agent of a channel, a run of a schedule, and those whose role has the mark `[ta:tells-of-its-turns]`, as the conversation of a goal) say nothing when a turn ends, their package telling you in its own way; they still tell you when they fail, ask or a dialog waits.
|
|
19
19
|
|
|
20
20
|
## Data and calls
|
|
21
21
|
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展 关闭):提醒。你在 Ta 的别处、别的应用里,或者把 Ta 放在后台时,哪个对话回复了、失败了、在等你拍板,就告诉你,像聊天软件那样。
|
|
4
4
|
|
|
5
|
-
-
|
|
5
|
+
- **一轮结束**:最后的回答取前两行做成提醒(失败时是错误信息)。你停下的一轮不提醒。提醒里只放人话:智能体压缩上下文时写的摘要(`<conversation_history_summary>`)这类内部标记会去掉,只有摘要的那条消息不算回答。
|
|
6
6
|
- **在等你**:扩展的对话框在等回答时(pi 的 `ui_prompt_start`),用它的标题提醒你。
|
|
7
7
|
- **一轮以提问结束**:别的包把这一轮记成在等你决定(`TA_ASK_ENTRY`,如速览的选项卡片)时,按“需要你”提醒,内容是那个问题。`notify_user` 的提问也这样记下,对话列表就一直标着它,直到你回答。
|
|
8
8
|
- **Ta 主动问你**:Ta 有一个工具 `notify_user({ message, options?, kind? })`。只有你能做的决定、卡住它的事、你说过要听结果的长任务才用;`options` 是最多 4 个短回答,在提醒上是按钮,点一个就以你的身份发进那个对话(电脑和手机同时点也只发一次)。用过它的一轮,结束时不再另外提醒。问题和回答按钮也作为一张卡片留在对话里(模型读不到),任何设备打开对话都能点。
|
|
@@ -15,7 +15,7 @@ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展
|
|
|
15
15
|
- **系统通知**:浏览器里点"允许"开启。Ta 桌面版不用点:由应用自己发,窗口关掉、最小化或在后面时也会提醒(应用在程序坞或托盘里运行着就行)。手机 App 被关掉或锁屏后的推送还没有接入(需要 APNs),这时只在 App 打开后从列表的黄点看到。
|
|
16
16
|
- **免打扰的对话**:在回复或失败的横幅上点"免打扰"加入;这些对话只在需要你时提醒。这里可以取消。
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
由别的包打开、承担固定角色的会话(频道里的智能体、定时任务的运行,以及角色里带 `[ta:tells-of-its-turns]` 标记的会话,如目标自己的对话)一轮结束时不提醒,由那个包自己告诉你;它们失败、问你或有对话框在等时照样提醒。
|
|
19
19
|
|
|
20
20
|
## 数据与调用
|
|
21
21
|
|
package/extension/index.mjs
CHANGED
|
@@ -50,6 +50,7 @@ var TaHostUtil;
|
|
|
50
50
|
}
|
|
51
51
|
TaHostUtil2.role = role;
|
|
52
52
|
})(TaHostUtil || (TaHostUtil = {}));
|
|
53
|
+
var TA_TELLS_OF_ITS_TURNS_MARK = "[ta:tells-of-its-turns]";
|
|
53
54
|
var TA_ASK_ENTRY = "ta-ask";
|
|
54
55
|
var TaAskUtil;
|
|
55
56
|
(function(TaAskUtil2) {
|
|
@@ -103,6 +104,499 @@ var Keys;
|
|
|
103
104
|
Keys.MUTED = "muted";
|
|
104
105
|
})(Keys ||= {});
|
|
105
106
|
|
|
107
|
+
// ../ta-protocol/esm/common/message-protocol.js
|
|
108
|
+
var TaMessageContext;
|
|
109
|
+
(function(TaMessageContext2) {
|
|
110
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
111
|
+
function wrap(context, message) {
|
|
112
|
+
return `<context>
|
|
113
|
+
${context}
|
|
114
|
+
</context>
|
|
115
|
+
${message}`;
|
|
116
|
+
}
|
|
117
|
+
TaMessageContext2.wrap = wrap;
|
|
118
|
+
function strip(message) {
|
|
119
|
+
return message.replace(BLOCK, "");
|
|
120
|
+
}
|
|
121
|
+
TaMessageContext2.strip = strip;
|
|
122
|
+
function read(message) {
|
|
123
|
+
var _a;
|
|
124
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
125
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
126
|
+
}
|
|
127
|
+
TaMessageContext2.read = read;
|
|
128
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
129
|
+
var TaMessageSource;
|
|
130
|
+
(function(TaMessageSource2) {
|
|
131
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
132
|
+
const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
133
|
+
function mark(message, from, detail) {
|
|
134
|
+
return marked(message, line(from, detail));
|
|
135
|
+
}
|
|
136
|
+
TaMessageSource2.mark = mark;
|
|
137
|
+
function notice(message, from, detail) {
|
|
138
|
+
return marked(message, line(from, detail, true));
|
|
139
|
+
}
|
|
140
|
+
TaMessageSource2.notice = notice;
|
|
141
|
+
function line(from, detail, notice2 = false) {
|
|
142
|
+
return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
143
|
+
}
|
|
144
|
+
TaMessageSource2.line = line;
|
|
145
|
+
function of(message) {
|
|
146
|
+
const context = TaMessageContext.read(message);
|
|
147
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
148
|
+
return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
|
|
149
|
+
}
|
|
150
|
+
TaMessageSource2.of = of;
|
|
151
|
+
function isNotice(message) {
|
|
152
|
+
var _a;
|
|
153
|
+
return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
|
|
154
|
+
}
|
|
155
|
+
TaMessageSource2.isNotice = isNotice;
|
|
156
|
+
TaMessageSource2.SECTION = "ta-sources";
|
|
157
|
+
TaMessageSource2.PROMPT = [
|
|
158
|
+
"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.",
|
|
159
|
+
"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:",
|
|
160
|
+
"- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
|
|
161
|
+
"- 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).",
|
|
162
|
+
"- Never quote it as the user's words nor answer it as if they had said it."
|
|
163
|
+
].join(`
|
|
164
|
+
`);
|
|
165
|
+
function marked(message, source) {
|
|
166
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
167
|
+
return message;
|
|
168
|
+
}
|
|
169
|
+
const context = TaMessageContext.read(message);
|
|
170
|
+
return TaMessageContext.wrap(context === undefined ? source : `${context}
|
|
171
|
+
${source}`, TaMessageContext.strip(message));
|
|
172
|
+
}
|
|
173
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
174
|
+
var TaImageNote;
|
|
175
|
+
(function(TaImageNote2) {
|
|
176
|
+
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 [^\]]+\.\]$/;
|
|
177
|
+
function strip(text) {
|
|
178
|
+
const lines = text.split(`
|
|
179
|
+
`);
|
|
180
|
+
const kept = lines.filter((line) => !NOTE.test(line.trim()));
|
|
181
|
+
if (kept.length === lines.length) {
|
|
182
|
+
return text;
|
|
183
|
+
}
|
|
184
|
+
return kept.join(`
|
|
185
|
+
`).replace(/\n+$/, "").replace(/^\n+/, "");
|
|
186
|
+
}
|
|
187
|
+
TaImageNote2.strip = strip;
|
|
188
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
189
|
+
var TaImageSize;
|
|
190
|
+
(function(TaImageSize2) {
|
|
191
|
+
const JPEG_BYTES = 256 * 1024;
|
|
192
|
+
function of(base64) {
|
|
193
|
+
var _a, _b, _c;
|
|
194
|
+
let bytes;
|
|
195
|
+
try {
|
|
196
|
+
const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
|
|
197
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
198
|
+
} catch (_d) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
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);
|
|
202
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
203
|
+
}
|
|
204
|
+
TaImageSize2.of = of;
|
|
205
|
+
function u16be(bytes, at) {
|
|
206
|
+
return bytes[at] << 8 | bytes[at + 1];
|
|
207
|
+
}
|
|
208
|
+
function u16le(bytes, at) {
|
|
209
|
+
return bytes[at] | bytes[at + 1] << 8;
|
|
210
|
+
}
|
|
211
|
+
function u24le(bytes, at) {
|
|
212
|
+
return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
|
|
213
|
+
}
|
|
214
|
+
function u32be(bytes, at) {
|
|
215
|
+
return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
216
|
+
}
|
|
217
|
+
function text(bytes, at, length) {
|
|
218
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
219
|
+
}
|
|
220
|
+
function png(bytes) {
|
|
221
|
+
return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
222
|
+
}
|
|
223
|
+
function gif(bytes) {
|
|
224
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
225
|
+
}
|
|
226
|
+
function webp(bytes) {
|
|
227
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
switch (text(bytes, 12, 4)) {
|
|
231
|
+
case "VP8 ":
|
|
232
|
+
return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
|
|
233
|
+
case "VP8L": {
|
|
234
|
+
const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
|
|
235
|
+
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
|
|
236
|
+
}
|
|
237
|
+
case "VP8X":
|
|
238
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
239
|
+
default:
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function jpeg(bytes) {
|
|
244
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
let at = 2;
|
|
248
|
+
while (at + 9 < bytes.length) {
|
|
249
|
+
if (bytes[at] !== 255) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const marker = bytes[at + 1];
|
|
253
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
254
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
255
|
+
}
|
|
256
|
+
at += 2 + u16be(bytes, at + 2);
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
261
|
+
var TaAgentSummary;
|
|
262
|
+
(function(TaAgentSummary2) {
|
|
263
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
264
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
265
|
+
function read(text) {
|
|
266
|
+
if (!START.test(text)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
|
|
270
|
+
}
|
|
271
|
+
TaAgentSummary2.read = read;
|
|
272
|
+
function strip(text) {
|
|
273
|
+
return text.replace(BLOCK, "");
|
|
274
|
+
}
|
|
275
|
+
TaAgentSummary2.strip = strip;
|
|
276
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
277
|
+
var TaSkillUse;
|
|
278
|
+
(function(TaSkillUse2) {
|
|
279
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
280
|
+
function parse(message) {
|
|
281
|
+
var _a;
|
|
282
|
+
const match = BLOCK.exec(message);
|
|
283
|
+
if (!match) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
287
|
+
}
|
|
288
|
+
TaSkillUse2.parse = parse;
|
|
289
|
+
function command(use) {
|
|
290
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
291
|
+
}
|
|
292
|
+
TaSkillUse2.command = command;
|
|
293
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
294
|
+
var TaTaskNote;
|
|
295
|
+
(function(TaTaskNote2) {
|
|
296
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
297
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
298
|
+
function write(note) {
|
|
299
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
300
|
+
if (note.was !== undefined) {
|
|
301
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
302
|
+
}
|
|
303
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
304
|
+
if (note.status !== undefined) {
|
|
305
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
306
|
+
}
|
|
307
|
+
return `<task_${note.kind} ${attributes.join(" ")}>
|
|
308
|
+
${note.body}
|
|
309
|
+
</task_${note.kind}>`;
|
|
310
|
+
}
|
|
311
|
+
TaTaskNote2.write = write;
|
|
312
|
+
function parse(text) {
|
|
313
|
+
const match = NOTE.exec(text.trim());
|
|
314
|
+
if (!match) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const attributes = {};
|
|
318
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
319
|
+
attributes[name] = unquote(value);
|
|
320
|
+
}
|
|
321
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const { id, title, status, was } = attributes;
|
|
325
|
+
return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
|
|
326
|
+
}
|
|
327
|
+
TaTaskNote2.parse = parse;
|
|
328
|
+
function quote(text) {
|
|
329
|
+
return text.replace(/&/g, "&").replace(/"/g, """).replace(/\n/g, " ");
|
|
330
|
+
}
|
|
331
|
+
function unquote(text) {
|
|
332
|
+
return text.replace(/"/g, '"').replace(/&/g, "&");
|
|
333
|
+
}
|
|
334
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
335
|
+
var TaSecretRef;
|
|
336
|
+
(function(TaSecretRef2) {
|
|
337
|
+
TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
|
|
338
|
+
const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
|
|
339
|
+
const KINDS = [
|
|
340
|
+
[/^PHONE(?:_\d+)?$/, "phone"],
|
|
341
|
+
[/^EMAIL(?:_\d+)?$/, "email"],
|
|
342
|
+
[/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
|
|
343
|
+
[/^BANK_CARD(?:_\d+)?$/, "bankCard"]
|
|
344
|
+
];
|
|
345
|
+
function has(text) {
|
|
346
|
+
return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
|
|
347
|
+
}
|
|
348
|
+
TaSecretRef2.has = has;
|
|
349
|
+
function kind(name) {
|
|
350
|
+
var _a;
|
|
351
|
+
var _b;
|
|
352
|
+
return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
|
|
353
|
+
}
|
|
354
|
+
TaSecretRef2.kind = kind;
|
|
355
|
+
function split(text) {
|
|
356
|
+
if (!has(text)) {
|
|
357
|
+
return [{ text }];
|
|
358
|
+
}
|
|
359
|
+
const parts = [];
|
|
360
|
+
let at = 0;
|
|
361
|
+
for (const match of text.matchAll(REF)) {
|
|
362
|
+
if (match.index > at) {
|
|
363
|
+
parts.push({ text: text.slice(at, match.index) });
|
|
364
|
+
}
|
|
365
|
+
parts.push({ secret: match[1], kind: kind(match[1]) });
|
|
366
|
+
at = match.index + match[0].length;
|
|
367
|
+
}
|
|
368
|
+
if (at < text.length) {
|
|
369
|
+
parts.push({ text: text.slice(at) });
|
|
370
|
+
}
|
|
371
|
+
return parts;
|
|
372
|
+
}
|
|
373
|
+
TaSecretRef2.split = split;
|
|
374
|
+
function plain(text, label) {
|
|
375
|
+
return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
|
|
376
|
+
}
|
|
377
|
+
TaSecretRef2.plain = plain;
|
|
378
|
+
})(TaSecretRef || (TaSecretRef = {}));
|
|
379
|
+
|
|
380
|
+
// ../ta-protocol/esm/common/said-protocol.js
|
|
381
|
+
var TaSaid;
|
|
382
|
+
(function(TaSaid2) {
|
|
383
|
+
const CARD = /^ta-/i;
|
|
384
|
+
const READ = 4000;
|
|
385
|
+
const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
|
|
386
|
+
const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
|
|
387
|
+
const MARKS_ONLY = /^[-*_=|:+\s]+$/;
|
|
388
|
+
const MARKS = [
|
|
389
|
+
["context", /<\/?context>/],
|
|
390
|
+
["source", /\[ta:(?:from|notice|by) /],
|
|
391
|
+
["image note", /\[Image: original \d+x\d+|\[Image converted from /],
|
|
392
|
+
["skill", /<skill name="|<\/skill>/],
|
|
393
|
+
["task note", /<\/?task_(?:update|adopted|renamed)\b/],
|
|
394
|
+
["summary", /<\/?(?:conversation_history_summary|summary)>/]
|
|
395
|
+
];
|
|
396
|
+
function text(content, joiner = `
|
|
397
|
+
`) {
|
|
398
|
+
if (typeof content === "string") {
|
|
399
|
+
return content;
|
|
400
|
+
}
|
|
401
|
+
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) : "";
|
|
402
|
+
}
|
|
403
|
+
TaSaid2.text = text;
|
|
404
|
+
function words(role, text2, options = {}) {
|
|
405
|
+
const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
|
|
406
|
+
return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
|
|
407
|
+
}
|
|
408
|
+
TaSaid2.words = words;
|
|
409
|
+
function of(message, options) {
|
|
410
|
+
return message ? words(message.role, text(message.content), options) : "";
|
|
411
|
+
}
|
|
412
|
+
TaSaid2.of = of;
|
|
413
|
+
function notice(message) {
|
|
414
|
+
return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
|
|
415
|
+
}
|
|
416
|
+
TaSaid2.notice = notice;
|
|
417
|
+
function marksOnly(role, text2) {
|
|
418
|
+
return !!text2.trim() && !line(words(role, text2), { chars: Number.POSITIVE_INFINITY });
|
|
419
|
+
}
|
|
420
|
+
TaSaid2.marksOnly = marksOnly;
|
|
421
|
+
function line(markdown, options) {
|
|
422
|
+
var _a;
|
|
423
|
+
const read = markdown.slice(0, READ);
|
|
424
|
+
const prose = withoutFences(read, () => true, true).trim();
|
|
425
|
+
const lines = plain(prose || codeOf(read)).split(`
|
|
426
|
+
`).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));
|
|
427
|
+
const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
|
|
428
|
+
const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
|
|
429
|
+
`);
|
|
430
|
+
return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
|
|
431
|
+
}
|
|
432
|
+
TaSaid2.line = line;
|
|
433
|
+
function leaks(shown, options = {}) {
|
|
434
|
+
const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
|
|
435
|
+
const lines = shown.split(`
|
|
436
|
+
`);
|
|
437
|
+
if (options.cards !== true && lines.some((part) => {
|
|
438
|
+
var _a;
|
|
439
|
+
var _b;
|
|
440
|
+
return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
|
|
441
|
+
})) {
|
|
442
|
+
found.push("card");
|
|
443
|
+
}
|
|
444
|
+
if (lines.some((part) => TAG_LINE.test(part.trim()))) {
|
|
445
|
+
found.push("tag");
|
|
446
|
+
}
|
|
447
|
+
return found;
|
|
448
|
+
}
|
|
449
|
+
TaSaid2.leaks = leaks;
|
|
450
|
+
const SUMMARY = `<conversation_history_summary>
|
|
451
|
+
<summary>
|
|
452
|
+
1. Primary Request and Intent:
|
|
453
|
+
The user works on the relay.
|
|
454
|
+
</summary>
|
|
455
|
+
</conversation_history_summary>`;
|
|
456
|
+
TaSaid2.SAMPLES = [
|
|
457
|
+
{
|
|
458
|
+
mark: "context and where it came from",
|
|
459
|
+
role: "user",
|
|
460
|
+
text: `<context>
|
|
461
|
+
The channel #ops, its members.
|
|
462
|
+
[ta:from @celljs/ta-channels #ops]
|
|
463
|
+
</context>
|
|
464
|
+
Check the build`,
|
|
465
|
+
said: "Check the build"
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
mark: "a notice, not the user",
|
|
469
|
+
role: "user",
|
|
470
|
+
text: `<context>
|
|
471
|
+
[ta:notice @celljs/ta-call]
|
|
472
|
+
</context>
|
|
473
|
+
The work finished. Its last words: tests pass.`,
|
|
474
|
+
said: "The work finished. Its last words: tests pass."
|
|
475
|
+
},
|
|
476
|
+
{ mark: "one let in", role: "user", text: `<context>
|
|
477
|
+
[ta:by p-7 Alice]
|
|
478
|
+
</context>
|
|
479
|
+
Hello there`, said: "Hello there" },
|
|
480
|
+
{
|
|
481
|
+
mark: "notes of images",
|
|
482
|
+
role: "user",
|
|
483
|
+
text: `Look at this
|
|
484
|
+
[Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
|
|
485
|
+
[Image converted from image/heic to image/png.]`,
|
|
486
|
+
said: "Look at this"
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
mark: "a skill run",
|
|
490
|
+
role: "user",
|
|
491
|
+
text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
|
|
492
|
+
# Ta package
|
|
493
|
+
Steps.
|
|
494
|
+
</skill>
|
|
495
|
+
|
|
496
|
+
Make a card`,
|
|
497
|
+
said: "Make a card"
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
mark: "a note of a task",
|
|
501
|
+
role: "user",
|
|
502
|
+
text: `<task_update id="t1" title="Fix login" status="done">
|
|
503
|
+
All tests pass.
|
|
504
|
+
</task_update>`,
|
|
505
|
+
said: "Fix login"
|
|
506
|
+
},
|
|
507
|
+
{ mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
|
|
508
|
+
Now t2.
|
|
509
|
+
</task_renamed>` },
|
|
510
|
+
{ mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
|
|
511
|
+
Switched to voice.`, said: "Switched to voice." },
|
|
512
|
+
{ mark: "a summary alone", role: "assistant", text: SUMMARY },
|
|
513
|
+
{ mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
|
|
514
|
+
<summary>` },
|
|
515
|
+
{
|
|
516
|
+
mark: "a card after the answer",
|
|
517
|
+
role: "assistant",
|
|
518
|
+
text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
|
|
519
|
+
said: "tests pass"
|
|
520
|
+
},
|
|
521
|
+
{ mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
|
|
522
|
+
{ mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
|
|
523
|
+
{ mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
|
|
524
|
+
{ mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
|
|
525
|
+
</system-reminder>
|
|
526
|
+
Ready.`, said: "Ready." }
|
|
527
|
+
];
|
|
528
|
+
function userWords(text2) {
|
|
529
|
+
const said = TaImageNote.strip(TaMessageContext.strip(text2));
|
|
530
|
+
const skill = TaSkillUse.parse(said);
|
|
531
|
+
if (skill) {
|
|
532
|
+
return TaSkillUse.command(skill);
|
|
533
|
+
}
|
|
534
|
+
const note = TaTaskNote.parse(said);
|
|
535
|
+
if (!note) {
|
|
536
|
+
return said;
|
|
537
|
+
}
|
|
538
|
+
if (note.kind === "renamed") {
|
|
539
|
+
return "";
|
|
540
|
+
}
|
|
541
|
+
return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
|
|
542
|
+
}
|
|
543
|
+
function withoutFences(text2, drop, tags = false) {
|
|
544
|
+
const kept = [];
|
|
545
|
+
let fence;
|
|
546
|
+
let left = false;
|
|
547
|
+
for (const part of text2.split(`
|
|
548
|
+
`)) {
|
|
549
|
+
const open = FENCE.exec(part);
|
|
550
|
+
if (!fence && open) {
|
|
551
|
+
fence = { mark: open[1], dropped: drop(open[2]) };
|
|
552
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
553
|
+
const dropped = fence.dropped;
|
|
554
|
+
fence = undefined;
|
|
555
|
+
if (dropped) {
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
|
|
560
|
+
left = true;
|
|
561
|
+
} else {
|
|
562
|
+
kept.push(part);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return left ? kept.join(`
|
|
566
|
+
`).replace(/\n{3,}/g, `
|
|
567
|
+
|
|
568
|
+
`) : kept.join(`
|
|
569
|
+
`);
|
|
570
|
+
}
|
|
571
|
+
function codeOf(text2) {
|
|
572
|
+
const code = [];
|
|
573
|
+
let fence;
|
|
574
|
+
for (const part of text2.split(`
|
|
575
|
+
`)) {
|
|
576
|
+
const open = FENCE.exec(part);
|
|
577
|
+
if (!fence && open) {
|
|
578
|
+
fence = { mark: open[1], card: CARD.test(open[2]) };
|
|
579
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
580
|
+
fence = undefined;
|
|
581
|
+
} else if (fence && !fence.card) {
|
|
582
|
+
code.push(part);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return code.join(`
|
|
586
|
+
`);
|
|
587
|
+
}
|
|
588
|
+
function closes(part, mark) {
|
|
589
|
+
var _a;
|
|
590
|
+
const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
|
|
591
|
+
return !!close && close[0] === mark[0] && close.length >= mark.length;
|
|
592
|
+
}
|
|
593
|
+
function plain(text2) {
|
|
594
|
+
const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
595
|
+
const words2 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
|
|
596
|
+
return words2 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
597
|
+
}
|
|
598
|
+
})(TaSaid || (TaSaid = {}));
|
|
599
|
+
|
|
106
600
|
// web-src/notify-util.ts
|
|
107
601
|
var KEEP = 30;
|
|
108
602
|
var FRESH_MS = 2 * 60000;
|
|
@@ -147,11 +641,7 @@ var NotifyUtil;
|
|
|
147
641
|
}
|
|
148
642
|
NotifyUtil.fresh = fresh;
|
|
149
643
|
function text(markdown) {
|
|
150
|
-
|
|
151
|
-
`).map((line) => line.replace(/^\s{0,3}(#{1,6}\s+|>\s?|[-*+]\s+|\d+[.)]\s+)/, "").replace(/(\*\*|__|\*|`|~~)/g, "").replace(/\s+/g, " ").trim()).filter((line) => line && !/^[-*_=|:\s]+$/.test(line));
|
|
152
|
-
const joined = lines.slice(0, 2).join(`
|
|
153
|
-
`);
|
|
154
|
-
return joined.length > TEXT_CHARS ? `${joined.slice(0, TEXT_CHARS - 1).trimEnd()}…` : joined;
|
|
644
|
+
return TaSaid.line(TaSaid.words("assistant", markdown), { chars: TEXT_CHARS, lines: 2 });
|
|
155
645
|
}
|
|
156
646
|
NotifyUtil.text = text;
|
|
157
647
|
function options(value) {
|
|
@@ -164,23 +654,15 @@ var NotifyUtil;
|
|
|
164
654
|
return picked.length ? picked : undefined;
|
|
165
655
|
}
|
|
166
656
|
NotifyUtil.options = options;
|
|
167
|
-
function contentText(content) {
|
|
168
|
-
if (typeof content === "string") {
|
|
169
|
-
return content;
|
|
170
|
-
}
|
|
171
|
-
return Array.isArray(content) ? content.filter((part) => part?.type === "text" && typeof part.text === "string").map((part) => part.text).join(`
|
|
172
|
-
`) : "";
|
|
173
|
-
}
|
|
174
|
-
NotifyUtil.contentText = contentText;
|
|
175
657
|
function lastAnswer(messages) {
|
|
176
|
-
const
|
|
658
|
+
const answers = messages.filter((message) => message?.role === "assistant");
|
|
659
|
+
const answer = [...answers].reverse().find((message) => message.stopReason === "error" || !TaSaid.marksOnly("assistant", TaSaid.text(message.content))) ?? answers.at(-1);
|
|
177
660
|
if (!answer) {
|
|
178
661
|
return;
|
|
179
662
|
}
|
|
180
663
|
const failed = answer.stopReason === "error";
|
|
181
|
-
const said = contentText(answer.content);
|
|
182
664
|
return {
|
|
183
|
-
text: failed && answer.errorMessage ? answer.errorMessage :
|
|
665
|
+
text: failed && answer.errorMessage ? answer.errorMessage : TaSaid.text(answer.content),
|
|
184
666
|
failed,
|
|
185
667
|
aborted: answer.stopReason === "aborted",
|
|
186
668
|
at: typeof answer.timestamp === "number" ? answer.timestamp : Date.now()
|
|
@@ -347,7 +829,16 @@ function activate(pi) {
|
|
|
347
829
|
}
|
|
348
830
|
const asking = answer.failed ? undefined : TaAskUtil.asking(ctx.sessionManager.getBranch?.() ?? []);
|
|
349
831
|
if (asking && asking.at >= startedAt) {
|
|
350
|
-
post({
|
|
832
|
+
post({
|
|
833
|
+
piSessionId: ctx.sessionManager.getSessionId(),
|
|
834
|
+
id: String(answer.at),
|
|
835
|
+
level: "ask",
|
|
836
|
+
source: "turn",
|
|
837
|
+
text: NotifyUtil.text(asking.question) || NotifyServerTexts.waiting()
|
|
838
|
+
});
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
if (!answer.failed && TaHostUtil.marked(ctx.getSystemPrompt?.(), TA_TELLS_OF_ITS_TURNS_MARK)) {
|
|
351
842
|
return;
|
|
352
843
|
}
|
|
353
844
|
const text = NotifyUtil.text(answer.text) || (answer.failed ? NotifyServerTexts.failed() : "");
|