Laravel AI chat for Saucebase: streaming replies, conversation history, web search, image generation and plan limits, built on laravel/ai, on Vue or React. It opens at /chat.
A module for Saucebase, the AI-ready Laravel SaaS kit. Modules are Composer packages you add to a Saucebase app; once installed, the code is yours to change.
- Streaming replies in markdown, with the steps that led to them: thinking, tool calls and sources
- Conversations per user: titled automatically, renamed, pinned, deleted and searched, grouped by date; long chats load older messages as you scroll up
- Tools: web search (the provider's own), image generation, and
about_my_account, which reads the signed-in user's profile, plan and workspace from the installed modules - Model picker with the models you offer
- Monthly limits per plan for messages and images, with the Billing module: a usage bar near the limit and an upgrade link
- Dictation in the message box
- Admin panel: provider API keys, the models users can pick, extra instructions, image settings, and a read-only conversation viewer
- Test mode: a demo provider answers, so you can build and try the chat without a key or tokens
- WebMCP (beta, off until turned on): the visitor's own browser agent can ask the assistant and read or switch chats
- Two layouts: a "Chat" item in the app sidebar and the chats in a panel of their own, or the chats in the app sidebar for a chat-first app
- Vue and React
New to Saucebase? Start a new app and pick ai-chat when it asks for modules:
curl -fsSL https://install.saucebase.dev | bashIt installs PHP and Composer if they're missing. With the CLI already installed, run saucebase new my-app instead.
With your Saucebase app ready, add AI Chat:
php artisan saucebase:module-install ai-chat
npm install && npm run buildIt needs Auth for sign-in. Conversation titles are written by a queued job, so run a queue worker.
Version 1 needs laravel/ai 1.4 or newer, which stores chats in a new format. The module's migration creates the new tables on a fresh install only, so an app that already has chats must convert them:
- Keep the chats: back up the database, copy the backfill migration from laravel/ai's upgrade guide into
database/migrations, and runphp artisan migrate. - Start over: rebuild the database with
php artisan migrate:fresh. This deletes all of the app's data, not only the chats.
Until then, chats don't save or reopen.
In the admin panel, under Settings → AI chat (people with the manage ai chat permission, and admins), in four sections:
- Models: each provider with its API key (stored encrypted; a key set in
.env, laravel/ai'sconfig/ai.php, works too) and the models users can pick, and the default model. Only providers with a key are offered. Amazon Bedrock also needscomposer require aws/aws-sdk-php. In test mode the page says the demos replace them. - Assistant: instructions added to the assistant's own.
- Images: the provider, model and quality
generate_imageuses..envcan set them too (AI_CHAT_IMAGE_PROVIDER,AI_CHAT_IMAGE_MODEL,AI_CHAT_IMAGE_QUALITY); without either, laravel/ai's default for images. - WebMCP (beta): off by default. On, the chat offers its tools to the visitor's own browser agent, in browsers that support WebMCP (a draft standard).
The conversation viewer is under Chats.
Where the chat list lives is sessions in config/ai-chat.php (publish the config, or set it from your own service provider):
| Value | Layout |
|---|---|
page (default) |
A "Chat" item in the app sidebar. On the chat, the app sidebar starts collapsed to its icons, and the chats, search and WebMCP sit in a resizable panel of their own (a sheet on phones). |
sidebar |
The chats and WebMCP in the app sidebar on every page, with no item and no panel. For an app where the chat is the product. |
With Billing installed, a plan can set two limits per month, as capabilities on its product:
ai_chat_messages: messages a user can sendai_chat_images: images the assistant can generate for them
A limit a user's plans don't set is unlimited. At the limit, sending is turned off until the next month, with a link to upgrade.
AI_CHAT_TEST_MODE=trueEvery provider call goes to a demo provider: the picker offers the demos (Demo: Steps, Demo: Image…), and titles and images use it too. The real agent, tools, storage and streaming all run. Each demo is a JSON file in resources/demos/; adding one is adding a file. Test mode is refused in production.
- A class in
src/Ai/Tools/implementingLaravel\Ai\Contracts\Tool, with aNAMEconstant. Take the user in the constructor and return a string (JSON for structured results).AboutMyAccountis the example to copy. - Return it from
ChatAgent::tools(). - Give it labels in
TOOL_LABELS(resources/js/lib/tools.ts), or the steps show its name. - Optionally, a demo in
resources/demos/so test mode can show it.
php artisan test --compact modules/ai-chat/tests
npx vitest run modules/ai-chat
npx playwright test modules/ai-chat/tests/e2e --project="@ai-chat*"MIT. See LICENSE.