Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f7a6fea
feat: stream chat replies with conversations and canned test mode
roble Nov 25, 2026
62d87da
feat: chat page with session list, steps and markdown replies
roble Nov 25, 2026
c137162
feat: retitle conversations at message milestones
roble Nov 25, 2026
8733253
feat: web search, account and image generation tools
roble Nov 25, 2026
c716670
feat: monthly message and image limits from billing plans
roble Nov 25, 2026
c205af7
feat: chat settings, model picker and conversation viewer in the admin
roble Nov 25, 2026
4d35212
feat: WebMCP tools for the visitor's browser agent
roble Nov 25, 2026
5409c46
docs: module guideline, skill and README
roble Nov 25, 2026
4122b7b
fix: phpstan clean: billing through BillingOwner, titles read only th…
roble Nov 25, 2026
9c6bd94
chore: 1.x branch alias like every other module
roble Nov 25, 2026
bb7285e
fix: stream canned replies unbuffered; keep a new chat's URL move
roble Nov 25, 2026
7c89028
fix: give each canned reply its own message id
roble Nov 25, 2026
f287346
fix: reopened chats show their history, images included
roble Nov 25, 2026
9068f67
feat: chat history in the app sidebar
roble Nov 25, 2026
f5f60e2
feat: drop the Chat nav item; New chat in the sidebar replaces it
roble Nov 25, 2026
890867e
feat: configurable image provider, model and quality
roble Nov 25, 2026
5e261e5
fix: show real tool calls in the steps list
roble Nov 25, 2026
b0af22d
feat: provider API keys, seeded models and image settings in the admin
roble Nov 25, 2026
990307a
feat: API keys and models as inline tables with provider selects
roble Nov 25, 2026
6dd1518
feat: name the provider keys that come from the server environment
roble Nov 25, 2026
cf08e73
feat: group the admin's keys and models by provider
roble Nov 25, 2026
68ede1e
fix: never preselect a default model whose provider has no key
roble Nov 25, 2026
4d5869e
fix: offer only capable providers, by their own names; narrow picker …
roble Nov 25, 2026
640b827
fix: ellipsis on a truncated model name
roble Nov 25, 2026
0e8e24c
test: stories match the failed-image text and wait for the markdown t…
roble Nov 28, 2026
82d94ab
feat: chat rebuilt on AI Elements, with a demo provider, sessions and…
roble Nov 28, 2026
b28c904
feat: pin chats, capped chat list, message history paging, usage bar
roble Nov 29, 2026
fa6e5f1
fix: thinking no longer jumps when the thought begins
roble Nov 29, 2026
5365e13
fix: sending no longer throws the chat's scroll about
roble Nov 29, 2026
5088065
feat: the chat list in a panel of its own, or in the app sidebar
roble Nov 29, 2026
a2fe61d
chore: require core ^3.3
roble Nov 29, 2026
b32a540
fix: the chat panel's resizer is `contained`; saved values wait for h…
roble Nov 29, 2026
19224c8
ci: install auth and billing alongside the module
roble Nov 30, 2026
7a27ca9
test: an E2E smoke test, answered by the demo provider
roble Nov 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ jobs:
uses: saucebase-dev/core/.github/workflows/test-module.yml@main
with:
module: ai-chat
# dependencies: saucebase/auth # add space-separated packages if needed
# Login (guests are sent to it) and billing's plans (the message and image limits).
dependencies: saucebase/auth saucebase/billing
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# AiChat Module
# AI Chat

A Laravel module that extends Saucebase core functionality. Designed for seamless integration with the ecosystem.
A streaming AI chat for Saucebase apps, at `/chat`.

