UNPKG

@phren/cli

Version:

Knowledge layer for AI agents - CLI, MCP server, and data layer

30 lines (29 loc) • 1.81 kB
import { peerRequest, type HookPeer } from "./peers.js"; import type { Json } from "./protocol.js"; /** * Peer reads that poll or fan out: the phone's `/v1/sets`, `/v1/computers`, `/v1/owner-inbox`, health details * and the `?peers=1` reports. Each used to be one SSH login per peer per request. The phone reads them from * every linked computer at once, so six computers made dozens of logins on each other within seconds, and one * computer that was off held every one of those reads for its full timeout. * * - A peer known to be off answers with its last error at once (peer-reach.ts). * - Reads of the same route on the same peer share one login while it runs. * - With `ttl`, an answer is reused for that long; with `failTtl`, so is an error (for a read the caller can do without). * * A write through this Hook to a peer (`peerRequest` with a body) is not tracked here, so keep `ttl` at 0 * for anything the owner changes and reads straight back. */ export declare const PEER_READ_TTL_MS = 5000; export interface PeerReadOptions { /** As for `peerRequest`: 15 s when absent. */ timeout?: number; /** How long an answer may be reused. 0 (the default) shares only a login that is still running. */ ttl?: number; /** How long a failure is answered again without a login. 0 (the default) keeps none. */ failTtl?: number; } export declare function peerRead(peer: HookPeer, route: string, options?: PeerReadOptions): Promise<Json>; /** `peerRead` in the shape of `peerRequest`, for callers that take either. A body is a write and always dials. */ export declare function peerReader(ttl?: number): typeof peerRequest; /** An explicit refresh (`?refresh=1`): kept answers and the memory of which peers are off are dropped. */ export declare function refreshPeerReads(): void;