UNPKG

@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.

37 lines • 2.03 kB
import { z } from "zod"; import { BridgeError, BridgeErrorCode, successResult, errorResult } from "../errors.js"; import { getBackend, HttpBackend } from "../backend/index.js"; import { getConfig } from "../config.js"; import { cleanupOldFiles, downloadSlackFile, filesRoot } from "../cloud/slack-files.js"; /** * cogent_fetch_file — COG-94. Download a file someone posted in the mapped Slack channel. * The copy is saved under ~/.cogent/files/<channel>/ and deleted after 7 days (operator * decision 2026-11-03); old copies are swept on every call. */ export function registerFetchFileTool(server) { server.registerTool("cogent_fetch_file", { title: "Fetch a Slack file", description: "Download a file shared in this channel's Slack channel (up to 1 GB). Pass the url from a " + "message's 📎 Attachments block. Returns the local path; the copy is deleted after 7 days.", inputSchema: { url: z.string().describe("The file url from the 📎 Attachments block, e.g. /api/slack/files/<channel>/<fileId>"), }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }, }, async ({ url }) => { try { const backend = getBackend(); if (!(backend instanceof HttpBackend)) { return errorResult(new BridgeError(BridgeErrorCode.JOIN_NOT_CONFIRMED, "Not connected to a cloud channel", "Join the channel first (cogent_join_session).")); } const root = filesRoot(getConfig().COGENT_STATE_PATH); const removed = await cleanupOldFiles(root); const { sessionId, http } = backend.fileTransport(); const file = await downloadSlackFile(http, sessionId, url, root); return successResult({ ...file, deletedAfterDays: 7, ...(removed ? { expiredCopiesRemoved: removed } : {}) }); } catch (err) { return errorResult(err); } }); } //# sourceMappingURL=fetch-file.js.map