Files
tutti/packages/agent/gui/agent-gui/agentGuiNode/view/useAgentGUIComposerInputHistoryProps.ts
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

72 lines
2.5 KiB
TypeScript

import { useMemo, type RefObject } from "react";
import type { AgentConversationVM } from "../../../shared/agentConversation/contracts/agentConversationVM";
import type { AgentComposerProps } from "../AgentComposer";
import type { AgentGUINodeViewProps } from "../AgentGUINodeView";
import type { AgentGUINodeViewModel } from "../model/agentGuiNodeTypes";
import { projectAgentComposerInputHistory } from "../model/agentComposerInputHistory";
import { useStableEventCallback } from "./agentGUIViewUtils";
type InputHistoryProps = Pick<
AgentComposerProps,
| "inputHistory"
| "inputHistoryHasOlderPage"
| "inputHistoryIsLoadingOlderPage"
| "onRequestOlderInputHistoryPage"
>;
const EMPTY_INPUT_HISTORY: NonNullable<InputHistoryProps["inputHistory"]> = [];
export function useAgentGUIComposerInputHistoryProps(input: {
actions: AgentGUINodeViewProps["actions"];
conversation: AgentConversationVM | null;
enabled: boolean;
pendingPrependScrollAnchorRef: RefObject<{
conversationId: string;
scrollHeight: number;
scrollTop: number;
} | null>;
timelineRef: RefObject<HTMLDivElement | null>;
viewModel: AgentGUINodeViewModel;
}): InputHistoryProps {
const onRequestOlderInputHistoryPage = useStableEventCallback(() => {
const activeConversationId = input.viewModel.rail.activeConversationId;
if (
!activeConversationId ||
!input.viewModel.detail.hasOlderMessages ||
input.viewModel.detail.isLoadingOlderMessages
) {
return;
}
const timeline = input.timelineRef.current;
if (timeline) {
input.pendingPrependScrollAnchorRef.current = {
conversationId: activeConversationId,
scrollHeight: timeline.scrollHeight,
scrollTop: timeline.scrollTop
};
}
input.actions.loadOlderConversationMessages();
});
const inputHistory = input.enabled
? projectAgentComposerInputHistory(input.conversation)
: EMPTY_INPUT_HISTORY;
return useMemo(
() => ({
inputHistory,
inputHistoryHasOlderPage:
input.enabled && input.viewModel.detail.hasOlderMessages,
inputHistoryIsLoadingOlderPage:
input.enabled && input.viewModel.detail.isLoadingOlderMessages,
onRequestOlderInputHistoryPage: input.enabled
? onRequestOlderInputHistoryPage
: undefined
}),
[
input.viewModel.detail.hasOlderMessages,
input.viewModel.detail.isLoadingOlderMessages,
input.enabled,
inputHistory,
onRequestOlderInputHistoryPage
]
);
}