Skip to content

Commit a9e7fe5

Browse files
authored
Merge pull request #6 from amazeeio/feature-devmode
Feature devmode
2 parents 79124c5 + 3d53e9e commit a9e7fe5

29 files changed

+766
-324
lines changed

docs/INTEGRATION_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The following variables must be configured in your Polydock Store:
5454
#### amazee.ai Direct API Configuration
5555
- `amazee-ai-api-key`: Your amazee.ai API key
5656
- `amazee-ai-api-url`: amazee.ai API URL (defaults to 'https://api.amazee.ai')
57-
- `amazee-ai-admin-email`: Email address for team administrator
57+
- `user-email`: Email address for team administrator - this comes from the polydock registration payload
5858

5959
## PrivateGPT Application Requirements
6060

generate-dtos.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
'User' => 'AdministratorResponse',
2323
'PrivateAIKey' => 'LlmKeysResponse', // for LLM keys
2424
'LiteLLMToken' => 'VdbKeysResponse', // for VDB keys
25+
'Region' => 'RegionResponse',
26+
'APIToken' => 'APIToken',
2527
];
2628

2729
function phpType($propSchema, $isNullable = false): string
@@ -48,7 +50,8 @@ function phpType($propSchema, $isNullable = false): string
4850
$format = $propSchema['format'] ?? null;
4951

5052
$type = match ($openApiType) {
51-
'string' => $format === 'date-time' ? '\DateTimeInterface' : 'string',
53+
// 'string' => $format === 'date-time' ? '\DateTimeInterface' : 'string',
54+
'string' => 'string',
5255
'integer' => 'int',
5356
'number' => 'float',
5457
'boolean' => 'bool',
@@ -127,24 +130,7 @@ public function __construct(
127130
/**
128131
* Health status
129132
*/
130-
public string $status,
131-
/**
132-
* Timestamp
133-
*/
134-
public string $timestamp,
135-
/**
136-
* API version
137-
*/
138-
public string $version,
139-
/**
140-
* Uptime in seconds
141-
*/
142-
public int $uptime,
143-
/**
144-
* Service status details
145-
* @var array<string, mixed>|null
146-
*/
147-
public ?array $services = null
133+
public string $status
148134
) {}
149135
}
150136
PHP;

generate_routemap.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
include 'vendor/autoload.php';
4+
5+
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Routemap\Routemapper;
6+
7+
var_dump(Routemapper::base64encodedRoutes(132, 'aaiprivategpt-testingroutes1'));
8+
9+
// $command = 'lagoon list deploytargets --output-json'; // Replace with the actual command
10+
// $output = null;
11+
// $returnVar = null;
12+
// exec($command, $output, $returnVar);
13+
14+
// if ($returnVar === 0) {
15+
// $jsonString = implode("\n", $output);
16+
// $data = json_decode($jsonString, true);
17+
// if (json_last_error() === JSON_ERROR_NONE) {
18+
19+
// if (isset($data['data']) && is_array($data['data'])) {
20+
// foreach ($data['data'] as $item) {
21+
// // Example: print each field
22+
// echo 'ID: '.$item['id']."\n";
23+
// echo 'Name: '.$item['name']."\n";
24+
// echo 'Console URL: '.$item['consoleurl']."\n";
25+
// echo 'SSH Host: '.$item['sshhost']."\n";
26+
// echo 'SSH Port: '.$item['sshport']."\n";
27+
// echo 'Build Image: '.$item['buildimage']."\n";
28+
// echo 'Router Pattern: '.$item['routerpattern']."\n";
29+
// echo "-----------------------------\n";
30+
// }
31+
// } else {
32+
// echo "No data found.\n";
33+
// }
34+
// } else {
35+
// echo 'Failed to parse JSON: '.json_last_error_msg()."\n";
36+
// }
37+
// } else {
38+
// echo "Command failed with exit code $returnVar\n";
39+
// }

