mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 23:42:03 +00:00
fix(cli,core): pass abort signal to MCP resource reads
This commit is contained in:
parent
5087426af7
commit
7e5d1470c8
4 changed files with 22 additions and 32 deletions
|
|
@ -247,6 +247,7 @@ describe('handleAtCommand', () => {
|
|||
expect(registry.readMcpResource).toHaveBeenCalledWith(
|
||||
'github',
|
||||
'github://repos/owner/repo/issues',
|
||||
expect.objectContaining({ signal: abortController.signal }),
|
||||
);
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
|
@ -298,6 +299,7 @@ describe('handleAtCommand', () => {
|
|||
expect(registry.readMcpResource).toHaveBeenCalledWith(
|
||||
'github',
|
||||
'github://repos/owner/repo/issues',
|
||||
expect.objectContaining({ signal: abortController.signal }),
|
||||
);
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
|
@ -349,6 +351,7 @@ describe('handleAtCommand', () => {
|
|||
expect(registry.readMcpResource).toHaveBeenCalledWith(
|
||||
'github',
|
||||
'github://repos/owner/repo/issues',
|
||||
expect.objectContaining({ signal: abortController.signal }),
|
||||
);
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
|
@ -417,6 +420,7 @@ describe('handleAtCommand', () => {
|
|||
expect(readMcpResourceSpy).toHaveBeenCalledWith(
|
||||
'github',
|
||||
'github://repos/owner/repo/issues',
|
||||
expect.objectContaining({ signal: abortController.signal }),
|
||||
);
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
|
@ -473,6 +477,7 @@ describe('handleAtCommand', () => {
|
|||
expect(registry.readMcpResource).toHaveBeenCalledWith(
|
||||
'github',
|
||||
'github://repos/owner/repo/issues',
|
||||
expect.objectContaining({ signal: abortController.signal }),
|
||||
);
|
||||
expect(mockAddItem).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
|
|
|||
|
|
@ -693,37 +693,17 @@ export async function handleAtCommand({
|
|||
const ref = mcpResourceRefs[i];
|
||||
let resourceResult: unknown;
|
||||
try {
|
||||
resourceResult = await new Promise((resolve, reject) => {
|
||||
if (signal.aborted) {
|
||||
const error = new Error('MCP resource read aborted');
|
||||
error.name = 'AbortError';
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
if (signal.aborted) {
|
||||
const error = new Error('MCP resource read aborted');
|
||||
error.name = 'AbortError';
|
||||
throw error;
|
||||
}
|
||||
|
||||
const onAbort = () => {
|
||||
cleanup();
|
||||
const error = new Error('MCP resource read aborted');
|
||||
error.name = 'AbortError';
|
||||
reject(error);
|
||||
};
|
||||
const cleanup = () => {
|
||||
signal.removeEventListener('abort', onAbort);
|
||||
};
|
||||
|
||||
signal.addEventListener('abort', onAbort, { once: true });
|
||||
|
||||
toolRegistry
|
||||
.readMcpResource(ref.serverName, ref.uri)
|
||||
.then((res) => {
|
||||
cleanup();
|
||||
resolve(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
cleanup();
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
resourceResult = await toolRegistry.readMcpResource(
|
||||
ref.serverName,
|
||||
ref.uri,
|
||||
{ signal },
|
||||
);
|
||||
|
||||
toolDisplays.push({
|
||||
callId: `client-mcp-resource-${userMessageTimestamp}-${i}`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue