@ghostlytools/cli 1.10.1 → 1.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -10
- package/SKILL.md +3 -2
- package/dist/assets/{api-BOWLZYXM.js → api-BdaxsDvA.js} +2 -2
- package/dist/assets/{api-Bi6hCcwG.js → api-C4MLg5Rs.js} +126 -49
- package/dist/assets/api-C4MLg5Rs.js.map +1 -0
- package/dist/assets/{apiKit-DzXHZojD.js → apiKit-BbNaxZGZ.js} +87 -25
- package/dist/assets/apiKit-BbNaxZGZ.js.map +1 -0
- package/dist/assets/{apps-DIQbzG08.js → apps-BluQgEhv.js} +5 -5
- package/dist/assets/{apps-DIQbzG08.js.map → apps-BluQgEhv.js.map} +1 -1
- package/dist/assets/{apps-0Ks6KjqS.js → apps-BtGFth7o.js} +1 -1
- package/dist/assets/{arkade-zozCldAE.js → arkade-DdZx4b_I.js} +2 -2
- package/dist/assets/{arkade-zozCldAE.js.map → arkade-DdZx4b_I.js.map} +1 -1
- package/dist/assets/{backup-BL49Kt-T.js → backup-DyDsW7sC.js} +7 -7
- package/dist/assets/{backup-BL49Kt-T.js.map → backup-DyDsW7sC.js.map} +1 -1
- package/dist/assets/{backup-BvIFcZM7.js → backup-I1n7ccz7.js} +1 -1
- package/dist/assets/{buttons-CAW5v5EE.js → buttons-Do7dCku6.js} +6 -6
- package/dist/assets/{buttons-CAW5v5EE.js.map → buttons-Do7dCku6.js.map} +1 -1
- package/dist/assets/buttons-DpjwXePb.js +2 -0
- package/dist/assets/{client-CyApKBEw.js → client-CWsjRiH8.js} +3 -3
- package/dist/assets/{client-CyApKBEw.js.map → client-CWsjRiH8.js.map} +1 -1
- package/dist/assets/{codec-DqFxxB_q.js → codec-DPaXhuYc.js} +2 -2
- package/dist/assets/{codec-DqFxxB_q.js.map → codec-DPaXhuYc.js.map} +1 -1
- package/dist/assets/{envelope-CMUgz31I.js → envelope-5Gu9yGk_.js} +2 -2
- package/dist/assets/{envelope-CMUgz31I.js.map → envelope-5Gu9yGk_.js.map} +1 -1
- package/dist/assets/{errors-R4S2SAEM.js → errors-Dt-ZnyOX.js} +3 -1
- package/dist/assets/errors-Dt-ZnyOX.js.map +1 -0
- package/dist/assets/{fixedHosts-C2hdCfzK.js → fixedHosts-PR1BcfKX.js} +7 -8
- package/dist/assets/fixedHosts-PR1BcfKX.js.map +1 -0
- package/dist/assets/{groupFiles-BAQIt_bJ.js → groupFiles-BuToTMUk.js} +307 -69
- package/dist/assets/groupFiles-BuToTMUk.js.map +1 -0
- package/dist/assets/{host-CaRlDMTd.js → host-fkQYBvKH.js} +322 -72
- package/dist/assets/host-fkQYBvKH.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-BxADl3SG.js → hyperdhtRelay-DDCak5PY.js} +28 -20
- package/dist/assets/hyperdhtRelay-DDCak5PY.js.map +1 -0
- package/dist/assets/{irohWeb-D2sh6EWp.js → irohWeb-B4_swKx0.js} +112 -34
- package/dist/assets/{irohWeb-D2sh6EWp.js.map → irohWeb-B4_swKx0.js.map} +1 -1
- package/dist/assets/{main-Bc4Ow56Z.js → main-ClYsttvY.js} +98 -51
- package/dist/assets/main-ClYsttvY.js.map +1 -0
- package/dist/assets/{mainline-DWh4Ccri.js → mainline-Hsk2SZ1B.js} +66 -6
- package/dist/assets/mainline-Hsk2SZ1B.js.map +1 -0
- package/dist/assets/{networkReason-DT_D_Wpc.js → networkReason-C9Hr-hO7.js} +4 -4
- package/dist/assets/{networkReason-DT_D_Wpc.js.map → networkReason-C9Hr-hO7.js.map} +1 -1
- package/dist/assets/{nwc-DoSEhUKb.js → nwc-BbK6qNxS.js} +3 -3
- package/dist/assets/{nwc-DoSEhUKb.js.map → nwc-BbK6qNxS.js.map} +1 -1
- package/dist/assets/{nwcProvider-CGWqUjpB.js → nwcProvider-D_tt2X3Z.js} +2 -2
- package/dist/assets/{nwcProvider-CGWqUjpB.js.map → nwcProvider-D_tt2X3Z.js.map} +1 -1
- package/dist/assets/{ownDid-CbGjRLBn.js → ownDid-DkK_jem4.js} +2 -2
- package/dist/assets/{ownDid-CbGjRLBn.js.map → ownDid-DkK_jem4.js.map} +1 -1
- package/dist/assets/{profiles-DgIfvBeN.js → profiles-aV9vaK0B.js} +17 -8
- package/dist/assets/profiles-aV9vaK0B.js.map +1 -0
- package/dist/assets/{registry-C5cn80Rw.js → registry-C9T6tYCO.js} +1 -1
- package/dist/assets/{registry-BSyxGjN6.js → registry-CEjnubep.js} +57 -17
- package/dist/assets/registry-CEjnubep.js.map +1 -0
- package/dist/assets/{resolve-D-9YRFhl.js → resolve-BBOrN13E.js} +27 -6
- package/dist/assets/resolve-BBOrN13E.js.map +1 -0
- package/dist/assets/{restoredRows-CRYwIx3g.js → restoredRows-YhlbokEE.js} +4 -2
- package/dist/assets/restoredRows-YhlbokEE.js.map +1 -0
- package/dist/assets/{secretGuard-CSVNxXVW.js → secretGuard-B7Hj0Kvz.js} +2 -2
- package/dist/assets/{secretGuard-CSVNxXVW.js.map → secretGuard-B7Hj0Kvz.js.map} +1 -1
- package/dist/assets/secretGuard-DUr6bgKc.js +2 -0
- package/dist/assets/{server-BufntkX8.js → server-BJ3T-kx3.js} +1051 -389
- package/dist/assets/server-BJ3T-kx3.js.map +1 -0
- package/dist/assets/{src-CCt5s4DK.js → src-BIdfHB7t.js} +667 -134
- package/dist/assets/src-BIdfHB7t.js.map +1 -0
- package/dist/assets/{sshForges-D8CPaIbR.js → sshForges-CRg-NGld.js} +2 -2
- package/dist/assets/{sshForges-D8CPaIbR.js.map → sshForges-CRg-NGld.js.map} +1 -1
- package/dist/assets/{translate-Cb-6hMhD.js → translate-b0X61WMI.js} +3 -3
- package/dist/assets/{translate-Cb-6hMhD.js.map → translate-b0X61WMI.js.map} +1 -1
- package/dist/assets/{usdt-ds461mzA.js → usdt-6CQdfye1.js} +7 -4
- package/dist/assets/usdt-6CQdfye1.js.map +1 -0
- package/dist/assets/waitNotice-Ce3YCinu.js +101 -0
- package/dist/assets/waitNotice-Ce3YCinu.js.map +1 -0
- package/dist/assets/{words-B1ylON2h.js → words-Dk6o6wz4.js} +4 -4
- package/dist/assets/words-Dk6o6wz4.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-Bi6hCcwG.js.map +0 -1
- package/dist/assets/apiKit-DzXHZojD.js.map +0 -1
- package/dist/assets/buttons-oJI5mHSL.js +0 -2
- package/dist/assets/errors-R4S2SAEM.js.map +0 -1
- package/dist/assets/fixedHosts-C2hdCfzK.js.map +0 -1
- package/dist/assets/groupFiles-BAQIt_bJ.js.map +0 -1
- package/dist/assets/host-CaRlDMTd.js.map +0 -1
- package/dist/assets/hyperdhtRelay-BxADl3SG.js.map +0 -1
- package/dist/assets/main-Bc4Ow56Z.js.map +0 -1
- package/dist/assets/mainline-DWh4Ccri.js.map +0 -1
- package/dist/assets/profiles-DgIfvBeN.js.map +0 -1
- package/dist/assets/registry-BSyxGjN6.js.map +0 -1
- package/dist/assets/resolve-D-9YRFhl.js.map +0 -1
- package/dist/assets/restoredRows-CRYwIx3g.js.map +0 -1
- package/dist/assets/secretGuard-Q2BKq0q0.js +0 -2
- package/dist/assets/server-BufntkX8.js.map +0 -1
- package/dist/assets/src-CCt5s4DK.js.map +0 -1
- package/dist/assets/usdt-ds461mzA.js.map +0 -1
- package/dist/assets/waitNotice-B8D8WhbE.js +0 -45
- package/dist/assets/waitNotice-B8D8WhbE.js.map +0 -1
- package/dist/assets/words-B1ylON2h.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apiKit-DzXHZojD.js","names":[],"sources":["../../src/apiKit.ts"],"sourcesContent":["import { INVITE_TAKEN, isZ32Key, type PairedTransport } from \"@ghostly/core\";\nimport type { GhostlyNode } from \"@ghostly/browser/engine/node\";\nimport type { EngineState, GroupView, LinkView, StoredMessage } from \"@ghostly/browser/shared/types\";\nimport { CliError } from \"./errors\";\nimport type { CallManager } from \"./calls/manager\";\nimport type { EventHub } from \"./events\";\nimport type { Runtime } from \"./runtime/engine\";\n\n/**\n * The methods of the local control API (WISP 1100): the daemon answers them over its socket, and a one-shot\n * command calls them in its own process. Parameters come from JSON: every one is checked here.\n */\nexport interface ApiContext {\n runtime: Runtime;\n hub: EventHub;\n /** Voice calls (WISP 1100 § Calls). */\n calls: CallManager;\n /** How the host runs: a daemon stays; a one-shot leaves when its command is done. */\n mode: \"daemon\" | \"one-shot\";\n version: string;\n /** The daemon asks to stop (answered first). */\n stop?: () => void;\n /** The daemon is a `listen` that found none and runs the profile itself: a stop ends that listen too. */\n listen?: true;\n}\n\nexport type Params = Record<string, unknown>;\nexport type Method = (ctx: ApiContext, params: Params) => Promise<unknown>;\n\nexport const node = (ctx: ApiContext): GhostlyNode => ctx.runtime.server.node;\nexport const state = (ctx: ApiContext): EngineState => node(ctx).getState();\n\n/**\n * The time of a send the engine names its row after (`me_<timestamp>`: a file, a payment, a request), its own even\n * within one millisecond (a bot paying or sending several times at once over the socket, `file send` run in\n * parallel), or the chat keeps only one. One clock for all of them: they share the row names. A file's resend after a\n * drop finds its row by it, as a forward does.\n */\nlet lastSentAt = 0;\nexport const sentAt = () => (lastSentAt = Math.max(Date.now(), lastSentAt + 1));\n\n// ---------- parameters ----------\n\nexport function str(params: Params, name: string, required: true): string;\nexport function str(params: Params, name: string, required?: false): string | undefined;\nexport function str(params: Params, name: string, required = false): string | undefined {\n const value = params[name];\n if (value === undefined || value === null || value === \"\") {\n if (required) throw new CliError(\"bad_request\", `${name} is required`);\n return undefined;\n }\n if (typeof value !== \"string\") throw new CliError(\"bad_request\", `${name} must be a string`);\n return value;\n}\n/** A number in `[min, max]`; `whole` takes only whole ones (a count of messages), as the engine needs them. */\nexport function num(params: Params, name: string, fallback: number, { min = 0, max = Number.MAX_SAFE_INTEGER, whole = false } = {}): number {\n const value = params[name];\n if (value === undefined || value === null) return fallback;\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < min || value > max) throw new CliError(\"bad_request\", `${name} must be a ${whole ? \"whole \" : \"\"}number from ${min} to ${max}`);\n if (whole && !Number.isSafeInteger(value)) throw new CliError(\"bad_request\", `${name} must be a whole number from ${min} to ${max}`);\n return value;\n}\nexport function bool(params: Params, name: string): boolean {\n const value = params[name];\n if (value === undefined || value === null) return false;\n if (typeof value !== \"boolean\") throw new CliError(\"bad_request\", `${name} must be true or false`);\n return value;\n}\nexport function list(params: Params, name: string): string[] {\n const value = params[name];\n if (value === undefined || value === null) return [];\n if (!Array.isArray(value) || value.some((item) => typeof item !== \"string\")) throw new CliError(\"bad_request\", `${name} must be a list of strings`);\n return value as string[];\n}\n/**\n * One of `values`; `fallback` when it was left out. Given empty (an unset variable in a script: `wallet remove \"\"`), it\n * is refused like any other wrong choice, never read as left out: that acted on the default (the Cashu wallet).\n */\nexport function oneOf<T extends string>(params: Params, name: string, values: readonly T[], fallback: T): T {\n const value = params[name] === \"\" ? \"\" : str(params, name) ?? fallback;\n if (!values.includes(value as T)) throw new CliError(\"bad_request\", `${name} must be one of ${values.join(\", \")}`);\n return value as T;\n}\n\n// ---------- finding things ----------\n\nconst KEY_SHAPED = /^[ybndrfg8ejkmcpqxot1uwisza345h769]{52}$/;\n/**\n * A contact key as chats show it (`peer`): 52 characters of z-base-32, in its one canonical spelling. The same 52\n * characters with the last one respelled decode to the same bytes but are no key (WISP 02): refused here, so that\n * they never fall through to a chat's name, which its contact chooses.\n */\nexport const CONTACT_KEY = {\n test(ref: string): boolean {\n if (isZ32Key(ref)) return true;\n if (KEY_SHAPED.test(ref)) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} is not a contact key: a key has one spelling, and its last character is not this one`);\n return false;\n },\n};\n\n/**\n * A chat by its id; by its contact's key (only by the key: a name is never taken for one); by the label this side gave\n * it; and only when no label matches, by a unique prefix of its id or the name the contact gave itself. The contact\n * controls both of those (a joiner's chat id is made from the inviter's code), so neither wins over a label, and a ref\n * that fits one chat's prefix and another's name is refused.\n */\nexport function findChat(links: readonly LinkView[], ref: string): LinkView {\n return chatBy(links, ref).link;\n}\n\n/** `findChat`, and whether only what the contact controls (`theirName`: a prefix of the id, its own name) found the chat. */\nfunction chatBy(links: readonly LinkView[], ref: string): { link: LinkView; theirName: boolean } {\n // \"\" (an unset variable in a script) is a prefix of every id: it took the only chat.\n if (!ref.trim()) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names no chat`);\n const exact = links.find((link) => link.id === ref);\n if (exact) return { link: exact, theirName: false };\n if (CONTACT_KEY.test(ref)) {\n const byKey = links.filter((link) => link.peerPubKeyZ32 === ref);\n if (byKey.length === 1) return { link: byKey[0], theirName: false };\n if (byKey.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names more than one chat: use its id`, { matches: byKey.map((link) => link.id) });\n throw new CliError(\"not_found\", `No chat with ${JSON.stringify(ref)} (ghostly chat list)`);\n }\n const lower = ref.toLowerCase();\n const named = (name: string | null | undefined) => name?.trim().toLowerCase() === lower;\n const byLabel = links.filter((link) => named(link.label));\n const found = byLabel.length ? byLabel : [...new Set([...links.filter((link) => link.id.startsWith(ref)), ...links.filter((link) => named(link.peerNick))])];\n if (found.length === 1) return { link: found[0], theirName: !byLabel.length };\n if (found.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names more than one chat: use its id`, { matches: found.map((link) => link.id) });\n throw new CliError(\"not_found\", `No chat ${JSON.stringify(ref)} (ghostly chat list)`);\n}\n\n/**\n * `findChat` for a grant the daemon keeps acting on (`call auto on --from`): only the chat's id, its contact's key or the\n * label this side gave it name the chat. A prefix of its id or the name its contact gave itself is refused, with the\n * chat it found: the contact chose those, so another contact could take the grant by calling itself that name.\n */\nexport function findOwnNamedChat(links: readonly LinkView[], ref: string): LinkView {\n const chat = chatBy(links, ref);\n if (chat.theirName) throw namedByThem(ref, { chat: chat.link.id, name: chat.link.peerNick ?? null, contact: chat.link.peerPubKeyZ32 });\n return chat.link;\n}\n\n/** `findOwnNamedChat`'s refusal: `ref` found `chat` only by what its contact chose. */\nexport function namedByThem(ref: string, chat: { chat: string; name: string | null; contact: string | undefined }): CliError {\n return new CliError(\"bad_request\", `${JSON.stringify(ref)} names a chat only by what its contact chose (a prefix of its id, its own name): use the chat's id, its contact's key or a label given here (ghostly chat rename <chat> <name>)`, chat);\n}\n\n/** Only an invitation so far: this profile is not in the group (yet), and whoever invited chose its name. */\nconst invitedOnly = (group: GroupView) => group.status === undefined && !!group.invitation;\n\n/**\n * A group by its id, by its name, or by a unique prefix of its id. Whoever created a group chose its id and its admin\n * chooses its name, so neither wins over the other: a ref that is one group's name and another's prefix is refused,\n * with both ids, as `chatBy` does for chats. A group this profile is in wins over an invitation with the same name or\n * prefix (the one who invites chooses those); an invitation is still found by its id, and by name or prefix where no\n * group of this profile has it.\n */\nexport function findGroup(groups: readonly GroupView[], ref: string): GroupView {\n if (!ref.trim()) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names no group`);\n const exact = groups.find((group) => group.id === ref);\n if (exact) return exact;\n const lower = ref.toLowerCase();\n for (const among of [groups.filter((group) => !invitedOnly(group)), groups.filter(invitedOnly)]) {\n const found = among.filter((group) => group.name.trim().toLowerCase() === lower || group.id.startsWith(ref));\n if (found.length === 1) return found[0];\n if (found.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names more than one group: use its id`, { matches: found.map((group) => group.id) });\n }\n throw new CliError(\"not_found\", `No group ${JSON.stringify(ref)} (ghostly group list)`);\n}\n\n/**\n * A chat or a group, where a command takes either: `group:<id>` is a group; anything else a chat first (`findChat`),\n * then a group. A chat found only by what its contact chose (a prefix of its id, its own name) never takes what also\n * names a group: a group's\n * own id is that group, and a prefix or the name of a group this profile is in is refused, with both ids. With neither,\n * one `not_found` names both and where to look (a contact's key: no chat with it); a name that matches more than one\n * chat or group stays that error.\n */\nexport function findChatOrGroup(links: readonly LinkView[], groups: readonly GroupView[], ref: string): { link: LinkView } | { group: GroupView } {\n if (ref.startsWith(\"group:\")) return { group: findGroup(groups, ref.slice(\"group:\".length)) };\n let chat: ReturnType<typeof chatBy>;\n try {\n chat = chatBy(links, ref);\n } catch (error) {\n if (!(error instanceof CliError) || error.code !== \"not_found\") throw error;\n try { return { group: findGroup(groups, ref) }; } catch (inner) {\n if (!(inner instanceof CliError) || inner.code !== \"not_found\") throw inner;\n if (CONTACT_KEY.test(ref)) throw error;\n throw new CliError(\"not_found\", `No chat or group ${JSON.stringify(ref)} (ghostly chat list, ghostly group list)`);\n }\n }\n if (!chat.theirName) return { link: chat.link };\n const exact = groups.find((group) => group.id === ref);\n if (exact) return { group: exact };\n const lower = ref.toLowerCase();\n const also = groups.filter((group) => !invitedOnly(group) && (group.id.startsWith(ref) || group.name.trim().toLowerCase() === lower));\n if (also.length) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names a chat (by what its contact chose) and a group: use the chat's id or group:<id>`, { chat: chat.link.id, groups: also.map((group) => group.id) });\n return { link: chat.link };\n}\n\n/**\n * Starts the chats a call names (its `chat`, a forward's `to`) in a runtime that left the saved chats unstarted\n * (`RuntimeOptions.deferChats`). A ref that names no chat, or names a group, starts nothing: the call says so itself.\n */\nexport function startNamedChats(ctx: ApiContext, params: Params): void {\n const { links, groups } = state(ctx);\n for (const ref of [params.chat, ...(Array.isArray(params.to) ? params.to : [])]) {\n if (typeof ref !== \"string\") continue;\n let found: ReturnType<typeof findChatOrGroup>;\n try { found = findChatOrGroup(links, groups, ref); } catch { continue; }\n if (\"link\" in found) node(ctx).startDeferredChat(found.link.id);\n }\n}\n\nexport const chatOf = (ctx: ApiContext, params: Params) => findChat(state(ctx).links, str(params, \"chat\", true));\n\n/**\n * A chat whose invite nobody took yet: nobody is there to pay or to dial, and its stage says so. Before, `chat pay`\n * waited 15 s and `chat connect` 25 s for the contact, then answered `engine`. A chat whose invite someone else used\n * first is refused too, with the sentence `send` gives: its contact seals everything to them (`connect` waited 120 s,\n * then answered `timeout`, a code a bot retries).\n */\nexport function inviteTaken(link: LinkView): void {\n if (link.profile && link.inviteCode && !link.peerParticipationKey) throw new CliError(\"unavailable\", \"Nobody joined this chat yet: its invite is still waiting to be taken\");\n if (link.dhtDelivery?.inviteTaken && link.textDelivery !== \"stream\") throw new CliError(\"refused\", INVITE_TAKEN);\n}\n\n/**\n * A chat on DHT only opens no live session: the engine refused `chat connect` as `engine`, \"Both peers must choose a\n * live method first\", which read as if this side had to change something. Refused instead, naming whose choice it is\n * (`details.reason`): the contact's (`peer-dht-only`, nothing to do here but wait), or this side's (`dht-only`).\n */\nexport function dhtOnly(link: LinkView): void {\n if (link.deliveryMode === \"dht\") throw new CliError(\"refused\", \"This chat is on DHT only on this side: choose a live method first (chat transport auto)\", { reason: \"dht-only\" });\n if (link.dhtDelivery?.peerMode === \"dht\") throw new CliError(\"refused\", \"Your contact keeps this chat on DHT only: it goes live once they choose a live method. Short texts still go on the DHT\", { reason: \"peer-dht-only\" });\n}\n\nconst TRANSPORT_TITLES: Record<PairedTransport, string> = { \"webrtc/1\": \"WebRTC\", \"iroh/1\": \"Iroh\", \"hyperdht/1\": \"HyperDHT\" };\n\n/**\n * A transport the chat's Connection menu offers: one this app runs (on DHT only, one it can start), and the contact's\n * app too, by its last word. `chat transport` took any: toward a contact with no WebRTC (`GHOSTLY_WEBRTC=0`) the choice\n * was kept and the chat stayed where it was, saying nothing; for one this app lacks, the engine answered `engine`,\n * \"Transport unavailable\". Refused instead, saying whose app lacks it (`details.reason`, as a chat's wait says it).\n */\nexport function transportOffered(link: LinkView, transport: PairedTransport): void {\n const mine = (link.deliveryMode === \"dht\" ? link.runnableTransports : undefined) ?? link.availableTransports;\n const title = TRANSPORT_TITLES[transport], error = link.transportErrors?.[transport];\n if (mine && !mine.includes(transport)) throw new CliError(\"refused\", `This app has no ${title} running${error ? `: ${error}` : \"\"}`, { reason: \"app-lacks\", transport });\n if (link.peerTransports?.length && !link.peerTransports.includes(transport)) throw new CliError(\"refused\", `Your contact's app doesn't have ${title}: choose another, or auto`, { reason: \"contact-lacks\", transport });\n}\n\n/** A chat or a group as `findChatOrGroup` reads it. `linkId` is what the engine calls it. */\nexport function chatOrGroup(ctx: ApiContext, ref: string): { id: string; linkId: string; group: boolean } {\n const found = findChatOrGroup(state(ctx).links, state(ctx).groups, ref);\n return \"group\" in found ? { id: found.group.id, linkId: `group:${found.group.id}`, group: true } : { id: found.link.id, linkId: found.link.id, group: false };\n}\n\n/**\n * The group a group command names. A chat's id, key or name says it is a chat, with `twin`, the chat command that takes\n * it (`group send` on a chat, where `send` is meant; `<chat>` stands for the ref), else where the groups are listed.\n * It read \"No group\" before. A name nothing has stays that error.\n */\nexport function groupOf(ctx: ApiContext, params: Params, twin?: string): GroupView {\n const ref = str(params, \"group\", true);\n try { return findGroup(state(ctx).groups, ref); } catch (error) {\n if (!(error instanceof CliError) || error.code !== \"not_found\") throw error;\n let chat: LinkView;\n try { chat = findChat(state(ctx).links, ref); } catch { throw error; }\n const shown = /^[\\w.:-]+$/.test(ref) ? ref : JSON.stringify(ref);\n throw new CliError(\"not_found\", `${JSON.stringify(ref)} is a chat, not a group${twin ? `: ghostly ${twin.replace(\"<chat>\", shown)}` : \" (ghostly group list)\"}`, { chat: chat.id });\n }\n}\n\n/**\n * A message of a chat or a group (`group:<id>`) named by its id here, read as one row; only a name that is no such\n * row's key (the id both sides know, `wireId`) reads the whole history. `keep`: only a message it accepts (mine, or\n * someone else's). The history is synchronous work on the daemon's one thread, about 120 ms at 10,000 messages.\n */\nexport async function messageOf(ctx: ApiContext, linkId: string, ref: string, keep: (message: StoredMessage) => boolean = () => true): Promise<StoredMessage | undefined> {\n const found = await node(ctx).getMessage(linkId, ref);\n if (found && keep(found)) return found;\n const all = linkId.startsWith(\"group:\") ? await node(ctx).groupMessages({ groupId: linkId.slice(\"group:\".length) }) : await node(ctx).getMessages(linkId);\n return all.find((m) => keep(m) && m.wireId === ref);\n}\n\n// ---------- waiting ----------\n\n/**\n * Resolves with `check`'s first defined answer: now, or on a later state; `timeout` error after `ms`. A check that\n * throws on a later state (`chat wait`'s chat removed) ends the wait with its error: the hub swallows what its\n * listeners throw, and the wait went on to its timeout.\n */\nexport function waitForState<T>(ctx: ApiContext, check: (state: EngineState) => T | undefined, ms: number, what: string): Promise<T> {\n const now = check(state(ctx));\n if (now !== undefined) return Promise.resolve(now);\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => { off(); reject(new CliError(\"timeout\", `Timed out after ${Math.round(ms / 1000)} s waiting for ${what}`)); }, ms);\n const off = ctx.hub.onState((next) => {\n let value: T | undefined;\n try { value = check(next); } catch (error) { clearTimeout(timer); off(); reject(error); return; }\n if (value === undefined) return;\n clearTimeout(timer);\n off();\n resolve(value);\n });\n });\n}\n\n"],"mappings":";;;AA6BA,IAAa,QAAQ,QAAiC,IAAI,QAAQ,OAAO;AACzE,IAAa,SAAS,QAAiC,KAAK,GAAG,CAAC,CAAC,SAAS;;;;;;;AAQ1E,IAAI,aAAa;AACjB,IAAa,eAAgB,aAAa,KAAK,IAAI,KAAK,IAAI,GAAG,aAAa,CAAC;AAM7E,SAAgB,IAAI,QAAgB,MAAc,WAAW,OAA2B;CACtF,MAAM,QAAQ,OAAO;CACrB,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IAAI;EACzD,IAAI,UAAU,MAAM,IAAI,SAAS,eAAe,GAAG,KAAK,aAAa;EACrE;CACF;CACA,IAAI,OAAO,UAAU,UAAU,MAAM,IAAI,SAAS,eAAe,GAAG,KAAK,kBAAkB;CAC3F,OAAO;AACT;;AAEA,SAAgB,IAAI,QAAgB,MAAc,UAAkB,EAAE,MAAM,GAAG,MAAM,OAAO,kBAAkB,QAAQ,UAAU,CAAC,GAAW;CAC1I,MAAM,QAAQ,OAAO;CACrB,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO;CAClD,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,SAAS,KAAK,KAAK,QAAQ,OAAO,QAAQ,KAAK,MAAM,IAAI,SAAS,eAAe,GAAG,KAAK,aAAa,QAAQ,WAAW,GAAG,cAAc,IA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,GAAG,CAAC,CAAC,YAAY,MAAM,EAAA,CAC7I,MAAM,MAAM,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG;AACpD;;;;;;AASA,SAAgB,aAAgB,KAAiB,OAA8C,IAAY,MAA0B;CACnI,MAAM,MAAM,MAAM,MAAM,GAAG,CAAC;CAC5B,IAAI,QAAQ,KAAA,GAAW,OAAO,QAAQ,QAAQ,GAAG;CACjD,OAAO,IAAI,SAAY,SAAS,WAAW;EACzC,MAAM,QAAQ,iBAAiB;GAAE,IAAI;GAAG,OAAO,IAAI,SAAS,WAAW,mBAAmB,KAAK,MAAM,KAAK,GAAI,EAAE,iBAAiB,MAAM,CAAC;EAAG,GAAG,EAAE;EAChJ,MAAM,MAAM,IAAI,IAAI,SAAS,SAAS;GACpC,IAAI;GACJ,IAAI;IAAE,QAAQ,MAAM,IAAI;GAAG,SAAS,OAAO;IAAE,aAAa,KAAK;IAAG,IAAI;IAAG,OAAO,KAAK;IAAG;GAAQ;GAChG,IAAI,UAAU,KAAA,GAAW;GACzB,aAAa,KAAK;GAClB,IAAI;GACJ,QAAQ,KAAK;EACf,CAAC;CACH,CAAC;AACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors-R4S2SAEM.js","names":[],"sources":["../../src/errors.ts"],"sourcesContent":["/**\n * Errors that reach a bot: a stable `code` to branch on, a message for people, and the exit status the CLI\n * leaves with (WISP 1100 § Exit codes). The daemon sends `{code, message}` over the socket; the CLI prints\n * `{\"error\": {code, message}}` on stdout and exits with `exit`.\n */\nexport type ErrorCode =\n | \"bad_request\" | \"usage\" | \"not_found\" | \"refused\" | \"unavailable\" | \"confirm\" | \"timeout\"\n | \"engine\" | \"busy\" | \"internal\" | \"interrupted\";\n\n/** `interrupted`: Ctrl-C (SIGINT) ended the command, 128 + 2 as a shell says of a command its signal ended. */\nexport const EXIT: Record<ErrorCode, number> = {\n engine: 1, refused: 1, unavailable: 1, bad_request: 1, busy: 1, internal: 1,\n usage: 2, not_found: 3, timeout: 4, confirm: 5, interrupted: 130,\n};\n\nexport class CliError extends Error {\n constructor(readonly code: ErrorCode, message: string, readonly details?: Record<string, unknown>) {\n super(message);\n this.name = \"CliError\";\n }\n toJSON(): { code: ErrorCode; message: string; details?: Record<string, unknown> } {\n return { code: this.code, message: this.message, ...(this.details ? { details: this.details } : {}) };\n }\n}\n\n/** Anything thrown, as the error a bot sees: the engine's own refusals keep their words. */\nexport function asCliError(error: unknown): CliError {\n if (error instanceof CliError) return error;\n if (error && typeof error === \"object\" && \"code\" in error && \"message\" in error && typeof (error as { code: unknown }).code === \"string\"\n && Object.hasOwn(EXIT, (error as { code: string }).code)) return new CliError((error as { code: ErrorCode }).code, String((error as { message: unknown }).message));\n // A contact the chat's link could not reach (its `GhostlyHttpError` \"unreachable\"): not there now, not the engine failing.\n if (error instanceof Error && (error as { code?: unknown }).code === \"unreachable\") return new CliError(\"unavailable\", error.message);\n const known = engineKnown(error);\n if (known) return known;\n const full = noRoomError(error);\n if (full) return full;\n const local = localFileError(error);\n if (local) return local;\n const unopened = profileOpenError(error);\n if (unopened) return unopened;\n const message = error instanceof Error ? error.message : String(error);\n if (/real money|confirmedReal|Mainnet/i.test(message) && /confirm/i.test(message)) return new CliError(\"confirm\", message);\n if (/other network|cross-network|network does not match/i.test(message)) return new CliError(\"refused\", message);\n // A member asking for a group's admin-only change, one removed from the group (or gone) asking for any, an invitation\n // already answered: not allowed, not the engine failing.\n if (/^Only the admin |^You are no longer in this group$|^No invitation to (accept|decline)$/.test(message)) return new CliError(\"refused\", message);\n // `group invite` into a community: it has no invitations, its link is how people join.\n if (message === \"Share the group's link with them: anyone who opens it joins\") return new CliError(\"bad_request\", message);\n return new CliError(\"engine\", message);\n}\n\n/**\n * The engine's known errors (`EngineError`, packages/core engineErrors.ts) a bot branches on, by their `engineCode`: a\n * host or the network not answering is `unavailable` (try again later), one too slow `timeout`, a value the person gave\n * `bad_request`, money that is not there `refused`, a contact that offers no way of paying `refused` with its reason in\n * `details.reason`. Any other keeps `engine`. Read by its shape, as `profileOpenError`.\n */\nconst ENGINE_CODES: Record<string, ErrorCode> = {\n mintUnreachable: \"unavailable\", lnurlUnreachable: \"unavailable\", hostUnreachable: \"unavailable\", networkUnreachable: \"unavailable\", usdtRpcUnavailable: \"unavailable\",\n hostTimedOut: \"timeout\", networkTimedOut: \"timeout\",\n invalidMintUrl: \"bad_request\", mintNotHttps: \"bad_request\", invalidMaxFee: \"bad_request\",\n notEnoughSats: \"refused\", notEnoughForFee: \"refused\", mintsNoAnyAmount: \"refused\", ecashAlreadySpent: \"refused\", ecashFeeTakesAll: \"refused\", lightningRefused: \"refused\", contactNoWallet: \"refused\", contactNoPayments: \"refused\",\n};\n/** `details.reason` of an engine error a bot tells apart from others of its code. */\nconst ENGINE_REASONS: Record<string, string> = { contactNoWallet: \"contact_no_wallet\", contactNoPayments: \"contact_payments_off\" };\n\nfunction engineKnown(error: unknown): CliError | undefined {\n if (!(error instanceof Error)) return undefined;\n const { engineCode, values } = error as { engineCode?: unknown; values?: { host?: unknown } };\n if (typeof engineCode !== \"string\" || !Object.hasOwn(ENGINE_CODES, engineCode)) return undefined;\n // The app's reason for a Lightning address it could not read (a browser's CORS) is no reason in a terminal.\n if (engineCode === \"lnurlUnreachable\" && typeof values?.host === \"string\") return new CliError(\"unavailable\", `Could not reach ${values.host}`);\n const details = Object.hasOwn(ENGINE_REASONS, engineCode) ? { reason: ENGINE_REASONS[engineCode] } : undefined;\n // The contact's next step, for a contact that is a bot too.\n if (engineCode === \"contactNoWallet\") return new CliError(\"refused\", `${error.message} (on a CLI: ghostly wallet create cashu)`, details);\n return new CliError(ENGINE_CODES[engineCode], error.message, details);\n}\n\n/**\n * A change the profile's store could not put on disk (`storage.ts` refuses its transaction with a QuotaExceededError;\n * the engine's `committed` wraps it in its own words, the store's as the cause): `unavailable`, try again once there is\n * room, in the store's words, which name the profile's folder. Before, a daemon on a full disk answered done.\n */\nfunction noRoomError(error: unknown): CliError | undefined {\n let said: string | undefined, found = false;\n for (let at = error, depth = 0; at && typeof at === \"object\" && depth < 4; at = (at as { cause?: unknown }).cause, depth++) {\n if ((at as { name?: unknown }).name !== \"QuotaExceededError\") continue;\n found = true;\n const message = (at as { message?: unknown }).message;\n if (typeof message === \"string\" && message.startsWith(\"No room left\")) said = message;\n }\n return found ? new CliError(\"unavailable\", said ?? \"No room left on the disk: free some space, then try again\") : undefined;\n}\n\n/**\n * The profile's database did not open (the engine's `ProfileOpenError`, packages/browser/src/shared/idb.ts): `engine`\n * (exit 1) with the engine's own words, which name the versions when a newer ghostly stored it, and the reason and\n * the versions in `details` for a bot. Read by its shape: this module is also the thin client's, which loads no engine.\n */\nfunction profileOpenError(error: unknown): CliError | undefined {\n if (!(error instanceof Error) || error.name !== \"ProfileOpenError\") return undefined;\n const failure = (error as { failure?: { reason?: unknown; storedVersion?: unknown; supportedVersion?: unknown } }).failure;\n if (!failure || typeof failure.reason !== \"string\") return undefined;\n return new CliError(\"engine\", error.message, {\n reason: failure.reason === \"newer\" ? \"newer_profile\" : `profile_${failure.reason}`,\n ...(typeof failure.storedVersion === \"number\" ? { storedVersion: failure.storedVersion } : {}),\n ...(typeof failure.supportedVersion === \"number\" ? { supportedVersion: failure.supportedVersion } : {}),\n });\n}\n\n/**\n * A file or folder on this machine the command could not open (`file save --dir`, `profile backup --out`): the\n * person's path, not the engine refusing, so it says so with the code a bot branches on. Before, a folder that did\n * not exist was `engine` (exit 1) with Node's `ENOENT: no such file or directory, open '…'`. `file`: the path read, for\n * an error that names none (a folder read as a file).\n */\nexport function localFileError(error: unknown, file?: string): CliError | undefined {\n if (!error || typeof error !== \"object\" || typeof (error as { syscall?: unknown }).syscall !== \"string\") return undefined;\n const { code, path } = error as { code?: unknown; path?: unknown };\n const where = typeof path === \"string\" ? path : file ?? \"the path\";\n if (code === \"ENOENT\" || code === \"ENOTDIR\") return new CliError(\"not_found\", `No such file or folder: ${where}`);\n if (code === \"EACCES\" || code === \"EPERM\" || code === \"EROFS\") return new CliError(\"refused\", `Not allowed to write or read ${where}`);\n if (code === \"EISDIR\") return new CliError(\"bad_request\", `${where} is a folder: name a file`);\n if (code === \"ENAMETOOLONG\") return new CliError(\"bad_request\", `A name in ${where} is too long for this file system (at most 255 bytes)`);\n // A full disk (or a quota) answered Node's raw \"ENOSPC: no space left on device, write\" as `engine`, naming nothing\n // (agents#1710). `unavailable`: it works again once there is room, with nothing lost.\n if (code === \"ENOSPC\" || code === \"EDQUOT\") {\n const at = typeof path === \"string\" ? path : file;\n return new CliError(\"unavailable\", at ? `No room left for ${at}: free some space, then try again` : \"No room left on the disk: free some space, then try again\", { reason: \"no_space\", errno: code, ...(at && { path: at }) });\n }\n return undefined;\n}\n"],"mappings":";;AAUA,IAAa,OAAkC;CAC7C,QAAQ;CAAG,SAAS;CAAG,aAAa;CAAG,aAAa;CAAG,MAAM;CAAG,UAAU;CAC1E,OAAO;CAAG,WAAW;CAAG,SAAS;CAAG,SAAS;CAAG,aAAa;AAC/D;AAEA,IAAa,WAAb,cAA8B,MAAM;CACb;CAA2C;CAAhE,YAAY,MAA0B,SAAiB,SAA4C;EACjG,MAAM,OAAO;EADM,KAAA,OAAA;EAA2C,KAAA,UAAA;EAE9D,KAAK,OAAO;CACd;CACA,SAAkF;EAChF,OAAO;GAAE,MAAM,KAAK;GAAM,SAAS,KAAK;GAAS,GAAI,KAAK,UAAU,EAAE,SAAS,KAAK,QAAQ,IAAI,CAAC;EAAG;CACtG;AACF;;AAGA,SAAgB,WAAW,OAA0B;CACnD,IAAI,iBAAiB,UAAU,OAAO;CACtC,IAAI,SAAS,OAAO,UAAU,YAAY,UAAU,SAAS,aAAa,SAAS,OAAQ,MAA4B,SAAS,YAC3H,OAAO,OAAO,MAAO,MAA2B,IAAI,GAAG,OAAO,IAAI,SAAU,MAA8B,MAAM,OAAQ,MAA+B,OAAO,CAAC;CAEpK,IAAI,iBAAiB,SAAU,MAA6B,SAAS,eAAe,OAAO,IAAI,SAAS,eAAe,MAAM,OA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AS;CACvB,MAAM,QAAQ,OAAO,SAAS,WAAW,OAAO,QAAQ;CACxD,IAAI,SAAS,YAAY,SAAS,WAAW,OAAO,IAAI,SAAS,aAAa,2BAA2B,OAAO;CAChH,IAAI,SAAS,YAAY,SAAS,WAAW,SAAS,SAAS,OAAO,IAAI,SAAS,WAAW,gCAAgC,OAAO;CACrI,IAAI,SAAS,UAAU,OAAO,IAAI,SAAS,eAAe,GAAG,MAAM,0BAA0B;CAC7F,IAAI,SAAS,gBAAgB,OAAO,IAAI,SAAS,eAAe,aAAa,MAAM,sDAAsD;CAGzI,IAAI,SAAS,YAAY,SAAS,UAAU;EAC1C,MAAM,KAAK,OAAO,SAAS,WAAW,OAAO;EAC7C,OAAO,IAAI,SAAS,eAAe,KAAK,oBAAoB,GAAG,qCAAqC,6DAA6D;GAAE,QAAQ;GAAY,OAAO;GAAM,GAAI,MAAM,EAAE,MAAM,GAAG;EAAG,CAAC;CAC/N;AAEF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fixedHosts-C2hdCfzK.js","names":[],"sources":["../../../browser/src/proofs/fixedHosts.ts"],"sourcesContent":["import { DEFAULT_RELAYS } from \"@ghostly/core\";\nimport { plcDirectory } from \"./atproto/resolve\";\nimport { DOH_RESOLVERS } from \"./domain\";\nimport { oidcProviders } from \"./oidc/providers\";\nimport { PUBKY_RELAYS } from \"./pubkyRelays\";\nimport { SSH_FORGE_HOST } from \"./sshForges\";\n\n/**\n * The hosts a contact's proof may be checked on while \"Hide my IP from contacts\" is on: the ones this app names\n * (DNS-over-HTTPS resolvers, the PLC directory, Pkarr relays, the OpenID providers' keys, the forges' APIs), never one\n * the contact's evidence names (a did:web or a domain's own web server, an AT Protocol server, a Pubky homeserver),\n * which would see this device's IP address.\n */\nexport function fixedIdentityHosts(): ReadonlySet<string> {\n const urls = [...DOH_RESOLVERS.map(r => r.url), plcDirectory(), ...PUBKY_RELAYS, ...DEFAULT_RELAYS, ...oidcProviders().map(p => p.jwksUri)];\n return new Set([...urls.map(u => new URL(u).host), ...Object.values(SSH_FORGE_HOST)]);\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,qBAA0C;CACxD,MAAM,OAAO;EAAC,GAAG,cAAc,KAAI,MAAK,EAAE,GAAG;EAAG,aAAa;EAAG,GAAG;EAAc,GAAG;EAAgB,GAAG,cAAc,CAAC,CAAC,KAAI,MAAK,EAAE,OAAO;CAAC;CAC1I,uBAAO,IAAI,IAAI,CAAC,GAAG,KAAK,KAAI,MAAK,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,OAAO,OAAO,cAAc,CAAC,CAAC;AACtF"}
|