mahesh-kerai / support-assistant
Reusable, documentation-grounded AI customer support for Laravel applications.
Package info
github.com/Maheshkerai/support-assistant
Language:Blade
pkg:composer/mahesh-kerai/support-assistant
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0|^12.0|^13.0
- illuminate/contracts: ^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-01 07:29:18 UTC
README
mahesh-kerai/support-assistant
Reusable, documentation-grounded AI customer support package for Laravel applications.
Features
- Sitemap-based documentation indexing: Syncs product documentation from XML sitemaps and stores clean
<article>/<main>page content per product slug. - Ranked documentation retrieval: Filters stopwords and scores matches across titles, URL paths, and page content using database-agnostic queries (MySQL, MariaDB, PostgreSQL, SQLite).
- Gemini-powered grounded answers: Answers strictly from indexed documentation with automatic fallback model support (
fallback_models), Gemini 3+thinkingConfighandling, and token usage tracking. - Modern Admin UI (
/ai-support):- Manage Products & Documentation and AI Support Settings in one place.
- Dynamically fetch available Gemini models via API (
Refresh models). - Save the Gemini API key encrypted at rest using Laravel's
Crypt(never displayed back in the input field). - Configure toggles (
Enable AI support,Show chat widget,Enable API), view the live API endpoint + cURL modal, and customize widget appearance, fallback message, rate limit, and max output tokens.
- Smart Blade chat widget (
<x-ai-support::widget />):- Expand/collapse size toggle in the chat header.
- XSS-safe Markdown renderer (built with DOM nodes and
textContent, zeroinnerHTML) supporting```bash/ code blocks with one-click Copy buttons. - Automatic light & dark theme support following system
prefers-color-schemeas well asdata-theme="dark"/data-theme="light". - Dynamic collision-avoidance positioning that automatically adjusts around existing floating buttons or sticky bars on the page.
Requirements
- PHP
8.2+ - Laravel
10,11,12, or13 - PHP
dom,libxml, andsimplexmlextensions - Google Gemini API key
Installation
composer require mahesh-kerai/support-assistant
Configuration
1. Publish Config & Views (Optional)
Package defaults load automatically. Publish the config when you need to customize middleware, paths, or retrieval settings:
php artisan vendor:publish --tag=ai-support-config
Optionally publish the Blade views if you want to customize templates directly:
php artisan vendor:publish --tag=ai-support-views
2. Environment Variables
Add these variables to your .env file (the Gemini API key can also be saved later from the Admin Settings UI):
AI_SUPPORT_ENABLED=true AI_SUPPORT_API_ENABLED=true AI_SUPPORT_DB_CONNECTION=mysql AI_SUPPORT_PRODUCT_ID=eschool-saas AI_SUPPORT_ADMIN_PATH=ai-support AI_SUPPORT_API_PREFIX=api/ai-support AI_SUPPORT_PROVIDER=gemini AI_SUPPORT_MODEL=gemini-3.5-flash-lite AI_SUPPORT_FALLBACK_MODELS=gemini-3.6-flash,gemini-3.5-flash AI_SUPPORT_API_KEY=YOUR_GEMINI_API_KEY
| Variable | Default | Description |
|---|---|---|
AI_SUPPORT_ENABLED |
true |
Global fallback enable flag (overridden by Admin Settings UI). |
AI_SUPPORT_API_ENABLED |
true |
Default flag for external API access (Enable API setting). |
AI_SUPPORT_DB_CONNECTION |
mysql |
Database connection name used by all ai_support_* tables and migrations (keeps package tables on the central MySQL database in multi-database/tenant setups). |
AI_SUPPORT_PRODUCT_ID |
your-product |
Default product slug fallback. |
AI_SUPPORT_ADMIN_PATH |
ai-support |
URL prefix for the Admin Panel routes. |
AI_SUPPORT_API_PREFIX |
api/ai-support |
URL prefix for the chat API endpoint. |
AI_SUPPORT_PROVIDER |
gemini |
Active AI provider (gemini). |
AI_SUPPORT_MODEL |
gemini-3.5-flash-lite |
Primary Gemini model fallback if not set in Admin Settings. |
AI_SUPPORT_FALLBACK_MODELS |
gemini-3.6-flash,gemini-3.5-flash |
Comma-separated fallback models used automatically on 404/429/502/503/504 or timeouts. |
AI_SUPPORT_API_KEY |
null |
Fallback Gemini API key if not saved via the Admin Settings UI. |
3. Run Database Migrations
Creates ai_support_products, ai_support_documents, ai_support_conversations, ai_support_messages, and ai_support_settings:
php artisan migrate
4. Configure Admin Authorization Middleware
By default, admin routes use ['web', 'auth'].
Important: Update admin_middleware in your published config/ai-support.php to enforce administrator access (for example, ['web', 'auth', 'role:Super Admin']):
'admin_middleware' => ['web', 'auth', 'role:Super Admin'],
Admin Panel & Settings
Visit /ai-support (or /ai-support/settings directly):
Settings Tab (/ai-support or /ai-support/settings)
- General settings
- Enable AI support: Master toggle. Turning this off automatically disables the chat widget and API across websites and external/mobile apps.
- Show chat widget: Shows or hides the floating launcher on frontend layouts (requires
Enable AI support). - Enable API: Enables external
POST /api/ai-support/chatrequests (for Next.js or mobile apps), displays the endpoint URL, and provides a View API example modal with a copyable cURL command.
- AI provider
- Provider:
Google Gemini. - API key: Enter your Gemini API key and click Save settings. The key is encrypted via Laravel
Cryptbefore storage and the input remains empty on reload with"Already configured. Leave it empty to keep the existing API key unchanged."shown below it. - Model: Automatically fetches available
generateContentGemini models from Google's API when a key is configured. Click Refresh models anytime after entering or updating an API key.
- Provider:
- Widget appearance
- Widget title, Show button text label (switch between
Icon & labelandIcon only), Welcome message, Widget position (Bottom right/Bottom left), and Widget color (synced color picker + hex input).
- Widget title, Show button text label (switch between
- AI behavior
- Fallback message: Reply returned when no matching documentation is found.
- Maximum messages per minute: Dynamic per-user/IP rate limit enforced on
POST /api/ai-support/chat. - Maximum response length: Maximum
maxOutputTokenssent to Gemini (100–8192).
Products & Documentation Tab (/ai-support?tab=products)
Register each product with a unique slug, documentation base URL, and XML sitemap URL. Example:
- Name:
eSchool SaaS - Slug:
eschool-saas - Documentation base URL:
https://wrteam-in.github.io/eSchool-SaaS-Doc - Sitemap URL:
https://wrteam-in.github.io/eSchool-SaaS-Doc/sitemap.xml
Syncing Documentation
From the Admin Panel (Recommended)
Open /ai-support?tab=products and click Sync all in Documentation sync command to sync all products, or click the Sync button on any individual product row in the documentation table to execute php artisan ai-support:sync directly without SSH or terminal access (you can also Delete any product row directly from the table). The sync command card shows live status (Not synced / Pending -> In Progress -> Completed / Synced or Failed), a live progress bar, and updates product document counts automatically.
Via Artisan CLI / Scheduler
You can also run or schedule documentation syncing via Artisan:
# Sync all products php artisan ai-support:sync # Sync a specific product by slug php artisan ai-support:sync eschool-saas
To keep documentation updated automatically, schedule the command in routes/console.php (Laravel 11+) or app/Console/Kernel.php:
Schedule::command('ai-support:sync')->daily();
The importer accepts URLs matching the product's configured docs_base_url host/path, extracts <article> or <main> text, hashes URLs via url_hash (sha256), and removes stale pages no longer present in a successfully fetched sitemap.
Embedding & Customizing the Widget
Add the Blade component once before </body> in your main layout:
<x-ai-support::widget product="eschool-saas" />
Use a different product slug in each product's layout, or register multiple products in a central admin host.
Theme Support (System, Light, and Dark)
The widget and admin UI automatically adapt to:
- System theme: Follows
prefers-color-scheme: dark/lightwhen nodata-themeattribute is set. - Explicit theme attribute: Honors
data-theme="dark"ordata-theme="light"on<html>, any ancestor element, or directly on the component:<x-ai-support::widget product="eschool-saas" data-theme="dark" />
Dynamic Positioning
Starting from the configured corner (Bottom right or Bottom left), the widget automatically detects visible fixed/sticky buttons or bars (such as a Buy Now button, cookie banner, or another chat launcher) and shifts above, beside, or to the opposite corner to avoid overlapping. It also caps the open panel height beneath fixed top navbars.
To disable automatic relocation on a specific page and keep the configured corner strictly fixed:
<x-ai-support::widget product="eschool-saas" data-auto-position="0" />
Chat API
POST /api/ai-support/chat
Request JSON:
{
"product": "eschool-saas",
"message": "How to setup queue on server?",
"conversation_id": null
}
Response JSON:
{
"conversation_id": "9f238ec6-02ca-40d1-afa5-7742ccb7e225",
"answer": "...",
"sources": [
{
"title": "🔄 Laravel Queue Implementation",
"url": "https://wrteam-in.github.io/eSchool-SaaS-Doc/installation/admin-panel-installation/queue-setup/"
}
]
}
Security Notes
- API keys saved in the Admin UI are encrypted with Laravel
Cryptand never sent to browser JavaScript or re-populated into form inputs. - Gemini requests pass the key in the
x-goog-api-keyheader rather than URL query strings. - Retrieved documentation is marked as untrusted reference content inside the system prompt.
- All Markdown, headings, lists, links (
http:/https:only), and code blocks in the widget are constructed safely via DOM nodes andtextContentwithoutinnerHTML.
