@celljs/ta-bots 4.9.1 → 4.11.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/extension/index.mjs +31 -253
- package/host/index.mjs +189 -1
- package/package.json +3 -3
- package/web/index.js +47 -16
package/extension/index.mjs
CHANGED
|
@@ -1,241 +1,24 @@
|
|
|
1
|
-
// ../ta-protocol/esm/common/access-protocol.js
|
|
2
|
-
var TaAccessServer = Symbol("TaAccessServer");
|
|
3
|
-
// ../ta-protocol/esm/common/auth-protocol.js
|
|
4
|
-
var TaAuthServer = Symbol("TaAuthServer");
|
|
5
|
-
// ../ta-protocol/esm/common/gateway-protocol.js
|
|
6
|
-
var TaGatewayServer = Symbol("TaGatewayServer");
|
|
7
|
-
// ../ta-protocol/esm/common/location.js
|
|
8
|
-
var TaLocation;
|
|
9
|
-
(function(TaLocation2) {
|
|
10
|
-
TaLocation2.SSH = "ssh://";
|
|
11
|
-
const HOST = /^(?!-)[\w.@:%+[\]-]+$/;
|
|
12
|
-
function isRemote(location) {
|
|
13
|
-
return location.startsWith(TaLocation2.SSH);
|
|
14
|
-
}
|
|
15
|
-
TaLocation2.isRemote = isRemote;
|
|
16
|
-
function parse(location) {
|
|
17
|
-
if (!isRemote(location)) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const rest = location.slice(TaLocation2.SSH.length);
|
|
21
|
-
const slash = rest.indexOf("/");
|
|
22
|
-
const host2 = slash < 0 ? rest : rest.slice(0, slash);
|
|
23
|
-
const path2 = slash < 0 ? "" : normalize(rest.slice(slash));
|
|
24
|
-
if (!isHost(host2)) {
|
|
25
|
-
throw new Error(`${JSON.stringify(location)} names no host: write ssh://<host>/<path>, the host as ssh takes it.`);
|
|
26
|
-
}
|
|
27
|
-
return { host: host2, path: path2 };
|
|
28
|
-
}
|
|
29
|
-
TaLocation2.parse = parse;
|
|
30
|
-
function isHost(host2) {
|
|
31
|
-
return HOST.test(host2);
|
|
32
|
-
}
|
|
33
|
-
TaLocation2.isHost = isHost;
|
|
34
|
-
const FLAGS = /^-[46AaCfGgKkMNnqsTtVvXxYy]+$/;
|
|
35
|
-
function readHost(input) {
|
|
36
|
-
const words = input.trim().split(/\s+/).filter(Boolean);
|
|
37
|
-
if (words[0] === "ssh") {
|
|
38
|
-
words.shift();
|
|
39
|
-
}
|
|
40
|
-
let destination;
|
|
41
|
-
let port;
|
|
42
|
-
let user;
|
|
43
|
-
const options = [];
|
|
44
|
-
for (let i = 0;i < words.length; i++) {
|
|
45
|
-
const word = words[i];
|
|
46
|
-
const glued = /^-([pl])(.+)$/.exec(word);
|
|
47
|
-
if (word === "-p" || word === "-l" || glued) {
|
|
48
|
-
const value = glued ? glued[2] : words[++i];
|
|
49
|
-
if (value === undefined) {
|
|
50
|
-
return { error: "invalid" };
|
|
51
|
-
}
|
|
52
|
-
if ((glued ? glued[1] : word[1]) === "p") {
|
|
53
|
-
port = value;
|
|
54
|
-
} else {
|
|
55
|
-
user = value;
|
|
56
|
-
}
|
|
57
|
-
} else if (word === "-o" || word.startsWith("-o")) {
|
|
58
|
-
const value = word === "-o" ? words[++i] : word.slice(2);
|
|
59
|
-
const option = /^(port|user)\s*=?\s*(.+)$/i.exec(value !== null && value !== undefined ? value : "");
|
|
60
|
-
if (!option) {
|
|
61
|
-
options.push(`-o ${value !== null && value !== undefined ? value : ""}`.trim());
|
|
62
|
-
} else if (option[1].toLowerCase() === "port") {
|
|
63
|
-
port = option[2];
|
|
64
|
-
} else {
|
|
65
|
-
user = option[2];
|
|
66
|
-
}
|
|
67
|
-
} else if (FLAGS.test(word)) {} else if (word.startsWith("-")) {
|
|
68
|
-
options.push(/^-[bBcDeEFiIJLmOQRSwW]$/.test(word) && words[i + 1] !== undefined ? `${word} ${words[++i]}` : word);
|
|
69
|
-
} else if (destination === undefined) {
|
|
70
|
-
destination = word;
|
|
71
|
-
} else {
|
|
72
|
-
return { error: "invalid" };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (options.length > 0) {
|
|
76
|
-
return { error: "options", options };
|
|
77
|
-
}
|
|
78
|
-
if (!destination) {
|
|
79
|
-
return { error: "empty" };
|
|
80
|
-
}
|
|
81
|
-
let host2 = destination.replace(/^ssh:\/\//, "").replace(/\/.*$/, "");
|
|
82
|
-
if (user && !host2.includes("@")) {
|
|
83
|
-
host2 = `${user}@${host2}`;
|
|
84
|
-
}
|
|
85
|
-
if (port) {
|
|
86
|
-
if (!/^\d{1,5}$/.test(port) || /:\d+$/.test(host2)) {
|
|
87
|
-
return { error: "invalid" };
|
|
88
|
-
}
|
|
89
|
-
host2 = port === "22" ? host2 : `${host2}:${port}`;
|
|
90
|
-
}
|
|
91
|
-
return isHost(host2) ? { host: host2 } : { error: "invalid" };
|
|
92
|
-
}
|
|
93
|
-
TaLocation2.readHost = readHost;
|
|
94
|
-
function ssh(host2, path2 = "") {
|
|
95
|
-
return `${TaLocation2.SSH}${host2}${path2 ? normalize(path2) : ""}`;
|
|
96
|
-
}
|
|
97
|
-
TaLocation2.ssh = ssh;
|
|
98
|
-
function hostLabel(host2) {
|
|
99
|
-
const name = host2.replace(/^[^@]*@/, "").replace(/^\[(.*)\](?::\d+)?$/, "$1").replace(/^([^:]*):\d+$/, "$1");
|
|
100
|
-
return /^[\d.]+$/.test(name) || name.includes(":") ? name : name.split(".")[0] || name;
|
|
101
|
-
}
|
|
102
|
-
TaLocation2.hostLabel = hostLabel;
|
|
103
|
-
function host(location) {
|
|
104
|
-
var _a;
|
|
105
|
-
return isRemote(location) ? (_a = parse(location)) === null || _a === undefined ? undefined : _a.host : undefined;
|
|
106
|
-
}
|
|
107
|
-
TaLocation2.host = host;
|
|
108
|
-
function path(location) {
|
|
109
|
-
var _a;
|
|
110
|
-
var _b;
|
|
111
|
-
return (_b = (_a = parse(location)) === null || _a === undefined ? undefined : _a.path) !== null && _b !== undefined ? _b : location;
|
|
112
|
-
}
|
|
113
|
-
TaLocation2.path = path;
|
|
114
|
-
function parent(location) {
|
|
115
|
-
const remote = parse(location);
|
|
116
|
-
if (remote) {
|
|
117
|
-
const above = remote.path ? parentPath(remote.path) : undefined;
|
|
118
|
-
return above === undefined ? undefined : ssh(remote.host, above);
|
|
119
|
-
}
|
|
120
|
-
return parentPath(location);
|
|
121
|
-
}
|
|
122
|
-
TaLocation2.parent = parent;
|
|
123
|
-
function child(location, name) {
|
|
124
|
-
const remote = parse(location);
|
|
125
|
-
if (remote) {
|
|
126
|
-
return ssh(remote.host, childPath(remote.path || "/", name));
|
|
127
|
-
}
|
|
128
|
-
return childPath(location, name);
|
|
129
|
-
}
|
|
130
|
-
TaLocation2.child = child;
|
|
131
|
-
function basename(location) {
|
|
132
|
-
const remote = parse(location);
|
|
133
|
-
const path2 = (remote ? remote.path : location).replace(/[\\/]+$/, "");
|
|
134
|
-
const name = path2.slice(Math.max(path2.lastIndexOf("/"), path2.lastIndexOf("\\")) + 1);
|
|
135
|
-
return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
|
|
136
|
-
}
|
|
137
|
-
TaLocation2.basename = basename;
|
|
138
|
-
function parentPath(path2) {
|
|
139
|
-
const trimmed = path2.replace(/[\\/]+$/, "");
|
|
140
|
-
const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
141
|
-
if (at < 0) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const head = trimmed.slice(0, at);
|
|
145
|
-
return head === "" || /^[A-Za-z]:$/.test(head) ? head + trimmed[at] : head;
|
|
146
|
-
}
|
|
147
|
-
function childPath(path2, name) {
|
|
148
|
-
const separator = path2.includes("/") || !path2.includes("\\") ? "/" : "\\";
|
|
149
|
-
return path2.endsWith(separator) ? path2 + name : path2 + separator + name;
|
|
150
|
-
}
|
|
151
|
-
function normalize(path2) {
|
|
152
|
-
const squeezed = `/${path2}`.replace(/\/+/g, "/");
|
|
153
|
-
return squeezed.length > 1 ? squeezed.replace(/\/$/, "") : squeezed;
|
|
154
|
-
}
|
|
155
|
-
})(TaLocation || (TaLocation = {}));
|
|
156
|
-
// ../ta-protocol/esm/common/package-protocol.js
|
|
157
|
-
var TaPackageServer = Symbol("TaPackageServer");
|
|
158
|
-
var TaPackageTextUtil;
|
|
159
|
-
(function(TaPackageTextUtil2) {
|
|
160
|
-
function pick(text, language) {
|
|
161
|
-
var _a, _b, _c, _d;
|
|
162
|
-
if (text === undefined || typeof text === "string") {
|
|
163
|
-
return text;
|
|
164
|
-
}
|
|
165
|
-
return (_d = (_c = (_b = (_a = text[language]) !== null && _a !== undefined ? _a : text[language.split("-")[0]]) !== null && _b !== undefined ? _b : text.en) !== null && _c !== undefined ? _c : text["en-US"]) !== null && _d !== undefined ? _d : Object.values(text)[0];
|
|
166
|
-
}
|
|
167
|
-
TaPackageTextUtil2.pick = pick;
|
|
168
|
-
})(TaPackageTextUtil || (TaPackageTextUtil = {}));
|
|
169
|
-
// ../ta-protocol/esm/common/relay-protocol.js
|
|
170
|
-
var TaRelayServer = Symbol("TaRelayServer");
|
|
171
|
-
// ../ta-protocol/esm/common/remote-protocol.js
|
|
172
|
-
var TaRemoteServer = Symbol("TaRemoteServer");
|
|
173
|
-
// ../ta-protocol/esm/common/settings-protocol.js
|
|
174
|
-
var TaSettingsServer = Symbol("TaSettingsServer");
|
|
175
1
|
// ../ta-protocol/esm/common/ta-extension-host.js
|
|
176
2
|
var TA_HOST_EVENT = "ta:host";
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
(function(TaMessageContext2) {
|
|
193
|
-
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
194
|
-
function wrap(context, message) {
|
|
195
|
-
return `<context>
|
|
196
|
-
${context}
|
|
197
|
-
</context>
|
|
198
|
-
${message}`;
|
|
199
|
-
}
|
|
200
|
-
TaMessageContext2.wrap = wrap;
|
|
201
|
-
function strip(message) {
|
|
202
|
-
return message.replace(BLOCK, "");
|
|
203
|
-
}
|
|
204
|
-
TaMessageContext2.strip = strip;
|
|
205
|
-
})(TaMessageContext || (TaMessageContext = {}));
|
|
206
|
-
var TaSkillUse;
|
|
207
|
-
(function(TaSkillUse2) {
|
|
208
|
-
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
209
|
-
function parse(message) {
|
|
210
|
-
var _a;
|
|
211
|
-
const match = BLOCK.exec(message);
|
|
212
|
-
if (!match) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
216
|
-
}
|
|
217
|
-
TaSkillUse2.parse = parse;
|
|
218
|
-
function command(use) {
|
|
219
|
-
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
220
|
-
}
|
|
221
|
-
TaSkillUse2.command = command;
|
|
222
|
-
})(TaSkillUse || (TaSkillUse = {}));
|
|
223
|
-
// ../ta-protocol/esm/common/workspace-protocol.js
|
|
224
|
-
var TaWorkspaceServer = Symbol("TaWorkspaceServer");
|
|
225
|
-
var TaTerminalServer = Symbol("TaTerminalServer");
|
|
226
|
-
var TaExcludedFiles;
|
|
227
|
-
(function(TaExcludedFiles2) {
|
|
228
|
-
TaExcludedFiles2.NAMES = [".git", ".svn", ".hg", ".DS_Store", "Thumbs.db"];
|
|
229
|
-
function has(name) {
|
|
230
|
-
return TaExcludedFiles2.NAMES.includes(name);
|
|
231
|
-
}
|
|
232
|
-
TaExcludedFiles2.has = has;
|
|
233
|
-
function filter(entries) {
|
|
234
|
-
return entries.filter((entry) => !has(entry.name));
|
|
3
|
+
var TaHostUtil;
|
|
4
|
+
(function(TaHostUtil2) {
|
|
5
|
+
TaHostUtil2.WAIT_MS = 1000;
|
|
6
|
+
function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
9
|
+
const request = {
|
|
10
|
+
name,
|
|
11
|
+
resolve: (answer) => {
|
|
12
|
+
clearTimeout(timer);
|
|
13
|
+
resolve(answer);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
events.emit(TA_HOST_EVENT, request);
|
|
17
|
+
});
|
|
235
18
|
}
|
|
236
|
-
|
|
237
|
-
})(
|
|
238
|
-
|
|
19
|
+
TaHostUtil2.reach = reach;
|
|
20
|
+
})(TaHostUtil || (TaHostUtil = {}));
|
|
21
|
+
|
|
239
22
|
// web-src/bots-protocol.ts
|
|
240
23
|
var NAME = "@celljs/ta-bots";
|
|
241
24
|
var Keys;
|
|
@@ -245,6 +28,7 @@ var Keys;
|
|
|
245
28
|
})(Keys ||= {});
|
|
246
29
|
var INBOUND_TYPE = "ta-bots";
|
|
247
30
|
var SENT_TYPE = "ta-bots-sent";
|
|
31
|
+
var SEND_FILE_TOOL = "bot_send_file";
|
|
248
32
|
var BotTargetUtil;
|
|
249
33
|
((BotTargetUtil) => {
|
|
250
34
|
function same(a, b) {
|
|
@@ -374,13 +158,19 @@ var BotText;
|
|
|
374
158
|
function plain(markdown) {
|
|
375
159
|
const lines = [];
|
|
376
160
|
let fenced = false;
|
|
161
|
+
let card = false;
|
|
377
162
|
for (const line of markdown.replace(/\r\n/g, `
|
|
378
163
|
`).split(`
|
|
379
164
|
`)) {
|
|
380
|
-
|
|
165
|
+
const fence = /^\s*(?:```|~~~)\s*([\w-]*)/.exec(line);
|
|
166
|
+
if (fence) {
|
|
167
|
+
card = !fenced && fence[1].toLowerCase().startsWith("ta-");
|
|
381
168
|
fenced = !fenced;
|
|
382
169
|
continue;
|
|
383
170
|
}
|
|
171
|
+
if (card) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
384
174
|
if (fenced) {
|
|
385
175
|
lines.push(line);
|
|
386
176
|
continue;
|
|
@@ -437,12 +227,12 @@ var BotText;
|
|
|
437
227
|
})(BotText ||= {});
|
|
438
228
|
|
|
439
229
|
// web-src/extension.ts
|
|
440
|
-
var HOST_WAIT_MS = 1000;
|
|
441
230
|
var INBOX = ".ta/inbox";
|
|
442
231
|
var IMAGE_BYTES = 5 * 1024 * 1024;
|
|
443
232
|
var MODEL_IMAGES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
|
444
|
-
var TOOL =
|
|
233
|
+
var TOOL = SEND_FILE_TOOL;
|
|
445
234
|
var KIND = { weixin: "WeChat", wecom: "WeCom" };
|
|
235
|
+
var SECTION = "ta-bots";
|
|
446
236
|
function inboundText(details) {
|
|
447
237
|
const who = details.from.name || details.from.id;
|
|
448
238
|
const head = `[${KIND[details.kind]} · ${details.botName}${details.group ? " · group" : ""}] ${who}:`;
|
|
@@ -451,9 +241,7 @@ function inboundText(details) {
|
|
|
451
241
|
`);
|
|
452
242
|
}
|
|
453
243
|
function botNote(details) {
|
|
454
|
-
return `
|
|
455
|
-
|
|
456
|
-
This message came from ${KIND[details.kind]} through the bot "${details.botName}" of Ta. The person reads your final answer there, as ${details.kind === "weixin" ? "plain text without Markdown" : "Markdown"}, on a phone: answer in a few short paragraphs, and say what you did rather than showing long output. Files they sent are saved under ${INBOX}/. To send them a file, a picture or a video, call ${TOOL} with its path.`;
|
|
244
|
+
return `This message came from ${KIND[details.kind]} through the bot "${details.botName}" of Ta. The person reads your final answer there, as ${details.kind === "weixin" ? "plain text without Markdown" : "Markdown"}, on a phone: answer in a few short paragraphs, and say what you did rather than showing long output; write no fenced block of a ta- language (a card of Ta's page, such as ta-glance), which the chat cannot draw. Files they sent are saved under ${INBOX}/. To send them a file, a picture or a video, call ${TOOL} with its path.`;
|
|
457
245
|
}
|
|
458
246
|
function activate(pi) {
|
|
459
247
|
let reached;
|
|
@@ -465,16 +253,7 @@ function activate(pi) {
|
|
|
465
253
|
let sessionFile = () => {
|
|
466
254
|
return;
|
|
467
255
|
};
|
|
468
|
-
const reach = () => reached ??=
|
|
469
|
-
const timer = setTimeout(() => resolve(undefined), HOST_WAIT_MS);
|
|
470
|
-
pi.events.emit(TA_HOST_EVENT, {
|
|
471
|
-
name: NAME,
|
|
472
|
-
resolve: (found) => {
|
|
473
|
-
clearTimeout(timer);
|
|
474
|
-
resolve(found.service && found.files ? { service: found.service, files: found.files } : undefined);
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
});
|
|
256
|
+
const reach = () => reached ??= TaHostUtil.reach(pi.events, NAME).then((found) => found?.service ? { service: found.service, files: found.files } : undefined);
|
|
478
257
|
pi.on("session_start", async (_event, ctx) => {
|
|
479
258
|
const found = await reach();
|
|
480
259
|
if (!found) {
|
|
@@ -498,9 +277,8 @@ function activate(pi) {
|
|
|
498
277
|
}
|
|
499
278
|
}
|
|
500
279
|
if (event.messageType === "custom" && event.message?.customType === INBOUND_TYPE) {
|
|
501
|
-
|
|
280
|
+
event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [SECTION]: botNote(event.message.details) };
|
|
502
281
|
}
|
|
503
|
-
return;
|
|
504
282
|
});
|
|
505
283
|
pi.on("message_end", (event) => {
|
|
506
284
|
const message = event.message;
|
package/host/index.mjs
CHANGED
|
@@ -335,6 +335,21 @@ var TaLocation;
|
|
|
335
335
|
return name || (remote === null || remote === undefined ? undefined : remote.host) || location;
|
|
336
336
|
}
|
|
337
337
|
TaLocation2.basename = basename;
|
|
338
|
+
function homeRelative(location) {
|
|
339
|
+
var _a;
|
|
340
|
+
const remote = parse(location);
|
|
341
|
+
const path2 = remote ? remote.path ? remote.path.slice(1) : "~" : location;
|
|
342
|
+
const match = /^~(?:[\\/]+(.*))?$/.exec(path2);
|
|
343
|
+
return match ? ((_a = match[1]) !== null && _a !== undefined ? _a : "").replace(/[\\/]+$/, "") : undefined;
|
|
344
|
+
}
|
|
345
|
+
TaLocation2.homeRelative = homeRelative;
|
|
346
|
+
function isAbsolute(location) {
|
|
347
|
+
if (homeRelative(location) !== undefined) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
return isRemote(location) || /^([\\/]|[A-Za-z]:)/.test(location);
|
|
351
|
+
}
|
|
352
|
+
TaLocation2.isAbsolute = isAbsolute;
|
|
338
353
|
function parentPath(path2) {
|
|
339
354
|
const trimmed = path2.replace(/[\\/]+$/, "");
|
|
340
355
|
const at = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
@@ -370,9 +385,64 @@ var TaPackageTextUtil;
|
|
|
370
385
|
var TaRelayServer = Symbol("TaRelayServer");
|
|
371
386
|
// ../ta-protocol/esm/common/remote-protocol.js
|
|
372
387
|
var TaRemoteServer = Symbol("TaRemoteServer");
|
|
388
|
+
// ../ta-protocol/esm/common/room-protocol.js
|
|
389
|
+
var TaRoomServer = Symbol("TaRoomServer");
|
|
390
|
+
var TaRoomWatchUtil;
|
|
391
|
+
(function(TaRoomWatchUtil2) {
|
|
392
|
+
function of(messages, state) {
|
|
393
|
+
const prefixes = Array.isArray(state) ? state.filter((prefix) => typeof prefix === "string" && prefix.length > 0) : [];
|
|
394
|
+
return { messages: messages !== false, state: [...new Set(prefixes)].sort() };
|
|
395
|
+
}
|
|
396
|
+
TaRoomWatchUtil2.of = of;
|
|
397
|
+
function union(watches) {
|
|
398
|
+
let messages = false;
|
|
399
|
+
const state = [];
|
|
400
|
+
for (const watch of watches) {
|
|
401
|
+
messages || (messages = watch.messages);
|
|
402
|
+
state.push(...watch.state);
|
|
403
|
+
}
|
|
404
|
+
return of(messages, messages ? [] : state);
|
|
405
|
+
}
|
|
406
|
+
TaRoomWatchUtil2.union = union;
|
|
407
|
+
function same(a, b) {
|
|
408
|
+
return a === b || !!a && !!b && a.messages === b.messages && a.state.join(`
|
|
409
|
+
`) === b.state.join(`
|
|
410
|
+
`);
|
|
411
|
+
}
|
|
412
|
+
TaRoomWatchUtil2.same = same;
|
|
413
|
+
function hears(watch, event) {
|
|
414
|
+
if (event.type === "message") {
|
|
415
|
+
return watch.messages;
|
|
416
|
+
}
|
|
417
|
+
if (event.type === "state") {
|
|
418
|
+
return watch.messages || watch.state.some((prefix) => event.key.startsWith(prefix));
|
|
419
|
+
}
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
TaRoomWatchUtil2.hears = hears;
|
|
423
|
+
})(TaRoomWatchUtil || (TaRoomWatchUtil = {}));
|
|
373
424
|
// ../ta-protocol/esm/common/settings-protocol.js
|
|
374
425
|
var TaSettingsServer = Symbol("TaSettingsServer");
|
|
375
426
|
// ../ta-protocol/esm/common/ta-extension-host.js
|
|
427
|
+
var TA_HOST_EVENT = "ta:host";
|
|
428
|
+
var TaHostUtil;
|
|
429
|
+
(function(TaHostUtil2) {
|
|
430
|
+
TaHostUtil2.WAIT_MS = 1000;
|
|
431
|
+
function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
|
|
432
|
+
return new Promise((resolve) => {
|
|
433
|
+
const timer = setTimeout(() => resolve(undefined), waitMs);
|
|
434
|
+
const request = {
|
|
435
|
+
name,
|
|
436
|
+
resolve: (answer) => {
|
|
437
|
+
clearTimeout(timer);
|
|
438
|
+
resolve(answer);
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
events.emit(TA_HOST_EVENT, request);
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
TaHostUtil2.reach = reach;
|
|
445
|
+
})(TaHostUtil || (TaHostUtil = {}));
|
|
376
446
|
var TA_DOUBLE_FILE = { name: "@celljs/ta-web", key: "assistant.file" };
|
|
377
447
|
// ../ta-protocol/esm/common/ta-protocol.js
|
|
378
448
|
var TaServer = Symbol("TaServer");
|
|
@@ -388,6 +458,15 @@ var TaErrorUtil;
|
|
|
388
458
|
}
|
|
389
459
|
TaErrorUtil2.code = code;
|
|
390
460
|
})(TaErrorUtil || (TaErrorUtil = {}));
|
|
461
|
+
var TaSlashCommandUtil;
|
|
462
|
+
(function(TaSlashCommandUtil2) {
|
|
463
|
+
function description(command, language) {
|
|
464
|
+
var _a, _b;
|
|
465
|
+
const { descriptions } = command;
|
|
466
|
+
return (_b = (_a = descriptions === null || descriptions === undefined ? undefined : descriptions[language]) !== null && _a !== undefined ? _a : descriptions === null || descriptions === undefined ? undefined : descriptions[language.split("-")[0]]) !== null && _b !== undefined ? _b : command.description;
|
|
467
|
+
}
|
|
468
|
+
TaSlashCommandUtil2.description = description;
|
|
469
|
+
})(TaSlashCommandUtil || (TaSlashCommandUtil = {}));
|
|
391
470
|
var TaMessageContext;
|
|
392
471
|
(function(TaMessageContext2) {
|
|
393
472
|
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
@@ -403,6 +482,109 @@ ${message}`;
|
|
|
403
482
|
}
|
|
404
483
|
TaMessageContext2.strip = strip;
|
|
405
484
|
})(TaMessageContext || (TaMessageContext = {}));
|
|
485
|
+
var TaImageNote;
|
|
486
|
+
(function(TaImageNote2) {
|
|
487
|
+
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 [^\]]+\.\]$/;
|
|
488
|
+
function strip(text) {
|
|
489
|
+
const lines = text.split(`
|
|
490
|
+
`);
|
|
491
|
+
const kept = lines.filter((line) => !NOTE.test(line.trim()));
|
|
492
|
+
if (kept.length === lines.length) {
|
|
493
|
+
return text;
|
|
494
|
+
}
|
|
495
|
+
return kept.join(`
|
|
496
|
+
`).replace(/\n+$/, "").replace(/^\n+/, "");
|
|
497
|
+
}
|
|
498
|
+
TaImageNote2.strip = strip;
|
|
499
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
500
|
+
var TaImageSize;
|
|
501
|
+
(function(TaImageSize2) {
|
|
502
|
+
const JPEG_BYTES = 256 * 1024;
|
|
503
|
+
function of(base64) {
|
|
504
|
+
var _a, _b, _c;
|
|
505
|
+
let bytes;
|
|
506
|
+
try {
|
|
507
|
+
const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
|
|
508
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
509
|
+
} catch (_d) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
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);
|
|
513
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
514
|
+
}
|
|
515
|
+
TaImageSize2.of = of;
|
|
516
|
+
function u16be(bytes, at) {
|
|
517
|
+
return bytes[at] << 8 | bytes[at + 1];
|
|
518
|
+
}
|
|
519
|
+
function u16le(bytes, at) {
|
|
520
|
+
return bytes[at] | bytes[at + 1] << 8;
|
|
521
|
+
}
|
|
522
|
+
function u24le(bytes, at) {
|
|
523
|
+
return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
|
|
524
|
+
}
|
|
525
|
+
function u32be(bytes, at) {
|
|
526
|
+
return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
527
|
+
}
|
|
528
|
+
function text(bytes, at, length) {
|
|
529
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
530
|
+
}
|
|
531
|
+
function png(bytes) {
|
|
532
|
+
return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
533
|
+
}
|
|
534
|
+
function gif(bytes) {
|
|
535
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
536
|
+
}
|
|
537
|
+
function webp(bytes) {
|
|
538
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
switch (text(bytes, 12, 4)) {
|
|
542
|
+
case "VP8 ":
|
|
543
|
+
return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
|
|
544
|
+
case "VP8L": {
|
|
545
|
+
const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
|
|
546
|
+
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
|
|
547
|
+
}
|
|
548
|
+
case "VP8X":
|
|
549
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
550
|
+
default:
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function jpeg(bytes) {
|
|
555
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
let at = 2;
|
|
559
|
+
while (at + 9 < bytes.length) {
|
|
560
|
+
if (bytes[at] !== 255) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const marker = bytes[at + 1];
|
|
564
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
565
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
566
|
+
}
|
|
567
|
+
at += 2 + u16be(bytes, at + 2);
|
|
568
|
+
}
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
572
|
+
var TaAgentSummary;
|
|
573
|
+
(function(TaAgentSummary2) {
|
|
574
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
575
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
576
|
+
function read(text) {
|
|
577
|
+
if (!START.test(text)) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
|
|
581
|
+
}
|
|
582
|
+
TaAgentSummary2.read = read;
|
|
583
|
+
function strip(text) {
|
|
584
|
+
return text.replace(BLOCK, "");
|
|
585
|
+
}
|
|
586
|
+
TaAgentSummary2.strip = strip;
|
|
587
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
406
588
|
var TaSkillUse;
|
|
407
589
|
(function(TaSkillUse2) {
|
|
408
590
|
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
@@ -665,13 +847,19 @@ var BotText;
|
|
|
665
847
|
function plain(markdown) {
|
|
666
848
|
const lines = [];
|
|
667
849
|
let fenced = false;
|
|
850
|
+
let card = false;
|
|
668
851
|
for (const line of markdown.replace(/\r\n/g, `
|
|
669
852
|
`).split(`
|
|
670
853
|
`)) {
|
|
671
|
-
|
|
854
|
+
const fence = /^\s*(?:```|~~~)\s*([\w-]*)/.exec(line);
|
|
855
|
+
if (fence) {
|
|
856
|
+
card = !fenced && fence[1].toLowerCase().startsWith("ta-");
|
|
672
857
|
fenced = !fenced;
|
|
673
858
|
continue;
|
|
674
859
|
}
|
|
860
|
+
if (card) {
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
675
863
|
if (fenced) {
|
|
676
864
|
lines.push(line);
|
|
677
865
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-bots",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"description": "A pi package for Ta: bots of WeChat (ClawBot) and WeCom connected to the double, an agent or a conversation, messages and files both ways",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@celljs/ta-protocol": "4.
|
|
31
|
-
"@celljs/ta-web": "4.
|
|
30
|
+
"@celljs/ta-protocol": "4.11.0",
|
|
31
|
+
"@celljs/ta-web": "4.11.0",
|
|
32
32
|
"@types/react": "^19.3.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
package/web/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var Keys;
|
|
|
6
6
|
})(Keys ||= {});
|
|
7
7
|
var INBOUND_TYPE = "ta-bots";
|
|
8
8
|
var SENT_TYPE = "ta-bots-sent";
|
|
9
|
+
var SEND_FILE_TOOL = "bot_send_file";
|
|
9
10
|
var BotTargetUtil;
|
|
10
11
|
((BotTargetUtil) => {
|
|
11
12
|
function same(a, b) {
|
|
@@ -111,7 +112,8 @@ var EN = {
|
|
|
111
112
|
file: "File",
|
|
112
113
|
video: "Video",
|
|
113
114
|
group: "group",
|
|
114
|
-
failedAction: "Failed: {message}"
|
|
115
|
+
failedAction: "Failed: {message}",
|
|
116
|
+
toolSendFile: "Send to the chat"
|
|
115
117
|
};
|
|
116
118
|
var ZH = {
|
|
117
119
|
title: "机器人",
|
|
@@ -191,7 +193,8 @@ var ZH = {
|
|
|
191
193
|
file: "文件",
|
|
192
194
|
video: "视频",
|
|
193
195
|
group: "群聊",
|
|
194
|
-
failedAction: "操作失败:{message}"
|
|
196
|
+
failedAction: "操作失败:{message}",
|
|
197
|
+
toolSendFile: "发到聊天"
|
|
195
198
|
};
|
|
196
199
|
var BotWords;
|
|
197
200
|
((BotWords) => {
|
|
@@ -688,6 +691,7 @@ function composerAddon(client, dialogs) {
|
|
|
688
691
|
icon: /* @__PURE__ */ React.createElement(Bot, {
|
|
689
692
|
size: 16
|
|
690
693
|
}),
|
|
694
|
+
setting: true,
|
|
691
695
|
detail: here.length > 0 ? t("menuHere", { count: here.length }) : undefined,
|
|
692
696
|
items: [
|
|
693
697
|
...bots.map((bot) => {
|
|
@@ -862,7 +866,9 @@ function BotsPicture() {
|
|
|
862
866
|
// web-src/bots-view.tsx
|
|
863
867
|
var PAGE = "page";
|
|
864
868
|
function run2(action) {
|
|
865
|
-
action.
|
|
869
|
+
return action.then(() => {
|
|
870
|
+
return;
|
|
871
|
+
}, (error) => pi.ui.notify(t("failedAction", { message: message(error) }), "error"));
|
|
866
872
|
}
|
|
867
873
|
function when(time) {
|
|
868
874
|
return new Date(time).toLocaleString(pi.ui.language, { month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit" });
|
|
@@ -896,19 +902,29 @@ function BotRow({ bot, client, dialogs }) {
|
|
|
896
902
|
const Trash = icon("Trash2");
|
|
897
903
|
const Unplug = icon("Unplug");
|
|
898
904
|
const Refresh = icon("RefreshCw");
|
|
905
|
+
const [doing, setDoing] = React.useState();
|
|
906
|
+
const act = (key, action) => {
|
|
907
|
+
setDoing(key);
|
|
908
|
+
run2(action).finally(() => setDoing(undefined));
|
|
909
|
+
};
|
|
910
|
+
const busy = (key, base) => doing === key ? `${base} ta-busy` : base;
|
|
911
|
+
const mark = (key) => doing === key && /* @__PURE__ */ React.createElement("span", {
|
|
912
|
+
className: "ta-spinner ta-busy-mark"
|
|
913
|
+
});
|
|
899
914
|
const rename = async () => {
|
|
900
915
|
const name = await pi.ui.input(t("rename"), bot.name, { value: bot.name });
|
|
901
916
|
if (name?.trim()) {
|
|
902
|
-
|
|
917
|
+
act("rename", client.call("rename", bot.id, name.trim()).then(() => client.load()));
|
|
903
918
|
}
|
|
904
919
|
};
|
|
905
920
|
const remove = async () => {
|
|
906
921
|
if (await pi.ui.confirm(t("removeConfirm", { name: bot.name }), t("removeMessage"), { confirmLabel: t("remove"), danger: true })) {
|
|
907
|
-
|
|
922
|
+
act("remove", client.call("remove", bot.id).then(() => client.load()));
|
|
908
923
|
}
|
|
909
924
|
};
|
|
910
925
|
return /* @__PURE__ */ React.createElement("div", {
|
|
911
|
-
className: "tbo-row"
|
|
926
|
+
className: doing === "remove" ? "tbo-row ta-pending" : "tbo-row",
|
|
927
|
+
"aria-busy": doing !== undefined || undefined
|
|
912
928
|
}, /* @__PURE__ */ React.createElement(KindMark, {
|
|
913
929
|
kind: bot.kind,
|
|
914
930
|
size: 32
|
|
@@ -944,33 +960,33 @@ function BotRow({ bot, client, dialogs }) {
|
|
|
944
960
|
size: 15
|
|
945
961
|
})), !BotTargetUtil.same(bot.target, { kind: "double" }) && /* @__PURE__ */ React.createElement("button", {
|
|
946
962
|
type: "button",
|
|
947
|
-
className: "tbo-button tbo-small",
|
|
948
|
-
onClick: () =>
|
|
949
|
-
}, t("connectTo")), bot.target && /* @__PURE__ */ React.createElement("button", {
|
|
963
|
+
className: busy("bind", "tbo-button tbo-small"),
|
|
964
|
+
onClick: () => act("bind", client.bindHere(bot, { kind: "double" }))
|
|
965
|
+
}, t("connectTo"), mark("bind")), bot.target && /* @__PURE__ */ React.createElement("button", {
|
|
950
966
|
type: "button",
|
|
951
|
-
className: "tbo-icon",
|
|
967
|
+
className: busy("unbind", "tbo-icon"),
|
|
952
968
|
title: t("disconnect"),
|
|
953
969
|
"aria-label": t("disconnect"),
|
|
954
|
-
onClick: () =>
|
|
970
|
+
onClick: () => act("unbind", client.unbind(bot))
|
|
955
971
|
}, /* @__PURE__ */ React.createElement(Unplug, {
|
|
956
972
|
size: 15
|
|
957
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
973
|
+
}), mark("unbind")), /* @__PURE__ */ React.createElement("button", {
|
|
958
974
|
type: "button",
|
|
959
|
-
className: "tbo-icon",
|
|
975
|
+
className: busy("rename", "tbo-icon"),
|
|
960
976
|
title: t("rename"),
|
|
961
977
|
"aria-label": t("rename"),
|
|
962
978
|
onClick: () => void rename()
|
|
963
979
|
}, /* @__PURE__ */ React.createElement(Pencil, {
|
|
964
980
|
size: 15
|
|
965
|
-
})), /* @__PURE__ */ React.createElement("button", {
|
|
981
|
+
}), mark("rename")), /* @__PURE__ */ React.createElement("button", {
|
|
966
982
|
type: "button",
|
|
967
|
-
className: "tbo-icon tbo-danger",
|
|
983
|
+
className: busy("remove", "tbo-icon tbo-danger"),
|
|
968
984
|
title: t("remove"),
|
|
969
985
|
"aria-label": t("remove"),
|
|
970
986
|
onClick: () => void remove()
|
|
971
987
|
}, /* @__PURE__ */ React.createElement(Trash, {
|
|
972
988
|
size: 15
|
|
973
|
-
}))));
|
|
989
|
+
}), mark("remove"))));
|
|
974
990
|
}
|
|
975
991
|
function BotsPage({ client, dialogs }) {
|
|
976
992
|
const { bots, loaded } = useBots(client);
|
|
@@ -1175,6 +1191,7 @@ var STYLE = `
|
|
|
1175
1191
|
.tbo-primary { background: var(--ta-brand); border-color: var(--ta-brand); color: var(--ta-brand-text); }
|
|
1176
1192
|
.tbo-primary:hover:not(:disabled) { background: var(--ta-brand); opacity: .88; }
|
|
1177
1193
|
.tbo-small { height: 28px; padding: 0 10px; font-size: calc(12.5px * var(--ta-font-scale)); }
|
|
1194
|
+
.tbo-icon.ta-busy, .tbo-button.ta-busy { position: relative; }
|
|
1178
1195
|
.tbo-icon { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border: 0; border-radius: 7px; background: none; color: var(--ta-muted); cursor: pointer; }
|
|
1179
1196
|
.tbo-icon:hover { background: var(--ta-hover); color: var(--ta-text); }
|
|
1180
1197
|
.tbo-danger:hover { color: var(--ta-red); }
|
|
@@ -1210,6 +1227,19 @@ function injectStyle() {
|
|
|
1210
1227
|
return () => element.remove();
|
|
1211
1228
|
}
|
|
1212
1229
|
|
|
1230
|
+
// web-src/tool-line.ts
|
|
1231
|
+
var BotToolLine;
|
|
1232
|
+
((BotToolLine) => {
|
|
1233
|
+
function renderCall(args, verb) {
|
|
1234
|
+
return { verb, target: typeof args.path === "string" ? args.path.trim() : "" };
|
|
1235
|
+
}
|
|
1236
|
+
BotToolLine.renderCall = renderCall;
|
|
1237
|
+
function register(pi2, verb) {
|
|
1238
|
+
pi2.registerToolRenderer?.((name, next) => name === SEND_FILE_TOOL ? { renderCall: (args) => renderCall(args, verb()) } : next());
|
|
1239
|
+
}
|
|
1240
|
+
BotToolLine.register = register;
|
|
1241
|
+
})(BotToolLine ||= {});
|
|
1242
|
+
|
|
1213
1243
|
// web-src/index.tsx
|
|
1214
1244
|
function activate(pi2) {
|
|
1215
1245
|
bind(pi2.React);
|
|
@@ -1221,6 +1251,7 @@ function activate(pi2) {
|
|
|
1221
1251
|
pi2.registerComposerAddon(composerAddon(client, dialogs));
|
|
1222
1252
|
pi2.registerMessageRenderer(INBOUND_TYPE, InboundMessage);
|
|
1223
1253
|
pi2.registerMessageRenderer(SENT_TYPE, SentMessageView);
|
|
1254
|
+
BotToolLine.register(pi2, () => t("toolSendFile"));
|
|
1224
1255
|
pi2.registerView("bots", {
|
|
1225
1256
|
title: () => t("title"),
|
|
1226
1257
|
icon: icon("Bot"),
|