mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Add AiConfigHealer to bootstrap or repair a store config via a tool-using structured agent (fetch/css/regex tools, HealingContext, shared StrategyExtractor). - Run healing before the one-shot enhancer; AI-bootstrap a store config when product create would otherwise fail; StoreUrl validation defers to self-healing when enabled - Per-feature AI provider resolution (AiFeature enum) and settings - Per-store self-healing opt-out plus cooldown; log heal attempts and unusable proposals - Heal with AI action with non-persisting preview/apply/discard in the store test modal; prompt switches to browser scraping when blocked
34 lines
1012 B
PHP
34 lines
1012 B
PHP
<?php
|
|
|
|
namespace App\Services\Ai\Tools;
|
|
|
|
use App\Services\Ai\HealingContext;
|
|
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
|
use Laravel\Ai\Contracts\Tool;
|
|
use Laravel\Ai\Tools\Request;
|
|
use Stringable;
|
|
|
|
class TestRegexTool implements Tool
|
|
{
|
|
public function __construct(protected HealingContext $context) {}
|
|
|
|
public function description(): Stringable|string
|
|
{
|
|
return 'Test a regex against the fetched HTML and return the extracted value. Wrap the target in a '
|
|
.'capture group (). Good for extracting values from JSON embedded in the page. '
|
|
.'Returns JSON {matched, value, error}.';
|
|
}
|
|
|
|
public function schema(JsonSchema $schema): array
|
|
{
|
|
return [
|
|
'regex' => $schema->string()->description('The regex pattern to test.')->required(),
|
|
];
|
|
}
|
|
|
|
public function handle(Request $request): Stringable|string
|
|
{
|
|
return (string) json_encode($this->context->validate('regex', (string) ($request['regex'] ?? '')));
|
|
}
|
|
}
|