@essentialai/cogent
Advanced tools
| /** | ||
| * Map an agent label to an emoji for the Slack bot icon. | ||
| * Backend/server agents get gear, frontend get palette, etc. | ||
| */ | ||
| export declare function getAgentEmoji(label: string): string; | ||
| /** | ||
| * Human-readable platform name for the Slack sender-attribution tag, e.g. | ||
| * "(via Codex)". Unknown/absent platform falls back to "CC" -- pre-3.3 peers | ||
| * had no platform field and were all Claude Code. | ||
| */ | ||
| export declare function platformLabel(platform?: string): string; | ||
| //# sourceMappingURL=attribution.d.ts.map |
| {"version":3,"file":"attribution.d.ts","sourceRoot":"","sources":["../../src/slack-format/attribution.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAcvD"} |
| /** | ||
| * Map an agent label to an emoji for the Slack bot icon. | ||
| * Backend/server agents get gear, frontend get palette, etc. | ||
| */ | ||
| export function getAgentEmoji(label) { | ||
| const lower = label.toLowerCase(); | ||
| if (lower.includes("backend") || lower.includes("server")) | ||
| return ":gear:"; | ||
| if (lower.includes("frontend") || lower.includes("ui") || lower.includes("ux")) | ||
| return ":art:"; | ||
| if (lower.includes("qa") || lower.includes("test") || lower.includes("quality")) | ||
| return ":mag:"; | ||
| if (lower.includes("devops") || lower.includes("infra") || lower.includes("deploy")) | ||
| return ":rocket:"; | ||
| return ":robot_face:"; | ||
| } | ||
| /** | ||
| * Human-readable platform name for the Slack sender-attribution tag, e.g. | ||
| * "(via Codex)". Unknown/absent platform falls back to "CC" -- pre-3.3 peers | ||
| * had no platform field and were all Claude Code. | ||
| */ | ||
| export function platformLabel(platform) { | ||
| switch (platform) { | ||
| case "codex": | ||
| return "Codex"; | ||
| case "slack": | ||
| return "Slack"; | ||
| case "gchat": | ||
| return "Google Chat"; | ||
| case "web": | ||
| return "Web"; | ||
| case "cc": | ||
| default: | ||
| return "CC"; | ||
| } | ||
| } | ||
| //# sourceMappingURL=attribution.js.map |
| {"version":3,"file":"attribution.js","sourceRoot":"","sources":["../../src/slack-format/attribution.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAClC,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC3E,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,OAAO,CAAC;IAC/F,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,OAAO,CAAC;IAChG,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,UAAU,CAAC;IACvG,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,QAAiB;IAC7C,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO;YACV,OAAO,aAAa,CAAC;QACvB,KAAK,KAAK;YACR,OAAO,KAAK,CAAC;QACf,KAAK,IAAI,CAAC;QACV;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"} |
| export { slackToMarkdown } from "./slack-to-md.js"; | ||
| export { markdownToSlack } from "./md-to-slack.js"; | ||
| export { extractUserIds, resolveInboundMentions, resolveOutboundMentions } from "./mentions.js"; | ||
| export { getAgentEmoji, platformLabel } from "./attribution.js"; | ||
| export { derivePeerId, buildPeerLabel } from "./peer-helpers.js"; | ||
| export type { UserLookup, CachedUser } from "./types.js"; | ||
| export type { PlatformUserInfo } from "./peer-helpers.js"; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/slack-format/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACjE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"} |
| export { slackToMarkdown } from "./slack-to-md.js"; | ||
| export { markdownToSlack } from "./md-to-slack.js"; | ||
| export { extractUserIds, resolveInboundMentions, resolveOutboundMentions } from "./mentions.js"; | ||
| export { getAgentEmoji, platformLabel } from "./attribution.js"; | ||
| export { derivePeerId, buildPeerLabel } from "./peer-helpers.js"; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/slack-format/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"} |
| import type { UserLookup } from "./types.js"; | ||
| /** | ||
| * Convert standard Markdown to Slack mrkdwn format. | ||
| * Uses slackify-markdown (AST-based, remark/unified) for reliable conversion. | ||
| * | ||
| * Key transformations: | ||
| * - **bold** -> *bold* (asterisk count swap) | ||
| * - *italic* -> _italic_ (asterisk to underscore) | ||
| * - [text](url) -> <url|text> | ||
| * - # Header -> *Header* (bold, since mrkdwn has no headers) | ||
| * - ~~strike~~ -> ~strike~ | ||
| * - Code blocks and inline code preserved | ||
| * | ||
| * When `users` is provided, @Name mentions are resolved to <@userId>. | ||
| * When omitted, mentions are left as-is (backward compatible). | ||
| * | ||
| * The library adds a trailing newline; we trim it for clean output. | ||
| */ | ||
| export declare function markdownToSlack(text: string, users?: UserLookup): string; | ||
| //# sourceMappingURL=md-to-slack.d.ts.map |
| {"version":3,"file":"md-to-slack.d.ts","sourceRoot":"","sources":["../../src/slack-format/md-to-slack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,MAAM,CASxE"} |
| import { slackifyMarkdown } from "slackify-markdown"; | ||
| import { resolveOutboundMentions } from "./mentions.js"; | ||
| /** | ||
| * Convert standard Markdown to Slack mrkdwn format. | ||
| * Uses slackify-markdown (AST-based, remark/unified) for reliable conversion. | ||
| * | ||
| * Key transformations: | ||
| * - **bold** -> *bold* (asterisk count swap) | ||
| * - *italic* -> _italic_ (asterisk to underscore) | ||
| * - [text](url) -> <url|text> | ||
| * - # Header -> *Header* (bold, since mrkdwn has no headers) | ||
| * - ~~strike~~ -> ~strike~ | ||
| * - Code blocks and inline code preserved | ||
| * | ||
| * When `users` is provided, @Name mentions are resolved to <@userId>. | ||
| * When omitted, mentions are left as-is (backward compatible). | ||
| * | ||
| * The library adds a trailing newline; we trim it for clean output. | ||
| */ | ||
| export function markdownToSlack(text, users) { | ||
| let result = slackifyMarkdown(text).replace(/\n$/, ""); | ||
| // Resolve outbound @Name mentions to <@userId> if lookup available | ||
| if (users) { | ||
| result = resolveOutboundMentions(result, users); | ||
| } | ||
| return result; | ||
| } | ||
| //# sourceMappingURL=md-to-slack.js.map |
| {"version":3,"file":"md-to-slack.js","sourceRoot":"","sources":["../../src/slack-format/md-to-slack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,KAAkB;IAC9D,IAAI,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEvD,mEAAmE;IACnE,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,GAAG,uBAAuB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"} |
| import type { UserLookup } from "./types.js"; | ||
| /** | ||
| * Extract unique Slack user IDs from a message body. | ||
| * Used to pre-warm a user cache before sync resolution. | ||
| */ | ||
| export declare function extractUserIds(text: string): string[]; | ||
| /** | ||
| * Resolve inbound Slack <@userId> mentions to readable @DisplayName. | ||
| * Synchronous -- only resolves users already in the lookup. | ||
| * Unknown user IDs are left as <@UXXXX>. | ||
| */ | ||
| export declare function resolveInboundMentions(text: string, users: UserLookup): string; | ||
| /** | ||
| * Resolve outbound @Name mentions to Slack <@userId> format. | ||
| * Synchronous -- only resolves names already in the lookup. | ||
| * Protects code blocks (``` and `) from resolution. | ||
| * Does NOT touch @here, @channel, @everyone (those are Slack special mentions). | ||
| * Unknown names are left as @Name. | ||
| */ | ||
| export declare function resolveOutboundMentions(text: string, users: UserLookup): string; | ||
| //# sourceMappingURL=mentions.d.ts.map |
| {"version":3,"file":"mentions.d.ts","sourceRoot":"","sources":["../../src/slack-format/mentions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAK7C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMrD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAU9E;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CA+D/E"} |
| /** Slack user-ID regex used by both extraction and resolution. */ | ||
| const USER_ID_RE = /<@(U[A-Z0-9]+)>/g; | ||
| /** | ||
| * Extract unique Slack user IDs from a message body. | ||
| * Used to pre-warm a user cache before sync resolution. | ||
| */ | ||
| export function extractUserIds(text) { | ||
| const ids = new Set(); | ||
| for (const match of text.matchAll(USER_ID_RE)) { | ||
| ids.add(match[1]); | ||
| } | ||
| return [...ids]; | ||
| } | ||
| /** | ||
| * Resolve inbound Slack <@userId> mentions to readable @DisplayName. | ||
| * Synchronous -- only resolves users already in the lookup. | ||
| * Unknown user IDs are left as <@UXXXX>. | ||
| */ | ||
| export function resolveInboundMentions(text, users) { | ||
| const allUsers = users.getAllCached(); | ||
| return text.replace(USER_ID_RE, (_match, userId) => { | ||
| const user = allUsers.get(userId); | ||
| if (user) { | ||
| return `@${user.displayName}`; | ||
| } | ||
| return `<@${userId}>`; | ||
| }); | ||
| } | ||
| /** | ||
| * Resolve outbound @Name mentions to Slack <@userId> format. | ||
| * Synchronous -- only resolves names already in the lookup. | ||
| * Protects code blocks (``` and `) from resolution. | ||
| * Does NOT touch @here, @channel, @everyone (those are Slack special mentions). | ||
| * Unknown names are left as @Name. | ||
| */ | ||
| export function resolveOutboundMentions(text, users) { | ||
| // Placeholders use \x00 (null) delimiters to avoid matching mention regex | ||
| const BLOCK_PREFIX = "\x00MB"; | ||
| const SPAN_PREFIX = "\x00MS"; | ||
| const SUFFIX = "\x00"; | ||
| // 1. Extract code blocks to protect from resolution | ||
| const codeBlocks = []; | ||
| let result = text.replace(/```[\s\S]*?```/g, (match) => { | ||
| codeBlocks.push(match); | ||
| return `${BLOCK_PREFIX}${codeBlocks.length - 1}${SUFFIX}`; | ||
| }); | ||
| // 2. Extract inline code spans to protect from resolution | ||
| const codeSpans = []; | ||
| result = result.replace(/`[^`]+`/g, (match) => { | ||
| codeSpans.push(match); | ||
| return `${SPAN_PREFIX}${codeSpans.length - 1}${SUFFIX}`; | ||
| }); | ||
| // 3. Resolve @mentions to <@userId> | ||
| // Build a map of all known names -> userId (longest names first to avoid partial matches) | ||
| const allUsers = users.getAllCached(); | ||
| const nameToUserId = new Map(); | ||
| for (const [userId, user] of allUsers) { | ||
| if (user.displayName) | ||
| nameToUserId.set(user.displayName.toLowerCase(), userId); | ||
| if (user.realName) | ||
| nameToUserId.set(user.realName.toLowerCase(), userId); | ||
| // First name from realName | ||
| const firstName = user.realName.split(" ")[0]; | ||
| if (firstName && !nameToUserId.has(firstName.toLowerCase())) { | ||
| nameToUserId.set(firstName.toLowerCase(), userId); | ||
| } | ||
| } | ||
| // Sort known names by length descending so "Jane D." matches before "Jane" | ||
| const sortedNames = [...nameToUserId.keys()].sort((a, b) => b.length - a.length); | ||
| // For each known name, replace @Name with <@userId> | ||
| for (const lowerName of sortedNames) { | ||
| const userId = nameToUserId.get(lowerName); | ||
| // Build regex that matches @Name at word boundary (case-insensitive) | ||
| // Escape regex special chars in the name | ||
| const escaped = lowerName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
| const re = new RegExp(`@(${escaped})(?=[\\s,.:;!?)"'\\]]|$)`, "gi"); | ||
| result = result.replace(re, (_match, _name) => { | ||
| return `<@${userId}>`; | ||
| }); | ||
| } | ||
| // Leave unresolved @mentions as-is (they don't match any known name) | ||
| // @here, @channel, @everyone are never in the cache, so they pass through untouched | ||
| // 4. Restore inline code spans (reverse order to preserve indices) | ||
| for (let i = codeSpans.length - 1; i >= 0; i--) { | ||
| result = result.replace(`${SPAN_PREFIX}${i}${SUFFIX}`, codeSpans[i]); | ||
| } | ||
| // 5. Restore code blocks (reverse order to preserve indices) | ||
| for (let i = codeBlocks.length - 1; i >= 0; i--) { | ||
| result = result.replace(`${BLOCK_PREFIX}${i}${SUFFIX}`, codeBlocks[i]); | ||
| } | ||
| return result; | ||
| } | ||
| //# sourceMappingURL=mentions.js.map |
| {"version":3,"file":"mentions.js","sourceRoot":"","sources":["../../src/slack-format/mentions.ts"],"names":[],"mappings":"AAEA,kEAAkE;AAClE,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY,EAAE,KAAiB;IACpE,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC;IAEtC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAc,EAAE,EAAE;QACzD,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,IAAI,IAAI,CAA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AE,CAAC,EAAE,EAAE,CAAC;QAC/C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,WAAW,GAAG,CAAC,GAAG,MAAM,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,6DAA6D;IAC7D,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAChD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,GAAG,CAAC,GAAG,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"} |
| /** | ||
| * Minimal user shape needed to build a peer label. The Slack adapter's | ||
| * richer `SlackUserInfo` (displayName + title + more) satisfies this | ||
| * structurally. | ||
| */ | ||
| export interface PlatformUserInfo { | ||
| displayName: string; | ||
| title?: string; | ||
| } | ||
| /** | ||
| * Derive a COGENT peerId from a Slack display name. | ||
| * "Pavlo S." -> "pavlo-s" | ||
| * "John Doe" -> "john-doe" | ||
| */ | ||
| export declare function derivePeerId(displayName: string): string; | ||
| /** | ||
| * Build a peer label from user info. | ||
| * Includes profile title when available: "Pavlo S. (PM)" | ||
| * Falls back to just display name: "Pavlo S." | ||
| */ | ||
| export declare function buildPeerLabel(user: PlatformUserInfo): string; | ||
| //# sourceMappingURL=peer-helpers.d.ts.map |
| {"version":3,"file":"peer-helpers.d.ts","sourceRoot":"","sources":["../../src/slack-format/peer-helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAK7D"} |
| /** | ||
| * Derive a COGENT peerId from a Slack display name. | ||
| * "Pavlo S." -> "pavlo-s" | ||
| * "John Doe" -> "john-doe" | ||
| */ | ||
| export function derivePeerId(displayName) { | ||
| return displayName | ||
| .toLowerCase() | ||
| .replace(/[^a-z0-9]+/g, "-") | ||
| .replace(/^-|-$/g, ""); | ||
| } | ||
| /** | ||
| * Build a peer label from user info. | ||
| * Includes profile title when available: "Pavlo S. (PM)" | ||
| * Falls back to just display name: "Pavlo S." | ||
| */ | ||
| export function buildPeerLabel(user) { | ||
| if (user.title) { | ||
| return `${user.displayName} (${user.title})`; | ||
| } | ||
| return user.displayName; | ||
| } | ||
| //# sourceMappingURL=peer-helpers.js.map |
| {"version":3,"file":"peer-helpers.js","sourceRoot":"","sources":["../../src/slack-format/peer-helpers.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,WAAmB;IAC9C,OAAO,WAAW;SACf,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAsB;IACnD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,KAAK,GAAG,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC,WAAW,CAAC;AAC1B,CAAC"} |
| import type { UserLookup } from "./types.js"; | ||
| /** | ||
| * Convert Slack mrkdwn to standard Markdown. | ||
| * Custom lightweight regex-based converter for inbound messages. | ||
| * | ||
| * Key difference: *text* is BOLD in mrkdwn but ITALIC in markdown. | ||
| * This converter handles the swap correctly: | ||
| * Slack *bold* -> Markdown **bold** | ||
| * Slack _italic_ -> Markdown *italic* | ||
| * | ||
| * Code blocks and inline code are extracted before transformation | ||
| * and restored after, preventing false matches inside code. | ||
| * | ||
| * When `users` is provided, <@U123ABC> mentions are resolved to @DisplayName. | ||
| * When omitted, user mentions are preserved as-is (backward compatible). | ||
| */ | ||
| export declare function slackToMarkdown(text: string, users?: UserLookup): string; | ||
| //# sourceMappingURL=slack-to-md.d.ts.map |
| {"version":3,"file":"slack-to-md.d.ts","sourceRoot":"","sources":["../../src/slack-format/slack-to-md.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,MAAM,CA6DxE"} |
| import { resolveInboundMentions } from "./mentions.js"; | ||
| /** | ||
| * Convert Slack mrkdwn to standard Markdown. | ||
| * Custom lightweight regex-based converter for inbound messages. | ||
| * | ||
| * Key difference: *text* is BOLD in mrkdwn but ITALIC in markdown. | ||
| * This converter handles the swap correctly: | ||
| * Slack *bold* -> Markdown **bold** | ||
| * Slack _italic_ -> Markdown *italic* | ||
| * | ||
| * Code blocks and inline code are extracted before transformation | ||
| * and restored after, preventing false matches inside code. | ||
| * | ||
| * When `users` is provided, <@U123ABC> mentions are resolved to @DisplayName. | ||
| * When omitted, user mentions are preserved as-is (backward compatible). | ||
| */ | ||
| export function slackToMarkdown(text, users) { | ||
| // Placeholders use \x00 (null) delimiters to avoid matching formatting regex | ||
| // (no underscores, asterisks, or tildes in placeholders) | ||
| const BLOCK_PREFIX = "\x00CB"; | ||
| const SPAN_PREFIX = "\x00CS"; | ||
| const SUFFIX = "\x00"; | ||
| // 1. Extract code blocks to protect from transformation | ||
| const codeBlocks = []; | ||
| let result = text.replace(/```[\s\S]*?```/g, (match) => { | ||
| codeBlocks.push(match); | ||
| return `${BLOCK_PREFIX}${codeBlocks.length - 1}${SUFFIX}`; | ||
| }); | ||
| // 2. Extract inline code spans to protect from transformation | ||
| const codeSpans = []; | ||
| result = result.replace(/`[^`]+`/g, (match) => { | ||
| codeSpans.push(match); | ||
| return `${SPAN_PREFIX}${codeSpans.length - 1}${SUFFIX}`; | ||
| }); | ||
| // 3. Convert Slack bold *text* to Markdown **text** | ||
| // Negative lookbehind for backslash prevents escaped asterisks | ||
| result = result.replace(/(?<![\\])\*([^*\n]+)\*/g, "**$1**"); | ||
| // 4. Convert Slack italic _text_ to Markdown *text* | ||
| result = result.replace(/(?<![\\])_([^_\n]+)_/g, "*$1*"); | ||
| // 5. Convert Slack strikethrough ~text~ to Markdown ~~text~~ | ||
| result = result.replace(/(?<![\\])~([^~\n]+)~/g, "~~$1~~"); | ||
| // 6. Convert Slack links <url|text> to Markdown [text](url) | ||
| result = result.replace(/<(https?:\/\/[^|>]+)\|([^>]+)>/g, "[$2]($1)"); | ||
| // 7. Convert bare Slack links <url> to Markdown [url](url) | ||
| result = result.replace(/<(https?:\/\/[^>]+)>/g, "[$1]($1)"); | ||
| // 8. Convert channel references <#C123|name> to #name | ||
| result = result.replace(/<#C[A-Z0-9]+\|([^>]+)>/g, "#$1"); | ||
| // 9. Convert special mentions | ||
| result = result.replace(/<!here>/g, "@here"); | ||
| result = result.replace(/<!channel>/g, "@channel"); | ||
| result = result.replace(/<!everyone>/g, "@everyone"); | ||
| // 10. Resolve user mentions <@U04ABC> to @DisplayName (if lookup provided) | ||
| if (users) { | ||
| result = resolveInboundMentions(result, users); | ||
| } | ||
| // 11. Restore inline code spans (reverse order to preserve indices) | ||
| for (let i = codeSpans.length - 1; i >= 0; i--) { | ||
| result = result.replace(`${SPAN_PREFIX}${i}${SUFFIX}`, codeSpans[i]); | ||
| } | ||
| // 12. Restore code blocks (reverse order to preserve indices) | ||
| for (let i = codeBlocks.length - 1; i >= 0; i--) { | ||
| result = result.replace(`${BLOCK_PREFIX}${i}${SUFFIX}`, codeBlocks[i]); | ||
| } | ||
| return result; | ||
| } | ||
| //# sourceMappingURL=slack-to-md.js.map |
| {"version":3,"file":"sl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ouples core translation from the Slack | ||
| * adapter's Bolt-bound `UserCache` (which makes live API calls). | ||
| * | ||
| * `ReadonlyMap` is covariant in its value type, so a concrete | ||
| * `Map<string, SlackUserInfo>` (the adapter's cache shape, which has extra | ||
| * fields) satisfies `UserLookup` structurally with no adapter changes. | ||
| */ | ||
| export interface CachedUser { | ||
| displayName: string; | ||
| realName: string; | ||
| } | ||
| export interface UserLookup { | ||
| getAllCached(): ReadonlyMap<string, CachedUser>; | ||
| } | ||
| //# sourceMappingURL=types.d.ts.map |
| {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/slack-format/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,IAAI,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACjD"} |
| export {}; | ||
| //# sourceMappingURL=types.js.map |
| {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/slack-format/types.ts"],"names":[],"mappings":""} |
+14
-0
| # Changelog | ||
| ## [3.2.0] - 2026-06-01 | ||
| ### Added | ||
| - New `./slack-format` subpath export — shared Slack <-> markdown translation engine, | ||
| reused by the Slack adapter (and the upcoming Business Edition's distributed app): | ||
| - `slackToMarkdown`, `markdownToSlack` | ||
| - `extractUserIds`, `resolveInboundMentions`, `resolveOutboundMentions` | ||
| - `derivePeerId`, `buildPeerLabel`, `platformLabel`, `getAgentEmoji` | ||
| - `UserLookup` / `CachedUser` / `PlatformUserInfo` types (decouples the pure mention | ||
| resolvers from any Bolt-bound user cache) | ||
| ### Changed | ||
| - Added `slackify-markdown` as a runtime dependency (used by `markdownToSlack`). | ||
| ## [3.0.0] - 2026-03-19 | ||
@@ -4,0 +18,0 @@ |
+8
-1
| { | ||
| "name": "@essentialai/cogent", | ||
| "version": "3.1.0", | ||
| "version": "3.2.0", | ||
| "description": "Shared types, schemas, and contracts for Cogent Bridge", | ||
@@ -14,2 +14,6 @@ "type": "module", | ||
| "default": "./dist/file/index.js" | ||
| }, | ||
| "./slack-format": { | ||
| "types": "./dist/slack-format/index.d.ts", | ||
| "default": "./dist/slack-format/index.js" | ||
| } | ||
@@ -31,2 +35,5 @@ }, | ||
| }, | ||
| "dependencies": { | ||
| "slackify-markdown": "^5.0.0" | ||
| }, | ||
| "peerDependencies": { | ||
@@ -33,0 +40,0 @@ "zod": "^3.25.0 || ^4.0.0" |
125052
26.54%116
31.82%1474
32.2%2
100%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added