Skip to content

chore: add credential check param field #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ export type Credential = {
ephemeral: boolean
expiresAt?: Date | undefined
refreshToken?: string | undefined
checkParam?: string | undefined
}

// Types for OpenAI API-compatible models
Expand Down Expand Up @@ -1277,6 +1278,7 @@ type cred = {
ephemeral: boolean
expiresAt: string | undefined
refreshToken: string | undefined
checkParam: string | undefined
}

export function credentialToJSON(c: Credential): string {
Expand All @@ -1289,7 +1291,8 @@ export function credentialToJSON(c: Credential): string {
env: c.env,
ephemeral: c.ephemeral,
expiresAt: expiresAt,
refreshToken: c.refreshToken
refreshToken: c.refreshToken,
checkParam: c.checkParam
} as cred)
}

Expand All @@ -1302,7 +1305,8 @@ function jsonToCredential(cred: string): Credential {
env: c.env,
ephemeral: c.ephemeral,
expiresAt: c.expiresAt ? new Date(c.expiresAt) : undefined,
refreshToken: c.refreshToken
refreshToken: c.refreshToken,
checkParam: c.checkParam
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/gptscript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ describe("gptscript module", () => {
ephemeral: false,
expiresAt: new Date(Date.now() + 5000), // 5 seconds from now
type: CredentialType.Tool,
checkParam: "my-check-param",
})
} catch (e) {
throw new Error("failed to create credential: " + e)
Expand All @@ -856,6 +857,8 @@ describe("gptscript module", () => {
const result = await g.revealCredential(["default"], name)
expect(result.env["TEST"]).toEqual(value)
expect(result.expiresAt!.valueOf()).toBeLessThan(new Date().valueOf())
expect(result.type).toEqual(CredentialType.Tool)
expect(result.checkParam).toEqual("my-check-param")
} catch (e) {
throw new Error("failed to reveal credential: " + e)
}
Expand Down