alibori / laravel-watson
Laravel Watson watches your application's exceptions, uses the Laravel AI SDK to diagnose the likely cause and fix, and notifies you only when it's actually worth knowing about.
Fund package maintenance!
Requires
- php: ^8.3
- illuminate/contracts: ^13.0
- illuminate/notifications: ^13.0
- illuminate/support: ^13.0
- laravel/ai: ^1.3.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^11.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Laravel Watson watches your application's exceptions, uses the Laravel AI SDK to diagnose the likely cause and fix, and notifies you only when it's actually worth knowing about.
Installation
You can install the package via composer:
composer require alibori/laravel-watson
You can publish the config file with:
php artisan vendor:publish --tag="watson-config"
Usage
1. Configure the AI provider
Watson uses the Laravel AI SDK. Set up a provider and its API key as described in its docs (e.g. OPENAI_API_KEY or ANTHROPIC_API_KEY in your .env).
2. Configure Watson
WATSON_ENABLED=true WATSON_CHANNEL=mail WATSON_ROUTE=dev-team@example.com
WATSON_ENABLED: master switch. Set tofalselocally or in tests.WATSON_CHANNEL: notification channel used to deliver the analysis. For now only works with mail.WATSON_ROUTE: destination for that channel (an email address formail). Watson does nothing if it's empty.
3. Hook it into your exception handler
In bootstrap/app.php:
use Alibori\LaravelWatson\LaravelWatson; use Illuminate\Foundation\Configuration\Exceptions; ->withExceptions(function (Exceptions $exceptions) { $exceptions->report(function (Throwable $e) { LaravelWatson::handle($e); }); })
4. Run a queue worker
The analysis runs in a queued job, so your requests are never slowed down by the AI call:
php artisan queue:work
Each notification includes a summary, the likely cause, a suggested fix and a severity (low, medium, high, critical).
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.