From 4deabc35dd6b1ba9ceb364d3a2b06da7901952ce Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Thu, 24 Oct 2024 15:03:18 -0400 Subject: [PATCH] chore: make credential calls use runBasicCommand Signed-off-by: Donnie Adams --- src/gptscript.ts | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/gptscript.ts b/src/gptscript.ts index 1e5ade5..6a81ead 100644 --- a/src/gptscript.ts +++ b/src/gptscript.ts @@ -366,33 +366,24 @@ export class GPTScript { } async createCredential(credential: Credential): Promise { - if (!this.opts.URL) { - await this.testGPTScriptURL(20) - } - - const r: Run = new RunSubcommand("credentials/create", "", {URL: this.opts.URL, Token: this.opts.Token}) - r.request({content: credentialToJSON(credential)}) - await r.text() + await this.runBasicCommand("credentials/create", { + content: credentialToJSON(credential) + }) } async revealCredential(context: Array, name: string): Promise { - if (!this.opts.URL) { - await this.testGPTScriptURL(20) - } - - const r: Run = new RunSubcommand("credentials/reveal", "", {URL: this.opts.URL, Token: this.opts.Token}) - r.request({context, name}) - return jsonToCredential(await r.text()) + const resp = await this.runBasicCommand("credentials/reveal", { + context, + name + }) + return jsonToCredential(resp) } async deleteCredential(context: string, name: string): Promise { - if (!this.opts.URL) { - await this.testGPTScriptURL(20) - } - - const r: Run = new RunSubcommand("credentials/delete", "", {URL: this.opts.URL, Token: this.opts.Token}) - r.request({context: [context], name}) - await r.text() + await this.runBasicCommand("credentials/delete", { + context: [context], + name + }) } // Dataset methods @@ -782,7 +773,10 @@ export class Run { fetch(req).then(resp => { return resp.json() }).then(res => { - resolve(res.stdout) + if (typeof res.stdout === "string") { + resolve(res.stdout) + } + resolve(JSON.stringify(res.stdout)) }).catch(e => { reject(new Error(e)) })