Media AI: Worked extension examples
These developer-facing recipes are kept beside the package contract. Replace the example values with the site-specific records and data objects used by the calling workflow.
<?phpdeclare(strict_types=1);final class ExampleImageDoctorImplementation implements \Capell\MediaAI\Contracts\ImageDoctor{ public function doctor(\Capell\Core\Models\Media $media, \Capell\MediaAI\Data\ImageDoctorRequest $request): \Capell\MediaAI\Data\ImageDoctorResult { throw new LogicException('Implement this package contract for the calling site.'); }}
app()->bind(\Capell\MediaAI\Contracts\ImageDoctor::class, ExampleImageDoctorImplementation::class);Bind your own image editing provider when the first-party HTTP provider does not fit your service. Keep the call bounded, send the request’s executionId as the idempotency key so a retried job is not charged twice, and return a non-retryable failure once the request has been sent. The provider only returns untrusted output; Media AI decides what is written.
<?phpdeclare(strict_types=1);final class ExampleImageEditingProvider implements \Capell\MediaAI\Contracts\ImageEditingProvider{ public function available(): bool { return is_string(config('services.example_images.key')) && config('services.example_images.key') !== ''; }
public function edit(\Capell\MediaAI\Data\ImageEditingRequestData $request): \Capell\MediaAI\Data\ImageDoctorResult { try { $response = \Illuminate\Support\Facades\Http::withToken((string) config('services.example_images.key')) ->withHeaders(['Idempotency-Key' => (string) $request->request->executionId]) ->connectTimeout(5) ->timeout(60) ->withoutRedirecting() ->post('https://images.example.com/v1/edit', $request->toProviderPayload()); } catch (\Illuminate\Http\Client\ConnectionException) { return \Capell\MediaAI\Data\ImageDoctorResult::failure('The image service could not be reached.'); }
if (! $response->successful() || ! is_string($response->json('image.base64'))) { return \Capell\MediaAI\Data\ImageDoctorResult::failure('The image service did not return an image.', retryable: false); }
return \Capell\MediaAI\Data\ImageDoctorResult::success( message: 'Image edited.', imageBase64: $response->json('image.base64'), imageMimeType: is_string($response->json('image.mime_type')) ? $response->json('image.mime_type') : 'image/png', ); }}
app()->singleton(\Capell\MediaAI\Contracts\ImageEditingProvider::class, ExampleImageEditingProvider::class);<?phpdeclare(strict_types=1);final class ExampleWebsiteMediaAcquisitionProviderImplementation implements \Capell\MediaAI\Contracts\WebsiteMediaAcquisitionProvider{ public function available(): bool { throw new LogicException('Implement this package contract for the calling site.'); } public function acquire(\Capell\MediaAI\Data\WebsiteMediaRequestData $request, \Capell\AIOrchestrator\Data\Ai\ProviderCallAuthorizationData $authorization, \DateTimeImmutable $now): \Capell\MediaAI\Data\WebsiteMediaProviderResponseData { throw new LogicException('Implement this package contract for the calling site.'); }}
app()->bind(\Capell\MediaAI\Contracts\WebsiteMediaAcquisitionProvider::class, ExampleWebsiteMediaAcquisitionProviderImplementation::class);<?phpdeclare(strict_types=1);final class ExampleWebsiteMediaAssetRepositoryImplementation implements \Capell\MediaAI\Contracts\WebsiteMediaAssetRepository{ public function available(?\DateTimeImmutable $now = null): bool { throw new LogicException('Implement this package contract for the calling site.'); } public function persist(\Capell\MediaAI\Data\WebsiteMediaRequestData $request, \Capell\AIOrchestrator\Data\Ai\ProviderCallAuthorizationData $authorization, \Capell\AIOrchestrator\Data\Ai\ProviderExecutionResultData $execution, \Capell\MediaAI\Data\WebsiteMediaAssetCandidateData $asset, \DateTimeImmutable $now): \Capell\MediaAI\Data\WebsiteMediaAssetReceiptData { throw new LogicException('Implement this package contract for the calling site.'); } public function verify(\Capell\MediaAI\Data\WebsiteMediaAssetReceiptData $receipt, \DateTimeImmutable $now): bool { throw new LogicException('Implement this package contract for the calling site.'); } public function load(string $receiptReference, \Capell\MediaAI\Data\WebsiteMediaRequestData $request, \Capell\AIOrchestrator\Data\Ai\ProviderCallAuthorizationData $authorization, \Capell\MediaAI\Contracts\WebsiteMediaProviderAttestationVerifier $attestationVerifier, \DateTimeImmutable $now): ?\Capell\MediaAI\Data\WebsiteMediaAssetReceiptData { throw new LogicException('Implement this package contract for the calling site.'); }}
app()->bind(\Capell\MediaAI\Contracts\WebsiteMediaAssetRepository::class, ExampleWebsiteMediaAssetRepositoryImplementation::class);<?phpdeclare(strict_types=1);final class ExampleWebsiteMediaProviderAttestationVerifierImplementation implements \Capell\MediaAI\Contracts\WebsiteMediaProviderAttestationVerifier{ public function verify(\Capell\MediaAI\Data\WebsiteMediaRequestData $request, \Capell\AIOrchestrator\Data\Ai\ProviderCallAuthorizationData $authorization, \Capell\MediaAI\Data\WebsiteMediaAssetCandidateData|\Capell\MediaAI\Data\WebsiteMediaAssetEvidenceData $asset, \DateTimeImmutable $now): bool { throw new LogicException('Implement this package contract for the calling site.'); }}
app()->bind(\Capell\MediaAI\Contracts\WebsiteMediaProviderAttestationVerifier::class, ExampleWebsiteMediaProviderAttestationVerifierImplementation::class);Queued outcomes use an optional dispatch identifier on RunImageDoctorJob; retries and duplicate deliveries of that payload share one database notification. New dispatches retain separate outcomes even when their image and instructions are identical. Older serialised jobs without the identifier fall back to the application digest. Accepted output and its durable outcome commit in one database transaction; terminal callbacks recheck source identity and the initiating actor’s current access before recording a redacted failure notice. No migration or provider-contract change is required.