@decentnetwork/beagle 0.1.145 → 0.1.147
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/dist/desktop/app.js +199 -116
- package/package.json +2 -2
package/dist/desktop/app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
window.__DK_UI_VERSION="0.1.
|
|
1
|
+
window.__DK_UI_VERSION="0.1.147";
|
|
2
2
|
"use strict";
|
|
3
3
|
(() => {
|
|
4
4
|
// packages/beagle-ui/dist/beagle-ui.js
|
|
@@ -389,6 +389,203 @@ 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 UTC_MARKER_CUTOFF_MS = Date.UTC(2026, 10, 24, 20, 31, 0);
|
|
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, notBeforeMs = -Infinity) {
|
|
526
|
+
if (!arrivalMs || sentMs == null)
|
|
527
|
+
return arrivalMs;
|
|
528
|
+
if (sentMs < notBeforeMs)
|
|
529
|
+
return arrivalMs;
|
|
530
|
+
const early = arrivalMs - sentMs;
|
|
531
|
+
if (early < SENT_TIME_MIN_EARLY_MS)
|
|
532
|
+
return arrivalMs;
|
|
533
|
+
return sentMs;
|
|
534
|
+
}
|
|
535
|
+
function groupSentTime(row) {
|
|
536
|
+
var _a, _b, _c;
|
|
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 meta = (_a = msg.file && msg.file.sent_at_ms) != null ? _a : msg.sent_at_ms;
|
|
551
|
+
const raw = meta != null ? meta : msg.timestamp;
|
|
552
|
+
const sent2 = epochMs(raw);
|
|
553
|
+
const origin = j.origin && (j.origin.userid || j.origin.friendid || j.origin.nickname) || "";
|
|
554
|
+
const body = typeof msg.text === "string" ? msg.text : msg.file ? JSON.stringify(msg.file) : "";
|
|
555
|
+
const ts = pickSentTime(arrival, sent2, meta != null ? UTC_MARKER_CUTOFF_MS : -Infinity);
|
|
556
|
+
return { ts, key: sent2 != null ? `cgp1|${origin}|${raw}|${body}` : null };
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (row.file) {
|
|
560
|
+
const raw = (_c = (_b = row.sent_at_ms) != null ? _b : row.file.sent_at_ms) != null ? _c : row.origin && row.origin.sent_at_ms;
|
|
561
|
+
const sent2 = epochMs(raw);
|
|
562
|
+
if (sent2 != null) {
|
|
563
|
+
const who = row.origin && (row.origin.userid || row.origin.nickname) || "";
|
|
564
|
+
return { ts: pickSentTime(arrival, sent2, UTC_MARKER_CUTOFF_MS), key: `file|${who}|${raw}|${row.file.name}|${row.file.size}` };
|
|
565
|
+
}
|
|
566
|
+
return { ts: arrival, key: null };
|
|
567
|
+
}
|
|
568
|
+
const marker = stripGroupTs(text).ts;
|
|
569
|
+
const sent = marker ? parseMarkerUtc(marker) : null;
|
|
570
|
+
if (sent == null)
|
|
571
|
+
return { ts: arrival, key: null };
|
|
572
|
+
return { ts: pickSentTime(arrival, sent, UTC_MARKER_CUTOFF_MS), key: `relay|${text}` };
|
|
573
|
+
}
|
|
574
|
+
function datedThread(rows) {
|
|
575
|
+
const seen = /* @__PURE__ */ new Set();
|
|
576
|
+
const out = [];
|
|
577
|
+
const ordered = [...rows || []].sort((a, b) => (a.ts || 0) - (b.ts || 0));
|
|
578
|
+
for (const r of ordered) {
|
|
579
|
+
const { ts, key } = groupSentTime(r);
|
|
580
|
+
if (key) {
|
|
581
|
+
if (seen.has(key))
|
|
582
|
+
continue;
|
|
583
|
+
seen.add(key);
|
|
584
|
+
}
|
|
585
|
+
out.push(ts === r.ts ? r : Object.assign({}, r, { ts, arrivedTs: r.ts }));
|
|
586
|
+
}
|
|
587
|
+
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);
|
|
588
|
+
}
|
|
392
589
|
function dkHash(s) {
|
|
393
590
|
let h = 2166136261;
|
|
394
591
|
for (let i = 0; i < s.length; i++) {
|
|
@@ -749,7 +946,7 @@ window.__DK_UI_VERSION="0.1.145";
|
|
|
749
946
|
const c = cache.current[peerId];
|
|
750
947
|
if (!c)
|
|
751
948
|
return;
|
|
752
|
-
const arr = [...c.byId.values()]
|
|
949
|
+
const arr = datedThread([...c.byId.values()]);
|
|
753
950
|
const withDay = [];
|
|
754
951
|
let lastDay = null;
|
|
755
952
|
for (const m of arr) {
|
|
@@ -2288,120 +2485,6 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2288
2485
|
const v = useEnsVerdict(userid, name);
|
|
2289
2486
|
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
2487
|
}
|
|
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
2488
|
var DK_CMD_HIST_KEY = "beagle.assistant.history";
|
|
2406
2489
|
var DK_CMD_HIST_MAX = 50;
|
|
2407
2490
|
function RequestsBlock({ T, requests, onAct }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/beagle",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.147",
|
|
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.
|
|
29
|
+
"@decentnetwork/beagle-ui": "^0.2.49",
|
|
30
30
|
"@decentnetwork/chat-components": "^0.1.3",
|
|
31
31
|
"@decentnetwork/lan": "^0.1.316",
|
|
32
32
|
"@decentnetwork/peer": "^0.1.178",
|