@celljs/ta-rooms 4.19.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.
@@ -1,5 +1,8 @@
1
1
  // web-src/extension.ts
2
- import { isAbsolute, relative, resolve } from "node:path";
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;
@@ -53,6 +56,22 @@ var TaHostUtil;
53
56
  }
54
57
  TaHostUtil2.role = role;
55
58
  })(TaHostUtil || (TaHostUtil = {}));
59
+ var TA_DOUBLE_LOOK = {
60
+ name: "@celljs/ta-web",
61
+ key: "assistant.species",
62
+ given: ["trex", "triceratops", "stegosaurus", "brachiosaurus", "velociraptor", "ankylosaurus", "pteranodon", "parasaurolophus"]
63
+ };
64
+ var TaDoubleLookUtil;
65
+ (function(TaDoubleLookUtil2) {
66
+ function given(id) {
67
+ let hash = 2166136261;
68
+ for (let i = 0;i < id.length; i++) {
69
+ hash = Math.imul(hash ^ id.charCodeAt(i), 16777619);
70
+ }
71
+ return TA_DOUBLE_LOOK.given[(hash >>> 0) % TA_DOUBLE_LOOK.given.length];
72
+ }
73
+ TaDoubleLookUtil2.given = given;
74
+ })(TaDoubleLookUtil || (TaDoubleLookUtil = {}));
56
75
  var TA_WITH_OTHERS_MARK = "[ta:speaks-with-others]";
57
76
  var TA_ASK_ENTRY = "ta-ask";
58
77
  var TaAskUtil;
@@ -178,6 +197,9 @@ var ROOM_CAPABILITIES = ["files", "commands"];
178
197
  var DoubleKeys;
179
198
  ((DoubleKeys) => {
180
199
  DoubleKeys.QUIET = "doubles.quiet";
200
+ DoubleKeys.REPLY = "doubles.reply";
201
+ DoubleKeys.DRAFTS = "doubles.drafts";
202
+ DoubleKeys.DONE = "doubles.done";
181
203
  DoubleKeys.GRANTS = "doubles.grants";
182
204
  DoubleKeys.ASKS = "doubles.asks";
183
205
  DoubleKeys.LOG = "doubles.log";
@@ -187,6 +209,8 @@ var DoubleKeys;
187
209
  DoubleKeys.HANDED = "doubles.handed";
188
210
  DoubleKeys.DEVICE = "doubles.device";
189
211
  })(DoubleKeys ||= {});
212
+ var DRAFTS_MAX = 50;
213
+ var DRAFT_MS = 24 * 60 * 60 * 1000;
190
214
  var GRANT_HOURS = [1, 24, 24 * 7];
191
215
 
192
216
  // ../ta-protocol/esm/common/language.js
@@ -254,8 +278,8 @@ var DoubleUtil;
254
278
  return all.filter((name) => !off.has(name));
255
279
  }
256
280
  DoubleUtil.ownTools = ownTools;
257
- function grantsOf(grants, friend, now) {
258
- 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));
259
283
  }
260
284
  DoubleUtil.grantsOf = grantsOf;
261
285
  function work(grants) {
@@ -277,9 +301,28 @@ var DoubleUtil;
277
301
  }
278
302
  DoubleUtil.tools = tools;
279
303
  function asking(lines, self, since, now) {
280
- 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));
281
305
  }
282
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;
283
326
  function askingAgents(lines, self, agents, since, now) {
284
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 })) : []);
285
328
  }
@@ -500,10 +543,39 @@ var USER_ROOM_TOOLS = [
500
543
  run: (doubles, params, file) => doubles.user.handTask(file, params.room, params.to, params.task)
501
544
  }
502
545
  ];
503
- function inside(cwd, path) {
504
- const target = resolve(cwd, typeof path === "string" && path ? path.replace(/^@/, "") : ".");
505
- const rest = relative(cwd, target);
506
- return !rest.startsWith("..") && !isAbsolute(rest);
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);
507
579
  }
508
580
  function activate(pi) {
509
581
  let reached;