Files
pricebuddy/app/Services/Ai/Tools/TestCssSelectorTool.php
Jeremy 8b02abb0aa feat: AI self-healing store config
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
2026-06-09 15:07:40 +10:00

34 lines
1.0 KiB
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 TestCssSelectorTool implements Tool
{
public function __construct(protected HealingContext $context) {}
public function description(): Stringable|string
{
return 'Test a CSS selector against the fetched HTML and return the extracted value. '
.'Append |attribute_name to read an attribute instead of the element text '
.'(e.g. "meta[property=og:price:amount]|content"). Returns JSON {matched, value, error}.';
}
public function schema(JsonSchema $schema): array
{
return [
'selector' => $schema->string()->description('The CSS selector to test.')->required(),
];
}
public function handle(Request $request): Stringable|string
{
return (string) json_encode($this->context->validate('selector', (string) ($request['selector'] ?? '')));
}
}