@ghostlytools/cli 1.7.2 → 1.7.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 (66) hide show
  1. package/README.md +22 -14
  2. package/SKILL.md +5 -1
  3. package/dist/assets/{api-CcuCtc1H.js → api-B42F9ytB.js} +2 -2
  4. package/dist/assets/{api-tSZELCPQ.js → api-tf-wAAnB.js} +214 -87
  5. package/dist/assets/api-tf-wAAnB.js.map +1 -0
  6. package/dist/assets/{apiKit-BFk7GAk9.js → apiKit-DJb9hulp.js} +33 -4
  7. package/dist/assets/{apiKit-BFk7GAk9.js.map → apiKit-DJb9hulp.js.map} +1 -1
  8. package/dist/assets/{apps-D6THreq_.js → apps-BfoDISRg.js} +1 -1
  9. package/dist/assets/{apps-C5Mi6x9Q.js → apps-DIrWmLgL.js} +3 -3
  10. package/dist/assets/{apps-C5Mi6x9Q.js.map → apps-DIrWmLgL.js.map} +1 -1
  11. package/dist/assets/{arkade-Cz0B9bJ0.js → arkade-CJAhhgPQ.js} +2 -2
  12. package/dist/assets/{arkade-Cz0B9bJ0.js.map → arkade-CJAhhgPQ.js.map} +1 -1
  13. package/dist/assets/{backup-A0hIa9GE.js → backup-BkUeeduy.js} +1 -1
  14. package/dist/assets/{backup-Wb2sm2dd.js → backup-Bko-AAm0.js} +4 -4
  15. package/dist/assets/{backup-Wb2sm2dd.js.map → backup-Bko-AAm0.js.map} +1 -1
  16. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
  17. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  18. package/dist/assets/buttons-Be7u0V5g.js +2 -0
  19. package/dist/assets/{buttons-Cf70NVYq.js → buttons-DeA6Yddq.js} +34 -8
  20. package/dist/assets/buttons-DeA6Yddq.js.map +1 -0
  21. package/dist/assets/{envelope-kQ5kYjVE.js → envelope-Cz5fc7BM.js} +2 -2
  22. package/dist/assets/{envelope-kQ5kYjVE.js.map → envelope-Cz5fc7BM.js.map} +1 -1
  23. package/dist/assets/{groupFiles-D9Ttlm3M.js → groupFiles-BlZRBWpt.js} +558 -4
  24. package/dist/assets/groupFiles-BlZRBWpt.js.map +1 -0
  25. package/dist/assets/{host-DpypH-fR.js → host-BX0DmKW6.js} +38 -15
  26. package/dist/assets/host-BX0DmKW6.js.map +1 -0
  27. package/dist/assets/{hyperdhtRelay-D1rj84v2.js → hyperdhtRelay-DitYDnXx.js} +2 -2
  28. package/dist/assets/{hyperdhtRelay-D1rj84v2.js.map → hyperdhtRelay-DitYDnXx.js.map} +1 -1
  29. package/dist/assets/{irohWeb-BTSlWgEX.js → irohWeb-R3bcd34h.js} +2 -2
  30. package/dist/assets/{irohWeb-BTSlWgEX.js.map → irohWeb-R3bcd34h.js.map} +1 -1
  31. package/dist/assets/{main-BwgoQZVu.js → main-6QOSvQ8b.js} +247 -102
  32. package/dist/assets/main-6QOSvQ8b.js.map +1 -0
  33. package/dist/assets/{mainline-B1urhbEZ.js → mainline-BfwezHWi.js} +2 -2
  34. package/dist/assets/{mainline-B1urhbEZ.js.map → mainline-BfwezHWi.js.map} +1 -1
  35. package/dist/assets/{networkReason-D2Z0BdIj.js → networkReason-Ba9415nn.js} +2 -2
  36. package/dist/assets/{networkReason-D2Z0BdIj.js.map → networkReason-Ba9415nn.js.map} +1 -1
  37. package/dist/assets/{nwc-T2aUK6bi.js → nwc-ovXSN2M2.js} +3 -3
  38. package/dist/assets/{nwc-T2aUK6bi.js.map → nwc-ovXSN2M2.js.map} +1 -1
  39. package/dist/assets/{nwcProvider-Dz-ty_DE.js → nwcProvider-BzZbfFP3.js} +2 -2
  40. package/dist/assets/{nwcProvider-Dz-ty_DE.js.map → nwcProvider-BzZbfFP3.js.map} +1 -1
  41. package/dist/assets/{registry-Bazitl0a.js → registry-B0Uv9yL6.js} +3 -3
  42. package/dist/assets/{registry-Bazitl0a.js.map → registry-B0Uv9yL6.js.map} +1 -1
  43. package/dist/assets/{registry-BlSTJlbv.js → registry-CFtlhWCI.js} +1 -1
  44. package/dist/assets/{resolve-Bx1Eeg-w.js → resolve-BzFG4WDU.js} +2 -2
  45. package/dist/assets/{resolve-Bx1Eeg-w.js.map → resolve-BzFG4WDU.js.map} +1 -1
  46. package/dist/assets/{server-CnPj9wWh.js → server-BGCuHbmQ.js} +266 -594
  47. package/dist/assets/server-BGCuHbmQ.js.map +1 -0
  48. package/dist/assets/{src-BsznF3XG.js → src-DWw2hUE5.js} +106 -38
  49. package/dist/assets/src-DWw2hUE5.js.map +1 -0
  50. package/dist/assets/{translate-cDBotA-b.js → translate-DObb-1tq.js} +2 -2
  51. package/dist/assets/{translate-cDBotA-b.js.map → translate-DObb-1tq.js.map} +1 -1
  52. package/dist/assets/{usdt-DxxLdG60.js → usdt-Bkva90Vo.js} +3 -3
  53. package/dist/assets/{usdt-DxxLdG60.js.map → usdt-Bkva90Vo.js.map} +1 -1
  54. package/dist/assets/{words-qH8gGtmc.js → words-odSAoasK.js} +4 -2
  55. package/dist/assets/words-odSAoasK.js.map +1 -0
  56. package/dist/ghostly.mjs +1 -1
  57. package/package.json +1 -1
  58. package/dist/assets/api-tSZELCPQ.js.map +0 -1
  59. package/dist/assets/buttons-Bxxu3lSk.js +0 -2
  60. package/dist/assets/buttons-Cf70NVYq.js.map +0 -1
  61. package/dist/assets/groupFiles-D9Ttlm3M.js.map +0 -1
  62. package/dist/assets/host-DpypH-fR.js.map +0 -1
  63. package/dist/assets/main-BwgoQZVu.js.map +0 -1
  64. package/dist/assets/server-CnPj9wWh.js.map +0 -1
  65. package/dist/assets/src-BsznF3XG.js.map +0 -1
  66. package/dist/assets/words-qH8gGtmc.js.map +0 -1
