Skip to content
Open
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
1 change: 0 additions & 1 deletion app/Integrations/OpenAI/OpenAIConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function resolveBaseUrl(): string
'openai' => 'https://api.openai.com/v1',
'deep_seek' => 'https://api.deepseek.com/v1',
};

}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/Services/ChatAssistant.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\Assistant;
use App\Models\Project;
use App\Tools\ExecuteCommand;
use App\Tools\GetWebsiteContent;
use App\Tools\ListFiles;
use App\Tools\ReadFile;
use App\Tools\UpdateFile;
Expand Down Expand Up @@ -43,6 +44,7 @@ public function __construct(OnBoardingSteps $onBoardingSteps)
UpdateFile::class,
ListFiles::class,
ReadFile::class,
GetWebsiteContent::class
]);
}

Expand Down
27 changes: 27 additions & 0 deletions app/Services/RoachSpider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace App\Services;

use App\Utils\RoachLoggerExtension;
use RoachPHP\Http\Response;
use RoachPHP\Spider\BasicSpider;

class RoachSpider extends BasicSpider
{
/**
* @var string[]
*/
public array $startUrls = [];

public array $extensions = [
RoachLoggerExtension::class,
];

public function parse(Response $response): \Generator
{
$title = $response->filter('body')->text();

yield $this->item([
'title' => $title
]);
}
}
49 changes: 49 additions & 0 deletions app/Tools/GetWebsiteContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Tools;

use App\Attributes\Description;
use App\Services\RoachSpider;
use Exception;

use RoachPHP\Roach;
use RoachPHP\Spider\Configuration\Overrides;
use function Termwind\render;

#[Description('Read content from a website using Laravel Dusk. Use this when you need to scrape content from a web page.')]
final class GetWebsiteContent
{
public function handle(
#[Description('URL of the website to read')]
string $url,
#[Description('CSS selector to target specific content (default: body)')]
?string $selector = 'body',
#[Description('Timeout in seconds for waiting for the selector (default: 60)')]
int $timeout = 60
): string {


try {

$content = Roach::collectSpider(
RoachSpider::class,
new Overrides(startUrls: [$url]),
);

// render(view('tool', [
// 'name' => 'GetWebsiteContent',
// 'output' => $content,
// ]));

return collect($content)->toJson();
} catch (Exception $e) {

render(view('tool', [
'name' => 'Get Website Content',
'output' => $e->getMessage(),
]));

return $e->getMessage();
}
}
}
26 changes: 26 additions & 0 deletions app/Utils/RoachLoggerExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Utils;

use RoachPHP\Events\RunFinished;
use RoachPHP\Extensions\ExtensionInterface;

class RoachLoggerExtension implements ExtensionInterface
{
public static function getSubscribedEvents(): array
{
return [
RunFinished::NAME => ['onRunFinished', 100],
];
}

public function onRunFinished(RunFinished $event): void
{

}

public function configure(array $options): void
{
// TODO: Implement configure() method.
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"illuminate/view": "^11.5",
"laravel-zero/phar-updater": "^1.4",
"openai-php/client": "^0.10.1",
"roach-php/core": "^3.2",
"saloonphp/saloon": "^3.9",
"spatie/laravel-data": "^4.7"
},
Expand Down
Loading