@@ -161,7 +161,7 @@ func (g *GPTScript) Parse(ctx context.Context, fileName string, opts ...ParseOpt
161
161
disableCache = disableCache || opt .DisableCache
162
162
}
163
163
164
- out , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"file" : fileName , "disableCache" : disableCache })
164
+ out , _ , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"file" : fileName , "disableCache" : disableCache })
165
165
if err != nil {
166
166
return nil , err
167
167
}
@@ -180,7 +180,7 @@ func (g *GPTScript) Parse(ctx context.Context, fileName string, opts ...ParseOpt
180
180
181
181
// ParseContent will parse the given string into a tool.
182
182
func (g * GPTScript ) ParseContent (ctx context.Context , toolDef string ) ([]Node , error ) {
183
- out , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"content" : toolDef })
183
+ out , _ , err := g .runBasicCommand (ctx , "parse" , map [string ]any {"content" : toolDef })
184
184
if err != nil {
185
185
return nil , err
186
186
}
@@ -203,7 +203,7 @@ func (g *GPTScript) Fmt(ctx context.Context, nodes []Node) (string, error) {
203
203
node .TextNode .combine ()
204
204
}
205
205
206
- out , err := g .runBasicCommand (ctx , "fmt" , Document {Nodes : nodes })
206
+ out , _ , err := g .runBasicCommand (ctx , "fmt" , Document {Nodes : nodes })
207
207
if err != nil {
208
208
return "" , err
209
209
}
@@ -241,7 +241,7 @@ func (g *GPTScript) load(ctx context.Context, payload map[string]any, opts ...Lo
241
241
}
242
242
}
243
243
244
- out , err := g .runBasicCommand (ctx , "load" , payload )
244
+ out , _ , err := g .runBasicCommand (ctx , "load" , payload )
245
245
if err != nil {
246
246
return nil , err
247
247
}
@@ -260,7 +260,7 @@ func (g *GPTScript) load(ctx context.Context, payload map[string]any, opts ...Lo
260
260
261
261
// Version will return the output of `gptscript --version`
262
262
func (g * GPTScript ) Version (ctx context.Context ) (string , error ) {
263
- out , err := g .runBasicCommand (ctx , "version" , nil )
263
+ out , _ , err := g .runBasicCommand (ctx , "version" , nil )
264
264
if err != nil {
265
265
return "" , err
266
266
}
@@ -285,7 +285,7 @@ func (g *GPTScript) ListModels(ctx context.Context, opts ...ListModelsOptions) (
285
285
o .Providers = append (o .Providers , g .globalOpts .DefaultModelProvider )
286
286
}
287
287
288
- out , err := g .runBasicCommand (ctx , "list-models" , map [string ]any {
288
+ out , _ , err := g .runBasicCommand (ctx , "list-models" , map [string ]any {
289
289
"providers" : o .Providers ,
290
290
"env" : g .globalOpts .Env ,
291
291
"credentialOverrides" : o .CredentialOverrides ,
@@ -298,12 +298,12 @@ func (g *GPTScript) ListModels(ctx context.Context, opts ...ListModelsOptions) (
298
298
}
299
299
300
300
func (g * GPTScript ) Confirm (ctx context.Context , resp AuthResponse ) error {
301
- _ , err := g .runBasicCommand (ctx , "confirm/" + resp .ID , resp )
301
+ _ , _ , err := g .runBasicCommand (ctx , "confirm/" + resp .ID , resp )
302
302
return err
303
303
}
304
304
305
305
func (g * GPTScript ) PromptResponse (ctx context.Context , resp PromptResponse ) error {
306
- _ , err := g .runBasicCommand (ctx , "prompt-response/" + resp .ID , resp .Responses )
306
+ _ , _ , err := g .runBasicCommand (ctx , "prompt-response/" + resp .ID , resp .Responses )
307
307
return err
308
308
}
309
309
@@ -315,7 +315,7 @@ func (g *GPTScript) ListCredentials(ctx context.Context, credCtxs []string, allC
315
315
req .Context = credCtxs
316
316
}
317
317
318
- out , err := g .runBasicCommand (ctx , "credentials" , req )
318
+ out , _ , err := g .runBasicCommand (ctx , "credentials" , req )
319
319
if err != nil {
320
320
return nil , err
321
321
}
@@ -333,12 +333,12 @@ func (g *GPTScript) CreateCredential(ctx context.Context, cred Credential) error
333
333
return fmt .Errorf ("failed to marshal credential: %w" , err )
334
334
}
335
335
336
- _ , err = g .runBasicCommand (ctx , "credentials/create" , CredentialRequest {Content : string (credJSON )})
336
+ _ , _ , err = g .runBasicCommand (ctx , "credentials/create" , CredentialRequest {Content : string (credJSON )})
337
337
return err
338
338
}
339
339
340
340
func (g * GPTScript ) RevealCredential (ctx context.Context , credCtxs []string , name string ) (Credential , error ) {
341
- out , err := g .runBasicCommand (ctx , "credentials/reveal" , CredentialRequest {
341
+ out , _ , err := g .runBasicCommand (ctx , "credentials/reveal" , CredentialRequest {
342
342
Context : credCtxs ,
343
343
Name : name ,
344
344
})
@@ -353,15 +353,25 @@ func (g *GPTScript) RevealCredential(ctx context.Context, credCtxs []string, nam
353
353
return cred , nil
354
354
}
355
355
356
- func (g * GPTScript ) DeleteCredential (ctx context.Context , credCtx , name string ) error {
357
- _ , err := g .runBasicCommand (ctx , "credentials/delete" , CredentialRequest {
356
+ // DeleteCredential will delete the credential with the given name in the given context.
357
+ // A return value of false, nil indicates that the credential was not found.
358
+ // false, non-nil error indicates a different error when trying to delete.
359
+ // true, nil indicates a successful deletion.
360
+ func (g * GPTScript ) DeleteCredential (ctx context.Context , credCtx , name string ) (bool , error ) {
361
+ _ , code , err := g .runBasicCommand (ctx , "credentials/delete" , CredentialRequest {
358
362
Context : []string {credCtx }, // Only one context can be specified for delete operations
359
363
Name : name ,
360
364
})
361
- return err
365
+ if err != nil {
366
+ if code == 404 {
367
+ return false , nil
368
+ }
369
+ return false , err
370
+ }
371
+ return true , nil
362
372
}
363
373
364
- func (g * GPTScript ) runBasicCommand (ctx context.Context , requestPath string , body any ) (string , error ) {
374
+ func (g * GPTScript ) runBasicCommand (ctx context.Context , requestPath string , body any ) (string , int , error ) {
365
375
run := & Run {
366
376
url : g .url ,
367
377
requestPath : requestPath ,
@@ -370,18 +380,18 @@ func (g *GPTScript) runBasicCommand(ctx context.Context, requestPath string, bod
370
380
}
371
381
372
382
if err := run .request (ctx , body ); err != nil {
373
- return "" , err
383
+ return "" , run . responseCode , err
374
384
}
375
385
376
386
out , err := run .Text ()
377
387
if err != nil {
378
- return "" , err
388
+ return "" , run . responseCode , err
379
389
}
380
390
if run .err != nil {
381
- return run .ErrorOutput (), run .err
391
+ return run .ErrorOutput (), run .responseCode , run . err
382
392
}
383
393
384
- return out , nil
394
+ return out , run . responseCode , nil
385
395
}
386
396
387
397
func getCommand () string {
0 commit comments