Skip to content

chore: add credential check param field #74

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 2 commits 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
4 changes: 4 additions & 0 deletions gptscript/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self,
ephemeral: bool = False,
expiresAt: datetime = None,
refreshToken: str = "",
checkParam: str = "",
**kwargs,
):
self.context = context
Expand All @@ -31,6 +32,7 @@ def __init__(self,
self.ephemeral = ephemeral
self.expiresAt = expiresAt
self.refreshToken = refreshToken
self.checkParam = checkParam

if self.env is None:
self.env = {}
Expand All @@ -56,6 +58,7 @@ def to_json(self):
"env": self.env,
"ephemeral": self.ephemeral,
"refreshToken": self.refreshToken,
"checkParam": self.checkParam,
}

if datetime_str != "":
Expand Down Expand Up @@ -95,4 +98,5 @@ def to_credential(c) -> Credential:
ephemeral=c.get("ephemeral", False),
expiresAt=expiresAt,
refreshToken=c["refreshToken"],
checkParam=c.get("checkParam", "")
)
6 changes: 4 additions & 2 deletions tests/test_gptscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def tool_list():
name="echo",
tools=["sys.exec"],
description="Echoes the input",
arguments=ArgumentSchema(properties={"input": Property("The string input to echo")}),
arguments=ArgumentSchema(properties={"input": Property(description="The string input to echo")}),
instructions=f"""
${shebang}
echo ${input}
Expand Down Expand Up @@ -742,7 +742,8 @@ async def test_credentials(gptscript):
name = "test-" + str(os.urandom(4).hex())
now = datetime.now()
res = await gptscript.create_credential(
Credential(toolName=name, env={"TEST": "test"}, expiresAt=now + timedelta(seconds=5)))
Credential(toolName=name, env={"TEST": "test"}, expiresAt=now + timedelta(seconds=5),
checkParam="my-check-param"))
assert not res.startswith("an error occurred"), "Unexpected error creating credential: " + res

sleep(5)
Expand All @@ -757,6 +758,7 @@ async def test_credentials(gptscript):
res = await gptscript.reveal_credential(name=name)
assert not str(res).startswith("an error occurred"), "Unexpected error revealing credential: " + res
assert res.env["TEST"] == "test", "Unexpected credential value: " + str(res)
assert res.checkParam == "my-check-param", "Unexpected credential value: " + str(res)

res = await gptscript.delete_credential(name=name)
assert not res.startswith("an error occurred"), "Unexpected error deleting credential: " + res
Expand Down