@ghostlytools/cli 1.11.3 → 1.11.4

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 (92) hide show
  1. package/README.md +27 -22
  2. package/SKILL.md +4 -2
  3. package/dist/assets/{api-DgU4MZPD.js → api-BwyFq4lA.js} +2 -2
  4. package/dist/assets/{api-DBlaoz8i.js → api-MYc6QNRs.js} +187 -87
  5. package/dist/assets/api-MYc6QNRs.js.map +1 -0
  6. package/dist/assets/{apiKit-DesObIDf.js → apiKit-CfsNx9ZR.js} +60 -14
  7. package/dist/assets/apiKit-CfsNx9ZR.js.map +1 -0
  8. package/dist/assets/{appFetch-C8yZIq1e.js → appFetch-DVYZOZFw.js} +2 -2
  9. package/dist/assets/{appFetch-C8yZIq1e.js.map → appFetch-DVYZOZFw.js.map} +1 -1
  10. package/dist/assets/{apps-rzxsjfBV.js → apps-Dbw2Hcko.js} +1 -1
  11. package/dist/assets/{apps-DkMjDHML.js → apps-h12II1us.js} +52 -30
  12. package/dist/assets/apps-h12II1us.js.map +1 -0
  13. package/dist/assets/{arkade-CarKONmH.js → arkade-Bw_4PZRG.js} +2 -2
  14. package/dist/assets/{arkade-CarKONmH.js.map → arkade-Bw_4PZRG.js.map} +1 -1
  15. package/dist/assets/{backup-CgWU7x0T.js → backup-CdEzTq5C.js} +1 -1
  16. package/dist/assets/{backup-C0OJCJlM.js → backup-Chvy79SN.js} +49 -36
  17. package/dist/assets/backup-Chvy79SN.js.map +1 -0
  18. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
  19. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  20. package/dist/assets/{buttons-fZTEa_2i.js → buttons-BgoExb4E.js} +6 -5
  21. package/dist/assets/{buttons-fZTEa_2i.js.map → buttons-BgoExb4E.js.map} +1 -1
  22. package/dist/assets/buttons-DK2aAGat.js +2 -0
  23. package/dist/assets/{client-Ibk3-e60.js → client-DY8tZZWi.js} +28 -8
  24. package/dist/assets/client-DY8tZZWi.js.map +1 -0
  25. package/dist/assets/{codec-DMpQqVSt.js → codec-BnMg-Grj.js} +2 -2
  26. package/dist/assets/{codec-DMpQqVSt.js.map → codec-BnMg-Grj.js.map} +1 -1
  27. package/dist/assets/{envelope-CvQVCGdf.js → envelope-CdV7vHVZ.js} +2 -2
  28. package/dist/assets/{envelope-CvQVCGdf.js.map → envelope-CdV7vHVZ.js.map} +1 -1
  29. package/dist/assets/{errors-Dt-ZnyOX.js → errors-CAh6GLJZ.js} +27 -2
  30. package/dist/assets/errors-CAh6GLJZ.js.map +1 -0
  31. package/dist/assets/{fedimintSdk-zV_5Qdqz.js → fedimintSdk-CPFfVK-G.js} +2 -2
  32. package/dist/assets/{fedimintSdk-zV_5Qdqz.js.map → fedimintSdk-CPFfVK-G.js.map} +1 -1
  33. package/dist/assets/{fixedHosts-6gKn8dp2.js → fixedHosts-CbgqrIKs.js} +3 -3
  34. package/dist/assets/{fixedHosts-6gKn8dp2.js.map → fixedHosts-CbgqrIKs.js.map} +1 -1
  35. package/dist/assets/{host-CYlIiY3r.js → host-C0NMNQLl.js} +556 -126
  36. package/dist/assets/host-C0NMNQLl.js.map +1 -0
  37. package/dist/assets/{hyperdhtRelay-CdsLcAhY.js → hyperdhtRelay-Dz7pvcBA.js} +2 -2
  38. package/dist/assets/{hyperdhtRelay-CdsLcAhY.js.map → hyperdhtRelay-Dz7pvcBA.js.map} +1 -1
  39. package/dist/assets/{irohWeb-D2IuloLL.js → irohWeb-caAj4Dms.js} +7 -7
  40. package/dist/assets/{irohWeb-D2IuloLL.js.map → irohWeb-caAj4Dms.js.map} +1 -1
  41. package/dist/assets/{main-C0PfjKTe.js → main-C6t5zrD5.js} +298 -92
  42. package/dist/assets/main-C6t5zrD5.js.map +1 -0
  43. package/dist/assets/{mainline-Cu61qcPS.js → mainline-DCuGUSZF.js} +2 -2
  44. package/dist/assets/{mainline-Cu61qcPS.js.map → mainline-DCuGUSZF.js.map} +1 -1
  45. package/dist/assets/{networkReason-Dt7Yx_n4.js → networkReason-BbQW1Xpc.js} +3 -3
  46. package/dist/assets/{networkReason-Dt7Yx_n4.js.map → networkReason-BbQW1Xpc.js.map} +1 -1
  47. package/dist/assets/{nwc-CtZypDcv.js → nwc-CSDRMZ0e.js} +3 -3
  48. package/dist/assets/{nwc-CtZypDcv.js.map → nwc-CSDRMZ0e.js.map} +1 -1
  49. package/dist/assets/{nwcProvider-DYHkd0iu.js → nwcProvider-PE0wli8n.js} +2 -2
  50. package/dist/assets/{nwcProvider-DYHkd0iu.js.map → nwcProvider-PE0wli8n.js.map} +1 -1
  51. package/dist/assets/{ownDid-CJ0ta8CL.js → ownDid-C1R5Kd8q.js} +2 -2
  52. package/dist/assets/{ownDid-CJ0ta8CL.js.map → ownDid-C1R5Kd8q.js.map} +1 -1
  53. package/dist/assets/{ownStatus-D4HC6tNR.js → ownStatus-BoTf5WqQ.js} +19 -6
  54. package/dist/assets/ownStatus-BoTf5WqQ.js.map +1 -0
  55. package/dist/assets/{profiles-Ccdq6Xf6.js → profiles-DszHjEJi.js} +25 -10
  56. package/dist/assets/profiles-DszHjEJi.js.map +1 -0
  57. package/dist/assets/{registry-LvxsLJ5S.js → registry-Da-r6eC3.js} +17 -10
  58. package/dist/assets/registry-Da-r6eC3.js.map +1 -0
  59. package/dist/assets/{registry-CE0PpQAE.js → registry-zUZBSHYv.js} +1 -1
  60. package/dist/assets/{resolve-6kVu2DE5.js → resolve-tUzh4lHh.js} +2 -2
  61. package/dist/assets/{resolve-6kVu2DE5.js.map → resolve-tUzh4lHh.js.map} +1 -1
  62. package/dist/assets/{secretGuard-B7Hj0Kvz.js → secretGuard-CsVHDdYk.js} +68 -6
  63. package/dist/assets/{secretGuard-B7Hj0Kvz.js.map → secretGuard-CsVHDdYk.js.map} +1 -1
  64. package/dist/assets/secretGuard-DCb1I0_B.js +2 -0
  65. package/dist/assets/{server-Q3VcNqGt.js → server-C1jZZ61O.js} +667 -196
  66. package/dist/assets/server-C1jZZ61O.js.map +1 -0
  67. package/dist/assets/{src-DjVj2ynY.js → src-DJe-OYxd.js} +826 -198
  68. package/dist/assets/src-DJe-OYxd.js.map +1 -0
  69. package/dist/assets/{sshForges-DeZ9cN9Q.js → sshForges-C9zTO72R.js} +2 -2
  70. package/dist/assets/{sshForges-DeZ9cN9Q.js.map → sshForges-C9zTO72R.js.map} +1 -1
  71. package/dist/assets/{translate-iQZq4TnY.js → translate-CUuC5szR.js} +3 -3
  72. package/dist/assets/{translate-iQZq4TnY.js.map → translate-CUuC5szR.js.map} +1 -1
  73. package/dist/assets/{usdt-DnyTGdTX.js → usdt-DI51znt-.js} +3 -3
  74. package/dist/assets/{usdt-DnyTGdTX.js.map → usdt-DI51znt-.js.map} +1 -1
  75. package/dist/ghostly.mjs +1 -1
  76. package/npm-shrinkwrap.json +2 -2
  77. package/package.json +1 -1
  78. package/dist/assets/api-DBlaoz8i.js.map +0 -1
  79. package/dist/assets/apiKit-DesObIDf.js.map +0 -1
  80. package/dist/assets/apps-DkMjDHML.js.map +0 -1
  81. package/dist/assets/backup-C0OJCJlM.js.map +0 -1
  82. package/dist/assets/buttons-Cco0Agfa.js +0 -2
  83. package/dist/assets/client-Ibk3-e60.js.map +0 -1
  84. package/dist/assets/errors-Dt-ZnyOX.js.map +0 -1
  85. package/dist/assets/host-CYlIiY3r.js.map +0 -1
  86. package/dist/assets/main-C0PfjKTe.js.map +0 -1
  87. package/dist/assets/ownStatus-D4HC6tNR.js.map +0 -1
  88. package/dist/assets/profiles-Ccdq6Xf6.js.map +0 -1
  89. package/dist/assets/registry-LvxsLJ5S.js.map +0 -1
  90. package/dist/assets/secretGuard-DUr6bgKc.js +0 -2
  91. package/dist/assets/server-Q3VcNqGt.js.map +0 -1
  92. package/dist/assets/src-DjVj2ynY.js.map +0 -1
