Skip to content

Commit 2f9831a

Browse files
authored
Merge pull request #269 from njhale/enhance/fine-tune-edit
enhance: fine tune edit page
2 parents a1fcd63 + a0650e0 commit 2f9831a

File tree

23 files changed

+283
-208
lines changed

23 files changed

+283
-208
lines changed

app/edit/page.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import { useEffect, useState, Suspense, useContext } from 'react';
44
import { useSearchParams } from 'next/navigation';
5-
import Script from '@/components/script';
65
import Configure from '@/components/edit/configure';
76
import { EditContextProvider } from '@/contexts/edit';
8-
import { ScriptContextProvider } from '@/contexts/script';
7+
import { ChatContextProvider } from '@/contexts/chat';
98
import New from '@/components/edit/new';
109
import ScriptNav from '@/components/edit/scriptNav';
1110
import { NavContext } from '@/contexts/nav';
@@ -26,7 +25,7 @@ function EditFile() {
2625
<New className="w-1/2" setFile={setFile} />
2726
</div>
2827
) : (
29-
<ScriptContextProvider
28+
<ChatContextProvider
3029
initialScript={file}
3130
initialScriptId={scriptId}
3231
enableThread={false}
@@ -38,18 +37,10 @@ function EditFile() {
3837
<div className="absolute left-6 top-6">
3938
<ScriptNav collapsed={collapsed} setCollapsed={setCollapsed} />
4039
</div>
41-
<div
42-
className={`h-full overflow-auto w-full border-r-2 dark:border-zinc-800 p-6 ${collapsed ? '' : 'xl:px-20'}`}
43-
>
44-
<Configure collapsed={collapsed} />
45-
</div>
46-
<Script
47-
messagesHeight="h-[93%]"
48-
className={`p-6 overflow-auto ${collapsed ? 'col-span-3 px-32' : ''}`}
49-
/>
40+
<Configure collapsed={collapsed} />
5041
</div>
5142
</EditContextProvider>
52-
</ScriptContextProvider>
43+
</ChatContextProvider>
5344
);
5445
}
5546

app/page.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import { useSearchParams } from 'next/navigation';
44
import { Suspense, useContext, useEffect, useState } from 'react';
5-
import Script from '@/components/script';
5+
import Chat from '@/components/chat';
66
import Threads from '@/components/threads';
7-
import { ScriptContextProvider } from '@/contexts/script';
7+
import { ChatContextProvider } from '@/contexts/chat';
88
import { NavContext } from '@/contexts/nav';
99
import { tildy } from '@/config/assistant';
1010

