AI Components

6 Components

Production-ready React components for building AI-powered chat interfaces, model selectors, and conversational experiences.

Works with useChat

These components integrate seamlessly with the useChat hook. Pass the hook's return values directly as props for full functionality.

ChatInterface

A complete chat interface component that handles message display, user input, streaming responses, and conversation history. The fastest way to add AI chat to your app.

Basic Usage

import { ChatInterface } from '@sylphx/platform-sdk/react'

export default function ChatPage() {
  return (
    <ChatInterface
      model="anthropic/claude-3.5-sonnet"
      systemMessage="You are a helpful assistant."
      placeholder="Ask me anything..."
    />
  )
}

Props

PropertyTypeDescription
modelrequiredstringAI model identifier (e.g., "anthropic/claude-3.5-sonnet")
systemMessagestringSystem prompt to set AI behavior
placeholderstring= "Type a message..."Input placeholder text
initialMessagesMessage[]Pre-populate conversation history
onMessage(msg: Message) => voidCallback when a new message is received
onError(error: Error) => voidCallback when an error occurs
showModelSelectorboolean= falseShow model dropdown in header
showTokenCountboolean= falseDisplay token usage
maxHeightstring= "600px"Maximum height of chat container
classNamestringAdditional CSS classes
themeThemeVariablesCustom theme overrides

Advanced Examples

import { ChatInterface, useChat } from '@sylphx/platform-sdk/react'

export default function CustomChat() {
  const chat = useChat({
    model: 'anthropic/claude-3.5-sonnet',
    systemMessage: 'You are a coding assistant.',
    onMessage: (msg) => console.log('New message:', msg),
  })

  return (
    <ChatInterface
      {...chat}
      showModelSelector
      showTokenCount
      maxHeight="80vh"
    />
  )
}

ChatBubble

Renders an individual chat message with support for markdown, syntax-highlighted code blocks, copy functionality, and streaming text animation.

Basic Usage

import { ChatBubble } from '@sylphx/platform-sdk/react'

function MessageList({ messages }) {
  return (
    <div className="space-y-4">
      {messages.map((msg, i) => (
        <ChatBubble
          key={i}
          role={msg.role}
          content={msg.content}
          timestamp={msg.createdAt}
        />
      ))}
    </div>
  )
}

Props

PropertyTypeDescription
rolerequired"user" | "assistant" | "system"Who sent the message
contentrequiredstringMessage content (supports markdown)
timestampDate | stringWhen the message was sent
isStreamingboolean= falseShow typing animation
avatarstring | ReactNodeCustom avatar URL or component
namestringDisplay name for the sender
showCopyboolean= trueShow copy button on hover
onCopy() => voidCallback when content is copied
classNamestringAdditional CSS classes
variant"default" | "compact" | "minimal"= "default"Visual style variant

Variants

<ChatBubble
  role="assistant"
  content="Here's a code example:\n\n\`\`\`typescript\nconst hello = 'world'\n\`\`\`"
  timestamp={new Date()}
  name="Claude"
/>

ChatInput

A text input component optimized for chat interfaces with auto-resize, keyboard shortcuts, and submit handling.

Basic Usage

import { ChatInput } from '@sylphx/platform-sdk/react'

function ChatFooter() {
  const handleSubmit = (message: string) => {
    console.log('Sending:', message)
    // Send to AI...
  }

  return (
    <ChatInput
      onSubmit={handleSubmit}
      placeholder="Type your message..."
    />
  )
}

Props

PropertyTypeDescription
onSubmitrequired(message: string) => voidCalled when user submits message
placeholderstring= "Type a message..."Input placeholder text
disabledboolean= falseDisable input while loading
isLoadingboolean= falseShow loading state on submit button
maxLengthnumberMaximum character limit
autoFocusboolean= trueFocus input on mount
onCancel() => voidCalled when user presses Escape
submitOnEnterboolean= trueSubmit on Enter (Shift+Enter for newline)
showCharCountboolean= falseDisplay character count
classNamestringAdditional CSS classes

Examples

import { ChatInput } from '@sylphx/platform-sdk/react'

function ChatFooter({ isLoading, onSend, onStop }) {
  return (
    <ChatInput
      onSubmit={onSend}
      onCancel={onStop}
      isLoading={isLoading}
      disabled={isLoading}
      placeholder={isLoading ? 'AI is thinking...' : 'Type a message...'}
    />
  )
}

Keyboard Shortcuts

By default, Enter submits and Shift+Enter creates a new line. Set submitOnEnter=false to require Cmd/Ctrl+Enter for submission.

ModelSelector

A dropdown component for selecting from available AI models. Shows model name, provider, context window, and pricing at a glance.

Basic Usage

import { ModelSelector } from '@sylphx/platform-sdk/react'

function ChatHeader() {
  const [model, setModel] = useState('anthropic/claude-3.5-sonnet')

  return (
    <ModelSelector
      value={model}
      onChange={setModel}
    />
  )
}

Props

PropertyTypeDescription
valuerequiredstringCurrently selected model ID
onChangerequired(modelId: string) => voidCalled when selection changes
modelsModel[]Custom model list (fetched automatically if not provided)
capability"chat" | "vision" | "embedding"= "chat"Filter models by capability
showPricingboolean= trueDisplay pricing per 1M tokens
showContextboolean= trueDisplay context window size
groupByProviderboolean= trueGroup models by provider
placeholderstring= "Select a model"Placeholder when no selection
disabledboolean= falseDisable the selector
classNamestringAdditional CSS classes

Advanced Examples

import { ModelSelector, useModels } from '@sylphx/platform-sdk/react'

