@decentnetwork/beagle 0.1.138 → 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.
@@ -5,6 +5,9 @@ export interface InlineFileEvent {
5
5
  fileType?: string;
6
6
  data: Uint8Array;
7
7
  via: "online" | "offline";
8
+ /** peer >= 0.1.176: SHA-256 hex of `data`. The Beagle apps key the row
9
+ * `ft-` + its first 16 chars, so a re-delivery is stored once. */
10
+ fileId?: string;
8
11
  }
9
12
  export interface InviteEvent {
10
13
  pubkey: string;
@@ -41,6 +44,16 @@ export interface FileCancel {
41
44
  friendId: string;
42
45
  fileId: string;
43
46
  sending: boolean;
47
+ /** Set by the SDK when it ended the transfer itself: "no-response" (no
48
+ * answer to the offer for 60 s), "timeout" (no ack progress for 60 s),
49
+ * "peer-offline" (the friend's session went away, peer >= 0.1.178),
50
+ * "local" (our own cancelSend). Absent = the friend sent KILL. */
51
+ reason?: "no-response" | "timeout" | "peer-offline" | "local" | string;
52
+ /** Incoming only (peer >= 0.1.178): how far it got, and whether the prefix
53
+ * is kept for a resumed re-offer. */
54
+ received?: number;
55
+ total?: number;
56
+ resumable?: boolean;
44
57
  }
45
58
  export interface CarrierNodeOptions {
46
59
  keyFile: string;
@@ -122,6 +135,14 @@ export declare class CarrierNode extends EventEmitter {
122
135
  * earns a "sent" checkmark. Older SDKs resolve void: report "accepted"
123
136
  * (bytes out, delivery unproven) rather than inventing a confirmation. */
124
137
  sendInlineFile(userid: string, data: Uint8Array, name: string): Promise<"acked" | "accepted" | "offline">;
138
+ /** Whether this SDK can park a file on Express (peer >= 0.1.176). Whether
139
+ * an Express node answers is only known when the post is tried. */
140
+ canSendFileViaExpress(): boolean;
141
+ /** Park a file on Express for an offline friend. Throws when the SDK cannot,
142
+ * the message is over 5 MiB, there is no Express node, or the post fails. */
143
+ sendFileViaExpress(userid: string, data: Uint8Array, name: string): Promise<{
144
+ fileId: string;
145
+ }>;
125
146
  /** True when the friend is a NATIVE Carrier client (iOS/Android/C): it can
126
147
  * only receive files as the inline envelope — a toxcore sendFile offer is
127
148
  * invisible to it and would hang at "sending" until the 60s give-up. */
@@ -43,7 +43,9 @@ export class CarrierNode extends EventEmitter {
43
43
  compatibilityMode: "legacy",
44
44
  bootstrapNodes: opts.bootstrapNodes,
45
45
  expressNodes: opts.expressNodes,
46
- nickname: opts.nickname,
46
+ // No name set yet: advertise none, not the SDK's default
47
+ // "@decentnetwork/peer" (the phones show that as the friend's name).
48
+ nickname: opts.nickname ?? "",
47
49
  statusMessage: opts.statusMessage,
48
50
  punkId: opts.punkId,
49
51
  fileResumeDir: opts.fileResumeDir,
@@ -227,6 +229,20 @@ export class CarrierNode extends EventEmitter {
227
229
  const r = await peer.sendInlineFile(userid, { name, data });
228
230
  return (r && typeof r === "object" ? r.delivery : undefined) ?? "accepted";
229
231
  }
232
+ /** Whether this SDK can park a file on Express (peer >= 0.1.176). Whether
233
+ * an Express node answers is only known when the post is tried. */
234
+ canSendFileViaExpress() {
235
+ return typeof this.#peer?.sendFileViaExpress === "function";
236
+ }
237
+ /** Park a file on Express for an offline friend. Throws when the SDK cannot,
238
+ * the message is over 5 MiB, there is no Express node, or the post fails. */
239
+ async sendFileViaExpress(userid, data, name) {
240
+ const peer = this.#require();
241
+ if (!peer.sendFileViaExpress)
242
+ throw new Error("This peer SDK build cannot send files through Express (needs >= 0.1.176)");
243
+ const r = await peer.sendFileViaExpress(userid, { name, data });
244
+ return { fileId: r.fileId };
245
+ }
230
246
  /** True when the friend is a NATIVE Carrier client (iOS/Android/C): it can
231
247
  * only receive files as the inline envelope — a toxcore sendFile offer is
232
248
  * invisible to it and would hang at "sending" until the 60s give-up. */
@@ -1,4 +1,4 @@
1
- window.__DK_UI_VERSION="0.1.138";
1
+ window.__DK_UI_VERSION="0.1.143";
2
2
  "use strict";
3
3
  (() => {
4
4
  // packages/beagle-ui/dist/beagle-ui.js
@@ -1879,6 +1879,114 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
1879
1879
  function isGreetingItem(m) {
1880
1880
  return !!m && m.kind === GREETING_KIND;
1881
1881
  }
1882
+ var nextId = 1;
1883
+ function createFileSendQueue({ onChange, onFinish } = {}) {
1884
+ let items = [];
1885
+ let running = false;
1886
+ const view = () => items.map(({ file, sender, ...rest }) => ({ ...rest }));
1887
+ const emit = () => {
1888
+ if (onChange)
1889
+ onChange(view());
1890
+ };
1891
+ async function run() {
1892
+ running = true;
1893
+ for (; ; ) {
1894
+ const it = items.find((x) => x.status === "waiting");
1895
+ if (!it)
1896
+ break;
1897
+ it.status = "sending";
1898
+ it.pct = 0;
1899
+ emit();
1900
+ const onProgress = (p) => {
1901
+ if (!p || it.status !== "sending")
1902
+ return;
1903
+ if (p.pct != null)
1904
+ it.pct = p.pct;
1905
+ if (p.sent != null)
1906
+ it.sent = p.sent;
1907
+ if (p.size)
1908
+ it.size = p.size;
1909
+ if (p.kbps != null)
1910
+ it.kbps = p.kbps;
1911
+ emit();
1912
+ };
1913
+ try {
1914
+ const r = await it.sender(it.file, onProgress);
1915
+ if (r && r.ok === false) {
1916
+ it.status = "failed";
1917
+ it.error = r.error && String(r.error) || "send failed";
1918
+ } else {
1919
+ it.status = "sent";
1920
+ it.pct = 100;
1921
+ }
1922
+ } catch (e) {
1923
+ it.status = "failed";
1924
+ it.error = e && e.message || String(e);
1925
+ }
1926
+ emit();
1927
+ }
1928
+ const done = view();
1929
+ items = [];
1930
+ running = false;
1931
+ emit();
1932
+ if (onFinish)
1933
+ onFinish(done);
1934
+ }
1935
+ return {
1936
+ /** Queue every file in `files` (a FileList or an array) for `sender`.
1937
+ * `meta` (`via`, `peerId`) rides on each item for the UI. The FileList
1938
+ * is copied now: the caller clears its <input> right after. */
1939
+ add(files, sender, meta = {}) {
1940
+ const list = Array.from(files || []).filter(Boolean);
1941
+ if (!list.length || typeof sender !== "function")
1942
+ return 0;
1943
+ for (const file of list) {
1944
+ items.push({
1945
+ id: nextId++,
1946
+ name: file.name || "file",
1947
+ size: file.size || 0,
1948
+ sent: 0,
1949
+ pct: null,
1950
+ kbps: null,
1951
+ status: "waiting",
1952
+ error: null,
1953
+ via: meta.via,
1954
+ peerId: meta.peerId,
1955
+ file,
1956
+ sender
1957
+ });
1958
+ }
1959
+ emit();
1960
+ if (!running)
1961
+ run();
1962
+ return list.length;
1963
+ },
1964
+ get running() {
1965
+ return running;
1966
+ },
1967
+ get items() {
1968
+ return view();
1969
+ }
1970
+ };
1971
+ }
1972
+ function failureReport(done, lang) {
1973
+ const failed = (done || []).filter((x) => x.status === "failed");
1974
+ if (!failed.length)
1975
+ return null;
1976
+ const zh = lang === "zh";
1977
+ if (done.length === 1)
1978
+ return (zh ? "\u53D1\u9001\u5931\u8D25: " : "Send failed: ") + (failed[0].error || "");
1979
+ const head = zh ? `${done.length} \u4E2A\u6587\u4EF6\u4E2D\u6709 ${failed.length} \u4E2A\u6CA1\u6709\u53D1\u9001:` : `${failed.length} of ${done.length} files did not send:`;
1980
+ return head + "\n\n" + failed.map((x) => `\u2022 ${x.name} \u2014 ${x.error || (zh ? "\u53D1\u9001\u5931\u8D25" : "send failed")}`).join("\n");
1981
+ }
1982
+ function successFlash(done, lang) {
1983
+ const n = (done || []).length;
1984
+ const zh = lang === "zh";
1985
+ const rtc = n > 0 && done.every((x) => x.via === "webrtc");
1986
+ if (n <= 1)
1987
+ return rtc ? zh ? "WebRTC \u6587\u4EF6\u53D1\u9001\u5B8C\u6210" : "WebRTC file sent" : zh ? "\u6587\u4EF6\u5DF2\u63D0\u4EA4\u53D1\u9001" : "File send started";
1988
+ return rtc ? zh ? `\u5DF2\u901A\u8FC7 WebRTC \u53D1\u9001 ${n} \u4E2A\u6587\u4EF6` : `${n} files sent via WebRTC` : zh ? `\u5DF2\u63D0\u4EA4\u53D1\u9001 ${n} \u4E2A\u6587\u4EF6` : `${n} file sends started`;
1989
+ }
1882
1990
  var PROOF_KEY = { eth: "proof.eth", sol: "proof.sol" };
1883
1991
  var HEAD = "Beagle wallet binding";
1884
1992
  var LINE = "I bind this wallet to my Beagle identity.";
@@ -2038,6 +2146,120 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2038
2146
  const action = friend ? "chat" : address ? isGroup ? "join" : "add" : null;
2039
2147
  return { userid, address, isGroup, friend, action };
2040
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
+ }
2041
2263
  var DK_CMD_HIST_KEY = "beagle.assistant.history";
2042
2264
  var DK_CMD_HIST_MAX = 50;
2043
2265
  function RequestsBlock({ T, requests, onAct }) {
@@ -2448,6 +2670,9 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2448
2670
  return card;
2449
2671
  const s = String(text == null ? "" : text);
2450
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);
2451
2676
  const cgp = dkParseCGP1(s.replace(/^you:\s*/i, ""));
2452
2677
  if (cgp)
2453
2678
  return (mine ? "you: " : "") + cgp.sender + ": " + (cgp.file ? fileLabel(cgp.file, T) : cgp.body.replace(/\s+/g, " "));
@@ -2555,31 +2780,6 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2555
2780
  }
2556
2781
  return html || dkHtmlEscape(src);
2557
2782
  }
2558
- var DK_NATIVE_MEDIA_MIME = {
2559
- ".jpg": "image/jpeg",
2560
- ".jpeg": "image/jpeg",
2561
- ".png": "image/png",
2562
- ".gif": "image/gif",
2563
- ".webp": "image/webp",
2564
- ".heic": "image/heic",
2565
- ".m4a": "audio/mp4",
2566
- ".aac": "audio/aac",
2567
- ".mp3": "audio/mpeg",
2568
- ".wav": "audio/wav",
2569
- ".caf": "audio/x-caf",
2570
- ".mp4": "video/mp4",
2571
- ".mov": "video/quicktime",
2572
- ".m4v": "video/x-m4v"
2573
- };
2574
- var DK_GROUP_TS_RE = /\n?\[(20\d{2}-\d{1,2}-\d{1,2}\s+\d{1,2}:\d{2}:\d{2})\]\s*$/;
2575
- function dkStripGroupTs(text) {
2576
- const m = DK_GROUP_TS_RE.exec(text);
2577
- return m ? { body: text.slice(0, m.index), ts: m[1] } : { body: text, ts: null };
2578
- }
2579
- function dkSplitGroupSender(text) {
2580
- const m = /^([^:\n]{1,48}):\s([\s\S]+)$/.exec(text);
2581
- return m ? { sender: m[1], body: m[2] } : null;
2582
- }
2583
2783
  function dkParseCGP1(text) {
2584
2784
  const t = String(text || "").trim();
2585
2785
  if (!t.startsWith("CGP1 "))
@@ -2604,8 +2804,8 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2604
2804
  if (cgp)
2605
2805
  return cgp;
2606
2806
  const t = String(text || "");
2607
- const { body: noTs, ts } = dkStripGroupTs(t);
2608
- const split = dkSplitGroupSender(noTs.trim());
2807
+ const { body: noTs, ts } = stripGroupTs(t);
2808
+ const split = splitGroupSender(noTs.trim());
2609
2809
  if (!split)
2610
2810
  return null;
2611
2811
  return { sender: split.sender, senderId: null, body: split.body.trim(), ts, strong: !!ts };
@@ -2691,36 +2891,6 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2691
2891
  function dkThreadIsGroup(thread) {
2692
2892
  return (thread || []).some((m) => !m.day && m.dir !== "out" && !m.file && (dkGroupParse(m.text) || {}).strong);
2693
2893
  }
2694
- function dkNativeMediaFromText(text) {
2695
- let body = dkStripGroupTs(String(text || "")).body.trim();
2696
- if (body.length < 32)
2697
- return null;
2698
- let sender = null;
2699
- if (!body.startsWith("{")) {
2700
- const split = dkSplitGroupSender(body);
2701
- if (!split || !split.body.startsWith("{"))
2702
- return null;
2703
- sender = split.sender;
2704
- body = split.body.trim();
2705
- }
2706
- if (!body.startsWith("{") || !body.endsWith("}"))
2707
- return null;
2708
- let j = null;
2709
- try {
2710
- j = JSON.parse(body);
2711
- } catch (e) {
2712
- return null;
2713
- }
2714
- if (!j || typeof j !== "object" || typeof j.data !== "string" || j.data.length < 16)
2715
- return null;
2716
- const kind = j.type === "image" ? "image" : j.type === "audio" || j.type === "voice" ? "audio" : j.type === "video" ? "video" : null;
2717
- if (!kind)
2718
- return null;
2719
- const ext = String(j.fileExtension || "").toLowerCase();
2720
- const mime = DK_NATIVE_MEDIA_MIME[ext] || kind + "/*";
2721
- const name = String(j.fileName || "file") + ext;
2722
- return { sender, kind, name, url: "data:" + mime + ";base64," + j.data.replace(/\s+/g, "") };
2723
- }
2724
2894
  function MarkdownText({ text, onNameCard }) {
2725
2895
  const onClick = (e) => {
2726
2896
  const a = e.target && e.target.closest && e.target.closest("a");
@@ -2948,10 +3118,10 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
2948
3118
  }
2949
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 }) {
2950
3120
  const mine = m.from === "me";
2951
- const nativeMedia = !m.file ? dkNativeMediaFromText(m.text) : null;
3121
+ const nativeMedia = !m.file ? nativeMediaFromText(m.text) : null;
2952
3122
  const grp = isGroup && m.dir !== "out" && !m.file && !nativeMedia ? dkGroupParse(m.text) : null;
2953
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;
2954
- 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);
2955
3125
  const read = window.ChatComponents ? window.ChatComponents.readMessage((grp ? grp.body : m.text) || "") : { text: grp ? grp.body : m.text, form: null, interaction: null };
2956
3126
  const submitted = read.form && answered ? answered.get(read.form.custom_id) : null;
2957
3127
  const rtcFile = !mine && !m.file ? dkRtcFileFromText(peer.userId || peer.id, m.text) : null;
@@ -3145,7 +3315,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
3145
3315
  cursor: mine ? "default" : "pointer"
3146
3316
  };
3147
3317
  const icon = /* @__PURE__ */ React.createElement("div", { style: { width: 34, height: 34, borderRadius: 7, flexShrink: 0, background: mine ? "rgba(255,255,255,0.16)" : "var(--chip)", display: "flex", alignItems: "center", justifyContent: "center", color: mine ? "#fff" : "var(--accent)" } }, /* @__PURE__ */ React.createElement(Icon, { name: m.file.media === "image" ? "image" : m.file.media === "video" ? "video" : m.file.media === "audio" ? "play" : "file", size: 18, stroke: 1.9 }));
3148
- const meta = /* @__PURE__ */ React.createElement("div", { style: { minWidth: 0, flex: 1 } }, /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 12.5, fontWeight: 600, color: mine ? "#fff" : "var(--text)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, m.file.name), /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 11, color: mine ? "rgba(255,255,255,0.7)" : "var(--faint)", marginTop: 1 } }, busy === "cancel" ? `${m.file.size} \xB7 ${T.cancelling || "Cancelling\u2026"}` : busy === "retry" ? `${m.file.size} \xB7 ${T.retrying || "Retrying\u2026"}` : m.file.status === "queued" ? `${m.file.size} \xB7 ${T.queued || "queued"}` : m.file.status === "sending" ? `${m.file.size} \xB7 ${dkPct(m.file.pct)}${m.file.kbps ? " \xB7 " + dkSpeed(m.file.kbps) : ""}` : m.file.status === "failed" ? `${m.file.size} \xB7 failed` : m.file.status === "cancelled" ? `${m.file.size} \xB7 ${T.cancelled || "cancelled"}` : mine ? `${m.file.size} \xB7 sent` : `${m.file.size} \xB7 ${T.open || "open"}`));
3318
+ const meta = /* @__PURE__ */ React.createElement("div", { style: { minWidth: 0, flex: 1 } }, /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 12.5, fontWeight: 600, color: mine ? "#fff" : "var(--text)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, m.file.name), /* @__PURE__ */ React.createElement("div", { style: { fontFamily: "var(--mono)", fontSize: 11, color: mine ? "rgba(255,255,255,0.7)" : "var(--faint)", marginTop: 1 } }, busy === "cancel" ? `${m.file.size} \xB7 ${T.cancelling || "Cancelling\u2026"}` : busy === "retry" ? `${m.file.size} \xB7 ${T.retrying || "Retrying\u2026"}` : m.file.status === "queued" ? `${m.file.size} \xB7 ${mine ? T.fileWaitsHere || "waits on this computer until they are online" : T.queued || "queued"}` : m.file.status === "sending" ? `${m.file.size} \xB7 ${dkPct(m.file.pct)}${m.file.kbps ? " \xB7 " + dkSpeed(m.file.kbps) : ""}` : m.file.status === "failed" ? `${m.file.size} \xB7 failed` : m.file.status === "cancelled" ? `${m.file.size} \xB7 ${T.cancelled || "cancelled"}` : mine && m.via === "offline" ? `${m.file.size} \xB7 ${T.fileOnExpress || "offline \xB7 stored on Express"}` : mine ? `${m.file.size} \xB7 sent` : `${m.file.size} \xB7 ${T.open || "open"}`));
3149
3319
  if (mine) {
3150
3320
  const btnBusy = !!busy;
3151
3321
  return /* @__PURE__ */ React.createElement(
@@ -3180,7 +3350,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
3180
3350
  },
3181
3351
  /* @__PURE__ */ React.createElement(Icon, { name: "download", size: 15, stroke: 2, color: "rgba(255,255,255,0.85)" })
3182
3352
  ),
3183
- busy === "cancel" || busy === "retry" ? /* @__PURE__ */ React.createElement(Icon, { name: "clock", size: 16, stroke: 2, color: "rgba(255,255,255,0.85)" }) : m.file.status === "queued" ? /* @__PURE__ */ React.createElement(Icon, { name: "clock", size: 16, stroke: 2, color: "rgba(255,255,255,0.85)" }) : m.file.status === "sending" ? /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 11, fontWeight: 700, color: "rgba(255,255,255,0.9)", whiteSpace: "nowrap" } }, dkPct(m.file.pct), m.file.kbps ? " \xB7 " + dkSpeed(m.file.kbps) : "") : m.file.status === "failed" || m.file.status === "cancelled" ? /* @__PURE__ */ React.createElement(Icon, { name: "x", size: 16, stroke: 2.4, color: "rgba(255,200,190,0.95)" }) : /* @__PURE__ */ React.createElement(Icon, { name: "checkCheck", size: 16, stroke: 2, color: "rgba(255,255,255,0.85)" }),
3353
+ busy === "cancel" || busy === "retry" ? /* @__PURE__ */ React.createElement(Icon, { name: "clock", size: 16, stroke: 2, color: "rgba(255,255,255,0.85)" }) : m.file.status === "queued" ? /* @__PURE__ */ React.createElement(Icon, { name: "clock", size: 16, stroke: 2, color: "rgba(255,255,255,0.85)" }) : m.file.status === "sending" ? /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 11, fontWeight: 700, color: "rgba(255,255,255,0.9)", whiteSpace: "nowrap" } }, dkPct(m.file.pct), m.file.kbps ? " \xB7 " + dkSpeed(m.file.kbps) : "") : m.file.status === "failed" || m.file.status === "cancelled" ? /* @__PURE__ */ React.createElement(Icon, { name: "x", size: 16, stroke: 2.4, color: "rgba(255,200,190,0.95)" }) : m.via === "offline" ? /* @__PURE__ */ React.createElement(Icon, { name: "check", size: 16, stroke: 2, color: "rgba(255,255,255,0.85)" }) : /* @__PURE__ */ React.createElement(Icon, { name: "checkCheck", size: 16, stroke: 2, color: "rgba(255,255,255,0.85)" }),
3184
3354
  (m.file.status === "sending" || m.file.status === "queued" || busy === "cancel") && m.id && /* @__PURE__ */ React.createElement(
3185
3355
  "button",
3186
3356
  {
@@ -3245,7 +3415,18 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
3245
3415
  )
3246
3416
  );