@@ -21,7 +21,7 @@ function RunFile() {
2121
useEffect(() => setCurrent('/'), []);
2222

2323
return (
24-
<ScriptContextProvider
24+
<ChatContextProvider
2525
initialScript={script}
2626
initialScriptId={scriptId}
2727
enableThread={true}
@@ -34,12 +34,12 @@ function RunFile() {
3434
<div className="w-full h-full flex pb-10">
3535
<Threads />
3636
<div className="mx-auto w-[75%] 2xl:w-[55%] 3xl:[w-50%]">
37-
<Script enableThreads showAssistantName className="px-4 pb-10" />
37+
<Chat showAssistantName className="px-4 pb-10" />
3838
</div>
3939
</div>
4040
</div>
4141
</section>
42-
</ScriptContextProvider>
42+
</ChatContextProvider>
4343
);
4444
}
4545

components/script.tsx renamed to components/chat.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
'use client';
22

33
import { useContext, useEffect, useState, useRef, useCallback } from 'react';
4-
import Messages, { MessageType } from '@/components/script/messages';
5-
import ChatBar from '@/components/script/chatBar';
6-
import ToolForm from '@/components/script/form';
4+
import Messages, { MessageType } from '@/components/chat/messages';
5+
import ChatBar from '@/components/chat/chatBar';
6+
import ToolForm from '@/components/chat/form';
77
import Loading from '@/components/loading';
88
import { Button } from '@nextui-org/react';
99
import { getWorkspaceDir } from '@/actions/workspace';
1010
import { getGatewayUrl } from '@/actions/gateway';
11-
import { ScriptContext } from '@/contexts/script';
11+
import { ChatContext } from '@/contexts/chat';
1212
import AssistantNotFound from '@/components/assistant-not-found';
1313
import { generateThreadName, renameThread } from '@/actions/threads';
1414

1515
interface ScriptProps {
1616
className?: string;
1717
messagesHeight?: string;
18-
enableThreads?: boolean;
1918
showAssistantName?: boolean;
19+
inputPlaceholder?: string;
20+
disableInput?: boolean;
21+
disableCommands?: boolean;
2022
}
2123

22-
const Script: React.FC<ScriptProps> = ({
24+
const Chat: React.FC<ScriptProps> = ({
2325
className,
2426
messagesHeight = 'h-full',
2527
showAssistantName,
28+
inputPlaceholder,
29+
disableInput = false,
30+
disableCommands = false,
2631
}) => {
2732
const inputRef = useRef<HTMLInputElement>(null);
2833
const [inputValue, _setInputValue] = useState<string>('');
@@ -45,7 +50,7 @@ const Script: React.FC<ScriptProps> = ({
4550
notFound,
4651
restartScript,
4752
fetchThreads,
48-
} = useContext(ScriptContext);
53+
} = useContext(ChatContext);
4954

5055
useEffect(() => {
5156
if (inputRef.current) {
@@ -140,7 +145,12 @@ const Script: React.FC<ScriptProps> = ({
140145
{tool.chat ? 'Start chat' : 'Run script'}
141146
</Button>
142147
) : (
143-
<ChatBar disabled={!running} onMessageSent={handleMessageSent} />
148+
<ChatBar
149+
disableInput={disableInput || !running}
150+
disableCommands={disableCommands}
151+
inputPlaceholder={inputPlaceholder}
152+
onMessageSent={handleMessageSent}
153+
/>
144154
)}
145155
</div>
146156
</>
@@ -153,4 +163,4 @@ const Script: React.FC<ScriptProps> = ({
153163
);
154164
};
155165

156-
export default Script;
166+
export default Chat;

components/script/chatBar.tsx renamed to components/chat/chatBar.tsx

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ import { IoMdSend } from 'react-icons/io';
55
import { Spinner } from '@nextui-org/react';
66
import { FaBackward } from 'react-icons/fa';
77
import { Button, Textarea } from '@nextui-org/react';
8-
import Commands from '@/components/script/chatBar/commands';
8+
import Commands from '@/components/chat/chatBar/commands';
99
import { GoKebabHorizontal, GoSquareFill } from 'react-icons/go';
10-
import { ScriptContext } from '@/contexts/script';
11-
import { MessageType } from '@/components/script/messages';
10+
import { ChatContext } from '@/contexts/chat';
11+
import { MessageType } from '@/components/chat/messages';
1212

1313
interface ChatBarProps {
14-
disabled?: boolean;
14+
disableInput?: boolean;
15+
disableCommands?: boolean;
16+
inputPlaceholder?: string;
1517
onMessageSent: (message: string) => void;
1618
}
1719

18-
const ChatBar = ({ disabled = false, onMessageSent }: ChatBarProps) => {
20+
const ChatBar = ({
21+
disableInput = false,
22+
disableCommands = false,
23+
inputPlaceholder,
24+
onMessageSent,
25+
}: ChatBarProps) => {
1926
const [inputValue, setInputValue] = useState('');
2027
const [commandsOpen, setCommandsOpen] = useState(false);
2128
const [locked, setLocked] = useState(false);
@@ -27,7 +34,7 @@ const ChatBar = ({ disabled = false, onMessageSent }: ChatBarProps) => {
2734
setShowForm,
2835
messages,
2936
setMessages,
30-
} = useContext(ScriptContext);
37+
} = useContext(ChatContext);
3138
const [userMessages, setUserMessages] = useState<string[]>([]);
3239
const [_userMessagesIndex, setUserMessagesIndex] = useState(-1);
3340

@@ -70,7 +77,7 @@ const ChatBar = ({ disabled = false, onMessageSent }: ChatBarProps) => {
7077
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
7178
// if the user started the message with /, we assume they are trying to run a command
7279
// so we don't update the input value and instead open the command modal
73-
setCommandsOpen(event.target.value.startsWith('/'));
80+
if (!disableCommands) setCommandsOpen(event.target.value.startsWith('/'));
7481
setInputValue(event.target.value);
7582
};
7683

@@ -97,18 +104,20 @@ const ChatBar = ({ disabled = false, onMessageSent }: ChatBarProps) => {
97104

98105
return (
99106
<div className="flex px-4 space-x-2 sw-full">
100-
<Button
101-
isIconOnly
102-
startContent={<GoKebabHorizontal />}
103-
radius="full"
104-
className="text-lg"
105-
color="primary"
106-
onPress={() => {
107-
if (disabled) return;
108-
setCommandsOpen(true);
109-
}}
110-
onBlur={() => setTimeout(() => setCommandsOpen(false), 300)} // super hacky but it does work
111-
/>
107+
{!disableCommands && (
108+
<Button
109+
isIconOnly
110+
startContent={<GoKebabHorizontal />}
111+
radius="full"
112+
className="text-lg"
113+
color="primary"
114+
onPress={() => {
115+
if (disableInput) return;
116+
setCommandsOpen(true);
117+
}}
118+
onBlur={() => setTimeout(() => setCommandsOpen(false), 300)} // super hacky but it does work
119+
/>
120+
)}
112121
<div className="w-full relative">
113122
<Commands
114123
text={inputValue}
@@ -118,10 +127,12 @@ const ChatBar = ({ disabled = false, onMessageSent }: ChatBarProps) => {
118127
>
119128
<Textarea
120129
color="primary"
121-
isDisabled={disabled}
130+
isDisabled={disableInput}
122131
id="chatInput"
123132
autoComplete="off"
124-
placeholder="Start chatting or type / for more options "
133+
placeholder={
134+
inputPlaceholder || 'Start chatting or type / for more options'
135+
}
125136
value={inputValue}
126137
radius="full"
127138
minRows={1}
@@ -171,16 +182,17 @@ const ChatBar = ({ disabled = false, onMessageSent }: ChatBarProps) => {
171182
startContent={<GoSquareFill className="mr-[1px] text-xl" />}
172183
isIconOnly
173184
radius="full"
174-
isDisabled={disabled}
185+
isDisabled={disableInput}
175186
className="text-lg"
176187
onPress={interrupt}
177188
/>
178189
) : (
179190
<>
180-
{disabled ? (
191+
{disableInput && !disableCommands ? (
181192
<Spinner />
182193
) : (
183194
<Button
195+
disabled={!disableInput}
184196
startContent={<IoMdSend />}
185197
isIconOnly
186198
isDisabled={!inputValue}

components/script/chatBar/commands.tsx renamed to components/chat/chatBar/commands.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
GoTools,
1010
} from 'react-icons/go';
1111
import { PiToolbox } from 'react-icons/pi';
12-
import { ScriptContext } from '@/contexts/script';
13-
import Upload from '@/components/script/chatBar/upload';
14-
import ToolCatalog from '@/components/script/chatBar/toolCatalog';
15-
import { MessageType } from '@/components/script/messages';
12+
import { ChatContext } from '@/contexts/chat';
13+
import Upload from '@/components/chat/chatBar/upload';
14+
import ToolCatalog from '@/components/chat/chatBar/toolCatalog';
15+
import { MessageType } from '@/components/chat/messages';
1616
import { useFilePicker } from 'use-file-picker';
1717
import { uploadFile } from '@/actions/upload';
1818
import { ingest } from '@/actions/knowledge/knowledge';
@@ -105,7 +105,7 @@ export default function Commands({
105105
setTool,
106106
workspace,
107107
selectedThreadId,
108-
} = useContext(ScriptContext);
108+
} = useContext(ChatContext);
109109
const { openFilePicker, filesContent, loading, plainFiles } = useFilePicker(
110110
{}
111111
);

components/script/chatBar/upload.tsx renamed to components/chat/chatBar/upload.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { GoUpload, GoFile, GoX } from 'react-icons/go';
33
import Files from './upload/files';
44
import { uploadFile, lsFiles } from '@/actions/upload';
55
import { Dirent } from 'fs';
6-
import Workspace from '@/components/script/chatBar/upload/workspace';
7-
import { ScriptContext } from '@/contexts/script';
6+
import Workspace from '@/components/chat/chatBar/upload/workspace';
7+
import { ChatContext } from '@/contexts/chat';
88
import {
99
Modal,
1010
ModalContent,
@@ -24,7 +24,7 @@ const UploadModal = ({ isOpen, setIsOpen }: UploadModalProps) => {
2424
const [selectedFile, setSelectedFile] = useState<File | null>(null);
2525
const [files, setFiles] = useState<Dirent[]>([]);
2626
const selectedFileRef = useRef(selectedFile);
27-
const { workspace, restartScript } = useContext(ScriptContext);
27+
const { workspace, restartScript } = useContext(ChatContext);
2828

2929
useEffect(() => {
3030
selectedFileRef.current = selectedFile;

components/script/chatBar/upload/files.tsx renamed to components/chat/chatBar/upload/files.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@nextui-org/react';
1212
import { deleteFile, lsFiles } from '@/actions/upload';
1313
import { Dirent } from 'fs';
14-
import { ScriptContext } from '@/contexts/script';
14+
import { ChatContext } from '@/contexts/chat';
1515
import path from 'path';
1616

1717
interface FilesProps {
@@ -21,7 +21,7 @@ interface FilesProps {
2121

2222
const Files: React.FC<FilesProps> = ({ files, setFiles }) => {
2323
useEffect(() => fetchFiles(), []);
24-
const { workspace } = useContext(ScriptContext);
24+
const { workspace } = useContext(ChatContext);
2525

2626
const fetchFiles = useCallback(() => {
2727
lsFiles(workspace)

components/script/chatBar/upload/workspace.tsx renamed to components/chat/chatBar/upload/workspace.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useCallback, useContext, useEffect } from 'react';
2-
import { ScriptContext } from '@/contexts/script';
2+
import { ChatContext } from '@/contexts/chat';
33
import {
44
Modal,
55
ModalContent,
@@ -17,8 +17,7 @@ interface WorkspaceProps {
1717

1818
const Workspace = ({ onRestart }: WorkspaceProps) => {
1919
const [isOpen, setIsOpen] = useState(false);
20-
const { workspace, setWorkspace, selectedThreadId } =
21-
useContext(ScriptContext);
20+
const { workspace, setWorkspace, selectedThreadId } = useContext(ChatContext);
2221
const [workspaceInput, setWorkspaceInput] = useState<string>('');
2322

2423
useEffect(() => {
File renamed without changes.

0 commit comments

Comments
 (0)