chore: Delete unused code (#551)

This commit is contained in:
Brace Sproul 2025-07-26 13:47:30 -07:00 • committed by GitHub
parent b2946ebf49
commit 83771e3ff7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 185 deletions

View file

@ -1,82 +0,0 @@
"use client";
import { useStreamContext } from "@/providers/Stream";
import { TooltipIconButton } from "@/components/ui/tooltip-icon-button";
import { useQueryState } from "nuqs";
import {
GitPullRequest,
GitMerge,
GitPullRequestClosed,
GitPullRequestDraft,
} from "lucide-react";
import { useEffect, useState } from "react";
import { getPullRequest } from "@/utils/github";
import { cn } from "@/lib/utils";
export function OpenPRButton() {
const stream = useStreamContext();
const [branch] = useQueryState("branch");
const [prState, setPrState] = useState<
"open" | "closed" | "draft" | "merged"
>();
const [pullRequest, setPullRequest] = useState<Record<string, any>>();
useEffect(() => {
const baseBranch =
stream.values?.targetRepository?.branch ??
stream.values?.targetRepository?.baseCommit ??
branch;
if (
!stream.values ||
!stream.values.branchName ||
!stream.values.targetRepository ||
!baseBranch
) {
return;
}
getPullRequest({
owner: stream.values.targetRepository.owner,
repo: stream.values.targetRepository.repo,
baseBranch: baseBranch,
headBranch: stream.values.branchName,
}).then((pr) => {
if (!pr) return;
setPullRequest(pr);
if (pr.merged_at) {
setPrState("merged");
} else if (pr.draft) {
setPrState("draft");
} else {
setPrState(pr.state);
}
});
}, [stream.values?.branchName, stream.values?.targetRepository, branch]);
if (!pullRequest) {
return null;
}
const handleOpenPR = () => {
window.open(pullRequest.html_url, "_blank", "noopener,noreferrer");
};
return (
<TooltipIconButton
tooltip={`Open Pull Request #${pullRequest.number}`}
variant="ghost"
onClick={handleOpenPR}
className={cn({
"text-green-500 hover:text-green-600": prState === "open",
"text-red-500 hover:text-red-600": prState === "closed",
"text-gray-500 hover:text-gray-600": prState === "draft",
"text-[#8957e5] hover:text-[#7847d1]": prState === "merged",
})}
size="sm"
>
{prState === "merged" && <GitMerge className="size-4" />}
{prState === "draft" && <GitPullRequestDraft className="size-4" />}
{prState === "closed" && <GitPullRequestClosed className="size-4" />}
{prState === "open" && <GitPullRequest className="size-4" />}
</TooltipIconButton>
);
}

View file

@ -1,4 +1,3 @@
import { useStreamContext } from "@/providers/Stream";
import { Message } from "@langchain/langgraph-sdk";
import { useState } from "react";
import { getContentString } from "../utils";
@ -8,6 +7,7 @@ import { BranchSwitcher, CommandBar } from "./shared";
import { MultimodalPreview } from "@/components/thread/MultimodalPreview";
import { isBase64ContentBlock } from "@/lib/multimodal-utils";
import { BaseMessage } from "@langchain/core/messages";
import { useStream } from "@langchain/langgraph-sdk/react";
function EditableContent({
value,
@ -38,12 +38,17 @@ function EditableContent({
export function HumanMessage({
message,
isLoading,
submit,
setBranch,
getMessagesMetadata,
}: {
message: Message;
isLoading: boolean;
submit: ReturnType<typeof useStream>["submit"];
setBranch: ReturnType<typeof useStream>["setBranch"];
getMessagesMetadata: ReturnType<typeof useStream>["getMessagesMetadata"];
}) {
const thread = useStreamContext();
const meta = thread.getMessagesMetadata(message);
const meta = getMessagesMetadata(message);
const parentCheckpoint = meta?.firstSeenState?.parent_checkpoint;
const [isEditing, setIsEditing] = useState(false);
@ -57,7 +62,7 @@ export function HumanMessage({
type: "human",
content: value,
} as unknown as BaseMessage;
thread.submit(
submit(
{ messages: [newMessage], internalMessages: [newMessage] },
{
checkpoint: parentCheckpoint,
@ -69,7 +74,7 @@ export function HumanMessage({
return {
...values,
messages: [
...(values.messages ?? []),
...((values.messages as Message[]) ?? []),
newMessage,
] as unknown as BaseMessage[],
};
@ -136,7 +141,7 @@ export function HumanMessage({
<BranchSwitcher
branch={meta?.branch}
branchOptions={meta?.branchOptions}
onSelect={(branch) => thread.setBranch(branch)}
onSelect={(branch) => setBranch(branch)}
isLoading={isLoading}
/>
<CommandBar

View file

@ -1,97 +0,0 @@
import React, { createContext, useContext, ReactNode, useState } from "react";
import { useStream } from "@langchain/langgraph-sdk/react";
import {
uiMessageReducer,
isUIMessage,
isRemoveUIMessage,
type UIMessage,
type RemoveUIMessage,
} from "@langchain/langgraph-sdk/react-ui";
import { useQueryState } from "nuqs";
import { useThreadsContext } from "./Thread";
import { GraphState, GraphUpdate } from "@open-swe/shared/open-swe/types";
import {
CustomNodeEvent,
isCustomNodeEvent,
} from "@open-swe/shared/open-swe/custom-node-events";
import { MANAGER_GRAPH_ID } from "@open-swe/shared/constants";
const useTypedStream = useStream<
GraphState,
{
UpdateType: GraphUpdate;
CustomEventType: UIMessage | RemoveUIMessage;
}
>;
type StreamContextType = ReturnType<typeof useTypedStream> & {
customEvents: CustomNodeEvent[];
};
const StreamContext = createContext<StreamContextType | undefined>(undefined);
async function sleep(ms = 4000) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
const StreamSession = ({ children }: { children: ReactNode }) => {
const [threadId, setThreadId] = useQueryState("threadId");
const [customEvents, setCustomEvents] = useState<CustomNodeEvent[]>([]);
const { refreshThreads } = useThreadsContext();
if (!process.env.NEXT_PUBLIC_API_URL) {
throw new Error(
"NEXT_PUBLIC_API_URL environment variable must be defined.",
);
}
const streamValue = useTypedStream({
apiUrl: process.env.NEXT_PUBLIC_API_URL,
assistantId: MANAGER_GRAPH_ID,
reconnectOnMount: true,
threadId: threadId ?? null,
onCustomEvent: (event, options) => {
if (isCustomNodeEvent(event)) {
setCustomEvents((prev) => [...prev, event]);
}
if (isUIMessage(event) || isRemoveUIMessage(event)) {
options.mutate((prev) => {
const ui = uiMessageReducer(prev.ui ?? [], event);
return { ...prev, ui };
});
}
},
onThreadId: (id) => {
setThreadId(id);
sleep().then(() => {
refreshThreads().catch(console.error);
});
},
});
return (
<StreamContext.Provider
value={{
...streamValue,
customEvents,
}}
>
{children}
</StreamContext.Provider>
);
};
export const StreamProvider: React.FC<{
children: ReactNode;
}> = ({ children }) => {
return <StreamSession>{children}</StreamSession>;
};
export const useStreamContext = (): StreamContextType => {
const context = useContext(StreamContext);
if (context === undefined) {
throw new Error("useStreamContext must be used within a StreamProvider");
}
return context;
};
export default StreamContext;