pixelworxio/filament-ai-action
Composer 安装命令:
composer require pixelworxio/filament-ai-action
包简介
AI-powered actions for Filament v5 — streaming modal, structured output, intelligent table actions
README 文档
README
AI-powered actions for Filament v5 — streaming modal, structured output, and intelligent table actions.
Requirements
- PHP ^8.4
- Laravel ^12.0
- Filament ^5.0
- pixelworxio/laravel-ai-action ^1.0
Installation
composer require pixelworxio/filament-ai-action
Then register the plugin in your panel provider:
use Pixelworxio\FilamentAiAction\FilamentAiActionPlugin; ->plugins([ FilamentAiActionPlugin::make(), ])
AiAction
AiAction extends Filament\Actions\Action and exposes seven fluent configuration methods.
agent()
Set the agent class to run:
use Pixelworxio\FilamentAiAction\AiAction; AiAction::make() ->agent(SummaryAgent::class)
stream()
Enable incremental text rendering in the modal:
AiAction::make() ->agent(SummaryAgent::class) ->stream()
withUserInstruction()
Show a free-text input in the modal before running the agent. The instruction is attached to the AgentContext as metadata:
AiAction::make() ->agent(SummaryAgent::class) ->withUserInstruction('What would you like to know about this record?')
persistResultTo()
Write the agent result to an Eloquent model column after successful execution. Structured results are JSON-encoded automatically:
AiAction::make() ->agent(SummaryAgent::class) ->persistResultTo('ai_summary')
queued()
Dispatch the agent as a background job instead of running inline. Accepts an optional queue name:
AiAction::make() ->agent(SummaryAgent::class) ->queued('high')
usingProvider()
Override the AI provider and model for this action only, ignoring the package-level defaults:
AiAction::make() ->agent(SummaryAgent::class) ->usingProvider('openai', 'gpt-4o')
withContext()
Enrich the AgentContext before the agent runs. The callback receives the built context and the Eloquent record:
use Pixelworxio\LaravelAiAction\DTOs\AgentContext; AiAction::make() ->agent(SummaryAgent::class) ->withContext(function (AgentContext $ctx, Model $record): AgentContext { return $ctx->withMeta('tenant_id', $record->tenant_id); })
AiBulkAction
AiBulkAction extends Filament\Tables\Actions\BulkAction and uses the same fluent API. When queued, one RunAgentActionJob is dispatched per selected record.
use Pixelworxio\FilamentAiAction\AiBulkAction; AiBulkAction::make() ->agent(SummaryAgent::class) ->persistResultTo('ai_summary') ->queued() ->deselectRecordsAfterCompletion()
AgentResultEntry
Render a persisted AI result inside a Filament infolist. Automatically detects whether the stored value is JSON (structured) or plain text:
use Pixelworxio\FilamentAiAction\Infolists\AgentResultEntry; AgentResultEntry::make('ai_summary') ->label('AI Summary') ->markdown() ->withRefreshAction()
->markdown()— passes the stored value throughStr::markdown()before rendering.->withRefreshAction()— embeds anAiActionbutton below the result to re-run and re-persist.
AiActionWidget
Embed an AI agent result directly on a Filament dashboard panel without a modal:
use Pixelworxio\FilamentAiAction\Widgets\AiActionWidget; // In your panel provider's getWidgets(): protected function getWidgets(): array { return [ AiActionWidget::agent(DashboardInsightAgent::class) ->contextBuilder(fn (): AgentContext => AgentContext::fromRecords( Post::latest()->limit(10)->get()->all() )), ]; }
The widget respects Filament's $columnSpan property and renders inline using the same streaming-text or structured-output components.
Streaming
When ->stream() is enabled on AiAction, the AgentResponseModal Livewire component pushes response text to the browser in chunks using Livewire v4's stream() helper. A blinking cursor is shown while the response is incomplete. Use streaming for long responses where you want to show the user progress rather than waiting for a final result.
AiAction::make() ->agent(LongFormWriterAgent::class) ->stream()
Structured Output
When an agent implements HasStructuredOutput from pixelworxio/laravel-ai-action, the modal and infolist entry render the result as a formatted definition list rather than plain text. Keys are converted from snake_case to Title Case. Array values are rendered as bulleted lists; integers and strings are rendered inline.
To store a structured result, use ->persistResultTo() — the value is JSON-encoded automatically. AgentResultEntry detects the JSON string and renders the structured view.
Testing
Use FakeAgentAction from the core package to test Filament actions without making real AI provider calls:
use Pixelworxio\LaravelAiAction\Testing\FakeAgentAction; beforeEach(fn () => FakeAgentAction::reset()); it('persists the agent result to the model column', function (): void { FakeAgentAction::fakeResponse(SummaryAgent::class, 'This is the summary.'); $record = Post::factory()->create(); $action = AiAction::make('ai') ->agent(SummaryAgent::class) ->persistResultTo('ai_summary'); $action->record($record); $reflection = new ReflectionMethod($action, 'runAgent'); $reflection->setAccessible(true); $reflection->invoke($action); expect($record->fresh()->ai_summary)->toBe('This is the summary.'); FakeAgentAction::assertAgentCalled(SummaryAgent::class, 1); });
Config Reference
Publish the config file:
php artisan vendor:publish --tag=filament-ai-action-config
| Key | Env Variable | Default | Description |
|---|---|---|---|
default_label |
FILAMENT_AI_ACTION_LABEL |
'Ask AI' |
Default button label for AiAction and AiBulkAction |
show_usage |
FILAMENT_AI_ACTION_SHOW_USAGE |
false |
Show input/output token counts in the modal footer |
modal_size |
FILAMENT_AI_ACTION_MODAL_SIZE |
'xl' |
Filament modal width (sm, md, lg, xl, 2xl, etc.) |
allow_copy |
FILAMENT_AI_ACTION_ALLOW_COPY |
true |
Show a copy-to-clipboard button when the response is complete |
Publishing Assets
Publish the config file:
php artisan vendor:publish --tag=filament-ai-action-config
Publish the Blade views to customise the modal and components:
php artisan vendor:publish --tag=filament-ai-action-views
pixelworxio/filament-ai-action 适用场景与选型建议
pixelworxio/filament-ai-action 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 137 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「modal」 「actions」 「ai」 「filament」 「structured output」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pixelworxio/filament-ai-action 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pixelworxio/filament-ai-action 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pixelworxio/filament-ai-action 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.
Fork from ghosh/Micromodal. Tiny, dependency-free javascript library for creating accessible modal dialogs.
Make Filament modals draggable.
A Filament form component that displays repeater items in a table with modal-based editing.
A Laravel Nova field. To create a modal for creating or viewing related HasMany records without leaving the index page
A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.
统计信息
- 总下载量: 137
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-23