Skip to content

Remove upload functionality and add tooltip for Code not in GitHub link #7431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 23, 2025
Merged
14 changes: 3 additions & 11 deletions frontend/src/components/features/chat/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ import { useGetTrajectory } from "#/hooks/mutation/use-get-trajectory";
import { downloadTrajectory } from "#/utils/download-trajectory";
import { displayErrorToast } from "#/utils/custom-toast-handlers";

function getEntryPoint(
hasRepository: boolean | null,
hasImportedProjectZip: boolean | null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, FWiW just the other day I tried it, and it did nothing. 🤷

): string {
function getEntryPoint(hasRepository: boolean | null): string {
if (hasRepository) return "github";
if (hasImportedProjectZip) return "zip";
return "direct";
}

Expand All @@ -48,7 +44,7 @@ export function ChatInterface() {
>("positive");
const [feedbackModalIsOpen, setFeedbackModalIsOpen] = React.useState(false);
const [messageToSend, setMessageToSend] = React.useState<string | null>(null);
const { selectedRepository, importedProjectZip } = useSelector(
const { selectedRepository } = useSelector(
(state: RootState) => state.initialQuery,
);
const params = useParams();
Expand All @@ -57,12 +53,8 @@ export function ChatInterface() {
const handleSendMessage = async (content: string, files: File[]) => {
if (messages.length === 0) {
posthog.capture("initial_query_submitted", {
entry_point: getEntryPoint(
selectedRepository !== null,
importedProjectZip !== null,
),
entry_point: getEntryPoint(selectedRepository !== null),
query_character_length: content.length,
uploaded_zip_size: importedProjectZip?.length,
});
} else {
posthog.capture("user_message_sent", {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { useDispatch } from "react-redux";
import { useCreateConversation } from "#/hooks/mutation/use-create-conversation";
import { setInitialPrompt } from "#/state/initial-query-slice";

const INITIAL_PROMPT = "";

export function CodeNotInGitHubLink() {
const dispatch = useDispatch();
const { mutate: createConversation } = useCreateConversation();

const handleStartFromScratch = () => {
// Set the initial prompt and create a new conversation
dispatch(setInitialPrompt(INITIAL_PROMPT));
createConversation({ q: INITIAL_PROMPT });
};

return (
<div className="text-xs text-neutral-400">
Code not in GitHub?{" "}
<span
onClick={handleStartFromScratch}
className="underline cursor-pointer"
>
Start from scratch
</span>{" "}
and use the VS Code link to upload and download your code.
</div>
);
}

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/components/shared/task-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function TaskForm({ ref }: TaskFormProps) {
};

return (
<div className="flex flex-col gap-2 w-full">
<div className="flex flex-col gap-1 w-full">
<form
ref={ref}
onSubmit={handleSubmit}
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/hooks/mutation/use-create-conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ export const useCreateConversation = () => {
const dispatch = useDispatch();
const queryClient = useQueryClient();

const { selectedRepository, files, importedProjectZip } = useSelector(
const { selectedRepository, files } = useSelector(
(state: RootState) => state.initialQuery,
);

return useMutation({
mutationFn: async (variables: { q?: string }) => {
if (
!variables.q?.trim() &&
!selectedRepository &&
files.length === 0 &&
!importedProjectZip
) {
throw new Error("No query provided");
}

if (variables.q) dispatch(setInitialPrompt(variables.q));

return OpenHands.createConversation(
Expand Down
26 changes: 6 additions & 20 deletions frontend/src/routes/_oh._index/route.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import React from "react";
import { useDispatch } from "react-redux";
import posthog from "posthog-js";
import { setImportedProjectZip } from "#/state/initial-query-slice";
import { convertZipToBase64 } from "#/utils/convert-zip-to-base64";
import { useGitHubUser } from "#/hooks/query/use-github-user";
import { useGitHubAuthUrl } from "#/hooks/use-github-auth-url";
import { useConfig } from "#/hooks/query/use-config";
import { ImportProjectSuggestionBox } from "../../components/features/suggestions/import-project-suggestion-box";
import { GitHubRepositoriesSuggestionBox } from "#/components/features/github/github-repositories-suggestion-box";
import { CodeNotInGitHubLink } from "#/components/features/github/code-not-in-github-link";
import { HeroHeading } from "#/components/shared/hero-heading";
import { TaskForm } from "#/components/shared/task-form";

function Home() {
const dispatch = useDispatch();
const formRef = React.useRef<HTMLFormElement>(null);

const { data: config } = useConfig();
Expand All @@ -29,29 +24,20 @@ function Home() {
className="bg-base-secondary h-full rounded-xl flex flex-col items-center justify-center relative overflow-y-auto px-2"
>
<HeroHeading />
<div className="flex flex-col gap-8 w-full md:w-[600px] items-center">
<div className="flex flex-col gap-1 w-full mt-8 md:w-[600px] items-center">
<div className="flex flex-col gap-2 w-full">
<TaskForm ref={formRef} />
</div>

<div className="flex gap-4 w-full flex-col md:flex-row">
<div className="flex gap-4 w-full flex-col md:flex-row mt-8">
<GitHubRepositoriesSuggestionBox
handleSubmit={() => formRef.current?.requestSubmit()}
gitHubAuthUrl={gitHubAuthUrl}
user={user || null}
/>
<ImportProjectSuggestionBox
onChange={async (event) => {
if (event.target.files) {
const zip = event.target.files[0];
dispatch(setImportedProjectZip(await convertZipToBase64(zip)));
posthog.capture("zip_file_uploaded");
formRef.current?.requestSubmit();
} else {
// TODO: handle error
}
}}
/>
</div>
<div className="w-full flex justify-start mt-2 ml-2">
<CodeNotInGitHubLink />
</div>
</div>
</div>
Expand Down
36 changes: 2 additions & 34 deletions frontend/src/routes/_oh.app/hooks/use-handle-runtime-active.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,12 @@
import React from "react";
import { useDispatch, useSelector } from "react-redux";
import { setImportedProjectZip } from "#/state/initial-query-slice";
import { useSelector } from "react-redux";
import { RootState } from "#/store";
import { base64ToBlob } from "#/utils/base64-to-blob";
import { useUploadFiles } from "../../../hooks/mutation/use-upload-files";

import { RUNTIME_INACTIVE_STATES } from "#/types/agent-state";
import { displayErrorToast } from "#/utils/custom-toast-handlers";

export const useHandleRuntimeActive = () => {
const dispatch = useDispatch();

const { mutate: uploadFiles } = useUploadFiles();
const { curAgentState } = useSelector((state: RootState) => state.agent);

const runtimeActive = !RUNTIME_INACTIVE_STATES.includes(curAgentState);

const { importedProjectZip } = useSelector(
(state: RootState) => state.initialQuery,
);

const handleUploadFiles = (zip: string) => {
const blob = base64ToBlob(zip);
const file = new File([blob], "imported-project.zip", {
type: blob.type,
});
uploadFiles(
{ files: [file] },
{
onError: () => {
displayErrorToast("Failed to upload project files.");
},
},
);
dispatch(setImportedProjectZip(null));
};

React.useEffect(() => {
if (runtimeActive && importedProjectZip) {
handleUploadFiles(importedProjectZip);
}
}, [runtimeActive, importedProjectZip]);
return { runtimeActive };
};
6 changes: 0 additions & 6 deletions frontend/src/state/initial-query-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ type SliceState = {
files: string[]; // base64 encoded images
initialPrompt: string | null;
selectedRepository: string | null;
importedProjectZip: string | null; // base64 encoded zip
};

const initialState: SliceState = {
files: [],
initialPrompt: null,
selectedRepository: null,
importedProjectZip: null,
};

export const selectedFilesSlice = createSlice({
Expand Down Expand Up @@ -39,9 +37,6 @@ export const selectedFilesSlice = createSlice({
clearSelectedRepository(state) {
state.selectedRepository = null;
},
setImportedProjectZip(state, action: PayloadAction<string | null>) {
state.importedProjectZip = action.payload;
},
},
});

Expand All @@ -53,6 +48,5 @@ export const {
clearInitialPrompt,
setSelectedRepository,
clearSelectedRepository,
setImportedProjectZip,
} = selectedFilesSlice.actions;
export default selectedFilesSlice.reducer;
10 changes: 0 additions & 10 deletions frontend/src/utils/convert-zip-to-base64.ts

This file was deleted.

Loading