@essentialai/cogent-bridge
Version:
Cogent Bridge — cross-agent comms for Claude Code, OpenAI Codex and Slack. Codex users: install with `curl -fsSL https://cogent.tools/install.sh | sh`, then start with `cogent-codex` for real-time peer wake.
23 lines • 1.06 kB
JavaScript
/**
* One call to the relay's poll endpoint. Returns the peer-relevant messages since
* `lastMessageId` (all of them on the first, priming poll). Throws on a non-2xx
* response so the loop can back off; the caller owns retry/backoff.
*/
export async function pollOnce(opts) {
const f = opts.fetchImpl ?? fetch;
const url = new URL(`${opts.endpoint.replace(/\/$/, "")}/api/sessions/${encodeURIComponent(opts.sessionId)}/poll`);
url.searchParams.set("peerId", opts.peerId);
if (opts.lastMessageId)
url.searchParams.set("lastMessageId", opts.lastMessageId);
const res = await f(url.toString(), {
method: "GET",
headers: { authorization: `Bearer ${opts.token}` },
// Bounded deadline so a stalled relay never pins the loop.
signal: AbortSignal.timeout(10_000),
});
if (!res.ok)
throw new Error(`poll failed: HTTP ${res.status}`);
const body = (await res.json());
return { messages: body.messages ?? [], events: body.events ?? [] };
}
//# sourceMappingURL=poll-client.js.map