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

fix: copilot chat extension does not work #335

Closed
wants to merge 9 commits into from
Closed

Conversation

vitaliy-guliy
Copy link
Contributor

@vitaliy-guliy vitaliy-guliy commented Feb 28, 2024

What does this PR do?

Ask the user when an extension wants to sign in using GitHub.

Screenshot from 2024-03-18 22-50-16

Screenshot from 2024-03-18 22-50-56

What issues does this PR fix?

eclipse-che/che#22781

How to test this PR?

  1. Create a workspace with
    https://github.com/vitaliy-guliy/vscode-test-extension?che-editor=https://gist.githubusercontent.com/vitaliy-guliy/8fbbfafa1de2448acffa01e1386f1a3f/raw/6ed01b24709f6afaa8e171fbd1e3666e65e8538d/editor.yaml

  2. Download both extensions to your laptop

  1. Open Extensions view, install the extensions

  2. If necessary, perform device authorization

Compatibility [WIP]

che-code@7.84.0 (main branch) / vscode@1.88.0 - dogfooding

desktop vscode@1.87.1

che-code@7.82.1 / vscode@1.87.0 - staging with Dev Spaces 3.12

apply the script from workaround section.

che-code@7.80.1 / vscode@1.86.0 - sandbox with Dev Spaces 3.11

apply the script from workaround section.

Workaround for workspaces without fixes in this pull request

If you try to install the extensions in che-code from the main branch, the copilot chat extension will not work because it cannot get GitHub session due to specific call of the extension plugin API like here
https://github.com/vitaliy-guliy/vscode-test-extension/blob/get-session/src/extension.ts#L39

If silent is true, user will not be asked to permit giving the access to his account to the extension. And as result the extension will have undefined instead of a session.

If you apply this fixup, it will update your browser database and granted the access for Pull Request extension and for both Copilot extensions.

How to test:

  • on the dogfooding instance open the browser console, go to Application tab and remove all what you have in IndexedDB
  • create any workspace
  • copy the script below, open the browser console again, go to Console tab, paste the script, replace 'vitaliy-guliy' on your github login and execute the script
  • remove existing Device Authentication token and authorize again
  • reload the page
  • install pull request extension, copilot and copilot-chat extensions in exact sequence
  • everything should work now

Just to check this workaround is working, try to repeat above steps but do not launch the script.

(async function update() {
    try {
        const accountName = 'vitaliy-guliy';
        console.log(`> updating rules for ${accountName}`);

        const req = indexedDB.open('vscode-web-state-db-global');
        await new Promise((r) => (req.onsuccess = r));

        const transaction = req.result.transaction('ItemTable', "readwrite");
        const store = transaction.objectStore('ItemTable');

        const keys = store.getAllKeys();
        await new Promise((r) => (keys.onsuccess = r));

        let rules = [];
        let usages = [];

        if (keys.result.includes(`github-${accountName}`)) {
            const value = store.get(`github-${accountName}`);
            await new Promise((r) => (value.onsuccess = r));
            rules = JSON.parse(value.result);
        }

        if (keys.result.includes(`github-${accountName}-usages`)) {
            const value = store.get(`github-${accountName}-usages`);
            await new Promise((r) => (value.onsuccess = r));
            usages = JSON.parse(value.result);
        }

        const ensureRule = function (extensionId, name) {
            if (rules.find(rule => rule.id === extensionId)) {
                console.log(`> rule for ${extensionId} already exists`);
            } else {
                console.log(`> add rule for ${extensionId}`);
                rules.push({
                    "id": extensionId,
                    "name": name,
                    "allowed": true
                });
            }

            if (usages.find(usage => usage.extensionId === extensionId)) {
                console.log(`> usage for ${extensionId} already exists`);
            } else {
                console.log(`> add usage for ${extensionId}`);
                usages.push({
                    "extensionId": extensionId,
                    "extensionName": name,
                    "lastUsed": Date.now().toString()
                });
            }
        };

        ensureRule('github.copilot', 'GitHub Copilot');
        ensureRule('github.copilot-chat', 'GitHub Copilot Chat');

        const putRules = store.put(JSON.stringify(rules), `github-${accountName}`);
        await new Promise((r) => (putRules.onsuccess = r));

        const putUsages = store.put(JSON.stringify(usages), `github-${accountName}-usages`);
        await new Promise((r) => (putUsages.onsuccess = r));

        console.log('> done');

        await new Promise((r) => setTimeout(r, 1000));
        window.location.reload()
    } catch (e) {
        console.error(e, e.trace);
    }
})();

