Genie Textarea

A powerful AI-enhanced textarea web component built with Svelte 5 that seamlessly integrates with the Serenity* Star AI platform. Transform any textarea into an intelligent text editor with AI-powered completions, suggestions, and content generation.
✨ Key Features
- 🤖 AI-Powered: Built-in integration with Serenity* Star AI platform
- 🎯 Easy Integration: Works as ES module, IIFE script, or jQuery plugin
- 🎨 Fully Customizable: Custom styling, icons, and behaviors
- 📱 Responsive: Auto-resizing textarea with modern UI
- 🔧 TypeScript Support: Complete type definitions included
- 🌐 Universal: Works with any framework or vanilla JavaScript
- ⚡ Lightweight: Minimal footprint with maximum functionality
- 🎛️ Dual Modes: Direct processing or assisted mode with quick actions and custom instructions
📦 Installation
NPM Installation
npm install @serenity-star/genie-textarea
CDN Usage (IIFE)
<script src="https://unpkg.com/@serenity-star/genie-textarea/dist/genie-textarea.iife.js"></script>
🚀 Quick Start
Basic HTML Setup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Genie Textarea Demo</title>
</head>
<body>
<!-- Container element that will be replaced -->
<div id="my-textarea"></div>
<!-- Include the IIFE script -->
<script src="https://unpkg.com/@serenity-star/genie-textarea/dist/genie-textarea.iife.js"></script>
<script>
// Initialize the component
genieTextarea('my-textarea', {
apiKey: 'your-api-key',
agentCode: 'your-agent-code',
placeholder: 'Type your content here...',
label: 'Content'
});
</script>
</body>
</html>
ES Module Usage
import { genieTextarea, defineElement } from '@serenity-star/genie-textarea';
// Register the web component
defineElement();
// Initialize the component
genieTextarea('my-textarea', {
apiKey: 'your-api-key',
agentCode: 'your-agent-code',
placeholder: 'Type your content here...'
});
🤖 AI Integration
Serenity* Star Integration (Recommended)
Genie Textarea is designed to work seamlessly with Serenity* Star, a powerful AI platform for content generation and processing. This is the simplest and most powerful way to add AI capabilities to your textarea.
Getting Started with Serenity* Star
- Sign up at Serenity* Star
- Create an Agent for your specific use case
- Get your API key from the dashboard
- Use your agent code in the component
genieTextarea('my-textarea', {
apiKey: 'sk-your-api-key-here',
agentCode: 'your-agent-code',
placeholder: 'Type something here...',
});
Custom Base URL
If you're using a custom Serenity* Star deployment:
genieTextarea('my-textarea', {
apiKey: 'your-api-key',
agentCode: 'your-agent-code',
baseURL: 'https://your-custom-api.example.com/api/v2'
});
Input Parameters
Pass additional parameters to your Serenity* Star agent:
genieTextarea('my-textarea', {
apiKey: 'your-api-key',
agentCode: 'your-agent-code',
inputParameters: {
tone: 'professional',
language: 'en',
maxLength: 500
}
});
Custom Completion Handler
For complete control over the AI completion process, use the handleRequestCompletion callback. When using this approach, agentCode and apiKey are not used.
genieTextarea('my-textarea', {
handleRequestCompletion: async ({ content, instruction, addChunk, setContent }) => {
try {
// Your custom AI logic here
const response = await fetch('https://your-ai-api.com/complete', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: content,
prompt: instruction
})
});
if (response.body) {
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
addChunk?.(chunk); // Stream chunks to the textarea
}
}
} catch (error) {
console.error('Completion error:', error);
// Handle error appropriately
}
}
});