feat: verify owned DeepSeek engine connections and responsive task execution
This commit is contained in:
@@ -11,9 +11,9 @@ const failure = (code, message, dispatched = false) => Object.assign(new Error(m
|
||||
// One owned stdio connection. The caller chooses a fixed executable/profile;
|
||||
// target content never becomes a shell command or a server-request approval.
|
||||
export class McpStdio extends EventEmitter {
|
||||
constructor(launch, { timeoutMs = 45000, maximumFrameBytes = 8 * 1024 * 1024 } = {}) {
|
||||
constructor(launch, { timeoutMs = 45000, maximumFrameBytes = 8 * 1024 * 1024, cancellationMethod = 'notifications/cancelled' } = {}) {
|
||||
super(); this.id = randomUUID(); this.pending = new Map(); this.sequence = 0; this.trace = [];
|
||||
this.timeoutMs = timeoutMs; this.maximumFrameBytes = maximumFrameBytes; this.stderr = ''; this.buffer = '';
|
||||
this.timeoutMs = timeoutMs; this.maximumFrameBytes = maximumFrameBytes; this.cancellationMethod = cancellationMethod; this.stderr = ''; this.buffer = '';
|
||||
this.child = spawn(launch.executable, launch.args, { cwd: launch.cwd, env: launch.env,
|
||||
shell: false, windowsHide: true, detached: process.platform !== 'win32', stdio: ['pipe', 'pipe', 'pipe'] });
|
||||
this.pid = this.child.pid; this.startedAt = new Date().toISOString(); this.exited = false;
|
||||
@@ -47,8 +47,10 @@ export class McpStdio extends EventEmitter {
|
||||
try { message = JSON.parse(line); } catch { return this.fail(failure('MCP_INVALID_FRAME', 'MCP返回了无效JSON帧。', true)); }
|
||||
if (!message || message.jsonrpc !== '2.0') return this.fail(failure('MCP_INVALID_FRAME', 'MCP返回了无效协议帧。', true));
|
||||
if (message.method) {
|
||||
if (message.id !== undefined) this.write({ jsonrpc: '2.0', id: message.id,
|
||||
error: { code: -32601, message: 'This profile does not grant server-initiated operations.' } });
|
||||
if (message.id !== undefined) {
|
||||
this.emit('server-request', message);
|
||||
this.write({ jsonrpc: '2.0', id: message.id, error: { code: -32601, message: 'This profile does not grant server-initiated operations.' } });
|
||||
}
|
||||
else this.emit('notification', message);
|
||||
continue;
|
||||
}
|
||||
@@ -82,11 +84,11 @@ export class McpStdio extends EventEmitter {
|
||||
startedAt: new Date().toISOString(), finishedAt: null, status: 'requesting', dispatched: true };
|
||||
this.trace.push(record);
|
||||
const abort = () => {
|
||||
this.notify('notifications/cancelled', { requestId: id, reason: 'Owned Workbench operation stopped.' });
|
||||
if (this.cancellationMethod) this.notify(this.cancellationMethod, { requestId: id, reason: 'Owned Workbench operation stopped.' });
|
||||
this.settle(id, failure('MCP_CANCELLED', '分析已请求停止,尚未返回的结果不算完成。', true));
|
||||
};
|
||||
const timer = setTimeout(() => {
|
||||
this.notify('notifications/cancelled', { requestId: id, reason: 'Owned Workbench request deadline.' });
|
||||
if (this.cancellationMethod) this.notify(this.cancellationMethod, { requestId: id, reason: 'Owned Workbench request deadline.' });
|
||||
this.settle(id, failure('MCP_TIMEOUT', 'MCP请求到达等待上限,没有自动重试。', true));
|
||||
}, timeoutMs);
|
||||
this.pending.set(id, { resolve, reject, timer, abort, signal, record }); signal?.addEventListener('abort', abort, { once: true });
|
||||
|
||||
Reference in New Issue
Block a user