// Transport facade. The rest of the app (inbox-service, Messages) imports // send/poll/stream/decrypt from here and never learns which pipe carries // the bytes. Both transports expose an identical surface and both ship the // same sealed envelope from crypto.ts — only the delivery mechanism differs. // // VITE_TRANSPORT=server (default) → kez-chat server inbox over HTTP/SSE // VITE_TRANSPORT=nostr → Nostr relays // // Set it in .env / .env.local. Switching transports is build-time; there's // no reason to flip it at runtime and keeping it static lets Vite tree-shake // the unused transport out of the bundle. import * as server from "./messages.js"; import * as nostr from "./nostr-transport.js"; const TRANSPORT = (import.meta.env.VITE_TRANSPORT ?? "server") as "server" | "nostr"; const impl = TRANSPORT === "nostr" ? nostr : server; export const sendMessage = impl.sendMessage; export const pollInbox = impl.pollInbox; export const streamInbox = impl.streamInbox; export const decrypt = impl.decrypt; /** Publish a delivery receipt for a message we just decrypted, so the * original sender's UI can flip the bubble from "sent" to "delivered". * No-op on the server transport for now. */ export const sendAck = impl.sendAck; /** Retry any acks that failed to publish on first attempt. Called on * session start so a flaky relay moment doesn't permanently strand * receipts. */ export const flushPendingAcks = impl.flushPendingAcks; /** Catch-up query: given a list of recently-sent event ids, returns * the subset for which a recipient ack has been published. Lets the * sender's UI self-heal "delivered" state on conversation open * instead of relying solely on the live stream. */ export const fetchAcksForEventIds = impl.fetchAcksForEventIds; /** Wire the user's seed into the relay pool so NIP-42 AUTH challenges * get signed transparently. No-op on the server transport. */ export const attachSigner = impl.attachSigner; export const detachSigner = impl.detachSigner; /** Snapshot of every configured relay (or the single chat-server) + * whether the socket is currently open. Drives the "● live (N)" * indicator and its popover. */ export const getRelayStatuses = impl.getRelayStatuses; export type { InboxMessage, StreamHandle, SealedEnvelope, MessagePlaintext } from "./messages.js"; export type { RelayStatus } from "./messages.js"; /** Which transport this build is using — handy for a debug line in the UI. */ export const activeTransport = TRANSPORT;