continuedev / continue

⏩ Continue is the leading open-source AI code assistant. You can connect any models and any context to build custom autocomplete and chat experiences inside VS Code and JetBrains
https://docs.continue.dev/
Apache License 2.0
18.79k stars 1.59k forks source link

Context Provider API broke down #2010

Closed samir-abis closed 1 month ago

samir-abis commented 2 months ago

Before submitting your bug report

Relevant environment info

- OS: linux-arm64
- Continue: main/dev/preview
- IDE: vscode - code-server

Description

Seems in the recent versions of Continue preview, the context providers are not working anymore.

I implemented context providers through the API connection and they show in the list, but when I try to run them unfortunately they show no results.

@fry69 mentioned that there were recent changes to ESM for config.ts, might be a cause? Discussion here: https://discord.com/channels/1108621136150929458/1273194528513458248

This wasn't the case a few builds ago.

image

here's an older build that runs the command with results image

and here's a newer build: image

To reproduce

  1. Develop a Context Provider with submenu through extension handling
  2. Verify if the submenu loads correctly
Patrick-Erichsen commented 2 months ago

Hi @samir-abis-everest , thanks for opening this. To clarify, you have a context provider with submenu items, but when you select the context provider, the submenu is empty?

Could you clarify what you mean by this?

might be? I'm not sure if it's related because I build the configurations in my extensions instead of Continue

There was a bug with config.ts related to us moving to a newer Typescript target but that was resolved and I don't believe would have an impact here.

samir-abis commented 2 months ago

Hi @Patrick-Erichsen.

you have a context provider with submenu items, but when you select the context provider, the submenu is empty?

Correct

Could you clarify what you mean by this?

I just tried out with a context provider directly in the config.ts (the example one of the documentation, reading .md files) and it works on the older build, while on the new build it still doesn't work.

Patrick-Erichsen commented 2 months ago

Got it - mind sharing your config.ts as well?

samir-abis commented 2 months ago
const markdownContextProvider: CustomContextProvider = {
  title: "markdown",
  displayTitle: "Markdown Files",
  description: "Access markdown files in your workspace",
  type: "submenu",

  async getContextItems(
    query: string,
    extras: ContextProviderExtras
  ): Promise<ContextItem[]> {
    const { ide } = extras;
    try {
      const content = await ide.readFile(query);
      return [
        {
          content,
          name: query,
          description: `Contents of ${query}`,
        },
      ];
    } catch (error) {
      console.error(`Error reading file ${query}:`, error);
      return [];
    }
  },

  async loadSubmenuItems({
    ide,
  }: LoadSubmenuItemsArgs): Promise<ContextSubmenuItem[]> {
    try {
      const workspaceDirs = await ide.getWorkspaceDirs();
      const allFiles = await Promise.all(
        workspaceDirs.map((dir) => ide.subprocess(`find ${dir} -name "*.md"`))
      );

      const markdownFiles = allFiles
        .flatMap((result) => result[0].split("\n"))
        .filter((file) => file.trim() !== "");

      return markdownFiles.map((file) => ({
        id: file,
        title: file.split("/").pop() || file,
        description: file,
      }));
    } catch (error) {
      console.error("Error loading markdown files:", error);
      return [];
    }
  },
};

export default markdownContextProvider;

export function modifyConfig(config: Config): Config {
  if (!config.contextProviders) {
    config.contextProviders = [];
  }
  config.contextProviders.push(markdownContextProvider);
  return config;
}

edit: corrected the code, now the prompt works. try it out

samir-abis commented 2 months ago

I've digged more through this in the debugger and this is the current status:

new version:

[2024-08-28T11:06:38] [DEBUG] Executing getSubmenuContextItems. Provider: lotse-context Query:  Limit: 70
[2024-08-28T11:06:38] [DEBUG] Executing getSubmenuSearchResults. Provider: lotse-context Query: 
[2024-08-28T11:06:38] [DEBUG] Current minisearches: []
[2024-08-28T11:06:38] [DEBUG] No minisearch found for provider: lotse-context
[2024-08-28T11:06:38] [DEBUG] Using fallback results: 0

old version:

[2024-08-28T11:08:46] [DEBUG] Logging initialized
[2024-08-28T11:09:12] [DEBUG] Executing getSubmenuContextItems. Provider: lotse-context Query:   Limit: 70
[2024-08-28T11:09:12] [DEBUG] Executing getSubmenuSearchResults. Provider: lotse-context Query:  
[2024-08-28T11:09:12] [DEBUG] Current minisearches: ["everest-nodes","everest-docs","lotse-context","markdown"]
[2024-08-28T11:09:12] [DEBUG] Search results for lotse-context: 0
[2024-08-28T11:09:12] [DEBUG] Using fallback results: 8

seems that minisearches are not being properly found/initialized, not even the one in the config.ts

samir-abis commented 2 months ago

https://github.com/continuedev/continue/pull/2124