This module is part of **[Saucebase](https://github.com/saucebase-dev/saucebase)**
- Conversations per user, titled automatically, with a session list.
- 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. It is the example to copy for your own tools.
- Monthly limits per plan (`ai_chat_messages`, `ai_chat_images`) with the Billing module.
- Admin: extra instructions, the models users can pick, and a read-only conversation viewer.
- WebMCP: the visitor's own browser agent can ask the assistant and read or switch chats.

**[Documentation →](https://saucebase-dev.github.io/docs/modules)**
## Install

```bash
php artisan saucebase:module-install ai-chat
npm install && npm run build
```

Set a provider key in `.env` (see `config/ai.php` from laravel/ai). Without one, `AI_CHAT_TEST_MODE=true` answers through a demo provider (the replies in `resources/demos/`, offered as models in the picker) so the chat can be built and tried for free.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "AI chat with streaming replies, web search, image generation, account-aware tools, plan usage limits and WebMCP.",
"type": "saucebase-module",
"license": "proprietary",
"version": "v0.1.0",
"version": "v1.0.0",
"authors": [
{
"name": "Saucebase",
Expand All @@ -22,7 +22,7 @@
]
},
"branch-alias": {
"dev-dev": "0.x-dev"
"dev-dev": "1.x-dev"
}
},
"autoload": {
Expand All @@ -39,7 +39,7 @@
},
"minimum-stability": "stable",
"require": {
"saucebase/core": "^3.1",
"saucebase/core": "^3.3",
"laravel/ai": "^0.11"
}
}
27 changes: 26 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
<?php

return [
// Add your configuration settings here

/*
| Where the chat list lives. `page`: the chat page has its own panel, and the app
| sidebar a "Chat" item. `sidebar`: the list sits in the app sidebar on every page,
| with no item and no panel (a chat-first app, like the chat template).
*/
'sessions' => 'page',

/*
| Answer through the demo provider (replies from resources/demos) instead of
| a real model, so the chat can be
| worked on without a provider key or tokens. Refused in production whatever
| this says: invented answers for real users are worse than an outage.
*/
'test_mode' => (bool) env('AI_CHAT_TEST_MODE', false),

/*
| Where generate_image sends its prompts. Null: laravel/ai's defaults
| (`ai.default_for_images`, which is Gemini). Quality: low, medium or high.
*/
'images' => [
'provider' => env('AI_CHAT_IMAGE_PROVIDER'),
'model' => env('AI_CHAT_IMAGE_MODEL'),
'quality' => env('AI_CHAT_IMAGE_QUALITY'),
],

];
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laravel\Ai\Migrations\AiMigration;

