package
Shared utilities for Chat SDK platform adapters
npm install @chat-adapter/sharedGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
npm package:
@chat-adapter/shared
Shared utilities for Chat SDK adapters. Provides common helpers used across adapter implementations.
Documentation: chat-sdk.dev/docs/contributing/building · Guides: vercel.com/kb/chat-sdk
pnpm add @chat-adapter/sharedextractCard(message) - extract a CardElement from an AdapterPostableMessageextractFiles(message) - extract FileUpload[] from an AdapterPostableMessageextractPostableAttachments(message) - extract Attachment[] from an AdapterPostableMessagetoBuffer(input) - convert various inputs (Buffer, Blob, string, URL) to BuffertoBufferSync(input) - synchronous version of toBufferbufferToDataUri(buffer, mimeType) - convert a Buffer to a data URI stringcardToFallbackText(card) - render a CardElement as plain text for platforms that don't support cardscreateEmojiConverter(platform) - create a function that converts emoji placeholders to platform formatmapButtonStyle(style) - map generic button styles to platform-specific variantsrenderGfmTable(headers, rows) - render a GitHub Flavored Markdown tableescapeTableCell(text) - escape pipe characters in table cellsfindCardActions(children) - find the first actions element, searching nested sectionstruncateWithEllipsis(text, maxLength) - cut text to a length limit and end it with …encodeCallbackData(actionId, value?) - encode a button or quick-reply payload as chat:{json}decodeCallbackData(data, fallbackActionId) - decode it, passing legacy and third-party payloads through unchangedisChatCallbackData(data) - check for the chat: prefixThese are also exported from @chat-adapter/shared/callback-data, which has no dependencies, for runtime-light entry points such as webhook parsers.
For platforms whose API cannot list past messages, such as Messenger and Instagram:
upsertMessage(messages, message, compare?) - insert or replace a message by ID in a list that is already sorted, keeping it sortedpaginateMessages(messages, options) - page a sorted list with message-ID cursorscompareMessagesByTime(a, b, sequence?) and messageSequence(id) - the default sort order: send time, then the trailing :{n} in the message IDUsed by @chat-adapter/messenger, @chat-adapter/instagram, and @chat-adapter/whatsapp:
verifyMetaWebhookChallenge(params, verifyToken) - check the query parameters of a webhook subscription request and return the challenge, or nullverifyMetaSignature(body, signature, appSecret) - verify the X-Hub-Signature-256 header in constant timethrowMetaGraphApiError(options) - map a failed Graph API response onto the shared error classesparseRetryAfter(header) - read a Retry-After header, given as seconds or as an HTTP date, and return the seconds to wait or undefinedAES-256-GCM helpers for encrypting OAuth tokens at rest before writing them to a state adapter. Used by @chat-adapter/slack and @chat-adapter/linear; available to any adapter that persists credentials.
encryptToken(plaintext, key) - encrypt a string and return an EncryptedTokenData envelope (random 12-byte IV per call)decryptToken(data, key) - decrypt an envelope back to the original stringdecodeKey(encoded) - decode a hex-64 or base64-44 encoded 32-byte key; throws on wrong lengthisEncryptedTokenData(value) - type guard for distinguishing envelopes from legacy plaintext recordsEncryptedTokenData - the envelope type ({ data, iv, tag }, all base64)Standardized errors for adapter implementations:
AdapterError - base error classAdapterRateLimitError - platform rate limit (includes retryAfter)AuthenticationError - expired or invalid tokensNetworkError - connection failuresPermissionError - missing scopes or permissionsResourceNotFoundError - missing channel/thread/messageValidationError - invalid config or inputIf you use an AI coding agent such as OpenAI Codex, Claude Code, or Cursor, install the Chat SDK skill so it knows the SDK APIs, adapter patterns, and project conventions before writing code.
npx skills add vercel/chatThe skill references bundled documentation in node_modules/chat/docs, plus adapter guides and starter templates in the published package.
You can also install the Vercel Plugin for a broader agent toolkit — it includes the Chat SDK skill alongside specialist agents, agent slash commands, and more:
npx plugins add vercel/vercel-pluginThe plugin is optional; the skill alone is enough to build with Chat SDK.
For agent-readable documentation, see chat-sdk.dev/llms.txt (page index) or chat-sdk.dev/llms-full.txt (full text).
MIT
vercel-release-bot
infra+release@vercel.com
Estimated unpacked size across 23 packages.
2.3 MB
Includes dependencies.