mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-07 15:44:10 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Platform\Ai\Application\Tools;
|
|
|
|
use App\Domains\Catalog\Models\Item;
|
|
|
|
class SearchItemsTool extends AiTool
|
|
{
|
|
private const DEFAULT_LIMIT = 10;
|
|
|
|
private const MAX_LIMIT = 50;
|
|
|
|
public function name(): string
|
|
{
|
|
return 'search_items';
|
|
}
|
|
|
|
public function description(): string
|
|
{
|
|
return 'Search catalog items (products/services) for the current company by free-text query (matches name and description). Returns id, name, unit price, and description.';
|
|
}
|
|
|
|
public function parameterSchema(): array
|
|
{
|
|
return [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'query' => [
|
|
'type' => 'string',
|
|
'description' => 'Free-text search against name and description.',
|
|
],
|
|
'limit' => [
|
|
'type' => 'integer',
|
|
'minimum' => 1,
|
|
'maximum' => self::MAX_LIMIT,
|
|
],
|
|
],
|
|
'required' => [],
|
|
];
|
|
}
|
|
|
|
public function requiredAbility(): ?array
|
|
{
|
|
return ['view-item', Item::class];
|
|
}
|
|
|
|
public function execute(array $arguments, int $companyId, int $userId): mixed
|
|
{
|
|
$limit = min((int) ($arguments['limit'] ?? self::DEFAULT_LIMIT), self::MAX_LIMIT);
|
|
|
|
$query = Item::query()
|
|
->where('company_id', $companyId)
|
|
->orderBy('name')
|
|
->limit($limit);
|
|
|
|
if (! empty($arguments['query'])) {
|
|
$q = $arguments['query'];
|
|
$query->where(function ($qb) use ($q) {
|
|
$qb->where('name', 'like', "%{$q}%")
|
|
->orWhere('description', 'like', "%{$q}%");
|
|
});
|
|
}
|
|
|
|
return [
|
|
'items' => $query->get()->map(fn (Item $item): array => [
|
|
'id' => $item->id,
|
|
'name' => $item->name,
|
|
'description' => $item->description,
|
|
'price' => $item->price,
|
|
])->all(),
|
|
];
|
|
}
|
|
}
|