/** * @license * Copyright 2026 Qwen Team * SPDX-License-Identifier: Apache-2.0 */ /** * Turning what someone typed into a session to write to. * * Sessions are addressed by name, because a name reads back to a person * and survives a restart where a socket path does not. Names are not * unique, so each session also has a short `ref`, and an address that could * mean two sessions is an error rather than a guess: a message delivered to * the wrong session cannot be taken back. */ import { type PeerSocketVerdict } from './client.js'; import type { SessionRecord } from './registry.js'; /** A live session that advertises an inbox. */ export interface PeerDirectoryEntry { sessionId: string; name: string; ref: string; cwd: string; pid: number; /** What the session says registered it; absent reads as `tui`. */ kind: string; ipcPath: string; ipcToken?: string; startedAt: number; } /** The addressable view of a record, or null when it has no inbox. */ export declare function toDirectoryEntry(record: SessionRecord): PeerDirectoryEntry | null; /** * The entries whose inbox answers a dial. * * Each distinct address is dialed once: a process hosting several sessions * advertises one inbox in all their records, and asking once per record * would open that many connections to one socket on every lookup. * * Then, unless `collapseTwins` is false, one entry per (session id, name) is * kept, the newest: resuming a session in a second terminal runs the same id * under another process, and two identical entries would make every address * for it ambiguous. The collapse also means a copied record shadows the * original, so a caller about to present a credential turns it off and * treats the pair as the ambiguity it is. */ export declare function reachableEntries(records: readonly SessionRecord[], probe?: (socketPath: string) => Promise, options?: { collapseTwins?: boolean; }): Promise; export type PeerResolution = { kind: 'one'; peer: PeerDirectoryEntry; } | { kind: 'none'; } | { kind: 'ambiguous'; matches: PeerDirectoryEntry[]; }; /** * Match `name`, `name [ref]`, `[ref]` or a bare ref. * * Every string is read every way it can be — `name [ref]` is also a * candidate literal name, a bare word is also a candidate ref — and the * matches are merged rather than ranked. Ranking would quietly pick one * session when two have a claim. */ export declare function resolvePeerTarget(peers: readonly PeerDirectoryEntry[], target: string): PeerResolution; /** * The shortest address that resolves back to exactly this peer, or * undefined when adversarial names leave none. No address is better than * one that routes somewhere else. */ export declare function advertisablePeerAddress(peer: PeerDirectoryEntry, peers: readonly PeerDirectoryEntry[]): string | undefined; /** * Up to `limit` names containing what was typed, prefix matches first. No * edit distance: a confident suggestion of the wrong session is worse than * none. */ export declare function suggestPeerNames(peers: readonly PeerDirectoryEntry[], target: string, limit?: number): string[];