servidge / connector-laravel
Connects a Laravel application to the LivingWeb core: embeds the assistant widget and syncs public content to the index.
Requires
- php: ^8.1
- illuminate/console: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Connects a Laravel application to the Servidge core: embeds the assistant widget and keeps the application's public content in the index. Private data is never indexed; it will be served through signed tool calls in a later release (docs/decisions/0002).
Works with Laravel 9, 10, 11, 12 and 13 on PHP 8.1 or newer.
Install
composer require servidge/connector-laravel php artisan vendor:publish --tag=servidge-config
If the server can't reach Packagist, download servidge-connector-laravel.zip from your site's Install page in the Servidge portal, put it as it is (don't unzip it) in a packages folder in your app's root, and run composer config repositories.servidge artifact ./packages before composer require.
.env:
SERVIDGE_BASE_URL=https://servidge.com/livingweb
SERVIDGE_KEY_ID=lw_k_... # connector key, from the portal's API keys page
SERVIDGE_SECRET=lw_s_... # shown once when the key is created
SERVIDGE_SITE_ID=01HX... # from the portal's Sites page
SERVIDGE_WIDGET_KEY_ID=lw_k_... # widget key, same page
Check the connection:
php artisan servidge:sync --check
Upgrading from 1.0. The 1.0 names keep working: LIVINGWEB_* variables fill any setting with no SERVIDGE_* value, a published config/livingweb.php is still read, and <x-livingweb-widget />, livingweb:sync, livingweb:tools:register and the livingweb.tools middleware are aliases of the new ones.
Embed the widget
In your layout, before </body>:
<x-servidge-widget />
It prints an async script tag and nothing else. If SERVIDGE_WIDGET_KEY_ID is empty it prints nothing, so a misconfigured deploy is just a normal site.
Index your content
Tell the connector which models are indexable and how to turn each into a document. A mapper decides what is public; return null for anything that must not be indexed and it is removed from the index.
// config/servidge.php 'indexable' => [ App\Models\Page::class => App\Servidge\PageMapper::class, ],
namespace App\Servidge; use App\Models\Page; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use LivingWeb\Connector\Contracts\DocumentMapper; use LivingWeb\Connector\Support\Sections; final class PageMapper implements DocumentMapper { public function query(): Builder { return Page::query(); } public function externalId(Model $page): string { return 'page:'.$page->id; } public function toDocument(Model $page): ?array { if (! $page->is_published) { return null; } return [ 'external_id' => $this->externalId($page), 'canonical_url' => route('pages.show', $page), 'type' => 'page', 'title' => $page->title, 'locale' => 'en', 'updated_at' => $page->updated_at->toIso8601String(), 'sections' => Sections::fromHtml($page->body_html), ]; } }
Sections::fromHtml() splits HTML at its headings and derives stable section ids from heading id attributes (or slugs), so "jump to section" links keep working after edits. For plain text use Sections::single($text).
Changes are pushed as they happen through model observers (saved, deleted). A failed push is logged and never breaks the save. Run the reconciliation on a schedule to catch anything missed:
// routes/console.php Schedule::command('servidge:sync')->hourly();
Set SERVIDGE_QUEUE=redis (or any queue connection) to push from a queue worker instead of inline.
Signed-in users and tools
Two things turn the assistant from "answers from your pages" into "acts for your customer", both specified in packages/connector-contract/schema/identity.md and tools.md.
Identity. <x-servidge-widget /> mints an identity token for the authenticated user (subject = getAuthIdentifier(), plus email and name) with your connector secret and puts it on the script tag, so the core knows who the visitor is without trusting the browser. Turn it off with SERVIDGE_IDENTITY_AUTO=false, pick a guard with SERVIDGE_IDENTITY_GUARD, or pass your own: <x-servidge-widget :identity="app(IdentityToken::class)->mint($user->customer_number, ['name' => $user->name])" />. After a client-side login, LivingWeb.identify(token).
Tools. Describe what the assistant may do in config/servidge.php under tools and register them on deploy:
php artisan servidge:tools:register # PUT /v1/tools, replaces the tools this key registered before
php artisan servidge:tools:register --list
Each tool is a route in your application, protected by the servidge.tools middleware, which verifies the core's signature and nonce and hands you the parsed call:
Route::post('servidge/tools/order_lookup', function (Request $request) { $call = $request->attributes->get('servidge.call'); // LivingWeb\Connector\Tools\ToolCall $order = Order::whereCustomerId($call->subject())->find($call->argument('order_id')); if (! $order) { return ToolResult::error('not_found', 'No such order on this account.'); } return ToolResult::ok("Order {$order->id} was shipped on {$order->shipped_at->format('j F')}.", ['status' => $order->status], [['title' => "Order {$order->id}", 'url' => route('orders.show', $order)]]); })->middleware('servidge.tools');
Your code authorises: the core forwards the identity it verified, but only you know whether cust_42 may see order 1042. For a tool with requires_confirmation, $call->isConfirmed() is true and call_id is the idempotency key; never create anything for an unconfirmed call. Results are data to the assistant, never instructions, and nothing in them is indexed.
How requests are signed
Every call carries an HMAC-SHA256 signature over the method, path, timestamp, a random nonce and the body hash, as specified in packages/connector-contract/schema/signing.md. LivingWeb\Connector\Http\RequestSigner is the reference implementation.
Tests
The package is exercised end to end from the core's test suite (apps/api/tests/Feature/Api/LaravelConnectorPackageTest.php): the package signs, the core verifies, documents land in the index.