3247
3417
  })()
3248
- ) : 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.kind === "image" ? /* @__PURE__ */ React.createElement(
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(
3249
3430
  "img",
3250
3431
  {
3251
3432
  src: nativeMedia.url,
@@ -3260,7 +3441,28 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
3260
3441
  }
3261
3442
  }
3262
3443
  }
3263
- ) : 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)" } })) : 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" })) : (() => {
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" })) : (() => {
3264
3466
  const contact = !read.form ? dkParseBeagleContact(read.text) : null;
3265
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: {
3266
3468
  padding: "8px 12px",
@@ -3280,7 +3482,8 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
3280
3482
  wordBreak: "break-word"
3281
3483
  } }, /* @__PURE__ */ React.createElement(MarkdownText, { text: read.text, onNameCard })));
3282
3484
  })(), read.form && /* @__PURE__ */ React.createElement("div", { style: { marginTop: 6 } }, /* @__PURE__ */ React.createElement(DkChatForm, { form: read.form, submitted, peer, onSubmit: onFormSubmit })), m.assistant && onAssistantRemove && /* @__PURE__ */ React.createElement(AssistantPanel, { m, T, lang, onRemove: onAssistantRemove, onAdopt: onAssistantAdopt }), /* @__PURE__ */ React.createElement("div", { style: { display: "flex", alignItems: "center", gap: 4, margin: "3px 3px 0" } }, /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 10, color: "var(--faint)" } }, m.time), (() => {
3283
- const sentDone = mine && m.status && m.status !== "queued" && m.status !== "sending" && m.status !== "failed";
3485
+ const st = m.file ? m.file.status : m.status;
3486
+ const sentDone = mine && st && st !== "queued" && st !== "sending" && st !== "failed" && st !== "cancelled";
3284
3487
  const via = !mine ? m.via : sentDone ? m.via === "offline" ? "offline" : "online" : null;
3285
3488
  if (!via)
3286
3489
  return null;
@@ -3297,7 +3500,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
3297
3500
  style: { background: "none", border: "none", cursor: "pointer", padding: 0, marginLeft: 2, display: "inline-flex", opacity: 0.55 }
3298
3501
  },
3299
3502
  /* @__PURE__ */ React.createElement(Icon, { name: "trash", size: 11, stroke: 2, color: "var(--faint)" })
3300
- ), mine && m.status === "failed" ? (
3503
+ ), mine && m.file && ["queued", "sending", "failed", "cancelled"].includes(m.file.status) ? null : mine && m.status === "failed" ? (
3301
3504
  /* Not delivered. Says so, and one tap tries again — silently
3302
3505
  rendering this as a sent message is how a chat loses mail. */
3303
3506
  /* @__PURE__ */ React.createElement(
@@ -3629,30 +3832,30 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
3629
3832
  requestAnimationFrame(scrollToBottom);
3630
3833
  }
3631
3834
  };
