Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace App\Command;

use Ibexa\Contracts\SiteContext\BrandContextAiContextResolverInterface;
use Ibexa\Contracts\SiteContext\SiteContextServiceInterface;
use Ibexa\Contracts\SiteContext\Values\BrandContextAi\BrandContextAiContext;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'doc:brand_context:ai_guidelines')]
final class BrandContextAiGuidelinesCommand extends Command
{
public function __construct(
private readonly BrandContextAiContextResolverInterface $aiContextResolver,
private readonly SiteContextServiceInterface $siteContextService
) {
parent::__construct();
}

protected function execute(
InputInterface $input,
OutputInterface $output
): int {
// Get the AI guidelines of the brand context that the carotella_pro website belongs to
$aiContext = $this->aiContextResolver->resolveForSiteAccess('carotella_pro', 'eng-GB');

foreach ($aiContext?->getEntries() ?? [] as $entry) {
$output->writeln(sprintf('- %s: %s', $entry->getDescription(), $entry->getValue()));
}

// Run code as if the carotella_pro website was selected in the back office
$aiContext = $this->siteContextService->runInContext(
'carotella_pro',
fn (): ?BrandContextAiContext => $this->aiContextResolver->resolveForCurrentSiteContext('eng-GB')
);

$output->writeln('Brand context: ' . ($aiContext?->getBrandContextIdentifier() ?? 'none'));

return self::SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

namespace App\Command;

use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\SiteContext\BrandContextAssignmentServiceInterface;
use Ibexa\Contracts\SiteContext\BrandContextServiceInterface;
use Ibexa\Contracts\SiteContext\Values\BrandContext\Assignment\AssignmentCreateStruct;
use Ibexa\Contracts\SiteContext\Values\BrandContext\BrandContextQuery;
use Ibexa\Contracts\SiteContext\Values\BrandContext\Query\Criterion\NameCriterion;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'doc:brand_context:manage')]
final class ManageBrandContextCommand extends Command
{
public function __construct(
private readonly UserService $userService,
private readonly PermissionResolver $permissionResolver,
private readonly BrandContextServiceInterface $brandContextService,
private readonly BrandContextAssignmentServiceInterface $assignmentService
) {
parent::__construct();
}

protected function execute(
InputInterface $input,
OutputInterface $output
): int {
$this->permissionResolver->setCurrentUserReference(
$this->userService->loadUserByLogin('admin')
);

// Create a brand context
$createStruct = $this->brandContextService->newBrandContextCreateStruct('carotella');
$createStruct->setName('eng-GB', 'Carotella');
$createStruct->setDescription('eng-GB', 'Organic vegetable products for home cooks and professional kitchens');
$createStruct->setLogo('ezcontent://57');
$createStruct->setColor('#E8730C');
$createStruct->setRegion('Europe');
$createStruct->setAttributeValue('tagline', 'Fresh from the field', 'eng-GB');
$createStruct->setAttributeValue('persona_definition', 'A friendly farmer who knows good food', 'eng-GB');

$brandContext = $this->brandContextService->createBrandContext($createStruct);

// Assign websites to the brand context
$this->assignmentService->setAssignments($brandContext->getId(), [
new AssignmentCreateStruct('carotella'),
new AssignmentCreateStruct('carotella_pro'),
]);

// Update the brand context
$updateStruct = $this->brandContextService->newBrandContextUpdateStruct($brandContext);
$updateStruct->setAttributeValue('tagline', 'Fresh from our fields', 'eng-GB');

$brandContext = $this->brandContextService->updateBrandContext($brandContext, $updateStruct);

// Find brand contexts
$brandContexts = $this->brandContextService->findBrandContexts(
new BrandContextQuery(new NameCriterion('Caro'), 0, 10)
);

foreach ($brandContexts as $foundBrandContext) {
$output->writeln($foundBrandContext->getIdentifier() . ': ' . $foundBrandContext->getName());
}

// Get a brand context and its attribute values
$brandContext = $this->brandContextService->getBrandContext('carotella', ['eng-GB']);

$output->writeln($brandContext->getAttributeValue('tagline', 'eng-GB')?->getValue());

// Get the brand context of a website
$assignment = $this->assignmentService->resolveContextForSiteAccess('carotella_pro');
if ($assignment !== null) {
$output->writeln('carotella_pro belongs to the brand context with ID ' . $assignment->getContextId());
}

return self::SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

namespace App\EventSubscriber;

use Ibexa\Contracts\SiteContext\Event\BrandContextAttributeRenderEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

final readonly class AccentColorAttributeRenderSubscriber
{
#[AsEventListener]
public function onAttributeRender(BrandContextAttributeRenderEvent $event): void
{
if ($event->getAttributeValue()->getDefinition()->getIdentifier() !== 'color_accent') {
return;
}

$event->prependTemplate('@ibexadesign/brand_context/accent_color_blocks.html.twig');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% block color_attribute %}
<span style="display: inline-block; width: 1em; height: 1em; background-color: {{ value }};"></span>
<strong>{{ value }}</strong>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-
type: brand_context_attribute_definition
mode: delete
criteria:
type: field_value
field: identifier
value: social_tiktok
operator: '='
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-
type: brand_context_attribute_definition
mode: update
criteria:
type: field_value
field: identifier
value: certifications
operator: '='
position: 20
descriptions:
eng-GB: Environmental and fair trade certifications held by the brand
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-
type: brand_context_attribute_group
mode: create
identifier: sustainability
labels:
eng-GB: Sustainability

-
type: brand_context_attribute_definition
mode: create
identifier: certifications
attribute_group_identifier: sustainability
type_identifier: text
position: 10
required: false
translatable: true
descriptions:
eng-GB: Environmental certifications held by the brand

-
type: brand_context_attribute_definition
mode: create
identifier: preferred_terms
attribute_group_identifier: ai_context
type_identifier: text
position: 70
required: false
translatable: true
descriptions:
eng-GB: Terms to use when describing products
6 changes: 6 additions & 0 deletions docs/ai/ai_actions/ai_actions_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ Pieces of PHP code that are responsible for resolving a model are called handler
They may include hardcoded prompts for conversational AI services like ChatGPT, or operate without prompts in the case of other types of AI.
Handlers take parameters defined in the AI action type and configuration, combine it with user input and any predefined settings or prompts, and pass this information to the AI service for processing.

### Brand guidelines

If the website that an editor selected in the back office top bar belongs to a [brand context](brand_context_guide.md), [[= product_name =]] adds the brand's AI guidelines to the prompt.
This way, AI actions follow the writing style, persona, and other rules of the brand on all its websites.
For more information, see [Brand context and AI](brand_context_guide.md#brand-context-and-ai).

### Triggering actions from the UI

Among other elements, AI Actions include UI components that are used in:
Expand Down
5 changes: 4 additions & 1 deletion docs/ai/mcp/mcp_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@
- `list_users` - lists user accounts, paginated
- `get_user` - gets one user account by `id` or `login`

The following tools are included with their respective packages, [Taxonomy](taxonomy.md) and [Workflow](workflow.md):
The following tools are included with their respective packages, [Brand context](brand_context_guide.md), [Taxonomy](taxonomy.md), and [Workflow](workflow.md):

Check notice on line 162 in docs/ai/mcp/mcp_config.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/ai/mcp/mcp_config.md#L162 <Ibexa.Passive>

Try to avoid passive tense, when possible.
Raw output
{"message":"Try to avoid passive tense, when possible.","location":{"path":"docs/ai/mcp/mcp_config.md","range":{"start":{"line":162,"column":21},"end":{"line":162,"column":33}}},"severity":"INFO","code":{"value":"Ibexa.Passive"}}

- `Ibexa\SiteContext\Mcp\Tool\BrandContextTools`
- `list_brand_contexts` - lists the brand contexts that the current user can view, with the SiteAccesses assigned to them, paginated and sorted by identifier

Check warning on line 165 in docs/ai/mcp/mcp_config.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/ai/mcp/mcp_config.md#L165 <Ibexa.OxfordComma>

Use a comma before the last 'and' or 'or' in a list of four or more items.
Raw output
{"message":"Use a comma before the last 'and' or 'or' in a list of four or more items.","location":{"path":"docs/ai/mcp/mcp_config.md","range":{"start":{"line":165,"column":28},"end":{"line":165,"column":142}}},"severity":"WARNING","code":{"value":"Ibexa.OxfordComma"}}
- `get_brand_context` - gets a brand context with its SiteAccesses and attribute values
- `Ibexa\Taxonomy\Mcp\Tool\TaxonomyTools`
- `list_taxonomies` - lists the taxonomies
- `list_taxonomy_entries` - lists entries of a taxonomy, paginated and ordered by entry ID
Expand Down
8 changes: 8 additions & 0 deletions docs/content_management/data_migration/exporting_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ The following types are available:
- `location`
- `attribute_group`
- `attribute`
- `brand_context_attribute_group`
- `brand_context_attribute_definition`
- `segment`
- `segment_group`
- `company`
Expand Down Expand Up @@ -189,6 +191,8 @@ The following combinations of types are modes are available:
|`location`||&#10004;||
|`attribute_group`|&#10004;|&#10004;|&#10004;|
|`attribute`|&#10004;|&#10004;|&#10004;|
|`brand_context_attribute_group`|&#10004;|&#10004;|&#10004;|
|`brand_context_attribute_definition`|&#10004;|&#10004;|&#10004;|
|`segment`|&#10004;|&#10004;|&#10004;|
|`segment_group`|&#10004;|&#10004;|&#10004;|
|`company`|&#10004;|||
Expand Down Expand Up @@ -262,6 +266,10 @@ The following properties are available (per type):
- `options`
- `attribute_group`
- `identifier`
- `brand_context_attribute_group`
- `identifier`
- `brand_context_attribute_definition`
- `identifier`

You can extend the list of available matchers by creating [a custom one](add_data_migration_matcher.md).

Expand Down
29 changes: 29 additions & 0 deletions docs/content_management/data_migration/importing_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
| `action_configuration` | &#10004; | &#10004; | &#10004; | | |
| `attribute` | &#10004; | &#10004; | &#10004; | | |
| `attribute_group` | &#10004; | &#10004; | &#10004; | | |
| `brand_context_attribute_definition` | &#10004; | &#10004; | &#10004; | | |
| `brand_context_attribute_group` | &#10004; | &#10004; | &#10004; | | |
| `company` | &#10004; | | | | |
| `content_type` | &#10004; | &#10004; | &#10004; | | |
| `content_type_group` | &#10004; | &#10004; | &#10004; | | |
Expand Down Expand Up @@ -672,6 +674,33 @@
[[= include_file('code_samples/data_migration/examples/ai/action_configuration_delete.yaml') =]]
```

### Brand context attributes

You can create, update, and delete the attribute groups and attribute definitions of [brand contexts](brand_context_guide.md).

Check warning on line 679 in docs/content_management/data_migration/importing_data.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/content_management/data_migration/importing_data.md#L679 <Ibexa.OxfordComma>

Use a comma before the last 'and' or 'or' in a list of four or more items.
Raw output
{"message":"Use a comma before the last 'and' or 'or' in a list of four or more items.","location":{"path":"docs/content_management/data_migration/importing_data.md","range":{"start":{"line":679,"column":1},"end":{"line":679,"column":61}}},"severity":"WARNING","code":{"value":"Ibexa.OxfordComma"}}

- The following example creates an attribute group with an attribute definition, and adds an attribute definition to the AI Context group, so that AI actions follow it as a guideline.
AI actions use values of all attribute types except the Content type, whose values aren't added to prompts:

``` yaml
[[= include_file('code_samples/data_migration/examples/brand_context/attribute_group_definition_create.yaml') =]]
```

- Use the `update` mode to modify an existing attribute definition.
You only need to provide the properties that you want to change:

``` yaml
[[= include_file('code_samples/data_migration/examples/brand_context/attribute_definition_update.yaml') =]]
```

- Use the `delete` mode to delete an existing attribute definition:

``` yaml
[[= include_file('code_samples/data_migration/examples/brand_context/attribute_definition_delete.yaml') =]]
```

The attribute groups use the same `update` and `delete` steps, with the `brand_context_attribute_group` type.
You can't change the identifier of the AI Context attribute group.

### Discounts

The following example shows how you can create a new [discount](discounts_guide.md) in your system:
Expand Down
16 changes: 16 additions & 0 deletions docs/multisite/brand_context/brand_context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
description: Brand context lets you describe a brand once, assign the brand's websites to it, and make AI actions follow the brand's guidelines.
page_type: landing_page
month_change: true
---

# Brand context

With brand context, you can describe a brand once and reuse that business perspective in all the websites that represent the brand, including the guidelines that AI actions follow.

[[= cards([
"multisite/brand_context/brand_context_guide",
"multisite/brand_context/configure_brand_context",
"multisite/brand_context/brand_context_api",
("api/php_api/php_api_reference/namespaces/ibexa-contracts-sitecontext.html", "PHP API Reference", "<code>Ibexa\\Contracts\\SiteContext</code>"),
], columns=3) =]]
Loading
Loading