Skip to content

Commit

Permalink
fix: tool calls show in revisiting thread (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivyjeong13 authored Dec 27, 2024
1 parent 5a5660f commit 98b067e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
34 changes: 30 additions & 4 deletions ui/admin/app/components/chat/ChatContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,8 @@ function useMessageSource(threadId?: Nullish<string>) {
return copy;
}

// skip tool call output events
if (toolCall && !toolCall.output) {
copy.push(toolCallMessage(toolCall));
return copy;
if (toolCall) {
return handleToolCallEvent(copy, event);
}

if (prompt) {
Expand Down Expand Up @@ -232,3 +230,31 @@ function useMessageSource(threadId?: Nullish<string>) {

return { messages, isRunning };
}

const findIndexLastPendingToolCall = (messages: Message[]) => {
for (let i = messages.length - 1; i >= 0; i--) {
const message = messages[i];
if (message.tools && !message.tools[0].output) {
return i;
}
}
return null;
};

const handleToolCallEvent = (messages: Message[], event: ChatEvent) => {
if (!event.toolCall) return messages;

const { toolCall } = event;
if (toolCall.output) {
const index = findIndexLastPendingToolCall(messages);
if (index !== null) {
// update the found pending toolcall message (without output)
messages[index].tools = [toolCall];
return messages;
}
}

// otherwise add a new toolcall message
messages.push(toolCallMessage(toolCall));
return messages;
};
1 change: 1 addition & 0 deletions ui/admin/app/routes/_auth.workflows._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export default function Workflows() {
cell: (info) => (
<div className="flex gap-2 items-center">
<Link
onClick={(event) => event.stopPropagation()}
to={$path("/threads", {
workflowId: info.row.original.id,
from: "workflows",
Expand Down

0 comments on commit 98b067e

Please sign in to comment.