return new class extends AiMigration
{
/**
* Run the migrations.
*/
public function up(): void
{
$conversationsTable = config('ai.conversations.tables.conversations', 'agent_conversations');
$messagesTable = config('ai.conversations.tables.messages', 'agent_conversation_messages');

// An app that already published laravel/ai's own migration keeps its tables.
if (Schema::hasTable($conversationsTable)) {
return;
}

Schema::create($conversationsTable, function (Blueprint $table) {
$table->string('id', 36)->primary();
$table->string('participant_type')->nullable();
$table->unsignedBigInteger('participant_id')->nullable();
$table->string('title');
$table->timestamps();

$table->index(['participant_type', 'participant_id', 'updated_at'], 'participant_updated_at_index');
});

Schema::create($messagesTable, function (Blueprint $table) {
$table->string('id', 36)->primary();
$table->string('conversation_id', 36)->index();
$table->string('participant_type')->nullable();
$table->unsignedBigInteger('participant_id')->nullable();
$table->string('agent');
$table->string('role', 25);
$table->text('content');
$table->text('attachments');
$table->text('tool_calls');
$table->text('tool_results');
$table->text('usage');
$table->text('meta');
$table->text('approval_state')->nullable();
$table->timestamps();

$table->index(['conversation_id', 'participant_type', 'participant_id', 'updated_at'], 'conversation_index');
$table->index(['participant_type', 'participant_id'], 'participant_index');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists(config('ai.conversations.tables.messages', 'agent_conversation_messages'));
Schema::dropIfExists(config('ai.conversations.tables.conversations', 'agent_conversations'));
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laravel\Ai\Migrations\AiMigration;

/**
* When the user named the chat themselves: generated titles leave it alone from then on.
*/
return new class extends AiMigration
{
public function up(): void
{
$table = config('ai.conversations.tables.conversations', 'agent_conversations');

if (! Schema::hasColumn($table, 'renamed_at')) {
Schema::table($table, fn (Blueprint $blueprint) => $blueprint->timestamp('renamed_at')->nullable());
}
}

public function down(): void
{
$table = config('ai.conversations.tables.conversations', 'agent_conversations');

Schema::table($table, fn (Blueprint $blueprint) => $blueprint->dropColumn('renamed_at'));
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laravel\Ai\Migrations\AiMigration;

/**
* When the user pinned the chat: pinned chats lead the sidebar's list.
*/
return new class extends AiMigration
{
public function up(): void
{
$table = config('ai.conversations.tables.conversations', 'agent_conversations');

if (! Schema::hasColumn($table, 'pinned_at')) {
Schema::table($table, fn (Blueprint $blueprint) => $blueprint->timestamp('pinned_at')->nullable());
}
}

public function down(): void
{
$table = config('ai.conversations.tables.conversations', 'agent_conversations');

Schema::table($table, fn (Blueprint $blueprint) => $blueprint->dropColumn('pinned_at'));
}
};
67 changes: 67 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Modules\AiChat\Database\Seeders;

use Illuminate\Database\Seeder;
use Laravel\Ai\AiManager;
use Modules\AiChat\Ai\Providers;
use Modules\AiChat\Settings\AiChatSettings;
use Spatie\Permission\Models\Permission;
use Throwable;

class DatabaseSeeder extends Seeder
{
/**
* Providers offered on a fresh install, in picker order. Their models come
* from laravel/ai, so names follow the package rather than this file.
*/
public const array PROVIDERS = ['openai', 'anthropic', 'gemini'];

/**
* The chat admin's permission, granted to nobody: the app's roles seeder
* decides who gets it, and `admin` passes every check anyway. Then common
* models, once: an admin's own list is never touched.
*/
public function run(): void
{
Permission::findOrCreate('manage ai chat');

$settings = app(AiChatSettings::class);

if ($settings->models !== []) {
return;
}

$settings->models = $this->commonModels();
$settings->default_model ??= $settings->models[0]['model'] ?? null;
$settings->save();
}

/**
* Each provider's cheapest, default and smartest text model, cheapest first.
*
* @return list<array{label: string, provider: string, model: string}>
*/
protected function commonModels(): array
{
$rows = [];

foreach (self::PROVIDERS as $provider) {
$label = Providers::label($provider);

try {
$text = app(AiManager::class)->textProvider($provider);
$models = [$text->cheapestTextModel(), $text->defaultTextModel(), $text->smartestTextModel()];
} catch (Throwable) {
// A provider this laravel/ai build can't construct: leave it out.
continue;
}

foreach (array_unique($models) as $model) {
$rows[] = ['label' => "{$label} {$model}", 'provider' => $provider, 'model' => $model];
}
}

return $rows;
}
}
21 changes: 21 additions & 0 deletions database/settings/1000_00_00_000002_create_ai_chat_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Spatie\LaravelSettings\Migrations\SettingsMigration;

return new class extends SettingsMigration
{
public function up(): void
{
$defaults = [
'ai_chat.instructions' => '',
'ai_chat.models' => [],
'ai_chat.default_model' => null,
];

foreach ($defaults as $name => $value) {
if (! $this->migrator->exists($name)) {
$this->migrator->add($name, $value);
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Spatie\LaravelSettings\Migrations\SettingsMigration;

return new class extends SettingsMigration
{
public function up(): void
{
if (! $this->migrator->exists('ai_chat.api_keys')) {
$this->migrator->addEncrypted('ai_chat.api_keys', []);
}

foreach (['ai_chat.image_provider', 'ai_chat.image_model', 'ai_chat.image_quality'] as $name) {
if (! $this->migrator->exists($name)) {
$this->migrator->add($name, null);
}
}
}
};
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"name": "@saucebase/ai-chat",
"private": true,
"type": "module"
"type": "module",
"dependencies": {
"@ai-sdk/vue": "^4.0.181",
"ai": "^7.0.181",
"shiki": "^4.6.0",
"vue-stream-markdown": "^1.1.0"
}
}
8 changes: 5 additions & 3 deletions resources/boost/guidelines/core.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Ai Chat module
## AI Chat module

`modules/ai-chat` (namespace `Modules\AiChat`) — describe what this module owns in one or two sentences.
`modules/ai-chat` (namespace `Modules\AiChat`) owns the streaming AI chat at `/chat`: conversations (laravel/ai's `agent_conversations` tables), the agent and its tools, monthly plan limits, the admin settings and conversation viewer, and the page's WebMCP tools.

- List the two to four conventions an agent must never break here.
- Resolve every client-sent conversation id through `AiChatController::ownedConversation()`: laravel/ai's `continue()` checks no ownership.
- A tool acts on the user the agent was built with (`new ChatAgent($request->user())`), never on an id the model passes.
- The browser may pick only a model listed in `AiChatSettings::$models`.

Activate the `saucebase-ai-chat-development` skill before changing this module.
Loading