@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.
53 lines • 3.55 kB
TypeScript
import type { HttpClient } from "./http-client.js";
import type { Attachment } from "../types.js";
/**
* COG-94 — Slack file attachments, the bridge side.
*
* Operator decisions (2026-11-03): files up to 1 GB; Slack is the store of record; a copy the agent
* fetches is kept 7 days ON THE AGENT'S MACHINE, then deleted; our servers stream and keep nothing.
* The agent never holds a Slack token: the file endpoint on our side (FREE adapter / Business
* control plane) checks this agent's relay Bearer against the channel, then streams from Slack.
*
* Wire contract (both editions):
* GET /api/slack/files/:sessionId/:fileId → bytes; X-Cogent-File-Name (URI-encoded), Content-Type
* POST /api/slack/files/:sessionId ← bytes; X-Cogent-File-Name, Content-Length,
* X-Cogent-From-Peer → 201 {fileId,name,size,mimeType,url}
*/
/** Slack's per-file maximum, "1 GB". Decimal on purpose: never larger than Slack's own limit. */
export declare const MAX_FILE_BYTES = 1000000000;
/** How long a fetched copy stays on this machine. */
export declare const FILE_RETENTION_MS: number;
export declare function isSlackFileRef(url: string | undefined): boolean;
/** Keep a received file name usable and inside its directory: no separators, no control chars. */
export declare function safeFileName(name: string | null | undefined): string;
export declare function filesRoot(stateDir: string): string;
/** Delete fetched copies older than the retention window; returns how many files were removed. */
export declare function cleanupOldFiles(root: string, now?: number, retentionMs?: number): Promise<number>;
/** How often a running bridge re-sweeps: the 7-day promise must hold for a bridge that runs for weeks. */
export declare const FILE_SWEEP_INTERVAL_MS: number;
/**
* Enforce the 7-day retention WITHOUT waiting for another fetch: sweep once now, then every
* `intervalMs` while the process lives. The timer is unref'd (it never keeps a bridge alive) and a
* failed sweep is ignored (the next one retries). Returns a stop function.
*/
export declare function startFileSweeper(root: string, intervalMs?: number): () => void;
export interface FetchedFile {
path: string;
name: string;
size: number;
mimeType?: string;
}
/** Download one file reference into `<root>/<sessionId>/<fileId>-<name>`. */
export declare function downloadSlackFile(http: HttpClient, sessionId: string, url: string, root: string, maxBytes?: number): Promise<FetchedFile>;
/**
* Refuse files an agent must never post into Slack, judged on the REAL path (symlinks resolved):
* anything under a hidden directory or itself hidden (`.ssh/`, `.aws/`, `.env`, `.git/`…), and
* anything inside Cogent's own state directory (its credentials) except THIS channel's fetched
* copies (`files/<sessionId>/` — another channel's copies would leak across channels).
* The tool is reachable from text other people write (a Slack message can ask an agent to "attach
* X"), so this is the line between attaching work and posting secrets into a channel.
*/
export declare function assertAttachable(filePath: string, stateDir: string, sessionId: string): Promise<string>;
/** Upload one local file to the Slack channel mapped to this channel; returns its attachment reference. */
export declare function uploadSlackFile(http: HttpClient, sessionId: string, filePath: string, fromPeerId: string, stateDir: string, maxBytes?: number): Promise<Attachment>;
//# sourceMappingURL=slack-files.d.ts.map