@@ -188,7 +188,7 @@ func (a *subAgentAPIClient) List(ctx context.Context) ([]SubAgent, error) {
188
188
return agents , nil
189
189
}
190
190
191
- func (a * subAgentAPIClient ) Create (ctx context.Context , agent SubAgent ) (SubAgent , error ) {
191
+ func (a * subAgentAPIClient ) Create (ctx context.Context , agent SubAgent ) (_ SubAgent , err error ) {
192
192
a .logger .Debug (ctx , "creating sub agent" , slog .F ("name" , agent .Name ), slog .F ("directory" , agent .Directory ))
193
193
194
194
displayApps := make ([]agentproto.CreateSubAgentRequest_DisplayApp , 0 , len (agent .DisplayApps ))
@@ -233,19 +233,27 @@ func (a *subAgentAPIClient) Create(ctx context.Context, agent SubAgent) (SubAgen
233
233
if err != nil {
234
234
return SubAgent {}, err
235
235
}
236
+ defer func () {
237
+ if err != nil {
238
+ // Best effort.
239
+ _ , _ = a .api .DeleteSubAgent (ctx , & agentproto.DeleteSubAgentRequest {
240
+ Id : resp .GetAgent ().GetId (),
241
+ })
242
+ }
243
+ }()
236
244
237
- agent .Name = resp .Agent . Name
238
- agent .ID , err = uuid .FromBytes (resp .Agent . Id )
245
+ agent .Name = resp .GetAgent (). GetName ()
246
+ agent .ID , err = uuid .FromBytes (resp .GetAgent (). GetId () )
239
247
if err != nil {
240
- return agent , err
248
+ return SubAgent {} , err
241
249
}
242
- agent .AuthToken , err = uuid .FromBytes (resp .Agent . AuthToken )
250
+ agent .AuthToken , err = uuid .FromBytes (resp .GetAgent (). GetAuthToken () )
243
251
if err != nil {
244
- return agent , err
252
+ return SubAgent {} , err
245
253
}
246
254
247
- for _ , appError := range resp .AppCreationErrors {
248
- app := apps [appError .Index ]
255
+ for _ , appError := range resp .GetAppCreationErrors () {
256
+ app := apps [appError .GetIndex () ]
249
257
250
258
a .logger .Warn (ctx , "unable to create app" ,
251
259
slog .F ("agent_name" , agent .Name ),
0 commit comments