PHP code example of vinkius-labs / laravel-vurb

1. Go to this page and download the library: Download vinkius-labs/laravel-vurb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vinkius-labs / laravel-vurb example snippets


// app/Vurb/Presenters/PatientPresenter.php — generated by your AI agent
class PatientPresenter extends VurbPresenter
{
    public function toArray($request): array
    {
        return [
            'id'        => $this->id,
            'name'      => $this->name,
            'status'    => $this->status,
            'physician' => $this->attending_physician,
        ];
        // ssn, diagnosis, internal_notes — physically absent from response
    }

    public function systemRules(): array
    {
        return [
            'HIPAA: diagnosis visible in UI blocks but NEVER in conversation text.',
            'Always confirm physician identity before discharge actions.',
        ];
    }

    public function suggestActions(): array
    {
        if ($this->status === 'cleared') {
            return [['tool' => 'patients.discharge', 'reason' => 'Physician has signed off']];
        }
        return [['tool' => 'patients.sign_off', 'reason' => 'Awaiting physician sign-off']];
    }
}

// app/Vurb/Tools/Patients/DischargePatient.php — generated by your AI agent

#[Description('Discharge a patient after physician sign-off')]
#[Instructions('NEVER call without verifying physician sign-off. Always confirm patient identity.')]
#[Presenter(PatientPresenter::class)]
#[FsmBind(states: ['cleared'], event: 'DISCHARGE')]
class DischargePatient extends VurbTool
{
    public function verb(): string { return 'mutation'; }

    public function handle(
        #[Param(description: 'Patient ID', example: 'PAT-001')]
        string $id,
    ): Patient {
        $patient = Patient::findOrFail($id);
        $patient->update(['status' => 'discharged', 'discharged_at' => now()]);
        return $patient;
    }
}

// app/Vurb/Tools/GetCustomerProfile.php

namespace App\Vurb\Tools;

use Vinkius\Vurb\Attributes\Param;
use Vinkius\Vurb\Tools\VurbTool;

class GetCustomerProfile extends VurbTool
{
    public function description(): string
    {
        return 'Retrieve a customer profile by ID.';
    }

    public function verb(): string
    {
        return 'query';
    }

    public function handle(
        #[Param(description: 'The customer ID', example: 42)]
        int $id,
    ): array {
        $customer = \App\Models\Customer::findOrFail($id);

        return $customer->only(['id', 'name', 'plan', 'created_at']);
    }
}

use Vinkius\Vurb\Tools\VurbTool;

class ListOrders extends VurbTool
{
    public function description(): string
    {
        return 'List recent orders for a customer.';
    }

    public function handle(int $customer_id, int $limit = 10): array
    {
        return Order::where('customer_id', $customer_id)
            ->latest()
            ->limit($limit)
            ->get()
            ->toArray();
    }
}

public function verb(): string
{
    return 'query';     // read-only, idempotent, cacheable
    return 'mutation';  // writes data, destructive, invalidates cache
    return 'action';    // side-effect (email, webhook), idempotent
}

use Vinkius\Vurb\Attributes\{Tool, Param, Description, Instructions, Tags, Presenter, Cached, Invalidates, FsmBind, Concurrency};

#[Description('Deep search across all customer records')]
#[Instructions('Only call when the user explicitly asks for a customer lookup. Never infer customer IDs.')]
#[Tags('crm', 'search')]
#[Cached(ttl: 120)]
#[Concurrency(max: 3)]
class SearchCustomers extends VurbTool
{
    public function description(): string
    {
        return 'Search customers by name or email.';
    }

    public function verb(): string
    {
        return 'query';
    }

    public function handle(
        #[Param(description: 'Search query — name, email, or phone', example: '[email protected]')]
        string $query,

        #[Param(description: 'Max results to return')]
        int $limit = 20,
    ): array {
        return Customer::search($query)->take($limit)->get()->toArray();
    }
}

public function handle(
    int $id,
    \App\Services\CrmGateway $crm,        // ← injected by container
    \Illuminate\Cache\Repository $cache,   // ← injected by container
): array {
    return $cache->remember("customer.{$id}", 60, fn () => $crm->find($id));
}

// app/Vurb/Presenters/CustomerPresenter.php

namespace App\Vurb\Presenters;

use Vinkius\Vurb\Presenters\VurbPresenter;

class CustomerPresenter extends VurbPresenter
{
    public function toArray($request): array
    {
        // Only these fields reach the LLM — email is stripped
        return [
            'id'   => $this->id,
            'name' => $this->name,
            'plan' => $this->plan,
        ];
    }

    public function systemRules(): array
    {
        return [
            'Never reveal the customer email address.',
            'Always use the customer name in responses.',
            'For billing questions, suggest the billing.get_invoice tool.',
        ];
    }

    public function uiBlocks(): array
    {
        return [
            ['type' => 'summary', 'title' => $this->name, 'subtitle' => "Plan: {$this->plan}"],
        ];
    }

    public function suggestActions(): array
    {
        return [
            ['tool' => 'customers.update', 'reason' => 'Edit customer details'],
            ['tool' => 'billing.get_invoice', 'reason' => 'View billing history'],
        ];
    }
}

