55use Amazeeio \PolydockAppAmazeeioPrivateGpt \Exceptions \AmazeeAiClientException ;
66use Amazeeio \PolydockAppAmazeeioPrivateGpt \Exceptions \AmazeeAiValidationException ;
77use Amazeeio \PolydockAppAmazeeioPrivateGpt \Generated \Dto \AdministratorResponse ;
8+ use Amazeeio \PolydockAppAmazeeioPrivateGpt \Generated \Dto \APIToken ;
89use Amazeeio \PolydockAppAmazeeioPrivateGpt \Generated \Dto \HealthResponse ;
910use Amazeeio \PolydockAppAmazeeioPrivateGpt \Generated \Dto \LlmKeysResponse ;
11+ use Amazeeio \PolydockAppAmazeeioPrivateGpt \Generated \Dto \RegionResponse ;
1012use Amazeeio \PolydockAppAmazeeioPrivateGpt \Generated \Dto \TeamResponse ;
1113use Amazeeio \PolydockAppAmazeeioPrivateGpt \Generated \Dto \VdbKeysResponse ;
1214use 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 );
0 commit comments