A PHP SDK for the Polyscope API, built in a Laravel-friendly style.
composer require beyondcode/polyscopeuse Polyscope\Laravel\Polyscope;
$polyscope = new Polyscope('your-api-token');
$servers = $polyscope->servers();
$repositories = $polyscope->repositories();
$workspaces = $polyscope->workspaces();
// Create a workspace directly from a repository resource.
$workspace = $repositories[0]->createWorkspace([
'prompt' => 'Fix the login flow',
'server_id' => 'srv-1', // optional
]);
// Or use a prompt string shorthand.
$workspace = $repositories[0]->createWorkspace('Fix the login flow');If no token is passed, the SDK automatically falls back to Polyscope's local settings file and reads authToken.
By default it checks:
~/.polyscope/settings.json~/Library/Application Support/com.getpolyscope.app/settings.json~/.config/com.getpolyscope.app/settings.json%APPDATA%/com.getpolyscope.app/settings.json
You can override this with:
POLYSCOPE_SETTINGS_PATH=/custom/path/settings.jsonIf you need a custom base URL:
$polyscope = (new Polyscope())
->setBaseUrl('https://your-polyscope-instance.com')
->setApiToken('your-api-token');The SDK auto-registers a service provider. Add credentials to config/services.php:
'polyscope' => [
'token' => env('POLYSCOPE_TOKEN'),
'url' => env('POLYSCOPE_URL', 'https://getpolyscope.com'),
],Then use the facade:
use Polyscope\Laravel\Facades\Polyscope;
$workspace = Polyscope::createWorkspace([
'repository_id' => 'repo-1',
'prompt' => 'Fix the login flow and add tests',
]);- Servers:
servers() - Repositories:
repositories() - Workspaces:
workspaces(),createWorkspace(),workspace(),deleteWorkspace() - Workspace messages:
workspaceMessages(),sendWorkspaceMessage() - Workspace actions:
workspaceDiff(),commitWorkspace(),createWorkspacePullRequest(),stopWorkspace()
The SDK maps common HTTP/API failures to typed exceptions:
ValidationExceptionAuthenticationExceptionForbiddenExceptionNotFoundExceptionRateLimitExceededExceptionServerOfflineExceptionServerTimeoutExceptionApiException
Example:
use Polyscope\Laravel\Exceptions\ValidationException;
try {
$polyscope->createWorkspace(['prompt' => 'Missing repository_id']);
} catch (ValidationException $e) {
$errors = $e->errors();
}composer test