@ghostlytools/cli 1.13.1 → 1.13.2

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 (93) hide show
  1. package/README.md +6 -4
  2. package/dist/assets/api-DV52o7A8.js +3 -0
  3. package/dist/assets/{api-Dnq86JAA.js → api-O57SNJcb.js} +375 -77
  4. package/dist/assets/api-O57SNJcb.js.map +1 -0
  5. package/dist/assets/{apiKit-nLK4jeTq.js → apiKit-CPTFJHA7.js} +39 -7
  6. package/dist/assets/{apiKit-nLK4jeTq.js.map → apiKit-CPTFJHA7.js.map} +1 -1
  7. package/dist/assets/{appFetch-wqBWi3Ry.js → appFetch-Ca9DNQQ2.js} +2 -2
  8. package/dist/assets/{appFetch-wqBWi3Ry.js.map → appFetch-Ca9DNQQ2.js.map} +1 -1
  9. package/dist/assets/{apps-DBVhKpfe.js → apps-gXpGFPiv.js} +11 -9
  10. package/dist/assets/apps-gXpGFPiv.js.map +1 -0
  11. package/dist/assets/{apps-nLtyhC2f.js → apps-uZTu5FlR.js} +1 -1
  12. package/dist/assets/{arkade-DryM-q5n.js → arkade-B6UNf5HI.js} +2 -2
  13. package/dist/assets/{arkade-DryM-q5n.js.map → arkade-B6UNf5HI.js.map} +1 -1
  14. package/dist/assets/{backup-Bczllmzf.js → backup-CxH3auHB.js} +8 -6
  15. package/dist/assets/backup-CxH3auHB.js.map +1 -0
  16. package/dist/assets/{backup-D6s0LQdg.js → backup-Di2U6QVH.js} +1 -1
  17. package/dist/assets/{bitcoind-DML_-Xbv.js → bitcoind-BpZn3bRN.js} +2 -2
  18. package/dist/assets/{bitcoind-DML_-Xbv.js.map → bitcoind-BpZn3bRN.js.map} +1 -1
  19. package/dist/assets/{buttons-B3C3vdhH.js → buttons-D4udKEvT.js} +4 -4
  20. package/dist/assets/{buttons-B3C3vdhH.js.map → buttons-D4udKEvT.js.map} +1 -1
  21. package/dist/assets/buttons-YTYEqvGC.js +1 -0
  22. package/dist/assets/{client-B7jRrSnb.js → client-DGx7E8b3.js} +2 -2
  23. package/dist/assets/{client-B7jRrSnb.js.map → client-DGx7E8b3.js.map} +1 -1
  24. package/dist/assets/{engineErrors--9hfgKlK.js → engineErrors-wWlLy54D.js} +11 -3
  25. package/dist/assets/engineErrors-wWlLy54D.js.map +1 -0
  26. package/dist/assets/{fixedHosts-H3i6o9Iy.js → fixedHosts-CODN2pTL.js} +3 -3
  27. package/dist/assets/{fixedHosts-H3i6o9Iy.js.map → fixedHosts-CODN2pTL.js.map} +1 -1
  28. package/dist/assets/{groupMeta--fxSh792.js → groupMeta-CeZpqVVC.js} +105 -36
  29. package/dist/assets/groupMeta-CeZpqVVC.js.map +1 -0
  30. package/dist/assets/{host-CGzVFfMz.js → host-CRA7h5A2.js} +113 -40
  31. package/dist/assets/host-CRA7h5A2.js.map +1 -0
  32. package/dist/assets/{hyperdhtRelay-Ce-gWsRY.js → hyperdhtRelay-B34Zhz4P.js} +2 -2
  33. package/dist/assets/{hyperdhtRelay-Ce-gWsRY.js.map → hyperdhtRelay-B34Zhz4P.js.map} +1 -1
  34. package/dist/assets/{hyperdhtRelay-B4_wdCtx.js → hyperdhtRelay-DDwU5b4P.js} +2 -2
  35. package/dist/assets/{hyperdhtRelay-B4_wdCtx.js.map → hyperdhtRelay-DDwU5b4P.js.map} +1 -1
  36. package/dist/assets/{identityProofs-Cksc_K7_.js → identityProofs-B8zCp5_0.js} +140 -27
  37. package/dist/assets/identityProofs-B8zCp5_0.js.map +1 -0
  38. package/dist/assets/{irohWeb-Dp1i8v6n.js → irohWeb-mnOi2Jp7.js} +10832 -4832
  39. package/dist/assets/irohWeb-mnOi2Jp7.js.map +1 -0
  40. package/dist/assets/{linkPreview-DdMf-YAc.js → linkPreview-5kHmKUTN.js} +20 -8
  41. package/dist/assets/linkPreview-5kHmKUTN.js.map +1 -0
  42. package/dist/assets/{main-C8J53SwH.js → main-Chc871HV.js} +72 -39
  43. package/dist/assets/main-Chc871HV.js.map +1 -0
  44. package/dist/assets/{mainline-DY95WbuK.js → mainline-CDUXtV-I.js} +2 -2
  45. package/dist/assets/{mainline-DY95WbuK.js.map → mainline-CDUXtV-I.js.map} +1 -1
  46. package/dist/assets/{networkReason-Be-hMghr.js → networkReason-DYlPZS5M.js} +2 -2
  47. package/dist/assets/{networkReason-Be-hMghr.js.map → networkReason-DYlPZS5M.js.map} +1 -1
  48. package/dist/assets/{ownDid-oa-T2vmZ.js → ownDid-BOuSlDv-.js} +4 -4
  49. package/dist/assets/{ownDid-oa-T2vmZ.js.map → ownDid-BOuSlDv-.js.map} +1 -1
  50. package/dist/assets/{ownStatus-Bc08eNJY.js → ownStatus-CLA1VPkL.js} +3 -3
  51. package/dist/assets/{ownStatus-Bc08eNJY.js.map → ownStatus-CLA1VPkL.js.map} +1 -1
  52. package/dist/assets/{pairedTransports-Dppn8lUN.js → pairedTransports-DAzupLYo.js} +21 -15
  53. package/dist/assets/pairedTransports-DAzupLYo.js.map +1 -0
  54. package/dist/assets/{paymentIntent-DySU3Ajm.js → paymentIntent-Cr3uZa_0.js} +2 -2
  55. package/dist/assets/{paymentIntent-DySU3Ajm.js.map → paymentIntent-Cr3uZa_0.js.map} +1 -1
  56. package/dist/assets/{profiles-B2uy04ph.js → profiles-BH1bH9aE.js} +2 -2
  57. package/dist/assets/{profiles-B2uy04ph.js.map → profiles-BH1bH9aE.js.map} +1 -1
  58. package/dist/assets/{registry-bLIfG619.js → registry-DAq16T-V.js} +1 -1
  59. package/dist/assets/{registry-DbTLLs3y.js → registry-DP_-RA-v.js} +5 -5
  60. package/dist/assets/{registry-DbTLLs3y.js.map → registry-DP_-RA-v.js.map} +1 -1
  61. package/dist/assets/{relay-CHWg5hpZ.js → relay-gJTOYQJZ.js} +93 -7
  62. package/dist/assets/relay-gJTOYQJZ.js.map +1 -0
  63. package/dist/assets/{resolve-DNX-eecG.js → resolve-B1eQ4dVQ.js} +3 -3
  64. package/dist/assets/{resolve-DNX-eecG.js.map → resolve-B1eQ4dVQ.js.map} +1 -1
  65. package/dist/assets/{server-DWJ4RzJn.js → server-Bd2ofxc1.js} +717 -6389
  66. package/dist/assets/server-Bd2ofxc1.js.map +1 -0
  67. package/dist/assets/{sshForges-BnvwmNj-.js → sshForges-As7dbGXM.js} +2 -2
  68. package/dist/assets/{sshForges-BnvwmNj-.js.map → sshForges-As7dbGXM.js.map} +1 -1
  69. package/dist/assets/{translate-CHj_PdLg.js → translate-DnuQMfj0.js} +10 -4
  70. package/dist/assets/translate-DnuQMfj0.js.map +1 -0
  71. package/dist/assets/{usdt-CBJ4Q5Ji.js → usdt-DLmtf8F9.js} +4 -4
  72. package/dist/assets/{usdt-CBJ4Q5Ji.js.map → usdt-DLmtf8F9.js.map} +1 -1
  73. package/dist/assets/{waitNotice-Cvz5CiKR.js → waitNotice-BHuMofaH.js} +2 -2
  74. package/dist/assets/{waitNotice-Cvz5CiKR.js.map → waitNotice-BHuMofaH.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-DF36rBJK.js +0 -3
  79. package/dist/assets/api-Dnq86JAA.js.map +0 -1
  80. package/dist/assets/apps-DBVhKpfe.js.map +0 -1
  81. package/dist/assets/backup-Bczllmzf.js.map +0 -1
  82. package/dist/assets/buttons-DaY5FYlV.js +0 -1
  83. package/dist/assets/engineErrors--9hfgKlK.js.map +0 -1
  84. package/dist/assets/groupMeta--fxSh792.js.map +0 -1
  85. package/dist/assets/host-CGzVFfMz.js.map +0 -1
  86. package/dist/assets/identityProofs-Cksc_K7_.js.map +0 -1
  87. package/dist/assets/irohWeb-Dp1i8v6n.js.map +0 -1
  88. package/dist/assets/linkPreview-DdMf-YAc.js.map +0 -1
  89. package/dist/assets/main-C8J53SwH.js.map +0 -1
  90. package/dist/assets/pairedTransports-Dppn8lUN.js.map +0 -1
  91. package/dist/assets/relay-CHWg5hpZ.js.map +0 -1
  92. package/dist/assets/server-DWJ4RzJn.js.map +0 -1
  93. package/dist/assets/translate-CHj_PdLg.js.map +0 -1
@@ -1,24 +1,24 @@
1
- import { Ai as GhostlyHttpError, An as baseMime, Ba as isAppRef, Dn as PLAYABLE_AUDIO, Dt as TYPING_KINDS, Ea as isAppUrl, En as sanitizeMime, Er as checkStatusCard, Fi as LIMITS, Fn as voiceLevel, Mr as MESSAGE_CLOCK_SKEW_MS, Ni as parseLocalTarget, Nn as parseVoiceMeta, O as GROUP_FILE_LIMITS, On as VOICE_LIMITS, Ot as TYPING_REFRESH_MS, Pa as appRef, Pn as voiceDownloadName, Pr as claimedTime, Qa as readImageMeta, Si as AWAITING_PEER_MS, Tn as sanitizeFileName, br as appCardId, co as inviteLink, cr as replySnippet, ji as VIEWER_PERMISSIONS_POLICY, jn as downsamplePeaks, jt as sanitizeTypingStatus, kn as VOICE_METER, kr as statusCardBytes, n as groupCallSfu, nn as APP_DATA_MAX_BYTES, uo as ownInviteRefusal, vr as STATUS_CARD_LIMITS, wr as cardLine, xr as appCardUrl } from "./groupMeta--fxSh792.js";
2
- import { B as removeStored, Qt as withoutPictureMetadata, Tt as decodeGroupEntryLink, U as waitingGroupFile, W as IDENTITY_DRAFT_TTL_MS, Xt as NO_PICTURE_METADATA, Yt as withoutVideoMetadata, Zt as stripPictureMetadata, 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, qt as withoutAudioMetadata, s as groupPayNoteId, t as DEFAULT_IROH_RELAYS } from "./irohWeb-Dp1i8v6n.js";
3
- import { c as normalizeRelayUrl, l as relayUrlProblem } from "./relay-CHWg5hpZ.js";
1
+ import { $a as readImageMeta, Ai as GhostlyHttpError, An as baseMime, Dn as PLAYABLE_AUDIO, Dt as TYPING_KINDS, Ea as isAppUrl, En as sanitizeMime, Er as checkStatusCard, Fi as LIMITS, Fn as voiceLevel, Mr as MESSAGE_CLOCK_SKEW_MS, Ni as parseLocalTarget, Nn as parseVoiceMeta, O as GROUP_FILE_LIMITS, On as VOICE_LIMITS, Ot as TYPING_REFRESH_MS, Pa as appRef, Pn as voiceDownloadName, Pr as claimedTime, Si as AWAITING_PEER_MS, Tn as sanitizeFileName, Va as isAppRef, br as appCardId, cr as replySnippet, do as ownInviteRefusal, ji as VIEWER_PERMISSIONS_POLICY, jn as downsamplePeaks, jt as sanitizeTypingStatus, kn as VOICE_METER, kr as statusCardBytes, lo as inviteLink, n as groupCallSfu, nn as APP_DATA_MAX_BYTES, vr as STATUS_CARD_LIMITS, wr as cardLine, xr as appCardUrl } from "./groupMeta-CeZpqVVC.js";
2
+ import { G as removeStored, J as waitingGroupFile, P as paymentNetwork, Pt as decodeCommunityLink, T as replyRef, Y as IDENTITY_DRAFT_TTL_MS, an as withoutAudioMetadata, b as groupOfFile, cn as NO_PICTURE_METADATA, d as groupPayLineId, f as groupPayNoteId, l as normalizeMintUrl, ln as stripPictureMetadata, p as groupPayTwin, sn as withoutVideoMetadata, t as DEFAULT_IROH_RELAYS, u as groupMemberOfLink, un as withoutPictureMetadata, v as groupFileId, vt as iceServerProblem, yt as iceServerSetting, zt as decodeGroupEntryLink } from "./irohWeb-mnOi2Jp7.js";
3
+ import { c as normalizeRelayUrl, l as relayUrlProblem } from "./relay-gJTOYQJZ.js";
4
4
  import { n as secretWords, r as findSecret, t as guardText } from "./secretGuard-oz_3hBfW.js";
5
- 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-Bc08eNJY.js";
5
+ 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-CLA1VPkL.js";
6
6
  import { i as localFileError, o as shownValue, r as asCliError, t as CliError } from "./errors-JVJsO8Iu.js";
7
- import { A as sentAt, B as shellWord, C as nobodyJoined, D as oneOf, E as num, I as state, L as str, M as shownName, N as sinceSeq, O as oneShotWaits, P as somebodyJoined, R as transportOffered, S as noMessage, T as node, _ as list, a as contactKeyOf, c as findChatOrGroup, d as groupById, f as groupNameOf, g as keptForJoin, h as inviteTaken, j as settingsOf, k as ownChatOf, l as findGroup, m as groupPrefixed, n as chatOf, o as dhtOnly, p as groupOf, r as chatOrGroup, s as findChat, t as bool, v as messageOf, x as noFile, z as waitForState } from "./apiKit-nLK4jeTq.js";
7
+ import { A as oneOf, B as str, C as noMessage, D as notInYet, E as node, F as shownName, H as waitForState, I as sinceSeq, L as somebodyJoined, M as ownChatOf, N as sentAt, O as notInYetError, P as settingsOf, S as noFile, U as shellWord, V as transportOffered, _ as keptForJoin, a as contactKeyOf, b as nameKey, c as findChatOrGroup, d as groupById, f as groupCalled, g as inviteTaken, h as groupPrefixed, j as oneShotWaits, k as num, l as findGroup, m as groupOf, n as chatOf, o as dhtOnly, p as groupNameOf, r as chatOrGroup, s as findChat, t as bool, v as list, w as nobodyJoined, y as messageOf, z as state } from "./apiKit-CPTFJHA7.js";
8
8
  import { l as toBase64Url, s as randomBytes$1 } from "./bytes-C1DNGY18.js";
9
9
  import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-CfvUXdSy.js";
10
10
  import { p as fileStore } from "./idb-ewvbqyDI.js";
11
11
  import { t as childEnv } from "./childEnv-C-99hdbL.js";
12
- import { a as checkTextSize$1, c as goesOn, d as purgeMessage, f as waitForConfirmed, g as waitForRemoval, h as waitForMessage, i as pressable, l as nobodyElseIn, m as waitForGroupFrame, n as buttonsCard, o as ended, p as waitForEdit, s as foldsAnyway, t as BUTTON_METHODS, u as outOf } from "./buttons-B3C3vdhH.js";
13
- import { a as checkShownName } from "./profiles-B2uy04ph.js";
14
- import { a as MAX_AVATAR_LENGTH, o as sanitizeAvatar } from "./linkPreview-DdMf-YAc.js";
15
- import { m as identityStatement } from "./identityProofs-Cksc_K7_.js";
16
- import { a as SignerTimeout, i as parseProofBunker, t as IDENTITY_PROVIDERS } from "./registry-DbTLLs3y.js";
17
- import { t as BACKUP_METHODS } from "./backup-Bczllmzf.js";
18
- import { s as isAppFetchUrl } from "./appFetch-wqBWi3Ry.js";
19
- import { o as checkedBundle } from "./apps-DBVhKpfe.js";
20
- import { m as parsePaymentAmount } from "./paymentIntent-DySU3Ajm.js";
21
- import { a as heldWords, n as dhtOnlyNote, t as chatState } from "./waitNotice-Cvz5CiKR.js";
12
+ import { a as checkTextSize$1, c as goesOn, d as purgeMessage, f as waitForConfirmed, g as waitForRemoval, h as waitForMessage, i as pressable, l as nobodyElseIn, m as waitForGroupFrame, n as buttonsCard, o as ended, p as waitForEdit, s as foldsAnyway, t as BUTTON_METHODS, u as outOf } from "./buttons-D4udKEvT.js";
13
+ import { a as checkShownName } from "./profiles-BH1bH9aE.js";
14
+ import { o as MAX_AVATAR_LENGTH, s as sanitizeAvatar } from "./linkPreview-5kHmKUTN.js";
15
+ import { m as identityStatement } from "./identityProofs-B8zCp5_0.js";
16
+ import { a as SignerTimeout, i as parseProofBunker, t as IDENTITY_PROVIDERS } from "./registry-DP_-RA-v.js";
17
+ import { t as BACKUP_METHODS } from "./backup-CxH3auHB.js";
18
+ import { s as isAppFetchUrl } from "./appFetch-Ca9DNQQ2.js";
19
+ import { o as checkedBundle } from "./apps-gXpGFPiv.js";
20
+ import { m as parsePaymentAmount } from "./paymentIntent-Cr3uZa_0.js";
21
+ import { a as heldWords, n as dhtOnlyNote, t as chatState } from "./waitNotice-BHuMofaH.js";
22
22
  import { generateMnemonic } from "@scure/bip39";
23
23
  import { wordlist } from "@scure/bip39/wordlists/english.js";
24
24
  import { execFile, spawn } from "node:child_process";
@@ -1122,6 +1122,15 @@ async function waitForFile(ctx, params, stopping) {
1122
1122
  size: transfer.size
1123
1123
  };
1124
1124
  }
