Zum Inhalt springen

HOST

Laravel

Das Paket wrappt php-sdk, mintet Sanctum-MCP-Tokens, StartSidecarSessionController.

Laravel

Das Paket wrappt php-sdk, mintet Sanctum-MCP-Tokens, StartSidecarSessionController.

sveda-ai/laravel-sdk, SVEDA_CLIENT_BASE_URL, POST /sveda/session, Chat aus Blade.

AGENT PROMPT

Paste into Cursor

Copy this into Cursor, Claude Code, or any coding agent. It installs Sveda against this stack using public packages.

Install Sveda into this Laravel app.

Read:
- https://sveda.dev/docs/hosts/laravel
- https://sveda.dev/docs/client
- https://sveda.dev/docs/deploy
- https://sveda.dev/llms.txt

Follow the numbered steps on the Laravel page. If unsure which frontend this repo uses (Vue, Blade, or something else), ask the user.

1. Run sveda-server

Sidecar beside Laravel, not inside php artisan serve. Pull ghcr.io/neresson/sveda-server:latest with Postgres and Redis. CORS origin is the Laravel URL.

# ghcr.io/neresson/sveda-server:latest
# curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.yaml -o compose.yaml && curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.env -o .env && # Edit .env: a model key, SVEDA_EMBED_HOST_API_KEY, SVEDA_CORS_ORIGINS &&  && docker compose up -d && curl -s http://127.0.0.1:8787/sveda/ready

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: sveda
      POSTGRES_PASSWORD: sveda
      POSTGRES_DB: sveda
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U sveda -d sveda"]
      interval: 5s
      timeout: 3s
      retries: 10
    volumes:
      - sveda-postgres:/var/lib/postgresql/data
  redis:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 10
  sveda-server:
    image: ghcr.io/neresson/sveda-server:latest
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    ports:
      - "8787:8787"
    environment:
      SVEDA_BIND: 0.0.0.0:8787
      SVEDA_EMBED_ENABLED: "true"
      SVEDA_DATABASE_URL: postgres://sveda:sveda@postgres:5432/sveda
      SVEDA_REDIS_URL: redis://redis:6379
      SVEDA_APP_KEY: ${SVEDA_APP_KEY:-dev-app-key-change-me}
      SVEDA_ADMIN_API_KEY: ${SVEDA_ADMIN_API_KEY:-dev-admin-key-change-me}
      SVEDA_EMBED_HOST_API_KEY: ${SVEDA_EMBED_HOST_API_KEY:-dev-host-key-change-me}
      SVEDA_CORS_ORIGINS: ${SVEDA_CORS_ORIGINS:-*}
      DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY:-}
volumes:
  sveda-postgres:

2. Install the Laravel package

sveda-ai/php-sdk comes in transitively. Publish config if you need to change MCP path or timeouts.

composer require sveda-ai/laravel-sdk
php artisan vendor:publish --tag=sveda-client-config

3. Env

Keys in .env map to config/sveda-client.php. Optional SVEDA_CLIENT_MCP_URL if the sidecar should call your /mcp/sveda server.

SVEDA_CLIENT_BASE_URL=http://127.0.0.1:8787
SVEDA_CLIENT_HOST_API_KEY=replace-me

4. Register POST /sveda/session

The package does not auto-register the route. Put it behind auth (or Sanctum). Unauthenticated → 401. Missing sidecar env → 404 from HostManager.

use Sveda\LaravelClient\Http\Controllers\StartSidecarSessionController;

Route::post('/sveda/session', StartSidecarSessionController::class)
    ->middleware('auth')
    ->name('sveda.session');
use Sveda\LaravelClient\Facades\SvedaClient;

$session = SvedaClient::host()->startSession($request->user());
// origin, token, expires_in, appearance

5. Open the chat

Two options. Host buttons plus sveda-host.js (JS and iframe, same as PHP). Or the Blade component, which mounts <sveda-chat session="/sveda/session"> when the base URL is set.

<html
  lang="en"
  data-sveda-origin="http://127.0.0.1:8787"
  data-sveda-session="/sveda/session"
>
  <body>
    <button type="button" data-sveda-open="js">Open JS chat</button>
    <button type="button" data-sveda-open="iframe">Open iframe chat</button>
    <script type="module" src="/sveda-host.js"></script>
  </body>
</html>
<x-sveda::chat session="/sveda/session" />

6. Optional host MCP tools

The package registers /mcp/sveda when Laravel MCP is installed. Map Spatie (or any) roles to a named policy with policyUsing; resolveToolsUsing narrows what the host lists. Runtime enforcement still follows the token policy. See embed policies.

use Sveda\LaravelClient\Facades\SvedaClient;

SvedaClient::host()->policyUsing(fn ($user) => $user->hasRole('agent') ? 'agent' : 'reader');

SvedaClient::host()->resolveToolsUsing(fn ($user) => $user->hasRole('agent')
    ? [new SearchOrdersTool, new CreateOrderTool]
    : [new SearchOrdersTool]);

SvedaClient::host()->authorizeUsing(fn ($user) => $user->can('use-ai'));

Mint from the host.

Install the language SDK. Expose POST /sveda/session. Open JS chat or an iframe.

Host SDKs