use Vinkius\Vurb\Attributes\Presenter;

#[Presenter(CustomerPresenter::class)]
class GetCustomerProfile extends VurbTool
{
    // handle() returns the Customer model
    // Presenter filters, enriches, and governs the response
}

// app/Vurb/Tools/Crm/Router.php

namespace App\Vurb\Tools\Crm;

use Vinkius\Vurb\Tools\VurbRouter;

class Router extends VurbRouter
{
    public string $prefix = 'crm';
    public string $description = 'CRM operations — leads, contacts, deals';
    public array $middleware = [
        \App\Vurb\Middleware\RequireCrmAccess::class,
    ];
}

use Vinkius\Vurb\Middleware\VurbMiddleware;

class AuditTrail implements VurbMiddleware
{
    public function handle(array $context, \Closure $next): mixed
    {
        $start = hrtime(true);
        $result = $next($context);
        $latency = (hrtime(true) - $start) / 1e6;

        logger()->channel('audit')->info('Tool executed', [
            'tool'    => $context['tool'],
            'user_id' => $context['user']?->id,
            'latency' => round($latency, 2),
        ]);

        return $result;
    }
}

// app/Models/Customer.php

use Vinkius\Vurb\Models\HasVurbSchema;

class Customer extends Model
{
    use HasVurbSchema;

    protected $hidden = ['password', 'remember_token'];

    protected $casts = [
        'plan' => PlanEnum::class,
        'email_verified_at' => 'datetime',
    ];

    public array $vurbDescriptions = [
        'name' => 'Full legal name of the customer',
        'plan' => 'Subscription tier: free, pro, or enterprise',
    ];
}

// config/vurb.php
'fsm' => [
    'id'      => 'order_flow',
    'initial' => 'draft',
    'store'   => 'cache',
    'states'  => [
        'draft'      => ['on' => ['CONFIRM' => 'confirmed']],
        'confirmed'  => ['on' => ['PAY' => 'paid', 'CANCEL' => 'cancelled']],
        'paid'       => ['on' => ['SHIP' => 'shipped']],
        'shipped'    => ['on' => ['DELIVER' => 'delivered']],
        'delivered'  => [],
        'cancelled'  => [],
    ],
],

use Vinkius\Vurb\Attributes\FsmBind;

#[FsmBind(states: ['confirmed'], event: 'PAY')]
class ProcessPayment extends VurbTool
{
    // Only visible when order_flow is in 'confirmed' state
    // Triggers PAY event on execution → transitions to 'paid'
}

// config/vurb.php
'dlp' => [
    'enabled'  => true,
    'strategy' => 'mask',       // 'mask', 'remove', or 'hash'
    'patterns' => [
        '/\b\d{3}-\d{2}-\d{4}\b/' => 'SSN',          // Social Security Number
        '/\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/' => 'credit_card',
        '/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z]{2,}\b/i' => 'email',
    ],
],

// config/vurb.php
'introspection' => [
    'enabled' => true,
    'filter'  => function (array $manifest, array $context) {
        $role = $context['role'] ?? 'viewer';

        if ($role !== 'admin') {
            unset($manifest['tools']['billing']);
        }

        return $manifest;
    },
],

use Vinkius\Vurb\Testing\FakeVurbTester;

class CustomerToolTest extends TestCase
{
    public function test_get_customer_returns_profile_without_email(): void
    {
        $result = FakeVurbTester::for(GetCustomerProfile::class)
            ->call(['id' => 42]);

        $result
            ->assertSuccessful()
            ->assertDataHasKey('name')
            ->assertDataHasKey('plan')
            ->assertDataMissingKey('email')           // egress firewall test
            ->assertDataEquals('name', 'Jane Doe')
            ->assertHasSystemRule('Never reveal the customer email address.')
            ->assertHasUiBlock('summary')
            ->assertHasSuggestedAction('customers.update');
    }

    public function test_tool_

use Vinkius\Vurb\Facades\Vurb;

Vurb::discover();           // All discovered tools
Vurb::compileManifest();    // Compiled manifest array
Vurb::isHealthy();          // Health check
Vurb::discovery();          // ToolDiscovery instance
Vurb::compiler();           // ManifestCompiler instance
Vurb::daemon();             // DaemonManager instance
Vurb::presenters();         // PresenterRegistry instance
Vurb::models();             // ModelRegistry instance
bash
php artisan vendor:publish --tag=vurb-llms      # llms.txt → project root
php artisan vendor:publish --tag=vurb-skills     # SKILL.md → .claude/skills/
bash
php artisan vurb:make-tool GetCustomerProfile --query
bash
php artisan vurb:serve

app/Vurb/Tools/
├── Crm/
│   ├── Router.php           ← namespace + middleware for all CRM tools
│   ├── GetLead.php
│   ├── UpdateLead.php
│   └── ListLeads.php
├── Billing/
│   ├── Router.php
│   ├── GetInvoice.php
│   └── ProcessRefund.php
└── GetCustomerProfile.php   ← top-level (auto-inferred namespace)
bash
php artisan vurb:lock