@celljs/ta-rooms 4.20.0 → 4.21.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 +64 -8
- package/host/index.mjs +537 -61
- package/package.json +4 -4
- package/web/index.js +2201 -463
package/extension/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// web-src/extension.ts
|
|
2
|
-
import {
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
3
6
|
|
|
4
7
|
// ../ta-protocol/esm/common/ta-extension-host.js
|
|
5
8
|
var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
|
|
@@ -194,6 +197,9 @@ var ROOM_CAPABILITIES = ["files", "commands"];
|
|
|
194
197
|
var DoubleKeys;
|
|
195
198
|
((DoubleKeys) => {
|
|
196
199
|
DoubleKeys.QUIET = "doubles.quiet";
|
|
200
|
+
DoubleKeys.REPLY = "doubles.reply";
|
|
201
|
+
DoubleKeys.DRAFTS = "doubles.drafts";
|
|
202
|
+
DoubleKeys.DONE = "doubles.done";
|
|
197
203
|
DoubleKeys.GRANTS = "doubles.grants";
|
|
198
204
|
DoubleKeys.ASKS = "doubles.asks";
|
|
199
205
|
DoubleKeys.LOG = "doubles.log";
|
|
@@ -203,6 +209,8 @@ var DoubleKeys;
|
|
|
203
209
|
DoubleKeys.HANDED = "doubles.handed";
|
|
204
210
|
DoubleKeys.DEVICE = "doubles.device";
|
|
205
211
|
})(DoubleKeys ||= {});
|
|
212
|
+
var DRAFTS_MAX = 50;
|
|
213
|
+
var DRAFT_MS = 24 * 60 * 60 * 1000;
|
|
206
214
|
var GRANT_HOURS = [1, 24, 24 * 7];
|
|
207
215
|
|
|
208
216
|
// ../ta-protocol/esm/common/language.js
|
|
@@ -270,8 +278,8 @@ var DoubleUtil;
|
|
|
270
278
|
return all.filter((name) => !off.has(name));
|
|
271
279
|
}
|
|
272
280
|
DoubleUtil.ownTools = ownTools;
|
|
273
|
-
function grantsOf(grants, friend, now) {
|
|
274
|
-
return grants.filter((grant) => grant.friend === friend && grant.expiresAt > now);
|
|
281
|
+
function grantsOf(grants, friend, now, room) {
|
|
282
|
+
return grants.filter((grant) => grant.friend === friend && grant.expiresAt > now && (grant.room === undefined || grant.room === room));
|
|
275
283
|
}
|
|
276
284
|
DoubleUtil.grantsOf = grantsOf;
|
|
277
285
|
function work(grants) {
|
|
@@ -293,9 +301,28 @@ var DoubleUtil;
|
|
|
293
301
|
}
|
|
294
302
|
DoubleUtil.tools = tools;
|
|
295
303
|
function asking(lines, self, since, now) {
|
|
296
|
-
return lines.filter((line) => line.from !== self && line.at > since && now - line.at < STALE_MS && !!line.to?.includes(self));
|
|
304
|
+
return lines.filter((line) => line.from !== self && line.at > since && now - line.at < STALE_MS && !line.person && !!line.to?.includes(self));
|
|
297
305
|
}
|
|
298
306
|
DoubleUtil.asking = asking;
|
|
307
|
+
function calling(lines, self, direct, since, now, awayMs) {
|
|
308
|
+
return lines.filter((line) => line.from !== self && !line.double && !line.agent && !line.task && line.at > since && now - line.at < awayMs + STALE_MS && (line.person ? !!line.to?.includes(self) : direct && !line.to));
|
|
309
|
+
}
|
|
310
|
+
DoubleUtil.calling = calling;
|
|
311
|
+
function answered(lines, self, at) {
|
|
312
|
+
return lines.some((line) => line.from === self && !line.double && !line.agent && line.at > at);
|
|
313
|
+
}
|
|
314
|
+
DoubleUtil.answered = answered;
|
|
315
|
+
function callNote(me, name, how, direct) {
|
|
316
|
+
const where = direct ? `wrote to ${me} in their chat of two` : `named ${me} with @`;
|
|
317
|
+
const why = how === "away" ? `${me} has not seen it for a while: answer for them.` : how === "draft" ? `Write the answer ${me} would send: ${me} reads it first, and sends it, changes it or drops it.` : `${me} lets you answer such lines for them at once.`;
|
|
318
|
+
return `[Ta] ${name} ${where}. ${why} You are ${me}'s double, not ${me}: decide nothing only ${me} can (promises, plans, money), say you will tell ${me}, and keep it short.`;
|
|
319
|
+
}
|
|
320
|
+
DoubleUtil.callNote = callNote;
|
|
321
|
+
function drafts(all, draft, now) {
|
|
322
|
+
const kept = all.filter((each) => now - each.at < DRAFT_MS && !(draft && each.room === draft.room && each.re === draft.re));
|
|
323
|
+
return [...kept, ...draft ? [draft] : []].slice(-DRAFTS_MAX);
|
|
324
|
+
}
|
|
325
|
+
DoubleUtil.drafts = drafts;
|
|
299
326
|
function askingAgents(lines, self, agents, since, now) {
|
|
300
327
|
return lines.flatMap((line) => line.at > since && now - line.at < STALE_MS ? agents.filter((agent) => line.to?.includes(RoomAgentsUtil.address(self, agent)) && !(line.from === self && line.agent?.id === agent)).map((agent) => ({ line, agent })) : []);
|
|
301
328
|
}
|
|
@@ -516,10 +543,39 @@ var USER_ROOM_TOOLS = [
|
|
|
516
543
|
run: (doubles, params, file) => doubles.user.handTask(file, params.room, params.to, params.task)
|
|
517
544
|
}
|
|
518
545
|
];
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
const rest =
|
|
522
|
-
|
|
546
|
+
var UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
|
|
547
|
+
function real(path) {
|
|
548
|
+
const rest = [];
|
|
549
|
+
for (let head = path;; ) {
|
|
550
|
+
try {
|
|
551
|
+
return join(realpathSync(head), ...rest);
|
|
552
|
+
} catch {
|
|
553
|
+
const parent = dirname(head);
|
|
554
|
+
if (parent === head) {
|
|
555
|
+
return path;
|
|
556
|
+
}
|
|
557
|
+
rest.unshift(basename(head));
|
|
558
|
+
head = parent;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
function inside(cwd, path, home = homedir()) {
|
|
563
|
+
let given = typeof path === "string" && path ? path.replace(UNICODE_SPACES, " ") : ".";
|
|
564
|
+
if (given.startsWith("@")) {
|
|
565
|
+
given = given.slice(1) || ".";
|
|
566
|
+
}
|
|
567
|
+
if (given === "~" || given.startsWith("~/")) {
|
|
568
|
+
given = join(home, given.slice(1));
|
|
569
|
+
}
|
|
570
|
+
if (/^file:\/\//.test(given)) {
|
|
571
|
+
try {
|
|
572
|
+
given = fileURLToPath(given);
|
|
573
|
+
} catch {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const rest = relative(real(resolve(cwd)), real(resolve(cwd, given)));
|
|
578
|
+
return rest !== ".." && !rest.startsWith(`..${sep}`) && !isAbsolute(rest);
|
|
523
579
|
}
|
|
524
580
|
function activate(pi) {
|
|
525
581
|
let reached;
|