Does this PR contain changes that override default upstream Code-OSS behavior?

  • the PR contains changes in the code folder (you can skip it if your changes are placed in a che extension )
  • the corresponding items were added to the CHANGELOG.md file
  • rules for automatic git rebase were added to the .rebase folder

Copy link

github-actions bot commented Feb 28, 2024

Click here to review and test in web IDE: Contribute

Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

14 similar comments
Copy link

github-actions bot commented Mar 5, 2024

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

github-actions bot commented Mar 6, 2024

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

github-actions bot commented Mar 7, 2024

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

github-actions bot commented Mar 7, 2024

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

github-actions bot commented Mar 8, 2024

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
@vitaliy-guliy vitaliy-guliy added the made-with-che Changes made with Che-Code label Mar 18, 2024
Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

1 similar comment
Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

@vitaliy-guliy vitaliy-guliy marked this pull request as ready for review March 19, 2024 18:23
@RomanNikitenko
Copy link
Contributor

@vitaliy-guliy
Yesterday I fetched a lot new commits from the upstream to the che-code repo.
I see there are some changes in the src/vs/workbench/api/browser/mainThreadAuthentication.ts: microsoft/vscode@be59ec5.
So, could you update your brach please.

options.silent = false;
options.createIfNone = true;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@vitaliy-guliy
I tested this solution - it works for me - I'm able to use Github Copilot Chat extension,
thank you!

At the same time it's still unclear how it works on VS Code side without these changes.
Also I detected some side-effects of the current solution:

  • let's say I don't have Copilot and Copilot extensions
  • It asks me to sign in using GitHub directly after starting a workspace
  • without these changes the system asks to sign in using GitHub only when I'm using some command that requires it (git clone for example)

Another use case is - Sign Out:

  • with these changes the system asks to Sign In directly after Sign Out for all extensions, like: I do Sign Out => 3 dialogs are shown to Sign in for 3 extensions

Without these changes:
https://github.com/che-incubator/che-code/assets/5676062/87a7f967-6621-4e26-b52d-04fb0e1e4cb3

With these changes:
https://github.com/che-incubator/che-code/assets/5676062/702d9f6b-29f4-4cf4-9c57-e069f5fe3a13

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 OK for me to merge the PR as is if we don't have another solution that allows to avoid those side-effects - they are insignificant from my point of view

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, user is asked to grant the access when the extension wants to get a session.
But is seems user is asked only once at the workspace startup.
It should not be very annoying in case you want to use extension like copilot.
From the other side, clicking the button each time when creating a workspace could make a user a bit nervous.

I created another PR to test a bit different behavior #339

Copy link
Contributor

Choose a reason for hiding this comment

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

But is seems user is asked only once at the workspace startup.

I also described another use case above:
I want to Sign Out => 3 dialogs are shown to Sign in for 3 extensions

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'm not sure users are practicing signing out in a real life.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But yes, it's a case

@vitaliy-guliy vitaliy-guliy changed the title [WIP] fix: copilot chat extension does not work fix: copilot chat extension does not work Mar 20, 2024
Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
Copy link

Pull Request Dev image published:
👉 quay.io/che-incubator-pull-requests/che-code-dev:pr-335-dev-amd64

Copy link

Pull Request Che-Code image published:
👉 quay.io/che-incubator-pull-requests/che-code:pr-335-amd64

@vitaliy-guliy vitaliy-guliy marked this pull request as draft March 22, 2024 22:15
@vitaliy-guliy vitaliy-guliy deleted the copilot-chat branch April 3, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
made-with-che Changes made with Che-Code
Projects
None yet
2 participants