Advanced Usage
Unlock the full potential of @termix-it/react-tool with advanced features like function calling, smart contract integration, streaming mode, floating chat widgets, custom implementations, and comprehensive API integration.Function Calling
The ChatInterface automatically handles different types of function calls based on your AI configuration.REST API Function Calls
Configure your AI to make REST API calls that are automatically executed:Dynamic Header Management
Update API headers dynamically based on user state:ChatWidget Advanced Usage
The ChatWidget component provides sophisticated floating chat capabilities with extensive customization options.Dynamic Widget State Management
Control widget behavior based on application state and user interactions:Multi-Widget Implementation
Deploy multiple specialized widgets for different use cases:Real-time Streaming Implementation
Advanced streaming configurations for optimal user experience:Streaming with Connection Monitoring
Streaming with Progressive Enhancement
Smart Contract Integration
Enable blockchain interactions with automatic smart contract execution:Basic Smart Contract Setup
Multi-Chain Contract Support
Handle contracts across different blockchain networks:Knowledge Base Integration
Set up sophisticated knowledge base search and reference systems:Custom Knowledge Base Handling
Custom Theming
Implement advanced theming with CSS custom properties:Dark Mode Theme
custom-theme.css
ReAct Pattern Implementation
Enable sophisticated reasoning and acting patterns:Error Handling and Recovery
Implement robust error handling:Performance Optimization
Optimize performance for production use:API Integration
Default API Configuration
The SDK now automatically connects to the Termix API:- Production:
https://dashboard.termix.ai
- Local Development:
http://127.0.0.1:3001
(when usingnpm run dev:local
)
Development Setup
For local development with a local backend server:-
Install the SDK in your project:
-
For local backend development:
If you need to connect to a local backend server running at
http://127.0.0.1:3001
, you have two options: Option 1: Build the SDK locally with local configurationOption 2: Use environment variable (if your build system supports it)
API Endpoints
The SDK automatically connects to these Termix API endpoints:Chat Endpoints
POST /api/v1/ai/projects/{projectId}/chat
- Regular chat messagesPOST /api/v1/ai/projects/{projectId}/chat/stream
- Streaming chat messages (SSE)GET /api/v1/ai/projects/{projectId}/configs/{configId}
- Get AI config (including greeting message)
Function Execution
- REST API endpoints for function calls (auto-detected)
- Smart contract execution via web3 providers
Knowledge Base
GET /api/v1/projects/{projectId}/knowledge-base/search
- Search knowledge baseGET /api/v1/knowledge/{projectId}
- Get all knowledge
MCP Tools
GET /api/v1/mcp-tools/{projectId}/parsed-endpoints
- Get parsed API endpointsGET /api/v1/mcp-tools/{projectId}/parsed-contracts
- Get parsed smart contracts
Styling and Customization
Style Import
Styles are now automatically bundled with the components - no separate CSS import needed:.termix-
prefix to prevent conflicts.
Using Inline Styles
BothChatInterface
and ChatWidget
support inline styles via the style
prop:
Custom Theming with CSS Variables
You can override the default colors using CSS custom properties:Exported Components and Utilities
Troubleshooting
Styles Not Loading Correctly
You must manually import the styles. If you experience issues:-
Check for CSS conflicts: The library’s styles are scoped to
.termix-container
to avoid conflicts, but ensure your global styles don’t override them. - Tailwind CSS conflicts: If your project uses Tailwind CSS, the scoped styles should prevent conflicts. The components also use inline styles for critical styling.
-
Header visibility: The chat header uses inline styles to ensure proper display:
- Blue gradient background:
linear-gradient(to right, #3b82f6, #2563eb)
- White text color is explicitly set
- Blue gradient background:
Input Alignment Issues
The input area automatically aligns the text input and send button vertically. If you experience alignment issues, check that parent containers don’t override the flex layout.Best Practices Summary
Security
Security
- Never expose API keys in frontend code
- Use server-side proxies for sensitive operations
- Validate user inputs and sanitize outputs
- Implement proper authentication and authorization
Performance
Performance
- Memoize expensive calculations and callbacks
- Disable unused features to reduce overhead
- Implement proper error boundaries
- Use lazy loading for large components
User Experience
User Experience
- Provide clear feedback for loading states
- Handle errors gracefully with user-friendly messages
- Implement retry mechanisms for network failures
- Show progress indicators for long-running operations
Development
Development
- Use TypeScript for better development experience
- Implement comprehensive error logging
- Test all function calling scenarios
- Document custom configurations and integrations