Skip to content

Commit bddb5a9

Browse files
committed
update for stacked contexts
Signed-off-by: Grant Linville <[email protected]>
1 parent 73aa542 commit bddb5a9

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/gptscript.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class GPTScript {
320320
return this._load({toolDefs, disableCache, subTool})
321321
}
322322

323-
async listCredentials(context: string, allContexts: boolean): Promise<Array<Credential>> {
323+
async listCredentials(context: Array<string>, allContexts: boolean): Promise<Array<Credential>> {
324324
if (!this.ready) {
325325
this.ready = await this.testGPTScriptURL(20)
326326
}
@@ -353,7 +353,7 @@ export class GPTScript {
353353
}
354354
}
355355

356-
async revealCredential(context: string, name: string): Promise<Credential> {
356+
async revealCredential(context: Array<string>, name: string): Promise<Credential> {
357357
if (!this.ready) {
358358
this.ready = await this.testGPTScriptURL(20)
359359
}
@@ -367,7 +367,7 @@ export class GPTScript {
367367
}
368368

369369
const r = await resp.json()
370-
return r["stdout"] as Credential
370+
return jsonToCredential(JSON.stringify(r["stdout"]))
371371
}
372372

373373
async deleteCredential(context: string, name: string): Promise<void> {
@@ -376,7 +376,7 @@ export class GPTScript {
376376
}
377377
const resp = await fetch(`${GPTScript.serverURL}/credentials/delete`, {
378378
method: "POST",
379-
body: JSON.stringify({context, name})
379+
body: JSON.stringify({context: [context], name})
380380
})
381381

382382
if (resp.status < 200 || resp.status >= 400) {

tests/gptscript.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,23 +813,28 @@ describe("gptscript module", () => {
813813
context: "default",
814814
env: {"TEST": value},
815815
ephemeral: false,
816+
expiresAt: new Date(Date.now() + 5000), // 5 seconds from now
816817
type: CredentialType.Tool,
817818
})
818819
} catch (e) {
819820
throw new Error("failed to create credential: " + e)
820821
}
821822

823+
// Wait 5 seconds
824+
await new Promise(resolve => setTimeout(resolve, 5000))
825+
822826
// Reveal
823827
try {
824-
const result = await g.revealCredential("default", name)
828+
const result = await g.revealCredential(["default"], name)
825829
expect(result.env["TEST"]).toEqual(value)
830+
expect(result.expiresAt!.valueOf()).toBeLessThan(new Date().valueOf())
826831
} catch (e) {
827832
throw new Error("failed to reveal credential: " + e)
828833
}
829834

830835
// List
831836
try {
832-
const result = await g.listCredentials("default", false)
837+
const result = await g.listCredentials(["default"], false)
833838
expect(result.length).toBeGreaterThan(0)
834839
expect(result.map(c => c.name)).toContain(name)
835840
} catch (e) {
@@ -845,10 +850,10 @@ describe("gptscript module", () => {
845850

846851
// Verify deletion
847852
try {
848-
const result = await g.listCredentials("default", false)
853+
const result = await g.listCredentials(["default"], false)
849854
expect(result.map(c => c.name)).not.toContain(name)
850855
} catch (e) {
851856
throw new Error("failed to verify deletion: " + e)
852857
}
853-
})
858+
}, 20000)
854859
})

0 commit comments

Comments
 (0)