Files
vercel__chat/packages/adapter-shared
github-actions[bot] a8dc522c4c Version Packages (#310)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-04-06 20:21:57 -07:00
..
2026-04-06 20:21:57 -07:00
2026-04-06 20:21:57 -07:00
2026-02-27 09:58:28 -08:00

@chat-adapter/shared

npm version npm downloads

Shared utilities for Chat SDK adapters. Provides common helpers used across adapter implementations.

Installation

pnpm add @chat-adapter/shared

Utilities

Adapter helpers

  • extractCard(message) - extract a CardElement from an AdapterPostableMessage
  • extractFiles(message) - extract FileUpload[] from an AdapterPostableMessage

Buffer conversion

  • toBuffer(input) - convert various inputs (Buffer, Blob, string, URL) to Buffer
  • toBufferSync(input) - synchronous version of toBuffer
  • bufferToDataUri(buffer, mimeType) - convert a Buffer to a data URI string

Card conversion

  • cardToFallbackText(card) - render a CardElement as plain text for platforms that don't support cards
  • createEmojiConverter(platform) - create a function that converts emoji placeholders to platform format
  • mapButtonStyle(style) - map generic button styles to platform-specific variants
  • renderGfmTable(headers, rows) - render a GitHub Flavored Markdown table
  • escapeTableCell(text) - escape pipe characters in table cells

Error classes

Standardized errors for adapter implementations:

  • AdapterError - base error class
  • AdapterRateLimitError - platform rate limit (includes retryAfter)
  • AuthenticationError - expired or invalid tokens
  • NetworkError - connection failures
  • PermissionError - missing scopes or permissions
  • ResourceNotFoundError - missing channel/thread/message
  • ValidationError - invalid config or input

License

MIT