@decentnetwork/beagle 0.1.145 → 0.1.146

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.
Files changed (2) hide show
  1. package/dist/desktop/app.js +197 -116
  2. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- window.__DK_UI_VERSION="0.1.145";
1
+ window.__DK_UI_VERSION="0.1.146";
2
2
  "use strict";
3
3
  (() => {
4
4
  // packages/beagle-ui/dist/beagle-ui.js
@@ -389,6 +389,201 @@ window.__DK_UI_VERSION="0.1.145";
389
389
  const icon = file.media === "image" ? "\u{1F5BC} " : file.media === "video" ? "\u{1F3AC} " : "\u{1F4CE} ";
390
390
  return icon + file.name;
391
391
  }
392
+ var NATIVE_MEDIA_MIME = {
393
+ ".jpg": "image/jpeg",
394
+ ".jpeg": "image/jpeg",
395
+ ".png": "image/png",
396
+ ".gif": "image/gif",
397
+ ".webp": "image/webp",
398
+ ".heic": "image/heic",
399
+ ".heif": "image/heif",
400
+ ".bmp": "image/bmp",
401
+ ".m4a": "audio/mp4",
402
+ ".aac": "audio/aac",
403
+ ".mp3": "audio/mpeg",
404
+ ".wav": "audio/wav",
405
+ ".caf": "audio/x-caf",
406
+ ".amr": "audio/amr",
407
+ ".ogg": "audio/ogg",
408
+ ".opus": "audio/ogg",
409
+ ".mp4": "video/mp4",
410
+ ".mov": "video/quicktime",
411
+ ".m4v": "video/x-m4v",
412
+ ".3gp": "video/3gpp",
413
+ ".webm": "video/webm"
414
+ };
415
+ var GROUP_TS_RE = /\n?\[(20\d{2}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{2}:\d{2})\]\s*$/;
416
+ function stripGroupTs(text) {
417
+ const m = GROUP_TS_RE.exec(text);
418
+ return m ? { body: text.slice(0, m.index), ts: m[1] } : { body: text, ts: null };
419
+ }
420
+ function splitGroupSender(text) {
421
+ const m = /^([^:\n]{1,48}):\s([\s\S]+)$/.exec(text);
422
+ return m ? { sender: m[1], body: m[2] } : null;
423
+ }
424
+ function nativeMediaKind(type, ext) {
425
+ const t = String(type || "").toLowerCase();
426
+ if (t === "image" || t === "photo" || t === "picture")
427
+ return "image";
428
+ if (t === "audio" || t === "voice")
429
+ return "audio";
430
+ if (t === "video")
431
+ return "video";
432
+ const mime = NATIVE_MEDIA_MIME[String(ext || "").toLowerCase()];
433
+ return mime ? mime.split("/")[0] : null;
434
+ }
435
+ function unwrapCGP1(text) {
436
+ if (!text.startsWith("CGP1 "))
437
+ return null;
438
+ let j = null;
439
+ try {
440
+ j = JSON.parse(text.slice(5));
441
+ } catch (e) {
442
+ return null;
443
+ }
444
+ if (!j || typeof j !== "object" || !j.message || typeof j.message.text !== "string")
445
+ return null;
446
+ const origin = j.origin || {};
447
+ const senderId = origin.userid || origin.friendid || null;
448
+ const sender = origin.nickname || origin.user_info && origin.user_info.name || (senderId ? senderId.slice(0, 10) : null);
449
+ return { text: j.message.text, sender, senderId };
450
+ }
451
+ var MEDIA_SHAPE_RE = /^\{[\s\S]*"(?:fileExtension|fileName)"\s*:[\s\S]*"data"\s*:\s*"|^\{[\s\S]*"data"\s*:\s*"[A-Za-z0-9+/\\]{64}/;
452
+ function nativeMediaFromText(input) {
453
+ let text = String(input == null ? "" : input).trim();
454
+ let sender = null;
455
+ let senderId = null;
456
+ const cgp = unwrapCGP1(text);
457
+ if (cgp) {
458
+ text = cgp.text;
459
+ sender = cgp.sender;
460
+ senderId = cgp.senderId;
461
+ }
462
+ let body = stripGroupTs(text).body.trim();
463
+ if (body.length < 32)
464
+ return null;
465
+ if (!body.startsWith("{")) {
466
+ const split = splitGroupSender(body);
467
+ if (!split || !split.body.trim().startsWith("{"))
468
+ return null;
469
+ sender = sender || split.sender;
470
+ body = split.body.trim();
471
+ }
472
+ if (!MEDIA_SHAPE_RE.test(body))
473
+ return null;
474
+ const extMatch = /"fileExtension"\s*:\s*"([^"]{0,16})"/.exec(body);
475
+ const nameMatch = /"fileName"\s*:\s*"([^"]{0,200})"/.exec(body);
476
+ const typeMatch = /"type"\s*:\s*"([^"]{0,32})"/.exec(body);
477
+ let j = null;
478
+ try {
479
+ j = body.endsWith("}") ? JSON.parse(body) : null;
480
+ } catch (e) {
481
+ j = null;
482
+ }
483
+ if (!j || typeof j !== "object" || typeof j.data !== "string" || j.data.length < 16) {
484
+ if (!extMatch && !nameMatch)
485
+ return null;
486
+ const ext2 = extMatch ? extMatch[1].toLowerCase() : "";
487
+ const kind2 = nativeMediaKind(typeMatch && typeMatch[1], ext2) || "file";
488
+ return { sender, senderId, kind: kind2, name: (nameMatch ? nameMatch[1] : "file") + ext2, broken: true };
489
+ }
490
+ const ext = String(j.fileExtension || "").toLowerCase();
491
+ const named = typeof j.fileName === "string" || typeof j.fileExtension === "string";
492
+ const typed = nativeMediaKind(j.type, "");
493
+ if (!named && !typed)
494
+ return null;
495
+ const kind = nativeMediaKind(j.type, ext) || "file";
496
+ const mime = NATIVE_MEDIA_MIME[ext] || (kind === "file" ? "application/octet-stream" : kind + "/*");
497
+ const name = String(j.fileName || "file") + ext;
498
+ return { sender, senderId, kind, name, url: "data:" + mime + ";base64," + j.data.replace(/\s+/g, "") };
499
+ }
500
+ function nativeMediaLabel(media) {
501
+ if (!media)
502
+ return "";
503
+ const word = media.kind === "image" ? "image" : media.kind === "audio" ? "voice" : media.kind === "video" ? "video" : "file";
504
+ return "[" + word + "] " + media.name;
505
+ }
506
+ var SENT_TIME_MIN_EARLY_MS = 2 * 6e4;
507
+ var MARKER_MAX_EARLY_MS = 6 * 36e5;
508
+ function parseMarkerUtc(s) {
509
+ const m = /^(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{2}):(\d{2})$/.exec(String(s || "").trim());
510
+ if (!m)
511
+ return null;
512
+ const ms = Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]);
513
+ return Number.isFinite(ms) ? ms : null;
514
+ }
515
+ function epochMs(x) {
516
+ const n = typeof x === "string" && /^\d+$/.test(x) ? Number(x) : x;
517
+ if (typeof n !== "number" || !Number.isFinite(n) || n <= 0)
518
+ return null;
519
+ if (n > 1e14)
520
+ return Math.floor(n / 1e3);
521
+ if (n > 1e11)
522
+ return Math.floor(n);
523
+ return Math.floor(n * 1e3);
524
+ }
525
+ function pickSentTime(arrivalMs, sentMs, maxEarlyMs = Infinity) {
526
+ if (!arrivalMs || sentMs == null)
527
+ return arrivalMs;
528
+ const early = arrivalMs - sentMs;
529
+ if (early < SENT_TIME_MIN_EARLY_MS)
530
+ return arrivalMs;
531
+ if (early > maxEarlyMs)
532
+ return arrivalMs;
533
+ return sentMs;
534
+ }
535
+ function groupSentTime(row) {
536
+ var _a, _b, _c, _d;
537
+ const arrival = row && row.ts;
538
+ if (!row || row.dir === "out" || !arrival)
539
+ return { ts: arrival, key: null };
540
+ const text = typeof row.text === "string" ? row.text : "";
541
+ if (text.startsWith("CGP1 ")) {
542
+ let j = null;
543
+ try {
544
+ j = JSON.parse(text.slice(5));
545
+ } catch (e) {
546
+ j = null;
547
+ }
548
+ const msg = j && j.message;
549
+ if (msg && typeof msg === "object") {
550
+ const raw = (_b = (_a = msg.file && msg.file.sent_at_ms) != null ? _a : msg.sent_at_ms) != null ? _b : msg.timestamp;
551
+ const sent2 = epochMs(raw);
552
+ const origin = j.origin && (j.origin.userid || j.origin.friendid || j.origin.nickname) || "";
553
+ const body = typeof msg.text === "string" ? msg.text : msg.file ? JSON.stringify(msg.file) : "";
554
+ return { ts: pickSentTime(arrival, sent2), key: sent2 != null ? `cgp1|${origin}|${raw}|${body}` : null };
555
+ }
556
+ }
557
+ if (row.file) {
558
+ const raw = (_d = (_c = row.sent_at_ms) != null ? _c : row.file.sent_at_ms) != null ? _d : row.origin && row.origin.sent_at_ms;
559
+ const sent2 = epochMs(raw);
560
+ if (sent2 != null) {
561
+ const who = row.origin && (row.origin.userid || row.origin.nickname) || "";
562
+ return { ts: pickSentTime(arrival, sent2), key: `file|${who}|${raw}|${row.file.name}|${row.file.size}` };
563
+ }
564
+ return { ts: arrival, key: null };
565
+ }
566
+ const marker = stripGroupTs(text).ts;
567
+ const sent = marker ? parseMarkerUtc(marker) : null;
568
+ if (sent == null)
569
+ return { ts: arrival, key: null };
570
+ return { ts: pickSentTime(arrival, sent, MARKER_MAX_EARLY_MS), key: `relay|${text}` };
571
+ }
572
+ function datedThread(rows) {
573
+ const seen = /* @__PURE__ */ new Set();
574
+ const out = [];
575
+ const ordered = [...rows || []].sort((a, b) => (a.ts || 0) - (b.ts || 0));
576
+ for (const r of ordered) {
577
+ const { ts, key } = groupSentTime(r);
578
+ if (key) {
579
+ if (seen.has(key))
580
+ continue;
581
+ seen.add(key);
582
+ }
583
+ out.push(ts === r.ts ? r : Object.assign({}, r, { ts, arrivedTs: r.ts }));
584
+ }
585
+ return out.map((r, i) => ({ r, i })).sort((a, b) => (a.r.ts || 0) - (b.r.ts || 0) || a.i - b.i).map((x) => x.r);
586
+ }
392
587
  function dkHash(s) {
393
588
  let h = 2166136261;
394
589
  for (let i = 0; i < s.length; i++) {
@@ -749,7 +944,7 @@ window.__DK_UI_VERSION="0.1.145";
749
944
  const c = cache.current[peerId];
750
945
  if (!c)
751
946
  return;
752
- const arr = [...c.byId.values()].sort((a, b) => a.ts - b.ts);
947
+ const arr = datedThread([...c.byId.values()]);
753
948
  const withDay = [];
754
949
  let lastDay = null;
755
950
  for (const m of arr) {
@@ -2288,120 +2483,6 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2288
2483
  const v = useEnsVerdict(userid, name);
2289
2484
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", { style, title: v.claimed ? v.claimed + " \u2192 " + v.label : void 0 }, v.label || fallback), /* @__PURE__ */ React.createElement(DkEnsMark, { verdict: v, T, size: markSize }));
2290
2485
  }
2291
- var NATIVE_MEDIA_MIME = {
2292
- ".jpg": "image/jpeg",
2293
- ".jpeg": "image/jpeg",
2294
- ".png": "image/png",
2295
- ".gif": "image/gif",
2296
- ".webp": "image/webp",
2297
- ".heic": "image/heic",
2298
- ".heif": "image/heif",
2299
- ".bmp": "image/bmp",
2300
- ".m4a": "audio/mp4",
2301
- ".aac": "audio/aac",
2302
- ".mp3": "audio/mpeg",
2303
- ".wav": "audio/wav",
2304
- ".caf": "audio/x-caf",
2305
- ".amr": "audio/amr",
2306
- ".ogg": "audio/ogg",
2307
- ".opus": "audio/ogg",
2308
- ".mp4": "video/mp4",
2309
- ".mov": "video/quicktime",
2310
- ".m4v": "video/x-m4v",
2311
- ".3gp": "video/3gpp",
2312
- ".webm": "video/webm"
2313
- };
2314
- var GROUP_TS_RE = /\n?\[(20\d{2}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{2}:\d{2})\]\s*$/;
2315
- function stripGroupTs(text) {
2316
- const m = GROUP_TS_RE.exec(text);
2317
- return m ? { body: text.slice(0, m.index), ts: m[1] } : { body: text, ts: null };
2318
- }
2319
- function splitGroupSender(text) {
2320
- const m = /^([^:\n]{1,48}):\s([\s\S]+)$/.exec(text);
2321
- return m ? { sender: m[1], body: m[2] } : null;
2322
- }
2323
- function nativeMediaKind(type, ext) {
2324
- const t = String(type || "").toLowerCase();
2325
- if (t === "image" || t === "photo" || t === "picture")
2326
- return "image";
2327
- if (t === "audio" || t === "voice")
2328
- return "audio";
2329
- if (t === "video")
2330
- return "video";
2331
- const mime = NATIVE_MEDIA_MIME[String(ext || "").toLowerCase()];
2332
- return mime ? mime.split("/")[0] : null;
2333
- }
2334
- function unwrapCGP1(text) {
2335
- if (!text.startsWith("CGP1 "))
2336
- return null;
2337
- let j = null;
2338
- try {
2339
- j = JSON.parse(text.slice(5));
2340
- } catch (e) {
2341
- return null;
2342
- }
2343
- if (!j || typeof j !== "object" || !j.message || typeof j.message.text !== "string")
2344
- return null;
2345
- const origin = j.origin || {};
2346
- const senderId = origin.userid || origin.friendid || null;
2347
- const sender = origin.nickname || origin.user_info && origin.user_info.name || (senderId ? senderId.slice(0, 10) : null);
2348
- return { text: j.message.text, sender, senderId };
2349
- }
2350
- var MEDIA_SHAPE_RE = /^\{[\s\S]*"(?:fileExtension|fileName)"\s*:[\s\S]*"data"\s*:\s*"|^\{[\s\S]*"data"\s*:\s*"[A-Za-z0-9+/\\]{64}/;
2351
- function nativeMediaFromText(input) {
2352
- let text = String(input == null ? "" : input).trim();
2353
- let sender = null;
2354
- let senderId = null;
2355
- const cgp = unwrapCGP1(text);
2356
- if (cgp) {
2357
- text = cgp.text;
2358
- sender = cgp.sender;
2359
- senderId = cgp.senderId;
2360
- }
2361
- let body = stripGroupTs(text).body.trim();
2362
- if (body.length < 32)
2363
- return null;
2364
- if (!body.startsWith("{")) {
2365
- const split = splitGroupSender(body);
2366
- if (!split || !split.body.trim().startsWith("{"))
2367
- return null;
2368
- sender = sender || split.sender;
2369
- body = split.body.trim();
2370
- }
2371
- if (!MEDIA_SHAPE_RE.test(body))
2372
- return null;
2373
- const extMatch = /"fileExtension"\s*:\s*"([^"]{0,16})"/.exec(body);
2374
- const nameMatch = /"fileName"\s*:\s*"([^"]{0,200})"/.exec(body);
2375
- const typeMatch = /"type"\s*:\s*"([^"]{0,32})"/.exec(body);
2376
- let j = null;
2377
- try {
2378
- j = body.endsWith("}") ? JSON.parse(body) : null;
2379
- } catch (e) {
2380
- j = null;
2381
- }
2382
- if (!j || typeof j !== "object" || typeof j.data !== "string" || j.data.length < 16) {
2383
- if (!extMatch && !nameMatch)
2384
- return null;
2385
- const ext2 = extMatch ? extMatch[1].toLowerCase() : "";
2386
- const kind2 = nativeMediaKind(typeMatch && typeMatch[1], ext2) || "file";
2387
- return { sender, senderId, kind: kind2, name: (nameMatch ? nameMatch[1] : "file") + ext2, broken: true };
2388
- }
2389
- const ext = String(j.fileExtension || "").toLowerCase();
2390
- const named = typeof j.fileName === "string" || typeof j.fileExtension === "string";
2391
- const typed = nativeMediaKind(j.type, "");
2392
- if (!named && !typed)
2393
- return null;
2394
- const kind = nativeMediaKind(j.type, ext) || "file";
2395
- const mime = NATIVE_MEDIA_MIME[ext] || (kind === "file" ? "application/octet-stream" : kind + "/*");
2396
- const name = String(j.fileName || "file") + ext;
2397
- return { sender, senderId, kind, name, url: "data:" + mime + ";base64," + j.data.replace(/\s+/g, "") };
2398
- }
2399
- function nativeMediaLabel(media) {
2400
- if (!media)
2401
- return "";
2402
- const word = media.kind === "image" ? "image" : media.kind === "audio" ? "voice" : media.kind === "video" ? "video" : "file";
2403
- return "[" + word + "] " + media.name;
2404
- }
2405
2486
  var DK_CMD_HIST_KEY = "beagle.assistant.history";
2406
2487
  var DK_CMD_HIST_MAX = 50;
2407
2488
  function RequestsBlock({ T, requests, onAct }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/beagle",
3
- "version": "0.1.145",
3
+ "version": "0.1.146",
4
4
  "description": "Beagle — P2P chat, file transfer and calls for regular users, on the Decent Network. No admin privilege required.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "start": "node dist/cli.js"
27
27
  },
28
28
  "dependencies": {
29
- "@decentnetwork/beagle-ui": "^0.2.47",
29
+ "@decentnetwork/beagle-ui": "^0.2.48",
30
30
  "@decentnetwork/chat-components": "^0.1.3",
31
31
  "@decentnetwork/lan": "^0.1.316",
32
32
  "@decentnetwork/peer": "^0.1.178",