PHP code example of promptphp / intercept-support

1. Go to this page and download the library: Download promptphp/intercept-support 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/ */

    

promptphp / intercept-support example snippets




declare(strict_types=1);

return [
    'middleware' => [
        'injection_guard' => [
            'action'             => 'block',
            'patterns'           => [],
            'merge_patterns'     => true,
            'normalise_prompt'   => true,
            'log_prompt_preview' => false,
        ],
    ],
];

use PromptPHP\Intercept\Support\InterceptConfig;

$config = InterceptConfig::middleware('injection_guard', [
    'action'             => 'block',
    'patterns'           => [],
    'merge_patterns'     => true,
    'normalise_prompt'   => true,
    'log_prompt_preview' => false,
]);

use Laravel\Ai\PendingStep;
use Laravel\Ai\Prompts\AgentPrompt;
use PromptPHP\Intercept\Support\Concerns\ScansApprovalDecisions;
use PromptPHP\Intercept\Support\Contracts\InspectsApprovalDecisions;

class ExampleMiddleware implements InspectsApprovalDecisions
{
    use ScansApprovalDecisions;

    public function handle(PendingStep $step, Closure $next): mixed
    {
        return $next($step);
    }

    public function inspectApprovalDecisions(AgentPrompt $prompt): void
    {
        foreach ($this->approvalDecisionSegments($prompt->approvalDecisions) as $segment) {
            // $segment->toolCallId, $segment->field, $segment->text
        }
    }
}

foreach ($this->pendingApprovalSegments($response->pendingApprovals) as $segment) {
    // $segment->toolCallId is the pending approval ID
}

PromptPHP\Intercept\Support\InterceptServiceProvider::class

$config = InterceptConfig::middleware(
    'pii_redactor',
    PIIRedactorDefaults::values(),
);
text
config/intercept.php
bash
php artisan vendor:publish --tag=intercept-config