1125
+ /**
1126
+ * `file accept` of a file that does not fit the room left beside the files still coming (`FileDesk.accept`), in this
1127
+ * CLI's MB: the engine's line gave the room in binary MB beside a size in decimal ones, and neither the files still
1128
+ * coming that take the rest nor the way out.
1129
+ */
1130
+ function noRoomWords(fileId, name, size, room, coming) {
1131
+ const rest = coming > 0 ? `, and ${megabytes(coming)} of files still coming need it first` : "";
1132
+ return `${name ?? "The file"} (${megabytes(size)}) does not fit: ${megabytes(room)} free${rest}. Free some space, then ghostly file accept ${fileId} again (or file decline)`;
1133
+ }
1125
1134
  /** A received file that waits for this person's `file accept` (`file wait`, `file save`): said naming the command. */
1126
1135
  function waitsForYou(name, fileId, where, size) {
1127
1136
  return new CliError("confirm", `${name ?? "The file"} (${megabytes(size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
@@ -1327,8 +1336,8 @@ var FILE_METHODS = {
1327
1336
  action
1328
1337
  });
1329
1338
  } catch (error) {
1330
- const room = error?.room;
1331
- if (action === "accept" && error instanceof Error && typeof room === "number" && error.message.startsWith("No room on this device")) throw new CliError("refused", error.message, {
1339
+ const { room, size, coming } = error ?? {};
1340
+ if (action === "accept" && error instanceof Error && typeof room === "number" && error.message.startsWith("No room on this device")) throw new CliError("refused", noRoomWords(fileId, (await fileStore.get(fileId).catch(() => void 0))?.metadata?.name, typeof size === "number" ? size : view?.size ?? 0, room, typeof coming === "number" ? coming : 0), {
1332
1341
  reason: "no_room",
1333
1342
  room
1334
1343
  });
@@ -2504,9 +2513,9 @@ function callNode(raw, ref, groupId) {
2504
2513
  */
2505
2514
  function joined(ctx, params, twin) {
2506
2515
  const group = groupOf(ctx, params, twin);
2507
- if (group.status || !group.invitation) return group;
2508
- const shown = shellWord(str(params, "group", true), group.id);
2509
- 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`);
2516
+ const yet = notInYet(group, str(params, "group", true));
2517
+ if (yet) throw new CliError("refused", yet);
2518
+ return group;
2510
2519
  }
