WIP: All changes including session and toolcall improvements

This commit is contained in:
yiliang114
2025-12-06 16:53:40 +08:00
parent 541d0b22e5
commit 57a684ad97
18 changed files with 622 additions and 230 deletions

View File

@@ -21,6 +21,11 @@ export const useSessionManagement = (vscode: VSCodeAPI) => {
const [showSessionSelector, setShowSessionSelector] = useState(false);
const [sessionSearchQuery, setSessionSearchQuery] = useState('');
const [savedSessionTags, setSavedSessionTags] = useState<string[]>([]);
const [nextCursor, setNextCursor] = useState<number | undefined>(undefined);
const [hasMore, setHasMore] = useState<boolean>(true);
const [isLoading, setIsLoading] = useState<boolean>(false);
const PAGE_SIZE = 20;
/**
* Filter session list
@@ -44,10 +49,24 @@ export const useSessionManagement = (vscode: VSCodeAPI) => {
* Load session list
*/
const handleLoadQwenSessions = useCallback(() => {
vscode.postMessage({ type: 'getQwenSessions', data: {} });
// Reset pagination state and load first page
setQwenSessions([]);
setNextCursor(undefined);
setHasMore(true);
setIsLoading(true);
vscode.postMessage({ type: 'getQwenSessions', data: { size: PAGE_SIZE } });
setShowSessionSelector(true);
}, [vscode]);
const handleLoadMoreSessions = useCallback(() => {
if (!hasMore || isLoading || nextCursor === undefined) return;
setIsLoading(true);
vscode.postMessage({
type: 'getQwenSessions',
data: { cursor: nextCursor, size: PAGE_SIZE },
});
}, [hasMore, isLoading, nextCursor, vscode]);
/**
* Create new session
*/
@@ -117,6 +136,9 @@ export const useSessionManagement = (vscode: VSCodeAPI) => {
sessionSearchQuery,
filteredSessions,
savedSessionTags,
nextCursor,
hasMore,
isLoading,
// State setters
setQwenSessions,
@@ -125,6 +147,9 @@ export const useSessionManagement = (vscode: VSCodeAPI) => {
setShowSessionSelector,
setSessionSearchQuery,
setSavedSessionTags,
setNextCursor,
setHasMore,
setIsLoading,
// Operations
handleLoadQwenSessions,
@@ -132,5 +157,6 @@ export const useSessionManagement = (vscode: VSCodeAPI) => {
handleSwitchSession,
handleSaveSession,
handleSaveSessionResponse,
handleLoadMoreSessions,
};
};

View File

@@ -18,10 +18,17 @@ interface UseWebViewMessagesProps {
// Session management
sessionManagement: {
currentSessionId: string | null;
setQwenSessions: (sessions: Array<Record<string, unknown>>) => void;
setQwenSessions: (
sessions:
| Array<Record<string, unknown>>
| ((prev: Array<Record<string, unknown>>) => Array<Record<string, unknown>>),
) => void;
setCurrentSessionId: (id: string | null) => void;
setCurrentSessionTitle: (title: string) => void;
setShowSessionSelector: (show: boolean) => void;
setNextCursor: (cursor: number | undefined) => void;
setHasMore: (hasMore: boolean) => void;
setIsLoading: (loading: boolean) => void;
handleSaveSessionResponse: (response: {
success: boolean;
message?: string;
@@ -487,8 +494,17 @@ export const useWebViewMessages = ({
}
case 'qwenSessionList': {
const sessions = message.data.sessions || [];
handlers.sessionManagement.setQwenSessions(sessions);
const sessions = (message.data.sessions as any[]) || [];
const append = Boolean(message.data.append);
const nextCursor = message.data.nextCursor as number | undefined;
const hasMore = Boolean(message.data.hasMore);
handlers.sessionManagement.setQwenSessions((prev: any[]) =>
append ? [...prev, ...sessions] : sessions,
);
handlers.sessionManagement.setNextCursor(nextCursor);
handlers.sessionManagement.setHasMore(hasMore);
handlers.sessionManagement.setIsLoading(false);
if (
handlers.sessionManagement.currentSessionId &&
sessions.length > 0