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

Add prompts migration API #5954

Merged
merged 13 commits into from
Oct 22, 2024
Merged

Add prompts migration API #5954

merged 13 commits into from
Oct 22, 2024

Conversation

vovakulikov
Copy link
Contributor

@vovakulikov vovakulikov commented Oct 21, 2024

Part of SRCH-1162
Closes CODY-3052

This PR adds commands to prompt migration. We store commands locally, and this migration transfers commands to the prompts library (since the prompts library has got near feature parity with commands when it comes to chat submission and inline change execution)

  • You can run this migration only once per repository
  • After you start running this migration welcome area and prompts tab should have the same state in the migration banner (which can be the initial state, scanning for commands, migration, or error success)
  • After the migration is complete, you should see no banner unless you open VSCode in another repository, and this repository contains some custom commands.
  • You can dismiss the migration banner on the welcome area only
Welcome screen Prompts Tab
Screenshot 2024-10-21 at 21 34 28 Screenshot 2024-10-21 at 21 34 18

Test plan

  • Check if you can see and use the migration tool to transfer your custom commands to the prompts library

@vovakulikov vovakulikov self-assigned this Oct 21, 2024
@vovakulikov vovakulikov marked this pull request as ready for review October 22, 2024 02:26
@vovakulikov vovakulikov requested review from thenamankumar, a team and taiyab October 22, 2024 02:27
@@ -747,6 +773,15 @@ export class SourcegraphGraphQLAPIClient {
)
}

public async getCurrentUserRole(): Promise<CurrentUserRoleResponse['currentUser'] | null | Error> {
Copy link
Member

Choose a reason for hiding this comment

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

Because the query only returns sideAdmin this should rather be renamed to isCurrentUserSideAdmin and should return Promise<boolean>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also have to have user's ID here to properly create prompt (owner ID field), so it's not pure admin check query


// Change prompt visibility to PUBLIC if it's admin performing migration
// TODO: [VK] Remove it and use visibility field in prompt creation (current API limitation)
if (currentUser.siteAdmin) {
Copy link
Member

Choose a reason for hiding this comment

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

In Jason's PR he is removing the isSiteAdmin check in his PR. I am not sure what we want to do with this check yet.

draft: false,
autoSubmit: false,
mode: commandModeToPromptMode(command.mode),
visibility: 'SECRET',
Copy link
Member

Choose a reason for hiding this comment

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

Can we not just set the visibility here only rather than transferring the ownership. How does the createPrompt mutation work? Is it allowed to do that? If not, then why is the visibility field even required if the default is SECRET?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is tricky, and it looks like a BE API issue, so prompt mutation requires a visibility field, but regardless of the value we're passing, it always will create a secret private prompt. So this is why we have different mutation for making it public (which doesn't make much sense to me why we can just create a public prompt with crete mutation)

This tricky with transferPromptOwnership exists here only as a workaround for this API limitation.

@@ -15,7 +16,8 @@ export const PromptsTab: React.FC<{
const runAction = useActionSelect()

return (
<div className="tw-overflow-auto tw-h-full">
<div className="tw-overflow-auto tw-h-full tw-flex tw-flex-col tw-gap-6">
Copy link
Member

Choose a reason for hiding this comment

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

Is the PromptsTab rendered for only the upcoming version of SG? If not, should we check for the SG version here so that users connected to old sg instance are not shown this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is very good point; I put this behind the feature flag code-unified-prompts, and also, getPromptsMigrationInfo handles this case when we're connected to lower versions than 5.9.0 (in this case we just skip means not rendering migration widget UI)

>
<Progress.Indicator
className={styles.loaderIndicator}
style={{
Copy link
Member

Choose a reason for hiding this comment

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

Lol, does the Progress component not handle the translate out of box? And if they don't, can we just extract it into a separate component in ui folder and use it from there.

Copy link
Contributor

@taiyab taiyab left a comment

Choose a reason for hiding this comment

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

LGTM!

@vovakulikov
Copy link
Contributor Author

Just realized that during migration we also should transfer custom command context *by adding now supported mention syntax in the prompt message, just putting it here in case someone wants to merge this

@vovakulikov vovakulikov merged commit 8cff1fc into main Oct 22, 2024
20 checks passed
@vovakulikov vovakulikov deleted the vk/add-prompt-migration branch October 22, 2024 23:09
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