feat: rules display

This commit is contained in:
tomasz-io 2025-03-14 11:56:03 -07:00
parent 09d7a1861e
commit 40914a8bf3
11 changed files with 120 additions and 37 deletions

View file

@ -1,4 +1,5 @@
import {
AssistantUnrolled,
ConfigResult,
ConfigValidationError,
FullSlug,
@ -22,6 +23,7 @@ export interface ProfileDescription {
iconUrl: string;
errors: ConfigValidationError[] | undefined;
uri: string;
unrolledAssistant?: AssistantUnrolled;
}
export interface OrganizationDescription {

View file

@ -62,6 +62,7 @@ export default class PlatformProfileLoader implements IProfileLoader {
errors: configResult.errors,
iconUrl: iconUrl,
uri: `${controlPlaneEnv}${ownerSlug}/${packageSlug}`,
unrolledAssistant: configResult.config,
};
return new PlatformProfileLoader(

24
gui/package-lock.json generated
View file

@ -46,6 +46,7 @@
"react-switch": "^7.0.0",
"react-syntax-highlighter": "^15.5.0",
"react-tooltip": "^5.18.0",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
"redux-persist-transform-filter": "^0.0.22",
"redux-thunk": "^3.1.0",
@ -79,6 +80,7 @@
"@types/react-dom": "^18.3.1",
"@types/react-router-dom": "^5.3.3",
"@types/react-syntax-highlighter": "^15.5.7",
"@types/redux-logger": "^3.0.13",
"@types/styled-components": "^5.1.26",
"@vitejs/plugin-react-swc": "^3.7.0",
"@vitest/coverage-v8": "^2.1.3",
@ -3061,6 +3063,15 @@
"@types/react": "*"
}
},
"node_modules/@types/redux-logger": {
"version": "3.0.13",
"resolved": "https://registry.npmjs.org/@types/redux-logger/-/redux-logger-3.0.13.tgz",
"integrity": "sha512-jylqZXQfMxahkuPcO8J12AKSSCQngdEWQrw7UiLUJzMBcv1r4Qg77P6mjGLjM27e5gFQDPD8vwUMJ9AyVxFSsg==",
"dev": true,
"dependencies": {
"redux": "^5.0.0"
}
},
"node_modules/@types/responselike": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.3.tgz",
@ -4532,6 +4543,11 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/deep-diff": {
"version": "0.3.8",
"resolved": "https://registry.npmjs.org/deep-diff/-/deep-diff-0.3.8.tgz",
"integrity": "sha512-yVn6RZmHiGnxRKR9sJb3iVV2XTF1Ghh2DiWRZ3dMnGc43yUdWWF/kX6lQyk3+P84iprfWKU/8zFTrlkvtFm1ug=="
},
"node_modules/deep-eql": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
@ -10153,6 +10169,14 @@
"resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz",
"integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w=="
},
"node_modules/redux-logger": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/redux-logger/-/redux-logger-3.0.6.tgz",
"integrity": "sha512-JoCIok7bg/XpqA1JqCqXFypuqBbQzGQySrhFzewB7ThcnysTO30l4VCst86AuB9T9tuT03MAA56Jw2PNhRSNCg==",
"dependencies": {
"deep-diff": "^0.3.5"
}
},
"node_modules/redux-persist": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/redux-persist/-/redux-persist-6.0.0.tgz",

View file

@ -54,6 +54,7 @@
"react-switch": "^7.0.0",
"react-syntax-highlighter": "^15.5.0",
"react-tooltip": "^5.18.0",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
"redux-persist-transform-filter": "^0.0.22",
"redux-thunk": "^3.1.0",
@ -87,6 +88,7 @@
"@types/react-dom": "^18.3.1",
"@types/react-router-dom": "^5.3.3",
"@types/react-syntax-highlighter": "^15.5.7",
"@types/redux-logger": "^3.0.13",
"@types/styled-components": "^5.1.26",
"@vitejs/plugin-react-swc": "^3.7.0",
"@vitest/coverage-v8": "^2.1.3",

View file