@@ -1,15 +1,15 @@
1
- import { $a as appCardId, $c as readImageMeta, Co as AWAITING_PEER_MS, Hc as appRef, Ir as sanitizeTypingStatus, Kc as isAppRef, No as LIMITS, Nr as TYPING_KINDS, Pc as isAppUrl, Pr as TYPING_REFRESH_MS, Wi as identityStatement, Wn as GROUP_FILE_LIMITS, Y as groupName, Za as STATUS_CARD_LIMITS, _a as voiceDownloadName, ao as statusCardBytes, bu as randomBytes$1, ca as sanitizeFileName, co as claimedTime, da as VOICE_LIMITS, fa as VOICE_METER, ga as parseVoiceMeta, hl as ownInviteRefusal, hu as sanitizeAvatar, jo as parseLocalTarget, kc as APP_PERMISSIONS, ko as GhostlyHttpError, la as sanitizeMime, ma as downsamplePeaks, mu as MAX_AVATAR_LENGTH, ni as APP_DATA_MAX_BYTES, pa as baseMime, pl as inviteLink, ro as checkStatusCard, to as cardLine, ua as PLAYABLE_AUDIO, va as voiceLevel, xu as toBase64Url } from "./src-BsznF3XG.js";
1
+ import { $a as appCardId, $c as readImageMeta, Co as AWAITING_PEER_MS, Ha as replySnippet, Hc as appRef, Ir as sanitizeTypingStatus, Kc as isAppRef, No as LIMITS, Nr as TYPING_KINDS, Pc as isAppUrl, Pr as TYPING_REFRESH_MS, Wi as identityStatement, Wn as GROUP_FILE_LIMITS, Y as groupName, Za as STATUS_CARD_LIMITS, _a as voiceDownloadName, ao as statusCardBytes, bu as randomBytes$1, ca as sanitizeFileName, co as claimedTime, da as VOICE_LIMITS, fa as VOICE_METER, ga as parseVoiceMeta, hl as ownInviteRefusal, hu as sanitizeAvatar, jo as parseLocalTarget, kc as APP_PERMISSIONS, ko as GhostlyHttpError, la as sanitizeMime, ma as downsamplePeaks, mu as MAX_AVATAR_LENGTH, ni as APP_DATA_MAX_BYTES, pa as baseMime, pl as inviteLink, ro as checkStatusCard, to as cardLine, ua as PLAYABLE_AUDIO, va as voiceLevel, xu as toBase64Url } from "./src-DWw2hUE5.js";
2
2
  import { u as fileStore } from "./idb-BlH8-O3R.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-D9Ttlm3M.js";
3
+ import { J as iceServerProblem, O as waitingGroupFile, T as removeStored, Y as iceServerSetting, i as groupOfFile, k as IDENTITY_DRAFT_TTL_MS, l as replyRef, n as groupFileId, v as paymentNetwork } from "./groupFiles-BlZRBWpt.js";
4
4
  import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-BD0v3rRG.js";
5
- import { t as IDENTITY_PROVIDERS } from "./registry-Bazitl0a.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-Cf70NVYq.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-qH8gGtmc.js";
5
+ import { t as IDENTITY_PROVIDERS } from "./registry-B0Uv9yL6.js";
6
+ import { a as waitForConfirmed, c as waitForMessage, i as pressable, l as waitForRemoval, n as buttonsCard, o as waitForEdit, s as waitForGroupFrame, t as BUTTON_METHODS, u as findSecret } from "./buttons-DeA6Yddq.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-odSAoasK.js";
8
8
  import { i as localFileError, r as asCliError, t as CliError } from "./errors-mnjSQlbX.js";
9
- import { _ as sentAt, a as findChat, b as waitForState, d as list, f as messageOf, g as oneOf, h as num, i as chatOrGroup, l as groupOf, m as node, n as bool, o as findChatOrGroup, r as chatOf, s as findGroup, u as inviteTaken, v as state, y as str } from "./apiKit-BFk7GAk9.js";
9
+ import { _ as oneOf, a as dhtOnly, b as str, c as findGroup, d as inviteTaken, f as list, g as num, h as node, i as chatOrGroup, n as bool, o as findChat, p as messageOf, r as chatOf, s as findChatOrGroup, u as groupOf, v as sentAt, x as waitForState, y as state } from "./apiKit-DJb9hulp.js";
10
10
  import { a as checkShownName } from "./profiles-C6XWqre5.js";
11
- import { t as BACKUP_METHODS } from "./backup-Wb2sm2dd.js";
12
- import { o as checkedBundle } from "./apps-C5Mi6x9Q.js";
11
+ import { t as BACKUP_METHODS } from "./backup-Bko-AAm0.js";
12
+ import { o as checkedBundle } from "./apps-DIrWmLgL.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";
@@ -1377,11 +1377,11 @@ async function sendCard(ctx, params, kind) {
1377
1377
  }, params, now));
1378
1378
  await parentThere(ctx, target, card);
1379
1379
  const text = str(params, "text") ?? "";
1380
- const wait = oneOf(params, "wait", target.group ? ["none", "sent"] : [
1380
+ const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", [
1381
1381
  "none",
1382
1382
  "sent",
1383
1383
  "delivered"
1384
- ], "none");
1384
+ ], ctx.mode === "one-shot" ? "sent" : "none");
1385
1385
  const ms = num(params, "timeout", 30, {
1386
1386
  min: 1,
1387
1387
  max: 3600
@@ -1447,7 +1447,7 @@ async function updateCard(ctx, params, kind) {
1447
1447
  }), params));
1448
1448
  if (isObject(patch) && patch.parent !== void 0) await parentThere(ctx, target, card);
1449
1449
  const text = str(params, "text") ?? "";
