Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"fusio/adapter-util": "^6.0",
"fusio/adapter-worker": "^0.2",
"fusio/marketplace": "^0.2",
"firebase/php-jwt": "^6.0",
"firebase/php-jwt": "^7.0",
"symfony/filesystem": "^6.0|^7.0",
"symfony/mailer": "^6.0|^7.0",
"symfony/doctrine-messenger": "^6.0|^7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,45 @@
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Connection\Agent;
namespace Fusio\Impl\Backend\Action\Agent;

use Fusio\Engine\Connector;
use Fusio\Engine\ActionInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use Fusio\Impl\Service\System\FrameworkConfig;
use Fusio\Impl\Table;
use Fusio\Impl\Service\Agent;
use Fusio\Impl\Service\System\ContextFactory;
use Fusio\Model\Backend\AgentCreate;
use PSX\Http\Environment\HttpResponse;
use PSX\Http\Exception\BadRequestException;

/**
* Reset
* Create
*
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://www.fusio-project.org
*/
readonly class Reset extends AgentAbstract
readonly class Create implements ActionInterface
{
public function __construct(private Table\Agent $agentTable, Connector $connector, FrameworkConfig $frameworkConfig)
public function __construct(private Agent $agentService, private ContextFactory $contextFactory)
{
parent::__construct($connector, $frameworkConfig);
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
$this->assertConnectionEnabled();
$body = $request->getPayload();

$connectionId = (int) $request->get('connection_id');
if (empty($connectionId)) {
throw new BadRequestException('Provided no connection');
}
assert($body instanceof AgentCreate);

$this->agentTable->reset($context->getUser()->getId(), $connectionId);
$id = $this->agentService->create(
$body,
$this->contextFactory->newActionContext($context)
);

return new HttpResponse(200, [], [
return new HttpResponse(201, [], [
'success' => true,
'message' => 'Chat successfully reset',
'message' => 'Agent successfully created',
'id' => '' . $id,
]);
}
}
56 changes: 56 additions & 0 deletions src/Backend/Action/Agent/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*
* Fusio - Self-Hosted API Management for Builders.
* For the current version and information visit <https://www.fusio-project.org/>
*
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Agent;

use Fusio\Engine\ActionInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use Fusio\Impl\Service\Agent;
use Fusio\Impl\Service\System\ContextFactory;

/**
* Delete
*
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://www.fusio-project.org
*/
readonly class Delete implements ActionInterface
{
public function __construct(private Agent $agentService, private ContextFactory $contextFactory)
{
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
$id = $this->agentService->delete(
$request->get('agent_id'),
$this->contextFactory->newActionContext($context)
);

return [
'success' => true,
'message' => 'Agent successfully deleted',
'id' => '' . $id,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Connection\Agent;
namespace Fusio\Impl\Backend\Action\Agent;

use Fusio\Engine\Connector;
use Fusio\Engine\ActionInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use Fusio\Impl\Backend\View;
use Fusio\Impl\Service\Agent\Intent;
use Fusio\Impl\Service\System\FrameworkConfig;
use PSX\Http\Environment\HttpResponse;
use PSX\Http\Exception\BadRequestException;
use Fusio\Impl\Table;
use PSX\Http\Exception as StatusCode;

/**
* Get
Expand All @@ -37,24 +35,27 @@
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://www.fusio-project.org
*/
readonly class Get extends AgentAbstract
readonly class Get implements ActionInterface
{
public function __construct(private View\Connection\Agent $view, Connector $connector, FrameworkConfig $frameworkConfig)
public function __construct(private View\Agent $view)
{
parent::__construct($connector, $frameworkConfig);
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
$this->assertConnectionEnabled();
$agent = $this->view->getEntity(
$request->get('agent_id'),
$context
);

$connectionId = (int) $request->get('connection_id');
if (empty($connectionId)) {
throw new BadRequestException('Provided no connection');
if (empty($agent)) {
throw new StatusCode\NotFoundException('Could not find agent');
}

$intent = Intent::tryFrom($request->get('intent') ?? '');
if ($agent['status'] == Table\Agent::STATUS_DELETED) {
throw new StatusCode\GoneException('Agent was deleted');
}

return new HttpResponse(200, [], $this->view->getCollection($connectionId, $intent, $context));
return $agent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@
* limitations under the License.
*/

namespace Fusio\Impl\Service\Agent;
namespace Fusio\Impl\Backend\Action\Agent;

use Fusio\Engine\ActionInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use Fusio\Impl\Backend\Filter\QueryFilter;
use Fusio\Impl\Backend\View;

/**
* IntentFactory
* GetAll
*
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://www.fusio-project.org
*/
readonly class IntentFactory
class GetAll implements ActionInterface
{
public function __construct(
private Intent\ActionIntent $actionIntent,
private Intent\SchemaIntent $schemaIntent,
private Intent\ArchitectIntent $architectIntent,
private Intent\GeneralIntent $generalIntent
) {
public function __construct(private View\Agent $view)
{
}

public function factory(?Intent $intent): IntentInterface
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
return match($intent) {
Intent::ACTION => $this->actionIntent,
Intent::SCHEMA => $this->schemaIntent,
Intent::ARCHITECT => $this->architectIntent,
default => $this->generalIntent,
};
return $this->view->getCollection(
QueryFilter::from($request),
$context
);
}
}
63 changes: 63 additions & 0 deletions src/Backend/Action/Agent/GetTools.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/*
* Fusio - Self-Hosted API Management for Builders.
* For the current version and information visit <https://www.fusio-project.org/>
*
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Agent;

use Fusio\Engine\ActionInterface;
use Fusio\Engine\Agent\ToolsInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;

/**
* GetTools
*
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://www.fusio-project.org
*/
readonly class GetTools implements ActionInterface
{
public function __construct(private ToolsInterface $tools)
{
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
return [
'tools' => $this->getTools(),
];
}

private function getTools(): array
{
$toolbox = $this->tools->resolve();

$result = [];
foreach ($toolbox->getTools() as $tool) {
$result[] = [
'name' => $tool->getName(),
'description' => $tool->getDescription(),
];
}

return $result;
}
}
50 changes: 50 additions & 0 deletions src/Backend/Action/Agent/Message/GetAll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/*
* Fusio - Self-Hosted API Management for Builders.
* For the current version and information visit <https://www.fusio-project.org/>
*
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Fusio\Impl\Backend\Action\Agent\Message;

use Fusio\Engine\ActionInterface;
use Fusio\Engine\ContextInterface;
use Fusio\Engine\ParametersInterface;
use Fusio\Engine\RequestInterface;
use Fusio\Impl\Backend\View;

/**
* GetAll
*
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
* @license http://www.apache.org/licenses/LICENSE-2.0
* @link https://www.fusio-project.org
*/
readonly class GetAll implements ActionInterface
{
public function __construct(private View\Agent\Message $view)
{
}

public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
{
return $this->view->getCollection(
(int) $request->get('agent_id'),
(int) $request->get('parent'),
$context
);
}
}
Loading