Skip to content

Commit 53b7f84

Browse files
authored
feat: add chat settings (#1911)
* refactor: ai * add user settings schema, query and mutation * hide mini chat and suggetion * protect procedures * working auto apply
1 parent 9919386 commit 53b7f84

File tree

27 files changed

+242
-248
lines changed

27 files changed

+242
-248
lines changed

apps/web/client/src/app/project/[id]/_components/canvas/frame/right-click.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Hotkey } from '@/components/hotkey';
22
import { IDE } from '@/components/ide';
33
import { useEditorEngine } from '@/components/store/editor';
4-
import { useUserManager } from '@/components/store/user';
54
import { DEFAULT_IDE, EditorTabValue, type DomElement } from '@onlook/models';
65
import {
76
ContextMenu,
@@ -32,9 +31,8 @@ interface MenuItem {
3231

3332
export const RightClickMenu = observer(({ children }: RightClickMenuProps) => {
3433
const editorEngine = useEditorEngine();
35-
const userManager = useUserManager();
3634
const [menuItems, setMenuItems] = useState<MenuItem[][]>([]);
37-
const ide = IDE.fromType(userManager.settings.settings?.editor?.ideType ?? DEFAULT_IDE);
35+
const ide = IDE.fromType(DEFAULT_IDE);
3836

3937
useEffect(() => {
4038
updateMenuItems();

apps/web/client/src/app/project/[id]/_components/canvas/hotkeys/delete.tsx

Lines changed: 0 additions & 80 deletions
This file was deleted.

apps/web/client/src/app/project/[id]/_components/canvas/hotkeys/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// import { useEditorEngine } from '@/components/Context';
21
import { Hotkey } from '@/components/hotkey';
32
import { useEditorEngine } from '@/components/store/editor';
43
import { DefaultSettings } from '@onlook/constants';
54
import { EditorMode, EditorTabValue } from '@onlook/models';
65
import type { ReactNode } from 'react';
76
import { useHotkeys } from 'react-hotkeys-hook';
8-
import { DeleteKey } from './delete';
97

108
export const HotkeysArea = ({ children }: { children: ReactNode }) => {
119
const editorEngine = useEditorEngine();
@@ -56,6 +54,7 @@ export const HotkeysArea = ({ children }: { children: ReactNode }) => {
5654
useHotkeys(Hotkey.ENTER.command, () => editorEngine.text.editSelectedElement());
5755
useHotkeys(Hotkey.REFRESH_LAYERS.command, () => editorEngine.refreshLayers());
5856
useHotkeys(Hotkey.OPEN_DEV_TOOL.command, () => editorEngine.inspect());
57+
useHotkeys([Hotkey.BACKSPACE.command, Hotkey.DELETE.command], () => editorEngine.elements.delete());
5958

6059
// Group
6160
useHotkeys(Hotkey.GROUP.command, () => editorEngine.group.groupSelectedElements());
@@ -93,7 +92,6 @@ export const HotkeysArea = ({ children }: { children: ReactNode }) => {
9392

9493
return (
9594
<>
96-
<DeleteKey />
9795
{children}
9896
</>
9997
);

apps/web/client/src/app/project/[id]/_components/canvas/overlay/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { EditorMode } from '@onlook/models';
55
import { cn } from '@onlook/ui/utils';
66
import { observer } from 'mobx-react-lite';
77
import { useMemo } from 'react';
8-
import { OverlayChat } from './elements/chat';
98
import { MeasurementOverlay } from './elements/measurement';
109
import { ClickRect } from './elements/rect/click';
1110
import { HoverRect } from './elements/rect/hover';
@@ -70,12 +69,13 @@ export const Overlay = observer(() => {
7069
toRect={overlayState.measurement.toRect}
7170
/>
7271
)}
73-
{overlayState.clickRects.length > 0 && (
72+
{/* TODO: Reenable overlay chat */}
73+
{/* {overlayState.clickRects.length > 0 && (
7474
<OverlayChat
7575
elementId={editorEngine.elements.selected[0]?.domId ?? ''}
7676
selectedEl={overlayState.clickRects[0] ?? null}
7777
/>
78-
)}
78+
)} */}
7979
</div>
8080
);
8181
});

apps/web/client/src/app/project/[id]/_components/right-click-menu/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Hotkey } from '@/components/hotkey';
22
import { IDE } from '@/components/ide';
33
import { useEditorEngine } from '@/components/store/editor';
4-
import { useUserManager } from '@/components/store/user';
54
import { EditorTabValue } from '@onlook/models/editor';
65
import type { DomElement } from '@onlook/models/element';
76
import { DEFAULT_IDE } from '@onlook/models/ide';
@@ -34,9 +33,8 @@ interface MenuItem {
3433

3534
export const RightClickMenu = observer(({ children }: RightClickMenuProps) => {
3635
const editorEngine = useEditorEngine();
37-
const userManager = useUserManager();
3836
const [menuItems, setMenuItems] = useState<MenuItem[][]>([]);
39-
const ide = IDE.fromType(userManager.settings.settings?.editor?.ideType ?? DEFAULT_IDE);
37+
const ide = IDE.fromType(DEFAULT_IDE);
4038

4139
useEffect(() => {
4240
updateMenuItems();

apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { observer } from 'mobx-react-lite';
1515
import { useTranslations } from 'next-intl';
1616
import { useEffect, useRef, useState } from 'react';
1717
import { InputContextPills } from '../context-pills/input-context-pills';
18-
import { Suggestions, type SuggestionsRef } from '../suggestions';
18+
import { type SuggestionsRef } from '../suggestions';
1919
import { ActionButtons } from './action-buttons';
2020

2121
export const ChatInput = observer(() => {
@@ -236,7 +236,8 @@ export const ChatInput = observer(() => {
236236
}
237237
}}
238238
>
239-
<Suggestions
239+
{/* TODO: Reenable suggestions */}
240+
{/* <Suggestions
240241
ref={suggestionRef}
241242
disabled={disabled}
242243
inputValue={inputValue}
@@ -254,7 +255,7 @@ export const ChatInput = observer(() => {
254255
textareaRef.current?.focus();
255256
}
256257
}}
257-
/>
258+
/> */}
258259
<div className="flex flex-col w-full p-4">
259260
<InputContextPills />
260261
<Textarea

apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/panel-dropdown.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useEditorEngine } from '@/components/store/editor';
22
import { useUserManager } from '@/components/store/user';
3-
import { DefaultSettings } from '@onlook/constants';
43
import type { ChatSettings } from '@onlook/models';
54
import { EditorTabValue } from '@onlook/models';
65
import {
@@ -12,8 +11,9 @@ import {
1211
} from '@onlook/ui/dropdown-menu';
1312
import { Icons } from '@onlook/ui/icons';
1413
import { cn } from '@onlook/ui/utils';
14+
import { observer } from 'mobx-react-lite';
1515

16-
export const ChatPanelDropdown = ({
16+
export const ChatPanelDropdown = observer(({
1717
children,
1818
isChatHistoryOpen,
1919
setIsChatHistoryOpen,
@@ -25,7 +25,7 @@ export const ChatPanelDropdown = ({
2525
const userManager = useUserManager();
2626
const editorEngine = useEditorEngine();
2727

28-
const chatSettings = userManager.settings.settings?.chat ?? DefaultSettings.CHAT_SETTINGS;
28+
const chatSettings = userManager.settings.settings.chat;
2929
const selectedTab = editorEngine.state.rightPanelTab;
3030

3131
const updateChatSettings = (e: React.MouseEvent, settings: Partial<ChatSettings>) => {
@@ -39,55 +39,60 @@ export const ChatPanelDropdown = ({
3939
<div className="flex items-center">{children}</div>
4040
</DropdownMenuTrigger>
4141
<DropdownMenuContent className="min-w-[220px]">
42+
4243
<DropdownMenuItem
4344
className="flex items-center py-1.5"
4445
onClick={(e) => {
4546
updateChatSettings(e, {
46-
showSuggestions: !chatSettings.showSuggestions,
47+
autoApplyCode: !chatSettings.autoApplyCode,
4748
});
4849
}}
4950
>
5051
<Icons.Check
5152
className={cn(
5253
'mr-2 h-4 w-4',
53-
chatSettings.showSuggestions ? 'opacity-100' : 'opacity-0',
54+
chatSettings.autoApplyCode ? 'opacity-100' : 'opacity-0',
5455
)}
5556
/>
56-
Show suggestions
57+
Auto - apply results
5758
</DropdownMenuItem>
5859
<DropdownMenuItem
5960
className="flex items-center py-1.5"
6061
onClick={(e) => {
6162
updateChatSettings(e, {
62-
autoApplyCode: !chatSettings.autoApplyCode,
63+
expandCodeBlocks: !chatSettings.expandCodeBlocks,
6364
});
6465
}}
6566
>
6667
<Icons.Check
6768
className={cn(
6869
'mr-2 h-4 w-4',
69-
chatSettings.autoApplyCode ? 'opacity-100' : 'opacity-0',
70+
chatSettings.expandCodeBlocks ? 'opacity-100' : 'opacity-0',
7071
)}
7172
/>
72-
Auto - apply results
73+
Show code while rendering
7374
</DropdownMenuItem>
74-
<DropdownMenuItem
75+
76+
{/* TODO: Reenable */}
77+
{/* <DropdownMenuItem
7578
className="flex items-center py-1.5"
7679
onClick={(e) => {
7780
updateChatSettings(e, {
78-
expandCodeBlocks: !chatSettings.expandCodeBlocks,
81+
showSuggestions: !chatSettings.showSuggestions,
7982
});
8083
}}
8184
>
8285
<Icons.Check
8386
className={cn(
8487
'mr-2 h-4 w-4',
85-
chatSettings.expandCodeBlocks ? 'opacity-100' : 'opacity-0',
88+
chatSettings.showSuggestions ? 'opacity-100' : 'opacity-0',
8689
)}
8790
/>
88-
Show code while rendering
89-
</DropdownMenuItem>
90-
<DropdownMenuItem
91+
Show suggestions
92+
</DropdownMenuItem> */}
93+
94+
{/* TODO: Reenable */}
95+
{/* <DropdownMenuItem
9196
className="flex items-center py-1.5"
9297
onClick={(e) => {
9398
updateChatSettings(e, {
@@ -102,7 +107,7 @@ export const ChatPanelDropdown = ({
102107
)}
103108
/>
104109
Show mini chat
105-
</DropdownMenuItem>
110+
</DropdownMenuItem> */}
106111
<DropdownMenuSeparator />
107112
<DropdownMenuItem onClick={() => setIsChatHistoryOpen(!isChatHistoryOpen)}>
108113
<Icons.CounterClockwiseClock className="mr-2 h-4 w-4" />
@@ -111,4 +116,4 @@ export const ChatPanelDropdown = ({
111116
</DropdownMenuContent>
112117
</DropdownMenu>
113118
);
114-
};
119+
});

apps/web/client/src/components/store/editor/chat/conversation/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type ChatConversation, type ChatMessageContext } from '@onlook/models';
44
import type { Project } from '@onlook/models/project';
55
import type { Message } from 'ai';
66
import { makeAutoObservable, reaction } from 'mobx';
7+
import type { ChatManager } from '..';
78
import { AssistantChatMessageImpl } from '../message/assistant';
89
import { UserChatMessageImpl } from '../message/user';
910
import { ChatConversationImpl, type ChatMessageImpl } from './conversation';
@@ -14,6 +15,7 @@ export class ConversationManager {
1415
private _conversations: ChatConversation[] = [];
1516

1617
constructor(
18+
private chatManager: ChatManager,
1719
private projectManager: ProjectManager,
1820
) {
1921
makeAutoObservable(this);
@@ -142,6 +144,7 @@ export class ConversationManager {
142144
}
143145
const newMessage = AssistantChatMessageImpl.fromMessage(message);
144146
await this.addMessage(newMessage);
147+
this.chatManager.autoApplyCode(newMessage);
145148
return newMessage;
146149
}
147150

apps/web/client/src/components/store/editor/chat/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ChatManager {
2525
private userManager: UserManager,
2626
) {
2727
this.context = new ChatContext(this.editorEngine, this.projectManager);
28-
this.conversation = new ConversationManager(this.projectManager);
28+
this.conversation = new ConversationManager(this, this.projectManager);
2929
this.code = new ChatCodeManager(this, this.editorEngine);
3030
this.suggestions = new SuggestionManager(this.projectManager);
3131
makeAutoObservable(this);
@@ -121,16 +121,16 @@ export class ChatManager {
121121
console.error('No conversation found');
122122
return null;
123123
}
124-
// Save current changes before sending to AI
124+
this.createCommit(userPrompt);
125+
return this.conversation.current.getMessagesForStream();
126+
}
125127

128+
createCommit(userPrompt?: string) {
126129
// TODO: Reenable this
127-
// this.projectsManager.versions?.createCommit(
128-
// userPrompt ?? "Save before chat",
130+
// this.projectManager.versions?.createCommit(
131+
// "Save before chat",
129132
// false,
130133
// );
131-
132-
const messages = this.conversation.current.getMessagesForStream();
133-
return messages;
134134
}
135135

136136
autoApplyCode(assistantMessage: AssistantChatMessage) {

0 commit comments

Comments
 (0)