Skip to content

Commit 305c0b2

Browse files
committed
chore: make credential calls use runBasicCommand
Signed-off-by: Donnie Adams <[email protected]>
1 parent 79a84d1 commit 305c0b2

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/gptscript.ts

+16-22
Original file line numberDiff line numberDiff line change
@@ -366,33 +366,24 @@ export class GPTScript {
366366
}
367367

368368
async createCredential(credential: Credential): Promise<void> {
369-
if (!this.opts.URL) {
370-
await this.testGPTScriptURL(20)
371-
}
372-
373-
const r: Run = new RunSubcommand("credentials/create", "", {URL: this.opts.URL, Token: this.opts.Token})
374-
r.request({content: credentialToJSON(credential)})
375-
await r.text()
369+
await this.runBasicCommand("credentials/create", {
370+
content: credentialToJSON(credential)
371+
})
376372
}
377373

378374
async revealCredential(context: Array<string>, name: string): Promise<Credential> {
379-
if (!this.opts.URL) {
380-
await this.testGPTScriptURL(20)
381-
}
382-
383-
const r: Run = new RunSubcommand("credentials/reveal", "", {URL: this.opts.URL, Token: this.opts.Token})
384-
r.request({context, name})
385-
return jsonToCredential(await r.text())
375+
const resp = await this.runBasicCommand("credentials/reveal", {
376+
context,
377+
name
378+
})
379+
return jsonToCredential(resp)
386380
}
387381

388382
async deleteCredential(context: string, name: string): Promise<void> {
389-
if (!this.opts.URL) {
390-
await this.testGPTScriptURL(20)
391-
}
392-
393-
const r: Run = new RunSubcommand("credentials/delete", "", {URL: this.opts.URL, Token: this.opts.Token})
394-
r.request({context: [context], name})
395-
await r.text()
383+
await this.runBasicCommand("credentials/delete", {
384+
context: [context],
385+
name
386+
})
396387
}
397388

398389
// Dataset methods
@@ -782,7 +773,10 @@ export class Run {
782773
fetch(req).then(resp => {
783774
return resp.json()
784775
}).then(res => {
785-
resolve(res.stdout)
776+
if (typeof res.stdout === "string") {
777+
resolve(res.stdout)
778+
}
779+
resolve(JSON.stringify(res.stdout))
786780
}).catch(e => {
787781
reject(new Error(e))
788782
})

0 commit comments

Comments
 (0)