feat: rules preview
This commit is contained in:
parent
40914a8bf3
commit
d57d35d5bd
9 changed files with 142 additions and 28 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export interface ProfileDescription {
|
|||
errors: ConfigValidationError[] | undefined;
|
||||
uri: string;
|
||||
unrolledAssistant?: AssistantUnrolled;
|
||||
rawYaml?: string;
|
||||
}
|
||||
|
||||
export interface OrganizationDescription {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ export default class LocalProfileLoader implements IProfileLoader {
|
|||
uri:
|
||||
overrideAssistantFile?.path ??
|
||||
localPathToUri(getPrimaryConfigFilePath()),
|
||||
rawYaml: undefined,
|
||||
};
|
||||
this.description = description;
|
||||
if (overrideAssistantFile?.content) {
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ export default class PlatformProfileLoader implements IProfileLoader {
|
|||
ideSettingsPromise: Promise<IdeSettings>,
|
||||
writeLog: (message: string) => Promise<void>,
|
||||
onReload: () => void,
|
||||
rawYaml: string,
|
||||
): Promise<PlatformProfileLoader> {
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@ async function configYamlToContinueConfig(
|
|||
rootUrl: doc.rootUrl,
|
||||
faviconUrl: doc.faviconUrl,
|
||||
})),
|
||||
rules: config.rules,
|
||||
contextProviders: [],
|
||||
modelsByRole: {
|
||||
chat: [],
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ export class ControlPlaneClient {
|
|||
ownerSlug: string;
|
||||
packageSlug: string;
|
||||
iconUrl: string;
|
||||
rawYaml: string;
|
||||
}[]
|
||||
> {
|
||||
const userId = await this.userId;
|
||||
|
|
|
|||
8
core/index.d.ts
vendored
8
core/index.d.ts
vendored
|
|
@ -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<any>;
|
||||
installModel(
|
||||
modelName: string,
|
||||
signal: AbortSignal,
|
||||
progressReporter?: (task: string, increment: number, total: number) => void,
|
||||
): Promise<any>;
|
||||
}
|
||||
|
||||
export type ContextProviderType = "normal" | "query" | "submenu";
|
||||
|
|
@ -1242,6 +1246,7 @@ export interface ContinueConfig {
|
|||
analytics?: AnalyticsConfig;
|
||||
docs?: SiteIndexingConfig[];
|
||||
tools: Tool[];
|
||||
rules?: string[];
|
||||
modelsByRole: Record<ModelRole, ILLM[]>;
|
||||
selectedModelByRole: Record<ModelRole, ILLM | null>;
|
||||
data?: DataDestination[];
|
||||
|
|
@ -1263,6 +1268,7 @@ export interface BrowserSerializedContinueConfig {
|
|||
analytics?: AnalyticsConfig;
|
||||
docs?: SiteIndexingConfig[];
|
||||
tools: Tool[];
|
||||
rules?: string[];
|
||||
usePlatform: boolean;
|
||||
tabAutocompleteOptions?: Partial<TabAutocompleteOptions>;
|
||||
modelsByRole: Record<ModelRole, ModelDescription[]>;
|
||||
|
|
|
|||
|
|
@ -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<RuleCardProps> = ({ index, rule, onClick, title }) => {
|
||||
const truncateRule = (rule: string) => {
|
||||
const maxLength = 75;
|
||||
return rule.length > maxLength
|
||||
? `${rule.substring(0, maxLength)}...`
|
||||
: rule;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="rounded-lg bg-[#1e1e1e] p-6 font-mono text-sm">
|
||||
<div className="text-[#d4d4d4]">
|
||||
<span className="text-[#c586c0]">rules</span>
|
||||
<span className="text-[#d4d4d4]">:</span>
|
||||
|
||||
{rules.map((rule, index) => (
|
||||
<div key={index} className="ml-6 mt-2">
|
||||
<span className="mr-2 text-[#d4d4d4]">-</span>
|
||||
<span
|
||||
className="whitespace-pre-wrap text-[#9cdcfe]"
|
||||
style={{ maxWidth: "80ch" }}
|
||||
>
|
||||
{rule}
|
||||
</span>
|
||||
<div className="rounded-lg bg-[#1e1e1e] p-4 transition-colors hover:bg-[#252525]">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1">
|
||||
<div className="mb-2 font-mono text-sm text-[#9cdcfe]">{title}</div>
|
||||
<div className="whitespace-pre-wrap font-mono text-sm text-gray-300">
|
||||
{truncateRule(rule)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{rules.length === 0 && (
|
||||
<div className="ml-6 mt-2 italic text-[#6a9955]">
|
||||
# No rules defined
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<HeaderButtonWithToolTip onClick={onClick} text="Edit">
|
||||
<PencilSquareIcon className="h-4 w-4 transition-colors group-hover:text-blue-400" />
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
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 (
|
||||
<div className="space-y-4">
|
||||
<h2 className="mb-4 text-lg font-semibold text-gray-200">
|
||||
Assistant Rules
|
||||
</h2>
|
||||
|
||||
{mergedRules.length === 0 ? (
|
||||
<div className="rounded-lg bg-[#1e1e1e] p-6">
|
||||
<p className="italic text-gray-400">No rules defined yet</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{mergedRules.map((rule, index) => {
|
||||
if (!rule.ruleFromYaml) {
|
||||
return (
|
||||
<RuleCard
|
||||
key={index}
|
||||
index={index}
|
||||
rule={rule.unrolledRule}
|
||||
onClick={() =>
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
})
|
||||
}
|
||||
title="Locally Defined Rule"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof rule.ruleFromYaml === "string") {
|
||||
const slug = `${selectedProfile?.fullSlug.ownerSlug}/${selectedProfile?.fullSlug.packageSlug}`;
|
||||
|
||||
return (
|
||||
<RuleCard
|
||||
key={index}
|
||||
index={index}
|
||||
rule={rule.unrolledRule}
|
||||
onClick={() => openUrl(`${slug}/new-version`)}
|
||||
title="Inline Rule"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (!rule.ruleFromYaml?.uses) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const ruleSlug = rule.ruleFromYaml?.uses;
|
||||
|
||||
return (
|
||||
<RuleCard
|
||||
key={index}
|
||||
index={index}
|
||||
rule={rule.unrolledRule}
|
||||
onClick={() => openUrl(`${ruleSlug}/new-version`)}
|
||||
title={ruleSlug}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue