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

How do I get the contents of a file provided by Visual Studio? #21

Open
evanyangxx opened this issue Dec 20, 2024 · 4 comments
Open

How do I get the contents of a file provided by Visual Studio? #21

evanyangxx opened this issue Dec 20, 2024 · 4 comments

Comments

@evanyangxx
Copy link

Here is the information for my payload object, the copilot_references property is empty.
Image

@gr2m
Copy link

gr2m commented Dec 20, 2024

The SDK is just passing through available information, but I'll ask the team working on the backend to see if there is a way

@D1M1TR10S
Copy link
Collaborator

D1M1TR10S commented Jan 2, 2025

@evanyangxx the client.file context should be accessible. This would show the relative path for the current file. Link to docs. We're planning to add more detailed builder docs on how to access and use local contexts soon.

Are you hoping to get the user's relative file path? The full file path? Or the actual contents of the current file a user is on? I'll find some info on how to troubleshoot this. It'll help if I know which specific context you're looking to access.

Here's an example of the request payload you should see when client.file is passed properly:

{
  "type": "client.file",
  "data": {
    "content": "this is the content of my file",
    "language": "markdown"
    },
  "id": "relative/path/to/file",
  "metadata": {
    "display_name": "",
    "display_icon": ""
  }
},

@D1M1TR10S
Copy link
Collaborator

Here are some steps you can take to troubleshoot the issue @evanyangxx:

  1. Verify that client.* references are included in the payload to your agent
  2. Ensure you have the proper permissions set up for the GH App + repo + org (particularly the “Read Access to Editor Context” permission)
  3. Verify the file doesn’t match any content exclusion patterns, preventing the references from being included
  4. Ensure the file isn’t hidden (.env and other files with a leading . are excluded by default)
  5. Check if the file meets size limitations (if the file is too big, you can just select the relevant portion)

Also, I'm going to move this issue to our user feedback repo since it's general and our team will have better visibility there.

@D1M1TR10S D1M1TR10S transferred this issue from copilot-extensions/preview-sdk.js Jan 3, 2025
@hjo12
Copy link

hjo12 commented Jan 6, 2025

@evanyangxx the client.file context should be accessible. This would show the relative path for the current file. Link to docs. We're planning to add more detailed builder docs on how to access and use local contexts soon.

Are you hoping to get the user's relative file path? The full file path? Or the actual contents of the current file a user is on? I'll find some info on how to troubleshoot this. It'll help if I know which specific context you're looking to access.

Here's an example of the request payload you should see when client.file is passed properly:

{
  "type": "client.file",
  "data": {
    "content": "this is the content of my file",
    "language": "markdown"
    },
  "id": "relative/path/to/file",
  "metadata": {
    "display_name": "",
    "display_icon": ""
  }
},

Curious if project type has anything to do with the op receiving null on references, since in my case for VSCode with a TS Node project the client.* references work perfectly, and in Visual Studio testing with a console C# .NET 8 app works the same as VSCode and id correctly has the relative path to the file.

Though if I try a C# WinUI3 / UWP project in Visual Studio I see some "odd" behavior when there are copilot_references, they aren't null with content being filled but the first user message copilot reference ends up being something like:

{
  type: "github.redacted",
  data: {
    type: "github.repository",
  },
  id: "someid",
  is_implicit: true,
  metadata: {
    display_name: "",
    display_icon: "",
    display_url: "",
  },
}

and after I re-prompt the agent the original user message first sent contains the expected format for copilot_references, except type is DocumentContext instead of the client.* and data is just a string instead of an object with content/language properties.

I'm not too sure if there's something I'm missing that causes this to get github.redacted at first in visual studio, then after another message is sent the original contains the reference objects to DocumentContext instead of github.redacted. Below is the flow for the example above with Visual Studio:

  1. Asked agent a question with text selected in C# WinUI3 application in Visual Studio

  2. Payload arrives and is below:

    [
      {
        role: "system",
        content: "You are an AI programming assistant.",
        copilot_references: [
        ],
        copilot_confirmations: null,
      },
      {
        role: "user",
        content: "whats in this file?",
        copilot_references: [
          {
            type: "github.redacted",
            data: {
              type: "github.repository",
            },
            id: "someid",
            is_implicit: true,
            metadata: {
              display_name: "",
              display_icon: "",
              display_url: "",
            },
          },
        ],
        copilot_confirmations: null,
      },
    ]
    
  3. Assistant responds, and agent is reprompted with the selected text again

    • content is "" here because of timeout during debugging, otherwise it typically comes back asking for more context
  4. Payload arrives, with the original user message now having DocumentContext reference types and the latest user message having the github.redacted again:

    [
      {
        role: "system",
        content: "You are an AI programming assistant.",
        copilot_references: [
        ],
        copilot_confirmations: null,
      },
      {
        role: "user",
        content: "whats in this?",
        copilot_references: [
          {
            type: "DocumentContext",
            data: "File: ChatTailorAI.WinUI/Services/Navigation/PageTypeResolver.cs\r\n......",
            id: "file",
            is_implicit: false,
            metadata: {
              display_name: "",
              display_icon: "",
              display_url: "",
            },
          },
          {
            type: "DocumentContext",
            data: "File: ChatTailorAI.WinUI/Services/Navigation/PageTypeResolver.cs\r\n\r\n\r\n## SIGNATURES OF REFERENCED TYPES IN DOCUMENT:\r\n......",
            id: "file",
            is_implicit: false,
            metadata: {
              display_name: "",
              display_icon: "",
              display_url: "",
            },
          },
        ],
        copilot_confirmations: null,
      },
      {
        role: "assistant",
        content: "",
        copilot_references: [
        ],
        copilot_confirmations: null,
      },
      {
        role: "user",
        content: "what is in this file?",
        copilot_references: [
          {
            type: "github.redacted",
            data: {
              type: "github.repository",
            },
            id: "someid",
            is_implicit: true,
            metadata: {
              display_name: "",
              display_icon: "",
              display_url: "",
            },
          },
        ],
        copilot_confirmations: null,
      },
    ]
    

Let me know if you need more information on this or if it should be asked elsewhere. Wasn't sure if all projects interacting with copilot should be having the same client.* reference types when payloads come through, or if there was some documentation on what I noticed above and when client.* / DocumentContext reference types are used, though so far only noticed DocumentContext used in a C# WinUI3 or C# UWP project in Visual Studio as far as I've tested. Also was curious if there's a way to control the system message that appears in the payload from both Visual Studio projects, since it doesn't seem to show in payloads when within a project in VSCode?

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

No branches or pull requests

4 participants