Skip to content
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

feat: add stacked credential contexts #849

Merged
merged 9 commits into from
Sep 18, 2024

Conversation

g-linville
Copy link
Member

@g-linville g-linville commented Sep 16, 2024

This implements the concept of "stacked" credential contexts. (Reminder: a credential context is basically just a namespace for credentials in the creds store.)

For more details on how this works, see the section that I added to the docs in this PR.

Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville marked this pull request as draft September 16, 2024 19:11
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
@@ -64,7 +64,7 @@ type GPTScript struct {
Chdir string `usage:"Change current working directory" short:"C"`
Daemon bool `usage:"Run tool as a daemon" local:"true" hidden:"true"`
Ports string `usage:"The port range to use for ephemeral daemon ports (ex: 11000-12000)" hidden:"true"`
CredentialContext string `usage:"Context name in which to store credentials" default:"default"`
Copy link
Member Author

@g-linville g-linville Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our cmd library doesn't support default values for slices, which is why I removed the default tag here.

Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville changed the title WIP: stacked credential contexts feat: stacked credential contexts Sep 16, 2024
@g-linville g-linville marked this pull request as ready for review September 16, 2024 20:55
@g-linville g-linville marked this pull request as draft September 16, 2024 20:56
Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville marked this pull request as ready for review September 16, 2024 22:31
@g-linville g-linville changed the title feat: stacked credential contexts feat: add stacked credential contexts Sep 16, 2024
Comment on lines 49 to 50
} else if len(ctxs) == 0 {
ctxs = []string{credentials.DefaultCredentialContext}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few places where you have added this logic. Can this logic be moved to the Complete function for the gptscript options instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it already is in the Complete function in the gptscript/gptscript.go file. But without it in places like this, the c.root.CredentialContext still ends up being empty when the user doesn't specify anything. Not sure why that's the case. Should I be manually calling the Complete function here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this isn't working as I expect, then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a longer look at this: instead of completing the entire opts (created on line 53), we are completing individual pieces of it (lines 55 and 56).

It would be better to complete everything instead of the individual pieces, but I won't hold up merging this based on that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, that worked. Thanks. I should have spent more time looking at this myself, lol

@@ -58,7 +58,7 @@ type toolOrFileRequest struct {
ChatState string `json:"chatState"`
Workspace string `json:"workspace"`
Env []string `json:"env"`
CredentialContext string `json:"credentialContext"`
CredentialContext []string `json:"credentialContext"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this as a string in the API to not break backwards compatibility Split in the implementation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darren specifically asked me to change this in the API. My SDK changes haven't been merged yet so this isn't really a breaking change, since nothing should be using it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a breaking change because older versions of the SDK won't work with the newer versions.

If Darren specifically asked for it, then that's fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhhh I just noticed that this is in the "toolOrFileRequest" and not in the Credentials struct. My bad. You are correct about this

pkg/credentials/store.go Outdated Show resolved Hide resolved
pkg/credentials/store.go Outdated Show resolved Hide resolved
Signed-off-by: Grant Linville <[email protected]>
@g-linville
Copy link
Member Author

The tests are failing right now only because the download links for Node.js are apparently down

thedadams
thedadams previously approved these changes Sep 17, 2024
StrongMonkey
StrongMonkey previously approved these changes Sep 17, 2024
Signed-off-by: Grant Linville <[email protected]>
@g-linville g-linville merged commit 780e07e into gptscript-ai:main Sep 18, 2024
10 checks passed
@g-linville g-linville deleted the stacked-credential-contexts branch September 18, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants