kuralit_sdk 0.1.1
kuralit_sdk: ^0.1.1 copied to clipboard
A Flutter SDK for Kuralit realtime communication with WebSocket support for text and audio streaming.
example/README.md
Kuralit Flutter SDK Examples #
Quick start examples for the Kuralit Flutter SDK. Each example is minimal, easy to understand, and ready to run.
π Examples Overview #
1. Basic Text Chat (basic/) #
- What it does: Simple text messaging - send and receive messages
- Best for: Understanding the core SDK functionality
- Features: Connection, text sending, event handling
- Lines of code: ~150
2. Popup Chat Template (popup_chat/) #
- What it does: Uses the ready-made
KuralitPopupChatwidget - Best for: Quick integration - just one button to open chat
- Features: Full chat UI with text + audio, no custom UI needed
- Lines of code: ~100
3. Agent Overlay (agent_overlay/) #
- What it does: Uses the full-screen
KuralitAgentOverlaywidget - Best for: Voice-first interactions with beautiful animations
- Features: Full-screen overlay, voice input, animated UI
- Lines of code: ~100
4. WebSocket Protocol (protocol/) #
- What it does: Shows actual WebSocket message formats
- Best for: Understanding the protocol and debugging
- Features: Message format display, event logging, audio streaming format
- Lines of code: ~300
π Quick Start #
Prerequisites #
- Flutter SDK installed (>=3.0.0)
- Android Studio / VS Code with Flutter extensions
- Your Kuralit API credentials:
- Server URL (e.g.,
wss://api.kuralit.com/ws) - API Key
- App ID
- Server URL (e.g.,
Running an Example #
-
Choose an example:
cd example/basic # or popup_chat, agent_overlay, protocol -
Update API credentials:
- Open
main.dart - Find these lines (around line 15-17):
const serverUrl = 'wss://api.kuralit.com/ws'; const apiKey = 'your-api-key-here'; const appId = 'your-app-id-here'; - Replace with your actual values
- Open
-
Install dependencies:
flutter pub get -
Run the example:
flutter run
π± Platform Requirements #
Android #
- Minimum SDK: 21 (Android 5.0)
- Permissions: Microphone (for audio examples)
- Add to
android/app/src/main/AndroidManifest.xml:<uses-permission android:name="android.permission.RECORD_AUDIO" />
iOS #
- Minimum version: iOS 12.0
- Permissions: Microphone (for audio examples)
- Add to
ios/Runner/Info.plist:<key>NSMicrophoneUsageDescription</key> <string>This app needs microphone access for voice chat</string>
π Example Details #
Basic Text Chat #
File: example/basic/main.dart
Shows:
- β SDK initialization
- β WebSocket connection
- β Sending text messages
- β Receiving responses
- β Event handling
- β Connection status
Use this when: You want to build your own custom UI.
Popup Chat Template #
File: example/popup_chat/main.dart
Shows:
- β
Using
KuralitPopupChat.show() - β One-line integration
- β Ready-made chat UI
- β Text + audio modes
- β Tool calls display
Use this when: You want a quick chat dialog without building UI.
Agent Overlay #
File: example/agent_overlay/main.dart
Shows:
- β
Using
KuralitAgentOverlay.show() - β Full-screen animated overlay
- β Voice-first interaction
- β Beautiful animations
Use this when: You want a premium voice-first experience.
WebSocket Protocol #
File: example/protocol/main.dart
Shows:
- β
Text message format:
{"type": "client_text", ...} - β
Audio start format:
{"type": "client_audio_start", ...} - β
Audio chunk format:
{"type": "client_audio_chunk", ...} - β
Audio end format:
{"type": "client_audio_end", ...} - β All response event types
- β Real-time message logging
Use this when: You need to understand the protocol or debug messages.
π§ Troubleshooting #
Connection Issues #
- Check your server URL is correct
- Verify API key and App ID
- Check network connectivity
- Enable debug mode:
debug: trueinKuralitConfig
Audio Not Working #
- Check microphone permissions are granted
- Verify platform-specific permissions are set (see above)
- Test on a physical device (emulators may not support audio)
Build Errors #
- Run
flutter cleanthenflutter pub get - Ensure Flutter SDK version is >=3.0.0
- Check that all dependencies are installed
π Next Steps #
- Start with Basic: Understand the core concepts
- Try Templates: See how easy it is to use ready-made widgets
- Explore Protocol: Understand the WebSocket messages
- Build Your App: Use these examples as a starting point
π‘ Tips #
- Enable debug mode: Set
debug: trueinKuralitConfigto see detailed logs - Session IDs: Each conversation needs a unique session ID - use
Kuralit.generateSessionId() - Event handling: Listen to
Kuralit.eventsstream to handle all responses - Connection status: Check
Kuralit.isConnected()before sending messages
π Code Structure #
Each example follows this pattern:
// 1. Import SDK
import 'package:kuralit_sdk/kuralit.dart';
// 2. Initialize (in main or initState)
Kuralit.init(KuralitConfig(...));
// 3. Connect
await Kuralit.connect();
// 4. Listen to events
Kuralit.events.listen((event) {
// Handle events
});
// 5. Send messages
Kuralit.sendText(sessionId, "Hello");
π€ Need Help? #
- Check the main SDK README:
../README.md - Review the example code comments
- Enable debug logging to see what's happening
Happy coding! π