@ -14,6 +14,7 @@ import ConfirmationDialog from "../components/dialogs/ConfirmationDialog";
import { useWebviewListener } from "../hooks/useWebviewListener";
import { useAppDispatch, useAppSelector } from "../redux/hooks";
import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice";
import { selectSelectedProfile } from "../redux/slices/sessionSlice";
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
import {
updateOrgsThunk,
@ -60,9 +61,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
// Profiles
const profiles = useAppSelector((store) => store.session.availableProfiles);
const selectedProfile = useAppSelector(
(store) => store.session.selectedProfile,
);
const selectedProfile = useAppSelector(selectSelectedProfile);
const login: AuthContextType["login"] = (useOnboarding: boolean) => {
return new Promise((resolve) => {

View file

@ -15,6 +15,7 @@ import { saveCurrentSession } from "../../redux/thunks/session";
import IndexingProgress from "./IndexingProgress";
import KeyboardShortcuts from "./KeyboardShortcuts";
import MoreHelpRow from "./MoreHelpRow";
import { RulesPreview } from "./RulesPreview";
function MorePage() {
useNavigationListener();
@ -55,6 +56,10 @@ function MorePage() {
<DocsIndexingStatuses />
</div>
<div className="flex flex-col py-5">
<RulesPreview />
</div>
<div className="py-5">
<h3 className="mb-4 mt-0 text-xl">Help center</h3>
<div className="-mx-4 flex flex-col">

View file

@ -0,0 +1,36 @@
import { useAuth } from "../../../context/Auth";
/**
* 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 ?? [];
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>
))}
{rules.length === 0 && (
<div className="ml-6 mt-2 italic text-[#6a9955]">
# No rules defined
</div>
)}
</div>
</div>
);
}

View file

@ -9,6 +9,7 @@ import { IdeMessengerContext } from "../../context/IdeMessenger";
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
import { selectUseHub } from "../../redux/selectors";
import { selectDefaultModel } from "../../redux/slices/configSlice";
import { selectSelectedProfile } from "../../redux/slices/sessionSlice";
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
import { isLocalProfile } from "../../util";
import { providers } from "../AddNewModel/configs/providers";
@ -21,9 +22,7 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => {
const ideMessenger = useContext(IdeMessengerContext);
const selectedModel = useAppSelector(selectDefaultModel);
const hubEnabled = useAppSelector(selectUseHub);
const selectedProfile = useAppSelector(
(store) => store.session.selectedProfile,
);
const selectedProfile = useAppSelector(selectSelectedProfile);
const { session, refreshProfiles } = useAuth();
const handleRefreshProfiles = () => {

View file

@ -47,7 +47,7 @@ type SessionState = {
id: string;
/** null indicates loading state */
availableProfiles: ProfileDescription[] | null;
selectedProfile: ProfileDescription | null;
selectedProfileId: string | null;
organizations: OrganizationDescription[];
selectedOrganizationId: string | null;
streamAborter: AbortController;
@ -88,7 +88,7 @@ const initialState: SessionState = {
isStreaming: false,
title: NEW_SESSION_TITLE,
id: uuidv4(),
selectedProfile: null,
selectedProfileId: null,
availableProfiles: null,
organizations: [],
selectedOrganizationId: "",
@ -328,7 +328,7 @@ export const sessionSlice = createSlice({
!(!lastMessage.toolCalls?.length && !lastMessage.content) &&
// And there's a difference in tool call presence
(lastMessage.toolCalls?.length ?? 0) !==
(message.toolCalls?.length ?? 0))
(message.toolCalls?.length ?? 0))
) {
// Create a new message
const historyItem: ChatHistoryItemWithMessageId = {
@ -473,9 +473,9 @@ export const sessionSlice = createSlice({
state.allSessionMetadata = state.allSessionMetadata.map((session) =>
session.sessionId === payload.sessionId
? {
...session,
...payload,
}
...session,
...payload,
}
: session,
);
if (payload.title && payload.sessionId === state.id) {
@ -510,8 +510,9 @@ export const sessionSlice = createSlice({
payload.rangeInFileWithContents.filepath,
);
const lineNums = `(${payload.rangeInFileWithContents.range.start.line + 1
}-${payload.rangeInFileWithContents.range.end.line + 1})`;
const lineNums = `(${
payload.rangeInFileWithContents.range.start.line + 1
}-${payload.rangeInFileWithContents.range.end.line + 1})`;
contextItems.push({
name: `${fileName} ${lineNums}`,
@ -533,11 +534,8 @@ export const sessionSlice = createSlice({
},
// Important: these reducers don't handle selected profile/organization fallback logic
// That is done in thunks
setSelectedProfile: (
state,
{ payload }: PayloadAction<ProfileDescription | null>,
) => {
state.selectedProfile = payload;
setSelectedProfile: (state, { payload }: PayloadAction<string | null>) => {
state.selectedProfileId = payload;
},
setAvailableProfiles: (
state,
@ -670,6 +668,15 @@ export const sessionSlice = createSlice({
selectIsInEditMode: (state) => {
return state.mode === "edit";
},
selectSelectedProfile: (state) => {
// state.session.availableProfiles.find((p) => p.id === newId) ?? null,
return (
state.availableProfiles?.find(
(profile) => profile.id === state.selectedProfileId,
) ?? null
);
},
selectIsSingleRangeEditOrInsertion: (state) => {
if (state.mode !== "edit") {
return false;
@ -696,9 +703,9 @@ function addPassthroughCases(
) {
thunks.forEach((thunk) => {
builder
.addCase(thunk.fulfilled, (state, action) => { })
.addCase(thunk.rejected, (state, action) => { })
.addCase(thunk.pending, (state, action) => { });
.addCase(thunk.fulfilled, (state, action) => {})
.addCase(thunk.rejected, (state, action) => {})
.addCase(thunk.pending, (state, action) => {});
});
}
@ -765,6 +772,7 @@ export const {
export const {
selectIsGatheringContext,
selectIsInEditMode,
selectSelectedProfile,
selectIsSingleRangeEditOrInsertion,
selectHasCodeToEdit,
} = sessionSlice.selectors;

View file

@ -1,4 +1,5 @@
import { combineReducers, configureStore } from "@reduxjs/toolkit";
import { createLogger } from "redux-logger";
import {
createMigrate,
MigrationManifest,
@ -14,8 +15,8 @@ import editModeStateReducer from "./slices/editModeState";
import indexingReducer from "./slices/indexingSlice";
import miscReducer from "./slices/miscSlice";
import sessionReducer from "./slices/sessionSlice";
import uiReducer from "./slices/uiSlice";
import tabsReducer from "./slices/tabsSlice";
import uiReducer from "./slices/uiSlice";
export interface ChatMessage {
role: "system" | "user" | "assistant";
@ -75,11 +76,14 @@ const migrations: MigrationManifest = {
id: oldState?.state?.sessionId ?? "",
},
tabs: {
tabs: [{
id: Date.now().toString(36) + Math.random().toString(36).substring(2),
title: "Chat 1",
isActive: true
}]
tabs: [
{
id:
Date.now().toString(36) + Math.random().toString(36).substring(2),
title: "Chat 1",
isActive: true,
},
],
},
_persist: oldState?._persist,
};
@ -101,6 +105,13 @@ const persistedReducer = persistReducer<ReturnType<typeof rootReducer>>(
);
export function setupStore() {
const logger = createLogger({
// Customize logger options if needed
collapsed: true, // Collapse console groups by default
timestamp: false, // Remove timestamps from log
diff: true, // Show diff between states
});
return configureStore({
// persistedReducer causes type errors with async thunks
reducer: persistedReducer as unknown as typeof rootReducer,
@ -113,7 +124,7 @@ export function setupStore() {
ideMessenger: new IdeMessenger(),
},
},
}),
}).concat(logger),
});
}

View file

@ -21,7 +21,7 @@ export const selectProfileThunk = createAsyncThunk<
return;
}
const initialId = state.session.selectedProfile?.id;
const initialId = state.session.selectedProfileId;
let newId = id;
@ -44,11 +44,7 @@ export const selectProfileThunk = createAsyncThunk<
// Only update if there's a change
if ((newId ?? null) !== (initialId ?? null)) {
dispatch(
setSelectedProfile(
state.session.availableProfiles.find((p) => p.id === newId) ?? null,
),
);
dispatch(setSelectedProfile(newId));
extra.ideMessenger.post("didChangeSelectedProfile", {
id: newId,
});
@ -72,8 +68,8 @@ export const cycleProfile = createAsyncThunk<void, undefined, ThunkApiType>(
return;
}
let nextId = profileIds[0];
if (state.session.selectedProfile) {
const curIndex = profileIds.indexOf(state.session.selectedProfile?.id);
if (state.session.selectedProfileId) {
const curIndex = profileIds.indexOf(state.session.selectedProfileId);
const nextIndex = (curIndex + 1) % profileIds.length;
nextId = profileIds[nextIndex];
}