@@ -1,18 +1,19 @@
1
- import { Ba as sanitizeFileName, Cd as toBase64Url, Co as replySnippet, Dl as isAppUrl, Fl as appRef, Fo as appCardUrl, Ga as baseMime, Gn as NO_PICTURE_METADATA, Go as claimedTime, Ha as PLAYABLE_AUDIO, Ja as parseVoiceMeta, Jn as stripPictureMetadata, Ju as relayUrlProblem, Ka as downsamplePeaks, Lo as cardLine, Mo as STATUS_CARD_LIMITS, Po as appCardId, Sd as randomBytes$1, Sl as APP_PERMISSIONS, Ss as LIMITS, Ua as VOICE_LIMITS, Uo as MESSAGE_CLOCK_SKEW_MS, Va as sanitizeMime, Vl as isAppRef, Vn as withoutAudioMetadata, Vo as statusCardBytes, Wa as VOICE_METER, Wn as withoutVideoMetadata, Xa as voiceLevel, Ya as voiceDownloadName, Yl as readImageMeta, Yn as withoutPictureMetadata, Zi as identityStatement, bs as parseLocalTarget, du as ownInviteRefusal, ii as TYPING_REFRESH_MS, ki as APP_DATA_MAX_BYTES, lu as inviteLink, md as sanitizeAvatar, oi as sanitizeTypingStatus, pd as MAX_AVATAR_LENGTH, qu as normalizeRelayUrl, ri as TYPING_KINDS, sr as GROUP_FILE_LIMITS, us as AWAITING_PEER_MS, vs as GhostlyHttpError, zo as checkStatusCard } from "./src-DjVj2ynY.js";
1
+ import { $i as identityStatement, Cd as randomBytes$1, Ga as VOICE_LIMITS, Go as MESSAGE_CLOCK_SKEW_MS, Ha as sanitizeFileName, Hl as isAppRef, Il as appRef, Io as appCardId, Ja as downsamplePeaks, Ju as normalizeRelayUrl, Ka as VOICE_METER, Kn as withoutVideoMetadata, Lo as appCardUrl, Ol as isAppUrl, Po as STATUS_CARD_LIMITS, Qa as voiceLevel, Ss as parseLocalTarget, To as replySnippet, Ua as sanitizeMime, Un as withoutAudioMetadata, Uo as statusCardBytes, Vo as checkStatusCard, Wa as PLAYABLE_AUDIO, Xa as parseVoiceMeta, Xl as readImageMeta, Xn as stripPictureMetadata, Yu as relayUrlProblem, Za as voiceDownloadName, Zn as withoutPictureMetadata, ai as TYPING_KINDS, bs as GhostlyHttpError, ci as sanitizeTypingStatus, fs as AWAITING_PEER_MS, fu as ownInviteRefusal, hd as sanitizeAvatar, ji as APP_DATA_MAX_BYTES, lr as GROUP_FILE_LIMITS, md as MAX_AVATAR_LENGTH, oi as TYPING_REFRESH_MS, pn as parsePaymentAmount, qa as baseMime, qn as NO_PICTURE_METADATA, qo as claimedTime, uu as inviteLink, wd as toBase64Url, ws as LIMITS, zo as cardLine } from "./src-DJe-OYxd.js";
2
2
  import { p as fileStore } from "./idb-CEuoNsTv.js";
3
3
  import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-BLPZq9YU.js";
4
- import { B as removeStored, U as waitingGroupFile, W as IDENTITY_DRAFT_TTL_MS, a as groupMemberOfLink, b as replyRef, c as groupPayTwin, ft as iceServerProblem, h as groupOfFile, k as paymentNetwork, o as groupPayLineId, p as groupFileId, pt as iceServerSetting, s as groupPayNoteId, t as DEFAULT_IROH_RELAYS } from "./irohWeb-D2IuloLL.js";
5
- import { t as IDENTITY_PROVIDERS } from "./registry-LvxsLJ5S.js";
6
- import { n as secretWords, r as findSecret, t as guardText } from "./secretGuard-B7Hj0Kvz.js";
7
- import { i as localFileError, r as asCliError, t as CliError } from "./errors-Dt-ZnyOX.js";
8
- import { a as PAY_METHODS, d as ENGINE_METHODS, f as ENGINE_PARAMS, g as engineParamsProblem, i as CHAT_METHODS, l as withStoredIds, m as READ_PARAMS, n as statusJson, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus, u as DESTRUCTIVE_CALLS } from "./ownStatus-D4HC6tNR.js";
9
- import { A as sinceSeq, D as oneShotWaits, E as oneOf, F as transportOffered, I as waitForState, N as state, O as sentAt, P as str, S as nobodyJoined, T as num, _ as messageOf, a as contactKeyOf, b as noFile, c as findChatOrGroup, d as groupNameOf, f as groupOf, g as list, h as keptForJoin, j as somebodyJoined, k as shownName, l as findGroup, m as inviteTaken, n as chatOf, o as dhtOnly, p as groupPrefixed, r as chatOrGroup, s as findChat, t as bool, u as findOwnNamedChat, w as node, x as noMessage } from "./apiKit-DesObIDf.js";
4
+ import { B as removeStored, U as waitingGroupFile, W as IDENTITY_DRAFT_TTL_MS, a as groupMemberOfLink, b as replyRef, c as groupPayTwin, ft as iceServerProblem, h as groupOfFile, k as paymentNetwork, o as groupPayLineId, p as groupFileId, pt as iceServerSetting, s as groupPayNoteId, t as DEFAULT_IROH_RELAYS } from "./irohWeb-caAj4Dms.js";
5
+ import { s as isAppFetchUrl } from "./appFetch-DVYZOZFw.js";
6
+ import { i as parseProofBunker, t as IDENTITY_PROVIDERS } from "./registry-Da-r6eC3.js";
7
+ import { n as secretWords, r as findSecret, t as guardText } from "./secretGuard-CsVHDdYk.js";
8
+ import { i as localFileError, r as asCliError, t as CliError } from "./errors-CAh6GLJZ.js";
9
+ import { a as PAY_METHODS, d as ENGINE_METHODS, f as ENGINE_PARAMS, g as engineParamsProblem, i as CHAT_METHODS, l as withStoredIds, m as READ_PARAMS, n as statusJson, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus, u as DESTRUCTIVE_CALLS } from "./ownStatus-BoTf5WqQ.js";
10
+ import { A as settingsOf, D as oneShotWaits, E as oneOf, F as state, I as str, L as transportOffered, M as sinceSeq, N as somebodyJoined, O as ownChatOf, R as waitForState, S as nobodyJoined, T as num, _ as messageOf, a as contactKeyOf, b as noFile, c as findChatOrGroup, d as groupNameOf, f as groupOf, g as list, h as keptForJoin, j as shownName, k as sentAt, l as findGroup, m as inviteTaken, n as chatOf, o as dhtOnly, p as groupPrefixed, r as chatOrGroup, s as findChat, t as bool, w as node, x as noMessage } from "./apiKit-CfsNx9ZR.js";
10
11
  import { t as childEnv } from "./childEnv-K_IzUqQx.js";
