Skip to content

Commit f525528

Browse files
committed
fix merge conflicts studio <> invalid interrupts
1 parent 6a69dc6 commit f525528

File tree

4 files changed

+102
-149
lines changed

4 files changed

+102
-149
lines changed

src/components/agent-inbox/components/generic-inbox-item.tsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ import { ThreadIdCopyable } from "./thread-id";
44
import { InboxItemStatuses } from "./statuses";
55
import { format } from "date-fns";
66
import { useQueryParams } from "../hooks/use-query-params";
7-
import { VIEW_STATE_THREAD_QUERY_PARAM } from "../constants";
8-
9-
import { GenericThreadData } from "../types";
10-
import { useToast } from "@/hooks/use-toast";
11-
import { constructOpenInStudioURL } from "../utils";
12-
import { Button } from "@/components/ui/button";
13-
import { useThreadsContext } from "../contexts/ThreadContext";
14-
import { useQueryParams } from "../hooks/use-query-params";
157
import {
168
STUDIO_NOT_WORKING_TROUBLESHOOTING_URL,
179
VIEW_STATE_THREAD_QUERY_PARAM,
1810
} from "../constants";
11+
import { GenericThreadData } from "../types";
12+
import { useToast } from "@/hooks/use-toast";
13+
import { Button } from "@/components/ui/button";
14+
import { useThreadsContext } from "../contexts/ThreadContext";
15+
16+
import { constructOpenInStudioURL } from "../utils";
1917

2018
interface GenericInboxItemProps<
2119
ThreadValues extends Record<string, any> = Record<string, any>,
@@ -34,6 +32,8 @@ export function GenericInboxItem<
3432
ThreadValues extends Record<string, any> = Record<string, any>,
3533
>({ threadData, isLast }: GenericInboxItemProps<ThreadValues>) {
3634
const { updateQueryParams } = useQueryParams();
35+
const { toast } = useToast();
36+
const { agentInboxes } = useThreadsContext();
3737

3838
const selectedInbox = agentInboxes.find((i) => i.selected);
3939

@@ -82,7 +82,6 @@ export function GenericInboxItem<
8282
}
8383
};
8484

85-
8685
const updatedAtDateString = format(
8786
new Date(threadData.thread.updated_at),
8887
"MM/dd h:mm a"
@@ -101,22 +100,22 @@ export function GenericInboxItem<
101100
!isLast && "border-b-[1px] border-gray-200"
102101
)}
103102
>
104-
<div className="flex items-center gap-2">
105-
<div className="col-span-1 flex justify-center pt-6">
103+
<div className="col-span-1 flex justify-center items-center">
106104
{/* Empty space for alignment with interrupted items */}
107105
</div>
106+
108107
<div
109108
className={cn(
110-
"flex items-center justify-start gap-2",
111-
selectedInbox ? "col-span-7" : "col-span-9"
109+
"col-span-6 flex items-center justify-start gap-2",
110+
!selectedInbox && "col-span-9"
112111
)}
113112
>
114-
<p className="text-sm font-semibold text-black">Thread ID:</p>
113+
<p className="text-sm font-semibold text-black">Thread ID:</p>
115114
<ThreadIdCopyable showUUID threadId={threadData.thread.thread_id} />
116115
</div>
117116

118117
{selectedInbox && (
119-
<div className="col-span-2">
118+
<div className="col-span-2 flex items-center">
120119
<Button
121120
size="sm"
122121
variant="outline"
@@ -126,19 +125,18 @@ export function GenericInboxItem<
126125
Studio
127126
</Button>
128127
</div>
129-
</div>
130-
131-
132-
<div className={cn("col-span-2", !selectedInbox && "col-start-10")}>
133-
<InboxItemStatuses status={threadData.status} />
134-
</div>
128+
)}
135129

136-
<p
130+
<div
137131
className={cn(
138-
"col-span-1 text-gray-600 font-light text-sm",
139-
!selectedInbox && "col-start-12"
132+
"col-span-2 flex items-center",
133+
!selectedInbox && "col-start-10"
140134
)}
141135
>
136+
<InboxItemStatuses status={threadData.status} />
137+
</div>
138+
139+
<p className="col-span-1 text-right text-sm text-gray-600 font-light pt-2">
142140
{updatedAtDateString}
143141
</p>
144142
</div>