src/Client/AmazeeAiClient.php

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Exceptions\AmazeeAiClientException;
66
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Exceptions\AmazeeAiValidationException;
77
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Dto\AdministratorResponse;
8+
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Dto\APIToken;
89
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Dto\HealthResponse;
910
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Dto\LlmKeysResponse;
11+
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Dto\RegionResponse;
1012
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Dto\TeamResponse;
1113
use Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Dto\VdbKeysResponse;
1214
use CuyZ\Valinor\Mapper\MappingError;
@@ -43,6 +45,7 @@ public function __construct(string $apiKey, string $apiUrl = 'https://api.amazee
4345
$this->mapper = (new MapperBuilder)
4446
->allowSuperfluousKeys()
4547
->allowPermissiveTypes()
48+
->allowUndefinedValues() // To handle missing nullable fields gracefully
4649
->mapper();
4750
}
4851

@@ -70,7 +73,7 @@ private function mapResponse(string $className, array $data): object
7073
public function createTeam(string $name, string $adminEmail): TeamResponse
7174
{
7275
try {
73-
$response = $this->httpClient->request('POST', '/v1/teams', [
76+
$response = $this->httpClient->request('POST', '/teams', [
7477
'json' => [
7578
'name' => $name,
7679
'admin_email' => $adminEmail,
@@ -89,21 +92,107 @@ public function createTeam(string $name, string $adminEmail): TeamResponse
8992
}
9093
}
9194

92-
public function addTeamAdministrator(string $teamId, string $email): AdministratorResponse
95+
// Adding this simply for downstream convenience.
96+
public function deleteTeam(string $teamId): string
9397
{
9498
try {
95-
$response = $this->httpClient->request('POST', "/v1/teams/{$teamId}/administrators", [
99+
$response = $this->httpClient->request('DELETE', "/teams/{$teamId}");
100+
101+
$data = json_decode($response->getBody()->getContents(), true);
102+
103+
return $data['message'];
104+
} catch (RequestException $e) {
105+
throw new AmazeeAiClientException(
106+
'Failed to delete team: '.$e->getMessage(),
107+
$e->getCode(),
108+
$e
109+
);
110+
}
111+
}
112+
113+
// public function addTeamAdministrator(string $teamId, string $email): AdministratorResponse
114+
// {
115+
// try {
116+
// $response = $this->httpClient->request('POST', "/teams/{$teamId}/administrators", [
117+
// 'json' => [
118+
// 'email' => $email,
119+
// ],
120+
// ]);
121+
122+
// $data = json_decode($response->getBody()->getContents(), true);
123+
124+
// return $this->mapResponse(AdministratorResponse::class, $data);
125+
// } catch (RequestException $e) {
126+
// throw new AmazeeAiClientException(
127+
// 'Failed to add team administrator: '.$e->getMessage(),
128+
// $e->getCode(),
129+
// $e
130+
// );
131+
// }
132+
// }
133+
134+
/**
135+
* @return RegionResponse[]
136+
*/
137+
public function getRegions(): array
138+
{
139+
try {
140+
$response = $this->httpClient->request('GET', '/regions');
141+
142+
$data = json_decode($response->getBody()->getContents(), true);
143+
144+
// Assuming $data is an array of regions
145+
return array_map(
146+
fn ($region) => $this->mapResponse(RegionResponse::class, $region),
147+
$data
148+
);
149+
} catch (RequestException $e) {
150+
throw new AmazeeAiClientException(
151+
'Failed to get regions: '.$e->getMessage(),
152+
$e->getCode(),
153+
$e
154+
);
155+
}
156+
}
157+
158+
public function createBackendKey(int $teamId): APIToken
159+
{
160+
try {
161+
$response = $this->httpClient->request('POST', '/auth/token', [
96162
'json' => [
97-
'email' => $email,
163+
'name' => sprintf('private-gpt-backend-%d', $teamId),
98164
],
99165
]);
100166

101167
$data = json_decode($response->getBody()->getContents(), true);
102168

103-
return $this->mapResponse(AdministratorResponse::class, $data);
169+
return $this->mapResponse(APIToken::class, $data);
104170
} catch (RequestException $e) {
105171
throw new AmazeeAiClientException(
106-
'Failed to add team administrator: '.$e->getMessage(),
172+
'Failed to generate backend key: '.$e->getMessage(),
173+
$e->getCode(),
174+
$e
175+
);
176+
}
177+
}
178+
179+
public function createLlmKey(int $teamId, int $regionId): LlmKeysResponse
180+
{
181+
try {
182+
$response = $this->httpClient->request('POST', '/private-ai-keys/token', [
183+
'json' => [
184+
'team_id' => $teamId,
185+
'region_id' => $regionId,
186+
'name' => sprintf('llm-%d-%d', $regionId, $teamId),
187+
],
188+
]);
189+
190+
$data = json_decode($response->getBody()->getContents(), true);
191+
192+
return $this->mapResponse(LlmKeysResponse::class, $data);
193+
} catch (RequestException $e) {
194+
throw new AmazeeAiClientException(
195+
'Failed to generate LLM keys: '.$e->getMessage(),
107196
$e->getCode(),
108197
$e
109198
);

src/Generated/Dto/APIToken.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Amazeeio\PolydockAppAmazeeioPrivateGpt\Generated\Dto;
4+
5+
/**
6+
* APIToken
7+
*
8+
* Auto-generated from OpenAPI specification. Do not edit manually.
9+
*
10+
* @see https://api.amazee.ai/openapi.json
11+
*/
12+
final readonly class APIToken
13+
{
14+
public function __construct(
15+
/**
16+
* Name
17+
*/
18+
public string $name,
19+
/**
20+
* Id
21+
*/
22+
public int $id,
23+
/**
24+
* Token
25+
*/
26+
public string $token,
27+
/**
28+
* Created At
29+
*/
30+
public string $created_at,
31+
/**
32+
* User Id
33+
*/
34+
public int $user_id,
35+
/**
36+
* Last Used At
37+
*/
38+
public ?string $last_used_at = null
39+
) {}
40+
}

src/Generated/Dto/AdministratorResponse.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* AdministratorResponse
77
*
88
* Auto-generated from OpenAPI specification. Do not edit manually.
9+
*
910
* @see https://api.amazee.ai/openapi.json
1011
*/
1112
final readonly class AdministratorResponse
@@ -40,4 +41,4 @@ public function __construct(
4041
*/
4142
public ?string $role = null
4243
) {}
43-
}
44+
}

src/Generated/Dto/HealthResponse.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* HealthResponse
77
*
88
* Auto-generated from OpenAPI specification. Do not edit manually.
9+
*
910
* @see https://api.amazee.ai/openapi.json
1011
*/
1112
final readonly class HealthResponse
@@ -14,23 +15,6 @@ public function __construct(
1415
/**
1516
* Health status
1617
*/
17-
public string $status,
18-
/**
19-
* Timestamp
20-
*/
21-
public string $timestamp,
22-
/**
23-
* API version
24-
*/
25-
public string $version,
26-
/**
27-
* Uptime in seconds
28-
*/
29-
public int $uptime,
30-
/**
31-
* Service status details
32-
* @var array<string, mixed>|null
33-
*/
34-
public ?array $services = null
18+
public string $status
3519
) {}
36-
}
20+
}

src/Generated/Dto/LlmKeysResponse.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* LlmKeysResponse
77
*
88
* Auto-generated from OpenAPI specification. Do not edit manually.
9+
*
910
* @see https://api.amazee.ai/openapi.json
1011
*/
1112
final readonly class LlmKeysResponse
@@ -50,7 +51,7 @@ public function __construct(
5051
/**
5152
* Created At
5253
*/
53-
public ?\DateTimeInterface $created_at = null,
54+
public ?string $created_at = null,
5455
/**
5556
* Owner Id
5657
*/
@@ -60,4 +61,4 @@ public function __construct(
6061
*/
6162
public ?int $team_id = null
6263
) {}
63-
}
64+
}

0 commit comments

Comments
 (0)