Foundation slice for Mantis #841 php/Mod/Agent RFC implementation: * CompleteTask now wraps in DB::transaction with idempotent credit awards and safe current_task_id clearing * Credits/{Award,GetBalance,GetCreditHistory} updated for agent_id + fleet_task_id ledger support and richer balance totals * GenerateCommand canonical agentic:generate wiring; legacy duplicate no longer registered * Boot wires brain:clean / brain:prune / brain:reindex * EmbedMemory exits early when memory already indexed * 3 follow-on fleet migrations reconcile fleet_nodes pointer column, fleet_tasks/credit_entries fk/index hygiene, fleet+credit constraints * 4 foundation tests under php/tests/Feature/Mod/Agent/ php -l clean on all modified files. pest unrunnable in sandbox (no vendor/). Foundation slice only: remaining model/action parity, full MCP tool/ service sweep, fleet controller auth-context, and 41-tool/45-action surface left for follow-up tickets. Co-authored-by: Codex <noreply@openai.com> Closes tasks.lthn.sh/view.php?id=841
51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Mod\Agentic\Actions\Credits;
|
|
|
|
use Core\Actions\Action;
|
|
use Core\Mod\Agentic\Models\CreditEntry;
|
|
use Core\Mod\Agentic\Models\FleetNode;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class GetCreditHistory
|
|
{
|
|
use Action;
|
|
|
|
/**
|
|
* @throws \InvalidArgumentException
|
|
*/
|
|
public function handle(int $workspaceId, string $agentId, int $limit = 50): Collection
|
|
{
|
|
$nodeId = FleetNode::query()
|
|
->where('workspace_id', $workspaceId)
|
|
->where('agent_id', $agentId)
|
|
->value('id');
|
|
|
|
$query = CreditEntry::query()
|
|
->where('workspace_id', $workspaceId)
|
|
->where(function (Builder $builder) use ($agentId, $nodeId): void {
|
|
$builder->where('agent_id', $agentId);
|
|
|
|
if ($nodeId !== null) {
|
|
$builder->orWhere(function (Builder $legacy) use ($nodeId): void {
|
|
$legacy->whereNull('agent_id')
|
|
->where('fleet_node_id', $nodeId);
|
|
});
|
|
}
|
|
});
|
|
|
|
if ($nodeId === null && ! $query->exists()) {
|
|
throw new \InvalidArgumentException('Fleet node not found');
|
|
}
|
|
|
|
return $query
|
|
->latest()
|
|
->limit($limit)
|
|
->get();
|
|
}
|
|
}
|