TransEdge

Action Capabilities

Register preview-confirm-apply AI actions for TransEdge modules.

Action capabilities let modules turn natural-language requests into safe, confirmed actions.

Use them for operations where the user expects TransEdge to prepare or change something: creating an order, assigning a driver, importing rows, generating a draft record, or optimizing a route.

Contract

An action capability implements AIActionCapabilityInterface:

interface AIActionCapabilityInterface extends AICapabilityInterface
{
    public function shouldPreview(AiTask $task): bool;

    public function inputSchema(): array;

    public function preview(AiTask $task, array $input = []): array;

    public function apply(AiTask $task, array $preview = [], array $input = []): array;
}

Preview first

Action capabilities should preview before mutating data. The preview should include:

  • the action key
  • a human label and message
  • draft input
  • missing requirements
  • validation status
  • any module-specific metadata needed by the preview UI

Example: create-order preview shape

return [
    'key' => 'fleet-ops.create_order',
    'label' => 'Create Fleet-Ops order preview',
    'message' => 'Review the order draft before applying.',
    'ready' => true,
    'draft' => [
        'type' => 'transport',
        'scheduled_at' => '2026-07-04T10:30:00+08:00',
        'payload' => [
            'pickup_query' => '4202 Thames Ave Durham NC',
            'dropoff_query' => '3400 Cambridge Rd Durham NC',
        ],
    ],
    'missing_fields' => [],
];

Apply only after confirmation

The apply() method should use the latest confirmed preview input, run normal module validation, enforce permissions, and record the result.

public function apply(AiTask $task, array $preview = [], array $input = []): array
{
    $draft = data_get($input, 'draft', data_get($preview, 'draft', []));

    // Validate permissions and route through the module's normal creation path.

    return [
        'message' => 'Fleet-Ops order was created.',
        'resource' => [
            'route' => 'operations.orders.index.details',
            'uuid' => $order->uuid,
            'id' => $order->public_id,
        ],
    ];
}

Terminal states

Completed, cancelled, and failed actions should stop accepting edits or repeat apply attempts.

Action Capabilities | TransEdge