Capability API
A capability is a named AI endpoint that a third-party Ai3 extension
provides. Ai3 Core exposes a tagged DI compiler pass so that
capabilities register without code changes in ai3_.
ZakAiEndpointInterface
Every capability must implement
\Wegewerk\:
interface ZakAiEndpointInterface
{
public function generate(array $options = []): string;
}
The generate method receives an associative array of options (such
as text, image, language, etc.) and returns the generated
string.
AbstractZakAiEndpoint
For most capabilities, extending
\Wegewerk\ is the recommended way
to implement endpoints. It handles required parameter validation,
building the API request payload, sending the POST request via
Zak, and extracting the response key.
Subclasses declare their configuration via protected properties:
| Property | Description |
|---|---|
string $endpoint | The API path for the POST request (e.g. bulletpoints, faq, alttexts). |
string $response | The JSON key to extract from the API response. |
array $required | List of required option keys (e.g. ['text'] or ['image']). |
array $optional | List of optional option keys passed through to the payload if present. |
Payload construction and hooks:
- Validation:
validateverifies that all keys inRequired Options (array $options) $requiredare present and non-empty.Options - Payload building:
buildpopulates the payload directly with all required and present optional option keys.Payload (array $options) - Preparation hook:
prepareallows custom manipulation before sending (e.g. image resizing and base64 encoding).Payload (array $payload, array $options): array - Result extraction:
extractextracts theResult (array $response): string $responsevalue (converting arrays to JSON if needed).Key
Registering a capability
Tag your endpoint service with ai3. in your extension's
Configuration/Services.yaml. The compiler pass picks up the
$key, $title, and $endpoint constructor arguments
automatically:
MyVendor\MyAiExt\Endpoint\SummaryEndpoint:
tags:
- name: ai3.capability
arguments:
$key: 'my_ext_summary'
$title: 'Automatic summary'
$endpoint: '@MyVendor\MyAiExt\Endpoint\SummaryEndpoint'
use Wegewerk\Ai3Core\Api\AbstractZakAiEndpoint;
final class SummaryEndpoint extends AbstractZakAiEndpoint
{
protected string $endpoint = 'bulletpoints';
protected string $responseKey = 'bulletpoints';
protected array $requiredOptions = ['text'];
protected array $optionalOptions = ['language'];
}
CapabilityRegistry
At runtime, all registered capabilities are available via
\Wegewerk\. It is a
Singleton and can be injected via constructor:
use Wegewerk\Ai3Core\Service\CapabilityRegistry;
final class MyService
{
public function __construct(
private readonly CapabilityRegistry $capabilityRegistry,
) {}
public function run(string $capabilityKey): string
{
$capability = $this->capabilityRegistry
->getCapability($capabilityKey);
if ($capability === null) {
throw new \RuntimeException(
'Unknown capability: ' . $capabilityKey,
);
}
return $capability->endpoint->generate([
'text' => 'Hello',
'language' => 'en',
]);
}
}
TCA integration
The CapabilityRegistry is used in the items of capability in tx_ai3_domain_model_generation_task
:
'capability' => [
'label' => 'AI capability',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'itemsProcFunc' =>
\Wegewerk\Ai3Core\FormEngine\CapabilityItemsProcFunc::class
. '->itemsProcFunc',
],
],