11
12
  import { t as chatState } from "./waitNotice-Cn0WJ-He.js";
12
- import { a as checkTextSize$1, c as waitForConfirmed, d as waitForMessage, f as waitForRemoval, i as pressable, l as waitForEdit, n as buttonsCard, o as goesOn, s as nobodyElseIn, t as BUTTON_METHODS, u as waitForGroupFrame } from "./buttons-fZTEa_2i.js";
13
- import { a as checkShownName } from "./profiles-Ccdq6Xf6.js";
14
- import { t as BACKUP_METHODS } from "./backup-C0OJCJlM.js";
15
- import { o as checkedBundle } from "./apps-DkMjDHML.js";
13
+ import { a as checkTextSize$1, c as waitForConfirmed, d as waitForMessage, f as waitForRemoval, i as pressable, l as waitForEdit, n as buttonsCard, o as goesOn, s as nobodyElseIn, t as BUTTON_METHODS, u as waitForGroupFrame } from "./buttons-BgoExb4E.js";
14
+ import { a as checkShownName } from "./profiles-DszHjEJi.js";
15
+ import { t as BACKUP_METHODS } from "./backup-Chvy79SN.js";
16
+ import { o as checkedBundle } from "./apps-h12II1us.js";
16
17
  import { generateMnemonic } from "@scure/bip39";
17
18
  import { wordlist } from "@scure/bip39/wordlists/english.js";
18
19
  import { execFile, spawn } from "node:child_process";
