From 5912c46f9d6d91572449bf63597271474f790fa5 Mon Sep 17 00:00:00 2001 From: hardcod3r Date: Thu, 17 Apr 2025 23:56:33 +0300 Subject: [PATCH 1/3] Added GenAI support: ai/agents resource --- composer.json | 2 +- src/Api/GenAi/Agent.php | 34 +++++++++++++++++++++++++ src/Api/GenAi/AgentRelationship.php | 24 ++++++++++++++++++ src/Api/GenAi/AnthropicKey.php | 39 +++++++++++++++++++++++++++++ src/Api/GenAi/IndexingJob.php | 14 +++++++++++ src/Api/GenAi/KnowledgeBase.php | 29 +++++++++++++++++++++ src/Api/GenAi/OpenAiKey.php | 39 +++++++++++++++++++++++++++++ src/Client.php | 39 +++++++++++++++++++++++++++++ vendor-bin/phpstan/composer.json | 11 -------- vendor-bin/phpunit/composer.json | 9 ------- vendor-bin/psalm/composer.json | 9 ------- 11 files changed, 219 insertions(+), 30 deletions(-) create mode 100644 src/Api/GenAi/Agent.php create mode 100644 src/Api/GenAi/AgentRelationship.php create mode 100644 src/Api/GenAi/AnthropicKey.php create mode 100644 src/Api/GenAi/IndexingJob.php create mode 100644 src/Api/GenAi/KnowledgeBase.php create mode 100644 src/Api/GenAi/OpenAiKey.php delete mode 100644 vendor-bin/phpstan/composer.json delete mode 100644 vendor-bin/phpunit/composer.json delete mode 100644 vendor-bin/psalm/composer.json diff --git a/composer.json b/composer.json index e4ce9bb..8950013 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "toin0u/digitalocean-v2", + "name": "hardcod3r/do-client", "description": "DigitalOcean API v2 client for PHP", "keywords": ["DigitalOcean", "API", "Cloud Hosting", "SSD", "VPS"], "license": "MIT", diff --git a/src/Api/GenAi/Agent.php b/src/Api/GenAi/Agent.php new file mode 100644 index 0000000..8671308 --- /dev/null +++ b/src/Api/GenAi/Agent.php @@ -0,0 +1,34 @@ +get('gen-ai/agents'); + } + + public function create(array $data): stdClass + { + return $this->post('gen-ai/agents', $data); + } + + public function retrieve(string $uuid): stdClass + { + return $this->get("gen-ai/agents/{$uuid}"); + } + + public function update(string $uuid, array $data): stdClass + { + return $this->put("gen-ai/agents/{$uuid}", $data); + } + + public function destroy(string $uuid): void + { + $this->delete("gen-ai/agents/{$uuid}"); + } +} diff --git a/src/Api/GenAi/AgentRelationship.php b/src/Api/GenAi/AgentRelationship.php new file mode 100644 index 0000000..5469ac0 --- /dev/null +++ b/src/Api/GenAi/AgentRelationship.php @@ -0,0 +1,24 @@ +get("gen-ai/agents/{$uuid}/child_agents"); + } + + public function attach(string $parentUuid, string $childUuid): stdClass + { + return $this->post("gen-ai/agents/{$parentUuid}/child_agents/{$childUuid}"); + } + + public function detach(string $parentUuid, string $childUuid): void + { + $this->delete("gen-ai/agents/{$parentUuid}/child_agents/{$childUuid}"); + } +} diff --git a/src/Api/GenAi/AnthropicKey.php b/src/Api/GenAi/AnthropicKey.php new file mode 100644 index 0000000..e26a002 --- /dev/null +++ b/src/Api/GenAi/AnthropicKey.php @@ -0,0 +1,39 @@ +get('gen-ai/anthropic/keys'); + } + + public function create(array $data): stdClass + { + return $this->post('gen-ai/anthropic/keys', $data); + } + + public function retrieve(string $uuid): stdClass + { + return $this->get("gen-ai/anthropic/keys/{$uuid}"); + } + + public function update(string $uuid, array $data): stdClass + { + return $this->put("gen-ai/anthropic/keys/{$uuid}", $data); + } + + public function destroy(string $uuid): void + { + $this->delete("gen-ai/anthropic/keys/{$uuid}"); + } + + public function listAgents(string $uuid): stdClass + { + return $this->get("gen-ai/anthropic/keys/{$uuid}/agents"); + } +} diff --git a/src/Api/GenAi/IndexingJob.php b/src/Api/GenAi/IndexingJob.php new file mode 100644 index 0000000..4bf03f6 --- /dev/null +++ b/src/Api/GenAi/IndexingJob.php @@ -0,0 +1,14 @@ +get('gen-ai/indexing_jobs'); + } +} diff --git a/src/Api/GenAi/KnowledgeBase.php b/src/Api/GenAi/KnowledgeBase.php new file mode 100644 index 0000000..bd40d6e --- /dev/null +++ b/src/Api/GenAi/KnowledgeBase.php @@ -0,0 +1,29 @@ +get('gen-ai/knowledge_bases'); + } + + public function create(array $data): stdClass + { + return $this->post('gen-ai/knowledge_bases', $data); + } + + public function retrieve(string $uuid): stdClass + { + return $this->get("gen-ai/knowledge_bases/{$uuid}"); + } + + public function destroy(string $uuid): void + { + $this->delete("gen-ai/knowledge_bases/{$uuid}"); + } +} diff --git a/src/Api/GenAi/OpenAiKey.php b/src/Api/GenAi/OpenAiKey.php new file mode 100644 index 0000000..b89212d --- /dev/null +++ b/src/Api/GenAi/OpenAiKey.php @@ -0,0 +1,39 @@ +get('gen-ai/openai/keys'); + } + + public function create(array $data): stdClass + { + return $this->post('gen-ai/openai/keys', $data); + } + + public function retrieve(string $uuid): stdClass + { + return $this->get("gen-ai/openai/keys/{$uuid}"); + } + + public function update(string $uuid, array $data): stdClass + { + return $this->put("gen-ai/openai/keys/{$uuid}", $data); + } + + public function destroy(string $uuid): void + { + $this->delete("gen-ai/openai/keys/{$uuid}"); + } + + public function listAgents(string $uuid): stdClass + { + return $this->get("gen-ai/openai/keys/{$uuid}/agents"); + } +} diff --git a/src/Client.php b/src/Client.php index b9a90af..81e51fa 100644 --- a/src/Client.php +++ b/src/Client.php @@ -37,6 +37,13 @@ use DigitalOceanV2\Api\Tag; use DigitalOceanV2\Api\Volume; use DigitalOceanV2\Api\Vpc; +use DigitalOceanV2\Api\GenAi\Agent; +use DigitalOceanV2\Api\GenAi\AgentRelationship; +use DigitalOceanV2\Api\GenAi\OpenAiKey; +use DigitalOceanV2\Api\GenAi\AnthropicKey; +use DigitalOceanV2\Api\GenAi\KnowledgeBase; +use DigitalOceanV2\Api\GenAi\IndexingJob; + use DigitalOceanV2\HttpClient\Builder; use DigitalOceanV2\HttpClient\Message\ResponseMediator; use DigitalOceanV2\HttpClient\Plugin\Authentication; @@ -213,6 +220,38 @@ public function vpc(): Vpc return new Vpc($this); } + public function genAiAgent(): Agent + { + return new Agent($this); + } + + public function genAiAgentRelationships(): AgentRelationship + { + return new AgentRelationship($this); + } + + public function genAiOpenAiKeys(): OpenAiKey + { + return new OpenAiKey($this); + } + + public function genAiAnthropicKeys(): AnthropicKey + { + return new AnthropicKey($this); + } + + public function genAiKnowledgeBases(): KnowledgeBase + { + return new KnowledgeBase($this); + } + + public function genAiIndexingJobs(): IndexingJob + { + return new IndexingJob($this); + } + + + public function authenticate(string $token): void { $this->getHttpClientBuilder()->addPlugin(new Authentication($token)); diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json deleted file mode 100644 index a1bd73c..0000000 --- a/vendor-bin/phpstan/composer.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "require": { - "php": "^8.1", - "phpstan/phpstan": "2.1.6", - "phpstan/phpstan-deprecation-rules": "2.0.1", - "phpstan/phpstan-strict-rules": "2.0.3" - }, - "config": { - "preferred-install": "dist" - } -} diff --git a/vendor-bin/phpunit/composer.json b/vendor-bin/phpunit/composer.json deleted file mode 100644 index 21464a1..0000000 --- a/vendor-bin/phpunit/composer.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "require": { - "php": "^8.1", - "phpunit/phpunit": "^10.5.45 || ^11.5.9" - }, - "config": { - "preferred-install": "dist" - } -} diff --git a/vendor-bin/psalm/composer.json b/vendor-bin/psalm/composer.json deleted file mode 100644 index feebf50..0000000 --- a/vendor-bin/psalm/composer.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "require": { - "php": "^8.1", - "psalm/phar": "5.26.1" - }, - "config": { - "preferred-install": "dist" - } -} From 5654964e521352c11afa6929b7448862b7271e6e Mon Sep 17 00:00:00 2001 From: hardcod3r Date: Fri, 18 Apr 2025 00:12:30 +0300 Subject: [PATCH 2/3] Added GenAI Entities --- src/Api/GenAi/Agent.php | 35 +++++++++++++++------ src/Api/GenAi/AnthropicKey.php | 49 ++++++++++++++++++++++-------- src/Api/GenAi/IndexingJob.php | 18 ++++++++--- src/Api/GenAi/KnowledgeBase.php | 30 +++++++++++++----- src/Api/GenAi/OpenAiKey.php | 48 +++++++++++++++++++++-------- src/Entity/GenAi/Agent.php | 30 ++++++++++++++++++ src/Entity/GenAi/AnthropicKey.php | 28 +++++++++++++++++ src/Entity/GenAi/IndexingJob.php | 28 +++++++++++++++++ src/Entity/GenAi/KnowledgeBase.php | 26 ++++++++++++++++ src/Entity/GenAi/OpenAiKey.php | 28 +++++++++++++++++ 10 files changed, 275 insertions(+), 45 deletions(-) create mode 100644 src/Entity/GenAi/Agent.php create mode 100644 src/Entity/GenAi/AnthropicKey.php create mode 100644 src/Entity/GenAi/IndexingJob.php create mode 100644 src/Entity/GenAi/KnowledgeBase.php create mode 100644 src/Entity/GenAi/OpenAiKey.php diff --git a/src/Api/GenAi/Agent.php b/src/Api/GenAi/Agent.php index 8671308..00fca8c 100644 --- a/src/Api/GenAi/Agent.php +++ b/src/Api/GenAi/Agent.php @@ -1,30 +1,47 @@ -get('gen-ai/agents'); + $response = $this->get('gen-ai/agents'); + + return array_map( + fn ($agent) => new AgentEntity($agent), + $response->agents + ); } - public function create(array $data): stdClass + public function create(array $data): AgentEntity { - return $this->post('gen-ai/agents', $data); + $response = $this->post('gen-ai/agents', $data); + + return new AgentEntity($response->agent); } - public function retrieve(string $uuid): stdClass + public function retrieve(string $uuid): AgentEntity { - return $this->get("gen-ai/agents/{$uuid}"); + $response = $this->get("gen-ai/agents/{$uuid}"); + + return new AgentEntity($response->agent); } - public function update(string $uuid, array $data): stdClass + public function update(string $uuid, array $data): AgentEntity { - return $this->put("gen-ai/agents/{$uuid}", $data); + $response = $this->put("gen-ai/agents/{$uuid}", $data); + + return new AgentEntity($response->agent); } public function destroy(string $uuid): void diff --git a/src/Api/GenAi/AnthropicKey.php b/src/Api/GenAi/AnthropicKey.php index e26a002..e3f0c6e 100644 --- a/src/Api/GenAi/AnthropicKey.php +++ b/src/Api/GenAi/AnthropicKey.php @@ -1,30 +1,47 @@ -get('gen-ai/anthropic/keys'); + $response = $this->get('gen-ai/anthropic/keys'); + + return array_map( + fn ($key) => new AnthropicKeyEntity($key), + $response->keys + ); } - public function create(array $data): stdClass + public function create(array $data): AnthropicKeyEntity { - return $this->post('gen-ai/anthropic/keys', $data); + $response = $this->post('gen-ai/anthropic/keys', $data); + + return new AnthropicKeyEntity($response->key); } - public function retrieve(string $uuid): stdClass + public function retrieve(string $uuid): AnthropicKeyEntity { - return $this->get("gen-ai/anthropic/keys/{$uuid}"); + $response = $this->get("gen-ai/anthropic/keys/{$uuid}"); + + return new AnthropicKeyEntity($response->key); } - public function update(string $uuid, array $data): stdClass + public function update(string $uuid, array $data): AnthropicKeyEntity { - return $this->put("gen-ai/anthropic/keys/{$uuid}", $data); + $response = $this->put("gen-ai/anthropic/keys/{$uuid}", $data); + + return new AnthropicKeyEntity($response->key); } public function destroy(string $uuid): void @@ -32,8 +49,16 @@ public function destroy(string $uuid): void $this->delete("gen-ai/anthropic/keys/{$uuid}"); } - public function listAgents(string $uuid): stdClass + /** + * @return AgentEntity[] + */ + public function listAgents(string $uuid): array { - return $this->get("gen-ai/anthropic/keys/{$uuid}/agents"); + $response = $this->get("gen-ai/anthropic/keys/{$uuid}/agents"); + + return array_map( + fn ($agent) => new AgentEntity($agent), + $response->agents + ); } } diff --git a/src/Api/GenAi/IndexingJob.php b/src/Api/GenAi/IndexingJob.php index 4bf03f6..3f48455 100644 --- a/src/Api/GenAi/IndexingJob.php +++ b/src/Api/GenAi/IndexingJob.php @@ -1,14 +1,24 @@ -get('gen-ai/indexing_jobs'); + $response = $this->get('gen-ai/indexing_jobs'); + + return array_map( + fn ($job) => new IndexingJobEntity($job), + $response->indexing_jobs + ); } } diff --git a/src/Api/GenAi/KnowledgeBase.php b/src/Api/GenAi/KnowledgeBase.php index bd40d6e..241937a 100644 --- a/src/Api/GenAi/KnowledgeBase.php +++ b/src/Api/GenAi/KnowledgeBase.php @@ -1,25 +1,39 @@ -get('gen-ai/knowledge_bases'); + $response = $this->get('gen-ai/knowledge_bases'); + + return array_map( + fn ($kb) => new KnowledgeBaseEntity($kb), + $response->knowledge_bases + ); } - public function create(array $data): stdClass + public function create(array $data): KnowledgeBaseEntity { - return $this->post('gen-ai/knowledge_bases', $data); + $response = $this->post('gen-ai/knowledge_bases', $data); + + return new KnowledgeBaseEntity($response->knowledge_base); } - public function retrieve(string $uuid): stdClass + public function retrieve(string $uuid): KnowledgeBaseEntity { - return $this->get("gen-ai/knowledge_bases/{$uuid}"); + $response = $this->get("gen-ai/knowledge_bases/{$uuid}"); + + return new KnowledgeBaseEntity($response->knowledge_base); } public function destroy(string $uuid): void diff --git a/src/Api/GenAi/OpenAiKey.php b/src/Api/GenAi/OpenAiKey.php index b89212d..583cc7b 100644 --- a/src/Api/GenAi/OpenAiKey.php +++ b/src/Api/GenAi/OpenAiKey.php @@ -1,30 +1,46 @@ -get('gen-ai/openai/keys'); + $response = $this->get('gen-ai/openai/keys'); + + return array_map( + fn ($key) => new OpenAiKeyEntity($key), + $response->keys + ); } - public function create(array $data): stdClass + public function create(array $data): OpenAiKeyEntity { - return $this->post('gen-ai/openai/keys', $data); + $response = $this->post('gen-ai/openai/keys', $data); + + return new OpenAiKeyEntity($response->key); } - public function retrieve(string $uuid): stdClass + public function retrieve(string $uuid): OpenAiKeyEntity { - return $this->get("gen-ai/openai/keys/{$uuid}"); + $response = $this->get("gen-ai/openai/keys/{$uuid}"); + + return new OpenAiKeyEntity($response->key); } - public function update(string $uuid, array $data): stdClass + public function update(string $uuid, array $data): OpenAiKeyEntity { - return $this->put("gen-ai/openai/keys/{$uuid}", $data); + $response = $this->put("gen-ai/openai/keys/{$uuid}", $data); + + return new OpenAiKeyEntity($response->key); } public function destroy(string $uuid): void @@ -32,8 +48,16 @@ public function destroy(string $uuid): void $this->delete("gen-ai/openai/keys/{$uuid}"); } - public function listAgents(string $uuid): stdClass + /** + * @return AgentEntity[] + */ + public function listAgents(string $uuid): array { - return $this->get("gen-ai/openai/keys/{$uuid}/agents"); + $response = $this->get("gen-ai/openai/keys/{$uuid}/agents"); + + return array_map( + fn ($agent) => new \DigitalOceanV2\Entity\GenAi\Agent($agent), + $response->agents + ); } } diff --git a/src/Entity/GenAi/Agent.php b/src/Entity/GenAi/Agent.php new file mode 100644 index 0000000..f6aebba --- /dev/null +++ b/src/Entity/GenAi/Agent.php @@ -0,0 +1,30 @@ +createdAt = static::convertToIso8601($value); + } + + public function setUpdatedAt(string $value): void + { + $this->updatedAt = static::convertToIso8601($value); + } +} diff --git a/src/Entity/GenAi/AnthropicKey.php b/src/Entity/GenAi/AnthropicKey.php new file mode 100644 index 0000000..1fd7bb3 --- /dev/null +++ b/src/Entity/GenAi/AnthropicKey.php @@ -0,0 +1,28 @@ +createdAt = static::convertToIso8601($value); + } + + public function setUpdatedAt(string $value): void + { + $this->updatedAt = static::convertToIso8601($value); + } +} diff --git a/src/Entity/GenAi/IndexingJob.php b/src/Entity/GenAi/IndexingJob.php new file mode 100644 index 0000000..a49c50a --- /dev/null +++ b/src/Entity/GenAi/IndexingJob.php @@ -0,0 +1,28 @@ +createdAt = static::convertToIso8601($value); + } + + public function setCompletedAt(?string $value): void + { + if ($value !== null) { + $this->completedAt = static::convertToIso8601($value); + } + } +} diff --git a/src/Entity/GenAi/KnowledgeBase.php b/src/Entity/GenAi/KnowledgeBase.php new file mode 100644 index 0000000..42b1315 --- /dev/null +++ b/src/Entity/GenAi/KnowledgeBase.php @@ -0,0 +1,26 @@ +createdAt = static::convertToIso8601($value); + } + + public function setUpdatedAt(string $value): void + { + $this->updatedAt = static::convertToIso8601($value); + } +} diff --git a/src/Entity/GenAi/OpenAiKey.php b/src/Entity/GenAi/OpenAiKey.php new file mode 100644 index 0000000..7862b80 --- /dev/null +++ b/src/Entity/GenAi/OpenAiKey.php @@ -0,0 +1,28 @@ +createdAt = static::convertToIso8601($value); + } + + public function setUpdatedAt(string $value): void + { + $this->updatedAt = static::convertToIso8601($value); + } +} From e16039177be09e4cf27554c7d9485a1397b83cd6 Mon Sep 17 00:00:00 2001 From: hardcod3r Date: Fri, 18 Apr 2025 00:18:19 +0300 Subject: [PATCH 3/3] Added Extended Readme --- digitalocean-genai-sdk-summary.md | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 digitalocean-genai-sdk-summary.md diff --git a/digitalocean-genai-sdk-summary.md b/digitalocean-genai-sdk-summary.md new file mode 100644 index 0000000..88b4cd9 --- /dev/null +++ b/digitalocean-genai-sdk-summary.md @@ -0,0 +1,77 @@ +# DigitalOcean GenAI Laravel SDK Extension (Entity-Based) + +## ✅ Supported Resources & Endpoints + +--- + +### 🧠 Agents (`Agent.php` / `AgentEntity.php`) +- `GET /v2/gen-ai/agents` → `all(): Agent[]` +- `POST /v2/gen-ai/agents` → `create(array): Agent` +- `GET /v2/gen-ai/agents/{uuid}` → `retrieve(string): Agent` +- `PUT /v2/gen-ai/agents/{uuid}` → `update(string, array): Agent` +- `DELETE /v2/gen-ai/agents/{uuid}` → `destroy(string): void` + +--- + +### 🔗 Agent Relationships (`AgentRelationship.php`) +- `GET /v2/gen-ai/agents/{uuid}/child_agents` → `list(string): Agent[]` +- `POST /v2/gen-ai/agents/{parent}/child_agents/{child}` → `attach(parent, child): Agent` +- `DELETE /v2/gen-ai/agents/{parent}/child_agents/{child}` → `detach(parent, child): void` + +--- + +### 🔑 OpenAI Keys (`OpenAiKey.php` / `OpenAiKeyEntity.php`) +- `GET /v2/gen-ai/openai/keys` → `all(): OpenAiKey[]` +- `POST /v2/gen-ai/openai/keys` → `create(array): OpenAiKey` +- `GET /v2/gen-ai/openai/keys/{uuid}` → `retrieve(string): OpenAiKey` +- `PUT /v2/gen-ai/openai/keys/{uuid}` → `update(string, array): OpenAiKey` +- `DELETE /v2/gen-ai/openai/keys/{uuid}` → `destroy(string): void` +- `GET /v2/gen-ai/openai/keys/{uuid}/agents` → `listAgents(string): Agent[]` + +--- + +### 👤 Anthropic Keys (`AnthropicKey.php` / `AnthropicKeyEntity.php`) +- `GET /v2/gen-ai/anthropic/keys` → `all(): AnthropicKey[]` +- `POST /v2/gen-ai/anthropic/keys` → `create(array): AnthropicKey` +- `GET /v2/gen-ai/anthropic/keys/{uuid}` → `retrieve(string): AnthropicKey` +- `PUT /v2/gen-ai/anthropic/keys/{uuid}` → `update(string, array): AnthropicKey` +- `DELETE /v2/gen-ai/anthropic/keys/{uuid}` → `destroy(string): void` +- `GET /v2/gen-ai/anthropic/keys/{uuid}/agents` → `listAgents(string): Agent[]` + +--- + +### 📚 Knowledge Bases (`KnowledgeBase.php` / `KnowledgeBaseEntity.php`) +- `GET /v2/gen-ai/knowledge_bases` → `all(): KnowledgeBase[]` +- `POST /v2/gen-ai/knowledge_bases` → `create(array): KnowledgeBase` +- `GET /v2/gen-ai/knowledge_bases/{uuid}` → `retrieve(string): KnowledgeBase` +- `DELETE /v2/gen-ai/knowledge_bases/{uuid}` → `destroy(string): void` + +--- + +### 🔍 Indexing Jobs (`IndexingJob.php` / `IndexingJobEntity.php`) +- `GET /v2/gen-ai/indexing_jobs` → `all(): IndexingJob[]` + +--- + +## 🧩 Binding Summary (`Client.php`) + +```php +$client->genAiAgent(); +$client->genAiAgentRelationships(); +$client->genAiOpenAiKeys(); +$client->genAiAnthropicKeys(); +$client->genAiKnowledgeBases(); +$client->genAiIndexingJobs(); +``` + +--- + +## 📦 Entities Implemented + +- `Agent` +- `OpenAiKey` +- `AnthropicKey` +- `KnowledgeBase` +- `IndexingJob` + +All extend `AbstractEntity` and use `setCreatedAt()`, `setUpdatedAt()`, etc. for normalization. \ No newline at end of file