Skip to content

Commit 202d7e4

Browse files
committed
Final tweaks for pagination data
1 parent 16e5c40 commit 202d7e4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/DescribeFilamentResourceTool.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function build(): PrismTool
3838
{
3939
return app(PrismTool::class)
4040
->as($this->getName())
41-
->for('Describes the structure, fields, columns, actions, and relationships for a given Filament resource. Always call the list_filament_resources tool before calling this tool.')
41+
->for('Describes the structure, fields, columns, actions, and relationships for a given Filament resource. Must call the list_filament_resources tool before calling this tool.')
4242
->withStringParameter('resource', 'The class name of the resource to describe.', required: true)
4343
->using(function (string $resource) {
4444
return json_encode($this->describe($resource));
@@ -180,10 +180,15 @@ public function makeFilamentTranslatableContentDriver(): ?TranslatableContentDri
180180

181181
return [
182182
'columns' => $columns,
183-
'filters' => array_values($filters), // Re-index the array
183+
'filters' => array_values($filters),
184184
'actions' => [
185185
'bulk' => $bulkActions,
186186
],
187+
'pagination' => [
188+
'total' => 'Total number of records (int)',
189+
'per_page' => 'Number of records per page (int)',
190+
'current_page' => 'Current page number (int)',
191+
],
187192
];
188193
} catch (Exception $e) {
189194
Log::error("Error extracting table schema for resource {$resource}: {$e->getMessage()}");
@@ -212,8 +217,7 @@ public function mapFilterType(BaseFilter $filter): string
212217
return match (true) {
213218
$filter instanceof TernaryFilter => 'boolean',
214219
$filter instanceof SelectFilter => 'select',
215-
// Add more mappings as needed
216-
default => class_basename($filter), // Fallback to class name
220+
default => class_basename($filter),
217221
};
218222
}
219223

src/GetFilamentResourceDataTool.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public function build(): PrismTool
2727
{
2828
return app(PrismTool::class)
2929
->as($this->getName())
30-
->for('Gets the data for a given Filament resource, applying optional filters (try to use them). Always call the describe_filament_resource tool before calling this tool. Always try to use the available filters to get the data you need.')
30+
->for('Retrieves paginated data from a Filament resource with optional filtering. Response includes page count and total record count. Must call describe_filament_resource first to understand available filters and structure. Use filters to narrow results when possible for better performance.')
3131
->withStringParameter('resource', 'The resource class name of the resource to get data for, from the list_filament_resources tool.')
3232
->withStringParameter('filters', 'JSON string of filters to apply (e.g., \'{"status": "published", "author_id": [1, 2]}\').', required: false)
33-
->withNumberParameter('perPage', 'The resource data is paginated. This is the number of records per page. It defaults to 10', required: false)
33+
->withNumberParameter('perPage', 'The resource data is paginated. This is the number of records per page. It defaults to 10. Maximum is 100.', required: false)
3434
->withNumberParameter('page', 'The resource data is paginated. This is the page the paginated results should be from.', required: false)
3535
->using(function (string $resource, ?string $filters = null, ?int $perPage = 10, ?int $page = null) {
3636
$resource = $this->getResourceInstance($resource);
@@ -72,6 +72,7 @@ public function build(): PrismTool
7272
}
7373
}
7474

75+
$perPage = $perPage > 100 ? 100 : $perPage;
7576
$results = $listPage->getFilteredTableQuery()->paginate(perPage: $perPage, page: $page);
7677

7778
$outputData = [

0 commit comments

Comments
 (0)