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(server, builder): OAuth support + API key management + GitHub blocks #8044

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

Pwuts
Copy link
Member

@Pwuts Pwuts commented Sep 12, 2024

Changes 🏗️

Config

  • For Supabase, the back end needs SUPABASE_URL, SUPABASE_SERVICE_KEY, and SUPABASE_JWT_SECRET
    • SUPABASE_SERVICE_KEY must be a service role key as the anon key doesn't have sufficient privileges for the operations it's used for
  • For the GitHub integration to work, the back end needs GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET

Front end

UI components

  • CredentialsInput for use on CustomNode: allows user to add/select credentials for a service.
    • APIKeyCredentialsModal: a dialog for creating API keys
    • OAuth2FlowWaitingModal: a dialog to indicate that the application is waiting for the user to log in to the 3rd party service in the provided pop-up window
  • NodeCredentialsInput: wrapper for CredentialsInput with the "usual" interface of node input components
  • New icons: IconKey, IconKeyPlus, IconUser, IconUserPlus

Data model

  • CredentialsProvider: introduces the app-level CredentialsProvidersContext, which acts as an application-wide store and cache for credentials metadata.
  • useCredentials for use on CustomNode: uses CredentialsProvidersContext and provides node-specific credential data and provider-specific data/functions
  • /auth/integrations/oauth_callback route to close the loop to the CredentialsInput after a user completes sign-in to the external service
  • Add BlockIOCredentialsSubSchema

API client

  • Add isAuthenticated method
  • Add methods for integration OAuth flow: oAuthLogin, oAuthCallback
  • Add CRD methods for credentials: createAPIKeyCredentials, listCredentials, getCredentials, deleteCredentials
  • Add mirrored types CredentialsMetaResponse, CredentialsMetaInput, OAuth2Credentials, APIKeyCredentials

REST API

  • Tweak output of OAuth /login endpoint: add state_token separately in response
  • Add POST /integrations/{provider}/credentials (for API keys)
  • Add DELETE /integrations/{provider}/credentials/{cred_id}

Back end

  • Add Supabase support to AppService
  • Add FRONTEND_BASE_URL config option, mainly for local development use

autogpt_libs.supabase_integration_credentials_store

  • Add CredentialsType alias
  • Add .bearer() helper methods to APIKeyCredentials and OAuth2Credentials

Blocks

  • Add CredentialsField(..) -> CredentialsMetaInput
  • Add GitHub blocks + "DEVELOPER_TOOLS" category
  • Add **kwargs to Block.run(..) signature to support additional kwargs

Executor

  • Add strict support for credentials fields on blocks
  • Fetch credentials for graph execution and pass them down through to the node execution

PR Quality Scorecard ✨

  • Have you used the PR description template?   +2 pts
  • Is your pull request atomic, focusing on a single change?   +5 pts
  • Have you linked the GitHub issue(s) that this PR addresses?   +5 pts
  • Have you documented your changes clearly and comprehensively?   +5 pts
  • Have you changed or added a feature?   -4 pts
    • Have you added/updated corresponding documentation?   +4 pts
    • Have you added/updated corresponding integration tests?   +5 pts
  • Have you changed the behavior of AutoGPT?   -5 pts
    • Have you also run agbenchmark to verify that these changes do not regress performance?   +10 pts

Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@github-actions github-actions bot added conflicts Automatically applied to PRs with merge conflicts documentation Improvements or additions to documentation Server size/xl and removed conflicts Automatically applied to PRs with merge conflicts labels Sep 12, 2024
Copy link

netlify bot commented Sep 12, 2024

Deploy Preview for auto-gpt-docs canceled.

Name Link
🔨 Latest commit 6aea79b
🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/66ec5dbef6a1020008f2e971

@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Sep 12, 2024
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

Copy link
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Sep 12, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

ugh, how about making a blocks/github directory and splitting this up a bit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can do later. For now it's easier to mass-edit them if they're all in one file.

@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label Sep 14, 2024
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Sep 16, 2024
Copy link
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

@github-actions github-actions bot added the Builder AutoGPT Builder label Sep 18, 2024
Copy link
Contributor

Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.

@github-actions github-actions bot removed the conflicts Automatically applied to PRs with merge conflicts label Sep 18, 2024
Pwuts and others added 3 commits September 19, 2024 00:05
## Front end
### UI components
- `CredentialsInput` for use on `CustomNode`: allows user to add/select credentials for a service.
  - `APIKeyCredentialsModal`: a dialog for creating API keys
  - `OAuth2FlowWaitingModal`: a dialog to indicate that the application is waiting for the user to log in to the 3rd party service in the provided pop-up window
- `NodeCredentialsInput`: wrapper for `CredentialsInput` with the "usual" interface of node input components

