mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Add route for starting a chat from a repository (#90)
This commit is contained in:
parent
ccfee95851
commit
16ee8276f9
@ -13,10 +13,14 @@ export const currentChatId = atom<string | undefined>(undefined);
|
|||||||
export const currentChatTitle = atom<string | undefined>(undefined);
|
export const currentChatTitle = atom<string | undefined>(undefined);
|
||||||
|
|
||||||
export function useChatHistory() {
|
export function useChatHistory() {
|
||||||
const { id: mixedId, problemId } = useLoaderData<{ id?: string; problemId?: string }>() ?? {};
|
const {
|
||||||
|
id: mixedId,
|
||||||
|
problemId,
|
||||||
|
repositoryId,
|
||||||
|
} = useLoaderData<{ id?: string; problemId?: string; repositoryId?: string }>() ?? {};
|
||||||
|
|
||||||
const [initialMessages, setInitialMessages] = useState<Message[]>([]);
|
const [initialMessages, setInitialMessages] = useState<Message[]>([]);
|
||||||
const [ready, setReady] = useState<boolean>(!mixedId && !problemId);
|
const [ready, setReady] = useState<boolean>(!mixedId && !problemId && !repositoryId);
|
||||||
|
|
||||||
const importChat = async (title: string, messages: Message[]) => {
|
const importChat = async (title: string, messages: Message[]) => {
|
||||||
try {
|
try {
|
||||||
@ -32,6 +36,16 @@ export function useChatHistory() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadRepository = async (repositoryId: string) => {
|
||||||
|
const messages = createMessagesForRepository(`Repository: ${repositoryId}`, repositoryId);
|
||||||
|
await importChat(`Repository: ${repositoryId}`, messages);
|
||||||
|
toast.success('Repository loaded successfully');
|
||||||
|
};
|
||||||
|
|
||||||
|
const debouncedSetChatContents = debounce(async (messages: Message[]) => {
|
||||||
|
await setChatContents(currentChatId.get() as string, currentChatTitle.get() as string, messages);
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
@ -51,6 +65,9 @@ export function useChatHistory() {
|
|||||||
} else if (problemId) {
|
} else if (problemId) {
|
||||||
await loadProblem(problemId, importChat);
|
await loadProblem(problemId, importChat);
|
||||||
setReady(true);
|
setReady(true);
|
||||||
|
} else if (repositoryId) {
|
||||||
|
await loadRepository(repositoryId);
|
||||||
|
setReady(true);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logStore.logError('Failed to load chat messages', error);
|
logStore.logError('Failed to load chat messages', error);
|
||||||
@ -62,7 +79,7 @@ export function useChatHistory() {
|
|||||||
return {
|
return {
|
||||||
ready,
|
ready,
|
||||||
initialMessages,
|
initialMessages,
|
||||||
storeMessageHistory: debounce(async (messages: Message[]) => {
|
storeMessageHistory: async (messages: Message[]) => {
|
||||||
if (messages.length === 0) {
|
if (messages.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -74,8 +91,8 @@ export function useChatHistory() {
|
|||||||
navigateChat(id);
|
navigateChat(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
await setChatContents(currentChatId.get() as string, currentChatTitle.get() as string, messages);
|
debouncedSetChatContents(messages);
|
||||||
}, 1000),
|
},
|
||||||
importChat,
|
importChat,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
8
app/routes/repository.$id.tsx
Normal file
8
app/routes/repository.$id.tsx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { json, type LoaderFunctionArgs } from '~/lib/remix-types';
|
||||||
|
import { default as IndexRoute } from './_index';
|
||||||
|
|
||||||
|
export async function loader(args: LoaderFunctionArgs) {
|
||||||
|
return json({ repositoryId: args.params.id });
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IndexRoute;
|
||||||
Loading…
Reference in New Issue
Block a user