@@ -292,6 +293,10 @@ async function* piecesOf(file, size, piece) {
292
293
  function ascii(bytes, at, length) {
293
294
  return String.fromCharCode(...bytes.subarray(at, at + length));
294
295
  }
296
+ /** The channels and rates a WAV's sound may have (ffmpeg's DSD at 705.6 kHz among them). */
297
+ var WAV_MAX_CHANNELS = 255;
298
+ var WAV_MIN_RATE = 1e3;
299
+ var WAV_MAX_RATE = 768e3;
295
300
  /** The format of a WAV and where its samples are; null while its header is not all there. */
296
301
  function wavHeader(bytes) {
297
302
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -313,6 +318,7 @@ function wavHeader(bytes) {
313
318
  }
314
319
  } else if (id === "data") {
315
320
  if (!channels || !sampleRate || !bits) throw new NotSound("a WAV without its format");
321
+ if (channels > WAV_MAX_CHANNELS || sampleRate < WAV_MIN_RATE || sampleRate > WAV_MAX_RATE) throw new NotSound(`a WAV with ${channels} channel${channels === 1 ? "" : "s"} at ${sampleRate} Hz, which no sound has`);
316
322
  const to = size === 0 || size === 4294967295 ? Infinity : body + size;
317
323
  return {
318
324
  format,
@@ -794,15 +800,16 @@ function withWaitingFor(transfer) {
794
800
  };
795
801
  }
796
802
  /** The chat or the group a file command names (`findChatOrGroup`). */
797
- var chatOrGroupOf = (ctx, params) => findChatOrGroup(state(ctx).links, state(ctx).groups, str(params, "chat", true));
803
+ var chatOrGroupOf = (ctx, params, { links, groups } = state(ctx)) => findChatOrGroup(links, groups, str(params, "chat", true));
798
804
  /**
799
805
  * The chat or group a file belongs to: a file id starts with its chat's id (a group's file with `group-<id>-`), so it
800
806
  * may be left out; given, it must be the file's own. `where` is what the answer names it by.
801
807
  */
802
808
  function fileChat(ctx, params, fileId) {
803
- const groupId = groupOfFile(fileId, state(ctx).groups.map((g) => g.id));
809
+ const s = state(ctx);
810
+ const groupId = groupOfFile(fileId, s.groups.map((g) => g.id));
804
811
  if (groupId) {
805
- const named = params.chat === void 0 ? void 0 : chatOrGroupOf(ctx, params);
812
+ const named = params.chat === void 0 ? void 0 : chatOrGroupOf(ctx, params, s);
806
813
  if (named && !("group" in named && named.group.id === groupId)) throw noFile(fileId, {
807
814
  group: "group" in named,
808
815
  ref: str(params, "chat", true)
@@ -812,7 +819,7 @@ function fileChat(ctx, params, fileId) {
812
819
  where: { group: groupId }
813
820
  };
814
821
  }
815
- const link = params.chat === void 0 ? state(ctx).links.find((l) => fileId.startsWith(`${l.id}-in-`) || fileId.startsWith(`${l.id}-out-`)) : chatOf(ctx, params);
822
+ const link = params.chat === void 0 ? s.links.find((l) => fileId.startsWith(`${l.id}-in-`) || fileId.startsWith(`${l.id}-out-`)) : chatOf(ctx, params, s);
816
823
  if (!link) throw noFile(fileId);
817
824
  if (!fileId.startsWith(`${link.id}-`)) throw noFile(fileId, {
818
825
  group: false,
@@ -1075,15 +1082,7 @@ async function waitForFile(ctx, params, stopping) {
1075
1082
  ...where,
1076
1083
  retry: !!transfer.retry
1077
1084
  });
1078
- if (transfer.state !== "done") {
1079
- const name = (stored ?? await fileStore.get(fileId).catch(() => void 0))?.metadata?.name ?? "The file";
1080
- throw new CliError("confirm", `${name} (${megabytes(transfer.size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
1081
- file: fileId,
1082
- ...where,
1083
- size: transfer.size,
1084
- stage: "asking"
1085
- });
1086
- }
1085
+ if (transfer.state !== "done") throw waitsForYou((stored ?? await fileStore.get(fileId).catch(() => void 0))?.metadata?.name, fileId, where, transfer.size);
1087
1086
  return {
1088
1087
  ...where,
1089
1088
  file: fileId,
@@ -1091,6 +1090,15 @@ async function waitForFile(ctx, params, stopping) {
1091
1090
  size: transfer.size
1092
1091
  };
1093
1092
  }
1093
+ /** A received file that waits for this person's `file accept` (`file wait`, `file save`): said naming the command. */
1094
+ function waitsForYou(name, fileId, where, size) {
1095
+ return new CliError("confirm", `${name ?? "The file"} (${megabytes(size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
1096
+ file: fileId,
1097
+ ...where,
1098
+ size,
1099
+ stage: "asking"
1100
+ });
1101
+ }
1094
1102
  var FILE_METHODS = {
1095
1103
  async "file.send"(ctx, params) {
1096
1104
  const path = resolve(str(params, "path", true));
@@ -1278,6 +1286,7 @@ var FILE_METHODS = {
1278
1286
  }
1279
1287
  const view = state(ctx).transfers[fileId];
1280
1288
  if ((action === "resume" || action === "request" || action === "resend") && view?.stage === "paused" && view.pausedBy === "peer") throw new CliError("refused", "Paused by the contact: it goes on when they resume it");
1289
+ if ((action === "pause" || action === "resume" || action === "request") && view?.stage === "asking" && view.direction === "in") throw new CliError("refused", "Not taken yet: it waits for you to take it (file accept, or file decline)");
1281
1290
  await node(ctx).fileAction({
1282
1291
  linkId,
1283
1292
  fileId,
@@ -1308,8 +1317,15 @@ var FILE_METHODS = {
1308
1317
  const stored = await fileStore.get(fileId);
1309
1318
  if (!stored?.metadata) throw noFile(fileId);
1310
1319
  if (stored.leftOut) throw new CliError("not_found", "Not in this backup: the light backup this profile was restored from left the file out");
1311
- const transfer = stored.direction === "out" ? void 0 : state(ctx).transfers[fileId] ?? stored.transfer;
1320
+ const transfer = stored.direction === "out" ? void 0 : state(ctx).transfers[fileId] ?? waitingGroupFile(stored) ?? stored.transfer;
1312
1321
  if (transfer?.state === "failed") throw new CliError("refused", `It ended: ${transfer.error ?? "failed"}`);
1322
+ if (transfer?.state === "transferring" && transfer.stage === "asking" && transfer.direction === "in") {
1323
+ let where;
1324
+ try {
1325
+ where = fileChat(ctx, params, fileId).where;
1326
+ } catch {}
1327
+ throw waitsForYou(stored.metadata.name, fileId, where, transfer.size);
1328
+ }
1313
1329
  if (transfer && transfer.state !== "done") throw new CliError("unavailable", `The file is not all here yet (${transfer.transferred} of ${transfer.size} bytes)`);
1314
1330
  const named = str(params, "path") ? resolve(str(params, "path", true)) : join(resolve(str(params, "dir") ?? "."), saveName(stored.metadata.voice ? voiceDownloadName(stored.metadata.mime, await voiceTime(ctx, stored)) : stored.metadata.name));
1315
1331
  const force = bool(params, "force");
@@ -1320,7 +1336,12 @@ var FILE_METHODS = {
1320
1336
  const taken = async (target, code) => {
1321
1337
  const there = await stat(target).catch(() => void 0);
1322
1338
  if (there?.isDirectory()) return new CliError("bad_request", `${target} is a folder: name a file, or use --dir ${target} (dir over the socket)`);
1323
- if (there && !force || code === "EEXIST") return new CliError("confirm", `${target} exists: pass --force (force: true over the socket) to replace it`);
1339
+ if (!(there && !force || code === "EEXIST")) return;
1340
+ const replace = `${target} exists: pass --force (force: true over the socket) to replace it`;
1341
+ if (path) return new CliError("confirm", replace);
1342
+ let n = 2;
1343
+ while (n <= 1e3 && await stat(`${stem} (${n})${ext}`).catch(() => void 0)) n += 1;
1344
+ return new CliError("confirm", `${replace}, or --path ${stem} (${n})${ext} (path over the socket) to keep both`);
1324
1345
  };
1325
1346
  let target = named;
1326
1347
  for (let n = 2, refused = await taken(target); refused; n += 1, refused = await taken(target)) {
@@ -2310,7 +2331,9 @@ function groupJson(group, showSecret = false) {
2310
2331
  chat: group.invitation.linkId,
2311
2332
  accepted: group.invitation.accepted,
2312
2333
  viaLink: !!group.invitation.viaLink,
2313
- stage: group.invitation.stage ?? null
2334
+ stage: group.invitation.stage ?? null,
2335
+ ...group.invitation.unanswered ? { unanswered: true } : {},
2336
+ ...group.invitation.takenBack ? { takenBack: true } : {}
2314
2337
  } : null,
2315
2338
  ...group.others?.length ? { others: group.others.map((o) => "link" in o ? { link: showSecret ? o.link : "<hidden>" } : {
2316
2339
  chat: o.linkId,
@@ -2406,12 +2429,12 @@ function joined(ctx, params, twin) {
2406
2429
  throw new CliError("refused", group.invitation.accepted ? `You are not in ${group.name} yet: you accepted its invitation, and its admin has not let you in` : `You are not in ${group.name} yet: ghostly group accept ${shown} joins it`);
2407
2430
  }
2408
2431
  /** The member `params.member` names in `group`, this profile's own name said to be it; by its key only for a grant. */
2409
- var member = (ctx, group, params, grant = false) => findMember(group, str(params, "member", true), state(ctx).settings.nick, grant);
2432
+ var member = (ctx, group, params, grant = false) => findMember(group, str(params, "member", true), settingsOf(ctx).nick, grant);
2410
2433
  var view = (ctx, id, params) => groupJson(state(ctx).groups.find((g) => g.id === id) ?? groupOf(ctx, { group: id }), bool(params, "showSecret"));
2411
2434
  var GROUP_ADMIN_METHODS = {
2412
2435
  async "group.invite"(ctx, params) {
2413
2436
  const group = joined(ctx, params);
2414
- const link = findOwnNamedChat(state(ctx).links, str(params, "chat", true), state(ctx).groups);
2437
+ const link = ownChatOf(ctx, params);
2415
2438
  await node(ctx).inviteToGroup({
2416
2439
  groupId: group.id,
2417
2440
  linkId: link.id
@@ -2534,7 +2557,7 @@ function headless(s) {
2534
2557
  function signerOf(p, id) {
2535
2558
  const usable = p.signers.filter(headless);
2536
2559
  const found = id ? p.signers.find((s) => s.id === id) : usable[0];
2537
- if (!found) throw new CliError(id ? "not_found" : "unavailable", id ? `${p.label} has no signer ${id}` : `${p.label} proofs need a browser window: make them in the app`);
2560
+ if (!found) throw new CliError(id ? "not_found" : "unavailable", id ? `${p.label} has no signer ${id}` : `${p.label}: this kind of proof needs a browser window, make it in the app`);
2538
2561
  if (!headless(found)) {
2539
2562
  const instead = usable.length ? ` (here: --signer ${usable.map((s) => s.id).join(" or ")})` : "";
2540
2563
  throw new CliError("unavailable", `${found.label} needs a browser window: make this proof in the app${instead}`);
@@ -2645,6 +2668,12 @@ var IDENTITY_METHODS = {
2645
2668
  const values = params.fields ?? {};
2646
2669
  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");
2647
2670
  for (const field of signer.fields ?? []) if (!field.optional && !values[field.name]) throw new CliError("usage", `${signer.label} needs ${field.name} (${field.label}): ${howToGive(field)}`);
2671
+ const bunker = signer.fields?.find((f) => f.name === "bunker");
2672
+ if (bunker && values.bunker) try {
2673
+ parseProofBunker(values.bunker);
2674
+ } catch (error) {
2675
+ throw new CliError("bad_request", `${bunker.name} (${bunker.label}): ${error instanceof Error ? error.message : String(error)}`);
2676
+ }
2648
2677
  const seconds = num(params, "timeout", 300, {
2649
2678
  min: 5,
2650
2679
  max: 3600
@@ -2764,9 +2793,10 @@ var IDENTITY_METHODS = {
2764
2793
  return { removed: id };
2765
2794
  },
2766
2795
  async "identity.share"(ctx, params) {
2767
- const link = findOwnNamedChat(state(ctx).links, str(params, "chat", true), state(ctx).groups);
2796
+ const s = state(ctx);
2797
+ const link = ownChatOf(ctx, params, s);
2768
2798
  const id = str(params, "id", true);
2769
- if (!state(ctx).identityProofs.some((p) => p.id === id)) throw new CliError("not_found", `No identity proof ${JSON.stringify(id)} (ghostly identity list)`);
2799
+ if (!s.identityProofs.some((p) => p.id === id)) throw new CliError("not_found", `No identity proof ${JSON.stringify(id)} (ghostly identity list)`);
2770
2800
  await node(ctx).shareIdentityProof({
2771
2801
  linkId: link.id,
2772
2802
  id
@@ -2777,7 +2807,7 @@ var IDENTITY_METHODS = {
2777
2807
  };
2778
2808
  },
2779
2809
  async "identity.withdraw"(ctx, params) {
2780
- const link = findOwnNamedChat(state(ctx).links, str(params, "chat", true), state(ctx).groups);
2810
+ const link = ownChatOf(ctx, params);
2781
2811
  const id = str(params, "id", true);
2782
2812
  if (!link.identities?.shared.some((s) => s.id === id)) throw new CliError("not_found", `No identity proof ${JSON.stringify(id)} shared in this chat (ghostly identity contact ${link.id})`);
2783
2813
  await node(ctx).withdrawIdentityProof({
@@ -2997,6 +3027,8 @@ function withoutReports(value) {
2997
3027
  }
2998
3028
  /** `service open` while Hide my IP from contacts is on (as the browser extension refuses to open one). */
2999
3029
  var SERVICE_OPEN_OFF_RELAY_ONLY = "A contact's app does not open here while Hide my IP from contacts is on: a browser tab cannot keep its page off WebRTC";
3030
+ /** `service open` or `service close` in a one-shot: only the daemon keeps a contact's app open on a port. */
3031
+ var SERVICE_NEEDS_DAEMON = "An opened service lives in the daemon: start `ghostly daemon --detach` first";
3000
3032
  function plain(response, status, text, headers = {}) {
3001
3033
  response.writeHead(status, {
3002
3034
  "content-type": "text/plain; charset=utf-8",
@@ -3017,9 +3049,10 @@ async function openServiceServer(send, port = 0, { relayOnly = false } = {}) {
3017
3049
  const name = `${randomBytes(16).toString("hex")}.localhost`;
3018
3050
  const token = randomBytes(32).toString("hex");
3019
3051
  const cookies = /* @__PURE__ */ new Set();
3020
- let host = "";
3052
+ let host = "", portless = "";
3021
3053
  const server = createServer((request, response) => {
3022
- if (request.headers.host?.toLowerCase() !== host) return plain(response, 404, "Not found");
3054
+ const asked = request.headers.host?.toLowerCase();
3055
+ if (!asked || asked !== host && asked !== portless) return plain(response, 404, "Not found");
3023
3056
  const path = request.url ?? "/";
3024
3057
  if (path.startsWith(OPEN_PATH)) {
3025
3058
  if (!sameSecret(path.slice(15), token)) return plain(response, 404, "Not found");
@@ -3054,7 +3087,9 @@ async function openServiceServer(send, port = 0, { relayOnly = false } = {}) {
3054
3087
  resolve();
3055
3088
  });
3056
3089
  });
3057
- host = `${name}:${server.address().port}`;
3090
+ const on = server.address().port;
3091
+ host = `${name}:${on}`;
3092
+ if (on === 80) portless = name;
3058
3093
  return {
3059
3094
  server,
3060
3095
  host,
@@ -3124,6 +3159,20 @@ function serviceOf(ctx, params) {
3124
3159
  * A port the person chose that could not be taken, in words that name it. Before, one in use was Node's EADDRINUSE as
3125
3160
  * `engine`, and one not allowed read as a file (`localFileError`): "Not allowed to write or read the path".
3126
3161
  */
3162
+ /** As long as the engine keeps a service's name (node.ts addService) and the Desktop's form takes it (Services.tsx). */
3163
+ var MAX_SERVICE_NAME_LENGTH = 48;
3164
+ /**
3165
+ * The `name` of `service add`, refused as a chat's or the profile's name is (`shownName`), before anything is made.
3166
+ * Before, one of spaces was the engine's plain error as `engine` (exit 1), and a longer one was cut with exit 0.
3167
+ */
3168
+ function serviceNameOf(params) {
3169
+ const name = shownName(str(params, "name", true), MAX_SERVICE_NAME_LENGTH, "A service's name");
3170
+ if (name.length > MAX_SERVICE_NAME_LENGTH) throw new CliError("bad_request", `A service's name is up to ${MAX_SERVICE_NAME_LENGTH} characters as stored, an emoji counting as 2 (this one is ${name.length})`, {
3171
+ length: name.length,
3172
+ max: MAX_SERVICE_NAME_LENGTH
3173
+ });
3174
+ return name;
3175
+ }
3127
3176
  function portError(error, port) {
3128
3177
  const { code } = error ?? {};
3129
3178
  if (port && code === "EADDRINUSE") return new CliError("busy", `Port ${port} is in use on this machine: choose another, or leave out --port`);
@@ -3142,23 +3191,22 @@ var SERVICE_METHODS = {
3142
3191
  })) };
3143
3192
  },
3144
3193
  async "service.add"(ctx, params) {
3194
+ const name = serviceNameOf(params);
3145
3195
  const target = str(params, "target", true);
3146
- let url;
3147
- try {
3148
- url = new URL(target);
3149
- } catch {
3150
- throw new CliError("bad_request", `Not a URL: ${target}`);
3151
- }
3152
- if (!(LOOPBACK.has(url.hostname) || /^127\.\d+\.\d+\.\d+$/.test(url.hostname))) throw new CliError("refused", "Only a web app on this machine (127.0.0.1, localhost) can be shared");
3153
3196
  try {
3154
3197
  parseLocalTarget(target);
3155
3198
  } catch (error) {
3156
3199
  const said = error instanceof Error ? error.message : String(error);
3157
- const shown = `${url.protocol}//${url.host}${url.pathname}`;
3200
+ const text = target.trim();
3201
+ let shown = text;
3202
+ try {
3203
+ const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `http://${text}`);
3204
+ shown = `${url.protocol}//${url.host}${url.pathname}`;
3205
+ } catch {}
3158
3206
  throw new CliError(/^Only services on this machine/.test(said) ? "refused" : "bad_request", `${said}: ${shown}`);
3159
3207
  }
3160
3208
  const { serviceId } = node(ctx).addService({
3161
- name: str(params, "name", true),
3209
+ name,
3162
3210
  target
3163
3211
  });
3164
3212
  return {
@@ -3183,7 +3231,7 @@ var SERVICE_METHODS = {
3183
3231
  };
3184
3232
  },
3185
3233
  async "service.share"(ctx, params) {
3186
- const link = findOwnNamedChat(state(ctx).links, str(params, "chat", true), state(ctx).groups);
3234
+ const link = ownChatOf(ctx, params);
3187
3235
  const shared = !bool(params, "off");
3188
3236
  const serviceId = serviceOf(ctx, params);
3189
3237
  await node(ctx).setServiceShared({
@@ -3208,8 +3256,8 @@ var SERVICE_METHODS = {
3208
3256
  },
3209
3257
  /** A contact's shared app on a loopback port of this machine, as the Desktop opens it in a window. */
3210
3258
  async "service.open"(ctx, params) {
3211
- if (ctx.mode !== "daemon") throw new CliError("unavailable", "An opened service lives in the daemon: start `ghostly daemon --detach` first");
3212
- if (state(ctx).settings?.relayOnly === true) throw new CliError("unavailable", SERVICE_OPEN_OFF_RELAY_ONLY);
3259
+ if (ctx.mode !== "daemon") throw new CliError("unavailable", SERVICE_NEEDS_DAEMON);
3260
+ if (settingsOf(ctx).relayOnly === true) throw new CliError("unavailable", SERVICE_OPEN_OFF_RELAY_ONLY);
3213
3261
  const link = chatOf(ctx, params);
3214
3262
  const service = str(params, "service", true);
3215
3263
  const key = `${link.peerPubKeyZ32}/${service}`;
@@ -3244,6 +3292,7 @@ var SERVICE_METHODS = {
3244
3292
  };
3245
3293
  },
3246
3294
  async "service.close"(ctx, params) {
3295
+ if (ctx.mode !== "daemon") throw new CliError("unavailable", SERVICE_NEEDS_DAEMON);
3247
3296
  const key = `${chatOf(ctx, params).peerPubKeyZ32}/${str(params, "service", true)}`;
3248
3297
  const pending = open$1.get(key);
3249
3298
  open$1.delete(key);
@@ -3315,7 +3364,7 @@ var CALL_METHODS = {
3315
3364
  };
3316
3365
  //#endregion
3317
3366
  //#region src/appServe.ts
3318
- /** The permissions a bot can be granted: `internet` is a page's, and no page runs here. */
3367
+ /** The permissions a bot can be granted: `internet` and `files` are a page's, and no page runs here. */
3319
3368
  var GRANTABLE = ["chat", "name"];
3320
3369
  var servedFile = (dir) => join(dir, "apps.json");
3321
3370
  /** The apps a profile serves, by its folder: none when the file is missing or not a list of them. */
@@ -3354,6 +3403,8 @@ function servedApp(apps, ref) {
3354
3403
  if (matches.length !== 1) throw new CliError(matches.length ? "bad_request" : "not_found", matches.length ? `${JSON.stringify(ref)} names more than one served app: give its whole reference` : `No served app ${JSON.stringify(ref)}: app serve its bundle first`);
3355
3404
  return matches[0];
3356
3405
  }
3406
+ /** A link a contact's app reads a card's bundle from. */
3407
+ var readable = (url) => isAppFetchUrl(url) && appCardUrl(url) !== void 0;
3357
3408
  /** Whether this engine offers apps/1 now: it read the list when it started, so the first app served waits for a restart. */
3358
3409
  var offered = (ctx, apps) => ({
3359
3410
  offered: ctx.runtime.apps,
@@ -3363,12 +3414,14 @@ var APP_SERVE_METHODS = {
3363
3414
  async "app.serve"(ctx, params) {
3364
3415
  const source = str(params, "bundle", true);
3365
3416
  const grant = list(params, "grant");
3366
- const unknown = grant.filter((p) => !APP_PERMISSIONS.includes(p));
3367
- if (unknown.length) throw new CliError("bad_request", `grant takes ${GRANTABLE.join(" or ")}, not ${unknown.map((p) => JSON.stringify(p)).join(", ")}`);
3368
3417
  if (grant.includes("internet")) throw new CliError("refused", "internet cannot be granted here: no app's page runs on the CLI, and a bot reaches the network as its own program");
3418
+ if (grant.includes("files")) throw new CliError("refused", "files cannot be granted here: no app's page runs on the CLI to ask a person for a file, and a bot reads files as its own program");
3419
+ const ungrantable = grant.filter((p) => !GRANTABLE.includes(p));
3420
+ if (ungrantable.length) throw new CliError("bad_request", `grant takes ${GRANTABLE.join(" or ")}, not ${ungrantable.map((p) => JSON.stringify(p)).join(", ")}`);
3369
3421
  const given = str(params, "url");
3370
3422
  if (given !== void 0 && !isAppUrl(given)) throw new CliError("bad_request", "url is where a contact's app reads the bundle: https only, no user or password, jsDelivr only at a full commit");
3371
3423
  if (given !== void 0 && /[?#]/.test(given)) throw new CliError("bad_request", "url goes to contacts on the app's card: no query or fragment (a private repository's token rides there); publish the app in a public repository");
3424
+ if (given !== void 0 && !readable(given)) throw new CliError("bad_request", "url is where a contact's app reads the bundle: raw.githubusercontent.com, or cdn.jsdelivr.net at a full commit, with no port and no space");
3372
3425
  const { bundle, url } = await checkedBundle(source);
3373
3426
  const m = bundle.manifest;
3374
3427
  if (!m.permissions.includes("chat")) throw new CliError("refused", `${m.title} does not ask for chat: it talks to no contact, so a bot has nothing to speak for it`);
@@ -3380,7 +3433,7 @@ var APP_SERVE_METHODS = {
3380
3433
  missing
3381
3434
  });
3382
3435
  const ref = appRef(m.publisher, m.name);
3383
- const cardUrl = appCardUrl(given ?? url ?? m.sources?.[0]);
3436
+ const cardUrl = appCardUrl(given ?? [url, ...m.sources ?? []].find(readable));
3384
3437
  const app = {
3385
3438
  ref,
3386
3439
  title: m.title,
@@ -3653,8 +3706,7 @@ function createChecked(type, n, offer, provider, values, params) {
3653
3706
  if (!provider) throw new CliError("bad_request", `${type} needs --provider: one of ${sources.map((p) => p.id).join(", ")} (ghostly wallet list)`);
3654
3707
  const source = sources.find((p) => p.id === provider);
3655
3708
  if (!source) throw new CliError("bad_request", `No ${type} source ${JSON.stringify(provider)} on ${n} (ghostly wallet list)`);
3656
- const unknown = Object.keys(values).find((name) => !source.fields.some((f) => f.name === name));
3657
- if (unknown) throw new CliError("bad_request", `${provider} takes no --value ${unknown}: ${source.fields.length ? `its fields are ${source.fields.map((f) => f.name).join(", ")}` : "it has no fields"}`);
3709
+ if (Object.keys(values).find((name) => !source.fields.some((f) => f.name === name))) throw new CliError("bad_request", `one --value names no field of ${provider}: ${source.fields.length ? `its fields are ${source.fields.map((f) => f.name).join(", ")}` : "it has no fields"}`);
3658
3710
  const missing = source.fields.find((f) => !f.optional && !f.defaults?.[n] && !values[f.name]?.trim());
3659
3711
  if (missing) throw new CliError("bad_request", `${provider} needs --value ${missing.name}=<${missing.options?.map((o) => o.value).join("|") ?? missing.placeholder ?? missing.label.toLowerCase()}>`);
3660
3712
  }
@@ -3782,6 +3834,18 @@ function walletJson(instance, s) {
3782
3834
  config: instance.config
3783
3835
  };
3784
3836
  }
3837
+ /** A token amount (USDT) is in base units: its `decimals` say how many make one. Sats carry none. */
3838
+ var tokenDecimals = (p) => p.target?.method === "usdt" ? { decimals: p.target.decimals ?? 6 } : {};
3839
+ /** USDT typed as the app's composer takes it ("5", "0.25") in base units: more decimals than the token has is refused. */
3840
+ function tokenUnits(text, decimals) {
3841
+ try {
3842
+ const units = parsePaymentAmount(text.trim(), decimals);
3843
+ if (units > 0) return units;
3844
+ } catch (error) {
3845
+ throw new CliError("bad_request", `amount: ${error.message}`);
3846
+ }
3847
+ throw new CliError("bad_request", "amount must be above 0");
3848
+ }
3785
3849
  function paymentJson(p) {
3786
3850
  return {
3787
3851
  id: p.id,
@@ -3790,6 +3854,7 @@ function paymentJson(p) {
3790
3854
  direction: p.direction,
3791
3855
  amount: p.amount,
3792
3856
  unit: p.unit,
3857
+ ...tokenDecimals(p),
3793
3858
  memo: p.memo ?? null,
3794
3859
  state: p.state,
3795
3860
  error: p.error ?? null,
@@ -4056,7 +4121,7 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4056
4121
  let n;
4057
4122
  let note;
4058
4123
  if (params.chat !== void 0 && !isInvoice(text)) throw new CliError("usage", "--chat names the chat an invoice came from: an address's or LNURL's invoice is its server's");
4059
- const chat = params.chat === void 0 ? void 0 : findOwnNamedChat(state(ctx).links, str(params, "chat", true), state(ctx).groups);
4124
+ const chat = params.chat === void 0 ? void 0 : ownChatOf(ctx, params);
4060
4125
  if (chat) inviteTaken(chat);
4061
4126
  if (isInvoice(text)) n = network(params);
4062
4127
  else if (isLnurl(text)) {
@@ -4110,7 +4175,7 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4110
4175
  /** Ecash to a contact in a chat (the payment sheet's Pay). */
4111
4176
  async "chat.pay"(ctx, params) {
4112
4177
  const memo = memoOf(params, "pay");
4113
- const link = findOwnNamedChat(state(ctx).links, str(params, "chat", true), state(ctx).groups);
4178
+ const link = ownChatOf(ctx, params);
4114
4179
  inviteTaken(link);
4115
4180
  const amount = num(params, "amount", 0, { min: 1 });
4116
4181
  if (!amount) throw new CliError("bad_request", "amount is required");
@@ -4132,16 +4197,20 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4132
4197
  paymentId
4133
4198
  };
4134
4199
  },
4135
- /** A request in a chat (the payment sheet's Request): the contact's app pays it. */
4200
+ /**
4201
+ * A request in a chat (the payment sheet's Request): the contact's app pays it. A USDT amount given as text ("5",
4202
+ * "0.25") is USDT, turned into base units with the wallet's decimals as the app's composer does; a number is base units.
4203
+ * The answer says the amount asked: USDT's carries the engine's tag of a few base units, and its decimals.
4204
+ */
4136
4205
  async "chat.request"(ctx, params) {
4137
4206
  const memo = memoOf(params, "request");
4138
4207
  const link = chatOf(ctx, params);
4139
- const amount = num(params, "amount", 0, { min: 1 });
4140
- if (!amount) throw new CliError("bad_request", "amount is required");
4141
4208
  const method = params.method === void 0 ? void 0 : oneOf(params, "method", PAY_METHODS, "cashu");
4209
+ const n = network(params);
4210
+ const amount = method === "usdt" && typeof params.amount === "string" ? tokenUnits(params.amount, netView(state(ctx), n)?.usdt?.decimals ?? 6) : num(params, "amount", 0, { min: 1 });
4211
+ if (!amount) throw new CliError("bad_request", "amount is required");
4142
4212
  const rail = params.rail === void 0 ? void 0 : oneOf(params, "rail", ["cashu", "lightning"], "cashu");
4143
4213
  await federationsOpen(ctx);
4144
- const n = network(params);
4145
4214
  const { paymentId } = await node(ctx).requestPayment({
4146
4215
  linkId: link.id,
4147
4216
  amount,
@@ -4154,16 +4223,23 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4154
4223
  }).catch((error) => {
4155
4224
  throw (!method || method === "cashu") && error instanceof Error && NO_MINT.test(error.message) ? noWalletOf(ctx, n, error) : error;
4156
4225
  });
4226
+ const asked = state(ctx).payments[paymentId];
4157
4227
  return {
4158
4228
  chat: link.id,
4159
- paymentId
4229
+ paymentId,
4230
+ ...asked ? {
4231
+ amount: asked.amount,
4232
+ unit: asked.unit,
4233
+ ...tokenDecimals(asked)
4234
+ } : {}
4160
4235
  };
4161
4236
  },
4162
4237
  /** Pays a request the contact made in a chat. */
4163
4238
  async "chat.payRequest"(ctx, params) {
4164
- const link = findOwnNamedChat(state(ctx).links, str(params, "chat", true), state(ctx).groups);
4239
+ const s = state(ctx);
4240
+ const link = ownChatOf(ctx, params, s);
4165
4241
  const paymentId = str(params, "payment", true);
4166
- const request = state(ctx).payments[paymentId];
4242
+ const request = s.payments[paymentId];
4167
4243
  if (!request || request.linkId !== link.id || request.kind !== "request") throw new CliError("not_found", `No request ${paymentId} in this chat`);
4168
4244
  const n = paymentNetwork(request);
4169
4245
  if (n === "mainnet" && !bool(params, "confirmReal")) throw new CliError("confirm", "This request is for real money (Mainnet): pass --confirm-real to confirm this payment", { network: n });
@@ -4212,12 +4288,14 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4212
4288
  };
4213
4289
  },
4214
4290
  async "payment.list"(ctx, params) {
4215
- const chat = params.chat === void 0 ? null : chatOf(ctx, params).id;
4216
- return { payments: Object.values(state(ctx).payments).filter((p) => !chat || p.linkId === chat).sort((a, b) => b.createdAt - a.createdAt).map(paymentJson) };
4291
+ const s = state(ctx);
4292
+ const chat = params.chat === void 0 ? null : chatOf(ctx, params, s).id;
4293
+ return { payments: Object.values(s.payments).filter((p) => !chat || p.linkId === chat).sort((a, b) => b.createdAt - a.createdAt).map(paymentJson) };
4217
4294
  },
4218
4295
  async "payment.check"(ctx, params) {
4219
- const link = chatOf(ctx, params);
4220
- const p = state(ctx).payments[str(params, "payment", true)];
4296
+ const s = state(ctx);
4297
+ const link = chatOf(ctx, params, s);
4298
+ const p = s.payments[str(params, "payment", true)];
4221
4299
  if (p?.linkId !== link.id) throw new CliError("not_found", `No payment ${JSON.stringify(str(params, "payment", true))} in this chat (ghostly payment list --chat ${link.id})`);
4222
4300
  if (p.kind !== "request" || p.direction !== "in") throw new CliError("bad_request", `${JSON.stringify(p.id)} is ${p.kind === "request" ? "your own request" : p.direction === "out" ? "a payment you sent" : "a payment you received"}: payment check is for a request the contact made of you`);
4223
4301
  await node(ctx).checkPayment({
@@ -4461,6 +4539,7 @@ function inviteNotOut(detail) {
4461
4539
  var BAD_VALUE = /^Cannot (destructure|read properties of (undefined|null))|is not (a function|iterable)/;
4462
4540
  /** A one-shot's typing without `--for` (it opens the profile offline, `offlineCall`): said on no live session. */
4463
4541
  var ONE_SHOT_TYPING = "Typing is said on a live session only, and a one-shot has none: it reached nobody. Keep the profile online (`ghostly daemon --detach`), or give --for to wait until it is live";
4542
+ var ONE_SHOT_TYPING_STOP = "A stop is said on a live session only, and a one-shot has none: it reached nobody. Keep the profile online (`ghostly daemon --detach`)";
4464
4543
  /**
4465
4544
  * A removal on its way goes with the chat's row, and the contact kept the message for good, though `message delete
4466
4545
  * --everyone` had said its removal goes on: `chat remove`, the engine's `removeLink` and `clearProfileData` (every
@@ -4543,7 +4622,7 @@ var METHODS = {
4543
4622
  return statusJson(node(ctx).getOwnStatus().status);
4544
4623
  },
4545
4624
  async "profile.get"(ctx) {
4546
- const { settings } = state(ctx);
4625
+ const settings = settingsOf(ctx);
4547
4626
  return {
4548
4627
  profile: ctx.runtime.paths.name,
4549
4628
  name: settings.nick || null,
@@ -4561,7 +4640,7 @@ var METHODS = {
4561
4640
  return METHODS["profile.get"](ctx, {});
4562
4641
  },
4563
4642
  async "settings.get"(ctx, params) {
4564
- return redactSettings(settingsInEffect(state(ctx).settings), bool(params, "showSecret"));
4643
+ return redactSettings(settingsInEffect(settingsOf(ctx)), bool(params, "showSecret"));
4565
4644
  },
4566
4645
  async "settings.set"(ctx, params) {
4567
4646
  const patch = {};
@@ -4598,7 +4677,7 @@ var METHODS = {
4598
4677
  throw relayRefused(error, patch);
4599
4678
  });
4600
4679
  return {
4601
- ...redactSettings(settingsInEffect(state(ctx).settings)),
4680
+ ...redactSettings(settingsInEffect(settingsOf(ctx))),
4602
4681
  ...warning ? { warning } : {}
4603
4682
  };
4604
4683
  },
@@ -4779,15 +4858,16 @@ var METHODS = {
4779
4858
  const kept = seconds ? keepTyping(ctx, { linkId: link.id }, seconds * 1e3, word) : null;
4780
4859
  const open = (s) => s.links.find((l) => l.id === link.id)?.dataLink === "open";
4781
4860
  if (kept && ctx.mode === "one-shot") await keepOneShot(ctx, { linkId: link.id }, kept, open);
4861
+ const now = state(ctx);
4782
4862
  return {
4783
4863
  chat: link.id,
4784
4864
  typing,
4785
4865
  ...typing ? { kind } : {},
4786
4866
  ...status ? { status } : {},
4787
- live: open(state(ctx)),
4788
- sendTyping: state(ctx).settings.sendTyping !== false,
4867
+ live: open(now),
4868
+ sendTyping: now.settings.sendTyping !== false,
4789
4869
  ...until ? { until } : {},
4790
- ...!kept && ctx.mode === "one-shot" && { note: ONE_SHOT_TYPING }
4870
+ ...!kept && ctx.mode === "one-shot" && { note: typing ? ONE_SHOT_TYPING : ONE_SHOT_TYPING_STOP }
4791
4871
  };
4792
4872
  },
4793
4873
  /**
@@ -4904,13 +4984,14 @@ var METHODS = {
4904
4984
  * took it), each file until its transfer is done. What a chat refused comes back per chat; any refusal fails the call.
4905
4985
  */
4906
4986
  async "chat.forward"(ctx, params) {
4907
- const from = chatOrGroup(ctx, str(params, "chat", true));
4987
+ const s = state(ctx);
4988
+ const from = chatOrGroup(ctx, str(params, "chat", true), s);
4908
4989
  const messageIds = [...new Set(list(params, "messages"))];
4909
4990
  if (!messageIds.length) throw new CliError("bad_request", "Name the messages to forward (their ids, from history or an event)");
4910
4991
  if (messageIds.length > 30) throw new CliError("bad_request", `Forward at most 30 messages at once, not ${messageIds.length}`);
4911
4992
  const to = [];
4912
4993
  for (const ref of new Set(list(params, "to"))) {
4913
- const target = chatOrGroup(ctx, ref);
4994
+ const target = chatOrGroup(ctx, ref, s);
4914
4995
  if (to.some((t) => t.linkId === target.linkId)) continue;
4915
4996
  if (to.length === 5) throw new CliError("bad_request", `Forward to at most 5 chats and groups at once`);
4916
4997
  to.push(target);
@@ -4955,32 +5036,50 @@ var METHODS = {
4955
5036
  sent: result.sent,
4956
5037
  error: result.error
4957
5038
  }));
5039
+ let short;
5040
+ const waited = async (wait, now) => {
5041
+ if (short) return now();
5042
+ try {
5043
+ return await wait();
5044
+ } catch (error) {
5045
+ short = asCliError(error);
5046
+ return now();
5047
+ }
5048
+ };
4958
5049
  for (const [i, result] of out.entries()) if (to[i].group) {
4959
5050
  let edges;
4960
5051
  for (const messageId of result.messageIds) {
4961
- const took = groupWait === "sent" ? await waitForGroupFrame(ctx, to[i].id, messageId, void 0, ms) : node(ctx).groupTaken({
5052
+ const taken = () => node(ctx).groupTaken({
4962
5053
  groupId: to[i].id,
4963
5054
  messageId
4964
5055
  });
5056
+ const took = groupWait === "sent" ? await waited(() => waitForGroupFrame(ctx, to[i].id, messageId, void 0, ms), taken) : taken();
4965
5057
  edges = Math.min(edges ?? took, took);
4966
5058
  }
4967
5059
  result.edges = edges ?? 0;
4968
5060
  }
4969
5061
  if (wait === "sent") for (const [i, result] of out.entries()) for (const messageId of result.messageIds) {
4970
5062
  if (to[i].group) continue;
4971
- const sent = await node(ctx).getMessage(to[i].id, messageId);
4972
- if (sent?.file) await FILE_METHODS["file.wait"](ctx, {
4973
- chat: to[i].id,
4974
- file: sent.file.id,
4975
- timeout: ms / 1e3
4976
- });
4977
- else await waitForMessage(ctx, to[i].id, messageId, "sent", ms);
5063
+ await waited(async () => {
5064
+ const sent = await node(ctx).getMessage(to[i].id, messageId);
5065
+ if (sent?.file) await FILE_METHODS["file.wait"](ctx, {
5066
+ chat: to[i].id,
5067
+ file: sent.file.id,
5068
+ timeout: ms / 1e3
5069
+ });
5070
+ else await waitForMessage(ctx, to[i].id, messageId, "sent", ms);
5071
+ }, () => void 0);
4978
5072
  }
4979
5073
  const failed = out.filter((r) => r.error);
4980
5074
  if (failed.length) throw new CliError(failed.length === out.length ? "refused" : "engine", failed.map((r) => `${r.to}: ${r.error}`).join("; "), {
4981
5075
  from: from.id,
4982
5076
  results: out
4983
5077
  });
5078
+ if (short) throw new CliError(short.code, short.message, {
5079
+ ...short.details,
5080
+ from: from.id,
5081
+ results: out
5082
+ });
4984
5083
  return {
4985
5084
  from: from.id,
4986
5085
  results: out
@@ -5397,15 +5496,16 @@ var METHODS = {
5397
5496
  const kept = seconds ? keepTyping(ctx, target, seconds * 1e3, word) : null;
5398
5497
  const reached = (s) => (s.groups.find((g) => g.id === group.id) ?? group).members.filter((m) => !m.me && m.online && !m.viaHub).length;
5399
5498
  if (kept && ctx.mode === "one-shot") await keepOneShot(ctx, target, kept, (s) => reached(s) > 0);
5499
+ const now = state(ctx);
5400
5500
  return {
5401
5501
  group: group.id,
5402
5502
  typing,
5403
5503
  ...typing ? { kind } : {},
5404
5504
  ...status ? { status } : {},
5405
- reached: reached(state(ctx)),
5406
- sendTyping: state(ctx).settings.sendTyping !== false,
5505
+ reached: reached(now),
5506
+ sendTyping: now.settings.sendTyping !== false,
5407
5507
  ...until ? { until } : {},
5408
- ...!kept && ctx.mode === "one-shot" && { note: ONE_SHOT_TYPING }
5508
+ ...!kept && ctx.mode === "one-shot" && { note: typing ? ONE_SHOT_TYPING : ONE_SHOT_TYPING_STOP }
5409
5509
  };
5410
5510
  },
5411
5511
  async "group.leave"(ctx, params) {
@@ -5852,4 +5952,4 @@ async function callApi(ctx, method, params = {}) {
5852
5952
  //#endregion
5853
5953
  export { groupPayTwins as _, hideStateSecrets as a, settingsInEffect as c, servedApps as d, nodeLocalFetch as f, groupMessageJson as g, groupJson as h, groupSendRefused as i, paymentJson as l, chatMessageJson as m, SETTABLE as n, mentionsFor as o, chatJson as p, callApi as r, redactSettings as s, API_METHODS as t, reportAppFrames as u, resumeHolds as v, flushCardUpdates as y };
5854
5954
 
5855
- //# sourceMappingURL=api-DBlaoz8i.js.map
5955
+ //# sourceMappingURL=api-MYc6QNRs.js.map