@hcu-lab.me/mcp-device 1.0.7 → 1.0.9
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.
|
@@ -58,6 +58,7 @@ export declare class GatewayDeviceChannel {
|
|
|
58
58
|
private sendUpdateStatusFlushed;
|
|
59
59
|
reportUpdateFailure(requestId: string, targetVersion: string, code: string, message: string): Promise<void>;
|
|
60
60
|
private handleUpdateRequest;
|
|
61
|
+
private dispatchToolCall;
|
|
61
62
|
private handleToolCall;
|
|
62
63
|
private scheduleReconnect;
|
|
63
64
|
private startHeartbeat;
|
|
@@ -282,7 +282,7 @@ export class GatewayDeviceChannel {
|
|
|
282
282
|
throw new Error('Gateway tool_call arrived before authentication');
|
|
283
283
|
if (String(message.connection_epoch) !== String(this.connectionEpoch))
|
|
284
284
|
throw new Error('Gateway tool_call connection_epoch mismatch');
|
|
285
|
-
|
|
285
|
+
this.dispatchToolCall(message);
|
|
286
286
|
}
|
|
287
287
|
async logoutAccount(timeoutMs = 5000) {
|
|
288
288
|
if (!this.socket || this.socket.readyState !== WebSocket.OPEN || this.connectionEpoch === undefined || !this.authenticatedDeviceId) {
|
|
@@ -395,30 +395,45 @@ export class GatewayDeviceChannel {
|
|
|
395
395
|
this.updateInFlight = undefined;
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
|
+
dispatchToolCall(message) {
|
|
399
|
+
void this.handleToolCall(message).catch(error => {
|
|
400
|
+
if (!this.shuttingDown)
|
|
401
|
+
this.fail(error instanceof Error ? error : new Error(String(error)));
|
|
402
|
+
});
|
|
403
|
+
}
|
|
398
404
|
async handleToolCall(message) {
|
|
399
405
|
if (this.connectionEpoch === undefined || !this.authenticatedDeviceId)
|
|
400
406
|
throw new Error('Gateway tool_call arrived before authentication');
|
|
401
407
|
const requestId = String(message.request_id || '');
|
|
402
408
|
const tool = String(message.payload?.tool || '');
|
|
409
|
+
const deviceId = this.authenticatedDeviceId;
|
|
410
|
+
const connectionEpoch = this.connectionEpoch;
|
|
411
|
+
const socket = this.socket;
|
|
412
|
+
const connectionIsCurrent = () => Boolean(socket && socket.readyState === WebSocket.OPEN && this.socket === socket &&
|
|
413
|
+
this.authenticatedDeviceId === deviceId && String(this.connectionEpoch) === String(connectionEpoch));
|
|
403
414
|
try {
|
|
404
415
|
const result = await this.options.adapter.call(tool, message.payload?.arguments || {});
|
|
416
|
+
if (!connectionIsCurrent())
|
|
417
|
+
return;
|
|
405
418
|
this.send({
|
|
406
419
|
protocol_version: this.protocolVersion,
|
|
407
420
|
type: 'tool_result',
|
|
408
421
|
request_id: requestId,
|
|
409
|
-
device_id:
|
|
410
|
-
connection_epoch:
|
|
422
|
+
device_id: deviceId,
|
|
423
|
+
connection_epoch: connectionEpoch,
|
|
411
424
|
timestamp: Date.now(),
|
|
412
425
|
payload: result
|
|
413
426
|
});
|
|
414
427
|
}
|
|
415
428
|
catch (error) {
|
|
429
|
+
if (!connectionIsCurrent())
|
|
430
|
+
return;
|
|
416
431
|
this.send({
|
|
417
432
|
protocol_version: this.protocolVersion,
|
|
418
433
|
type: 'tool_error',
|
|
419
434
|
request_id: requestId,
|
|
420
|
-
device_id:
|
|
421
|
-
connection_epoch:
|
|
435
|
+
device_id: deviceId,
|
|
436
|
+
connection_epoch: connectionEpoch,
|
|
422
437
|
timestamp: Date.now(),
|
|
423
438
|
payload: {
|
|
424
439
|
message: String(error?.message || error),
|
|
@@ -221,7 +221,9 @@ async function runNpm(nodePath, npmCliPath, args, execFile) {
|
|
|
221
221
|
return await execFile(nodePath, [npmCliPath, ...args]);
|
|
222
222
|
}
|
|
223
223
|
export async function findCurrentPackageRoot(entrypoint = process.argv[1]) {
|
|
224
|
-
|
|
224
|
+
const resolvedEntrypoint = path.resolve(entrypoint || process.execPath);
|
|
225
|
+
const canonicalEntrypoint = await fs.realpath(resolvedEntrypoint).catch(() => resolvedEntrypoint);
|
|
226
|
+
let current = path.dirname(canonicalEntrypoint);
|
|
225
227
|
for (let i = 0; i < 8; i++) {
|
|
226
228
|
const manifest = path.join(current, 'package.json');
|
|
227
229
|
if (await exists(manifest)) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.0.
|
|
1
|
+
export declare const VERSION = "1.0.9";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '1.0.
|
|
1
|
+
export const VERSION = '1.0.9';
|