3835
+ const finishRef = React.useRef(null);
3836
+ finishRef.current = (done) => {
3837
+ const report = failureReport(done, lang);
3838
+ if (report)
3839
+ window.alert(report);
3840
+ else
3841
+ showFlash("ok", successFlash(done, lang));
3842
+ requestAnimationFrame(scrollToBottom);
3843
+ };
3844
+ const queueRef = React.useRef(null);
3845
+ if (!queueRef.current) {
3846
+ queueRef.current = createFileSendQueue({
3847
+ onChange: (items) => setSending(items.length ? items : null),
3848
+ onFinish: (done) => finishRef.current && finishRef.current(done)
3849
+ });
3850
+ }
3632
3851
  const sendFiles = (files, mode) => {
3633
3852
  const sender = mode === "webrtc" ? onSendRtcFile : onSendFile;
3634
3853
  if (!files || !files.length || !sender)
3635
3854
  return;
3636
- const file = files[0];
3637
3855
  followScrollRef.current = true;
3638
- setSending({ name: file.name, via: mode, pct: 0, sent: 0, size: file.size });
3639
- const onProgress = (p) => setSending((s) => s && s.name === file.name ? {
3640
- ...s,
3641
- pct: p && p.pct,
3642
- sent: p && p.sent,
3643
- size: p && p.size || s.size,
3644
- kbps: p && p.kbps
3645
- } : s);
3646
- Promise.resolve(sender(file, onProgress)).then((r) => {
3647
- if (r && r.ok === false)
3648
- window.alert((lang === "zh" ? "\u53D1\u9001\u5931\u8D25: " : "Send failed: ") + (r.error || ""));
3649
- else
3650
- showFlash("ok", mode === "webrtc" ? lang === "zh" ? "WebRTC \u6587\u4EF6\u53D1\u9001\u5B8C\u6210" : "WebRTC file sent" : lang === "zh" ? "\u6587\u4EF6\u5DF2\u63D0\u4EA4\u53D1\u9001" : "File send started");
3651
- }).finally(() => {
3652
- setSending(null);
3653
- requestAnimationFrame(scrollToBottom);
3654
- });
3856
+ queueRef.current.add(files, sender, { via: mode, peerId: peer.id });
3655
3857
  };
