Skip to content

Commit 5720bfd

Browse files
authored
Merge pull request #117 from huggingface/claude/fix-dynamic-space-invoke-streaming-011CV2CCtztFce9Bxajivb3w
Use SSE for Invoke, JSON for view_parameters
2 parents adc406d + 66fc3a3 commit 5720bfd

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

packages/app/src/server/transport/base-transport.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,25 @@ export abstract class BaseTransport {
232232
* @returns true if this is a tools/call for a Gradio tool, false otherwise
233233
*/
234234
protected isGradioToolCall(requestBody: unknown): boolean {
235-
const body = requestBody as { method?: string; params?: { name?: string } } | undefined;
235+
const body = requestBody as { method?: string; params?: { name?: string; arguments?: unknown } } | undefined;
236236
const methodName = body?.method || 'unknown';
237237

238238
// Check if this is a tools/call with a valid tool name
239239
if (methodName === 'tools/call' && body?.params && typeof body.params === 'object' && 'name' in body.params) {
240240
const toolName = body.params.name;
241241
if (typeof toolName === 'string') {
242-
return isGradioTool(toolName);
242+
// Check for standard Gradio tools (gr<number>_ or grp<number>_)
243+
if (isGradioTool(toolName)) {
244+
return true;
245+
}
246+
247+
// Special case: dynamic_space with "invoke" operation needs streaming
248+
if (toolName === 'dynamic_space' && body.params.arguments) {
249+
const args = body.params.arguments as { operation?: string } | undefined;
250+
if (args?.operation === 'invoke') {
251+
return true;
252+
}
253+
}
243254
}
244255
}
245256

packages/app/src/server/utils/gradio-utils.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* Utility functions for handling Gradio endpoint detection and configuration
33
*/
4-
import { DYNAMIC_SPACE_TOOL_CONFIG } from '@llmindset/hf-mcp';
54
import type { SpaceTool } from '../../shared/settings.js';
65
import { GRADIO_PREFIX, GRADIO_PRIVATE_PREFIX } from '../../shared/constants.js';
76
import { logger } from './logger.js';
@@ -17,14 +16,12 @@ import { getGradioSpaces } from './gradio-discovery.js';
1716
* @example
1817
* isGradioTool('gr1_evalstate_flux1_schnell') // true
1918
* isGradioTool('grp2_private_tool') // true
20-
* isGradioTool('dynamic_space') // true
2119
* isGradioTool('hf_doc_search') // false
2220
* isGradioTool('regular_tool') // false
2321
*/
2422
export function isGradioTool(toolName: string): boolean {
2523
// Gradio tools follow pattern: gr<number>_<name> or grp<number>_<name>
26-
// Also includes the special dynamic_space tool
27-
return /^grp?\d+_/.test(toolName) || toolName === DYNAMIC_SPACE_TOOL_CONFIG.name;
24+
return /^grp?\d+_/.test(toolName);
2825
}
2926

3027
/**

packages/app/test/server/utils/gradio-utils.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ describe('isGradioTool', () => {
1919
expect(isGradioTool('grp10_test')).toBe(true);
2020
});
2121

22-
it('should detect dynamic_space tool', () => {
23-
expect(isGradioTool('dynamic_space')).toBe(true);
24-
});
25-
2622
it('should detect real-world Gradio tool names', () => {
2723
expect(isGradioTool('gr1_evalstate_flux1_schnell')).toBe(true);
2824
expect(isGradioTool('grp3_my_private_space')).toBe(true);
@@ -51,6 +47,7 @@ describe('isGradioTool', () => {
5147
expect(isGradioTool('hf_doc_search')).toBe(false);
5248
expect(isGradioTool('hf_model_search')).toBe(false);
5349
expect(isGradioTool('hf_whoami')).toBe(false);
50+
expect(isGradioTool('dynamic_space')).toBe(false);
5451
});
5552

5653
it('should reject tools with missing number', () => {

0 commit comments

Comments
 (0)