@celljs/ta-rooms 4.22.0 → 4.23.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 +201 -2
- package/host/index.mjs +2542 -1296
- package/package.json +4 -4
- package/web/index.js +1015 -71
package/extension/index.mjs
CHANGED
|
@@ -264,6 +264,8 @@ var TASK_MESSAGE_TYPE = "ta-rooms:task";
|
|
|
264
264
|
var ROOM_CAPABILITIES = ["files", "commands"];
|
|
265
265
|
var DoubleKeys;
|
|
266
266
|
((DoubleKeys) => {
|
|
267
|
+
DoubleKeys.PICTURES = "pictures.came";
|
|
268
|
+
DoubleKeys.FILES = "files.came";
|
|
267
269
|
DoubleKeys.QUIET = "doubles.quiet";
|
|
268
270
|
DoubleKeys.REPLY = "doubles.reply";
|
|
269
271
|
DoubleKeys.DRAFTS = "doubles.drafts";
|
|
@@ -281,6 +283,54 @@ var DRAFTS_MAX = 50;
|
|
|
281
283
|
var DRAFT_MS = 24 * 60 * 60 * 1000;
|
|
282
284
|
var GRANT_HOURS = [1, 24, 24 * 7];
|
|
283
285
|
|
|
286
|
+
// ../ta-protocol/esm/common/confine-protocol.js
|
|
287
|
+
var TA_CONFINED_MARK = "[ta:confined]";
|
|
288
|
+
var AT = String.raw`(?:^|[;&|(\`]|\$\()\s*(?:sudo\s+|env\s+(?:\S+=\S*\s+)*|npx\s+|bunx\s+|pnpm\s+(?:exec|dlx)\s+|yarn\s+dlx\s+|exec\s+|xargs\s+(?:-\S+\s+)*)*`;
|
|
289
|
+
var command = (names) => new RegExp(`${AT}(?:${names})(?=\\s|$|[;&|)])`, "m");
|
|
290
|
+
var BLOCKED = [
|
|
291
|
+
[/\bgit\b[^\n;&|]*\s(?:push|send-email|request-pull)\b/, "pushing: the user puts the work out once they looked at it"],
|
|
292
|
+
[/\bgit\b[^\n;&|]*\sremote\s+(?:add|set-url|rename|remove|rm)\b/, "changing the remotes"],
|
|
293
|
+
[/\bgit\b[^\n;&|]*\sconfig\b[^\n;&|]*(?:credential|url\.|core\.sshcommand|core\.hookspath)/i, "changing how git reaches others"],
|
|
294
|
+
[/\b(?:publish|unpublish|deprecate)\b/, "publishing"],
|
|
295
|
+
[
|
|
296
|
+
command("wrangler|vercel|netlify|flyctl|fly|firebase|heroku|gh|aws|gcloud|az|kubectl|helm|terraform|pulumi|docker|podman|eas|fastlane|xcrun\\s+altool|twine"),
|
|
297
|
+
"deploying, or the tools of a cloud"
|
|
298
|
+
],
|
|
299
|
+
[command("ssh|scp|sftp|rsync|nc|ncat|netcat|telnet|ftp|socat"), "reaching other machines"],
|
|
300
|
+
[
|
|
301
|
+
/\b(?:curl|wget|http|https|Invoke-WebRequest|Invoke-RestMethod|iwr|irm)\b[^\n;&|]*(?:\s-[a-zA-Z]*[dFT]\b|\s--(?:data|upload|form|post|put|json)|\s-X\s*(?:POST|PUT|PATCH|DELETE)|\s-Method\s+(?:Post|Put|Patch|Delete)|\s-Body\b|\s-InFile\b)/i,
|
|
302
|
+
"sending data out"
|
|
303
|
+
],
|
|
304
|
+
[
|
|
305
|
+
/(?:~|\$HOME|\$\{HOME\}|\$env:USERPROFILE|\/Users\/[^/\s]+|\/home\/[^/\s]+|\/root)[\\/]\.(?:ssh|aws|gnupg|netrc|npmrc|yarnrc|pypirc|zshenv|zshrc|zprofile|bashrc|bash_profile|profile|docker|kube|ta|codebuddy|claude|cursor|config[\\/](?:gh|gcloud|hub))\b/i,
|
|
306
|
+
"the user's secrets and settings"
|
|
307
|
+
],
|
|
308
|
+
[/\bsecurity\s+(?:find|dump|export)-/, "the keychain"],
|
|
309
|
+
[command("printenv|env|set|export\\s+-p|declare\\s+-x|Get-ChildItem\\s+env:|gci\\s+env:|dir\\s+env:"), "printing the environment (it holds tokens)"],
|
|
310
|
+
[command("sudo|su|doas|osascript|launchctl|crontab|defaults\\s+write|schtasks|reg"), "acting as the system"],
|
|
311
|
+
[/\brm\s+-[a-zA-Z]*[rR][a-zA-Z]*\s+(?:-[a-zA-Z]+\s+)*(?:\/|~|\$HOME|\$\{HOME\})(?:\s|$|\/\s|\/\*)/, "deleting outside its directory"]
|
|
312
|
+
];
|
|
313
|
+
var TaConfineUtil;
|
|
314
|
+
(function(TaConfineUtil2) {
|
|
315
|
+
TaConfineUtil2.FILE_TOOLS = ["read", "edit", "write", "grep", "find", "ls"];
|
|
316
|
+
TaConfineUtil2.COMMAND_TOOLS = ["bash", "powershell"];
|
|
317
|
+
function confine(role) {
|
|
318
|
+
return role.includes(TA_CONFINED_MARK) ? role : `${TA_CONFINED_MARK}
|
|
319
|
+
${role}`;
|
|
320
|
+
}
|
|
321
|
+
TaConfineUtil2.confine = confine;
|
|
322
|
+
function confined(systemPrompt) {
|
|
323
|
+
return TaHostUtil.marked(systemPrompt, TA_CONFINED_MARK);
|
|
324
|
+
}
|
|
325
|
+
TaConfineUtil2.confined = confined;
|
|
326
|
+
function blocked(commandText) {
|
|
327
|
+
var _a;
|
|
328
|
+
const text = String(commandText !== null && commandText !== undefined ? commandText : "");
|
|
329
|
+
return (_a = BLOCKED.find(([pattern]) => pattern.test(text))) === null || _a === undefined ? undefined : _a[1];
|
|
330
|
+
}
|
|
331
|
+
TaConfineUtil2.blocked = blocked;
|
|
332
|
+
})(TaConfineUtil || (TaConfineUtil = {}));
|
|
333
|
+
|
|
284
334
|
// ../ta-protocol/esm/common/language.js
|
|
285
335
|
var TaLanguageUtil;
|
|
286
336
|
(function(TaLanguageUtil2) {
|
|
@@ -320,6 +370,150 @@ var TaLanguageUtil;
|
|
|
320
370
|
TaLanguageUtil2.list = list;
|
|
321
371
|
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
322
372
|
|
|
373
|
+
// ../ta-relay/esm/common/relay-room-chat.js
|
|
374
|
+
var RELAY_CHAT_FILE_BYTES = { file: 50 * 1024 * 1024, video: 30 * 1024 * 1024, voice: 2 * 1024 * 1024 };
|
|
375
|
+
var RELAY_CHAT_VOICE_MS = 60000;
|
|
376
|
+
var RELAY_CHAT_VIDEO_MS = 3 * 60000;
|
|
377
|
+
var RELAY_CHAT_FILES = 9;
|
|
378
|
+
var RELAY_CHAT_KEY = "chat:";
|
|
379
|
+
var RELAY_CHAT_PART_BYTES = 8 * 1024;
|
|
380
|
+
var RELAY_CHAT_TEXT_MAX = 2000;
|
|
381
|
+
var RELAY_CHAT_IMAGES = 9;
|
|
382
|
+
var RELAY_CHAT_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
383
|
+
var RELAY_CHAT_THUMB_CHARS = 900;
|
|
384
|
+
var IMAGE_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp"];
|
|
385
|
+
var RelayRoomChatUtil;
|
|
386
|
+
(function(RelayRoomChatUtil2) {
|
|
387
|
+
function key(member, part) {
|
|
388
|
+
return `${RELAY_CHAT_KEY}${member}:${part}`;
|
|
389
|
+
}
|
|
390
|
+
RelayRoomChatUtil2.key = key;
|
|
391
|
+
function parse(key2) {
|
|
392
|
+
const match = /^chat:([^:]+):(\d+)$/.exec(key2);
|
|
393
|
+
return match ? { member: match[1], part: Number(match[2]) } : undefined;
|
|
394
|
+
}
|
|
395
|
+
RelayRoomChatUtil2.parse = parse;
|
|
396
|
+
function lines(member, value, by) {
|
|
397
|
+
if (by !== member || !Array.isArray(value)) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const lines2 = [];
|
|
401
|
+
for (const line of value) {
|
|
402
|
+
if (line && typeof line.id === "string" && typeof line.text === "string" && typeof line.at === "number") {
|
|
403
|
+
lines2.push({ id: line.id, from: member, name: typeof line.name === "string" ? line.name : "", text: line.text, at: line.at, ...extra(line) });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return lines2;
|
|
407
|
+
}
|
|
408
|
+
RelayRoomChatUtil2.lines = lines;
|
|
409
|
+
function extra(line) {
|
|
410
|
+
const to = Array.isArray(line.to) ? line.to.filter((each) => typeof each === "string").slice(0, 16) : [];
|
|
411
|
+
const agent = line.agent;
|
|
412
|
+
return {
|
|
413
|
+
...line.double === true ? { double: true } : {},
|
|
414
|
+
...agent && typeof agent.id === "string" && agent.id && typeof agent.name === "string" && line.double !== true ? { agent: { id: agent.id.slice(0, 64), name: agent.name.slice(0, 64) } } : {},
|
|
415
|
+
...to.length ? { to } : {},
|
|
416
|
+
...line.person === true && to.length && line.double !== true && !line.agent ? { person: true } : {},
|
|
417
|
+
...typeof line.re === "string" ? { re: line.re } : {},
|
|
418
|
+
...line.task === true && to.length ? { task: true } : {},
|
|
419
|
+
...images(line.images),
|
|
420
|
+
...files(line.files)
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
RelayRoomChatUtil2.extra = extra;
|
|
424
|
+
function files(value) {
|
|
425
|
+
if (!Array.isArray(value)) {
|
|
426
|
+
return {};
|
|
427
|
+
}
|
|
428
|
+
const files2 = [];
|
|
429
|
+
for (const file of value.slice(0, RELAY_CHAT_FILES)) {
|
|
430
|
+
const kind = file === null || file === undefined ? undefined : file.kind;
|
|
431
|
+
if (!file || kind !== "file" && kind !== "voice" && kind !== "video" || typeof file.id !== "string" || !/^[a-f0-9]{24}$/.test(file.id) || typeof file.sha !== "string" || !/^[0-9a-f]{64}$/.test(file.sha) || !Number.isInteger(file.bytes) || file.bytes <= 0 || file.bytes > RELAY_CHAT_FILE_BYTES[kind]) {
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
const name = [...typeof file.name === "string" ? file.name : ""].filter((char) => char.charCodeAt(0) >= 32 && char !== "/" && char !== "\\").join("").slice(0, 120) || kind;
|
|
435
|
+
const type = typeof file.type === "string" && /^[\w.+-]+\/[\w.+-]+$/.test(file.type) ? file.type.slice(0, 100) : "application/octet-stream";
|
|
436
|
+
const most = kind === "voice" ? RELAY_CHAT_VOICE_MS : RELAY_CHAT_VIDEO_MS;
|
|
437
|
+
const ms = kind !== "file" && Number.isFinite(file.ms) ? Math.min(Math.max(Math.round(file.ms), 0), most) : undefined;
|
|
438
|
+
const size = kind === "video" && Number.isInteger(file.w) && Number.isInteger(file.h) && file.w > 0 && file.h > 0;
|
|
439
|
+
const thumb = kind === "video" && typeof file.thumb === "string" && file.thumb.length <= RELAY_CHAT_THUMB_CHARS && /^data:image\/(jpeg|png|webp);base64,/.test(file.thumb) ? file.thumb : undefined;
|
|
440
|
+
files2.push({
|
|
441
|
+
id: file.id,
|
|
442
|
+
kind,
|
|
443
|
+
name,
|
|
444
|
+
type,
|
|
445
|
+
bytes: file.bytes,
|
|
446
|
+
sha: file.sha,
|
|
447
|
+
...ms !== undefined ? { ms } : {},
|
|
448
|
+
...size ? { w: file.w, h: file.h } : {},
|
|
449
|
+
...thumb ? { thumb } : {}
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return files2.length ? { files: files2 } : {};
|
|
453
|
+
}
|
|
454
|
+
RelayRoomChatUtil2.files = files;
|
|
455
|
+
function images(value) {
|
|
456
|
+
if (!Array.isArray(value)) {
|
|
457
|
+
return {};
|
|
458
|
+
}
|
|
459
|
+
const images2 = [];
|
|
460
|
+
for (const image of value.slice(0, RELAY_CHAT_IMAGES)) {
|
|
461
|
+
if (image && typeof image.id === "string" && /^[A-Za-z0-9-]{8,64}$/.test(image.id) && typeof image.type === "string" && IMAGE_TYPES.includes(image.type) && typeof image.sha === "string" && /^[0-9a-f]{64}$/.test(image.sha) && Number.isInteger(image.w) && Number.isInteger(image.h) && Number.isInteger(image.bytes) && image.w > 0 && image.h > 0 && image.bytes > 0 && image.bytes <= RELAY_CHAT_IMAGE_BYTES) {
|
|
462
|
+
const thumb = typeof image.thumb === "string" && image.thumb.length <= RELAY_CHAT_THUMB_CHARS && /^data:image\/(jpeg|png|webp);base64,/.test(image.thumb) ? image.thumb : undefined;
|
|
463
|
+
const blob = image.blob;
|
|
464
|
+
const ok = !!blob && typeof blob.id === "string" && /^[A-Za-z0-9_-]{16,64}$/.test(blob.id) && typeof blob.read === "string" && /^[A-Za-z0-9_-]{43}$/.test(blob.read) && typeof blob.key === "string" && /^[A-Za-z0-9_-]{43}$/.test(blob.key) && Number.isFinite(blob.until);
|
|
465
|
+
images2.push({
|
|
466
|
+
id: image.id,
|
|
467
|
+
type: image.type,
|
|
468
|
+
w: image.w,
|
|
469
|
+
h: image.h,
|
|
470
|
+
bytes: image.bytes,
|
|
471
|
+
sha: image.sha,
|
|
472
|
+
...thumb ? { thumb } : {},
|
|
473
|
+
...ok && blob ? { blob: { id: blob.id, read: blob.read, key: blob.key, until: blob.until } } : {}
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return images2.length ? { images: images2 } : {};
|
|
478
|
+
}
|
|
479
|
+
function preview(line, picture, words = { file: "[file]", voice: "[voice]", video: "[video]" }) {
|
|
480
|
+
var _a;
|
|
481
|
+
var _b;
|
|
482
|
+
const pictures = ((_a = line.images) === null || _a === undefined ? undefined : _a.length) ? line.images.length > 1 ? `${picture}×${line.images.length}` : picture : "";
|
|
483
|
+
const files2 = ((_b = line.files) !== null && _b !== undefined ? _b : []).map((file) => file.kind === "file" ? `${words.file} ${file.name}` : words[file.kind]);
|
|
484
|
+
return [pictures, ...files2, line.text].filter(Boolean).join(" ");
|
|
485
|
+
}
|
|
486
|
+
RelayRoomChatUtil2.preview = preview;
|
|
487
|
+
function stored(lines2) {
|
|
488
|
+
return lines2.map(({ from: _from, seq: _seq, pending: _pending, failed: _failed, ...line }) => line);
|
|
489
|
+
}
|
|
490
|
+
RelayRoomChatUtil2.stored = stored;
|
|
491
|
+
function signed(member, value, seq) {
|
|
492
|
+
const line = value;
|
|
493
|
+
if (!line || typeof line.id !== "string" || typeof line.text !== "string" || typeof line.at !== "number") {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const name = typeof line.name === "string" ? line.name.slice(0, 64) : "";
|
|
497
|
+
const text = line.text.slice(0, RELAY_CHAT_TEXT_MAX);
|
|
498
|
+
return { id: line.id.slice(0, 40), from: member, name, text, at: line.at, ...extra(line), ...seq ? { seq } : {} };
|
|
499
|
+
}
|
|
500
|
+
RelayRoomChatUtil2.signed = signed;
|
|
501
|
+
function bytes(lines2) {
|
|
502
|
+
return new TextEncoder().encode(JSON.stringify(lines2)).length;
|
|
503
|
+
}
|
|
504
|
+
RelayRoomChatUtil2.bytes = bytes;
|
|
505
|
+
function unknownMethod(error) {
|
|
506
|
+
var _a;
|
|
507
|
+
const found = error;
|
|
508
|
+
return (found === null || found === undefined ? undefined : found.code) === -32601 || /method not found|not a function|unknown method|no such method/i.test(String((_a = found === null || found === undefined ? undefined : found.message) !== null && _a !== undefined ? _a : error));
|
|
509
|
+
}
|
|
510
|
+
RelayRoomChatUtil2.unknownMethod = unknownMethod;
|
|
511
|
+
function id() {
|
|
512
|
+
return `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
513
|
+
}
|
|
514
|
+
RelayRoomChatUtil2.id = id;
|
|
515
|
+
})(RelayRoomChatUtil || (RelayRoomChatUtil = {}));
|
|
516
|
+
|
|
323
517
|
// web-src/double-util.ts
|
|
324
518
|
var STALE_MS = 10 * 60 * 1000;
|
|
325
519
|
var HOURLY = 30;
|
|
@@ -452,6 +646,10 @@ var DoubleUtil;
|
|
|
452
646
|
`);
|
|
453
647
|
}
|
|
454
648
|
DoubleUtil.role = role;
|
|
649
|
+
function taskRole(me, title, approved) {
|
|
650
|
+
return approved ? role(me, title) : TaConfineUtil.confine(role(me, title));
|
|
651
|
+
}
|
|
652
|
+
DoubleUtil.taskRole = taskRole;
|
|
455
653
|
function agentRole(me, title, agent) {
|
|
456
654
|
const lines = [
|
|
457
655
|
`${ROOM_DOUBLE_MARK} ${TA_WITH_OTHERS_MARK}`,
|
|
@@ -482,13 +680,14 @@ var DoubleUtil;
|
|
|
482
680
|
function prompt(input) {
|
|
483
681
|
const index = input.lines.findIndex((line) => line.id === input.line.id);
|
|
484
682
|
const before = input.lines.slice(Math.max(0, index - CONTEXT_LINES), Math.max(0, index));
|
|
485
|
-
const said = (line) => `${DoubleUtil.quote(input.nameOf(line))}${line.double ? " (double)" : ""}: ${DoubleUtil.quote(line
|
|
683
|
+
const said = (line) => `${DoubleUtil.quote(input.nameOf(line))}${line.double ? " (double)" : ""}: ${DoubleUtil.quote(RelayRoomChatUtil.preview(line, "[picture]"))}`;
|
|
486
684
|
return [
|
|
487
685
|
input.permits,
|
|
488
686
|
`<room_request room="${DoubleUtil.quote(input.title)}" from="${DoubleUtil.quote(input.asker.name)}"${input.asker.guest ? ' guest="true"' : ""}>`,
|
|
489
687
|
...before.length ? ["The chat before it:", ...before.map(said), ""] : [],
|
|
490
688
|
`${DoubleUtil.quote(input.asker.name)} asks you:`,
|
|
491
|
-
DoubleUtil.quote(input.line
|
|
689
|
+
DoubleUtil.quote(RelayRoomChatUtil.preview(input.line, "[picture]")),
|
|
690
|
+
...input.line.images?.length ? ["(Its pictures are attached, as far as they came.)"] : [],
|
|
492
691
|
"</room_request>"
|
|
493
692
|
].join(`
|
|
494
693
|
`);
|