3858
+ const mySending = sending ? sending.filter((s) => s.peerId === peer.id) : [];
3656
3859
  const onDrop = (e) => {
3657
3860
  e.preventDefault();
3658
3861
  setDragOver(false);
@@ -3673,7 +3876,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
3673
3876
  },
3674
3877
  onDrop
3675
3878
  },
3676
- dragOver && /* @__PURE__ */ React.createElement("div", { style: { position: "absolute", inset: 0, zIndex: 30, background: "rgba(91,140,255,0.10)", border: "2px dashed var(--accent)", borderRadius: 12, display: "flex", alignItems: "center", justifyContent: "center", pointerEvents: "none", fontFamily: "var(--mono)", fontSize: 14, color: "var(--accent)" } }, lang === "zh" ? "\u677E\u5F00\u53D1\u9001\u6587\u4EF6" : "Drop to send file"),
3879
+ dragOver && /* @__PURE__ */ React.createElement("div", { style: { position: "absolute", inset: 0, zIndex: 30, background: "rgba(91,140,255,0.10)", border: "2px dashed var(--accent)", borderRadius: 12, display: "flex", alignItems: "center", justifyContent: "center", pointerEvents: "none", fontFamily: "var(--mono)", fontSize: 14, color: "var(--accent)" } }, lang === "zh" ? "\u677E\u5F00\u53D1\u9001\u6587\u4EF6" : "Drop to send files"),
3677
3880
  /* @__PURE__ */ React.createElement("div", { style: { height: phone ? 56 : 60, boxSizing: "content-box", paddingTop: phone ? "env(safe-area-inset-top, 0px)" : 0, flexShrink: 0, borderBottom: "1px solid var(--line)", display: "flex", alignItems: "center", gap: phone ? 8 : 12, paddingLeft: phone ? 4 : 16, paddingRight: phone ? 8 : 16, background: "var(--panel)" } }, phone && onBack && /* @__PURE__ */ React.createElement(
3678
3881
  "button",
3679
3882
  {
@@ -3710,6 +3913,7 @@ ${peer.address}`
3710
3913
  {
3711
3914
  ref: rtcFileRef,
3712
3915
  type: "file",
3916
+ multiple: true,
3713
3917
  style: { display: "none" },
3714
3918
  onChange: (e) => {
3715
3919
  sendFiles(e.target.files, "webrtc");
@@ -3803,11 +4007,20 @@ ${peer.address}`
3803
4007
  stroke: 2.2,
3804
4008
  color: flash.kind === "err" ? "var(--danger)" : "var(--accent)"
3805
4009
  }
3806
- ), flash.msg), sending && /* @__PURE__ */ React.createElement("div", { style: { maxWidth: 1200, margin: "0 auto 8px", display: "flex", alignItems: "center", gap: 8, fontFamily: "var(--mono)", fontSize: 11.5, color: "var(--faint)" } }, /* @__PURE__ */ React.createElement(Icon, { name: "paperclip", size: 13, stroke: 2, color: "var(--accent)" }), (lang === "zh" ? "\u53D1\u9001\u4E2D: " : "Sending: ") + (sending.via === "webrtc" ? "WebRTC \xB7 " : "") + sending.name + (sending.size ? " \xB7 " + dkFileSize(sending.sent || 0) + " / " + dkFileSize(sending.size) : "") + (sending.pct != null ? " \xB7 " + Math.min(100, Math.max(0, sending.pct)).toFixed(1) + "%" : "") + (sending.kbps != null ? " \xB7 " + dkSpeed(sending.kbps) : "")), /* @__PURE__ */ React.createElement("div", { style: { maxWidth: 1200, margin: "0 auto", display: "flex", alignItems: "center", gap: phone ? 6 : 10 } }, /* @__PURE__ */ React.createElement(
4010
+ ), flash.msg), mySending.length > 0 && /* @__PURE__ */ React.createElement("div", { "data-testid": "file-send-queue", style: { maxWidth: 1200, margin: "0 auto 8px", display: "flex", flexDirection: "column", gap: 3, fontFamily: "var(--mono)", fontSize: 11.5, color: "var(--faint)", maxHeight: 132, overflowY: "auto" } }, mySending.length > 1 && /* @__PURE__ */ React.createElement("div", { style: { color: "var(--dim)" } }, (lang === "zh" ? "\u53D1\u9001 " : "Sending ") + mySending.filter((s) => s.status === "sent" || s.status === "failed").length + " / " + mySending.length + (lang === "zh" ? " \u4E2A\u6587\u4EF6" : " files")), mySending.map((s) => /* @__PURE__ */ React.createElement("div", { key: s.id, "data-status": s.status, style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0, color: s.status === "failed" ? "var(--danger)" : void 0 } }, /* @__PURE__ */ React.createElement(
4011
+ Icon,
4012
+ {
4013
+ name: s.status === "sent" ? "check" : s.status === "failed" ? "x" : "paperclip",
4014
+ size: 13,
4015
+ stroke: 2,
4016
+ color: s.status === "failed" ? "var(--danger)" : s.status === "waiting" ? "var(--faint)" : "var(--accent)"
4017
+ }
4018
+ ), /* @__PURE__ */ React.createElement("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", minWidth: 0 } }, (s.status === "sending" ? lang === "zh" ? "\u53D1\u9001\u4E2D: " : "Sending: " : "") + (s.via === "webrtc" ? "WebRTC \xB7 " : "") + s.name + (s.status === "sending" ? (s.size ? " \xB7 " + dkFileSize(s.sent || 0) + " / " + dkFileSize(s.size) : "") + (s.pct != null ? " \xB7 " + Math.min(100, Math.max(0, s.pct)).toFixed(1) + "%" : "") + (s.kbps != null ? " \xB7 " + dkSpeed(s.kbps) : "") : s.status === "waiting" ? " \xB7 " + (s.size ? dkFileSize(s.size) + " \xB7 " : "") + (lang === "zh" ? "\u7B49\u5F85\u4E2D" : "waiting") : s.status === "failed" ? " \xB7 " + (s.error || "") : " \xB7 " + (lang === "zh" ? "\u5DF2\u63D0\u4EA4" : "done")))))), /* @__PURE__ */ React.createElement("div", { style: { maxWidth: 1200, margin: "0 auto", display: "flex", alignItems: "center", gap: phone ? 6 : 10 } }, /* @__PURE__ */ React.createElement(
3807
4019
  "input",
3808
4020
  {
3809
4021
  ref: fileRef,
3810
4022
  type: "file",
4023
+ multiple: true,
3811
4024
  style: { display: "none" },
3812
4025
  onChange: (e) => {
3813
4026
  sendFiles(e.target.files);
@@ -7180,6 +7393,8 @@ ${peer.address}`
7180
7393
  message: "Message",
7181
7394
  send: "Send",
7182
7395
  pickPeer: "Select a peer to open the conversation",
7396
+ fileWaitsHere: "waits on this computer until they are online",
7397
+ fileOnExpress: "offline \xB7 stored on Express",
7183
7398
  queued: "queued",
7184
7399
  sendingMsg: "sending",
7185
7400
  groupTag: "group",
@@ -7408,6 +7623,8 @@ ${peer.address}`
7408
7623
  message: "\u6D88\u606F",
7409
7624
  send: "\u53D1\u9001",
7410
7625
  pickPeer: "\u9009\u62E9\u4E00\u4F4D\u597D\u53CB\u5F00\u59CB\u4F1A\u8BDD",
7626
+ fileWaitsHere: "\u5728\u672C\u673A\u7B49\u5F85,\u597D\u53CB\u4E0A\u7EBF\u540E\u53D1\u9001",
7627
+ fileOnExpress: "\u79BB\u7EBF \xB7 \u5DF2\u5B58\u5230 Express",
7411
7628
  queued: "\u5F85\u53D1\u9001",
7412
7629
  sendingMsg: "\u53D1\u9001\u4E2D",
7413
7630
  groupTag: "\u7FA4",
@@ -1,5 +1,12 @@
1
+ import { CarrierNode } from "./carrier-node.js";
1
2
  import type { IpcRequest, IpcResponse } from "./ipc.js";
2
3
  import type { PeerHost } from "./peer-host.js";
4
+ /** What a sending-side `file-cancel` means (peer's `onFileCancel` reasons):
5
+ * none = the friend's KILL, they declined it → "cancelled"; "local" = our own
6
+ * cancelSend, the caller sets the row; anything else ("no-response",
7
+ * "timeout", "peer-offline", or a reason a later peer adds) = the SDK gave up
8
+ * on the path → the file is still owed (#liveDeliveryGaveUp). */
9
+ export declare function liveCancelMeaning(reason: string | undefined): "declined" | "ours" | "gave-up";
3
10
  export interface EmbeddedHostOptions {
4
11
  configDir: string;
5
12
  keyFile: string;
@@ -30,6 +37,12 @@ export interface EmbeddedHostOptions {
30
37
  /** @decentnetwork/peer version backing this embedded node, surfaced by `ping`
31
38
  * so the panel can name the code that is actually running. */
32
39
  peerVersion?: string;
40
+ /** Tests only: a CarrierNode stand-in, a shorter offer window, a shorter
41
+ * first re-offer backoff, and a shorter no-progress give-up. */
42
+ node?: CarrierNode;
43
+ offerWindowMs?: number;
44
+ liveRetryBaseMs?: number;
45
+ liveStallMs?: number;
33
46
  }
34
47
  export declare class EmbeddedHost implements PeerHost {
35
48
  #private;