Skip to content

Commit 2ed44c0

Browse files
committed
PR feedback
Signed-off-by: Grant Linville <[email protected]>
1 parent f0e2a46 commit 2ed44c0

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

src/gptscript.ts

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -324,64 +324,41 @@ export class GPTScript {
324324
if (!this.ready) {
325325
this.ready = await this.testGPTScriptURL(20)
326326
}
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-
}
335327

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)))
338332
}
339333

340334
async createCredential(credential: Credential): Promise<void> {
341335
if (!this.ready) {
342336
this.ready = await this.testGPTScriptURL(20)
343337
}
344-
const resp = await fetch(`${GPTScript.serverURL}/credentials/create`, {
345-
method: "POST",
346-
body: JSON.stringify({
347-
content: credentialToJSON(credential)
348-
})
349-
})
350338

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()
354342
}
355343

356344
async revealCredential(context: Array<string>, name: string): Promise<Credential> {
357345
if (!this.ready) {
358346
this.ready = await this.testGPTScriptURL(20)
359347
}
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-
}
368348

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())
371352
}
372353

373354
async deleteCredential(context: string, name: string): Promise<void> {
374355
if (!this.ready) {
375356
this.ready = await this.testGPTScriptURL(20)
376357
}
377-
const resp = await fetch(`${GPTScript.serverURL}/credentials/delete`, {
378-
method: "POST",
379-
body: JSON.stringify({context: [context], name})
380-
})
381358

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()
385362
}
386363

387364
/**

0 commit comments

Comments
 (0)