truncate history icon on non-last tool messages
This commit is contained in:
parent
d5afd9ae4b
commit
ec7c497faf
5 changed files with 77 additions and 18 deletions
|
|
@ -1,23 +1,28 @@
|
|||
import { ArrowPathIcon, ChevronRightIcon } from "@heroicons/react/24/outline";
|
||||
import { ChevronRightIcon } from "@heroicons/react/24/outline";
|
||||
import { Tool, ToolCallState } from "core";
|
||||
import { ComponentType, useMemo, useState } from "react";
|
||||
import { ContextItemsPeekItem } from "../../../components/mainInput/belowMainInput/ContextItemsPeek";
|
||||
import { ToolbarButtonWithTooltip } from "../../../components/StyledMarkdownPreview/StepContainerPreToolbar/ToolbarButtonWithTooltip";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
|
||||
import { toolCallStateToContextItems } from "./toolCallStateToContextItem";
|
||||
import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
|
||||
import { TruncateHistoryIcon } from "./TruncateHistoryIcon";
|
||||
|
||||
interface SimpleToolCallUIProps {
|
||||
toolCallState: ToolCallState;
|
||||
tool: Tool | undefined;
|
||||
icon?: ComponentType<React.SVGProps<SVGSVGElement>>;
|
||||
historyIndex: number;
|
||||
}
|
||||
|
||||
export function SimpleToolCallUI({
|
||||
icon: Icon,
|
||||
toolCallState,
|
||||
tool,
|
||||
historyIndex,
|
||||
}: SimpleToolCallUIProps) {
|
||||
const history = useAppSelector((state) => state.session.history);
|
||||
const dispatch = useAppDispatch();
|
||||
const shownContextItems = useMemo(() => {
|
||||
const contextItems = toolCallStateToContextItems(toolCallState);
|
||||
return contextItems.filter((item) => !item.hidden);
|
||||
|
|
@ -55,15 +60,8 @@ export function SimpleToolCallUI({
|
|||
</div>
|
||||
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
|
||||
</div>
|
||||
<div>
|
||||
<ToolbarButtonWithTooltip
|
||||
tooltipContent="Resubmit"
|
||||
onClick={() => {
|
||||
console.log("Resubmit clicked");
|
||||
}}
|
||||
>
|
||||
<ArrowPathIcon className="h-4 w-4" />
|
||||
</ToolbarButtonWithTooltip>
|
||||
<div className="flex flex-row items-center gap-1.5">
|
||||
<TruncateHistoryIcon historyIndex={historyIndex} />
|
||||
{args.length > 0 ? (
|
||||
<ArgsToggleIcon
|
||||
isShowing={showingArgs}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ import { Tool, ToolCallState } from "core";
|
|||
import { useMemo, useState } from "react";
|
||||
import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
|
||||
import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
|
||||
import { TruncateHistoryIcon } from "./TruncateHistoryIcon";
|
||||
|
||||
interface ToolCallDisplayProps {
|
||||
children: React.ReactNode;
|
||||
icon: React.ReactNode;
|
||||
tool: Tool | undefined;
|
||||
toolCallState: ToolCallState;
|
||||
historyIndex: number;
|
||||
}
|
||||
|
||||
export function ToolCallDisplay({
|
||||
|
|
@ -15,6 +17,7 @@ export function ToolCallDisplay({
|
|||
toolCallState,
|
||||
children,
|
||||
icon,
|
||||
historyIndex,
|
||||
}: ToolCallDisplayProps) {
|
||||
const [argsExpanded, setArgsExpanded] = useState(false);
|
||||
|
||||
|
|
@ -39,13 +42,16 @@ export function ToolCallDisplay({
|
|||
toolCallState={toolCallState}
|
||||
/>
|
||||
</div>
|
||||
{!!args.length ? (
|
||||
<ArgsToggleIcon
|
||||
isShowing={argsExpanded}
|
||||
setIsShowing={setArgsExpanded}
|
||||
toolCallId={toolCallState.toolCallId}
|
||||
/>
|
||||
) : null}
|
||||
<div className="gap 1.5 flex flex-row items-center">
|
||||
<TruncateHistoryIcon historyIndex={historyIndex} />
|
||||
{!!args.length ? (
|
||||
<ArgsToggleIcon
|
||||
isShowing={argsExpanded}
|
||||
setIsShowing={setArgsExpanded}
|
||||
toolCallId={toolCallState.toolCallId}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{argsExpanded && !!args.length && (
|
||||
<ArgsItems args={args} isShowing={argsExpanded} />
|
||||
|
|
|
|||
31
gui/src/pages/gui/ToolCallDiv/TruncateHistoryIcon.tsx
Normal file
31
gui/src/pages/gui/ToolCallDiv/TruncateHistoryIcon.tsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { ArrowUpTrayIcon } from "@heroicons/react/24/outline";
|
||||
import { ToolbarButtonWithTooltip } from "../../../components/StyledMarkdownPreview/StepContainerPreToolbar/ToolbarButtonWithTooltip";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import { truncateHistoryToMessage } from "../../../redux/slices/sessionSlice";
|
||||
|
||||
export function TruncateHistoryIcon({
|
||||
historyIndex,
|
||||
}: {
|
||||
historyIndex: number;
|
||||
}) {
|
||||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
const history = useAppSelector((state) => state.session.history);
|
||||
const dispatch = useAppDispatch();
|
||||
if (isStreaming || historyIndex === history.length - 1) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<ToolbarButtonWithTooltip
|
||||
tooltipContent="Truncate chat to this message"
|
||||
onClick={() => {
|
||||
dispatch(
|
||||
truncateHistoryToMessage({
|
||||
index: historyIndex,
|
||||
}),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<ArrowUpTrayIcon className="h-2.5 w-2.5" />
|
||||
</ToolbarButtonWithTooltip>
|
||||
);
|
||||
}
|
||||
|
|
@ -80,6 +80,7 @@ export function ToolCallDiv(props: ToolCallDivProps) {
|
|||
icon={
|
||||
props.toolCallState.status === "generated" ? ArrowRightIcon : icon
|
||||
}
|
||||
historyIndex={props.historyIndex}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -89,6 +90,7 @@ export function ToolCallDiv(props: ToolCallDivProps) {
|
|||
icon={getStatusIcon(props.toolCallState.status)}
|
||||
tool={tool}
|
||||
toolCallState={props.toolCallState}
|
||||
historyIndex={props.historyIndex}
|
||||
>
|
||||
<FunctionSpecificToolCallDiv
|
||||
toolCall={props.toolCall}
|
||||
|
|
|
|||
|
|
@ -146,6 +146,27 @@ export const sessionSlice = createSlice({
|
|||
state.history[index].contextItems = contextItems;
|
||||
}
|
||||
},
|
||||
truncateHistoryToMessage: (
|
||||
state,
|
||||
{
|
||||
payload,
|
||||
}: PayloadAction<{
|
||||
index: number;
|
||||
}>,
|
||||
) => {
|
||||
const { index } = payload;
|
||||
|
||||
if (state.history.length && index < state.history.length) {
|
||||
state.history = state.history.slice(0, index + 1).concat({
|
||||
message: {
|
||||
id: uuidv4(),
|
||||
role: "assistant",
|
||||
content: "", // IMPORTANT - this is subsequently updated by response streaming
|
||||
},
|
||||
contextItems: [],
|
||||
});
|
||||
}
|
||||
},
|
||||
submitEditorAndInitAtIndex: (
|
||||
state,
|
||||
{
|
||||
|
|
@ -676,6 +697,7 @@ export const {
|
|||
addPromptCompletionPair,
|
||||
setActive,
|
||||
submitEditorAndInitAtIndex,
|
||||
truncateHistoryToMessage,
|
||||
updateHistoryItemAtIndex,
|
||||
clearLastEmptyResponse,
|
||||
setMainEditorContentTrigger,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue