@ghostlytools/cli 1.5.2 → 1.5.3

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 (101) hide show
  1. package/README.md +16 -11
  2. package/dist/assets/{api-CHD8_kcJ.js → api-BIg0Msax.js} +2 -2
  3. package/dist/assets/{api-CMohP9Pw.js → api-d2aXkbM5.js} +341 -114
  4. package/dist/assets/api-d2aXkbM5.js.map +1 -0
  5. package/dist/assets/{apiKit-CfwVtBcw.js → apiKit-Ba_t7MZO.js} +4 -4
  6. package/dist/assets/apiKit-Ba_t7MZO.js.map +1 -0
  7. package/dist/assets/{apps-733nXRBy.js → apps-B_F3gEI4.js} +1 -1
  8. package/dist/assets/{apps-LG-QOIxs.js → apps-CJo1MmSY.js} +17 -16
  9. package/dist/assets/apps-CJo1MmSY.js.map +1 -0
  10. package/dist/assets/{arkade-C8x3Efyj.js → arkade-DTne0O3Q.js} +12 -5
  11. package/dist/assets/arkade-DTne0O3Q.js.map +1 -0
  12. package/dist/assets/{backup-CfJenOQo.js → backup-BY88aZr5.js} +11 -8
  13. package/dist/assets/backup-BY88aZr5.js.map +1 -0
  14. package/dist/assets/{backup-nCbNWJ7-.js → backup-CqpDAZZG.js} +1 -1
  15. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
  16. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  17. package/dist/assets/{blobFiles-1wUBd8ZD.js → blobFiles-B1lX6iGy.js} +3 -3
  18. package/dist/assets/{blobFiles-1wUBd8ZD.js.map → blobFiles-B1lX6iGy.js.map} +1 -1
  19. package/dist/assets/{buttons-BC0stvPg.js → buttons-B5EnA2nh.js} +23 -6
  20. package/dist/assets/buttons-B5EnA2nh.js.map +1 -0
  21. package/dist/assets/buttons-azvbN6xn.js +2 -0
  22. package/dist/assets/{daemonProof-CWTVNUmr.js → daemonProof-Dx3N_DLC.js} +19 -37
  23. package/dist/assets/daemonProof-Dx3N_DLC.js.map +1 -0
  24. package/dist/assets/{endpoint-Cl3cgAYl.js → endpoint-BdaeBw2L.js} +3 -3
  25. package/dist/assets/endpoint-BdaeBw2L.js.map +1 -0
  26. package/dist/assets/{envelope-BbvUBjc5.js → envelope-BU-BB1wR.js} +2 -2
  27. package/dist/assets/{envelope-BbvUBjc5.js.map → envelope-BU-BB1wR.js.map} +1 -1
  28. package/dist/assets/{errors-BLSPp0tK.js → errors-DI6Z3jTH.js} +26 -1
  29. package/dist/assets/errors-DI6Z3jTH.js.map +1 -0
  30. package/dist/assets/{fileBytes-gTd_8l-P.js → fileBytes-BMlLVdfg.js} +1 -1
  31. package/dist/assets/{fileBytes-uRqLyxa0.js → fileBytes-D0CYuRwZ.js} +2 -2
  32. package/dist/assets/{fileBytes-uRqLyxa0.js.map → fileBytes-D0CYuRwZ.js.map} +1 -1
  33. package/dist/assets/{fileBytes-B8eTZfAT.js → fileBytes-D85lBh-Q.js} +3 -3
  34. package/dist/assets/{fileBytes-B8eTZfAT.js.map → fileBytes-D85lBh-Q.js.map} +1 -1
  35. package/dist/assets/fileBytesIdb-Dn9levD1.js +2 -0
  36. package/dist/assets/{fileBytesIdb-BIFKtgln.js → fileBytesIdb-LAhH7kY2.js} +7 -7
  37. package/dist/assets/fileBytesIdb-LAhH7kY2.js.map +1 -0
  38. package/dist/assets/{fileBytesOpfs-ChrHcCVV.js → fileBytesOpfs-DjBBghvq.js} +3 -3
  39. package/dist/assets/{fileBytesOpfs-ChrHcCVV.js.map → fileBytesOpfs-DjBBghvq.js.map} +1 -1
  40. package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js → ghostly_iroh_web-BXCsSxxo.js} +29 -29
  41. package/dist/assets/{ghostly_iroh_web-BsAEFIjl.js.map → ghostly_iroh_web-BXCsSxxo.js.map} +1 -1
  42. package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
  43. package/dist/assets/{groupFiles-Bmo-SkVQ.js → groupFiles-D9k6fyhf.js} +61 -17
  44. package/dist/assets/groupFiles-D9k6fyhf.js.map +1 -0
  45. package/dist/assets/{host-DxDRCRKD.js → host-DrL7FPG4.js} +125 -47
  46. package/dist/assets/host-DrL7FPG4.js.map +1 -0
  47. package/dist/assets/{hyperdhtRelay-CZfsPfT9.js → hyperdhtRelay-C-BsT6_V.js} +2 -2
  48. package/dist/assets/{hyperdhtRelay-CZfsPfT9.js.map → hyperdhtRelay-C-BsT6_V.js.map} +1 -1
  49. package/dist/assets/{idb-BJARz3Qi.js → idb-CWvq4HKc.js} +25 -3
  50. package/dist/assets/{idb-BJARz3Qi.js.map → idb-CWvq4HKc.js.map} +1 -1
  51. package/dist/assets/{irohWeb-BUvaADop.js → irohWeb-DdHXEwgj.js} +3 -3
  52. package/dist/assets/{irohWeb-BUvaADop.js.map → irohWeb-DdHXEwgj.js.map} +1 -1
  53. package/dist/assets/{main-BIXIs84L.js → main-xeoX7yLM.js} +160 -50
  54. package/dist/assets/main-xeoX7yLM.js.map +1 -0
  55. package/dist/assets/{mainline-HQVJ5ukA.js → mainline-CEqGvRYJ.js} +46 -16
  56. package/dist/assets/mainline-CEqGvRYJ.js.map +1 -0
  57. package/dist/assets/{networkReason-CKBiFTwt.js → networkReason-RGRU5xoa.js} +3 -3
  58. package/dist/assets/{networkReason-CKBiFTwt.js.map → networkReason-RGRU5xoa.js.map} +1 -1
  59. package/dist/assets/{nwc-Dm4RSvvF.js → nwc-s5xHLqNf.js} +3 -3
  60. package/dist/assets/{nwc-Dm4RSvvF.js.map → nwc-s5xHLqNf.js.map} +1 -1
  61. package/dist/assets/{nwcProvider-yQdL-DfC.js → nwcProvider-CfAFO5Fr.js} +2 -2
  62. package/dist/assets/{nwcProvider-yQdL-DfC.js.map → nwcProvider-CfAFO5Fr.js.map} +1 -1
  63. package/dist/assets/{profiles-BehWURA9.js → profiles-gZdQPyaz.js} +74 -13
  64. package/dist/assets/profiles-gZdQPyaz.js.map +1 -0
  65. package/dist/assets/{registry-CHVZ0Jzl.js → registry-BUhSjM-J.js} +1 -1
  66. package/dist/assets/{registry-C9f2Ogff.js → registry-CVUdD4bJ.js} +3 -3
  67. package/dist/assets/{registry-C9f2Ogff.js.map → registry-CVUdD4bJ.js.map} +1 -1
  68. package/dist/assets/{resolve-Cqj1jjK2.js → resolve-uZECJ3f7.js} +2 -2
  69. package/dist/assets/{resolve-Cqj1jjK2.js.map → resolve-uZECJ3f7.js.map} +1 -1
  70. package/dist/assets/{restoredRows-DGuKtIBz.js → restoredRows-D6WZUA2U.js} +2 -2
  71. package/dist/assets/{restoredRows-DGuKtIBz.js.map → restoredRows-D6WZUA2U.js.map} +1 -1
  72. package/dist/assets/{server-CcAs54Yb.js → server-DOtUKoYR.js} +776 -248
  73. package/dist/assets/server-DOtUKoYR.js.map +1 -0
  74. package/dist/assets/{src-BLHey3Q1.js → src-Dd_7Ew1X.js} +459 -129
  75. package/dist/assets/src-Dd_7Ew1X.js.map +1 -0
  76. package/dist/assets/{usdt-DMKpMhdM.js → usdt-C2Anx8p7.js} +3 -3
  77. package/dist/assets/{usdt-DMKpMhdM.js.map → usdt-C2Anx8p7.js.map} +1 -1
  78. package/dist/assets/{words-DUlvkoUT.js → words-DoLU6p8H.js} +4 -4
  79. package/dist/assets/words-DoLU6p8H.js.map +1 -0
  80. package/dist/ghostly.mjs +1 -1
  81. package/package.json +1 -1
  82. package/dist/assets/api-CMohP9Pw.js.map +0 -1
  83. package/dist/assets/apiKit-CfwVtBcw.js.map +0 -1
  84. package/dist/assets/apps-LG-QOIxs.js.map +0 -1
  85. package/dist/assets/arkade-C8x3Efyj.js.map +0 -1
  86. package/dist/assets/backup-CfJenOQo.js.map +0 -1
  87. package/dist/assets/buttons-BC0stvPg.js.map +0 -1
  88. package/dist/assets/buttons-BDKeKyKw.js +0 -2
  89. package/dist/assets/daemonProof-CWTVNUmr.js.map +0 -1
  90. package/dist/assets/endpoint-Cl3cgAYl.js.map +0 -1
  91. package/dist/assets/errors-BLSPp0tK.js.map +0 -1
  92. package/dist/assets/fileBytesIdb-BIFKtgln.js.map +0 -1
  93. package/dist/assets/fileBytesIdb-BVVr_rWX.js +0 -2
  94. package/dist/assets/groupFiles-Bmo-SkVQ.js.map +0 -1
  95. package/dist/assets/host-DxDRCRKD.js.map +0 -1
  96. package/dist/assets/main-BIXIs84L.js.map +0 -1
  97. package/dist/assets/mainline-HQVJ5ukA.js.map +0 -1
  98. package/dist/assets/profiles-BehWURA9.js.map +0 -1
  99. package/dist/assets/server-CcAs54Yb.js.map +0 -1
  100. package/dist/assets/src-BLHey3Q1.js.map +0 -1
  101. package/dist/assets/words-DUlvkoUT.js.map +0 -1