1450
- const wait = oneOf(params, "wait", target.group ? ["none", "sent"] : ["none", "confirmed"], "none");
1450
+ const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", ["none", "confirmed"], ctx.mode === "one-shot" ? "confirmed" : "none");
1451
1451
  const ms = num(params, "timeout", 30, {
1452
1452
  min: 1,
1453
1453
  max: 3600
@@ -1526,7 +1526,7 @@ async function reportUsage(ctx, ref, fields, params) {
1526
1526
  };
1527
1527
  checked(report);
1528
1528
  const sent = await cardMessage(ctx, target, "usage", id).catch(() => void 0);
1529
- const wait = oneOf(params, "wait", ["none", "sent"], "none");
1529
+ const wait = oneOf(params, "wait", ["none", "sent"], !target.group && ctx.mode === "one-shot" ? "sent" : "none");
1530
1530
  if (!sent || (sent.edit?.seq ?? 0) >= STATUS_CARD_LIMITS.edits) return {
1531
1531
  ...await sendCard(ctx, {
1532
1532
  ...params,
@@ -1675,14 +1675,16 @@ async function holdChat(ctx, link, minutes) {
1675
1675
  }
1676
1676
  /**
1677
1677
  * Ends a hold: the chat leaves DHT only, unless someone chose otherwise meanwhile. Whether there was one. `reason`:
1678
- * expired, connect (`chat connect`) or lifted (`--hold 0`).
1678
+ * expired, connect (`chat connect`) or lifted (`--hold 0`, or `chat transport`: `chosen`, the chat's transport was
1679
+ * just chosen, and stays as chosen).
1679
1680
  */
1680
- async function releaseHold(ctx, linkId, reason) {
1681
+ async function releaseHold(ctx, linkId, reason, chosen = false) {
1681
1682
  const holds = readHolds(ctx);
1682
1683
  if (!holds[linkId]) return false;
1683
1684
  clearTimeout(timersOf(ctx).get(linkId));
1684
1685
  timersOf(ctx).delete(linkId);
1685
- if (state(ctx).links.find((l) => l.id === linkId)?.deliveryMode === "dht") await node(ctx).setDeliveryMode({
1686
+ const link = state(ctx).links.find((l) => l.id === linkId);
1687
+ if (!chosen && link?.deliveryMode === "dht") await node(ctx).setDeliveryMode({
1686
1688
  linkId,
1687
1689
  mode: "stream"
1688
1690
  });
@@ -1765,6 +1767,7 @@ function chatDetailsJson(link, showSecret) {
1765
1767
  rttMs: link.transportRttMs ?? null,
1766
1768
  relays: link.transportRelayed?.relays ?? null,
1767
1769
  deliveryMode: link.deliveryMode ?? null,
1770
+ peerDeliveryMode: link.dhtDelivery?.peerMode ?? null,
1768
1771
  capabilities: link.capabilities ?? null,
1769
1772
  hold: link.hold ?? null,
1770
1773
  peerOnline: link.peerOnline,
@@ -2009,7 +2012,7 @@ var GROUP_ADMIN_METHODS = {
2009
2012
  return view(ctx, group.id, params);
2010
2013
  },
2011
2014
  async "group.rename"(ctx, params) {
2012
- const group = groupOf(ctx, params);
2015
+ const group = groupOf(ctx, params, "chat rename <chat> <name...>");
2013
2016
  const name = groupName(str(params, "name", true));
2014
2017
  if (!name) throw new CliError("bad_request", `A group's name is 1 to 64 characters on one line`);
2015
2018
  await node(ctx).renameGroup({
@@ -2060,9 +2063,12 @@ var GROUP_ADMIN_METHODS = {
2060
2063
  };
2061
2064
  //#endregion
2062
2065
  //#region src/identities.ts
2063
- /** Drafts per daemon: a proof made in two steps needs the same process for both. */
2066
+ /**
2067
+ * Drafts per daemon: a proof made in two steps needs the same process for both. Kept as long as the engine keeps them,
2068
+ * and the oldest dropped when a fifth begins as the engine drops it, so what `identity add` promises still completes.
2069
+ */
2064
2070
  var drafts = /* @__PURE__ */ new Map();
2065
- var DRAFT_TTL_MS = 36e5;
2071
+ var NO_DRAFT = `No such draft here: it is kept by the daemon that made it, for ${IDENTITY_DRAFT_TTL_MS / 6e4} minutes and while fewer than 4 newer ones wait`;
2066
2072
  function provider(id) {
2067
2073
  const found = IDENTITY_PROVIDERS.find((p) => p.id === id);
2068
2074
  if (!found) throw new CliError("not_found", `No identity provider ${id} (ghostly identity providers)`);
@@ -2112,7 +2118,7 @@ function proofJson(p) {
2112
2118
  };
2113
2119
  }
2114
2120
  function pruneDrafts(now = Date.now()) {
2115
- for (const [id, draft] of drafts) if (now - draft.createdAt > DRAFT_TTL_MS) drafts.delete(id);
2121
+ for (const [id, draft] of drafts) if (now - draft.createdAt > 18e5) drafts.delete(id);
2116
2122
  }
2117
2123
  async function begin(ctx, p, subject, params) {
2118
2124
  let normalized;
@@ -2169,10 +2175,11 @@ var IDENTITY_METHODS = {
2169
2175
  const values = params.fields ?? {};
2170
2176
  if (typeof values !== "object" || Array.isArray(values) || Object.values(values).some((v) => typeof v !== "string")) throw new CliError("bad_request", "fields must be an object of strings");
2171
2177
  for (const field of signer.fields ?? []) if (!field.optional && !values[field.name]) throw new CliError("bad_request", `${signer.label} needs ${field.name} (${field.label})`);
2172
- const signal = AbortSignal.timeout(num(params, "timeout", 300, {
2178
+ const seconds = num(params, "timeout", 300, {
2173
2179
  min: 5,
2174
2180
  max: 3600
2175
- }) * 1e3);
2181
+ });
2182
+ const signal = AbortSignal.timeout(seconds * 1e3);
2176
2183
  return {
2177
2184
  done: true,
2178
2185
  proof: proofJson(await signer.run({
@@ -2213,6 +2220,9 @@ var IDENTITY_METHODS = {
2213
2220
  } catch {}
2214
2221
  throw error;
2215
2222
  }
2223
+ }).catch((error) => {
2224
+ if (!signal.aborted || error instanceof CliError) throw error;
2225
+ throw new CliError("timeout", `Timed out after ${seconds} s waiting for ${signer.label} to approve the ${p.label} proof: --timeout <seconds> waits longer`);
2216
2226
  }))
2217
2227
  };
2218
2228
  }
@@ -2224,6 +2234,7 @@ var IDENTITY_METHODS = {
2224
2234
  }
2225
2235
  const { draftId, binding } = await begin(ctx, p, subject, params);
2226
2236
  const statement = identityStatement(binding);
2237
+ while (drafts.size >= 4) drafts.delete(drafts.keys().next().value);
2227
2238
  drafts.set(draftId, {
2228
2239
  draftId,
2229
2240
  provider: p.id,
@@ -2238,19 +2249,23 @@ var IDENTITY_METHODS = {
2238
2249
  signer: signer.id,
2239
2250
  statement: statement.text,
2240
2251
  instructions: instructionsJson(signer.instructions(statement)),
2241
- expiresInSeconds: DRAFT_TTL_MS / 1e3
2252
+ expiresInSeconds: IDENTITY_DRAFT_TTL_MS / 1e3
2242
2253
  };
2243
2254
  },
2244
2255
  /** Finishes a two-step proof: what the tool printed (external-tool), or nothing (publish: the engine looks it up). */
2245
2256
  async "identity.complete"(ctx, params) {
2257
+ pruneDrafts();
2246
2258
  const draft = drafts.get(str(params, "draft", true));
2247
- if (!draft) throw new CliError("not_found", "No such draft here: it is kept by the daemon that made it, for an hour");
2259
+ if (!draft) throw new CliError("not_found", NO_DRAFT);
2248
2260
  const signer = signerOf(provider(draft.provider), draft.signer);
2249
2261
  const statement = identityStatement(draft.binding);
2250
2262
  let evidence;
2251
2263
  try {
2252
- if (signer.kind === "external-tool") evidence = await signer.parse(str(params, "evidence", true), statement);
2253
- else if (signer.kind === "publish") evidence = await signer.evidence(statement);
2264
+ if (signer.kind === "external-tool") {
2265
+ const output = str(params, "evidence");
2266
+ if (!output?.trim()) throw new CliError("usage", `Missing what ${signer.label} printed: give it from a file (--evidence-file f) or on stdin (… | ghostly identity complete ${draft.draftId})`, { needs: "evidence" });
2267
+ evidence = await signer.parse(output, statement);
2268
+ } else if (signer.kind === "publish") evidence = await signer.evidence(statement);
2254
2269
  else throw new CliError("bad_request", "This draft needs no completion");
2255
2270
  } catch (error) {
2256
2271
  if (error instanceof CliError) throw error;
@@ -2268,7 +2283,7 @@ var IDENTITY_METHODS = {
2268
2283
  },
2269
2284
  async "identity.cancel"(ctx, params) {
2270
2285
  const draftId = str(params, "draft", true);
2271
- if (!drafts.delete(draftId)) throw new CliError("not_found", "No such draft here: it is kept by the daemon that made it, for an hour");
2286
+ if (!drafts.delete(draftId)) throw new CliError("not_found", NO_DRAFT);
2272
2287
  await node(ctx).cancelIdentityProof({ draftId });
2273
2288
  return { cancelled: draftId };
2274
2289
  },
@@ -2916,7 +2931,7 @@ function reportAppFrames(hub, node, profileDir) {
2916
2931
  /** The chat and the served app a command names, on an engine that speaks apps/1. */
2917
2932
  function target(ctx, params) {
2918
2933
  const app = servedApp(servedApps(ctx.runtime.paths.dir), str(params, "ref", true));
2919
- if (ctx.mode !== "daemon") throw new CliError("unavailable", "An app is open only while a daemon runs: start one (ghostly daemon start) and open it there");
2934
+ if (ctx.mode !== "daemon") throw new CliError("unavailable", "An app is open only while a daemon runs: start one (ghostly daemon --detach) and open it there");
2920
2935
  if (!ctx.runtime.apps) throw new CliError("unavailable", "This daemon started before an app was served, so it offers no apps/1 yet: ghostly daemon restart");
2921
2936
  const link = chatOf(ctx, params);
2922
2937
  return {
@@ -3697,6 +3712,15 @@ function mentionsFor(text, refs, group) {
3697
3712
  /** Per host: stops watching the invite it marked as the chat on screen. */
3698
3713
  var inviteShown = /* @__PURE__ */ new WeakMap();
3699
3714
  /**
3715
+ * Refuses DHT only (a hold, `chat transport dht`) while a call is on in the chat. A call's signals cross the live
3716
+ * link: off it, the call talked on over its own connection, and a hang-up from either side never reached the other
3717
+ * (that call ended only when its media stalled out, 16 s later).
3718
+ */
3719
+ function noCallOn(ctx, linkId, then) {
3720
+ const call = ctx.calls.list().find((c) => c.chat === linkId);
3721
+ if (call) throw new CliError("busy", `A call is on in this chat: hang it up first (ghostly call hangup ${linkId}), then ${then}`, { call: call.call });
3722
+ }
3723
+ /**
3700
3724
  * Marks a new invite as the chat on screen (native listeners, the quick pace) only until it is paired: a paired chat
3701
3725
  * keeps its listeners anyway, and a daemon nobody looks at reads an away contact at the background pace, as its
3702
3726
  * other chats and the same chat after a restart do. Nor past its wait for a peer (`AWAITING_PEER_MS`): an invite
@@ -3833,13 +3857,19 @@ var METHODS = {
3833
3857
  return p && (p.stage !== "publishing" || ctx.mode === "daemon" && p.relayWaitUntil) ? p : void 0;
3834
3858
  }, 2e4, "the invite to be published").catch(() => progressOf(state(ctx)));
3835
3859
  const published = !!progress && progress.stage !== "publishing" && progress.reason !== "publish";
3836
- const waitUntil = published ? void 0 : progress?.relayWaitUntil;
3837
- return {
3860
+ const answer = {
3838
3861
  chat: linkId,
3839
3862
  invite: inviteCode,
3840
3863
  link: inviteLink(inviteCode),
3841
- published,
3842
- ...waitUntil !== void 0 && { retryInMs: Math.max(0, waitUntil - Date.now()) }
3864
+ published
3865
+ };
3866
+ if (published) return answer;
3867
+ const waitUntil = progress?.relayWaitUntil;
3868
+ return {
3869
+ ...answer,
3870
+ ...waitUntil !== void 0 && { retryInMs: Math.max(0, waitUntil - Date.now()) },
3871
+ ...progress?.detail && { reason: progress.detail },
3872
+ note: "The invite is good: it goes out by itself once a relay answers, while a daemon runs for this profile"
3843
3873
  };
3844
3874
  },
3845
3875
  async "invite.join"(ctx, params) {
@@ -3993,32 +4023,53 @@ var METHODS = {
3993
4023
  ...until ? { until } : {}
3994
4024
  };
3995
4025
  },
3996
- /** WISP 400 § Reactions: one emoji per person per message, a new one replaces mine; `remove` takes mine back. */
4026
+ /**
4027
+ * WISP 400 § Reactions: one emoji per person per message, a new one replaces mine; `remove` takes mine back.
4028
+ * `wait: confirmed` (a one-shot's default) stays until the contact confirmed it; `confirmed` says whether it has.
4029
+ */
3997
4030
  async "chat.react"(ctx, params) {
3998
4031
  const link = chatNotGroup(ctx, params, "group react", "<message> <emoji>");
4032
+ const { wait, ms } = confirmWait(ctx, params);
4033
+ const before = Math.max(...node(ctx).chatUnconfirmed({ linkId: link.id }).reactions);
4034
+ const result = await react(ctx, link.id, params);
4035
+ const pending = (left) => left.reactions.some((n) => n > before);
4036
+ if (wait === "confirmed") await waitForConfirmed(ctx, link.id, "reaction", pending, ms);
3999
4037
  return {
4000
4038
  chat: link.id,
4001
- ...await react(ctx, link.id, params)
4039
+ ...result,
4040
+ confirmed: !pending(node(ctx).chatUnconfirmed({ linkId: link.id }))
4002
4041
  };
4003
4042
  },
4004
4043
  /**
4005
4044
  * WISP 400 § Pinned message: one per chat or group, a new pin replaces it; `remove` unpins. In a community only the
4006
- * admin pins. Answers the chat (or group) and the message now pinned (null once unpinned).
4045
+ * admin pins. Answers the chat (or group) and the message now pinned (null once unpinned). In a 1:1 chat `wait:
4046
+ * confirmed` (a one-shot's default) stays until the contact confirmed it, and `confirmed` says whether it has.
4007
4047
  */
4008
4048
  async "chat.pin"(ctx, params) {
4009
4049
  const target = chatOrGroup(ctx, str(params, "chat", true));
4010
4050
  const remove = bool(params, "remove"), messageId = remove ? str(params, "message") : str(params, "message", true);
4051
+ if (target.group && params.wait === "confirmed") throw new CliError("bad_request", "A group has no receipts: wait confirmed is for a 1:1 chat");
4052
+ const { wait, ms } = confirmWait(ctx, params);
4011
4053
  const result = await node(ctx).pinMessage({
4012
4054
  linkId: target.linkId,
4013
4055
  ...messageId && { messageId },
4014
4056
  remove
4015
4057
  });
4016
- if (result.error) throw new CliError(/not in this chat|Nothing is pinned/.test(result.error) ? "not_found" : /Only the admin/.test(result.error) ? "refused" : "bad_request", result.error);
4017
- return {
4018
- [target.group ? "group" : "chat"]: target.id,
4058
+ if (result.error) throw new CliError(result.refused || /Only the admin/.test(result.error) ? "refused" : /not in this chat|Nothing is pinned/.test(result.error) ? "not_found" : "bad_request", result.error);
4059
+ if (target.group) return {
4060
+ group: target.id,
4019
4061
  messageId: remove ? null : messageId,
4020
4062
  removed: remove
4021
4063
  };
4064
+ const mine = node(ctx).chatUnconfirmed({ linkId: target.linkId }).pin;
4065
+ const pending = (left) => mine !== null && left.pin === mine;
4066
+ if (wait === "confirmed") await waitForConfirmed(ctx, target.linkId, "pin", pending, ms);
4067
+ return {
4068
+ chat: target.id,
4069
+ messageId: remove ? null : messageId,
4070
+ removed: remove,
4071
+ confirmed: !pending(node(ctx).chatUnconfirmed({ linkId: target.linkId }))
4072
+ };
4022
4073
  },
4023
4074
  /** Saved messages: a mark on a message of a chat or a group, kept for this profile on this device; nothing is sent. */
4024
4075
  async "saved.add"(ctx, params) {
@@ -4031,10 +4082,10 @@ var METHODS = {
4031
4082
  async "saved.list"(ctx) {
4032
4083
  const { links, groups } = state(ctx);
4033
4084
  const saved = await node(ctx).savedMessages();
4034
- const gone = /* @__PURE__ */ new Map();
4035
- 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] : [])));
4085
+ const originals = /* @__PURE__ */ new Map();
4086
+ for (const linkId of new Set(saved.map((s) => s.message.linkId))) originals.set(linkId, await originalsNow(ctx, linkId, saved.flatMap((s) => s.message.linkId === linkId ? [s.message] : [])));
4036
4087
  return saved.map(({ savedAt, message }) => {
4037
- const checked = (json) => quoteChecked(json, message, gone.get(message.linkId));
4088
+ const checked = (json) => quoteChecked(json, message, originals.get(message.linkId));
4038
4089
  if (!message.linkId.startsWith("group:")) return {
4039
4090
  chat: message.linkId,
4040
4091
  savedAt,
@@ -4119,7 +4170,7 @@ var METHODS = {
4119
4170
  };
4120
4171
  },
4121
4172
  async "chat.retry"(ctx, params) {
4122
- const link = chatOf(ctx, params);
4173
+ const link = notAGroup(ctx, params, () => chatOf(ctx, params), () => "a group's message is not sent again by hand, it goes by itself when a member's edge opens");
4123
4174
  const messageId = str(params, "message", true);
4124
4175
  const message = await node(ctx).getMessage(link.id, messageId);
4125
4176
  if (!message) throw new CliError("not_found", `No message ${messageId} in this chat`);
@@ -4137,6 +4188,12 @@ var METHODS = {
4137
4188
  async "chat.delete"(ctx, params) {
4138
4189
  if (bool(params, "everyone")) {
4139
4190
  const target = chatOrGroup(ctx, str(params, "chat", true));
4191
+ const wait = oneOf(params, "wait", ["none", "confirmed"], !target.group && ctx.mode === "one-shot" ? "confirmed" : "none");
4192
+ if (target.group && wait !== "none") throw new CliError("bad_request", "A group has no receipts: --wait confirmed is for a chat");
4193
+ const ms = num(params, "timeout", 30, {
4194
+ min: 1,
4195
+ max: 3600
4196
+ }) * 1e3;
4140
4197
  const ref = str(params, "message", true);
4141
4198
  const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender === "me");
4142
4199
  if (!message) throw new CliError("not_found", `No message ${ref} of yours in this ${target.group ? "group" : "chat"}: only your own messages are deleted for everyone`);
@@ -4145,12 +4202,23 @@ var METHODS = {
4145
4202
  messageId: message.id
4146
4203
  });
4147
4204
  if (result.error) throw new CliError(result.refused ? "refused" : "unavailable", result.error);
4148
- return {
4149
- [target.group ? "group" : "chat"]: target.id,
4205
+ if (target.group) return {
4206
+ group: target.id,
4150
4207
  messageId: message.id,
4151
4208
  deleted: message.id,
4152
4209
  everyone: true
4153
4210
  };
4211
+ if (wait === "confirmed") await waitForRemoval(ctx, target.linkId, message.id, ms);
4212
+ return {
4213
+ chat: target.id,
4214
+ messageId: message.id,
4215
+ deleted: message.id,
4216
+ everyone: true,
4217
+ confirmed: !node(ctx).removalPending({
4218
+ linkId: target.linkId,
4219
+ messageId: message.id
4220
+ })
4221
+ };
4154
4222
  }
4155
4223
  const ref = str(params, "message") ?? "<message>";
4156
4224
  const link = chatNotGroup(ctx, params, "message delete", `${/^[\w.:<>-]+$/.test(ref) ? ref : JSON.stringify(ref)} --everyone`);
@@ -4167,13 +4235,14 @@ var METHODS = {
4167
4235
  everyone: false
4168
4236
  };
4169
4237
  },
4238
+ /** A chat's or a group's (`group:<id>`, or its name) message, as the app's details show it; a group's said `No chat`. */
4170
4239
  async "chat.details"(ctx, params) {
4171
- const link = chatOf(ctx, params);
4240
+ const target = chatOrGroup(ctx, str(params, "chat", true));
4172
4241
  const details = await node(ctx).messageDetails({
4173
- linkId: link.id,
4242
+ linkId: target.linkId,
4174
4243
  messageId: str(params, "message", true)
4175
4244
  });
4176
- if (!details) throw new CliError("not_found", `No message ${String(params.message)} in this chat`);
4245
+ if (!details) throw new CliError("not_found", `No message ${String(params.message)} in this ${target.group ? "group" : "chat"}`);
4177
4246
  return details;
4178
4247
  },
4179
4248
  async "chat.rename"(ctx, params) {
@@ -4195,10 +4264,12 @@ var METHODS = {
4195
4264
  const name = str(params, "transport", true);
4196
4265
  const transport = Object.hasOwn(TRANSPORT_NAMES, name) ? TRANSPORT_NAMES[name] : void 0;
4197
4266
  if (!transport) throw new CliError("bad_request", `transport must be one of auto, dht, webrtc, iroh, hyperdht`);
4267
+ if (transport === "dht") noCallOn(ctx, link.id, "put the chat on DHT only");
4198
4268
  await node(ctx).setChatTransport({
4199
4269
  linkId: link.id,
4200
4270
  transport
4201
4271
  });
4272
+ await releaseHold(ctx, link.id, "lifted", true);
4202
4273
  return chatDetailsJson(findChat(state(ctx).links, link.id));
4203
4274
  },
4204
4275
  /** Reconnects now; a chat held off its direct link (`chat disconnect --hold`) leaves the hold first. */
@@ -4206,7 +4277,11 @@ var METHODS = {
4206
4277
  const link = chatOf(ctx, params);
4207
4278
  await releaseHold(ctx, link.id, "connect");
4208
4279
  inviteTaken(link);
4209
- await node(ctx).connect({ linkId: link.id });
4280
+ dhtOnly(findChat(state(ctx).links, link.id));
4281
+ await connectWithin(ctx, link, num(params, "timeout", CONNECT_MAX_SECONDS, {
4282
+ min: 1,
4283
+ max: CONNECT_MAX_SECONDS
4284
+ }) * 1e3);
4210
4285
  return chatJson(findChat(state(ctx).links, link.id));
4211
4286
  },
4212
4287
  /**
@@ -4223,6 +4298,7 @@ var METHODS = {
4223
4298
  min: 0,
4224
4299
  max: HOLD_MAX_MINUTES
4225
4300
  });
4301
+ if (minutes > 0) noCallOn(ctx, link.id, "hold the chat");
4226
4302
  if (minutes === 0) await releaseHold(ctx, link.id, "lifted");
4227
4303
  else await holdChat(ctx, link, minutes);
4228
4304
  return {
@@ -4289,14 +4365,14 @@ var METHODS = {
4289
4365
  return { groups: state(ctx).groups.map((g) => groupJson(g, showSecret)).sort((a, b) => b.lastMessageAt - a.lastMessageAt) };
4290
4366
  },
4291
4367
  async "group.get"(ctx, params) {
4292
- return groupJson(groupOf(ctx, params), bool(params, "showSecret"));
4368
+ return groupJson(groupOf(ctx, params, "chat show <chat>"), bool(params, "showSecret"));
4293
4369
  },
4294
4370
  async "group.history"(ctx, params) {
4295
- const group = groupOf(ctx, params);
4371
+ const group = groupOf(ctx, params, "chat history <chat>");
4296
4372
  return historyOf(ctx, `group:${group.id}`, params, (m) => groupMessageJson(m, group));
4297
4373
  },
4298
4374
  async "group.send"(ctx, params) {
4299
- const group = groupOf(ctx, params);
4375
+ const group = groupOf(ctx, params, "send <chat> [text...]");
4300
4376
  const text = str(params, "text", true);
4301
4377
  checkTextSize(text);
4302
4378
  if (!bool(params, "force")) {
@@ -4339,10 +4415,10 @@ var METHODS = {
4339
4415
  /**
4340
4416
  * WISP 902 § Edits: the whole new text of one of my messages in a group. It shows here at once and goes to the members
4341
4417
  * (a private group's over the edges that are up, the others when theirs open; a community's through the group).
4342
- * `mentions`: members the new text names beyond those the message named. `sent`: no longer waiting for the pace.
4418
+ * `mentions`: members the new text names beyond those the message named. `sent`: whether an edge took it, as for group send.
4343
4419
  */
4344
4420
  async "group.edit"(ctx, params) {
4345
- const group = groupOf(ctx, params);
4421
+ const group = groupOf(ctx, params, "edit <chat> <message> <text...>");
4346
4422
  const messageId = str(params, "message", true);
4347
4423
  const text = str(params, "text", true);
4348
4424
  if (!bool(params, "force")) {
@@ -4364,8 +4440,7 @@ var METHODS = {
4364
4440
  ...mentions.length ? { mentions } : {}
4365
4441
  });
4366
4442
  if (result.error) throw editRefused(await messageOf(ctx, linkId, messageId), messageId, "group", result.error, result.refused);
4367
- const message = await node(ctx).getMessage(linkId, messageId);
4368
- const edits = message?.edit?.seq ?? 0;
4443
+ const edits = (await node(ctx).getMessage(linkId, messageId))?.edit?.seq ?? 0;
4369
4444
  if (edits === before) return {
4370
4445
  group: group.id,
4371
4446
  messageId,
@@ -4383,12 +4458,12 @@ var METHODS = {
4383
4458
  group: group.id,
4384
4459
  messageId,
4385
4460
  edits,
4386
- sent: edges > 0 || !!message && !message.edit?.pending,
4461
+ sent: edges > 0,
4387
4462
  edges
4388
4463
  };
4389
4464
  },
4390
4465
  async "group.react"(ctx, params) {
4391
- const group = groupOf(ctx, params);
4466
+ const group = groupOf(ctx, params, "react <chat> <message> <emoji>");
4392
4467
  return {
4393
4468
  group: group.id,
4394
4469
  ...await react(ctx, `group:${group.id}`, params)
@@ -4399,7 +4474,7 @@ var METHODS = {
4399
4474
  * how many members), with the same kinds, status rules, 6 s hold and `for`. A community does not carry typing yet.
4400
4475
  */
4401
4476
  async "group.typing"(ctx, params) {
4402
- const group = groupOf(ctx, params);
4477
+ const group = groupOf(ctx, params, "typing <chat>");
4403
4478
  if (group.profile !== "mesh") throw new CliError("unavailable", "A community does not carry typing yet: only a private group does");
4404
4479
  const typing = !bool(params, "stop");
4405
4480
  const { kind, status } = typingWord(params, typing);
@@ -4444,7 +4519,7 @@ var METHODS = {
4444
4519
  };
4445
4520
  },
4446
4521
  async "group.forget"(ctx, params) {
4447
- const group = groupOf(ctx, params);
4522
+ const group = groupOf(ctx, params, "chat remove <chat> --yes");
4448
4523
  if (!bool(params, "yes")) throw new CliError("confirm", "Forgetting a group deletes its history on this device; pass yes (--yes) to go on");
4449
4524
  await node(ctx).forgetGroup({ groupId: group.id });
4450
4525
  return { forgotten: group.id };
@@ -4561,6 +4636,19 @@ async function guardEngineSend(ctx, method, args) {
4561
4636
  const secret = secretIn(texts);
4562
4637
  if (secret) throw new CliError("confirm", `The text looks like ${secret.kind === "cashu" ? "a Cashu token (money anyone who reads it can take)" : "a secret (a seed or a private key)"}; call ${method} with --force if you mean to`, { kind: secret.kind });
4563
4638
  }
4639
+ /**
4640
+ * How long `react` and `pin` in a 1:1 chat wait for the contact: a one-shot until it confirmed (as `edit`), since what
4641
+ * is not said yet leaves with the process; a daemon goes on saying it, so it answers at once unless asked to wait.
4642
+ */
4643
+ function confirmWait(ctx, params) {
4644
+ return {
4645
+ wait: oneOf(params, "wait", ["none", "confirmed"], ctx.mode === "one-shot" ? "confirmed" : "none"),
4646
+ ms: num(params, "timeout", 30, {
4647
+ min: 1,
4648
+ max: 3600
4649
+ }) * 1e3
4650
+ };
4651
+ }
4564
4652
  /** Reacts to a message of a chat or a group (`group:<id>`): `emoji`, or `remove` for "" (WISP 400 § Reactions). */
4565
4653
  async function react(ctx, linkId, params) {
4566
4654
  const messageId = str(params, "message", true);
@@ -4609,28 +4697,31 @@ function groupSendRefused(error) {
4609
4697
  return new CliError("unavailable", error);
4610
4698
  }
4611
4699
  /**
4612
- * A chat command given a group's id, prefix or name: `not_found` that says it is a group, with the group command that
4613
- * takes it (`react` on a group, where `group react` is meant). A name no chat and no group has stays the chat's error.
4700
+ * A chat command given a group's id, prefix or name: `not_found` that says it is a group, with `hint`: the group
4701
+ * command that takes it (`react` on a group, where `group react` is meant), or what to do where none does. `group:<id>`,
4702
+ * the form `pin` and `saved` take, is that group too (it read "No chat" before). A name no chat and no group has stays
4703
+ * the chat's error.
4614
4704
  */
4615
- function notAGroup(ctx, params, chat, command, rest) {
4705
+ function notAGroup(ctx, params, chat, hint) {
4616
4706
  try {
4617
4707
  return chat();
4618
4708
  } catch (error) {
4619
4709
  if (!(error instanceof CliError) || error.code !== "not_found") throw error;
4620
4710
  const ref = str(params, "chat", true);
4711
+ const named = ref.startsWith("group:") ? ref.slice(6) : ref;
4621
4712
  let group;
4622
4713
  try {
4623
- group = findGroup(state(ctx).groups, ref);
4714
+ group = findGroup(state(ctx).groups, named);
4624
4715
  } catch {
4625
4716
  throw error;
4626
4717
  }
4627
- const shown = /^[\w.:-]+$/.test(ref) ? ref : JSON.stringify(ref);
4628
- throw new CliError("not_found", `${JSON.stringify(ref)} is a group, not a chat: ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}`, { group: group.id });
4718
+ const shown = /^[\w.:-]+$/.test(named) ? named : JSON.stringify(named);
4719
+ throw new CliError("not_found", `${JSON.stringify(ref)} is a group, not a chat: ${hint(shown)}`, { group: group.id });
4629
4720
  }
4630
4721
  }
4631
4722
  /** The chat a chat command with a group twin names: a group's name says so, with `command`, the twin (see `notAGroup`). */
4632
4723
  function chatNotGroup(ctx, params, command, rest = "") {
4633
- return notAGroup(ctx, params, () => chatOf(ctx, params), command, rest);
4724
+ return notAGroup(ctx, params, () => chatOf(ctx, params), (shown) => `ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}`);
4634
4725
  }
4635
4726
  /**
4636
4727
  * An edit the engine refused. A message that is not in the chat or group at all is `not_found` (exit 3), naming the id
@@ -4641,6 +4732,29 @@ function editRefused(message, ref, where, error, refused) {
4641
4732
  if (refused && !message) return new CliError("not_found", `No message ${JSON.stringify(ref)} in this ${where}: give the messageId ${where === "group" ? "group send" : "send"} printed`);
4642
4733
  return new CliError(refused ? "refused" : "unavailable", error);
4643
4734
  }
4735
+ /** The chat link's own wait for a contact (`GhostLink.connect`): `chat connect --timeout` waits at most that long. */
4736
+ var CONNECT_MAX_SECONDS = 90;
4737
+ /**
4738
+ * `chat connect`, waiting at most `ms` for the contact; the link's dial goes on behind a shorter wait. Timed out (here,
4739
+ * or by the link's own 90 s), it says what happens next: before, it waited a fixed 90 s and ended "Timed out connecting
4740
+ * to the peer", with no next step.
4741
+ */
4742
+ async function connectWithin(ctx, link, ms) {
4743
+ const dial = node(ctx).connect({ linkId: link.id });
4744
+ let timer;
4745
+ const late = new Promise((resolve) => {
4746
+ timer = setTimeout(() => resolve("late"), ms);
4747
+ });
4748
+ try {
4749
+ if (await Promise.race([dial, late]) !== "late") return;
4750
+ } catch (error) {
4751
+ if (asCliError(error).code !== "timeout") throw error;
4752
+ } finally {
4753
+ clearTimeout(timer);
4754
+ }
4755
+ const shown = /^[\w.:-]+$/.test(link.label ?? "") ? link.label : link.id;
4756
+ throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact did not answer. ${ctx.mode === "one-shot" ? "Try again later, or keep this profile online with `ghostly daemon --detach`: it reconnects by itself" : `It reconnects by itself while this profile is online; ghostly chat wait ${shown} --until live waits for it`}`, { chat: link.id });
4757
+ }
4644
4758
  /**
4645
4759
  * A page of a chat's or a group's history. Without `after` only that page is read from the store (the newest, or those
4646
4760
  * before `before`), so a long chat's is as quick as a short one's; with `after` the whole history is read and cut.
@@ -4663,9 +4777,9 @@ async function saveMark(ctx, params, remove) {
4663
4777
  async function historyOf(ctx, chat, params, json = messageJson) {
4664
4778
  if (params.after !== void 0 && params.after !== null) {
4665
4779
  const whole = await node(ctx).getMessages(chat), { messages, more } = history(whole, params);
4666
- const gone = await originalsGone(ctx, chat, messages, whole);
4780
+ const originals = await originalsNow(ctx, chat, messages, whole);
4667
4781
  return {
4668
- messages: messages.map((m) => quoteChecked(json(m), m, gone)),
4782
+ messages: messages.map((m) => quoteChecked(json(m), m, originals)),
4669
4783
  more
4670
4784
  };
4671
4785
  }
@@ -4683,34 +4797,39 @@ async function historyOf(ctx, chat, params, json = messageJson) {
4683
4797
  }).catch((error) => {
4684
4798
  throw error instanceof Error && error.message === `No message ${before}` ? new CliError("not_found", error.message) : error;
4685
4799
  });
4686
- const gone = await originalsGone(ctx, chat, page.messages);
4800
+ const originals = await originalsNow(ctx, chat, page.messages);
4687
4801
  return {
4688
- messages: page.messages.map((m) => quoteChecked(json(m), m, gone)),
4802
+ messages: page.messages.map((m) => quoteChecked(json(m), m, originals)),
4689
4803
  more: page.more
4690
4804
  };
4691
4805
  }
4692
4806
  /** Past this many originals outside a page, its history is read once instead of row by row. */
4693
4807
  var ORIGINAL_READS = 32;
4694
4808
  /**
4695
- * The originals a page's replies found here when they came that are gone now: deleted on this device, or for everyone
4696
- * by their author (WISP 400 § Delete for everyone). Each is looked for in the page, else read as its one row, one at
4697
- * a time (a burst of reads stalls fake-indexeddb's scheduler); `whole` is the chat's whole history when it was read
4698
- * already. Before, such a reply still said `found`, with the original's text.
4809
+ * The originals a page's replies found here when they came, as they are now: gone (deleted on this device, or for
4810
+ * everyone by their author: WISP 400 § Delete for everyone), or the row, edited since or not. Each is looked for in the
4811
+ * page, else read as its one row, one at a time (a burst of reads stalls fake-indexeddb's scheduler); `whole` is the
4812
+ * chat's whole history when it was read already. Before, such a reply still said `found`, with the original's text.
4813
+ */
4814
+ async function originalsNow(ctx, chat, page, whole = page) {
4815
+ const here = new Map(whole.map((m) => [m.id, m]));
4816
+ const named = [...new Set(page.flatMap((m) => m.replyTo?.messageId ? [m.replyTo.messageId] : []))];
4817
+ const asked = named.filter((id) => !here.has(id));
4818
+ if (whole === page && asked.length > ORIGINAL_READS) return originalsNow(ctx, chat, page, await node(ctx).getMessages(chat));
4819
+ const originals = new Map(named.flatMap((id) => here.has(id) ? [[id, here.get(id)]] : []));
4820
+ for (const id of asked) originals.set(id, whole === page ? await node(ctx).getMessage(chat, id) : void 0);
4821
+ return originals;
4822
+ }
4823
+ /**
4824
+ * A reply's quote as the apps show it (`quoteFor`): an original gone reads "Original message deleted", not found and
4825
+ * none of its text; one edited since the reply quotes its text as it reads now. A button press keeps the question as
4826
+ * it was answered (WISP 406 · Message Buttons), and a card's or a file's line stays the one the reply carries.
4699
4827
  */
4700
- async function originalsGone(ctx, chat, page, whole = page) {
4701
- const here = new Set(whole.map((m) => m.id));
4702
- const asked = [...new Set(page.flatMap((m) => m.replyTo?.messageId && !here.has(m.replyTo.messageId) ? [m.replyTo.messageId] : []))];
4703
- if (whole !== page) return new Set(asked);
4704
- if (asked.length > ORIGINAL_READS) return originalsGone(ctx, chat, page, await node(ctx).getMessages(chat));
4705
- const gone = /* @__PURE__ */ new Set();
4706
- for (const id of asked) if (!await node(ctx).getMessage(chat, id)) gone.add(id);
4707
- return gone;
4708
- }
4709
- /** A reply whose original is gone, as the apps show it ("Original message deleted"): not found, and none of its text. */
4710
- function quoteChecked(json, message, gone) {
4828
+ function quoteChecked(json, message, originals) {
4711
4829
  const id = message.replyTo?.messageId;
4712
- if (!json.replyTo || !id || !gone.has(id)) return json;
4713
- return {
4830
+ if (!json.replyTo || !id || !originals.has(id)) return json;
4831
+ const original = originals.get(id);
4832
+ if (!original) return {
4714
4833
  ...json,
4715
4834
  replyTo: {
4716
4835
  ...json.replyTo,
@@ -4719,6 +4838,14 @@ function quoteChecked(json, message, gone) {
4719
4838
  deleted: true
4720
4839
  }
4721
4840
  };
4841
+ if (!original.edit || json.replyTo.button || original.card || original.file) return json;
4842
+ return {
4843
+ ...json,
4844
+ replyTo: {
4845
+ ...json.replyTo,
4846
+ snippet: replySnippet(original.text)
4847
+ }
4848
+ };
4722
4849
  }
4723
4850
  function history(messages, params) {
4724
4851
  const limit = num(params, "limit", 50, {
@@ -4756,4 +4883,4 @@ async function callApi(ctx, method, params = {}) {
4756
4883
  //#endregion
4757
4884
  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 };
4758
4885
 
4759
- //# sourceMappingURL=api-tSZELCPQ.js.map
4886
+ //# sourceMappingURL=api-tf-wAAnB.js.map