### Data model
- `CredentialsProvider`: introduces the app-level `CredentialsProvidersContext`, which acts as an application-wide store and cache for credentials metadata.
- `useCredentials` for use on `CustomNode`: uses `CredentialsProvidersContext` and provides node-specific credential data and provider-specific data/functions
- `/auth/integrations/oauth_callback` route to close the loop to the `CredentialsInput` after a user completes sign-in to the external service

### API client
- Add `oAuthLogin`, `oAuthCallback` methods
- Add types `BlockIOCredentialsSubSchema`, `CredentialsMetaInput`
- Add `isAuthenticated` method

## REST API
- Tweak output of OAuth `/login` endpoint: add `state_token` separately in response

## Back end
- Add `required_scopes` param to `CredentialsField` (`credentials_scopes` in schema)
- Add scope requirement (`repo` in all cases) to all GitHub blocks
- Add `FRONTEND_BASE_URL` config option, mainly for local development use.

---------

Co-authored-by: Reinier van der Leer <[email protected]>
@Pwuts Pwuts marked this pull request as ready for review September 19, 2024 02:16
@Pwuts Pwuts requested a review from a team as a code owner September 19, 2024 02:16
@Pwuts Pwuts requested review from Bentlybro and aarushik93 and removed request for a team September 19, 2024 02:16
@Pwuts
Copy link
Member Author

Pwuts commented Sep 19, 2024

If you read this, this PR works :)

@Pwuts Pwuts changed the title feat(server, builder): Add GitHub blocks with OAuth support feat(server, builder): OAuth support + API key management + GitHub blocks Sep 19, 2024
@aarushik93
Copy link
Contributor

@Pwuts how do I run this PR? Are there config settings for supabase needed?

@Pwuts
Copy link
Member Author

Pwuts commented Sep 19, 2024

@aarushik93 I have updated the description with additional config instructions:

  • For Supabase, the back end now needs SUPABASE_URL, SUPABASE_KEY, and SUPABASE_JWT_SECRET
    • SUPABASE_KEY must be a service role key as the anon key doesn't have sufficient privileges for the operations it's used for
  • For the GitHub integration to work, the back end now needs GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET

@aarushik93
Copy link
Contributor

Thanks could you please add the new envrionment variables (SUPABASE_KEY) to the appropriate places in the .env.example and docker compose please?

@@ -84,7 +84,7 @@ Follow these steps to create and test a new block:
5. **Implement the `run` method with error handling:**, this should contain the main logic of the block:

Copy link
Contributor

@aarushik93 aarushik93 Sep 19, 2024

Choose a reason for hiding this comment

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

For the GitHub integration to work, the back end now needs GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET

In the docs and readme, can we add a section for "integration blocks" or wtv we are calling them and start adding this kind of information about configuring them?

Copy link
Member Author

@Pwuts Pwuts Sep 19, 2024

Choose a reason for hiding this comment

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

Done: 74138d7

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 didn't update the README because:

  • I want to avoid duplicating documentation
  • The extra stuff for credentials technically fits within the summary instructions for adding blocks that's currently in the README

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks - what about also adding somewhere - where I go to find client id and secret and API key?
I was thinking we'd just have a subsection somewhere in docs for each integration that just tells you where to go

Copy link
Contributor

Choose a reason for hiding this comment

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

cause rn I can't find exactly where to go for the gh client id and secret....

Copy link
Member Author

Choose a reason for hiding this comment

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

Added to .env.example: 57afc85

@@ -36,6 +38,7 @@ class BlockCategory(Enum):
INPUT = "Block that interacts with input of the graph."
OUTPUT = "Block that interacts with output of the graph."
LOGIC = "Programming logic to control the flow of your agent"
DEVELOPER_TOOLS = "Developer tools like Github." # added this so all the github blocks are in the same category for now, this is to be changed
Copy link
Contributor

Choose a reason for hiding this comment

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

what needs to be changed? The desc or the name? I quite like the category name tbh

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

It was a suggestion to maybe change the name or description if needed but if its fine and does not need changing then the comment can be removed and it can be kept as is 😄

@Pwuts Pwuts force-pushed the reinier/open-1806-implement-front-to-back-github-oauth-support-on-blocks branch 2 times, most recently from 04143db to 47786f6 Compare September 19, 2024 15:28
@Pwuts Pwuts force-pushed the reinier/open-1806-implement-front-to-back-github-oauth-support-on-blocks branch from 47786f6 to 74138d7 Compare September 19, 2024 15:34
@Pwuts Pwuts force-pushed the reinier/open-1806-implement-front-to-back-github-oauth-support-on-blocks branch from 5c83d97 to 6aea79b Compare September 19, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Builder AutoGPT Builder documentation Improvements or additions to documentation Server size/xl
Projects
Status: 🆕 Needs initial review
Development

Successfully merging this pull request may close these issues.

4 participants