Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.
TypeScript agentai-agentai-agentsai-assistantandroidautomationchatgptcoding-agentcomputer-usedesktop-appelectronllmlocal-firstmcpmulti-agentollamaopenaiprivacyself-hostedtypescript
fix(chat): dismiss the context compaction success notice after five seconds
leen.zhoua7ea581b426d
diff --git a/apps/desktop/src/renderer/features/chat/screen/chat-composer-view.tsx b/apps/desktop/src/renderer/features/chat/screen/chat-composer-view.tsxindex a3d0618..812919c 100644--- a/apps/desktop/src/renderer/features/chat/screen/chat-composer-view.tsx+++ b/apps/desktop/src/renderer/features/chat/screen/chat-composer-view.tsx@@ -25,9 +25,9 @@ import type { ChatScreenModel } from "./chat-screen-model.ts";// composer's + menu (「整理上下文」) for someone who wants to shorten a long topic.const compactionFailures = new Set(["compaction_failed", "compaction_timeout", "context_overflow"]);-function needsCompaction(messages: ChatScreenModel["state"]["messages"]): boolean {+function compactionFailure(messages: ChatScreenModel["state"]["messages"]): string | undefined {const last = messages.findLast((message) => message.role === "assistant");- return Boolean(last?.errorCode && compactionFailures.has(last.errorCode));+ return last?.errorCode && compactionFailures.has(last.errorCode) ? last.id : undefined;}export function renderChatComposer(screen: ChatScreenModel) {@@ -70,7 +70,11 @@ export function renderChatComposer(screen: ChatScreenModel) {requestKey,compactRequested,requestCompact,+ compactDismissed,+ dismissCompaction,} = screen;+ const failedCompaction = compactionFailure(state.messages);+ const needsCompaction = !!failedCompaction && failedCompaction !== compactDismissed;const canOrganize =state.bot?.category !== "image" &&!!state.bot &&@@ -93,7 +97,7 @@ export function renderChatComposer(screen: ChatScreenModel) {canOrganize &&state.bot &&state.conversationId &&- !needsCompaction(state.messages) &&+ !needsCompaction &&compactRequested !== state.conversationId && (<ContextHintNoticekey={`${state.bot.id}:${state.conversationId}`}@@ -108,13 +112,19 @@ export function renderChatComposer(screen: ChatScreenModel) {{canOrganize &&state.bot &&state.conversationId &&- (needsCompaction(state.messages) || compactRequested === state.conversationId) && (+ (needsCompaction || compactRequested === state.conversationId) && (<CompactionActionskey={`${state.bot.id}:${state.conversationId}`}peer={peer}botId={state.bot.id}conversationId={state.conversationId}disabled={busy || sendingBlocked}+ dismiss={() => {+ requestCompact((requested) =>+ requested === state.conversationId ? undefined : requested,+ );+ dismissCompaction(failedCompaction);+ }}/>)}{/* An external agent has its own model; Pi Bot's model settings do not apply. */}diff --git a/apps/desktop/src/renderer/features/chat/screen/chat-screen-model.ts b/apps/desktop/src/renderer/features/chat/screen/chat-screen-model.tsindex 53d2ea6..a2f5a93 100644--- a/apps/desktop/src/renderer/features/chat/screen/chat-screen-model.ts+++ b/apps/desktop/src/renderer/features/chat/screen/chat-screen-model.ts@@ -21,6 +21,7 @@ export function useChatScreenModel(props: ConnectedChatProps) {const memoryNotices = useMemoryNotices(props.peer, state.state.bot?.id, state.actualTopicId);// Keyed by conversation so a request made in one topic never opens the row in another.const [compactRequested, requestCompact] = useState<string>();+ const [compactDismissed, dismissCompaction] = useState<string>();return {...props,...state,@@ -29,6 +30,8 @@ export function useChatScreenModel(props: ConnectedChatProps) {memoryNotices,compactRequested,requestCompact,+ compactDismissed,+ dismissCompaction,};}export type ChatScreenModel = ReturnType<typeof useChatScreenModel>;diff --git a/apps/desktop/src/renderer/features/chat/status/CompactionActions.tsx b/apps/desktop/src/renderer/features/chat/status/CompactionActions.tsxindex dc77a77..32728c5 100644--- a/apps/desktop/src/renderer/features/chat/status/CompactionActions.tsx+++ b/apps/desktop/src/renderer/features/chat/status/CompactionActions.tsx@@ -10,14 +10,17 @@ export function CompactionActions({botId,conversationId,disabled,+ dismiss,}: {peer: ChatPeer;botId: string;conversationId: string;disabled: boolean;+ dismiss(): void;}) {const t = useT();const active = useRef<{ requestId: string; signal: AbortController } | undefined>(undefined);+ const successTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);const [pending, setPending] = useState(false);const [result, setResult] = useState<"done" | "mechanical" | "failed" | "nothing">();const cancel = useCallback(() => {@@ -36,8 +39,17 @@ export function CompactionActions({},[cancel],);+ useEffect(+ () => () => {+ clearTimeout(successTimer.current);+ successTimer.current = undefined;+ },+ [],+ );const compact = async (fork: boolean) => {if (active.current || disabled) return;+ clearTimeout(successTimer.current);+ successTimer.current = undefined;const current = { requestId: crypto.randomUUID(), signal: new AbortController() };active.current = current;setPending(true);@@ -48,7 +60,19 @@ export function CompactionActions({{ botId, conversationId, requestId: current.requestId, fork },{ timeoutMs: 1_210_000, signal: current.signal.signal },);- if (!current.signal.signal.aborted) setResult(result.mechanical ? "mechanical" : "done");+ if (!current.signal.signal.aborted) {+ setResult(result.mechanical ? "mechanical" : "done");+ if (!result.mechanical) {+ const timer = setTimeout(() => {+ // An earlier completion must not close a newer compaction or a different topic.+ if (successTimer.current !== timer || current.signal.signal.aborted) return;+ successTimer.current = undefined;+ setResult(undefined);+ dismiss();+ }, 5_000);+ successTimer.current = timer;+ }+ }} catch (error) {// A topic whose replies never created a model session (welcome text, a failed first turn)// has nothing to summarize; that is not a failure worth retrying.