@@ -1,15 +1,15 @@
1
- import { Co as GhostlyHttpError, Dc as isAppUrl, Do as LIMITS, Fc as appRef, Gc as readImageMeta, Hi as identityStatement, Ja as appCardId, Ka as STATUS_CARD_LIMITS, Mr as TYPING_REFRESH_MS, Pr as sanitizeTypingStatus, Qa as checkStatusCard, Sc as APP_PERMISSIONS, Un as GROUP_FILE_LIMITS, Xa as cardLine, Y as groupName, _o as AWAITING_PEER_MS, al as inviteLink, au as MAX_AVATAR_LENGTH, ca as PLAYABLE_AUDIO, du as randomBytes$1, ei as APP_DATA_MAX_BYTES, fa as parseVoiceMeta, fu as toBase64Url, jr as TYPING_KINDS, la as VOICE_LIMITS, ma as voicePeaksOf, oa as sanitizeFileName, ou as sanitizeAvatar, pa as voiceDownloadName, sa as sanitizeMime, sl as ownInviteRefusal, ua as baseMime, zc as isAppRef } from "./src-BLHey3Q1.js";
2
- import { l as fileStore } from "./idb-BJARz3Qi.js";
3
- import { O as waitingGroupFile, T as removeStored, U as iceServerProblem, W as iceServerSetting, i as groupOfFile, l as replyRef, n as groupFileId, v as paymentNetwork } from "./groupFiles-Bmo-SkVQ.js";
4
- import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-B8eTZfAT.js";
5
- import { t as IDENTITY_PROVIDERS } from "./registry-C9f2Ogff.js";
6
- import { a as waitForEdit, c as findSecret, i as pressable, n as buttonsCard, o as waitForGroupFrame, s as waitForMessage, t as BUTTON_METHODS } from "./buttons-BC0stvPg.js";
7
- import { a as WALLET_TYPES, c as DESTRUCTIVE_CALLS, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, m as engineParamsProblem, n as CHAT_METHODS, r as PAY_METHODS, s as withStoredIds, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-DUlvkoUT.js";
8
- import { i as localFileError, r as asCliError, t as CliError } from "./errors-BLSPp0tK.js";
9
- import { _ as state, a as findChat, d as list, f as messageOf, g as sentAt, h as oneOf, i as chatOrGroup, l as groupOf, m as num, n as bool, o as findChatOrGroup, p as node, r as chatOf, s as findGroup, u as inviteTaken, v as str, y as waitForState } from "./apiKit-CfwVtBcw.js";
10
- import { a as checkShownName } from "./profiles-BehWURA9.js";
11
- import { t as BACKUP_METHODS } from "./backup-CfJenOQo.js";
12
- import { o as checkedBundle } from "./apps-LG-QOIxs.js";
1
+ import { Do as GhostlyHttpError, Ec as APP_PERMISSIONS, Ir as sanitizeTypingStatus, Nr as TYPING_KINDS, Pr as TYPING_REFRESH_MS, Qa as appCardId, Uc as isAppRef, Wi as identityStatement, Wn as GROUP_FILE_LIMITS, Xa as STATUS_CARD_LIMITS, Y as groupName, Yc as readImageMeta, _a as voiceDownloadName, _u as toBase64Url, ca as sanitizeFileName, da as VOICE_LIMITS, dl as ownInviteRefusal, du as sanitizeAvatar, eo as cardLine, fa as VOICE_METER, ga as parseVoiceMeta, gu as randomBytes$1, jc as isAppUrl, jo as LIMITS, la as sanitizeMime, ll as inviteLink, ma as downsamplePeaks, ni as APP_DATA_MAX_BYTES, no as checkStatusCard, pa as baseMime, ua as PLAYABLE_AUDIO, uu as MAX_AVATAR_LENGTH, va as voiceLevel, xo as AWAITING_PEER_MS, zc as appRef } from "./src-Dd_7Ew1X.js";
2
+ import { u as fileStore } from "./idb-CWvq4HKc.js";
3
+ import { O as waitingGroupFile, T as removeStored, U as iceServerProblem, W as iceServerSetting, i as groupOfFile, l as replyRef, n as groupFileId, v as paymentNetwork } from "./groupFiles-D9k6fyhf.js";
4
+ import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-D85lBh-Q.js";
5
+ import { t as IDENTITY_PROVIDERS } from "./registry-CVUdD4bJ.js";
6
+ import { a as waitForEdit, c as findSecret, i as pressable, n as buttonsCard, o as waitForGroupFrame, s as waitForMessage, t as BUTTON_METHODS } from "./buttons-B5EnA2nh.js";
7
+ import { a as WALLET_TYPES, c as DESTRUCTIVE_CALLS, d as ENGINE_READS, f as READ_PARAMS, i as TRANSPORT_NAMES, l as ENGINE_METHODS, m as engineParamsProblem, n as CHAT_METHODS, r as PAY_METHODS, s as withStoredIds, t as ADDRESS_TYPES, u as ENGINE_PARAMS } from "./words-DoLU6p8H.js";
8
+ import { i as localFileError, r as asCliError, t as CliError } from "./errors-DI6Z3jTH.js";
9
+ import { _ as state, a as findChat, d as list, f as messageOf, g as sentAt, h as oneOf, i as chatOrGroup, l as groupOf, m as num, n as bool, o as findChatOrGroup, p as node, r as chatOf, s as findGroup, u as inviteTaken, v as str, y as waitForState } from "./apiKit-Ba_t7MZO.js";
10
+ import { a as checkShownName } from "./profiles-gZdQPyaz.js";
11
+ import { t as BACKUP_METHODS } from "./backup-BY88aZr5.js";
12
+ import { o as checkedBundle } from "./apps-CJo1MmSY.js";
13
13
  import { generateMnemonic } from "@scure/bip39";
14
14
  import { wordlist } from "@scure/bip39/wordlists/english.js";
15
15
  import { openAsBlob, readFileSync, renameSync, writeFileSync } from "node:fs";
@@ -122,65 +122,175 @@ function endTyping(ctx, target, tell) {
122
122
  }
123
123
  //#endregion
124
124
  //#region src/voicePeaks.ts
125
- /** Longer than any voice note (15 minutes) with room: a file past it is not decoded into memory. */
125
+ /** Longer than any voice note (15 minutes) with room: a WebM or Ogg past it is not read (their demuxers hold it all). */
126
126
  var MAX_BYTES = 268435456;
127
+ /** Read first to tell a file's kind; a WAV's header is looked for in up to `WAV_HEAD_MAX` (as in ffmpeg's output). */
128
+ var HEAD_BYTES = 65536;
129
+ var WAV_HEAD_MAX = 1048576;
127
130
  var FFMPEG_TIMEOUT_MS = 12e4;
128
- /** The waveform and length of the sound in `path`, or why they could not be read. */
131
+ /** Read past the longest voice note by this much, so its length is known to be too long (`parseVoiceMeta` allows 5 s). */
132
+ var PAST_LIMIT_MS = 6e3;
133
+ /**
134
+ * The recorder's meter, run over the samples as they come (core `voiceLevelsOf`, reading for reading): the channels
135
+ * averaged as `mix` does, a reading every `intervalMs` over the window that ends there, nothing kept but that window.
136
+ */
137
+ var VoiceMeter = class {
138
+ maxMs;
139
+ rate = 0;
140
+ window = 1;
141
+ ring = /* @__PURE__ */ new Float32Array(1);
142
+ count = 0;
143
+ step = 1;
144
+ nextEnd = 0;
145
+ limit = Infinity;
146
+ levels = [];
147
+ scratch = [];
148
+ constructor(maxMs = VOICE_LIMITS.maxDurationMs + PAST_LIMIT_MS) {
149
+ this.maxMs = maxMs;
150
+ }
151
+ start(sampleRate) {
152
+ if (this.rate) return;
153
+ this.rate = sampleRate;
154
+ this.window = Math.max(1, Math.round(VOICE_METER.window * sampleRate / VOICE_METER.windowRate));
155
+ this.ring = new Float32Array(this.window);
156
+ this.nextEnd = this.endOf(1);
157
+ this.limit = Math.ceil(this.maxMs * sampleRate / 1e3);
158
+ }
159
+ endOf(step) {
160
+ return Math.round(step * VOICE_METER.intervalMs * this.rate / 1e3);
161
+ }
162
+ push(channels, length) {
163
+ if (!(this.rate > 0)) return false;
164
+ const one = channels.length === 1 ? channels[0] : null, n = channels.length;
165
+ for (let i = 0; i < length; i++) {
166
+ if (this.count >= this.limit) return false;
167
+ let sample;
168
+ if (one) sample = one[i];
169
+ else {
170
+ sample = 0;
171
+ for (let c = 0; c < n; c++) sample = Math.fround(sample + channels[c][i] / n);
172
+ }
173
+ this.ring[this.count % this.window] = sample;
174
+ this.count++;
175
+ while (this.count === this.nextEnd) {
176
+ const from = Math.max(0, this.count - this.window);
177
+ this.scratch.length = 0;
178
+ for (let k = from; k < this.count; k++) this.scratch.push(this.ring[k % this.window]);
179
+ this.levels.push(voiceLevel(this.scratch));
180
+ this.nextEnd = this.endOf(++this.step);
181
+ }
182
+ }
183
+ return this.count < this.limit;
184
+ }
185
+ /** The length and waveform measured so far; null when no sound came. */
186
+ result() {
187
+ if (!this.count || !(this.rate > 0)) return null;
188
+ return {
189
+ duration: Math.round(this.count / this.rate * 1e3),
190
+ peaks: downsamplePeaks(this.levels, VOICE_LIMITS.bars)
191
+ };
192
+ }
193
+ };
194
+ /**
195
+ * A file that is not sound: a decoder read it and found none (a WAV without its samples, ffmpeg's "Invalid data
196
+ * found"). Not one that could not be read here (no ffmpeg, a WAV format not read): that may still be a voice note.
197
+ */
198
+ var NotSound = class extends Error {};
199
+ /**
200
+ * The waveform and length of the sound in `path`, or why they could not be read (`notSound` when the file is no sound
201
+ * at all). A sound longer than a voice note may be is read only a little past that length: its duration says it is
202
+ * too long, and the send is refused for it.
203
+ */
129
204
  async function measureVoice(path) {
130
- let sound;
205
+ const meter = new VoiceMeter();
131
206
  try {
132
- sound = await decodeSound(path);
207
+ await streamSound(path, meter);
133
208
  } catch (error) {
134
- return { problem: error instanceof Error ? error.message : String(error) };
209
+ return {
210
+ problem: error instanceof Error ? error.message : String(error),
211
+ ...error instanceof NotSound ? { notSound: true } : {}
212
+ };
135
213
  }
136
- if (sound.mono.length === 0) return { problem: "no sound in it" };
137
- return { voice: {
138
- duration: Math.round(sound.mono.length / sound.sampleRate * 1e3),
139
- peaks: voicePeaksOf(sound.mono, sound.sampleRate)
140
- } };
141
- }
142
- async function decodeSound(path) {
143
- const bytes = await readFile(path);
144
- if (bytes.length > MAX_BYTES) throw new Error("too large to decode");
214
+ const voice = meter.result();
215
+ return voice ? { voice } : {
216
+ problem: "no sound in it",
217
+ notSound: true
218
+ };
219
+ }
220
+ /** Decodes the sound in `path` into `sink`, by this module's decoders or else ffmpeg. */
221
+ async function streamSound(path, sink) {
145
222
  let own;
146
223
  try {
147
- const sound = await decodeBytes(bytes);
148
- if (sound) return sound;
224
+ if (await streamFile(path, sink)) return;
149
225
  } catch (error) {
150
226
  own = error instanceof Error ? error : new Error(String(error));
151
227
  }
152
228
  try {
153
- return await decodeWithFfmpeg(path);
229
+ await streamFfmpeg(path, sink);
154
230
  } catch (error) {
155
231
  const reason = error instanceof Error ? error.message : String(error);
156
- throw new Error(own ? `${own.message}; ${reason}` : reason, { cause: error });
232
+ throw new (error instanceof NotSound || own instanceof NotSound ? NotSound : Error)(own ? `${own.message}; ${reason}` : reason, { cause: error });
157
233
  }
158
234
  }
159
- /** The sound in a file this module decodes itself, or null for a kind it leaves to ffmpeg. */
160
- async function decodeBytes(bytes) {
161
- if (ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 4) === "WAVE") return decodeWav(bytes);
162
- if (bytes[0] === 26 && bytes[1] === 69 && bytes[2] === 223 && bytes[3] === 163) {
163
- const opus = demuxWebm(bytes);
164
- return opus ? decodeOpus(opus) : null;
235
+ /** The kind of sound a file's first bytes say it is, of those this module decodes itself. */
236
+ function kindOf(head) {
237
+ if (ascii(head, 0, 4) === "RIFF" && ascii(head, 8, 4) === "WAVE") return "wav";
238
+ if (head[0] === 26 && head[1] === 69 && head[2] === 223 && head[3] === 163) return "webm";
239
+ if (ascii(head, 0, 4) === "OggS") return "ogg";
240
+ if (ascii(head, 0, 3) === "ID3" || head[0] === 255 && (head[1] & 224) === 224) return "mp3";
241
+ return null;
242
+ }
243
+ /** As `streamBytes`, reading the file only as far as its decoder goes; a kind left to ffmpeg is not read past its head. */
244
+ async function streamFile(path, sink) {
245
+ const file = await open(path);
246
+ try {
247
+ const { size } = await file.stat();
248
+ const kind = kindOf(await readAt(file, 0, Math.min(size, 12)));
249
+ if (kind === "wav") {
250
+ await streamWavFile(file, size, sink);
251
+ return true;
252
+ }
253
+ if (kind === "mp3") {
254
+ await streamMp3(piecesOf(file, size, MP3_PIECE), sink);
255
+ return true;
256
+ }
257
+ if (!kind) return false;
258
+ if (size > MAX_BYTES) throw new Error("too large to decode");
259
+ return streamOpusOf(kind, await file.readFile(), sink);
260
+ } finally {
261
+ await file.close();
165
262
  }
166
- if (ascii(bytes, 0, 4) === "OggS") {
167
- const opus = demuxOgg(bytes);
168
- return opus ? decodeOpus(opus) : null;
263
+ }
264
+ async function streamOpusOf(kind, bytes, sink) {
265
+ const opus = kind === "webm" ? demuxWebm(bytes) : demuxOgg(bytes);
266
+ if (!opus) return false;
267
+ await streamOpus(opus, sink);
268
+ return true;
269
+ }
270
+ /** Up to `length` bytes of the file from `at` (fewer at its end), into `into` when given. */
271
+ async function readAt(file, at, length, into = Buffer.allocUnsafe(length)) {
272
+ let got = 0;
273
+ while (got < length) {
274
+ const { bytesRead } = await file.read(into, got, length - got, at + got);
275
+ if (!bytesRead) break;
276
+ got += bytesRead;
277
+ }
278
+ return into.subarray(0, got);
279
+ }
280
+ /** The file in pieces of `piece` bytes, each read into the same buffer once the one before is used. */
281
+ async function* piecesOf(file, size, piece) {
282
+ const buffer = Buffer.allocUnsafe(piece);
283
+ for (let at = 0; at < size; at += piece) {
284
+ const bytes = await readAt(file, at, Math.min(piece, size - at), buffer);
285
+ if (!bytes.length) return;
286
+ yield bytes;
169
287
  }
170
- if (ascii(bytes, 0, 3) === "ID3" || bytes[0] === 255 && (bytes[1] & 224) === 224) return decodeMp3(bytes);
171
- return null;
172
288
  }
173
289
  function ascii(bytes, at, length) {
174
290
  return String.fromCharCode(...bytes.subarray(at, at + length));
175
291
  }
176
- function mix(channels, length) {
177
- if (channels.length === 1) return channels[0].subarray(0, length);
178
- const mono = new Float32Array(length);
179
- for (const channel of channels) for (let i = 0; i < length; i++) mono[i] += channel[i] / channels.length;
180
- return mono;
181
- }
182
- /** PCM (8, 16, 24 or 32 bit) or float (32 or 64 bit) WAV. A data chunk whose size is unknown (a pipe) runs to the end. */
183
- function decodeWav(bytes) {
292
+ /** The format of a WAV and where its samples are; null while its header is not all there. */
293
+ function wavHeader(bytes) {
184
294
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
185
295
  let format = 0, channels = 0, sampleRate = 0, bits = 0;
186
296
  let at = 12;
@@ -189,34 +299,76 @@ function decodeWav(bytes) {
189
299
  const size = view.getUint32(at + 4, true);
190
300
  const body = at + 8;
191
301
  if (id === "fmt ") {
302
+ if (body + 16 > bytes.length) return null;
192
303
  format = view.getUint16(body, true);
193
304
  channels = view.getUint16(body + 2, true);
194
305
  sampleRate = view.getUint32(body + 4, true);
195
306
  bits = view.getUint16(body + 14, true);
196
- if (format === 65534 && size >= 26) format = view.getUint16(body + 24, true);
307
+ if (format === 65534 && size >= 26) {
308
+ if (body + 26 > bytes.length) return null;
309
+ format = view.getUint16(body + 24, true);
310
+ }
197
311
  } else if (id === "data") {
198
- if (!channels || !sampleRate || !bits) throw new Error("a WAV without its format");
312
+ if (!channels || !sampleRate || !bits) throw new NotSound("a WAV without its format");
313
+ const to = size === 0 || size === 4294967295 ? Infinity : body + size;
199
314
  return {
200
- mono: wavSamples(view, body, size === 0 || size === 4294967295 || body + size > bytes.length ? bytes.length : body + size, format, channels, bits),
201
- sampleRate
315
+ format,
316
+ channels,
317
+ sampleRate,
318
+ bits,
319
+ from: body,
320
+ to
202
321
  };
203
322
  }
204
323
  at = body + size + (size & 1);
205
324
  }
206
- throw new Error("a WAV without sound");
207
- }
208
- function wavSamples(view, from, to, format, channels, bits) {
209
- const width = bits / 8;
210
- const read = format === 1 && bits === 8 ? (at) => (view.getUint8(at) - 128) / 128 : format === 1 && bits === 16 ? (at) => view.getInt16(at, true) / 32768 : format === 1 && bits === 24 ? (at) => (view.getInt8(at + 2) << 16 | view.getUint8(at + 1) << 8 | view.getUint8(at)) / 8388608 : format === 1 && bits === 32 ? (at) => view.getInt32(at, true) / 2147483648 : format === 3 && bits === 32 ? (at) => view.getFloat32(at, true) : format === 3 && bits === 64 ? (at) => view.getFloat64(at, true) : void 0;
211
- if (!read) throw new Error(`a WAV in a format not read here (${format}, ${bits} bit)`);
212
- const frames = Math.floor((to - from) / (width * channels));
213
- const mono = new Float32Array(frames);
214
- for (let frame = 0; frame < frames; frame++) {
215
- let sum = 0;
216
- for (let c = 0; c < channels; c++) sum += read(from + (frame * channels + c) * width);
217
- mono[frame] = sum / channels;
325
+ return null;
326
+ }
327
+ /** How a WAV's sample is read, or undefined for a format not read here. */
328
+ function sampleReader(view, format, bits) {
329
+ return format === 1 && bits === 8 ? (at) => (view.getUint8(at) - 128) / 128 : format === 1 && bits === 16 ? (at) => view.getInt16(at, true) / 32768 : format === 1 && bits === 24 ? (at) => (view.getInt8(at + 2) << 16 | view.getUint8(at + 1) << 8 | view.getUint8(at)) / 8388608 : format === 1 && bits === 32 ? (at) => view.getInt32(at, true) / 2147483648 : format === 3 && bits === 32 ? (at) => view.getFloat32(at, true) : format === 3 && bits === 64 ? (at) => view.getFloat64(at, true) : void 0;
330
+ }
331
+ /** Frames of a channel each pushed at a time: few enough to keep nothing large, many enough for few calls. */
332
+ var PIECE_FRAMES = 4096;
333
+ /** As `streamWav`, reading the file a piece of frames at a time until the sink wants no more. */
334
+ async function streamWavFile(file, size, sink) {
335
+ let header = null;
336
+ for (let length = HEAD_BYTES; !header; length *= 2) {
337
+ header = wavHeader(await readAt(file, 0, Math.min(size, length)));
338
+ if (length >= size || length >= WAV_HEAD_MAX) break;
218
339
  }
219
- return mono;
340
+ if (!header) throw new NotSound("a WAV without sound");
341
+ const { format, bits, channels } = header;
342
+ if (!sampleReader(/* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(0)), format, bits)) throw new Error(`a WAV in a format not read here (${format}, ${bits} bit)`);
343
+ sink.start(header.sampleRate);
344
+ const frame = bits / 8 * channels, end = Math.min(size, header.to);
345
+ const buffer = Buffer.allocUnsafe(PIECE_FRAMES * frame);
346
+ for (let at = header.from; at + frame <= end;) {
347
+ const bytes = await readAt(file, at, Math.min(buffer.length, end - at), buffer);
348
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
349
+ const pushed = pushWavFrames(view, 0, bytes.length, channels, bits / 8, sampleReader(view, format, bits), sink);
350
+ if (!pushed.more || !pushed.at) return;
351
+ at += pushed.at;
352
+ }
353
+ }
354
+ /** The whole frames between `from` and `to`, as the channels' samples; the byte where it stopped (a frame cut off). */
355
+ function pushWavFrames(view, from, to, channels, width, read, sink) {
356
+ const frame = width * channels;
357
+ const parts = Array.from({ length: channels }, () => new Float32Array(PIECE_FRAMES));
358
+ let at = from;
359
+ while (at + frame <= to) {
360
+ const count = Math.min(PIECE_FRAMES, Math.floor((to - at) / frame));
361
+ for (let f = 0; f < count; f++) for (let c = 0; c < channels; c++) parts[c][f] = read(at + (f * channels + c) * width);
362
+ at += count * frame;
363
+ if (!sink.push(parts, count)) return {
364
+ at,
365
+ more: false
366
+ };
367
+ }
368
+ return {
369
+ at,
370
+ more: true
371
+ };
220
372
  }
221
373
  /** A variable-length number in EBML: its length in bytes and value (the marker bit kept for ids, dropped for sizes). */
222
374
  function vint(bytes, at, keepMarker) {
@@ -372,7 +524,9 @@ function demuxOgg(bytes) {
372
524
  endGranule
373
525
  };
374
526
  }
375
- async function decodeOpus(stream) {
527
+ /** Opus frames decoded at a time: about 2 s of sound at 20 ms a frame. */
528
+ var OPUS_BATCH = 100;
529
+ async function streamOpus(stream, sink) {
376
530
  const { OpusDecoder } = await import("opus-decoder");
377
531
  const head = stream.head && ascii(stream.head, 0, 8) === "OpusHead" ? stream.head : null;
378
532
  const channels = head ? head[9] : Math.max(1, stream.channels);
@@ -392,34 +546,45 @@ async function decodeOpus(stream) {
392
546
  });
393
547
  await decoder.ready;
394
548
  try {
395
- const decoded = decoder.decodeFrames(stream.frames);
396
- let length = decoded.samplesDecoded;
397
- if (stream.endGranule !== void 0 && stream.endGranule > preSkip) length = Math.min(length, stream.endGranule - preSkip);
398
- return {
399
- mono: mix(decoded.channelData, length),
400
- sampleRate: decoded.sampleRate
401
- };
549
+ let left = stream.endGranule !== void 0 && stream.endGranule > preSkip ? stream.endGranule - preSkip : Infinity;
550
+ for (let at = 0; at < stream.frames.length && left > 0; at += OPUS_BATCH) {
551
+ const decoded = decoder.decodeFrames(stream.frames.slice(at, at + OPUS_BATCH));
552
+ if (!decoded.samplesDecoded) continue;
553
+ sink.start(decoded.sampleRate);
554
+ const length = Math.min(decoded.samplesDecoded, left);
555
+ left -= length;
556
+ if (!sink.push(decoded.channelData, length)) return;
557
+ }
402
558
  } finally {
403
559
  decoder.free();
404
560
  }
405
561
  }
406
- async function decodeMp3(bytes) {
562
+ /** MP3 bytes handed to the decoder at a time: about 16 s of a 128 kbit/s file. */
563
+ var MP3_PIECE = 262144;
564
+ /** The MP3 in `pieces`, decoded one at a time (the decoder copies each in before the next is asked for). */
565
+ async function streamMp3(pieces, sink) {
407
566
  const { MPEGDecoder } = await import("mpg123-decoder");
408
567
  const decoder = new MPEGDecoder();
409
568
  await decoder.ready;
410
569
  try {
411
- const decoded = decoder.decode(bytes);
412
- if (!decoded.samplesDecoded) throw new Error("no MP3 frames in it");
413
- return {
414
- mono: mix(decoded.channelData, decoded.samplesDecoded),
415
- sampleRate: decoded.sampleRate
416
- };
570
+ let any = false;
571
+ for await (const piece of pieces) {
572
+ const decoded = decoder.decode(piece);
573
+ if (!decoded.samplesDecoded) continue;
574
+ any = true;
575
+ sink.start(decoded.sampleRate);
576
+ if (!sink.push(decoded.channelData, decoded.samplesDecoded)) return;
577
+ }
578
+ if (!any) throw new Error("no MP3 frames in it");
417
579
  } finally {
418
580
  decoder.free();
419
581
  }
420
582
  }
421
- /** Anything ffmpeg reads, as a float WAV on its output (the channels kept, so they are averaged as above). */
422
- function decodeWithFfmpeg(path, command = process.env.GHOSTLY_FFMPEG || "ffmpeg") {
583
+ /**
584
+ * Anything ffmpeg reads, into `sink` as its WAV output comes: nothing kept but a frame cut between two pieces. Once
585
+ * the sink wants no more, ffmpeg is stopped.
586
+ */
587
+ function streamFfmpeg(path, sink, command = process.env.GHOSTLY_FFMPEG || "ffmpeg") {
423
588
  return new Promise((resolve, reject) => {
424
589
  const child = spawn(command, [
425
590
  "-v",
@@ -438,13 +603,44 @@ function decodeWithFfmpeg(path, command = process.env.GHOSTLY_FFMPEG || "ffmpeg"
438
603
  "pipe",
439
604
  "pipe"
440
605
  ] });
441
- const chunks = [];
442
- let size = 0, errors = "";
443
- const timer = setTimeout(() => child.kill("SIGKILL"), FFMPEG_TIMEOUT_MS);
606
+ let errors = "", pending = Buffer.alloc(0), header = null, done = false, failed = null;
607
+ let read, left = Infinity, timedOut = false;
608
+ const timer = setTimeout(() => {
609
+ timedOut = true;
610
+ child.kill("SIGKILL");
611
+ }, FFMPEG_TIMEOUT_MS);
612
+ const stop = () => {
613
+ done = true;
614
+ child.stdout.removeAllListeners("data");
615
+ child.kill("SIGKILL");
616
+ };
444
617
  child.stdout.on("data", (chunk) => {
445
- size += chunk.length;
446
- if (size > MAX_BYTES * 2) child.kill("SIGKILL");
447
- else chunks.push(chunk);
618
+ if (done) return;
619
+ pending = pending.length ? Buffer.concat([pending, chunk]) : chunk;
620
+ try {
621
+ if (!header) {
622
+ if (pending.length < 12) return;
623
+ if (ascii(pending, 0, 4) !== "RIFF" || ascii(pending, 8, 4) !== "WAVE") throw new Error("ffmpeg gave no WAV");
624
+ header = wavHeader(pending);
625
+ if (!header) {
626
+ if (pending.length > 1048576) throw new Error("a WAV without sound");
627
+ return;
628
+ }
629
+ if (!sampleReader(new DataView(pending.buffer, pending.byteOffset, pending.byteLength), header.format, header.bits)) throw new Error(`a WAV in a format not read here (${header.format}, ${header.bits} bit)`);
630
+ sink.start(header.sampleRate);
631
+ left = header.to === Infinity ? Infinity : header.to - header.from;
632
+ pending = pending.subarray(header.from);
633
+ }
634
+ const view = new DataView(pending.buffer, pending.byteOffset, pending.byteLength);
635
+ read = sampleReader(view, header.format, header.bits);
636
+ const { at, more } = pushWavFrames(view, 0, Math.min(pending.length, left), header.channels, header.bits / 8, read, sink);
637
+ if (left !== Infinity) left -= at;
638
+ pending = Buffer.from(pending.subarray(at));
639
+ if (!more || left <= 0) stop();
640
+ } catch (error) {
641
+ failed = error instanceof Error ? error : new Error(String(error));
642
+ stop();
643
+ }
448
644
  });
449
645
  child.stderr.on("data", (chunk) => {
450
646
  if (errors.length < 2e3) errors += chunk.toString();
@@ -455,15 +651,28 @@ function decodeWithFfmpeg(path, command = process.env.GHOSTLY_FFMPEG || "ffmpeg"
455
651
  });
456
652
  child.on("close", (code) => {
457
653
  clearTimeout(timer);
654
+ if (failed) {
655
+ reject(failed);
656
+ return;
657
+ }
658
+ if (done && header) {
659
+ resolve();
660
+ return;
661
+ }
662
+ if (timedOut) {
663
+ reject(/* @__PURE__ */ new Error(`ffmpeg took more than ${FFMPEG_TIMEOUT_MS / 6e4} minutes to read it`));
664
+ return;
665
+ }
666
+ const said = errors.trim().split("\n")[0].replace(/\[[^\]]*@ 0x[0-9a-f]+\]\s*/gi, "");
458
667
  if (code !== 0) {
459
- reject(/* @__PURE__ */ new Error(`ffmpeg could not read it${errors.trim() ? `: ${errors.trim().split("\n")[0]}` : ""}`));
668
+ reject(new NotSound(`ffmpeg could not read it${said ? `: ${said}` : ""}`));
460
669
  return;
461
670
  }
462
- try {
463
- resolve(decodeWav(Buffer.concat(chunks)));
464
- } catch (error) {
465
- reject(error);
671
+ if (!header) {
672
+ reject(new NotSound("a WAV without sound"));
673
+ return;
466
674
  }
675
+ resolve();
467
676
  });
468
677
  });
469
678
  }
@@ -542,12 +751,18 @@ function fileChat(ctx, params, fileId) {
542
751
  where: { chat: link.id }
543
752
  };
544
753
  }
545
- var VOICE_ONLY = "A voice note is audio (webm, ogg, mp4, mpeg, aac, m4a or wav) of at most 15 minutes, with peaks from 0 to 255";
546
- /** `--voice [ms] [--peaks …]`: the voice description, its length and waveform measured from the sound when not given. */
547
- async function voiceOf(params, path, mime) {
754
+ var VOICE_MINUTES = VOICE_LIMITS.maxDurationMs / 6e4;
755
+ /**
756
+ * `--voice [ms] [--peaks …]`: the voice description, its length and waveform measured from the sound when not given.
757
+ * A file that is not a voice note is refused naming what is wrong with it: empty, not audio, too long.
758
+ */
759
+ async function voiceOf(params, path, mime, size) {
548
760
  if (params.voice === void 0) return {};
549
- if (!PLAYABLE_AUDIO.test(baseMime(mime))) throw new CliError("bad_request", VOICE_ONLY);
550
- let duration = params.voice === true ? void 0 : num(params, "voice", 0, { min: 1 });
761
+ const name = basename(path);
762
+ if (!size) throw new CliError("bad_request", `${name} is empty: a voice note is audio`);
763
+ if (!PLAYABLE_AUDIO.test(baseMime(mime))) throw new CliError("bad_request", `${name} is ${mime}, not audio (webm, ogg, mp4, mpeg, aac, m4a or wav)`);
764
+ const given = params.voice === true ? void 0 : num(params, "voice", 0, { min: 1 });
765
+ let duration = given;
551
766
  let peaks = list(params, "peaks").map(Number);
552
767
  let warning;
553
768
  if (duration === void 0 || !peaks.length) {
@@ -555,18 +770,20 @@ async function voiceOf(params, path, mime) {
555
770
  if ("voice" in measured) {
556
771
  duration ??= measured.voice.duration;
557
772
  if (!peaks.length) peaks = measured.voice.peaks;
558
- } else if (duration === void 0) throw new CliError("bad_request", `Could not measure the voice note (${measured.problem}): give its length as --voice <ms>`);
773
+ } else if (measured.notSound) throw new CliError("bad_request", `${name} is not audio (${measured.problem})`);
774
+ else if (duration === void 0) throw new CliError("bad_request", `Could not measure the voice note (${measured.problem}): give its length as --voice <ms>`);
559
775
  else warning = `Sent without a waveform: could not read the sound (${measured.problem})`;
560
776
  }
561
777
  const voice = parseVoiceMeta({
562
778
  duration,
563
779
  peaks: peaks.length ? peaks : new Array(VOICE_LIMITS.bars).fill(0)
564
780
  }, mime);
565
- if (!voice) throw new CliError("bad_request", VOICE_ONLY);
566
- return {
781
+ if (voice) return {
567
782
  voice,
568
783
  ...warning ? { warning } : {}
569
784
  };
785
+ if (duration > VOICE_LIMITS.maxDurationMs + 5e3) throw new CliError("bad_request", given === void 0 ? `${name} is longer than ${VOICE_MINUTES} minutes: a voice note is at most ${VOICE_MINUTES}` : `A voice note is at most ${VOICE_MINUTES} minutes (${VOICE_LIMITS.maxDurationMs} ms), not ${given} ms`);
786
+ throw new CliError("bad_request", `A voice note's waveform is 1 to ${VOICE_LIMITS.maxBars} peaks from 0 to 255`);
570
787
  }
571
788
  /**
572
789
  * A file announced in a group (WISP 503): its bytes staged under a group file id with their digest, as a chat's are, then
@@ -582,7 +799,7 @@ async function sendToGroup(ctx, params, group, path, size) {
582
799
  }
583
800
  const check = await node(ctx).groupFileCheck({ groupId: group.id });
584
801
  if (check.error) throw check.refused ? new CliError("refused", check.error) : groupSendRefused(check.error);
585
- const { voice, warning } = await voiceOf(params, path, mime);
802
+ const { voice, warning } = await voiceOf(params, path, mime, size);
586
803
  const source = await openAsBlob(path, { type: mime });
587
804
  const image = voice ? void 0 : await readImageMeta(source, mime);
588
805
  const fileId = groupFileId(group.id, "out");
@@ -696,7 +913,7 @@ var FILE_METHODS = {
696
913
  if (replyTo) {
697
914
  if (!(await node(ctx).getMessages(link.id)).some((m) => m.id === replyTo || replyRef(m) === replyTo)) throw new CliError("not_found", "That message is not in this chat, or cannot be replied to");
698
915
  }
699
- const { voice, warning } = await voiceOf(params, path, mime);
916
+ const { voice, warning } = await voiceOf(params, path, mime, info.size);
700
917
  const source = await openAsBlob(path, { type: mime });
701
918
  const image = voice ? void 0 : await readImageMeta(source, mime);
702
919
  const wireId = toBase64Url(randomBytes$1(12));
@@ -2204,12 +2421,14 @@ function sameSecret(a, b) {
2204
2421
  }
2205
2422
  /**
2206
2423
  * Added to every answer of a contact's app, next to any policy the contact sends (a browser enforces both): its
2207
- * scripts and forms reach its own origin and public https sites, never plain http. The page is served from
2208
- * `<random>.localhost`, which Chrome counts as this machine, so its own guard for requests to local addresses
2209
- * (Local Network Access) would not ask before the page read or posted to another service on 127.0.0.1 or the local
2210
- * network. Pictures, frames and navigation are not covered.
2424
+ * scripts, forms, pictures, frames, fonts, media, styles and workers reach its own origin and public https sites
2425
+ * (and inline, data: and blob: content), never plain http. The page is served from `<random>.localhost`, which Chrome
2426
+ * counts as this machine, so its own guard for requests to local addresses (Local Network Access) would not ask
2427
+ * before the page reached another service on 127.0.0.1 or the local network. Inline scripts and styles stay allowed:
2428
+ * this policy bounds where the page reaches, not how the app is written. A top-level navigation is not covered: no
2429
+ * browser lets a policy bound it.
2211
2430
  */
2212
- var OPENED_SERVICE_CSP = "connect-src 'self' https: wss:; form-action 'self' https:";
2431
+ var OPENED_SERVICE_CSP = "default-src 'self' https: data: blob: 'unsafe-inline' 'unsafe-eval'; connect-src 'self' https: wss:; form-action 'self' https:";
2213
2432
  function plain(response, status, text, headers = {}) {
2214
2433
  response.writeHead(status, {
2215
2434
  "content-type": "text/plain; charset=utf-8",
@@ -3717,17 +3936,21 @@ var METHODS = {
3717
3936
  /** The saved messages, the last saved first, each as it is now and named by its chat or group. */
3718
3937
  async "saved.list"(ctx) {
3719
3938
  const { links, groups } = state(ctx);
3720
- return (await node(ctx).savedMessages()).map(({ savedAt, message }) => {
3939
+ const saved = await node(ctx).savedMessages();
3940
+ const gone = /* @__PURE__ */ new Map();
3941
+ for (const linkId of new Set(saved.map((s) => s.message.linkId))) gone.set(linkId, await originalsGone(ctx, linkId, saved.flatMap((s) => s.message.linkId === linkId ? [s.message] : [])));
3942
+ return saved.map(({ savedAt, message }) => {
3943
+ const checked = (json) => quoteChecked(json, message, gone.get(message.linkId));
3721
3944
  if (!message.linkId.startsWith("group:")) return {
3722
3945
  chat: message.linkId,
3723
3946
  savedAt,
3724
- message: chatMessageJson(message, links.find((l) => l.id === message.linkId))
3947
+ message: checked(chatMessageJson(message, links.find((l) => l.id === message.linkId)))
3725
3948
  };
3726
3949
  const id = message.linkId.slice(6);
3727
3950
  return {
3728
3951
  group: id,
3729
3952
  savedAt,
3730
- message: groupMessageJson(message, groups.find((g) => g.id === id))
3953
+ message: checked(groupMessageJson(message, groups.find((g) => g.id === id)))
3731
3954
  };
3732
3955
  });
3733
3956
  },
@@ -3830,6 +4053,7 @@ var METHODS = {
3830
4053
  if (result.error) throw new CliError(result.refused ? "refused" : "unavailable", result.error);
3831
4054
  return {
3832
4055
  [target.group ? "group" : "chat"]: target.id,
4056
+ messageId: message.id,
3833
4057
  deleted: message.id,
3834
4058
  everyone: true
3835
4059
  };
@@ -3844,7 +4068,9 @@ var METHODS = {
3844
4068
  });
3845
4069
  return {
3846
4070
  chat: link.id,
3847
- deleted: messageId
4071
+ messageId,
4072
+ deleted: messageId,
4073
+ everyone: false
3848
4074
  };
3849
4075
  },
3850
4076
  async "chat.details"(ctx, params) {
@@ -4328,6 +4554,7 @@ async function saveMark(ctx, params, remove) {
4328
4554
  messageId,
4329
4555
  remove
4330
4556
  });
4557
+ if (result.error && remove && /not in this chat/.test(result.error)) throw new CliError("not_found", `No saved message ${JSON.stringify(messageId)} in this chat (ghostly saved list shows the saved ones)`);
4331
4558
  if (result.error) throw new CliError(/not in this chat/.test(result.error) ? "not_found" : "bad_request", result.error);
4332
4559
  return {
4333
4560
  [target.group ? "group" : "chat"]: target.id,
@@ -4431,4 +4658,4 @@ async function callApi(ctx, method, params = {}) {
4431
4658
  //#endregion
4432
4659
  export { flushCardUpdates as _, hideStateSecrets as a, paymentJson as c, nodeLocalFetch as d, chatJson as f, resumeHolds as g, groupMessageJson as h, groupSendRefused as i, reportAppFrames as l, groupJson as m, SETTABLE as n, mentionsFor as o, chatMessageJson as p, callApi as r, redactSettings as s, API_METHODS as t, servedApps as u };
4433
4660
 
4434
- //# sourceMappingURL=api-CMohP9Pw.js.map
4661
+ //# sourceMappingURL=api-d2aXkbM5.js.map