diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 3eadb9708..18738640f 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -170,6 +170,7 @@ export class ConfigHandler { } async loadAssistantsForSelectedOrg() { + // debugger; // Get the profiles and create their lifecycle managers const userId = await this.controlPlaneClient.userId; const selectedOrgId = await this.getSelectedOrgId(); @@ -186,6 +187,7 @@ export class ConfigHandler { const hubProfiles = await Promise.all( assistants.map(async (assistant) => { + // debugger; const profileLoader = await PlatformProfileLoader.create( { ...assistant.configResult, @@ -200,6 +202,7 @@ export class ConfigHandler { this.ideSettingsPromise, this.writeLog, this.reloadConfig.bind(this), + assistant.rawYaml, ); return new ProfileLifecycleManager(profileLoader, this.ide); diff --git a/core/config/ProfileLifecycleManager.ts b/core/config/ProfileLifecycleManager.ts index aca588a22..29f3bcec1 100644 --- a/core/config/ProfileLifecycleManager.ts +++ b/core/config/ProfileLifecycleManager.ts @@ -24,6 +24,7 @@ export interface ProfileDescription { errors: ConfigValidationError[] | undefined; uri: string; unrolledAssistant?: AssistantUnrolled; + rawYaml?: string; } export interface OrganizationDescription { diff --git a/core/config/load.ts b/core/config/load.ts index 5abb3fd5e..c1d94f5f0 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -674,6 +674,7 @@ async function finalToBrowserConfig( userToken: final.userToken, ui: final.ui, experimental: final.experimental, + rules: final.rules, docs: final.docs, tools: final.tools, tabAutocompleteOptions: final.tabAutocompleteOptions, diff --git a/core/config/profile/LocalProfileLoader.ts b/core/config/profile/LocalProfileLoader.ts index 94af3a0e2..46245a7f0 100644 --- a/core/config/profile/LocalProfileLoader.ts +++ b/core/config/profile/LocalProfileLoader.ts @@ -38,6 +38,7 @@ export default class LocalProfileLoader implements IProfileLoader { uri: overrideAssistantFile?.path ?? localPathToUri(getPrimaryConfigFilePath()), + rawYaml: undefined, }; this.description = description; if (overrideAssistantFile?.content) { diff --git a/core/config/profile/PlatformProfileLoader.ts b/core/config/profile/PlatformProfileLoader.ts index 4414b3d02..a5cc8fcdc 100644 --- a/core/config/profile/PlatformProfileLoader.ts +++ b/core/config/profile/PlatformProfileLoader.ts @@ -47,6 +47,7 @@ export default class PlatformProfileLoader implements IProfileLoader { ideSettingsPromise: Promise, writeLog: (message: string) => Promise, onReload: () => void, + rawYaml: string, ): Promise { const controlPlaneEnv = await getControlPlaneEnv(ideSettingsPromise); @@ -63,6 +64,7 @@ export default class PlatformProfileLoader implements IProfileLoader { iconUrl: iconUrl, uri: `${controlPlaneEnv}${ownerSlug}/${packageSlug}`, unrolledAssistant: configResult.config, + rawYaml, }; return new PlatformProfileLoader( diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index b0cabac3b..aae720342 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -153,6 +153,7 @@ async function configYamlToContinueConfig( rootUrl: doc.rootUrl, faviconUrl: doc.faviconUrl, })), + rules: config.rules, contextProviders: [], modelsByRole: { chat: [], diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index 9dcf40b6d..dee4d7ef4 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -113,6 +113,7 @@ export class ControlPlaneClient { ownerSlug: string; packageSlug: string; iconUrl: string; + rawYaml: string; }[] > { const userId = await this.userId; diff --git a/core/index.d.ts b/core/index.d.ts index f9daec503..14c377538 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -164,7 +164,11 @@ export interface ILLM extends LLMOptions { } export interface ModelInstaller { - installModel(modelName: string, signal: AbortSignal, progressReporter?: (task: string, increment: number, total: number) => void): Promise; + installModel( + modelName: string, + signal: AbortSignal, + progressReporter?: (task: string, increment: number, total: number) => void, + ): Promise; } export type ContextProviderType = "normal" | "query" | "submenu"; @@ -1242,6 +1246,7 @@ export interface ContinueConfig { analytics?: AnalyticsConfig; docs?: SiteIndexingConfig[]; tools: Tool[]; + rules?: string[]; modelsByRole: Record; selectedModelByRole: Record; data?: DataDestination[]; @@ -1263,6 +1268,7 @@ export interface BrowserSerializedContinueConfig { analytics?: AnalyticsConfig; docs?: SiteIndexingConfig[]; tools: Tool[]; + rules?: string[]; usePlatform: boolean; tabAutocompleteOptions?: Partial; modelsByRole: Record; diff --git a/gui/src/pages/More/RulesPreview/index.tsx b/gui/src/pages/More/RulesPreview/index.tsx index 3dee60423..02f351d07 100644 --- a/gui/src/pages/More/RulesPreview/index.tsx +++ b/gui/src/pages/More/RulesPreview/index.tsx @@ -1,36 +1,134 @@ +import { parseConfigYaml } from "@continuedev/config-yaml"; +import { PencilSquareIcon } from "@heroicons/react/24/outline"; +import { useContext, useMemo } from "react"; +import { useSelector } from "react-redux"; +import HeaderButtonWithToolTip from "../../../components/gui/HeaderButtonWithToolTip"; import { useAuth } from "../../../context/Auth"; +import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { RootState } from "../../../redux/store"; -/** - * Displays a formatted preview of the AI assistant's rules in a code editor style - */ -export function RulesPreview() { - const { selectedProfile } = useAuth(); - const rules = selectedProfile?.unrolledAssistant?.rules ?? []; +interface RuleCardProps { + index: number; + rule: string; + onClick: () => void; + title: string; +} + +const RuleCard: React.FC = ({ index, rule, onClick, title }) => { + const truncateRule = (rule: string) => { + const maxLength = 75; + return rule.length > maxLength + ? `${rule.substring(0, maxLength)}...` + : rule; + }; return ( -
-
- rules - : - - {rules.map((rule, index) => ( -
- - - - {rule} - +
+
+
+
{title}
+
+ {truncateRule(rule)}
- ))} - - {rules.length === 0 && ( -
- # No rules defined -
- )} +
+ + +
); +}; + +export function RulesPreview() { + const ideMessenger = useContext(IdeMessengerContext); + const { selectedProfile } = useAuth(); + + const rules = useSelector( + (state: RootState) => state.config.config.rules ?? [], + ); + + const parsed = useMemo(() => { + if (!selectedProfile?.rawYaml) { + return undefined; + } + + return parseConfigYaml(selectedProfile?.rawYaml ?? ""); + }, [rules]); + + const mergedRules = useMemo(() => { + return rules.map((rule, index) => ({ + unrolledRule: rule, + ruleFromYaml: parsed?.rules?.[index], + })); + }, [rules, parsed]); + + const openUrl = (path: string) => + ideMessenger.request("controlPlane/openUrl", { + path, + orgSlug: undefined, + }); + + return ( +
+

+ Assistant Rules +

+ + {mergedRules.length === 0 ? ( +
+

No rules defined yet

+
+ ) : ( +
+ {mergedRules.map((rule, index) => { + if (!rule.ruleFromYaml) { + return ( + + ideMessenger.post("config/openProfile", { + profileId: undefined, + }) + } + title="Locally Defined Rule" + /> + ); + } + + if (typeof rule.ruleFromYaml === "string") { + const slug = `${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`; + + return ( + openUrl(`${slug}/new-version`)} + title="Inline Rule" + /> + ); + } + + if (!rule.ruleFromYaml?.uses) { + return null; + } + + const ruleSlug = rule.ruleFromYaml?.uses; + + return ( + openUrl(`${ruleSlug}/new-version`)} + title={ruleSlug} + /> + ); + })} +
+ )} +
+ ); }