context peek formatting and fix last index logic for tool truncation logic

This commit is contained in:
Dallin Romney 2025-06-27 20:23:03 -07:00
parent 62381e8790
commit c28f70a9f0
5 changed files with 52 additions and 42 deletions

View file

@ -1,6 +1,6 @@
export function findLastIndex(
arr: any[],
criterion: (item: any) => boolean,
export function findLastIndex<T = any>(
arr: T[],
criterion: (item: T) => boolean,
): number {
let lastIndex = -1;

View file

@ -117,40 +117,36 @@ export function ContextItemsPeekItem({
return (
<div
onClick={openContextItem}
className="group mr-2 flex cursor-pointer items-center overflow-hidden text-ellipsis whitespace-nowrap rounded px-1.5 py-1 text-xs hover:bg-white/10"
className="mr-2 flex cursor-pointer flex-row items-center gap-1.5 rounded px-1.5 py-1 text-xs hover:bg-white/10"
data-testid="context-items-peek-item"
>
<div className="flex w-full items-center">
{getContextItemIcon()}
<div className="flex min-w-0 flex-1 gap-2 text-xs">
<div
className={`max-w-[50%] flex-shrink-0 truncate ${isUrl ? "hover:underline" : ""}`}
>
{contextItem.name}
</div>
<div
className={`min-w-0 flex-1 overflow-hidden truncate whitespace-nowrap text-xs text-gray-400 ${isUrl ? "hover:underline" : ""}`}
onClick={
isUrl
? (e) => {
if (contextItem.uri?.value) {
e.stopPropagation();
ideMessenger.post("openUrl", contextItem.uri.value);
} else {
console.error("Couldn't open url", contextItem.uri);
}
}
: undefined
}
>
{contextItem.uri?.type === "file"
? getUriPathBasename(contextItem.description)
: contextItem.description}
</div>
</div>
{getContextItemIcon()}
<span className={`max-s-[100px] line-clamp-1 flex-shrink-0`}>
{contextItem.name}
</span>
<div
className={`group flex flex-row items-center gap-1.5 pr-1.5 text-xs text-gray-400 ${isUrl ? "hover:underline" : ""}`}
onClick={
isUrl
? (e) => {
if (contextItem.uri?.value) {
e.stopPropagation();
ideMessenger.post("openUrl", contextItem.uri.value);
} else {
console.error("Couldn't open url", contextItem.uri);
}
}
: undefined
}
>
<span className={`line-clamp-1 flex-1 break-all`}>
{contextItem.uri?.type === "file"
? getUriPathBasename(contextItem.description)
: contextItem.description}
adsfasdfasdjk; asdfl;kjasdl;fkjasdlk;fja asdfklj;asdl;fkjasdf
</span>
{isUrl && (
<ArrowTopRightOnSquareIcon className="mx-2 h-4 w-4 flex-shrink-0 text-gray-400 opacity-0 group-hover:opacity-100" />
<ArrowTopRightOnSquareIcon className="h-3 w-3 flex-shrink-0 text-gray-400 opacity-80 group-hover:opacity-100" />
)}
</div>
</div>

View file

@ -6,7 +6,7 @@ import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
import { toolCallStateToContextItems } from "./toolCallStateToContextItem";
import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
import { TruncateHistoryIcon } from "./TruncateHistoryIcon";
import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
interface SimpleToolCallUIProps {
toolCallState: ToolCallState;
@ -61,7 +61,9 @@ export function SimpleToolCallUI({
<ToolCallStatusMessage tool={tool} toolCallState={toolCallState} />
</div>
<div className="flex flex-row items-center gap-1.5">
<TruncateHistoryIcon historyIndex={historyIndex} />
{!!toolCallState.output?.length && (
<ToolTruncateHistoryIcon historyIndex={historyIndex} />
)}
{args.length > 0 ? (
<ArgsToggleIcon
isShowing={showingArgs}

View file

@ -2,7 +2,7 @@ import { Tool, ToolCallState } from "core";
import { useMemo, useState } from "react";
import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs";
import { ToolCallStatusMessage } from "./ToolCallStatusMessage";
import { TruncateHistoryIcon } from "./TruncateHistoryIcon";
import { ToolTruncateHistoryIcon } from "./ToolTruncateHistoryIcon";
interface ToolCallDisplayProps {
children: React.ReactNode;
@ -43,7 +43,9 @@ export function ToolCallDisplay({
/>
</div>
<div className="gap 1.5 flex flex-row items-center">
<TruncateHistoryIcon historyIndex={historyIndex} />
{!!toolCallState.output && (
<ToolTruncateHistoryIcon historyIndex={historyIndex} />
)}
{!!args.length ? (
<ArgsToggleIcon
isShowing={argsExpanded}

View file

@ -1,17 +1,25 @@
import { ArrowUpTrayIcon } from "@heroicons/react/24/outline";
import { BarsArrowUpIcon } from "@heroicons/react/24/outline";
import { chatMessageIsEmpty } from "core/llm/messages";
import { findLastIndex } from "core/util/findLast";
import { useMemo } from "react";
import { useMainEditor } from "../../../components/mainInput/TipTapEditor";
import { ToolbarButtonWithTooltip } from "../../../components/StyledMarkdownPreview/StepContainerPreToolbar/ToolbarButtonWithTooltip";
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
import { truncateHistoryToMessage } from "../../../redux/slices/sessionSlice";
export function TruncateHistoryIcon({
export function ToolTruncateHistoryIcon({
historyIndex,
}: {
historyIndex: number;
}) {
const isStreaming = useAppSelector((state) => state.session.isStreaming);
const history = useAppSelector((state) => state.session.history);
const lastMessageIndex = useMemo(() => {
return findLastIndex(history, (item) => !chatMessageIsEmpty(item.message));
}, [history]);
const dispatch = useAppDispatch();
if (isStreaming || historyIndex === history.length - 1) {
const { mainEditor } = useMainEditor();
if (isStreaming || lastMessageIndex) {
return null;
}
return (
@ -23,9 +31,11 @@ export function TruncateHistoryIcon({
index: historyIndex,
}),
);
mainEditor?.commands.focus();
}}
>
<ArrowUpTrayIcon className="h-2.5 w-2.5" />
{historyIndex}/{history.length - 1}
<BarsArrowUpIcon className="h-2.5 w-2.5 flex-shrink-0 opacity-60" />
</ToolbarButtonWithTooltip>
);
}