Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Saucebase

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
[![Tests](https://github.com/saucebase-dev/ai-chat/actions/workflows/test.yml/badge.svg)](https://github.com/saucebase-dev/ai-chat/actions/workflows/test.yml)
[![Release](https://img.shields.io/github/v/release/saucebase-dev/ai-chat)](https://github.com/saucebase-dev/ai-chat/releases)
[![Saucebase Core](https://img.shields.io/packagist/dependency-v/saucebase/ai-chat/saucebase%2Fcore?label=Saucebase%20Core&color=FF6B35)](https://github.com/saucebase-dev/core)
[![License](https://img.shields.io/github/license/saucebase-dev/ai-chat)](LICENSE)

</div>

A streaming AI chat for Saucebase apps, at `/chat`, built on [laravel/ai](https://github.com/laravel/ai).
Laravel AI chat for Saucebase: streaming replies, conversation history, web search, image generation and plan limits, built on [laravel/ai](https://github.com/laravel/ai), on Vue or React. It opens at `/chat`.

A module for [Saucebase](https://github.com/saucebase-dev/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.

Expand All @@ -28,9 +29,7 @@ A module for [Saucebase](https://github.com/saucebase-dev/saucebase), the AI-rea

## Install

AI Chat is a private module: your app needs access to the Saucebase package registry. <!-- TODO: how to get access, as for tenancy -->

**New to Saucebase?** Start a new app first:
**New to Saucebase?** Start a new app and pick **ai-chat** when it asks for modules:

```bash
curl -fsSL https://install.saucebase.dev | bash
Expand Down Expand Up @@ -96,3 +95,7 @@ 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*"
```

## License

MIT. See [LICENSE](LICENSE).
27 changes: 25 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
{
"name": "saucebase/ai-chat",
"description": "AI chat with streaming replies, web search, image generation, account-aware tools, plan usage limits and WebMCP.",
"description": "Laravel AI chat for your SaaS: streaming replies, conversation history, web search, image generation, tools that read the user's account, monthly limits per plan and a model picker for OpenAI, Anthropic, Gemini and more. Built on laravel/ai, on Vue and React (Inertia).",
"keywords": [
"saucebase",
"saucebase-module",
"laravel",
"laravel-package",
"filament",
"inertiajs",
"vuejs",
"reactjs",
"laravel-ai",
"ai-chat",
"chatbot",
"ai-assistant",
"llm",
"openai",
"anthropic",
"gemini",
"ollama",
"image-generation",
"web-search",
"webmcp"
],
"homepage": "https://saucebase-dev.github.io/docs/",
"type": "saucebase-module",
"license": "proprietary",
"license": "MIT",
"version": "v0.2.0",
"authors": [
{
Expand Down
2 changes: 2 additions & 0 deletions resources/boost/skills/saucebase-ai-chat-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ npx playwright test modules/ai-chat/tests/e2e --project="@ai-chat*" # E2E
```

E2E specs turn test mode on per test (`laravel.config('ai-chat.test_mode', true)` in `beforeEach`, as themes does), so no key is needed in CI or locally.

They also run inside the chat template, which puts the list in the app sidebar (`sessions=sidebar`) and seeds a Free plan of 50 messages a month. A spec about the panel sets `laravel.config('ai-chat.sessions', 'page')` too; one that sends many messages makes room with `limitMessages()`, and the limits specs count from the limit it returns, not a fixed number.
10 changes: 6 additions & 4 deletions tests/Support/AiChatTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ public static function conversations(string $email, int $count): array
/**
* Subscribes the user to a plan with a monthly message limit: theirs alone, so specs
* running beside it keep no limit (a key none of a user's plans declares is unlimited).
* False without billing.
* Returns the limit the user ends up with: an app's free plan can allow more (the chat
* template's allows 50), and billing gives the user the more generous of the two. Null
* without billing.
*/
public static function limitMessages(string $email, int $limit): bool
public static function limitMessages(string $email, int $limit): ?int
{
if (! class_exists(Product::class)) {
return false;
return null;
}

$user = User::where('email', $email)->firstOrFail();
Expand All @@ -106,7 +108,7 @@ public static function limitMessages(string $email, int $limit): bool
'price_id' => $price->getKey(),
]);

return true;
return Usage::limit($user->fresh(), Usage::MESSAGES);
}

/** Turns WebMCP (beta) on or off for the whole site. Returns what it was. */
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/tests/history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ const topOf = (page: Page, text: string) =>
test.describe('Chat history', () => {
test.beforeEach(async ({ laravel, credentials, loginAs, page }) => {
await laravel.config('ai-chat.test_mode', true);
// The chat's own panel, also in an app that puts the list in its sidebar (the chat template).
await laravel.config('ai-chat.sessions', 'page');
await loginAs(credentials.user);
const id = await laravel.callFunction<string>(
`${helper}::conversation`,
[credentials.user.email, 'Long chat', 120],
);
// Room for another question: these 60 are over a free plan's monthly limit (the chat
// template's allows 50). Without billing there is no limit.
await laravel.callFunction(`${helper}::limitMessages`, [
credentials.user.email,
1000,
]);
await page.goto(`/chat/${id}`);
});

Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/tests/layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { helper, panel } from '../helpers';
test.describe('Chat layout', () => {
test.beforeEach(async ({ laravel, credentials, loginAs }) => {
await laravel.config('ai-chat.test_mode', true);
// The chat's own panel, also in an app that puts the list in its sidebar (the chat template).
await laravel.config('ai-chat.sessions', 'page');
await loginAs(credentials.user);
});

Expand Down Expand Up @@ -131,6 +133,8 @@ test.describe('Chat WebMCP', () => {

test.beforeEach(async ({ laravel, credentials, loginAs }) => {
await laravel.config('ai-chat.test_mode', true);
// The chat's own panel, also in an app that puts the list in its sidebar (the chat template).
await laravel.config('ai-chat.sessions', 'page');
await loginAs(credentials.user);
});

Expand Down
29 changes: 19 additions & 10 deletions tests/e2e/tests/limits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import { ask, helper } from '../helpers';
// The month's messages against the plan's limit, with billing: a bar above the box from 80%,
// an orange one at the limit, which stays, and Send turned off.
test.describe('Chat limits', () => {
// The user's monthly limit: 10 from their own plan, or more when the app's free plan
// allows more (the chat template's allows 50).
let limit = 0;
// Questions already asked: n questions are 2n - 1 stored messages, the last a question.
const asked = (questions: number) => 2 * questions - 1;

test.beforeEach(async ({ laravel, credentials, loginAs }) => {
// A plan of the user's own with 10 messages a month.
const limited = await laravel.callFunction<boolean>(
const limited = await laravel.callFunction<number | null>(
`${helper}::limitMessages`,
[credentials.user.email, 10],
);
test.skip(!limited, 'Billing is not installed.');
test.skip(limited === null, 'Billing is not installed.');
limit = limited ?? 0;
await laravel.config('ai-chat.test_mode', true);
// The chat's own panel, also in an app that puts the list in its sidebar (the chat template).
await laravel.config('ai-chat.sessions', 'page');
await loginAs(credentials.user);
});

Expand All @@ -20,20 +28,21 @@ test.describe('Chat limits', () => {
laravel,
credentials,
}) => {
// 7 questions this month.
// One question short of 80%, which the bar shows from.
const shown = Math.ceil(limit * 0.8);
await laravel.callFunction(`${helper}::conversation`, [
credentials.user.email,
'Earlier',
13,
asked(shown - 1),
]);
await page.goto('/chat');
await expect(page.getByTestId('chat-input')).toBeVisible();
await expect(page.getByTestId('chat-usage')).toHaveCount(0);

await ask(page, 'The eighth');
await ask(page, 'One more');

const bar = page.getByTestId('chat-usage');
await expect(bar).toContainText('8 of 10');
await expect(bar).toContainText(`${shown} of ${limit}`);
await expect(bar.getByTestId('chat-upgrade')).toBeVisible();

await bar.getByRole('button', { name: 'Dismiss' }).click();
Expand All @@ -49,16 +58,16 @@ test.describe('Chat limits', () => {
laravel,
credentials,
}) => {
// 10 questions this month.
// Every question of the month.
await laravel.callFunction(`${helper}::conversation`, [
credentials.user.email,
'Earlier',
19,
asked(limit),
]);
await page.goto('/chat');

const bar = page.getByTestId('chat-usage');
await expect(bar).toContainText('all 10');
await expect(bar).toContainText(`all ${limit}`);
await expect(bar.getByRole('button', { name: 'Dismiss' })).toHaveCount(
0,
);
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/tests/sessions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ask, chatMenu, helper, panel } from '../helpers';
test.describe('Chat list', () => {
test.beforeEach(async ({ laravel, credentials, loginAs }) => {
await laravel.config('ai-chat.test_mode', true);
// The chat's own panel, also in an app that puts the list in its sidebar (the chat template).
await laravel.config('ai-chat.sessions', 'page');
await loginAs(credentials.user);
});

Expand Down