@decentnetwork/beagle 0.1.142 → 0.1.143
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 +156 -62
- 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.143";
|
|
2
2
|
"use strict";
|
|
3
3
|
(() => {
|
|
4
4
|
// packages/beagle-ui/dist/beagle-ui.js
|
|
@@ -2146,6 +2146,120 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2146
2146
|
const action = friend ? "chat" : address ? isGroup ? "join" : "add" : null;
|
|
2147
2147
|
return { userid, address, isGroup, friend, action };
|
|
2148
2148
|
}
|
|
2149
|
+
var NATIVE_MEDIA_MIME = {
|
|
2150
|
+
".jpg": "image/jpeg",
|
|
2151
|
+
".jpeg": "image/jpeg",
|
|
2152
|
+
".png": "image/png",
|
|
2153
|
+
".gif": "image/gif",
|
|
2154
|
+
".webp": "image/webp",
|
|
2155
|
+
".heic": "image/heic",
|
|
2156
|
+
".heif": "image/heif",
|
|
2157
|
+
".bmp": "image/bmp",
|
|
2158
|
+
".m4a": "audio/mp4",
|
|
2159
|
+
".aac": "audio/aac",
|
|
2160
|
+
".mp3": "audio/mpeg",
|
|
2161
|
+
".wav": "audio/wav",
|
|
2162
|
+
".caf": "audio/x-caf",
|
|
2163
|
+
".amr": "audio/amr",
|
|
2164
|
+
".ogg": "audio/ogg",
|
|
2165
|
+
".opus": "audio/ogg",
|
|
2166
|
+
".mp4": "video/mp4",
|
|
2167
|
+
".mov": "video/quicktime",
|
|
2168
|
+
".m4v": "video/x-m4v",
|
|
2169
|
+
".3gp": "video/3gpp",
|
|
2170
|
+
".webm": "video/webm"
|
|
2171
|
+
};
|
|
2172
|
+
var GROUP_TS_RE = /\n?\[(20\d{2}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{2}:\d{2})\]\s*$/;
|
|
2173
|
+
function stripGroupTs(text) {
|
|
2174
|
+
const m = GROUP_TS_RE.exec(text);
|
|
2175
|
+
return m ? { body: text.slice(0, m.index), ts: m[1] } : { body: text, ts: null };
|
|
2176
|
+
}
|
|
2177
|
+
function splitGroupSender(text) {
|
|
2178
|
+
const m = /^([^:\n]{1,48}):\s([\s\S]+)$/.exec(text);
|
|
2179
|
+
return m ? { sender: m[1], body: m[2] } : null;
|
|
2180
|
+
}
|
|
2181
|
+
function nativeMediaKind(type, ext) {
|
|
2182
|
+
const t = String(type || "").toLowerCase();
|
|
2183
|
+
if (t === "image" || t === "photo" || t === "picture")
|
|
2184
|
+
return "image";
|
|
2185
|
+
if (t === "audio" || t === "voice")
|
|
2186
|
+
return "audio";
|
|
2187
|
+
if (t === "video")
|
|
2188
|
+
return "video";
|
|
2189
|
+
const mime = NATIVE_MEDIA_MIME[String(ext || "").toLowerCase()];
|
|
2190
|
+
return mime ? mime.split("/")[0] : null;
|
|
2191
|
+
}
|
|
2192
|
+
function unwrapCGP1(text) {
|
|
2193
|
+
if (!text.startsWith("CGP1 "))
|
|
2194
|
+
return null;
|
|
2195
|
+
let j = null;
|
|
2196
|
+
try {
|
|
2197
|
+
j = JSON.parse(text.slice(5));
|
|
2198
|
+
} catch (e) {
|
|
2199
|
+
return null;
|
|
2200
|
+
}
|
|
2201
|
+
if (!j || typeof j !== "object" || !j.message || typeof j.message.text !== "string")
|
|
2202
|
+
return null;
|
|
2203
|
+
const origin = j.origin || {};
|
|
2204
|
+
const senderId = origin.userid || origin.friendid || null;
|
|
2205
|
+
const sender = origin.nickname || origin.user_info && origin.user_info.name || (senderId ? senderId.slice(0, 10) : null);
|
|
2206
|
+
return { text: j.message.text, sender, senderId };
|
|
2207
|
+
}
|
|
2208
|
+
var MEDIA_SHAPE_RE = /^\{[\s\S]*"(?:fileExtension|fileName)"\s*:[\s\S]*"data"\s*:\s*"|^\{[\s\S]*"data"\s*:\s*"[A-Za-z0-9+/\\]{64}/;
|
|
2209
|
+
function nativeMediaFromText(input) {
|
|
2210
|
+
let text = String(input == null ? "" : input).trim();
|
|
2211
|
+
let sender = null;
|
|
2212
|
+
let senderId = null;
|
|
2213
|
+
const cgp = unwrapCGP1(text);
|
|
2214
|
+
if (cgp) {
|
|
2215
|
+
text = cgp.text;
|
|
2216
|
+
sender = cgp.sender;
|
|
2217
|
+
senderId = cgp.senderId;
|
|
2218
|
+
}
|
|
2219
|
+
let body = stripGroupTs(text).body.trim();
|
|
2220
|
+
if (body.length < 32)
|
|
2221
|
+
return null;
|
|
2222
|
+
if (!body.startsWith("{")) {
|
|
2223
|
+
const split = splitGroupSender(body);
|
|
2224
|
+
if (!split || !split.body.trim().startsWith("{"))
|
|
2225
|
+
return null;
|
|
2226
|
+
sender = sender || split.sender;
|
|
2227
|
+
body = split.body.trim();
|
|
2228
|
+
}
|
|
2229
|
+
if (!MEDIA_SHAPE_RE.test(body))
|
|
2230
|
+
return null;
|
|
2231
|
+
const extMatch = /"fileExtension"\s*:\s*"([^"]{0,16})"/.exec(body);
|
|
2232
|
+
const nameMatch = /"fileName"\s*:\s*"([^"]{0,200})"/.exec(body);
|
|
2233
|
+
const typeMatch = /"type"\s*:\s*"([^"]{0,32})"/.exec(body);
|
|
2234
|
+
let j = null;
|
|
2235
|
+
try {
|
|
2236
|
+
j = body.endsWith("}") ? JSON.parse(body) : null;
|
|
2237
|
+
} catch (e) {
|
|
2238
|
+
j = null;
|
|
2239
|
+
}
|
|
2240
|
+
if (!j || typeof j !== "object" || typeof j.data !== "string" || j.data.length < 16) {
|
|
2241
|
+
if (!extMatch && !nameMatch)
|
|
2242
|
+
return null;
|
|
2243
|
+
const ext2 = extMatch ? extMatch[1].toLowerCase() : "";
|
|
2244
|
+
const kind2 = nativeMediaKind(typeMatch && typeMatch[1], ext2) || "file";
|
|
2245
|
+
return { sender, senderId, kind: kind2, name: (nameMatch ? nameMatch[1] : "file") + ext2, broken: true };
|
|
2246
|
+
}
|
|
2247
|
+
const ext = String(j.fileExtension || "").toLowerCase();
|
|
2248
|
+
const named = typeof j.fileName === "string" || typeof j.fileExtension === "string";
|
|
2249
|
+
const typed = nativeMediaKind(j.type, "");
|
|
2250
|
+
if (!named && !typed)
|
|
2251
|
+
return null;
|
|
2252
|
+
const kind = nativeMediaKind(j.type, ext) || "file";
|
|
2253
|
+
const mime = NATIVE_MEDIA_MIME[ext] || (kind === "file" ? "application/octet-stream" : kind + "/*");
|
|
2254
|
+
const name = String(j.fileName || "file") + ext;
|
|
2255
|
+
return { sender, senderId, kind, name, url: "data:" + mime + ";base64," + j.data.replace(/\s+/g, "") };
|
|
2256
|
+
}
|
|
2257
|
+
function nativeMediaLabel(media) {
|
|
2258
|
+
if (!media)
|
|
2259
|
+
return "";
|
|
2260
|
+
const word = media.kind === "image" ? "image" : media.kind === "audio" ? "voice" : media.kind === "video" ? "video" : "file";
|
|
2261
|
+
return "[" + word + "] " + media.name;
|
|
2262
|
+
}
|
|
2149
2263
|
var DK_CMD_HIST_KEY = "beagle.assistant.history";
|
|
2150
2264
|
var DK_CMD_HIST_MAX = 50;
|
|
2151
2265
|
function RequestsBlock({ T, requests, onAct }) {
|
|
@@ -2556,6 +2670,9 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2556
2670
|
return card;
|
|
2557
2671
|
const s = String(text == null ? "" : text);
|
|
2558
2672
|
const mine = /^you:\s*/i.test(s);
|
|
2673
|
+
const media = nativeMediaFromText(s.replace(/^you:\s*/i, ""));
|
|
2674
|
+
if (media)
|
|
2675
|
+
return (mine ? "you: " : "") + (media.sender ? media.sender + ": " : "") + nativeMediaLabel(media);
|
|
2559
2676
|
const cgp = dkParseCGP1(s.replace(/^you:\s*/i, ""));
|
|
2560
2677
|
if (cgp)
|
|
2561
2678
|
return (mine ? "you: " : "") + cgp.sender + ": " + (cgp.file ? fileLabel(cgp.file, T) : cgp.body.replace(/\s+/g, " "));
|
|
@@ -2663,31 +2780,6 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2663
2780
|
}
|
|
2664
2781
|
return html || dkHtmlEscape(src);
|
|
2665
2782
|
}
|
|
2666
|
-
var DK_NATIVE_MEDIA_MIME = {
|
|
2667
|
-
".jpg": "image/jpeg",
|
|
2668
|
-
".jpeg": "image/jpeg",
|
|
2669
|
-
".png": "image/png",
|
|
2670
|
-
".gif": "image/gif",
|
|
2671
|
-
".webp": "image/webp",
|
|
2672
|
-
".heic": "image/heic",
|
|
2673
|
-
".m4a": "audio/mp4",
|
|
2674
|
-
".aac": "audio/aac",
|
|
2675
|
-
".mp3": "audio/mpeg",
|
|
2676
|
-
".wav": "audio/wav",
|
|
2677
|
-
".caf": "audio/x-caf",
|
|
2678
|
-
".mp4": "video/mp4",
|
|
2679
|
-
".mov": "video/quicktime",
|
|
2680
|
-
".m4v": "video/x-m4v"
|
|
2681
|
-
};
|
|
2682
|
-
var DK_GROUP_TS_RE = /\n?\[(20\d{2}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{2}:\d{2})\]\s*$/;
|
|
2683
|
-
function dkStripGroupTs(text) {
|
|
2684
|
-
const m = DK_GROUP_TS_RE.exec(text);
|
|
2685
|
-
return m ? { body: text.slice(0, m.index), ts: m[1] } : { body: text, ts: null };
|
|
2686
|
-
}
|
|
2687
|
-
function dkSplitGroupSender(text) {
|
|
2688
|
-
const m = /^([^:\n]{1,48}):\s([\s\S]+)$/.exec(text);
|
|
2689
|
-
return m ? { sender: m[1], body: m[2] } : null;
|
|
2690
|
-
}
|
|
2691
2783
|
function dkParseCGP1(text) {
|
|
2692
2784
|
const t = String(text || "").trim();
|
|
2693
2785
|
if (!t.startsWith("CGP1 "))
|
|
@@ -2712,8 +2804,8 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2712
2804
|
if (cgp)
|
|
2713
2805
|
return cgp;
|
|
2714
2806
|
const t = String(text || "");
|
|
2715
|
-
const { body: noTs, ts } =
|
|
2716
|
-
const split =
|
|
2807
|
+
const { body: noTs, ts } = stripGroupTs(t);
|
|
2808
|
+
const split = splitGroupSender(noTs.trim());
|
|
2717
2809
|
if (!split)
|
|
2718
2810
|
return null;
|
|
2719
2811
|
return { sender: split.sender, senderId: null, body: split.body.trim(), ts, strong: !!ts };
|
|
@@ -2799,36 +2891,6 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2799
2891
|
function dkThreadIsGroup(thread) {
|
|
2800
2892
|
return (thread || []).some((m) => !m.day && m.dir !== "out" && !m.file && (dkGroupParse(m.text) || {}).strong);
|
|
2801
2893
|
}
|
|
2802
|
-
function dkNativeMediaFromText(text) {
|
|
2803
|
-
let body = dkStripGroupTs(String(text || "")).body.trim();
|
|
2804
|
-
if (body.length < 32)
|
|
2805
|
-
return null;
|
|
2806
|
-
let sender = null;
|
|
2807
|
-
if (!body.startsWith("{")) {
|
|
2808
|
-
const split = dkSplitGroupSender(body);
|
|
2809
|
-
if (!split || !split.body.startsWith("{"))
|
|
2810
|
-
return null;
|
|
2811
|
-
sender = split.sender;
|
|
2812
|
-
body = split.body.trim();
|
|
2813
|
-
}
|
|
2814
|
-
if (!body.startsWith("{") || !body.endsWith("}"))
|
|
2815
|
-
return null;
|
|
2816
|
-
let j = null;
|
|
2817
|
-
try {
|
|
2818
|
-
j = JSON.parse(body);
|
|
2819
|
-
} catch (e) {
|
|
2820
|
-
return null;
|
|
2821
|
-
}
|
|
2822
|
-
if (!j || typeof j !== "object" || typeof j.data !== "string" || j.data.length < 16)
|
|
2823
|
-
return null;
|
|
2824
|
-
const kind = j.type === "image" ? "image" : j.type === "audio" || j.type === "voice" ? "audio" : j.type === "video" ? "video" : null;
|
|
2825
|
-
if (!kind)
|
|
2826
|
-
return null;
|
|
2827
|
-
const ext = String(j.fileExtension || "").toLowerCase();
|
|
2828
|
-
const mime = DK_NATIVE_MEDIA_MIME[ext] || kind + "/*";
|
|
2829
|
-
const name = String(j.fileName || "file") + ext;
|
|
2830
|
-
return { sender, kind, name, url: "data:" + mime + ";base64," + j.data.replace(/\s+/g, "") };
|
|
2831
|
-
}
|
|
2832
2894
|
function MarkdownText({ text, onNameCard }) {
|
|
2833
2895
|
const onClick = (e) => {
|
|
2834
2896
|
const a = e.target && e.target.closest && e.target.closest("a");
|
|
@@ -3056,10 +3118,10 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3056
3118
|
}
|
|
3057
3119
|
function DkMsgBody({ m, peer, T, lang, onTheater, onDelete, onCancel, onRetry, onRetryMsg, onReveal, onOpenFile, onCall, onFormSubmit, onNameCard, onAssistantRemove, onAssistantAdopt, answered, selMode, selected, onToggleSel, busy, isGroup }) {
|
|
3058
3120
|
const mine = m.from === "me";
|
|
3059
|
-
const nativeMedia = !m.file ?
|
|
3121
|
+
const nativeMedia = !m.file ? nativeMediaFromText(m.text) : null;
|
|
3060
3122
|
const grp = isGroup && m.dir !== "out" && !m.file && !nativeMedia ? dkGroupParse(m.text) : null;
|
|
3061
3123
|
const fileSender = !mine && m.file && m.origin && (m.origin.userid || m.origin.nickname) ? { sender: m.origin.nickname || (m.origin.userid || "").slice(0, 10), senderId: m.origin.userid || null } : null;
|
|
3062
|
-
const grpSender = grp || fileSender || (nativeMedia && nativeMedia.sender ? { sender: nativeMedia.sender, senderId: null } : null);
|
|
3124
|
+
const grpSender = grp || fileSender || (nativeMedia && nativeMedia.sender ? { sender: nativeMedia.sender, senderId: nativeMedia.senderId || null } : null);
|
|
3063
3125
|
const read = window.ChatComponents ? window.ChatComponents.readMessage((grp ? grp.body : m.text) || "") : { text: grp ? grp.body : m.text, form: null, interaction: null };
|
|
3064
3126
|
const submitted = read.form && answered ? answered.get(read.form.custom_id) : null;
|
|
3065
3127
|
const rtcFile = !mine && !m.file ? dkRtcFileFromText(peer.userId || peer.id, m.text) : null;
|
|
@@ -3353,7 +3415,18 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3353
3415
|
)
|
|
3354
3416
|
);
|
|
3355
3417
|
})()
|
|
3356
|
-
) : nativeMedia ? /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 4, maxWidth: "min(420px, 88%)" } }, nativeMedia.sender && /* @__PURE__ */ React.createElement(DkGroupSender, { grp: { sender: nativeMedia.sender, senderId: null }, T }), nativeMedia.
|
|
3418
|
+
) : nativeMedia ? /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 4, maxWidth: "min(420px, 88%)" } }, nativeMedia.sender && /* @__PURE__ */ React.createElement(DkGroupSender, { grp: { sender: nativeMedia.sender, senderId: nativeMedia.senderId || null }, T }), nativeMedia.broken ? (
|
|
3419
|
+
// Cut short or malformed: say what it was, never show the base64.
|
|
3420
|
+
/* @__PURE__ */ React.createElement("span", { style: {
|
|
3421
|
+
padding: "9px 12px",
|
|
3422
|
+
borderRadius: 12,
|
|
3423
|
+
background: "var(--bub-them)",
|
|
3424
|
+
border: "1px solid var(--line)",
|
|
3425
|
+
fontFamily: "var(--ui)",
|
|
3426
|
+
fontSize: 12.5,
|
|
3427
|
+
color: "var(--faint)"
|
|
3428
|
+
} }, "[" + (T && T["mediaKind_" + nativeMedia.kind] || nativeMedia.kind) + ", " + (T && T.mediaNotShown || "could not be shown") + "] " + nativeMedia.name)
|
|
3429
|
+
) : nativeMedia.kind === "image" ? /* @__PURE__ */ React.createElement(
|
|
3357
3430
|
"img",
|
|
3358
3431
|
{
|
|
3359
3432
|
src: nativeMedia.url,
|
|
@@ -3368,7 +3441,28 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3368
3441
|
}
|
|
3369
3442
|
}
|
|
3370
3443
|
}
|
|
3371
|
-
) : nativeMedia.kind === "audio" ? /* @__PURE__ */ React.createElement("audio", { controls: true, src: nativeMedia.url, style: { maxWidth: "100%" } }) : /* @__PURE__ */ React.createElement("video", { controls: true, src: nativeMedia.url, style: { maxWidth: "100%", borderRadius: 12, border: "1px solid var(--line)" } })
|
|
3444
|
+
) : nativeMedia.kind === "audio" ? /* @__PURE__ */ React.createElement("audio", { controls: true, src: nativeMedia.url, style: { maxWidth: "100%" } }) : nativeMedia.kind === "video" ? /* @__PURE__ */ React.createElement("video", { controls: true, src: nativeMedia.url, style: { maxWidth: "100%", borderRadius: 12, border: "1px solid var(--line)" } }) : /* @__PURE__ */ React.createElement(
|
|
3445
|
+
"a",
|
|
3446
|
+
{
|
|
3447
|
+
href: nativeMedia.url,
|
|
3448
|
+
download: nativeMedia.name,
|
|
3449
|
+
style: {
|
|
3450
|
+
display: "inline-flex",
|
|
3451
|
+
alignItems: "center",
|
|
3452
|
+
gap: 8,
|
|
3453
|
+
padding: "9px 12px",
|
|
3454
|
+
borderRadius: 12,
|
|
3455
|
+
background: "var(--bub-them)",
|
|
3456
|
+
border: "1px solid var(--line)",
|
|
3457
|
+
color: "var(--text)",
|
|
3458
|
+
fontFamily: "var(--mono)",
|
|
3459
|
+
fontSize: 12.5,
|
|
3460
|
+
textDecoration: "none"
|
|
3461
|
+
}
|
|
3462
|
+
},
|
|
3463
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "download", size: 16, stroke: 2, color: "var(--accent)" }),
|
|
3464
|
+
nativeMedia.name
|
|
3465
|
+
)) : grp && grp.file ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(DkGroupSender, { grp, T }), /* @__PURE__ */ React.createElement(DkGroupFileCard, { file: grp.file, T, offline: m.via === "offline" })) : (() => {
|
|
3372
3466
|
const contact = !read.form ? dkParseBeagleContact(read.text) : null;
|
|
3373
3467
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, grp && /* @__PURE__ */ React.createElement(DkGroupSender, { grp, T }), contact && (contact.address || contact.userid) ? /* @__PURE__ */ React.createElement(DkContactCardMsg, { card: contact, mine, T, onNameCard }) : /* @__PURE__ */ React.createElement("div", { style: {
|
|
3374
3468
|
padding: "8px 12px",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/beagle",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.143",
|
|
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.45",
|
|
30
30
|
"@decentnetwork/chat-components": "^0.1.3",
|
|
31
31
|
"@decentnetwork/lan": "^0.1.316",
|
|
32
32
|
"@decentnetwork/peer": "^0.1.178",
|