fix: Type errors where thread value is undefined (#144)

This commit is contained in:
Brace Sproul 2025-06-12 13:34:46 -07:00 • committed by GitHub
parent f549d119ab
commit baab1e989a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 10 deletions

View file

@ -23,10 +23,11 @@ export function OpenPRButton() {
useEffect(() => {
const baseBranch =
stream.values.targetRepository?.branch ??
stream.values.targetRepository?.baseCommit ??
stream.values?.targetRepository?.branch ??
stream.values?.targetRepository?.baseCommit ??
branch;
if (
!stream.values ||
!stream.values.branchName ||
!stream.values.targetRepository ||
!baseBranch
@ -49,7 +50,7 @@ export function OpenPRButton() {
setPrState(pr.state);
}
});
}, [stream.values?.branchName, stream.values.targetRepository, branch]);
}, [stream.values?.branchName, stream.values?.targetRepository, branch]);
if (!pullRequest) {
return null;

View file

@ -86,12 +86,12 @@ export const ThreadItem = memo(function ThreadItem({
className="flex-shrink-0"
/>
<span className="max-w-[90px] truncate">
{thread.values.targetRepository.repo}
{thread.values?.targetRepository?.repo || "x"}
</span>
<span>/</span>
<GitBranch className="size-2.5 flex-shrink-0" />
<span className="max-w-[70px] truncate">
{thread.values.targetRepository.branch}
{thread.values?.targetRepository?.branch || "x"}
</span>
</div>

View file

@ -32,10 +32,10 @@ function ThreadList({
typeof t.values === "object" &&
t.values &&
"messages" in t.values &&
Array.isArray(t.values.messages) &&
t.values.messages?.length > 0
Array.isArray(t.values?.messages) &&
t.values?.messages?.length > 0
) {
const firstMessage = t.values.messages[0];
const firstMessage = t.values?.messages[0];
itemText = getContentString(firstMessage.content);
}
return (

View file

@ -4,7 +4,7 @@ import { GraphState } from "@open-swe/shared/open-swe/types";
import { getActivePlanItems } from "@open-swe/shared/open-swe/tasks";
export function getThreadTitle(thread: Thread<GraphState>): string {
const messages = thread?.values.messages;
const messages = thread?.values?.messages;
if (!messages?.length || !messages[0]?.content) {
return `Thread ${thread.thread_id.substring(0, 8)}`;
}
@ -16,7 +16,7 @@ export function getThreadTasks(thread: Thread<GraphState>): {
totalTasks: number;
completedTasks: number;
} {
if (!thread.values.plan) {
if (!thread.values || !thread.values?.plan) {
return {
totalTasks: 0,
completedTasks: 0,