@llmindset/hf-mcp 0.2.55 → 0.2.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/space/utils/gradio-caller.d.ts +4 -3
- package/dist/space/utils/gradio-caller.d.ts.map +1 -1
- package/dist/space/utils/gradio-caller.js +30 -9
- package/dist/space/utils/gradio-caller.js.map +1 -1
- package/dist/space/utils/result-formatter.d.ts +2 -2
- package/dist/space/utils/result-formatter.d.ts.map +1 -1
- package/dist/space/utils/result-formatter.js.map +1 -1
- package/package.json +2 -2
- package/src/space/utils/gradio-caller.ts +44 -13
- package/src/space/utils/result-formatter.ts +3 -3
- package/test/gradio-caller.test.ts +5 -5
- package/test/gradio-progress-relay.test.ts +81 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type CallToolResult, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
3
3
|
export interface GradioCallResult {
|
|
4
|
-
result:
|
|
4
|
+
result: CallToolResult;
|
|
5
5
|
capturedHeaders: Record<string, string>;
|
|
6
6
|
}
|
|
7
7
|
export interface GradioCallOptions {
|
|
8
8
|
onHeaders?: (headers: Headers) => void;
|
|
9
9
|
logProxiedReplica?: boolean;
|
|
10
|
+
onProgressRelayFailure?: () => void;
|
|
10
11
|
}
|
|
11
12
|
export declare function extractReplicaId(headerValue: string | undefined): string | null;
|
|
12
|
-
export declare function rewriteReplicaUrlsInResult(result:
|
|
13
|
+
export declare function rewriteReplicaUrlsInResult(result: CallToolResult, proxiedReplicaHeader: string | undefined): CallToolResult;
|
|
13
14
|
export declare function callGradioToolWithHeaders(sseUrl: string, toolName: string, parameters: Record<string, unknown>, hfToken: string | undefined, extra: RequestHandlerExtra<ServerRequest, ServerNotification> | undefined, options?: GradioCallOptions): Promise<GradioCallResult>;
|
|
14
15
|
//# sourceMappingURL=gradio-caller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradio-caller.d.ts","sourceRoot":"","sources":["../../../src/space/utils/gradio-caller.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"gradio-caller.d.ts","sourceRoot":"","sources":["../../../src/space/utils/gradio-caller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,cAAc,EAAE,KAAK,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAC5I,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,8CAA8C,CAAC;AAExG,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,cAAc,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,iBAAiB;IAEjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAEvC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACpC;AAMD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAO/E;AAOD,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,cAAc,EACtB,oBAAoB,EAAE,MAAM,GAAG,SAAS,GACtC,cAAc,CAuChB;AAMD,wBAAsB,yBAAyB,CAC9C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,CAAC,GAAG,SAAS,EACzE,OAAO,GAAE,iBAAsB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CA8I3B"}
|
|
@@ -104,18 +104,39 @@ export async function callGradioToolWithHeaders(sseUrl, toolName, parameters, hf
|
|
|
104
104
|
await remoteClient.connect(transport);
|
|
105
105
|
try {
|
|
106
106
|
const progressToken = extra?._meta?.progressToken;
|
|
107
|
+
let progressRelayDisabled = false;
|
|
108
|
+
const sendProgressNotification = async (progress) => {
|
|
109
|
+
if (!extra || progressRelayDisabled)
|
|
110
|
+
return;
|
|
111
|
+
if (extra.signal?.aborted) {
|
|
112
|
+
progressRelayDisabled = true;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const params = {
|
|
117
|
+
progressToken: progressToken,
|
|
118
|
+
progress: progress.progress ?? 0,
|
|
119
|
+
};
|
|
120
|
+
if (progress.total !== undefined) {
|
|
121
|
+
params.total = progress.total;
|
|
122
|
+
}
|
|
123
|
+
if (progress.message !== undefined) {
|
|
124
|
+
params.message = progress.message;
|
|
125
|
+
}
|
|
126
|
+
await extra.sendNotification({
|
|
127
|
+
method: 'notifications/progress',
|
|
128
|
+
params,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
progressRelayDisabled = true;
|
|
133
|
+
options.onProgressRelayFailure?.();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
107
136
|
const requestOptions = {};
|
|
108
137
|
if (progressToken !== undefined && extra) {
|
|
109
138
|
requestOptions.onprogress = (progress) => {
|
|
110
|
-
void
|
|
111
|
-
method: 'notifications/progress',
|
|
112
|
-
params: {
|
|
113
|
-
progressToken,
|
|
114
|
-
progress: progress.progress,
|
|
115
|
-
total: progress.total,
|
|
116
|
-
message: progress.message,
|
|
117
|
-
},
|
|
118
|
-
});
|
|
139
|
+
void sendProgressNotification(progress);
|
|
119
140
|
};
|
|
120
141
|
requestOptions.resetTimeoutOnProgress = true;
|
|
121
142
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradio-caller.js","sourceRoot":"","sources":["../../../src/space/utils/gradio-caller.ts"],"names":[],"mappings":"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,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;IAC/C,CAAC;YAAS,CAAC;QACV,MAAM,YAAY,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;AACF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function formatToolResult(result:
|
|
1
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
export declare function formatToolResult(result: CallToolResult): string;
|
|
3
3
|
export declare function formatWarnings(warnings: string[]): string;
|
|
4
4
|
//# sourceMappingURL=result-formatter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-formatter.d.ts","sourceRoot":"","sources":["../../../src/space/utils/result-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"result-formatter.d.ts","sourceRoot":"","sources":["../../../src/space/utils/result-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAUzE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAa/D;AAmMD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAOzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-formatter.js","sourceRoot":"","sources":["../../../src/space/utils/result-formatter.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"result-formatter.js","sourceRoot":"","sources":["../../../src/space/utils/result-formatter.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,gBAAgB,CAAC,MAAsB;IAEtD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAGD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,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S,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrC,CAAC;IAGD,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,SAAS,UAAU,aAAa,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAKD,MAAM,UAAU,cAAc,CAAC,QAAkB;IAChD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;IAChE,OAAO,GAAG,MAAM,KAAK,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;AACrE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmindset/hf-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.57",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@huggingface/hub": "^2.6.12",
|
|
27
27
|
"@mcp-ui/server": "^5.12.0",
|
|
28
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.24.3",
|
|
29
29
|
"shell-quote": "^1.8.3",
|
|
30
30
|
"turndown": "^7.2.0",
|
|
31
31
|
"zod": "^3.24.4"
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
2
|
import { SSEClientTransport, type SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
3
|
-
import { CallToolResultSchema, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import { CallToolResultSchema, type CallToolResult, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
4
4
|
import type { RequestHandlerExtra, RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
5
5
|
|
|
6
6
|
export interface GradioCallResult {
|
|
7
|
-
result:
|
|
7
|
+
result: CallToolResult;
|
|
8
8
|
capturedHeaders: Record<string, string>;
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -13,6 +13,8 @@ export interface GradioCallOptions {
|
|
|
13
13
|
onHeaders?: (headers: Headers) => void;
|
|
14
14
|
/** Log the X-Proxied-Replica header to stderr once */
|
|
15
15
|
logProxiedReplica?: boolean;
|
|
16
|
+
/** Optional hook for when progress relay fails (e.g., client disconnected) */
|
|
17
|
+
onProgressRelayFailure?: () => void;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -34,9 +36,9 @@ export function extractReplicaId(headerValue: string | undefined): string | null
|
|
|
34
36
|
* https://mcp-tools-qwen-image-fast.hf.space/--replicas/<replica_id>/gradio_api
|
|
35
37
|
*/
|
|
36
38
|
export function rewriteReplicaUrlsInResult(
|
|
37
|
-
result:
|
|
39
|
+
result: CallToolResult,
|
|
38
40
|
proxiedReplicaHeader: string | undefined
|
|
39
|
-
):
|
|
41
|
+
): CallToolResult {
|
|
40
42
|
if (process.env.NO_REPLICA_REWRITE) return result;
|
|
41
43
|
const replicaId = extractReplicaId(proxiedReplicaHeader);
|
|
42
44
|
if (!replicaId) return result;
|
|
@@ -163,20 +165,49 @@ export async function callGradioToolWithHeaders(
|
|
|
163
165
|
try {
|
|
164
166
|
// Check if the client is requesting progress notifications
|
|
165
167
|
const progressToken = extra?._meta?.progressToken;
|
|
168
|
+
|
|
169
|
+
// Track whether we've seen a transport closure to avoid noisy retries
|
|
170
|
+
let progressRelayDisabled = false;
|
|
171
|
+
|
|
172
|
+
const sendProgressNotification = async (progress: { progress?: number; total?: number; message?: string }) => {
|
|
173
|
+
if (!extra || progressRelayDisabled) return;
|
|
174
|
+
if (extra.signal?.aborted) {
|
|
175
|
+
progressRelayDisabled = true;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
const params: {
|
|
180
|
+
progressToken: number;
|
|
181
|
+
progress: number;
|
|
182
|
+
total?: number;
|
|
183
|
+
message?: string;
|
|
184
|
+
} = {
|
|
185
|
+
progressToken: progressToken as number,
|
|
186
|
+
progress: progress.progress ?? 0,
|
|
187
|
+
};
|
|
188
|
+
if (progress.total !== undefined) {
|
|
189
|
+
params.total = progress.total;
|
|
190
|
+
}
|
|
191
|
+
if (progress.message !== undefined) {
|
|
192
|
+
params.message = progress.message;
|
|
193
|
+
}
|
|
194
|
+
await extra.sendNotification({
|
|
195
|
+
method: 'notifications/progress',
|
|
196
|
+
params,
|
|
197
|
+
});
|
|
198
|
+
} catch {
|
|
199
|
+
// The underlying transport has likely closed (e.g., client disconnected); disable further relays.
|
|
200
|
+
progressRelayDisabled = true;
|
|
201
|
+
options.onProgressRelayFailure?.();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
166
205
|
const requestOptions: RequestOptions = {};
|
|
167
206
|
|
|
168
207
|
if (progressToken !== undefined && extra) {
|
|
169
208
|
// Fire-and-forget; best-effort relay
|
|
170
209
|
requestOptions.onprogress = (progress) => {
|
|
171
|
-
void
|
|
172
|
-
method: 'notifications/progress',
|
|
173
|
-
params: {
|
|
174
|
-
progressToken,
|
|
175
|
-
progress: progress.progress,
|
|
176
|
-
total: progress.total,
|
|
177
|
-
message: progress.message,
|
|
178
|
-
},
|
|
179
|
-
});
|
|
210
|
+
void sendProgressNotification(progress);
|
|
180
211
|
};
|
|
181
212
|
requestOptions.resetTimeoutOnProgress = true;
|
|
182
213
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Formats tool result for user-friendly display
|
|
@@ -8,7 +8,7 @@ import type { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
|
8
8
|
* - Resource content (with URIs)
|
|
9
9
|
* - Error results
|
|
10
10
|
*/
|
|
11
|
-
export function formatToolResult(result:
|
|
11
|
+
export function formatToolResult(result: CallToolResult): string {
|
|
12
12
|
// Handle error results
|
|
13
13
|
if (result.isError) {
|
|
14
14
|
return formatErrorResult(result);
|
|
@@ -26,7 +26,7 @@ export function formatToolResult(result: typeof CallToolResultSchema._type): str
|
|
|
26
26
|
/**
|
|
27
27
|
* Formats error results
|
|
28
28
|
*/
|
|
29
|
-
function formatErrorResult(result:
|
|
29
|
+
function formatErrorResult(result: CallToolResult): string {
|
|
30
30
|
if (!Array.isArray(result.content) || result.content.length === 0) {
|
|
31
31
|
return 'Error: Tool execution failed (no error details provided).';
|
|
32
32
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { rewriteReplicaUrlsInResult, extractReplicaId } from '../src/space/utils/gradio-caller.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
4
4
|
|
|
5
|
-
const baseResult:
|
|
5
|
+
const baseResult: CallToolResult = {
|
|
6
6
|
content: [],
|
|
7
7
|
isError: false,
|
|
8
8
|
};
|
|
@@ -35,7 +35,7 @@ describe('rewriteReplicaUrlsInResult', () => {
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it('rewrites URLs in text content when header is present', () => {
|
|
38
|
-
const result:
|
|
38
|
+
const result: CallToolResult = {
|
|
39
39
|
...baseResult,
|
|
40
40
|
content: [
|
|
41
41
|
{ type: 'text', text: `prefix ${matchUrl} suffix` },
|
|
@@ -53,7 +53,7 @@ describe('rewriteReplicaUrlsInResult', () => {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it('does nothing when header is missing', () => {
|
|
56
|
-
const result:
|
|
56
|
+
const result: CallToolResult = {
|
|
57
57
|
...baseResult,
|
|
58
58
|
content: [{ type: 'text', text: `prefix ${matchUrl} suffix` }],
|
|
59
59
|
};
|
|
@@ -65,7 +65,7 @@ describe('rewriteReplicaUrlsInResult', () => {
|
|
|
65
65
|
|
|
66
66
|
it('respects NO_REPLICA_REWRITE env', () => {
|
|
67
67
|
process.env.NO_REPLICA_REWRITE = '1';
|
|
68
|
-
const result:
|
|
68
|
+
const result: CallToolResult = {
|
|
69
69
|
...baseResult,
|
|
70
70
|
content: [{ type: 'text', text: matchUrl }],
|
|
71
71
|
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeAll } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Stub out the SSE transport to simulate progress + response without network.
|
|
4
|
+
vi.mock('@modelcontextprotocol/sdk/client/sse.js', () => {
|
|
5
|
+
class FakeSSEClientTransport {
|
|
6
|
+
onmessage?: (msg: unknown) => void;
|
|
7
|
+
onclose?: () => void;
|
|
8
|
+
onerror?: (err: unknown) => void;
|
|
9
|
+
sessionId = 'fake';
|
|
10
|
+
|
|
11
|
+
constructor(_url: URL, _options: unknown) {}
|
|
12
|
+
|
|
13
|
+
async start() {
|
|
14
|
+
/* no-op */
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async close() {
|
|
18
|
+
this.onclose?.();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async send(message: any) {
|
|
22
|
+
// Simulate two progress notifications followed by a result.
|
|
23
|
+
const progressToken = message?.id ?? message?.params?._meta?.progressToken ?? 0;
|
|
24
|
+
queueMicrotask(() => {
|
|
25
|
+
this.onmessage?.({
|
|
26
|
+
jsonrpc: '2.0',
|
|
27
|
+
method: 'notifications/progress',
|
|
28
|
+
params: { progressToken, progress: 1, total: 10, message: 'first' },
|
|
29
|
+
});
|
|
30
|
+
this.onmessage?.({
|
|
31
|
+
jsonrpc: '2.0',
|
|
32
|
+
method: 'notifications/progress',
|
|
33
|
+
params: { progressToken, progress: 2, total: 10, message: 'second' },
|
|
34
|
+
});
|
|
35
|
+
this.onmessage?.({
|
|
36
|
+
jsonrpc: '2.0',
|
|
37
|
+
id: message.id,
|
|
38
|
+
result: { isError: false, content: [{ type: 'text', text: 'ok' }] },
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { SSEClientTransport: FakeSSEClientTransport };
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
let callGradioToolWithHeaders: typeof import('../src/space/utils/gradio-caller.js').callGradioToolWithHeaders;
|
|
48
|
+
|
|
49
|
+
beforeAll(async () => {
|
|
50
|
+
({ callGradioToolWithHeaders } = await import('../src/space/utils/gradio-caller.js'));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('callGradioToolWithHeaders progress relay', () => {
|
|
54
|
+
it('swallows progress send failures after disconnect', async () => {
|
|
55
|
+
let attempts = 0;
|
|
56
|
+
const extra = {
|
|
57
|
+
_meta: { progressToken: 42 },
|
|
58
|
+
sendNotification: vi.fn().mockImplementation(async () => {
|
|
59
|
+
attempts += 1;
|
|
60
|
+
throw new Error('Not connected');
|
|
61
|
+
}),
|
|
62
|
+
signal: new AbortController().signal,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const { result } = await callGradioToolWithHeaders(
|
|
66
|
+
'http://fake-sse.local/gradio_api/mcp/sse',
|
|
67
|
+
'tools/call',
|
|
68
|
+
{},
|
|
69
|
+
undefined,
|
|
70
|
+
extra as any
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// Allow pending microtasks (progress relay) to flush
|
|
74
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
75
|
+
|
|
76
|
+
expect(result.isError).toBe(false);
|
|
77
|
+
// Progress relay should never crash and should not spam after failure.
|
|
78
|
+
expect(attempts).toBeLessThanOrEqual(1);
|
|
79
|
+
expect(extra.sendNotification.mock.calls.length).toBeLessThanOrEqual(1);
|
|
80
|
+
});
|
|
81
|
+
});
|