Skip to content

Commit d9699a6

Browse files
authored
Topic edit assistant (#267)
* edit one * PUT / POST switch based on if we are creating or editing * link to edit
1 parent 9dda0f5 commit d9699a6

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

frontend/src/App.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { MessageWithFiles } from "./utils/formTypes.ts";
1616
import { useNavigate } from "react-router-dom";
1717
import { useThreadAndAssistant } from "./hooks/useThreadAndAssistant.ts";
1818

19-
function App() {
19+
function App(props: { edit?: boolean }) {
2020
const navigate = useNavigate();
2121
const [sidebarOpen, setSidebarOpen] = useState(false);
2222
const { chats, createChat } = useChatList();
@@ -124,7 +124,7 @@ function App() {
124124
{currentChat && assistantConfig && (
125125
<Chat startStream={startTurn} stopStream={stopStream} stream={stream} />
126126
)}
127-
{!currentChat && assistantConfig && (
127+
{!currentChat && assistantConfig && !props.edit && (
128128
<NewChat
129129
startChat={startChat}
130130
configSchema={configSchema}
@@ -134,6 +134,17 @@ function App() {
134134
enterConfig={selectConfig}
135135
/>
136136
)}
137+
{!currentChat && assistantConfig && props.edit && (
138+
<Config
139+
className="mb-6"
140+
config={assistantConfig}
141+
configSchema={configSchema}
142+
configDefaults={configDefaults}
143+
saveConfig={saveConfig}
144+
enterConfig={selectConfig}
145+
edit={props.edit}
146+
/>
147+
)}
137148
{!currentChat && !assistantConfig && !isLoading && (
138149
<Config
139150
className="mb-6"

frontend/src/components/Config.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ export function Config(props: {
484484
config: ConfigInterface | null;
485485
saveConfig: ConfigListProps["saveConfig"];
486486
enterConfig: (id: string | null) => void;
487+
edit?: boolean;
487488
}) {
488489
const [values, setValues] = useState(
489490
props.config?.config ?? props.configDefaults,
@@ -537,9 +538,9 @@ export function Config(props: {
537538
}
538539
}, [dropzone.acceptedFiles, setFiles]);
539540
const [inflight, setInflight] = useState(false);
540-
const readonly = !!props.config && !inflight;
541+
const readonly = !!props.config && !props.edit && !inflight;
541542

542-
const settings = !props.config ? (
543+
const settings = !readonly ? (
543544
<div className="flex flex-row gap-4">
544545
<div className="flex flex-row flex-1">
545546
<div className="relative flex flex-grow items-stretch focus-within:z-10">
@@ -550,6 +551,7 @@ export function Config(props: {
550551
autoComplete="off"
551552
className="block w-full rounded-none rounded-l-md border-0 py-1.5 pl-4 text-gray-900 ring-1 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 ring-inset ring-gray-300"
552553
placeholder="Name your bot"
554+
defaultValue={props.config?.name}
553555
/>
554556
</div>
555557
<button
@@ -564,7 +566,7 @@ export function Config(props: {
564566
</div>
565567
) : (
566568
<>
567-
{props.config.public && (
569+
{props.config?.public && (
568570
<PublicLink assistantId={props.config?.assistant_id} />
569571
)}
570572
</>
@@ -585,7 +587,13 @@ export function Config(props: {
585587
vals.configurable["type==agent/tools"] = [...selectedTools];
586588
setSelectedTools([]);
587589
}
588-
const assistantId = await props.saveConfig(key, vals!, files, isPublic);
590+
const assistantId = await props.saveConfig(
591+
key,
592+
vals!,
593+
files,
594+
isPublic,
595+
props.config?.assistant_id,
596+
);
589597
props.enterConfig(assistantId);
590598
setInflight(false);
591599
}}

frontend/src/components/ConfigList.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { TYPES } from "../constants";
22
import { Config, ConfigListProps } from "../hooks/useConfigList";
33
import { cn } from "../utils/cn";
4+
import { PencilSquareIcon } from "@heroicons/react/24/outline";
5+
import { Link } from "react-router-dom";
46

57
function ConfigItem(props: {
68
config: Config;
@@ -41,6 +43,13 @@ function ConfigItem(props: {
4143
}
4244
</span>
4345
</div>
46+
<Link
47+
className="ml-auto w-5"
48+
to={`/assistant/${props.config.assistant_id}/edit`}
49+
onClick={(event) => event.stopPropagation()}
50+
>
51+
<PencilSquareIcon />
52+
</Link>
4453
</div>
4554
</li>
4655
);

frontend/src/hooks/useConfigList.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface ConfigListProps {
2222
config: Config["config"],
2323
files: File[],
2424
isPublic: boolean,
25+
assistantId?: string,
2526
) => Promise<string>;
2627
}
2728

@@ -64,15 +65,19 @@ export function useConfigList(): ConfigListProps {
6465
config: Config["config"],
6566
files: File[],
6667
isPublic: boolean,
68+
assistantId?: string,
6769
): Promise<string> => {
68-
const confResponse = await fetch(`/assistants`, {
69-
method: "POST",
70-
body: JSON.stringify({ name, config, public: isPublic }),
71-
headers: {
72-
"Content-Type": "application/json",
73-
Accept: "application/json",
70+
const confResponse = await fetch(
71+
assistantId ? `/assistants/${assistantId}` : "/assistants",
72+
{
73+
method: assistantId ? "PUT" : "POST",
74+
body: JSON.stringify({ name, config, public: isPublic }),
75+
headers: {
76+
"Content-Type": "application/json",
77+
Accept: "application/json",
78+
},
7479
},
75-
});
80+
);
7681
const savedConfig = (await confResponse.json()) as Config;
7782
if (files.length) {
7883
const assistant_id = savedConfig.assistant_id;

frontend/src/main.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
1919
<BrowserRouter>
2020
<Routes>
2121
<Route path="/thread/:chatId" element={<App />} />
22+
<Route
23+
path="/assistant/:assistantId/edit"
24+
element={<App edit={true} />}
25+
/>
2226
<Route path="/assistant/:assistantId" element={<App />} />
2327
<Route path="/" element={<App />} />
2428
<Route path="*" element={<NotFound />} />

0 commit comments

Comments
 (0)