<?php
namespace Claromentis\Core\Ai\Controller;

$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"] ?: array()) + array("_1ab2691b0149e6c0f5be" . "f2e034d68c11" => base64_decode("Jyw" . "gJw" . "=="), "modu" . "le" => base64_decode("bW9kdW" . "xl"), "da" . "ta" => base64_decode("ZGF" . "0YQ" . "=="), "_54faabe694dfa8d05dc6" . "c0827a214f82" => base64_decode("aW" . "1h" . "Z2" . "U="), "st" . "at" . "us" => base64_decode("c3RhdH" . "Vz"), "_b2ffc45fa7bfe7aac7" . "2914a57d0f9162" => base64_decode("SW52YWxpZCBt" . "b2R1bGUgJw=="), "la" . "ng" . "ua" . "ge" => base64_decode("bGFuZ3" . "VhZ2U="), "_ea8229a121285ee649a7" . "2fd880bac39b" => base64_decode("YXJyYXlf" . "ZmlsdGVy"), "_e05e0022a2e5" . "ad344b9c4a0d3" . "f64e1a5" => base64_decode("bWVzc" . "2FnZQ" . "=="), "_df34c069de43011ad" . "e22c720a3318f60" => base64_decode("aGlzdG9y" . "eVtd"), "_f083878fb61180fbf68b" . "a3a77b8d7de3" => base64_decode("aW1h" . "Z2Vz"), "_8dacf52654336" . "5460ea3a88a3a0" . "904a1" => base64_decode("JzsgdmFsaWQgbW9kdWxlcyBhcmU" . "g"), "_475c4ddf7873ea4e9044df10ae" . "31d01e" => base64_decode("QUkgaW1hZ2UgZ2VuZXJhdGlvbiBpcyB" . "kaXNhYmxlZA=="), "_f73dab606630b3886" . "45c4f7d3fbb13bb" => base64_decode("YXJyYXlfbW" . "VyZ2U="), "_c862508fd80f2ba2b8ec" . "b2b75ac53467" => base64_decode("YWkuaW52YWxpZF9jaG" . "F0LmVycm9y"), "_792a339ad0d1fe818" . "084474ec06e4cc1" => base64_decode("Y2hhd" . "HM="), "_839809c6beb4465bd21e037814ee46" . "83" => base64_decode("Y29tbW9uLmFpLmludmFsaWRfc" . "HJvbXB0"), "_eac6791bbe0decdc" . "5761307838b277de" => base64_decode("Y29tbW9uLmFpLnVuZXhwZWN0Z" . "WRfcmVzcG9uc2U="), "_4d707fab9" . "3bebb00bbe" . "69e8159697" . "c90" => base64_decode(""), "_cfab5a4a6804604f4998a7244eba8" . "6bd" => base64_decode("Cgo" . "="), "_a1b32522d3c9a793e0e430746" . "6b172d9" => base64_decode("ZGF0" . "YTog"), "_c2900f14e63513f00ce80edbb04" . "5506c" => base64_decode("b2JfZm" . "x1c2g="), "_9a122dd9e0255" . "ca418d473b4ba6" . "8f14b" => base64_decode("bWV0YWRhdGFbXQ=" . "="), "_d962cfd1735" . "adb2dfba46f6" . "9c7f15cb8" => base64_decode("cGFydA" . "=="), "_bd71c3b5c201fc11" . "db82ed14ce424de5" => base64_decode("aW5fYXJ" . "yYXk="), "te" . "xt" => base64_decode("dGV4" . "dA=="), "_24ca62b" . "4d01cc6d" . "515dfd0b" . "ea4c9d59" . "a" => base64_decode("Y29u" . "dGVu" . "dA=="), "_321258308ef09879cd184188c6cd274" . "4" => base64_decode("dGVybWluYXR" . "lZA=="), "_4ab3bd4dedba7" . "2e68b590ded0d6" . "473ed" => base64_decode("ZmlsZV91cm" . "k="), "_e956b2bd945b591c54805c958" . "2d15a3b" => base64_decode("b3B0" . "aW9u" . "c1td"), "_38f12d8b8c719a8ce0fc2faef" . "c225f35" => base64_decode("YXJyYXlfb" . "WFw"), "_967e161" . "ed500fcf" . "11d56175" . "ec79897d" . "c" => base64_decode("QUkgaXMgbm90IGVuY" . "WJsZWQgZm9yIGFueS" . "Btb2R1bGVz"), "_a7442cd7a4" . "d3c557bf6b6" . "b4b0d724559" => base64_decode("cH" . "Jv" . "bX" . "B0"), "_4c7c6c6c634d167851" . "8c0a4321bc3d76" => base64_decode("Y2h" . "hdA" . "=="), "_655a561f4e34bbdfa745" . "dc13393471b3" => base64_decode("bWltZV" . "90eXBl"), "_7669a8431d" . "2368b1dc095" . "81496aea68e" => base64_decode("Zmlua" . "XNo"), "_e608e5b5c4c34" . "a67ba97ef84c1e" . "16199" => base64_decode("J" . "w" . "=" . "="), "_5159b3572969eca46acd1b2e1418459" . "c" => base64_decode("aW1w" . "bG9k" . "ZQ=="), "_1128df95be7b7b" . "a48e931c0662b15" . "8c1" => base64_decode("Zmx1" . "c2g="), "_7aefd482de788" . "5f4293c2926df2" . "8c235" => base64_decode("anNvbl" . "9lbmNv" . "ZGU="), "_d1071a032215f0eb5c" . "4a8ef175f7049d" => base64_decode("cm" . "9s" . "ZQ" . "=="));
use Claromentis\Core\Ai\Adapters\Vertex\Responses\Text\VertexAiGenerateTextResponse;
use Claromentis\Core\Ai\Ai;
use Claromentis\Core\Ai\AiImageConfiguration;
use Claromentis\Core\Ai\AiPluginInterface;
use Claromentis\Core\Ai\AiResponseInterface;
use Claromentis\Core\Ai\AiTextGenerationConfiguration;
use Claromentis\Core\Ai\Exceptions\AiInvalidRequestException;
use Claromentis\Core\Ai\Exceptions\AiInvalidResponseException;
use Claromentis\Core\Ai\Exceptions\AiServerResponseException;
use Claromentis\Core\Ai\Format\ChatFormatter;
use Claromentis\Core\Ai\Parts\FilePart;
use Claromentis\Core\Ai\Parts\FileUriPart;
use Claromentis\Core\Ai\Parts\InlineFilePart;
use Claromentis\Core\Ai\Parts\PartInterface;
use Claromentis\Core\Ai\Parts\TextPart;
use Claromentis\Core\Ai\Repository\AiChatRepository;
use Claromentis\Core\Config\Config;
use Claromentis\Core\Http\JsonPrettyResponse;
use Claromentis\Core\Http\RequestData;
use Claromentis\Core\Http\ResponseFactory;
use Claromentis\Core\Localization\Lmsg;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Core\TextUtil\ClaText;
use Parsedown;
use RestExBadRequest;
use RestExError;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Throwable;




