-
-
Notifications
You must be signed in to change notification settings - Fork 177
feat(client, server): infinite scroll for tools #1159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+120
−39
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7a5f01
feat(client, server): infinite scroll for tools
and1can 542ea82
feat(client, server): infinite scroll for tools
and1can db390be
prettier fix
and1can c1d74b6
clean up code
and1can 13b065d
update call for listTools
and1can 78ba3b3
update useEffect dependencies
and1can File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useEffect, useMemo, useState } from "react"; | ||
| import { useEffect, useMemo, useRef, useState } from "react"; | ||
| import type { | ||
| CallToolResult, | ||
| ElicitRequest, | ||
|
|
@@ -116,7 +116,7 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| useState<"not_applicable" | "valid" | "invalid_json" | "schema_mismatch">( | ||
| "not_applicable", | ||
| ); | ||
| const [loading, setLoading] = useState(false); | ||
| const [loadingExecuteTool, setLoadingExecuteTool] = useState(false); | ||
| const [fetchingTools, setFetchingTools] = useState(false); | ||
| const [error, setError] = useState<string>(""); | ||
| const [activeElicitation, setActiveElicitation] = | ||
|
|
@@ -147,6 +147,9 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| useState<TaskCapabilities | null>(null); | ||
| // TTL for task execution (milliseconds, 0 = no expiration) | ||
| const [taskTtl, setTaskTtl] = useState<number>(0); | ||
| // Infinite scroll state | ||
| const sentinelRef = useRef<HTMLDivElement | null>(null); | ||
| const [cursor, setCursor] = useState<string | undefined>(undefined); | ||
| const serverKey = useMemo(() => { | ||
| if (!serverConfig) return "none"; | ||
| try { | ||
|
|
@@ -267,7 +270,6 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
|
|
||
| setFetchingTools(true); | ||
| setError(""); | ||
| setTools({}); | ||
| setSelectedTool(""); | ||
| setFormFields([]); | ||
| setResult(null); | ||
|
|
@@ -277,12 +279,14 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| setUnstructuredValidationResult("not_applicable"); | ||
|
|
||
| try { | ||
| const data = await listTools(serverName); | ||
| // Call to get all of the tools for server | ||
| const data = await listTools(serverName, undefined, cursor); | ||
| const toolArray = data.tools ?? []; | ||
| const dictionary = Object.fromEntries( | ||
| toolArray.map((tool: Tool) => [tool.name, tool]), | ||
| ); | ||
| setTools(dictionary); | ||
| setTools((prev) => ({ ...prev, ...dictionary })); | ||
| setCursor(data.nextCursor); | ||
| logger.info("Tools fetched", { | ||
| serverId: serverName, | ||
| toolCount: toolArray.length, | ||
|
|
@@ -427,7 +431,7 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| return; | ||
| } | ||
|
|
||
| setLoading(true); | ||
| setLoadingExecuteTool(true); | ||
| setError(""); | ||
| setResult(null); | ||
| setStructuredResult(null); | ||
|
|
@@ -473,15 +477,20 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| }); | ||
| setError(message); | ||
| } finally { | ||
| setLoading(false); | ||
| setLoadingExecuteTool(false); | ||
| } | ||
| }; | ||
|
|
||
| // Handle Enter key to execute tool globally | ||
| useEffect(() => { | ||
| const handleKeyDown = (e: KeyboardEvent) => { | ||
| // Check if Enter is pressed (not Shift+Enter) | ||
| if (e.key === "Enter" && !e.shiftKey && selectedTool && !loading) { | ||
| if ( | ||
| e.key === "Enter" && | ||
| !e.shiftKey && | ||
| selectedTool && | ||
| !loadingExecuteTool | ||
| ) { | ||
| // Don't trigger if user is typing in an input, textarea, or contenteditable | ||
| const target = e.target as HTMLElement; | ||
| const tagName = target.tagName; | ||
|
|
@@ -498,7 +507,7 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
|
|
||
| window.addEventListener("keydown", handleKeyDown); | ||
| return () => window.removeEventListener("keydown", handleKeyDown); | ||
| }, [selectedTool, loading]); | ||
| }, [selectedTool, loadingExecuteTool]); | ||
|
|
||
| const handleElicitationResponse = async ( | ||
| action: "accept" | "decline" | "cancel", | ||
|
|
@@ -576,6 +585,29 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| }) | ||
| : toolNames; | ||
|
|
||
| // IntersectionObserver for infinite scroll | ||
| useEffect(() => { | ||
| if (!sentinelRef.current) return; | ||
| if (activeTab !== "tools") return; // Only observe when tools tab is active | ||
|
|
||
| const element = sentinelRef.current; | ||
| const observer = new IntersectionObserver((entries) => { | ||
| const entry = entries[0]; | ||
| if (!entry.isIntersecting) return; | ||
| if (!cursor || fetchingTools) return; | ||
|
|
||
| // Load more tools | ||
| fetchTools(); | ||
| }); | ||
|
|
||
| observer.observe(element); | ||
|
|
||
| return () => { | ||
| observer.unobserve(element); | ||
| observer.disconnect(); | ||
| }; | ||
| }, [filteredToolNames.length, activeTab]); | ||
|
|
||
| const filteredSavedRequests = searchQuery.trim() | ||
| ? savedRequests.filter((tool) => { | ||
| const haystack = | ||
|
|
@@ -588,11 +620,9 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| ? { | ||
| requestId: activeElicitation.requestId, | ||
| message: activeElicitation.request.message, | ||
| schema: ( | ||
| activeElicitation.request as unknown as { | ||
| requestedSchema?: Record<string, unknown>; | ||
| } | ||
| ).requestedSchema as Record<string, unknown> | undefined, | ||
| schema: (activeElicitation.request as any).requestedSchema as | ||
| | Record<string, unknown> | ||
| | undefined, | ||
|
Comment on lines
+623
to
+625
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard 🔧 Suggested guardconst requestedSchema = (activeElicitation.request as any).requestedSchema;
const safeSchema =
requestedSchema &&
typeof requestedSchema === "object" &&
!Array.isArray(requestedSchema)
? (requestedSchema as Record<string, unknown>)
: undefined;🤖 Prompt for AI Agents |
||
| timestamp: activeElicitation.timestamp, | ||
| } | ||
| : null; | ||
|
|
@@ -630,6 +660,10 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| onRenameRequest={handleRenameRequest} | ||
| onDuplicateRequest={handleDuplicateRequest} | ||
| onDeleteRequest={handleDeleteRequest} | ||
| displayedToolCount={toolNames.length} | ||
| sentinelRef={sentinelRef} | ||
| loadingMore={fetchingTools} | ||
| cursor={cursor ?? ""} | ||
| /> | ||
| <ResizableHandle withHandle /> | ||
| {selectedTool ? ( | ||
|
|
@@ -638,7 +672,7 @@ export function ToolsTab({ serverConfig, serverName }: ToolsTabProps) { | |
| toolDescription={tools[selectedTool]?.description} | ||
| formFields={formFields} | ||
| onToggleField={updateFieldIsSet} | ||
| loading={loading} | ||
| loading={loadingExecuteTool} | ||
| waitingOnElicitation={!!activeElicitation} | ||
| onExecute={executeTool} | ||
| onSave={handleSaveCurrent} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.