heysolana-kit
v1.0.1
Published
A TypeScript SDK for building voice-enabled Solana applications with natural language interactions.
Readme
Hey Solana SDK
A TypeScript SDK for building voice-enabled Solana applications with natural language interactions.
Features
- Real-time voice interactions with AI
- WebRTC-based audio streaming
- Built-in Solana wallet integration
- Customizable system instructions
- Function calling capabilities
- Memory management for conversation context
- Audio permission handling
- Event-based communication
Installation
npm install heysolana-kit
# or
yarn add heysolana-kitQuick Start
import { Connection } from "@solana/web3.js";
import { useHeySolana } from "heysolana-kit";
// Initialize Solana connection
const connection = new Connection("YOUR_RPC_URL", "confirmed");
// Create HeySolana instance
const hey = new useHeySolana(connection, {
apiKey: {
key: "YOUR_API_KEY",
type: "OPENAI" // or "HEYSOLANA" or "GEMINI"
},
systemInstructions: "You are a helpful Solana assistant.",
tools: [], // Optional: Add custom tools
callbacks: {
setMode: (mode) => {
console.log("Current mode:", mode);
},
setConversationId: (id) => {
console.log("Conversation ID:", id);
}
}
});Configuration
API Keys
The SDK supports multiple AI providers:
- OpenAI
- HeySolana
- Gemini
System Instructions
Customize the AI's behavior by providing system instructions:
const hey = new useHeySolana(connection, {
systemInstructions: "You are a Solana expert assistant that helps users with blockchain transactions.",
// ... other options
});Custom Tools
Add custom tools to extend the SDK's functionality:
const customTools = [
{
name: "transfer_tokens",
owner: "HeySolana",
description: "Transfer tokens between users",
parameters: {
type: "object",
properties: {
amount: {
type: "number",
description: "Amount to transfer"
},
token: {
type: "string",
description: "Token to transfer"
},
recipient: {
type: "string",
description: "Recipient's username"
}
},
required: ["amount", "recipient", "token"]
},
handler: (sessionManager) => async (params) => {
// Implement token transfer logic
}
}
];
const hey = new useHeySolana(connection, {
tools: customTools,
// ... other options
});Usage
Managing Conversations
// Get current conversation ID
const conversationId = hey.getCurrentConversation();
// Get messages from current conversation
const messages = hey.getCurrentConversationMessages();
// Get all conversations
const conversations = hey.getConversations();
// Get messages from a specific conversation
const conversationMessages = hey.getConversationMessages(conversationId);Audio Settings
The SDK includes built-in audio management with the following features:
- Voice selection (default: "alloy")
- Language support
- Audio permissions handling
- Real-time audio streaming
Network Configuration
The SDK supports both mainnet and devnet:
// Default network is mainnet
// To switch to devnet:
hey.changeNetwork("devnet");State Management
The SDK uses Zustand for state management, providing:
- User session management
- Wallet state
- Application settings
- Conversation history
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
ISC