class RestAiController
{
    
    
    
    
    private Ai $ai;
    
    
    
    
    protected Config $config;
    
    
    
    
    private ResponseFactory $responseFactory;
    
    
    
    
    private ClaText $claText;
    
    
    
    
    private Lmsg $lmsg;
    
    
    
    
    
    
    
    
    public function __construct(Ai $ai, Config $config, ResponseFactory $responseFactory, ClaText $cla_text, Lmsg $lmsg)
    {
        $this->ai = $ai;
        $this->config = $config;
        $this->responseFactory = $responseFactory;
        $this->claText = $cla_text;
        $this->lmsg = $lmsg;
    }
    
    
    
    
    
    
    
    public function generateTextStream(RequestData $requestData) : Response
    {
        $_a7442cd7a4d3c557bf6b6b4b0d724559 = $requestData->get($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_a7442cd7a4d3c557bf6b6b" . "4b0d724559"]);
        $module = $requestData->get($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["mo" . "du" . "le"], $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_4d707fab93bebb00bb" . "e69e8159697c90"]);
        $language = $requestData->get($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["lang" . "uage"]);
        $this->validateModule($module);
        $plugin = $this->ai->getPlugin($module, AiPluginInterface::TYPE_TEXT_GENERATION);
        if ($plugin) {
            $_a7442cd7a4d3c557bf6b6b4b0d724559 = $this->initializeParts($plugin, $language, $_a7442cd7a4d3c557bf6b6b4b0d724559);
        }
        $_f9aef021fb8e50005cc6aa3a9d7e2117 = $this->responseFactory->GetEventStreamResponse(function () use($_a7442cd7a4d3c557bf6b6b4b0d724559) {
            $_e696d5598f94156853fd8b977b8c344c = new Parsedown();
            $_77ab044ee5ed2012c760c0fbb7bd34f9 = $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_4d707fab93bebb00bbe69e8159697c9" . "0"];
            $this->ai->generateTextStream(function (AiResponseInterface $_fd5a3a643834299cbdadfc3540ba0bcb) use($_e696d5598f94156853fd8b977b8c344c, &$_77ab044ee5ed2012c760c0fbb7bd34f9) {
                if ($_fd5a3a643834299cbdadfc3540ba0bcb->hasTerminated()) {
                    $this->flush($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_321258308ef0987" . "9cd184188c6cd274" . "4"]);
                } else {
                    try {
                        $_77ab044ee5ed2012c760c0fbb7bd34f9 .= $_fd5a3a643834299cbdadfc3540ba0bcb->getResponse();
                    } catch (Throwable $throwable) {
                        $this->handleException($throwable);
                    }
                    $this->flush($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_e05e0022a2e5ad34" . "4b9c4a0d3f64e1a5"], $this->claText->SanitizeHtml($_e696d5598f94156853fd8b977b8c344c->text($_77ab044ee5ed2012c760c0fbb7bd34f9)));
                }
            }, $_a7442cd7a4d3c557bf6b6b4b0d724559);
            $this->flush($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7669a84" . "31d2368b" . "1dc09581" . "496aea68" . "e"]);
        });
        return $_f9aef021fb8e50005cc6aa3a9d7e2117;
    }
    
    
    
    
    
    
    
    
    
    public function generateText(RequestData $requestData, SecurityContext $context, SessionInterface $session) : Response
    {
        $_a7442cd7a4d3c557bf6b6b4b0d724559 = $requestData->get($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_a7442cd7a4d3c55" . "7bf6b6b4b0d72455" . "9"]);
        $module = $requestData->get($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["modu" . "le"], $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_4d707fab9" . "3bebb00bbe" . "69e8159697" . "c90"]);
        $language = $requestData->get($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["langua" . "ge"]);
        $metadata = $requestData->get($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_9a122dd9e0" . "255ca418d47" . "3b4ba68f14b"], []);
        $this->validateModule($module);
        $plugin = $this->ai->getPlugin($module, AiPluginInterface::TYPE_TEXT_GENERATION);
        if ($plugin) {
            $_a7442cd7a4d3c557bf6b6b4b0d724559 = $this->initializeParts($plugin, $language, $_a7442cd7a4d3c557bf6b6b4b0d724559, $metadata);
            $plugin->getConfiguration()->setContext($context)->setSession($session);
        }
        try {
            $_fd5a3a643834299cbdadfc3540ba0bcb = $this->ai->generateText($_a7442cd7a4d3c557bf6b6b4b0d724559, $plugin?->getConfiguration());
            if ($plugin) {
                $_fd5a3a643834299cbdadfc3540ba0bcb = $plugin->transformResponse($_fd5a3a643834299cbdadfc3540ba0bcb);
            } else {
                $_fd5a3a643834299cbdadfc3540ba0bcb = $this->claText->SanitizeHtml($_fd5a3a643834299cbdadfc3540ba0bcb);
            }
        } catch (Throwable $throwable) {
            $this->handleException($throwable);
        }
        return $this->responseFactory->GetJsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_24ca62b4d01cc6d515dfd0bea4c9" . "d59a"] => $_fd5a3a643834299cbdadfc3540ba0bcb]);
    }
    
    
    
    
    
    
    
    public function generateImages(RequestData $requestData) : Response
    {
        $_a7442cd7a4d3c557bf6b6b4b0d724559 = $requestData->get($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_a7442cd7a4d3c557bf" . "6b6b4b0d724559"]);
        $options = $requestData->get($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_e956b2bd945b591" . "c54805c9582d15a3" . "b"]);
        if (!$this->ai->isModuleEnabled($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_54faabe694dfa8d05dc6c" . "0827a214f82"])) {
            throw new RestExBadRequest($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_475c4ddf7873ea4e9044df10ae31" . "d01e"]);
        }
        try {
            $_f083878fb61180fbf68ba3a77b8d7de3 = $this->ai->generateImages($_a7442cd7a4d3c557bf6b6b4b0d724559, new AiImageConfiguration($options ?? []));
        } catch (Throwable $throwable) {
            $this->handleException($throwable);
        }
        return $this->responseFactory->GetJsonPrettyResponse([$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_f083878fb61180fbf68ba3a77b8d" . "7de3"] => $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_38f12d8b8c719a8ce0fc2fae" . "fc225f35"](function ($_54faabe694dfa8d05dc6c0827a214f82) {
            return [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_655a561f4e34bbdfa74" . "5dc13393471b3"] => $_54faabe694dfa8d05dc6c0827a214f82->getMimeType(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["d" . "a" . "t" . "a"] => $_54faabe694dfa8d05dc6c0827a214f82->getValue()];
        }, $_f083878fb61180fbf68ba3a77b8d7de3)]);
    }
    
    
    
    
    
    
    
    public function generateChat(?string $id, RequestData $requestData) : JsonPrettyResponse
    {
        $_a82e7c9cba13670954fbe01d604c242a = $requestData->get($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_df34c069de4301" . "1ade22c720a3318" . "f60"], []);
        $module = $requestData->get($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["mo" . "du" . "le"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_4d707fab93be" . "bb00bbe69e815" . "9697c90"]);
        $language = $requestData->get($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["langua" . "ge"]);
        $metadata = $requestData->get($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_9a122dd9e025" . "5ca418d473b4b" . "a68f14b"], []);
        $this->validateModule($module);
        $plugin = $this->ai->getPlugin($module, AiPluginInterface::TYPE_CHAT_GENERATION);
        $_9961f986823b4be7f5c4cc8379c6b228 = [];
        if ($plugin) {
            $_9961f986823b4be7f5c4cc8379c6b228 = $this->initializeParts($plugin, $language, null, $metadata);
        }
        $_9961f986823b4be7f5c4cc8379c6b228 = $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_f73dab60663" . "0b388645c4f7" . "d3fbb13bb"]($_9961f986823b4be7f5c4cc8379c6b228, $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_38f12d8b8c7" . "19a8ce0fc2fa" . "efc225f35"](function ($_9258ac851c9bc3180b251966de4a02bc) {
            if (isset($_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_655a561" . "f4e34bbd" . "fa745dc1" . "3393471b" . "3"]], $_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_d1071a032215f" . "0eb5c4a8ef175f" . "7049d"]])) {
                if (isset($_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["d" . "a" . "t" . "a"]])) {
                    return new InlineFilePart($_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["d" . "a" . "t" . "a"]], $_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_655a561f4e34bb" . "dfa745dc1339347" . "1b3"]], $_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d1071a032215f0eb5c4a" . "8ef175f7049d"]]);
                } else {
                    if (isset($_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_4ab3bd4dedba72e68b590ded" . "0d6473ed"]])) {
                        return new FileUriPart($_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_4ab3bd4dedba72e" . "68b590ded0d6473e" . "d"]], $_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_655a561f4e34bbdfa" . "745dc13393471b3"]], $_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_d1071a03" . "2215f0eb5" . "c4a8ef175" . "f7049d"]]);
                    }
                }
                return null;
            }
            return new TextPart($_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["t" . "e" . "x" . "t"]], $_9258ac851c9bc3180b251966de4a02bc[$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_d1071a032215f0eb5c4a8ef175f70" . "49d"]]);
        }, $_a82e7c9cba13670954fbe01d604c242a));
        try {
            $_fd5a3a643834299cbdadfc3540ba0bcb = $this->ai->generateChat($_9961f986823b4be7f5c4cc8379c6b228, $id, $plugin?->getConfiguration());
            if ($plugin) {
                $_fd5a3a643834299cbdadfc3540ba0bcb = $plugin->transformResponse($_fd5a3a643834299cbdadfc3540ba0bcb);
            } else {
                $_fd5a3a643834299cbdadfc3540ba0bcb = $this->claText->SanitizeHtml($_fd5a3a643834299cbdadfc3540ba0bcb);
            }
        } catch (Throwable $throwable) {
            $this->handleException($throwable);
        }
        return $this->responseFactory->GetJsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_d962cfd1735adb2d" . "fba46f69c7f15cb8"] => [$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_d1071a032215f0eb5c" . "4a8ef175f7049d"] => PartInterface::PART_ROLE_MODEL, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_24ca62b4d01cc6d515dfd0bea4c9d5" . "9a"] => $_fd5a3a643834299cbdadfc3540ba0bcb]]);
    }
    public function chat(string $id, ChatFormatter $formatter, AiChatRepository $repository, SecurityContext $context)
    {
        $_dace5e187fa775d4aabf1747566801d7 = $repository->getChatWithHistory($context, $id);
        if (!$_dace5e187fa775d4aabf1747566801d7) {
            throw new RestExBadRequest(($this->lmsg)($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_c862508fd80f2ba2b8ec" . "b2b75ac53467"]));
        }
        return $this->responseFactory->GetJsonPrettyResponse([$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_4c7c6c6c634d1678518c0a4321bc3" . "d76"] => $formatter->FormatChat($_dace5e187fa775d4aabf1747566801d7)]);
    }
    public function newChat(AiChatRepository $repository, ChatFormatter $formatter, SecurityContext $context)
    {
        $_dace5e187fa775d4aabf1747566801d7 = $repository->newChat($context);
        return $this->responseFactory->GetJsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_4c7c6c6c634d1" . "678518c0a4321b" . "c3d76"] => $formatter->FormatChat($_dace5e187fa775d4aabf1747566801d7)]);
    }
    public function chats(SecurityContext $context, ChatFormatter $formatter, AiChatRepository $repository)
    {
        $_792a339ad0d1fe818084474ec06e4cc1 = $repository->getChats($context);
        return $this->responseFactory->GetJsonPrettyResponse([$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_792a339ad0" . "d1fe8180844" . "74ec06e4cc1"] => $formatter->FormatChats($_792a339ad0d1fe818084474ec06e4cc1)]);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    private function initializeParts(AiPluginInterface $plugin, ?string $languageCode = null, ?string $userPrompt = null, ?array $metadata = null) : ?array
    {
        $_70b52ce74e40801d2c81b11669a461e6 = $this->ai->getSystemPromptParts($plugin, $languageCode, $metadata);
        return $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_ea8229a121285ee649a7" . "2fd880bac39b"]($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_f73dab606630b388645c4f7d3f" . "bb13bb"]($_70b52ce74e40801d2c81b11669a461e6, [new TextPart($userPrompt ?? $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_4d707fab93bebb00bbe69e815969" . "7c90"])]), function ($_59cdb5ce92fcf760d09d3c6ed5b03aaa) {
            return $_59cdb5ce92fcf760d09d3c6ed5b03aaa !== null && !empty($_59cdb5ce92fcf760d09d3c6ed5b03aaa->getValue());
        });
    }
    
    
    
    
    
    
    
    
    private function flush(string $status, string $text = '')
    {
        echo $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_a1b32522d3c9a793e0e4307466" . "b172d9"] . $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7aefd482de7885f4293c29" . "26df28c235"]([$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["sta" . "tus"] => $status, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["te" . "xt"] => $text]) . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_cfab5a4a6804604f4998a7244eba86" . "bd"];
        $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_c2900f14e63513f00ce80edbb04550" . "6c"]();
        $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_1128df95be7b7ba" . "48e931c0662b158c" . "1"]();
    }
    
    
    
    
    
    
    
    
    
    
    private function handleException($throwable) : void
    {
        if ($throwable instanceof AiInvalidRequestException) {
            throw new RestExBadRequest(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_839809c6beb4465bd21e037" . "814ee4683"]), $throwable->getCode(), $throwable);
        } elseif ($throwable instanceof AiInvalidResponseException || $throwable instanceof AiServerResponseException) {
            throw new RestExError(($this->lmsg)($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_eac6791bbe0decdc5761307838b27" . "7de"], $throwable->getCode()), $throwable->getCode(), $throwable);
        }
        throw new RestExError($throwable->getMessage(), $throwable->getCode(), $throwable);
    }
    
    
    
    
    
    
    private function validateModule(string $module) : void
    {
        $_7e868a0f1e76721d67a3c57a1406d916 = $this->ai->getModules();
        if (empty($_7e868a0f1e76721d67a3c57a1406d916)) {
            throw new RestExBadRequest($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_967e161ed500fcf1" . "1d56175ec79897dc"]);
        }
        if (!$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_bd71c3b5" . "c201fc11d" . "b82ed14ce" . "424de5"]($module, $_7e868a0f1e76721d67a3c57a1406d916)) {
            $_de3bcb12af58b547f987c780da4b95d3 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_e608e5b5c4c34a67ba97e" . "f84c1e16199"] . $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_5159b357" . "2969eca46" . "acd1b2e14" . "18459c"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_1ab2691b0149e6c0f5bef2e034d68c" . "11"], $_7e868a0f1e76721d67a3c57a1406d916) . $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_e608e5b5c4c34a67ba" . "97ef84c1e16199"];
            throw new RestExBadRequest($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_b2ffc45fa7bf" . "e7aac72914a57" . "d0f9162"] . $module . $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_8dacf526543" . "365460ea3a88" . "a3a0904a1"] . $_de3bcb12af58b547f987c780da4b95d3);
        }
    }
}