Skip to content

Commit

Permalink
chore: make credential calls use runBasicCommand
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Oct 24, 2024
1 parent ce1d9f1 commit 4deabc3
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,33 +366,24 @@ export class GPTScript {
}

async createCredential(credential: Credential): Promise<void> {
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<string>, name: string): Promise<Credential> {
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<void> {
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
Expand Down Expand Up @@ -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))
})
Expand Down

0 comments on commit 4deabc3

Please sign in to comment.