2511
2520
  /** The member `params.member` names in `group`, this profile's own name said to be it; by its key only for a grant. */
2512
2521
  var member = (ctx, group, params, grant = false) => findMember(group, str(params, "member", true), settingsOf(ctx).nick, grant);
@@ -2646,7 +2655,8 @@ var GROUP_ADMIN_METHODS = {
2646
2655
  */
2647
2656
  var drafts = /* @__PURE__ */ new Map();
2648
2657
  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`;
2649
- function provider(id) {
2658
+ /** The provider `id` names; a one-shot `identity add` asks before the profile opens (main.ts `identityAddCommand`). */
2659
+ function identityProvider(id) {
2650
2660
  const found = IDENTITY_PROVIDERS.find((p) => p.id === id);
2651
2661
  if (!found) throw new CliError("not_found", `No identity provider ${id} (ghostly identity providers)`);
2652
2662
  return found;
@@ -2771,7 +2781,7 @@ var IDENTITY_METHODS = {
2771
2781
  /** Starts a proof. In-app signers finish it here; the others return the statement and what to do with it. */
2772
2782
  async "identity.add"(ctx, params) {
2773
2783
  pruneDrafts();
2774
- const p = provider(str(params, "provider", true));
2784
+ const p = identityProvider(str(params, "provider", true));
2775
2785
  const signer = signerOf(p, str(params, "signer"));
2776
2786
  if (signer.kind === "in-app") {
2777
2787
  const values = params.fields ?? {};
@@ -2791,6 +2801,11 @@ var IDENTITY_METHODS = {
2791
2801
  });
2792
2802
  const signal = AbortSignal.timeout(seconds * 1e3);
2793
2803
  let signed = false;
2804
+ const request = str(params, "request");
2805
+ const tag = {
2806
+ provider: p.id,
2807
+ ...request ? { request } : {}
2808
+ };
2794
2809
  return {
2795
2810
  done: true,
2796
2811
  proof: proofJson(await signer.run({
@@ -2799,19 +2814,19 @@ var IDENTITY_METHODS = {
2799
2814
  waitMs: seconds * 1e3,
2800
2815
  onAuthUrl: (url) => {
2801
2816
  ctx.hub.emitLive("identity.approval", `identity.approval:${Date.now()}`, {
2802
- provider: p.id,
2817
+ ...tag,
2803
2818
  url
2804
2819
  });
2805
2820
  },
2806
2821
  onProgress: (message) => {
2807
2822
  ctx.hub.emit("identity.progress", `identity.progress:${Date.now()}`, {
2808
- provider: p.id,
2823
+ ...tag,
2809
2824
  message
2810
2825
  });
2811
2826
  },
2812
2827
  onApproval: (request) => {
2813
2828
  if (request) ctx.hub.emitLive("identity.approval", `identity.approval:${Date.now()}`, {
2814
- provider: p.id,
2829
+ ...tag,
2815
2830
  ...request.qr ? {
2816
2831
  qr: request.qr.value,
2817
2832
  label: request.qr.label
@@ -2871,7 +2886,7 @@ var IDENTITY_METHODS = {
2871
2886
  pruneDrafts();
2872
2887
  const draft = drafts.get(str(params, "draft", true));
2873
2888
  if (!draft) throw new CliError("not_found", NO_DRAFT);
2874
- const signer = signerOf(provider(draft.provider), draft.signer);
2889
+ const signer = signerOf(identityProvider(draft.provider), draft.signer);
2875
2890
  const statement = identityStatement(draft.binding);
2876
2891
  let evidence;
2877
2892
  try {
@@ -3271,9 +3286,25 @@ async function proxy(request, response, chunks, send, cookies, policy) {
3271
3286
  */
3272
3287
  function serviceOf(ctx, params) {
3273
3288
  const serviceId = str(params, "service", true);
3274
- if (!state(ctx).services.some((s) => s.id === serviceId)) throw new CliError("not_found", `No service ${JSON.stringify(serviceId)} (ghostly service list)`);
3289
+ const { services } = state(ctx);
3290
+ if (!services.some((s) => s.id === serviceId)) throw noService(serviceId, servicesNamed(services, serviceId));
3275
3291
  return serviceId;
3276
3292
  }
3293
+ /** The ids of the services `given` names by their name, compared as a chat's label is (`nameKey`: one case, one form). */
3294
+ function servicesNamed(services, given) {
3295
+ const key = nameKey(given);
3296
+ return key ? services.filter((s) => nameKey(s.name) === key).map((s) => s.id) : [];
3297
+ }
3298
+ /**
3299
+ * No service of that id. A service's name given instead (`service add "My App"` makes `my-app`) is told which id to
3300
+ * use: before, it read "No service" of a service `service list` shows by that very name. Same code and exit either way.
3301
+ */
3302
+ function noService(given, named) {
3303
+ const quoted = JSON.stringify(given);
3304
+ if (!named.length) return new CliError("not_found", `No service ${quoted} (ghostly service list)`);
3305
+ const which = named.length === 1 ? `${named[0]}: use its id` : `${named.length} services, ${named.slice(0, -1).join(", ")} and ${named.at(-1)}: use one of their ids`;
3306
+ return new CliError("not_found", `No service with id ${quoted}. ${quoted} is the name of ${which} (ghostly service list)`);
3307
+ }
3277
3308
  /**
3278
3309
  * On, unless `off`; or as the answer's own key (`shared`, `enabled`) says, when a socket client sends it back. Before,
3279
3310
  * only `off` was read, so `{"shared": false}` shared the service with the contact and `{"enabled": false}` turned it on.
@@ -3304,6 +3335,27 @@ function serviceNameOf(params) {
3304
3335
  });
3305
3336
  return name;
3306
3337
  }
3338
+ /** `service add`'s name and target, checked with no profile open (api.ts `refuseBeforeStart`). */
3339
+ function serviceShape(params) {
3340
+ const name = serviceNameOf(params);
3341
+ const target = str(params, "target", true);
3342
+ try {
3343
+ parseLocalTarget(target);
3344
+ } catch (error) {
3345
+ const said = error instanceof Error ? error.message : String(error);
3346
+ const text = target.trim();
3347
+ let shown = "";
3348
+ try {
3349
+ const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `http://${text}`);
3350
+ shown = `: ${url.protocol}//${url.host}${url.pathname}`;
3351
+ } catch {}
3352
+ throw new CliError(/^Only services on this machine/.test(said) ? "refused" : "bad_request", `${said}${shown}`);
3353
+ }
3354
+ return {
3355
+ name,
3356
+ target
3357
+ };
3358
+ }
3307
3359
  function portError(error, port) {
3308
3360
  const { code } = error ?? {};
3309
3361
  if (port && code === "EADDRINUSE") return new CliError("busy", `Port ${port} is in use on this machine: choose another, or leave out --port`);
@@ -3322,20 +3374,7 @@ var SERVICE_METHODS = {
3322
3374
  })) };
