@@ -324,64 +324,41 @@ export class GPTScript {
324
324
if ( ! this . ready ) {
325
325
this . ready = await this . testGPTScriptURL ( 20 )
326
326
}
327
- const resp = await fetch ( `${ GPTScript . serverURL } /credentials` , {
328
- method : "POST" ,
329
- body : JSON . stringify ( { context, allContexts} )
330
- } )
331
-
332
- if ( resp . status < 200 || resp . status >= 400 ) {
333
- throw new Error ( `Failed to list credentials: ${ ( await resp . json ( ) ) [ "stderr" ] } ` )
334
- }
335
327
336
- const r = await resp . json ( )
337
- return r [ "stdout" ] . map ( ( c : any ) => jsonToCredential ( JSON . stringify ( c ) ) )
328
+ const r : Run = new RunSubcommand ( "credentials" , "" , { } , GPTScript . serverURL )
329
+ r . request ( { context, allContexts} )
330
+ const out = await r . json ( )
331
+ return out . map ( ( c : any ) => jsonToCredential ( JSON . stringify ( c ) ) )
338
332
}
339
333
340
334
async createCredential ( credential : Credential ) : Promise < void > {
341
335
if ( ! this . ready ) {
342
336
this . ready = await this . testGPTScriptURL ( 20 )
343
337
}
344
- const resp = await fetch ( `${ GPTScript . serverURL } /credentials/create` , {
345
- method : "POST" ,
346
- body : JSON . stringify ( {
347
- content : credentialToJSON ( credential )
348
- } )
349
- } )
350
338
351
- if ( resp . status < 200 || resp . status >= 400 ) {
352
- throw new Error ( `Failed to create credential: ${ ( await resp . json ( ) ) [ "stderr" ] } ` )
353
- }
339
+ const r : Run = new RunSubcommand ( "credentials/create" , "" , { } , GPTScript . serverURL )
340
+ r . request ( { content : credentialToJSON ( credential ) } )
341
+ await r . text ( )
354
342
}
355
343
356
344
async revealCredential ( context : Array < string > , name : string ) : Promise < Credential > {
357
345
if ( ! this . ready ) {
358
346
this . ready = await this . testGPTScriptURL ( 20 )
359
347
}
360
- const resp = await fetch ( `${ GPTScript . serverURL } /credentials/reveal` , {
361
- method : "POST" ,
362
- body : JSON . stringify ( { context, name} )
363
- } )
364
-
365
- if ( resp . status < 200 || resp . status >= 400 ) {
366
- throw new Error ( `Failed to reveal credential: ${ ( await resp . json ( ) ) [ "stderr" ] } ` )
367
- }
368
348
369
- const r = await resp . json ( )
370
- return jsonToCredential ( JSON . stringify ( r [ "stdout" ] ) )
349
+ const r : Run = new RunSubcommand ( "credentials/reveal" , "" , { } , GPTScript . serverURL )
350
+ r . request ( { context, name} )
351
+ return jsonToCredential ( await r . text ( ) )
371
352
}
372
353
373
354
async deleteCredential ( context : string , name : string ) : Promise < void > {
374
355
if ( ! this . ready ) {
375
356
this . ready = await this . testGPTScriptURL ( 20 )
376
357
}
377
- const resp = await fetch ( `${ GPTScript . serverURL } /credentials/delete` , {
378
- method : "POST" ,
379
- body : JSON . stringify ( { context : [ context ] , name} )
380
- } )
381
358
382
- if ( resp . status < 200 || resp . status >= 400 ) {
383
- throw new Error ( `Failed to delete credential: ${ ( await resp . json ( ) ) [ "stderr" ] } ` )
384
- }
359
+ const r : Run = new RunSubcommand ( "credentials/delete" , "" , { } , GPTScript . serverURL )
360
+ r . request ( { context : [ context ] , name } )
361
+ await r . text ( )
385
362
}
386
363
387
364
/**
0 commit comments