| 1 | import { createSelector } from "@reduxjs/toolkit"; |
| 2 | import { |
| 3 | ComboBoxItem, |
| 4 | ComboBoxItemType, |
| 5 | } from "../../components/mainInput/types"; |
| 6 | import { RootState } from "../store"; |
| 7 | |
| 8 | export const selectSlashCommandComboBoxInputs = createSelector( |
| 9 | [(state: RootState) => state.config.config.slashCommands], |
| 10 | (slashCommands) => { |
| 11 | return ( |
| 12 | slashCommands?.map((cmd) => { |
| 13 | let content = cmd.prompt; |
| 14 | |
| 15 | // For MCP prompts without content, show that it failed to load |
| 16 | if (cmd.source === "mcp-prompt" && !content) { |
| 17 | content = "[MCP Prompt - failed to load content during startup]"; |
| 18 | } |
| 19 | |
| 20 | return { |
| 21 | title: cmd.name, |
| 22 | description: cmd.description, |
| 23 | type: "slashCommand" as ComboBoxItemType, |
| 24 | content: content, |
| 25 | } as ComboBoxItem; |
| 26 | }) || [] |
| 27 | ); |
| 28 | }, |
| 29 | ); |
| 30 | |
| 31 | export const selectSlashCommands = createSelector( |
| 32 | [(state: RootState) => state.config.config.slashCommands], |
| 33 | (slashCommands) => { |
| 34 | return slashCommands || []; |
| 35 | }, |
| 36 | ); |
| 37 | |
| 38 | export const selectSubmenuContextProviders = createSelector( |
| 39 | [(state: RootState) => state.config.config.contextProviders], |
| 40 | (providers) => { |
| 41 | return providers?.filter((desc) => desc.type === "submenu") || []; |
| 42 | }, |
| 43 | ); |
| 44 | |
| 45 | export const selectDefaultContextProviders = createSelector( |
| 46 | [(state: RootState) => state.config.config.experimental?.defaultContext], |
| 47 | (defaultProviders) => { |
| 48 | return defaultProviders ?? []; |
| 49 | }, |
| 50 | ); |
| 51 | |
| 52 | export const selectUseActiveFile = createSelector( |
| 53 | [(state: RootState) => state.config.config.experimental?.defaultContext], |
| 54 | (defaultContext) => defaultContext?.includes("activeFile" as any), |
| 55 | ); |