function SmartModelSelector() {
  const [selected, setSelected] = useState('')
  const { models, isLoading } = useModels({ capability: 'chat' })

  return (
    <ModelSelector
      value={selected}
      onChange={setSelected}
      models={models}
      disabled={isLoading}
      showPricing
      groupByProvider
    />
  )
}

ModelCard

A display card for showcasing AI model information including capabilities, pricing, context window, and provider details.

Basic Usage

import { ModelCard } from '@sylphx/platform-sdk/react'

function ModelShowcase() {
  return (
    <ModelCard
      id="anthropic/claude-3.5-sonnet"
      name="Claude 3.5 Sonnet"
      provider="Anthropic"
      contextWindow={200000}
      inputCost={3}
      outputCost={15}
      capabilities={['chat', 'vision', 'tools']}
    />
  )
}

Props

PropertyTypeDescription
idrequiredstringModel identifier
namerequiredstringDisplay name
providerrequiredstringProvider name (e.g., "Anthropic")
contextWindownumberMaximum context size in tokens
inputCostnumberCost per 1M input tokens (USD)
outputCostnumberCost per 1M output tokens (USD)
capabilitiesstring[]List of capabilities (chat, vision, tools, etc.)
badgestringOptional badge text (e.g., "Recommended")
descriptionstringBrief model description
selectedboolean= falseShow selected state
onClick() => voidClick handler
classNamestringAdditional CSS classes

Variants

<ModelCard
  id="anthropic/claude-3.5-sonnet"
  name="Claude 3.5 Sonnet"
  provider="Anthropic"
  contextWindow={200000}
  capabilities={['chat', 'vision', 'tools']}
  badge="Best Overall"
  description="Most intelligent model with excellent reasoning"
/>

ModelGrid

A responsive grid layout for displaying and comparing multiple AI models. Includes filtering, sorting, and selection functionality.

Basic Usage

import { ModelGrid } from '@sylphx/platform-sdk/react'

function ModelsPage() {
  const [selected, setSelected] = useState<string | null>(null)

  return (
    <ModelGrid
      onSelect={setSelected}
      selected={selected}
    />
  )
}

Props

PropertyTypeDescription
modelsModel[]Model list (fetched automatically if not provided)
selectedstring | nullCurrently selected model ID
onSelect(modelId: string) => voidCalled when a model is selected
capability"chat" | "vision" | "embedding"Filter by capability
showSearchboolean= trueShow search input
showFiltersboolean= trueShow capability filters
showSortboolean= trueShow sort options
columns2 | 3 | 4= 3Number of grid columns
emptyStateReactNodeCustom empty state component
classNamestringAdditional CSS classes

Advanced Examples

import { ModelGrid, useModels } from '@sylphx/platform-sdk/react'

function ModelExplorer() {
  const [selected, setSelected] = useState<string>('anthropic/claude-3.5-sonnet')
  const { models, isLoading } = useModels()

  return (
    <div className="space-y-8">
      <ModelGrid
        models={models}
        selected={selected}
        onSelect={setSelected}
        showSearch
        showFilters
        showSort
        columns={3}
      />

      {selected && (
        <div className="p-4 rounded-lg border">
          <p>Selected: {selected}</p>
          <button onClick={() => startChat(selected)}>
            Start Chat
          </button>
        </div>
      )}
    </div>
  )
}

Theming

All AI components support theming via the theme prop for consistent styling across your application.

import {
  ChatInterface,
  ModelSelector,
  defaultTheme,
  darkTheme,
  type ThemeVariables
} from '@sylphx/platform-sdk/react'

// Custom theme
const customTheme: ThemeVariables = {
  colorPrimary: '#8b5cf6',
  colorBackground: '#1e1b4b',
  colorText: '#e0e7ff',
  colorMutedForeground: '#a5b4fc',
  colorBorder: '#3730a3',
  borderRadius: '1rem',
  fontFamily: '"Inter", sans-serif',
}

// Apply to components
<ChatInterface theme={customTheme} model="..." />
<ModelSelector theme={customTheme} value={...} onChange={...} />

Theme Variables

PropertyTypeDescription
colorPrimarystring= #000000Primary accent color
colorBackgroundstring= #ffffffBackground color
colorTextstring= #1f2937Primary text color
colorMutedForegroundstring= #6b7280Secondary text color
colorBorderstring= #e5e7ebBorder color
colorUserBubblestring= colorPrimaryUser message bubble color
colorAssistantBubblestring= #f3f4f6Assistant message bubble color
fontFamilystring= system-uiFont family
borderRadiusstring= 0.5remBorder radius

Hook Integration

Components work seamlessly with the AI hooks for state management and API calls.

Complete Example
import {
  ChatInterface,
  ModelSelector,
  useChat,
  useModels,
} from '@sylphx/platform-sdk/react'
import { useState } from 'react'

export default function AIPlayground() {
  const [model, setModel] = useState('anthropic/claude-3.5-sonnet')
  const { models } = useModels({ capability: 'chat' })

  const chat = useChat({
    model,
    systemMessage: 'You are a helpful coding assistant.',
    onError: (err) => console.error('Chat error:', err),
  })

  return (
    <div className="max-w-4xl mx-auto p-4 space-y-4">
      <div className="flex items-center justify-between">
        <h1 className="text-2xl font-bold">AI Playground</h1>
        <ModelSelector
          value={model}
          onChange={setModel}
          models={models}
          showPricing
        />
      </div>

      <ChatInterface
        {...chat}
        showTokenCount
        maxHeight="70vh"
        placeholder="Ask me about code..."
      />
    </div>
  )
}

Build AI experiences faster

Combine these components with the useChat hook for production-ready AI chat in minutes.