src/components/agent-inbox/components/thread-actions-view.tsx

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ interface ThreadActionsViewProps<
3636
ThreadValues extends Record<string, any> = Record<string, any>,
3737
> {
3838
threadData: ThreadData<ThreadValues>;
39-
interruptedActions: ReturnType<typeof useInterruptedActions>;
4039
isInterrupted: boolean;
4140
threadTitle: string;
4241
showState: boolean;
@@ -106,8 +105,7 @@ export function ThreadActionsView<
106105
ThreadValues extends Record<string, any> = Record<string, any>,
107106
>({
108107
threadData,
109-
interruptedActions,
110-
isInterrupted,
108+
isInterrupted: _propIsInterrupted,
111109
threadTitle,
112110
showDescription,
113111
showState,
@@ -118,9 +116,9 @@ export function ThreadActionsView<
118116
const { updateQueryParams } = useQueryParams();
119117
const [refreshing, setRefreshing] = useState(false);
120118

121-
122119
// Get the selected inbox object
123120
const selectedInbox = agentInboxes.find((i) => i.selected);
121+
const deploymentUrl = selectedInbox?.deploymentUrl;
124122

125123
// Only use interrupted actions for interrupted threads
126124
const isInterrupted =
@@ -129,16 +127,15 @@ export function ThreadActionsView<
129127
threadData.interrupts.length > 0;
130128

131129
// Initialize the hook outside of conditional to satisfy React rules of hooks
132-
// Pass null values when not needed
133-
const interruptedActions = useInterruptedActions<ThreadValues>({
130+
const actions = useInterruptedActions<ThreadValues>({
134131
threadData: isInterrupted
135132
? {
136133
thread: threadData.thread,
137134
status: "interrupted",
138135
interrupts: threadData.interrupts || [],
139136
}
140137
: null,
141-
setThreadData: isInterrupted ? setThreadData : null,
138+
setThreadData: null,
142139
});
143140

144141
const handleOpenInStudio = () => {
@@ -316,8 +313,8 @@ export function ThreadActionsView<
316313
<Button
317314
variant="outline"
318315
className="text-gray-800 border-gray-500 font-normal bg-white"
319-
onClick={interruptedActions?.handleIgnore} // Assuming ignore doesn't need config
320-
disabled={interruptedActions?.loading}
316+
onClick={actions?.handleIgnore} // Assuming ignore doesn't need config
317+
disabled={actions?.loading}
321318
>
322319
Ignore Thread
323320
</Button>
@@ -506,8 +503,8 @@ export function ThreadActionsView<
506503
<Button
507504
variant="outline"
508505
className="text-gray-800 border-gray-500 font-normal bg-white"
509-
onClick={interruptedActions?.handleResolve}
510-
disabled={interruptedActions?.loading}
506+
onClick={actions?.handleResolve}
507+
disabled={actions?.loading}
511508
>
512509
Mark as Resolved
513510
</Button>
@@ -517,8 +514,8 @@ export function ThreadActionsView<
517514
<Button
518515
variant="outline"
519516
size="sm"
520-
onClick={interruptedActions?.handleIgnore}
521-
disabled={interruptedActions?.loading}
517+
onClick={actions?.handleIgnore}
518+
disabled={actions?.loading}
522519
>
523520
Ignore
524521
</Button>
@@ -533,28 +530,20 @@ export function ThreadActionsView<
533530
{/* Actions */}
534531
<InboxItemInput
535532
acceptAllowed={acceptAllowed}
536-
hasEdited={interruptedActions?.hasEdited ?? false}
537-
hasAddedResponse={interruptedActions?.hasAddedResponse ?? false}
533+
hasEdited={actions?.hasEdited ?? false}
534+
hasAddedResponse={actions?.hasAddedResponse ?? false}
538535
interruptValue={firstInterrupt!}
539-
humanResponse={interruptedActions?.humanResponse as any}
540-
initialValues={
541-
interruptedActions?.initialHumanInterruptEditValue.current || {}
542-
}
543-
setHumanResponse={interruptedActions?.setHumanResponse ?? (() => {})}
544-
streaming={interruptedActions?.streaming ?? false}
545-
streamFinished={interruptedActions?.streamFinished ?? false}
546-
currentNode={interruptedActions?.currentNode ?? ""}
547-
supportsMultipleMethods={
548-
interruptedActions?.supportsMultipleMethods ?? false
549-
}
550-
setSelectedSubmitType={
551-
interruptedActions?.setSelectedSubmitType ?? (() => {})
552-
}
553-
setHasAddedResponse={
554-
interruptedActions?.setHasAddedResponse ?? (() => {})
555-
}
556-
setHasEdited={interruptedActions?.setHasEdited ?? (() => {})}
557-
handleSubmit={interruptedActions?.handleSubmit ?? (async () => {})}
536+
humanResponse={actions?.humanResponse as any}
537+
initialValues={actions?.initialHumanInterruptEditValue.current || {}}
538+
setHumanResponse={actions?.setHumanResponse ?? (() => {})}
539+
streaming={actions?.streaming ?? false}
540+
streamFinished={actions?.streamFinished ?? false}
541+
currentNode={actions?.currentNode ?? ""}
542+
supportsMultipleMethods={actions?.supportsMultipleMethods ?? false}
543+
setSelectedSubmitType={actions?.setSelectedSubmitType ?? (() => {})}
544+
setHasAddedResponse={actions?.setHasAddedResponse ?? (() => {})}
545+
setHasEdited={actions?.setHasEdited ?? (() => {})}
546+
handleSubmit={actions?.handleSubmit ?? (async () => {})}
558547
/>
559548
</div>
560549
);

src/components/agent-inbox/hooks/use-inboxes.tsx

Lines changed: 57 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -121,78 +121,75 @@ export function useInboxes() {
121121
return;
122122
}
123123

124-
// Ensure each agent inbox has an ID, and if not, add one
125-
parsedAgentInboxes = parsedAgentInboxes.map((i) => {
126-
return {
127-
...i,
128-
id: i.id || uuidv4(),
129-
};
130-
});
131-
132-
// If there is no agent inbox search param, or the search param is not
133-
// a valid UUID, update search param and local storage
134-
if (!agentInboxSearchParam || !validate(agentInboxSearchParam)) {
135-
const selectedInbox = parsedAgentInboxes.find((i) => i.selected);
136-
if (!selectedInbox) {
137-
parsedAgentInboxes[0].selected = true;
138-
updateQueryParams(
139-
[AGENT_INBOX_PARAM, OFFSET_PARAM, LIMIT_PARAM, INBOX_PARAM],
140-
[parsedAgentInboxes[0].id, "0", "10", "interrupted"]
141-
);
142-
setAgentInboxes(parsedAgentInboxes);
143-
setItem(
144-
AGENT_INBOXES_LOCAL_STORAGE_KEY,
145-
JSON.stringify(parsedAgentInboxes)
146-
);
147-
} else {
148-
updateQueryParams(
149-
[AGENT_INBOX_PARAM, OFFSET_PARAM, LIMIT_PARAM, INBOX_PARAM],
150-
[selectedInbox.id, "0", "10", "interrupted"]
151-
);
152-
setAgentInboxes(parsedAgentInboxes);
153-
setItem(
154-
AGENT_INBOXES_LOCAL_STORAGE_KEY,
155-
JSON.stringify(parsedAgentInboxes)
124+
// Ensure each agent inbox has an ID, and if not, add one
125+
currentInboxes = currentInboxes.map((inbox) => {
126+
return {
127+
...inbox,
128+
id: inbox.id || uuidv4(),
129+
};
130+
});
156131

157132
const agentInboxSearchParam = getSearchParam(AGENT_INBOX_PARAM);
158133
logger.log(
159134
"Agent inbox search param for selection:",
160135
agentInboxSearchParam
161136
);
162137

163-
let finalSelectedInboxId: string | null = null;
164-
138+
// If there is no agent inbox search param, or the search param does not match any inbox
139+
// update search param and local storage
165140
if (!agentInboxSearchParam) {
166-
// No param: Select first or already selected (in memory)
167-
const alreadySelected = currentInboxes.find((inbox) => inbox.selected);
168-
finalSelectedInboxId =
169-
alreadySelected?.id || currentInboxes[0]?.id || null;
170-
logger.log("No search param, selecting inbox:", finalSelectedInboxId);
171-
if (finalSelectedInboxId && !initialLoadComplete.current) {
141+
const selectedInbox = currentInboxes.find((inbox) => inbox.selected);
142+
if (!selectedInbox) {
143+
currentInboxes[0].selected = true;
144+
updateQueryParams(
145+
[AGENT_INBOX_PARAM, OFFSET_PARAM, LIMIT_PARAM, INBOX_PARAM],
146+
[currentInboxes[0].id, "0", "10", "interrupted"]
147+
);
148+
setAgentInboxes(currentInboxes);
149+
setItem(
150+
AGENT_INBOXES_LOCAL_STORAGE_KEY,
151+
JSON.stringify(currentInboxes)
152+
);
153+
} else {
154+
updateQueryParams(
155+
[AGENT_INBOX_PARAM, OFFSET_PARAM, LIMIT_PARAM, INBOX_PARAM],
156+
[selectedInbox.id, "0", "10", "interrupted"]
157+
);
158+
setAgentInboxes(currentInboxes);
159+
setItem(
160+
AGENT_INBOXES_LOCAL_STORAGE_KEY,
161+
JSON.stringify(currentInboxes)
162+
);
163+
}
164+
165+
// Mark initial load as complete
166+
if (!initialLoadComplete.current) {
172167
initialLoadComplete.current = true;
173-
// Update URL only on initial load if needed
174-
updateQueryParams(AGENT_INBOX_PARAM, finalSelectedInboxId);
175168
}
176-
} else {
177-
// Param exists: Find inbox by param ID
178-
const selectedByParam = currentInboxes.find(
179-
(inbox) => inbox.id === agentInboxSearchParam
180169

170+
return;
171+
}
172+
173+
let finalSelectedInboxId: string | null = null;
174+
175+
// Param exists: Find inbox by param ID
176+
const selectedByParam = currentInboxes.find(
177+
(inbox) => inbox.id === agentInboxSearchParam
178+
);
179+
180+
if (selectedByParam) {
181+
finalSelectedInboxId = selectedByParam.id;
182+
logger.log("Found inbox by search param:", finalSelectedInboxId);
183+
} else {
184+
// Param exists but inbox not found: Select first
185+
finalSelectedInboxId = currentInboxes[0]?.id || null;
186+
logger.log(
187+
"Inbox for search param not found, selecting first inbox:",
188+
finalSelectedInboxId
181189
);
182-
if (selectedByParam) {
183-
finalSelectedInboxId = selectedByParam.id;
184-
logger.log("Found inbox by search param:", finalSelectedInboxId);
185-
} else {
186-
// Param exists but inbox not found: Select first
187-
finalSelectedInboxId = currentInboxes[0]?.id || null;
188-
logger.log(
189-
"Inbox for search param not found, selecting first inbox:",
190-
finalSelectedInboxId
191-
);
192-
if (finalSelectedInboxId) {
193-
// Update URL to reflect the actual selection
194-
updateQueryParams(AGENT_INBOX_PARAM, finalSelectedInboxId);
195-
}
190+
if (finalSelectedInboxId) {
191+
// Update URL to reflect the actual selection
192+
updateQueryParams(AGENT_INBOX_PARAM, finalSelectedInboxId);
196193
}
197194
}
198195

@@ -244,19 +241,6 @@ export function useInboxes() {
244241
return;
245242
}
246243

247-
const parsedAgentInboxes = JSON.parse(agentInboxes);
248-
parsedAgentInboxes.push(newInbox);
249-
setAgentInboxes(parsedAgentInboxes);
250-
setItem(
251-
AGENT_INBOXES_LOCAL_STORAGE_KEY,
252-
JSON.stringify(parsedAgentInboxes)
253-
);
254-
// Set agent inbox, offset, and limit
255-
updateQueryParams(
256-
[AGENT_INBOX_PARAM, OFFSET_PARAM, LIMIT_PARAM, INBOX_PARAM],
257-
[newInbox.id, "0", "10", "interrupted"]
258-
);
259-
260244
try {
261245
const parsedAgentInboxes: AgentInbox[] = JSON.parse(agentInboxesStr);
262246

@@ -402,7 +386,6 @@ export function useInboxes() {
402386

403387
// Update URL parameters
404388
if (!replaceAll) {
405-
406389
// Set agent inbox, offset, limit, and inbox param
407390
updateQueryParams(
408391
[AGENT_INBOX_PARAM, OFFSET_PARAM, LIMIT_PARAM, INBOX_PARAM],
@@ -418,7 +401,6 @@ export function useInboxes() {
418401
});
419402
const newUrl = url.pathname + "?" + newParams.toString();
420403
window.location.href = newUrl;
421-
422404
}
423405
},
424406
[getItem, setItem, updateQueryParams, router]

0 commit comments

Comments
 (0)