3323
3375
  },
3324
3376
  async "service.add"(ctx, params) {
3325
- const name = serviceNameOf(params);
3326
- const target = str(params, "target", true);
3327
- try {
3328
- parseLocalTarget(target);
3329
- } catch (error) {
3330
- const said = error instanceof Error ? error.message : String(error);
3331
- const text = target.trim();
3332
- let shown = text;
3333
- try {
3334
- const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `http://${text}`);
3335
- shown = `${url.protocol}//${url.host}${url.pathname}`;
3336
- } catch {}
3337
- throw new CliError(/^Only services on this machine/.test(said) ? "refused" : "bad_request", `${said}: ${shown}`);
3338
- }
3377
+ const { name, target } = serviceShape(params);
3339
3378
  const { serviceId } = node(ctx).addService({
3340
3379
  name,
3341
3380
  target
@@ -3795,6 +3834,42 @@ var NOT_SENT = {
3795
3834
  message: `More than 48 frames in a second, or the connection is still sending earlier ones: slow down and send it again`
3796
3835
  }
3797
3836
  };
3837
+ // ../../apps/ui/src/lib/localHost.ts
3838
+ /**
3839
+ * Names only a local network answers (RFC 6762, RFC 8375, ICANN's .internal, and the usual router and company ones).
3840
+ * A copy of packages/core/src/localNames.ts, as this module imports nothing; the same as Desktop's
3841
+ * apps/desktop/src/local_names.rs (src/test/chat/linkPreviewParse.test.ts pins all three).
3842
+ */
3843
+ var LOCAL_SUFFIXES = [
3844
+ "localhost",
3845
+ "local",
3846
+ "internal",
3847
+ "lan",
3848
+ "home",
3849
+ "home.arpa",
3850
+ "localdomain",
3851
+ "intranet",
3852
+ "corp"
3853
+ ];
3854
+ /**
3855
+ * A host that names this machine or the local network, as far as its spelling tells: a name under a local suffix
3856
+ * (`localhost`, `.local`, `.lan`, `.home`, `.corp`, …), a single label, private and reserved IP addresses. Previews
3857
+ * are never made for these, a page on the internet may not point its picture at one, and a contact's app may not open
3858
+ * one. (Desktop also checks the addresses a name resolves to.)
3859
+ * In a module of its own, importing nothing: the extension's background worker reads it too.
3860
+ */
3861
+ function isLocalHost(hostname) {
3862
+ const host = hostname.toLowerCase().replace(/\.+$/, "").replace(/^\[|\]$/g, "");
3863
+ if (!host.includes(".") && !host.includes(":")) return true;
3864
+ if (LOCAL_SUFFIXES.some((s) => host === s || host.endsWith(`.${s}`))) return true;
3865
+ const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
3866
+ if (v4) {
3867
+ const [a, b] = [Number(v4[1]), Number(v4[2])];
3868
+ return a === 0 || a === 10 || a === 127 || a >= 224 || a === 169 && b === 254 || a === 172 && b >= 16 && b < 32 || a === 192 && b === 168 || a === 100 && b >= 64 && b < 128 || a === 198 && (b === 18 || b === 19) || a === 192 && b === 0;
3869
+ }
3870
+ if (host.includes(":")) return !/^[23][0-9a-f]{3}:/.test(host) || host.includes(".") || host.startsWith("2002:") || /^2001:(0{0,4}|0{0,3}db8):/.test(host);
3871
+ return false;
3872
+ }
3798
3873
  // src/wallets.ts
3799
3874
  /**
3800
3875
  * Wallets and payments (WISP 1100, phase 2): the app's wallet deck and a chat's payment sheet, as methods. Test
@@ -4013,6 +4088,54 @@ function memoOf(params, verb, field = "memo") {
4013
4088
  }
4014
4089
  return memo || void 0;
4015
4090
  }
4091
+ /**
4092
+ * What `pay` reads of its own words, the target's shape among them: checked again before a one-shot opens the profile
4093
+ * (`refuseBeforeStart`), where a target that is no invoice, address or LNURL started every saved chat to be refused.
4094
+ */
4095
+ function payShape(params) {
4096
+ const comment = memoOf(params, "pay", "comment");
4097
+ const text = str(params, "target", true).trim();
4098
+ const card = cardParam(params);
4099
+ 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");
4100
+ if (!isInvoice(text) && !isLnurl(text)) throw new CliError("bad_request", "Not a Lightning invoice, Lightning address or LNURL");
4101
+ return {
4102
+ comment,
4103
+ text,
4104
+ card
4105
+ };
4106
+ }
4107
+ /** The token `wallet redeem` takes, refused as the engine refuses one Cashu's library cannot read (`refuseBeforeStart`). */
4108
+ async function tokenShape(params) {
4109
+ const token = str(params, "token", true).trim();
4110
+ const { getTokenMetadata } = await import("@cashu/cashu-ts");
4111
+ try {
4112
+ getTokenMetadata(token);
4113
+ } catch {
4114
+ throw new CliError("bad_request", "That is not a valid ecash token");
4115
+ }
4116
+ return token;
4117
+ }
4118
+ /** The mint URL `wallet add-mint` takes, refused in the engine's words when it is no URL or not https (`refuseBeforeStart`). */
4119
+ function mintUrlShape(params) {
4120
+ const url = str(params, "url", true);
4121
+ try {
4122
+ normalizeMintUrl(url);
4123
+ } catch (error) {
4124
+ throw badMintUrl(error) ? new CliError("bad_request", error.message) : error;
4125
+ }
4126
+ return url;
4127
+ }
4128
+ /**
4129
+ * What `pay` says with `paid: false`: the payment is not known paid yet. The mint (or the card's source) holds it
4130
+ * pending, or its answer was lost; the engine keeps asking and never pays it twice. Before, the answer said `paid:
4131
+ * false` and nothing else, and no read showed the sats the Cashu wallet set aside for it. Said in the
4132
+ * words of the app's Cashu card ("set aside", `wallet.cashu.setAsideInfo`).
4133
+ */
4134
+ function notPaidYet(ctx, n, source, amount, feeReserve) {
4135
+ const running = ctx.mode === "one-shot" ? " while this profile runs (`ghostly daemon --detach`)" : "";
4136
+ if (source !== "cashu-mint") return `Not paid yet: your Lightning source has not confirmed this payment (it is pending, or its answer was lost). It is asked again${running} and never paid twice: \`ghostly wallet list\` shows the card's balance once it settles.`;
4137
+ return `Not paid yet: the mint has not settled this payment (it is pending, or its answer was lost). ${`${amount + feeReserve} ${n === "testnet" ? "test sats" : "sats"}`} are set aside for it, out of the balance: they leave with the payment, or come back to the balance if the mint says it failed. It settles by itself: the wallet keeps asking the mint${running} and never pays it twice. \`ghostly wallet history\` lists it once paid, and \`ghostly wallet list\` shows the balance.`;
4138
+ }
4016
4139
  function badMintUrl(error) {
4017
4140
  const code = error instanceof Error ? error.engineCode : void 0;
4018
4141
  return code === "invalidMintUrl" || code === "mintNotHttps";
@@ -4067,6 +4190,34 @@ function walletRefusal(error) {
4067
4190
  const code = WALLET_REFUSALS.find(([pattern]) => pattern.test(error.message))?.[1];
4068
4191
  return code ? new CliError(code, error.message) : error;
4069
4192
  }
4193
+ /**
4194
+ * `wallet redeem` of ecash from a mint that is not one of the wallet's: the engine names the mint's host only and no
4195
+ * way on. Its words, then the command that adds the whole mint URL (the token's), for one who trusts that mint: a mint
4196
+ * holds the sats, so it is offered, never done. Shell-quoted as any hint's word; a URL no quoting survives is not printed.
4197
+ */
4198
+ function mintNotAdded(error) {
4199
+ if (!(error instanceof Error) || !/^Ecash from \S+ is not accepted$/.test(error.message)) return void 0;
4200
+ const mint = error.mint;
4201
+ if (typeof mint !== "string") return void 0;
4202
+ return new CliError("engine", `${error.message}: its mint is not one of yours (if you trust it to hold your sats: ghostly wallet add-mint ${shellWord(mint, "<the token's mint URL>")})`);
4203
+ }
4204
+ /**
4205
+ * The mints `mintNotAdded` offers no `add-mint` for. A token is what a contact sends, and the way out reads as the
4206
+ * app's advice: never a command `wallet add-mint` refuses (plain http off this machine), nor one that makes a server
4207
+ * on this machine or the local network a mint the wallet then talks to. One who runs such a mint types its URL.
4208
+ */
4209
+ function mintNotOffered(error) {
4210
+ const mint = error instanceof Error && /^Ecash from \S+ is not accepted$/.test(error.message) ? error.mint : void 0;
4211
+ if (typeof mint !== "string") return void 0;
4212
+ const words = error.message;
4213
+ try {
4214
+ normalizeMintUrl(mint);
4215
+ } catch (refusal) {
4216
+ return new CliError("engine", `${words}: its mint is not one of yours, and not one a wallet can add (${refusal.message})`);
4217
+ }
4218
+ if (!isLocalHost(new URL(mint).hostname)) return void 0;
4219
+ return new CliError("engine", `${words}: its mint is not one of yours, and it is on this machine or a local network (add a mint there only if you run it yourself)`);
4220
+ }
4070
4221
  var WALLET_METHODS = Object.fromEntries(Object.entries({
4071
4222
  async "wallet.list"(ctx, params) {
4072
4223
  await federationsOpen(ctx);
@@ -4212,11 +4363,13 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4212
4363
  };
4213
4364
  },
4214
4365
  async "wallet.redeem"(ctx, params) {
4215
- return node(ctx).walletReceiveToken({ token: str(params, "token", true).trim() });
4366
+ return node(ctx).walletReceiveToken({ token: await tokenShape(params) }).catch((error) => {
4367
+ throw mintNotOffered(error) ?? mintNotAdded(error) ?? error;
4368
+ });
4216
4369
  },
4217
4370
  async "wallet.mint.add"(ctx, params) {
4218
4371
  return node(ctx).walletAddMint({
4219
- url: str(params, "url", true),
4372
+ url: mintUrlShape(params),
4220
4373
  ...bool(params, "primary") ? { primary: true } : {}
4221
4374
  }).catch((error) => {
4222
4375
  throw badMintUrl(error) ? new CliError("bad_request", error.message) : error;
@@ -4248,18 +4401,13 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4248
4401
  },
4249
4402
  /** An invoice, a Lightning address or an LNURL, from the network's Lightning (a card of it, or its default). */
4250
4403
  async "pay"(ctx, params) {
4251
- const comment = memoOf(params, "pay", "comment");
4252
- const text = str(params, "target", true).trim();
4253
- const card = cardParam(params);
4404
+ const { comment, text, card } = payShape(params);
4254
4405
  let invoice = text.replace(/^lightning:/i, "");
4255
- let n;
4256
4406
  let note;
4257
- 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");
4258
4407
  const chat = params.chat === void 0 ? void 0 : ownChatOf(ctx, params);
4259
4408
  if (chat) inviteTaken(chat);
4260
- if (isInvoice(text)) n = network(params);
4261
- else if (isLnurl(text)) {
4262
- n = network(params);
4409
+ const n = network(params);
4410
+ if (!isInvoice(text)) {
4263
4411
  const amount = num(params, "amount", 0, { min: 1 });
4264
4412
  if (!amount) throw new CliError("bad_request", "amount is required to pay a Lightning address or LNURL");
4265
4413
  if (n === "mainnet" && !bool(params, "confirmReal")) throw new CliError("confirm", "This pays real money (Mainnet): pass --confirm-real to confirm this payment");
@@ -4276,7 +4424,7 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4276
4424
  });
4277
4425
  invoice = got.invoice;
4278
4426
  note = got.note;
4279
- } else throw new CliError("bad_request", "Not a Lightning invoice, Lightning address or LNURL");
4427
+ }
4280
4428
  if (n === "mainnet" && !bool(params, "confirmReal")) throw new CliError("confirm", "This pays real money (Mainnet): pass --confirm-real to confirm this payment");
4281
4429
  await federationsOpen(ctx);
4282
4430
  const quote = await node(ctx).walletQuoteInvoice({
@@ -4298,12 +4446,14 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
4298
4446
  invoice
4299
4447
  } : {}
4300
4448
  });
4449
+ const source = quote.source ?? quote.mint;
4301
4450
  return {
4302
4451
  network: n,
4303
4452
  amount: quote.amount,
4304
4453
  feeReserve: quote.feeReserve,
4305
- source: quote.source ?? quote.mint,
4306
- paid: paid.paid
4454
+ source,
4455
+ paid: paid.paid,
4456
+ ...!paid.paid && { note: notPaidYet(ctx, n, source, quote.amount, quote.feeReserve) }
4307
4457
  };
4308
4458
  },
4309
4459
  /** Ecash to a contact in a chat (the payment sheet's Pay). */
@@ -4833,6 +4983,34 @@ function dhtOnlyTimeout(ctx, chat, text, ref, ms, error) {
4833
4983
  note
4834
4984
  }) : error;
4835
4985
  }
4986
+ /**
4987
+ * What keeps `link` off a live session, or undefined: a chat on DHT only opens none (WISP 100: no app dials it). A hold
4988
+ * of this side's (`chat disconnect --hold`) ends by itself (`held`: when), unless the contact's choice keeps it there
4989
+ * too; this side's choice or the contact's is `chat connect`'s refusal (apiKit `dhtOnly`), in its words.
4990
+ */
4991
+ function offLive(ctx, link) {
4992
+ const held = link.deliveryMode === "dht" && link.dhtDelivery?.peerMode !== "dht" ? holdEnds(ctx, link.id) : null;
4993
+ if (held !== null) return { held };
4994
+ try {
4995
+ dhtOnly(link);
4996
+ } catch (error) {
4997
+ if (error instanceof CliError) return { refusal: error };
4998
+ throw error;
4999
+ }
5000
+ }
5001
+ /**
5002
+ * A `chat wait --until live` that timed out on a chat on DHT only: it could never go live, and its timeout read as a
5003
+ * slow network, so a script waited again. Said with why and what ends it, in `chat connect`'s words; same code, exit
5004
+ * and fields. Read as the chat is at the end: one taken off DHT only meanwhile keeps the usual words.
5005
+ */
5006
+ function liveNeverCame(ctx, linkId, ref, error) {
5007
+ if (!(error instanceof CliError) || error.code !== "timeout" || error.details) return error;
5008
+ const link = state(ctx).links.find((l) => l.id === linkId);
5009
+ const off = link && offLive(ctx, link);
5010
+ if (!off) return error;
5011
+ const why = "held" in off ? heldWords(off.held, ref, "it goes live", ctx.mode === "one-shot") : off.refusal.message;
5012
+ return new CliError("timeout", `${error.message}. ${why.charAt(0).toUpperCase()}${why.slice(1)}`);
5013
+ }
4836
5014
  var METHODS = {
4837
5015
  ...WALLET_METHODS,
4838
5016
  ...FILE_METHODS,
@@ -5090,6 +5268,8 @@ var METHODS = {
5090
5268
  if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; edit with --force if you mean to`, { kind: secret.kind });
5091
5269
  }
5092
5270
  const { wait, ms } = confirmWait(ctx, params, link.id);
5271
+ const prior = await node(ctx).getMessage(link.id, messageId);
5272
+ const before = prior ? prior.edit?.seq ?? 0 : void 0;
5093
5273
  const result = await node(ctx).editMessage({
5094
5274
  linkId: link.id,
5095
5275
  messageId,
@@ -5101,6 +5281,8 @@ var METHODS = {
5101
5281
  }, dhtTooLong(ctx, link, result.error, "edit", str(params, "chat", true)), result);
5102
5282
  const id = result.messageId ?? messageId;
5103
5283
  let message = await node(ctx).getMessage(link.id, id);
5284
+ const edits = message?.edit?.seq ?? 0;
5285
+ const unchanged = !!message && edits === (before ?? 0);
5104
5286
  if (wait === "confirmed" && message?.edit?.pending) message = await waitForEdit(ctx, link.id, id, ms);
5105
5287
  const confirmed = !!message && !message.edit?.pending;
5106
5288
  return {
@@ -5108,6 +5290,7 @@ var METHODS = {
5108
5290
  messageId: id,
5109
5291
  edits: message?.edit?.seq ?? 0,
5110
5292
  confirmed,
5293
+ ...unchanged && { unchanged: true },
5111
5294
  ...!confirmed && result.note && { note: result.note },
5112
5295
  ...!confirmed && keptForJoin(ctx, link.id, "the edit")
5113
5296
  };
@@ -5205,7 +5388,11 @@ var METHODS = {
5205
5388
  ref: str(params, "chat", true)
5206
5389
  }) : void 0;
5207
5390
  if (gone) throw gone;
5208
- if (result.error) throw new CliError(result.refused || /Only the admin/.test(result.error) ? "refused" : /not in this (?:chat|group)|Nothing is pinned/.test(result.error) ? "not_found" : "bad_request", result.error);
5391
+ if (result.error) {
5392
+ const error = new CliError(result.refused || /Only the admin/.test(result.error) ? "refused" : /not in this (?:chat|group)|Nothing is pinned/.test(result.error) ? "not_found" : "bad_request", result.error);
5393
+ const group = target.group ? groupById(ctx, target.id) : void 0;
5394
+ throw group ? notInYetError(group, str(params, "chat", true), error) : error;
5395
+ }
5209
5396
  if (target.group) {
5210
5397
  const n = result.n, pinned = remove ? null : messageId;
5211
5398
  const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, target.id, messageId ?? "", { pin: n }, ms) : node(ctx).groupTaken({
@@ -5421,14 +5608,15 @@ var METHODS = {
5421
5608
  max: 3600
5422
5609
  }) * 1e3;
5423
5610
  const ref = str(params, "message", true);
5424
- const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender === "me");
5425
- if (!message) throw noMessage(ref, {
5611
+ let theirs;
5612
+ const message = await messageOf(ctx, target.linkId, ref, (m) => {
5613
+ if (m.sender !== "me" && (m.id === ref || m.wireId === ref)) theirs ??= m;
5614
+ return m.sender === "me";
5615
+ });
5616
+ if (!message) throw deleteNotMine(ctx, target, ref, theirs, {
5426
5617
  group: target.group,
5427
5618
  ref: str(params, "chat", true)
5428
- }, {
5429
- whose: "of yours",
5430
- tail: ": only your own messages are deleted for everyone"
5431
- });
5619
+ }, purge);
5432
5620
  const result = await node(ctx).removeMessage({
5433
5621
  linkId: target.linkId,
5434
5622
  messageId: message.id
@@ -5548,7 +5736,7 @@ var METHODS = {
5548
5736
  return { removed: link.id };
5549
5737
  },
5550
5738
  async "chat.transport"(ctx, params) {
5551
- const link = chatOf(ctx, params);
5739
+ const link = chatNotGroupLink(ctx, params);
5552
5740
  const name = str(params, "transport", true);
5553
5741
  const transport = Object.hasOwn(TRANSPORT_NAMES, name) ? TRANSPORT_NAMES[name] : void 0;
5554
5742
  if (!transport) throw new CliError("bad_request", `transport must be one of auto, dht, webrtc, iroh, hyperdht`);
@@ -5563,7 +5751,7 @@ var METHODS = {
5563
5751
  },
5564
5752
  /** Reconnects now; a chat held off its direct link (`chat disconnect --hold`) leaves the hold first. */
5565
5753
  async "chat.connect"(ctx, params) {
5566
- const link = chatOf(ctx, params);
5754
+ const link = chatNotGroupLink(ctx, params);
5567
5755
  await releaseHold(ctx, link.id, "connect");
5568
5756
  inviteTaken(link);
5569
5757
  dhtOnly(findChat(state(ctx).links, link.id));
@@ -5578,7 +5766,7 @@ var METHODS = {
5578
5766
  * direct link that long, on the DHT (its "DHT only" choice, taken back after); 0 ends a hold now.
5579
5767
  */
5580
5768
  async "chat.disconnect"(ctx, params) {
5581
- const link = chatOf(ctx, params);
5769
+ const link = chatNotGroupLink(ctx, params);
5582
5770
  const minutes = params.hold === void 0 ? void 0 : num(params, "hold", 0, {
5583
5771
  min: 0,
5584
5772
  max: HOLD_MAX_MINUTES
@@ -5609,7 +5797,7 @@ var METHODS = {
5609
5797
  return chatJson(findChat(state(ctx).links, link.id));
5610
5798
  },
5611
5799
  async "chat.wait"(ctx, params) {
5612
- const link = chatOf(ctx, params);
5800
+ const link = chatNotGroupLink(ctx, params);
5613
5801
  const until = oneOf(params, "until", [
5614
5802
  "live",
5615
5803
  "text",
@@ -5619,11 +5807,14 @@ var METHODS = {
5619
5807
  min: 1,
5620
5808
  max: 86400
5621
5809
  }) * 1e3;
5810
+ const ref = str(params, "chat", true);
5622
5811
  return chatJson(await waitForState(ctx, (s) => {
5623
5812
  const now = s.links.find((l) => l.id === link.id);
5624
5813
  if (!now) throw new CliError("not_found", `Chat ${link.id} was removed`);
5625
5814
  return (until === "live" ? isLive(now) : until === "text" ? now.textDelivery === "stream" || now.textDelivery === "dht" || now.textDelivery === "hold" : !!now.peerParticipationKey || !!now.pairingProgress?.peerSeen || now.pairing?.status === "ready" || isLive(now)) ? now : void 0;
5626
- }, ms, `chat ${link.id} ${chatState(until).to}`));
5815
+ }, ms, `chat ${ref} ${chatState(until).to}`).catch((error) => {
5816
+ throw until === "live" ? liveNeverCame(ctx, link.id, ref, error) : error;
5817
+ }));
5627
5818
  },
5628
5819
  async "group.create"(ctx, params) {
5629
5820
  const name = groupNameOf(params);
@@ -5645,7 +5836,7 @@ var METHODS = {
5645
5836
  ({groupId} = await node(ctx).joinGroupByLink({ link }));
5646
5837
  } catch (error) {
5647
5838
  if (error instanceof Error && error.message === "This is not a link to a group") throw new CliError("bad_request", error.message);
5648
- throw error;
5839
+ throw joinRefused(link, error);
5649
5840
  }
5650
5841
  return letIn(ctx, groupId, link, before.find((g) => g.id === groupId));
5651
5842
  },
@@ -5701,7 +5892,7 @@ var METHODS = {
5701
5892
  if (result.error) throw replyTo && notHere(result.error, replyTo, {
5702
5893
  group: true,
5703
5894
  ref: str(params, "group", true)
5704
- }) || (result.refused ? new CliError("refused", result.error) : groupSendRefused(result.error));
5895
+ }) || notInYetError(group, str(params, "group", true), result.refused ? new CliError("refused", result.error) : groupSendRefused(result.error));
5705
5896
  const messageId = result.messageId ?? null;
5706
5897
  const edges = messageId ? wait === "sent" ? await waitForGroupFrame(ctx, group.id, messageId, void 0, ms) : node(ctx).groupTaken({
5707
5898
  groupId: group.id,
@@ -5784,9 +5975,12 @@ var METHODS = {
5784
5975
  min: 1,
5785
5976
  max: 3600
5786
5977
  }) * 1e3;
5978
+ const ref = str(params, "group", true);
5787
5979
  const { n, ...said } = await react(ctx, `group:${group.id}`, params, {
5788
5980
  group: true,
5789
- ref: str(params, "group", true)
5981
+ ref
5982
+ }).catch((error) => {
5983
+ throw error instanceof CliError ? notInYetError(group, ref, error) : error;
5790
5984
  });
5791
5985
  const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, group.id, said.messageId, { reaction: n }, ms) : node(ctx).groupTaken({
5792
5986
  groupId: group.id,
@@ -5818,7 +6012,7 @@ var METHODS = {
5818
6012
  max: 600
5819
6013
  });
5820
6014
  if (!typing && seconds) throw new CliError("bad_request", "for keeps typing on: not with stop");
5821
- if (typing && group.status !== "active") throw new CliError("refused", group.statusReason ?? "You are not in this group");
6015
+ if (typing && group.status !== "active") throw new CliError("refused", group.statusReason ?? notInYet(group, str(params, "group", true)) ?? "You are not in this group");
5822
6016
  const target = { groupId: group.id };
5823
6017
  endTyping(ctx, target, false);
5824
6018
  sayTyping(ctx, target, typing, word);
@@ -5840,7 +6034,10 @@ var METHODS = {
5840
6034
  async "group.leave"(ctx, params) {
5841
6035
  const group = groupOf(ctx, params);
5842
6036
  if (!bool(params, "yes")) throw new CliError("confirm", "Leaving a group deletes its history and files on this device; pass --yes (yes: true over the socket) to go on");
5843
- const { admin } = await node(ctx).leaveGroup({ groupId: group.id });
6037
+ const ref = str(params, "group", true);
6038
+ const { admin } = await node(ctx).leaveGroup({ groupId: group.id }).catch((error) => {
6039
+ throw leaveRefused(group, ref, error);
6040
+ });
5844
6041
  const next = admin ? group.members.find((m) => m.key === admin) : void 0;
5845
6042
  return {
5846
6043
  left: group.id,
@@ -5992,9 +6189,9 @@ async function guardEngineSend(ctx, method, args) {
5992
6189
  ...args.fields && typeof args.fields === "object" ? Object.values(args.fields) : []
5993
6190
  ];
5994
6191
  if (method === "forwardMessages") {
5995
- const ids = Array.isArray(args.messageIds) ? args.messageIds.filter((id) => typeof id === "string") : [];
6192
+ const ids = Array.isArray(args.messageIds) ? [...new Set(args.messageIds.filter((id) => typeof id === "string"))] : [];
5996
6193
  const linkId = args.linkId;
5997
- texts = typeof linkId === "string" && linkId ? await Promise.all(ids.map(async (id) => {
6194
+ texts = typeof linkId === "string" && linkId && ids.length <= 30 ? await Promise.all(ids.map(async (id) => {
5998
6195
  const message = await node(ctx).getMessage(linkId, id);
5999
6196
  return message && !message.file ? message.text : null;
6000
6197
  })) : [];
@@ -6069,6 +6266,49 @@ function groupSendRefused(error) {
6069
6266
  if (/^You (were removed from|left|are no longer in) this group$|Membership changes are halted/.test(error)) return new CliError("refused", error);
6070
6267
  return new CliError("unavailable", error);
6071
6268
  }
6269
+ /** The engine's admin who may not leave: the app's words say "make someone the admin", which names no command here. */
6270
+ var ADMIN_ALONE = "You are the admin and nobody else in the group is online to take over. Try again when a member is, or make someone the admin first.";
6271
+ /**
6272
+ * `group leave` the engine refused, said with the CLI's next step: an invitation not joined yet answered "Group not
6273
+ * found" of a group `group show` lists (its way out is `group decline`), and an admin alone online "make someone the
6274
+ * admin", the app's words. The code stays the engine's.
6275
+ */
6276
+ function leaveRefused(group, ref, error) {
6277
+ if (!(error instanceof Error)) return error;
6278
+ const shown = shellWord(ref, group.id);
6279
+ if (error.message === ADMIN_ALONE) return new CliError("engine", `You are the admin and nobody else in ${groupCalled(group)} is online to take over: try again when a member is, or make one the admin first (ghostly group admin ${shown} <member key>)`);
6280
+ const yet = error.message === "Group not found" ? notInYet(group, ref, true) : void 0;
6281
+ return yet ? new CliError("engine", yet) : error;
6282
+ }
6283
+ /**
6284
+ * `group join` the engine refused for a group held here under the link's id, in the app's words ("Delete it from this
6285
+ * device", its menu item), said with the CLI's command. The code stays the engine's. "Answer it first" comes only for
6286
+ * an invitation taken back (a live one is kept and the link goes on beside it), which `group accept` refuses: its way
6287
+ * out is `group decline`.
6288
+ */
6289
+ /**
6290
+ * The link `group join` takes, read before a one-shot opens the profile (`refuseBeforeStart`): one that names no group,
6291
+ * a private one's or a community's, is refused as the engine's `joinByLink` refuses it with the same two decoders.
6292
+ */
6293
+ function groupLinkShape(params) {
6294
+ const link = str(params, "link", true);
6295
+ if (!decodeCommunityLink(link) && !decodeGroupEntryLink(link)) throw new CliError("bad_request", "This is not a link to a group");
6296
+ }
6297
+ function joinRefused(link, error) {
6298
+ if (!(error instanceof Error)) return error;
6299
+ const id = (decodeCommunityLink(link) ?? decodeGroupEntryLink(link))?.g ?? "<group>";
6300
+ if (error.message === "You are out of this group and its history is still here. Delete it from this device to join with a link.") return new CliError("engine", `You are out of this group and its history is still here: ghostly group forget ${id} --yes deletes it from this device, then join with the link`);
6301
+ if (error.message === "You have an invitation to this group. Answer it first.") return new CliError("engine", `Its invitation to this group was taken back: ghostly group decline ${id} drops it, then join with the link`);
6302
+ return error;
6303
+ }
6304
+ /**
6305
+ * The chat a command about a chat's own connection names (`chat connect`, `disconnect`, `transport`, `wait`): a group's
6306
+ * name says a group has none of its own, as `chat show` names `group show`. It read "(ghostly chat list)", a list that
6307
+ * never has the group.
6308
+ */
6309
+ function chatNotGroupLink(ctx, params) {
6310
+ return notAGroup(ctx, params, () => chatOf(ctx, params), (shown) => `it connects through its members' chats, with no transport of its own (ghostly group show ${shown})`);
6311
+ }
6072
6312
  /**
6073
6313
  * A chat command given a group's id, prefix or name: `not_found` that says it is a group, with `hint`: the group
6074
6314
  * command that takes it (`react` on a group, where `group react` is meant), or what to do where none does. `group:<id>`,
@@ -6106,7 +6346,32 @@ function chatNotGroup(ctx, params, command, rest = "") {
6106
6346
  async function editRefused(ctx, linkId, ref, place, error, result) {
6107
6347
  if (!result.refused) return new CliError("unavailable", error);
6108
6348
  if (result.missing ?? !await messageOf(ctx, linkId, ref)) return noMessage(ref, place);
6109
- return new CliError("refused", error);
6349
+ return new CliError("refused", editRefusalWords(error, ref, place));
6350
+ }
6351
+ /**
6352
+ * The engine's refusal of an edit with what to run instead: it named none, so a bot that hit the edit cap had a sentence
6353
+ * and exit 1 to go on. Matched by the engine's exact words (`editMessage`, `GroupEdits.edit`); any other sentence, or
6354
+ * one these no longer match, stays the engine's.
6355
+ */
6356
+ function editRefusalWords(error, ref, place) {
6357
+ const chat = shellWord(place.ref, place.group ? "<group>" : "<chat>"), id = shellWord(ref, "<message>");
6358
+ const send = `ghostly ${place.group ? "group send" : "send"} ${chat}`;
6359
+ if (error === "Only your own text messages can be edited") return `${error}: to answer this one, reply to it (${send} --reply ${id} <text>)`;
6360
+ const most = /^(This message was edited \d+ times, the most one takes)\.$/.exec(error);
6361
+ if (most) return `${most[1]}: send the new text as a new message (${send} <text>); ghostly message delete ${chat} ${id} --everyone takes the old one away`;
6362
+ if (error === "An edit cannot read as a join notice.") return "An edit cannot read as a join notice (\"👋 … joined\"): change its first words";
6363
+ return error;
6364
+ }
6365
+ /**
6366
+ * `message delete --everyone` given no message of mine. It said "No message … of yours" for all of them, as if one of
6367
+ * mine deleted already were the contact's: another's message says whose it is (in a chat, with the delete that takes
6368
+ * it off this device), one of mine deleted already says so (the chat's deleted ids), and any other is not here.
6369
+ */
6370
+ function deleteNotMine(ctx, target, ref, theirs, place, purge) {
6371
+ if (theirs && target.group) return new CliError("not_found", `${JSON.stringify(ref)} is another member's message: only its author deletes a group's message, for everyone`);
6372
+ if (theirs) return new CliError("not_found", `${JSON.stringify(ref)} is the contact's message: only your own messages are deleted for everyone (ghostly message delete ${shellWord(place.ref, "<chat>")} ${shellWord(theirs.id, "<message>")}${purge ? " --purge" : ""} deletes it on this device)`);
6373
+ const deleted = !target.group && node(ctx).deletedIdsOf(target.linkId).includes(ref);
6374
+ return noMessage(ref, place, deleted ? { tail: ": it was deleted already" } : {});
6110
6375
  }
6111
6376
  /**
6112
6377
  * About the longest ASCII text, and edit, the DHT packet carries once sealed and signed: within the 256 bytes, the
@@ -6169,7 +6434,24 @@ async function connectWithin(ctx, link, ms) {
6169
6434
  } finally {
6170
6435
  clearTimeout(timer);
6171
6436
  }
6172
- throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact did not answer. ${connectNext(ctx, link)}`, { chat: link.id });
6437
+ throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: ${notLiveYet(ctx, link)}. ${connectNext(ctx, link)}`, { chat: link.id });
6438
+ }
6439
+ /**
6440
+ * How long after a daemon's start a chat with no attempt ended yet reads as still resuming: with many chats, the start
6441
+ * brings them back a few at a time, over minutes.
6442
+ */
6443
+ var RESUMING_MS = 3e5;
6444
+ /**
6445
+ * Why a daemon's `chat connect` timed out, as the chat reads at the end. No attempt of this run ended yet
6446
+ * (`lastAttempt` null) while the daemon just started, or while the contact reads online: the chat is still coming
6447
+ * back, nobody failed to answer. It said "the contact did not answer" right after a `daemon restart`, with the
6448
+ * contact online. A one-shot always just started: it keeps the words it had.
6449
+ */
6450
+ function notLiveYet(ctx, link) {
6451
+ const now = state(ctx).links.find((l) => l.id === link.id) ?? link;
6452
+ if (ctx.mode !== "daemon" || now.liveAttempt) return "the contact did not answer";
6453
+ if (process.uptime() * 1e3 < RESUMING_MS) return "the chat is still resuming after the daemon's start, and no attempt to reach the contact has ended yet";
6454
+ return now.peerOnline ? "your contact's app reads online, and no attempt to reach it has ended yet" : "the contact did not answer";
6173
6455
  }
6174
6456
  /** What happens after a `chat connect` the contact did not answer: the daemon dials again by itself, a one-shot does not. */
6175
6457
  function connectNext(ctx, link) {
@@ -6301,6 +6583,22 @@ function quoteChecked(json, message, originals) {
6301
6583
  }
6302
6584
  };
6303
6585
  }
6586
+ /**
6587
+ * Each method's check of its own words, the one its handler makes first: none needs the profile. A one-shot makes it
6588
+ * before the profile opens (main.ts `session`): a target that is no invoice, a token or mint URL that is none, or a word
6589
+ * that is no group link started every saved chat to be refused (with 10 chats, 20 relay requests and 0.4 s more).
6590
+ */
6591
+ var SHAPES = {
6592
+ "pay": payShape,
6593
+ "wallet.redeem": tokenShape,
6594
+ "wallet.mint.add": mintUrlShape,
6595
+ "group.join": groupLinkShape,
6596
+ "service.add": serviceShape
6597
+ };
6598
+ /** Throws what `method` answers `params` whose shape it refuses, with no profile open; nothing for any other. */
6599
+ async function refuseBeforeStart(method, params) {
6600
+ if (Object.hasOwn(SHAPES, method)) await SHAPES[method](params);
6601
+ }
6304
6602
  var API_METHODS = Object.keys(METHODS);
6305
6603
  /**
6306
6604
  * Runs one method of the API: one the table lists itself (`constructor`, which every object has, is none). `call`: who
@@ -6312,6 +6610,6 @@ async function callApi(ctx, method, params = {}, call) {
6312
6610
  if (params === null || typeof params !== "object" || Array.isArray(params)) throw new CliError("bad_request", "params must be an object");
6313
6611
  return run(ctx, await withStoredIds(ctx, params), call);
6314
6612
  }
6315
- 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 };
6613
+ export { groupJson as _, hideStateSecrets as a, resumeHolds as b, refuseBeforeStart as c, reportAppFrames as d, servedApps as f, chatMessageJson as g, chatJson as h, groupSendRefused as i, settingsInEffect as l, identityProvider as m, SETTABLE as n, mentionsFor as o, nodeLocalFetch as p, callApi as r, redactSettings as s, API_METHODS as t, paymentJson as u, groupMessageJson as v, flushCardUpdates as x, groupPayTwins as y };
6316
6614
 
6317
- //# sourceMappingURL=api-Dnq86JAA.js.map
6615
+ //# sourceMappingURL=api-O57SNJcb.js.map