Skip to content

Commit c2ce5c2

Browse files
committed
Initial commit
0 parents  commit c2ce5c2

File tree

17 files changed

+431
-0
lines changed

17 files changed

+431
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
vendor
3+
composer.lock

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Contributing
2+
============
3+
4+
This repository follows the [CakeDC Plugin Standard](https://www.cakedc.com/plugin-standard).
5+
If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our [Contribution Guidelines](https://www.cakedc.com/contribution-guidelines) for detailed instructions.

LICENSE.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
The MIT License
2+
3+
Copyright 2009-2019
4+
Cake Development Corporation
5+
1785 E. Sahara Avenue, Suite 490-423
6+
Las Vegas, Nevada 89104
7+
Phone: +1 702 425 5085
8+
https://www.cakedc.com
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in
18+
all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# DebugKit AI Panel for CakePHP
2+
3+
## Installation
4+
* composer require cakedc/cakephp-debugkit-ai
5+
* Add `DebugKit.AI.apiKey` to your `app_local.php`
6+
* Load plugin in `Application::bootstrap()` and ensure it is done before loading `DebugKit` plugin:
7+
8+
```php
9+
public function bootstrap(): void
10+
{
11+
...
12+
$this->addPlugin(DebugKitAIPlugin::class, ['bootstrap' => true]);
13+
$this->addPlugin('DebugKit', ['bootstrap' => true]);
14+
...
15+
}
16+
```
17+
18+
## TODO
19+
20+
* HTML help

composer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "cakedc/cakephp-debugkit-ai",
3+
"description": "DebugKit AI enhancements",
4+
"autoload": {
5+
"psr-4": {
6+
"CakeDC\\DebugKitAI\\": "src/"
7+
}
8+
},
9+
"require": {
10+
"php": ">8.2",
11+
"google-gemini-php/client": "^2.6",
12+
"cakephp/cakephp": "^5.0"
13+
}
14+
}

config/debugkit_ai.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
return [
4+
'DebugKit' => [
5+
'AI' => [
6+
'client' => \CakeDC\DebugKitAI\Client\Gemini::class,
7+
'model' => 'gemini-2.5-flash',
8+
'excludedPanels' => ['AI']
9+
],
10+
'panels' => [
11+
'CakeDC/DebugKitAI.AI' => true
12+
],
13+
],
14+
];

src/Client/AbstractClient.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace CakeDC\DebugKitAI\Client;
4+
5+
use CakeDC\DebugKitAI\Enum\Prompt;
6+
7+
abstract class AbstractClient
8+
{
9+
10+
public abstract function sendPrompt(Prompt $prompt, string $info): string;
11+
12+
}

src/Client/Gemini.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace CakeDC\DebugKitAI\Client;
4+
5+
use Cake\Core\Configure;
6+
use CakeDC\DebugKitAI\Enum\Prompt;
7+
8+
class Gemini extends AbstractClient
9+
{
10+
11+
/**
12+
* @param Prompt $prompt
13+
* @param string $info
14+
* @return string
15+
*/
16+
public function sendPrompt(Prompt $prompt, string $info): string
17+
{
18+
$client = \Gemini::client(Configure::read('DebugKit.AI.apiKey'));
19+
$prompt = sprintf($prompt->getTemplate(), $info);
20+
$result = $client->generativeModel(Configure::read('DebugKit.AI.model'))->generateContent($prompt);
21+
22+
return $result->text();
23+
}
24+
}

src/Controller/AppController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace CakeDC\DebugKitAI\Controller;
5+
6+
use App\Controller\AppController as BaseController;
7+
8+
class AppController extends BaseController
9+
{
10+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace CakeDC\DebugKitAI\Controller;
5+
6+
use App\Controller\AppController;
7+
use Cake\Cache\Cache;
8+
use Cake\Core\Configure;
9+
use CakeDC\DebugKitAI\Client\AbstractClient;
10+
use CakeDC\DebugKitAI\Enum\Prompt;
11+
12+
/**
13+
* Requests Controller
14+
*
15+
*/
16+
class RequestsController extends AppController
17+
{
18+
public function htmlHelp()
19+
{
20+
//TODO
21+
}
22+
public function debugKitHelp()
23+
{
24+
$request = $this->getTableLocator()->get('DebugKit.Requests')->find()->contain(['Panels'])->orderByDesc('requested_at')->first();
25+
$panels = [];
26+
foreach ($request->panels as $panel) {
27+
if (in_array($panel->panel, Configure::read('DebugKit.AI.excludedPanels'))) continue;
28+
$panels[$panel->panel] = [
29+
'summary' => $panel->summary,
30+
'content' => $panel->content
31+
];
32+
}
33+
$json = json_encode($panels);
34+
35+
$response = Cache::remember("DebugKitAI.requests.{$request->id}.debugKitHelp.response", function () use ($json) {
36+
$clientClass = Configure::read('DebugKit.AI.client');
37+
/** @var AbstractClient $client */
38+
$client = new $clientClass();
39+
40+
return $client->sendPrompt(Prompt::ANALYZE_DEBUGKIT_DATA, $json);
41+
});
42+
43+
$this->viewBuilder()->disableAutoLayout();
44+
$this->viewBuilder()->setTemplate('help');
45+
$this->set('response', $response);
46+
47+
}
48+
}

0 commit comments

Comments
 (0)