Skip to content
Merged
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
37 changes: 37 additions & 0 deletions .github/workflows/build_magento_plugins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Check Magento Plugins

on:
workflow_dispatch: {}
push:
branches:
- develop
paths:
- "plugins/magento/**"
- ".github/workflows/build_magento_plugins.yml"
pull_request:
branches:
- develop
paths:
- "plugins/magento/**"
- ".github/workflows/build_magento_plugins.yml"

jobs:
compute_matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.supported-version.outputs.matrix }}
steps:
- uses: graycoreio/github-actions-magento2/supported-version@main
id: supported-version
with:
include_services: true

check-cms-ai-builder:
needs: compute_matrix
uses: graycoreio/github-actions-magento2/.github/workflows/check-extension.yaml@main
with:
matrix: ${{ needs.compute_matrix.outputs.matrix }}
fail-fast: false
path: plugins/magento/cms-ai-builder
secrets:
composer_auth: ${{ secrets.COMPOSER_AUTH }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Copyright © Graycore, LLC. All rights reserved.
*/

declare(strict_types=1);

namespace Graycore\CmsAiBuilder\Api\Exception;

use Magento\Framework\Exception\LocalizedException;

/**
* Exception thrown when the LLM API returns an error
*/
class LlmApiException extends LocalizedException
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Copyright © Graycore, LLC. All rights reserved.
*/

declare(strict_types=1);

namespace Graycore\CmsAiBuilder\Api\Exception;

use Magento\Framework\Exception\LocalizedException;

/**
* Exception thrown when LLM configuration is invalid or missing
*/
class LlmConfigurationException extends LocalizedException
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Copyright © Graycore, LLC. All rights reserved.
*/

declare(strict_types=1);

namespace Graycore\CmsAiBuilder\Api\Exception;

use Magento\Framework\Exception\LocalizedException;

/**
* Exception thrown when the LLM response is invalid or has unexpected structure
*/
class LlmResponseException extends LocalizedException
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Copyright © Graycore, LLC. All rights reserved.
*/

declare(strict_types=1);

namespace Graycore\CmsAiBuilder\Api\Exception;

use Magento\Framework\Exception\LocalizedException;

/**
* Exception thrown when JSON patch operations fail to apply
*/
class PatchApplicationException extends LocalizedException
{
}
12 changes: 8 additions & 4 deletions plugins/magento/cms-ai-builder/Api/LlmModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@

interface LlmModelInterface
{
/**
* Get the JSON schema definition for this component
*/
public function call(array $schema, array $messages): LlmCallResultInterface;
/**
* Call the LLM model with schema and messages
*
* @param array $schema
* @param array $messages
* @return LlmCallResultInterface
*/
public function call(array $schema, array $messages): LlmCallResultInterface;
}
14 changes: 7 additions & 7 deletions plugins/magento/cms-ai-builder/Api/RendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

interface RendererInterface
{
/**
* Render JSON content to HTML
*
* @param string $schema
* @return string
*/
public function render(array $schema): string;
/**
* Render JSON content to HTML
*
* @param string $schema
* @return string
*/
public function render(array $schema): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function getReply(): string;
* @return array
*/
public function getPatch(): array;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@

interface SchemaChatGeneratorInterface
{
/**
* Generate JSON Patch from user prompt using OpenAI
* @throws \Exception
*/
public function generate(string $prompt, string | null $schema, ?array $conversationHistory = null, ?int $storeId = null): GenerateSchemaResultInterface;
/**
* Generate JSON Patch from user prompt
*
* @param string $prompt
* @param string|null $schema
* @param array|null $conversationHistory
* @return GenerateSchemaResultInterface
* @throws \Exception
*/
public function generate(
string $prompt,
?string $schema,
?array $conversationHistory = null
): GenerateSchemaResultInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

class IdentityRenderer extends Template
{
/**
* @param Context $context
* @param Schema $schema
* @param array $data
*/
public function __construct(
Context $context,
private readonly Schema $schema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,32 @@

class NativeRenderer extends Template
{
public function __construct(
Context $context,
private readonly Schema $schema,
private readonly RendererInterface $renderer,
array $data = [],
) {
parent::__construct($context, $data);
}

/**
* @inheritDoc
*/
public function getChildHtml($alias = '', $useCache = true)
{
$schema = $this->schema->getSchema();

if ($schema === null) {
return '';
}

return $this->renderer->render($schema);
}
/**
* @param Context $context
* @param Schema $schema
* @param RendererInterface $renderer
* @param array $data
*/
public function __construct(
Context $context,
private readonly Schema $schema,
private readonly RendererInterface $renderer,
array $data = [],
) {
parent::__construct($context, $data);
}

/**
* @inheritDoc
*/
public function getChildHtml($alias = '', $useCache = true)
{
$schema = $this->schema->getSchema();

if ($schema === null) {
return '';
}

return $this->renderer->render($schema);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
class NoopRenderer extends Template
{
/**
* Return empty string for no-op rendering
*
* @param string $alias
* @param boolean $useCache
* @return string
*/
public function getChildHtml($alias = '', $useCache = true) {
public function getChildHtml($alias = '', $useCache = true)
{
return '';
}
}
Loading
Loading