token27 / nexus-ai-content
Generic content orchestration layer for NexusAI workflows, prompts, tracking, pricing, and domain extensions.
Requires
- php: ^8.3
- token27/nexus-ai: ^1.0
- token27/nexus-ai-pricing: ^1.0
- token27/nexus-ai-prompts: ^1.0
- token27/nexus-ai-tracking: ^1.0
- token27/nexus-ai-workflows: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- guzzlehttp/guzzle: ^7.0
- nyholm/psr7: ^1.8
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
Suggests
- token27/nexus-ai-content-formatters: Use at the publication/export boundary to format generated structured content.
- token27/nexus-ai-images: Use from content domain extensions when a workflow needs generated images.
- token27/nexus-ai-tokenizer: Optional tokenizer support for pre-request token estimation through a configured nexus-ai-pricing engine.
README
A framework-agnostic, workflow-first PHP 8.3+ content orchestration layer for the NexusAI ecosystem. Compose versioned prompts, AI drivers, resumable workflows, tracking, pricing, and domain extensions behind one fluent API.
Why nexus-ai-content?
Article generation, social posts, newsletters, scripts, product descriptions, and future content types all need the same foundation:
- choose a content type and workflow
- resolve versioned prompts from
nexus-ai-prompts - execute nodes through
nexus-ai-workflows - call providers through
nexus-ai - track every run through
nexus-ai-tracking - calculate cost and enforce budgets through
nexus-ai-pricing - keep domain packages focused on their domain instead of infrastructure
nexus-ai-content is that shared layer. It is intentionally not an article generator. Article logic belongs in nexus-ai-content-articles.
Features
- Engine + Builder + Registry pattern consistent with the NexusAI libraries.
- Fluent content API for provider/model selection, workflow selection, variables, language, run id, tracking, pricing, and budgets.
- Workflow registry keyed by
contentType/workflowName. - Prompt-aware AI node with
ContentAINode. - Tracking-ready execution with run id, prompt id, prompt version, content type, workflow, provider, model, tokens, cost, and latency.
- Pricing-ready execution with post-request cost calculation and optional pre-request budget checks.
- Extension bootstrap so packages like
nexus-ai-content-articlescan register workflows cleanly. - Test-friendly driver injection through
withDriver().
Installation
composer require token27/nexus-ai-content
Requires: PHP 8.3+ and the core NexusAI packages listed in composer.json.
Quick Start
use Token27\NexusAI\Content\ContentEngine; use Token27\NexusAI\Content\Node\ContentAINode; use Token27\NexusAI\Workflows\Engine\WorkflowBuilder; $workflow = WorkflowBuilder::named('default') ->addNode('draft', new ContentAINode( promptIdentifier: 'content/draft', outputKey: 'content', promptVersion: '1.0.0', )) ->build(); $engine = ContentEngine::create() ->withPromptRegistry($promptRegistry) ->withTracking($tracking) ->withPricing($pricing); $engine->getRegistry()->register('article', $workflow); $result = $engine ->for('openai', 'gpt-4o-mini') ->withContentType('article') ->withLanguage('es') ->withVariable('topic', 'Calidad de contenido con IA') ->withBudget(0.25) ->generate(); echo $result->text;
For tests, inject a pre-built driver:
$result = $engine ->for('fake', 'test-model') ->withContentType('article') ->withDriver($fakeDriver) ->generate();
Documentation
| Guide | Description |
|---|---|
| Documentation Home | Full documentation map |
| Installation | Composer, dependencies, and first setup |
| Quick Start | First workflow with a fake driver |
| Fluent API | Engine and builder methods |
| Workflows | Registering and running content workflows |
| Prompts | Using nexus-ai-prompts with ContentAINode |
| Tracking and Pricing | Telemetry, costs, budgets, and tokenizer notes |
| Extending | Creating domain extensions |
| Testing | Testing content workflows and nodes |
| Contributing | Development setup and collaboration rules |
| Architecture | Why this package exists before article domains |
| Troubleshooting | Common failures and fixes |
Examples
The examples/ directory contains runnable production-style examples that read .env, configure real providers through NexusAI, load prompts, enable pricing, and optionally write tracking events:
- 00-openai-draft.php
- 01-anthropic-outline.php
- 02-gemini-spanish.php
- 03-deepseek-budget.php
- 04-tracking-jsonfile.php
- 05-custom-openai-compatible.php
- 06-testing-fake-driver.php
- 07-openai-raw-prompt.php
Quality Gates
composer validate --strict vendor/bin/php-cs-fixer fix --dry-run --diff vendor/bin/phpstan analyse --level=8 src tests vendor/bin/phpunit
License
MIT. See LICENSE.