Add macOS companion node status and system.nodes APIs
This commit is contained in:
+53
-1
@@ -220,6 +220,48 @@ export class GatewayServer {
|
||||
}
|
||||
return sorted;
|
||||
},
|
||||
getNodes: ({ role, platform, limit } = {}) => {
|
||||
const entries: Array<{
|
||||
connectionId: string;
|
||||
nodeId: string;
|
||||
role: string;
|
||||
identity?: string;
|
||||
protocolVersion: number;
|
||||
capabilities: string[];
|
||||
registeredAt: number;
|
||||
location?: NodeConnectionState['location'];
|
||||
status?: NodeConnectionState['status'];
|
||||
}> = [];
|
||||
|
||||
for (const [connectionId, state] of this.connectionStateMap.entries()) {
|
||||
if (!state.node) {
|
||||
continue;
|
||||
}
|
||||
if (role && state.node.role !== role) {
|
||||
continue;
|
||||
}
|
||||
if (platform && state.status?.platform !== platform) {
|
||||
continue;
|
||||
}
|
||||
entries.push({
|
||||
connectionId,
|
||||
nodeId: state.node.nodeId,
|
||||
role: state.node.role,
|
||||
identity: state.identity,
|
||||
protocolVersion: state.node.protocolVersion,
|
||||
capabilities: state.node.capabilities,
|
||||
registeredAt: state.node.registeredAt,
|
||||
location: state.location,
|
||||
status: state.status,
|
||||
});
|
||||
}
|
||||
|
||||
const sorted = entries.sort((a, b) => b.registeredAt - a.registeredAt);
|
||||
if (typeof limit === 'number' && Number.isFinite(limit) && limit > 0) {
|
||||
return sorted.slice(0, Math.floor(limit));
|
||||
}
|
||||
return sorted;
|
||||
},
|
||||
getUsage: () => ({
|
||||
totalSessions: this.config.sessionManager.listSessions().length,
|
||||
activeConnections: this.sessionBridge.connectionCount,
|
||||
@@ -342,6 +384,16 @@ export class GatewayServer {
|
||||
location,
|
||||
});
|
||||
},
|
||||
setNodeStatus: (connectionId, status) => {
|
||||
const existing = this.connectionStateMap.get(connectionId);
|
||||
if (!existing) {
|
||||
return;
|
||||
}
|
||||
this.connectionStateMap.set(connectionId, {
|
||||
...existing,
|
||||
status,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// Config handlers (only if config object is provided)
|
||||
@@ -688,7 +740,7 @@ export class GatewayServer {
|
||||
nodeRole: this.connectionStateMap.get(connectionId)?.node?.role,
|
||||
allowedRoles: this.config.nodes?.allowedRoles ?? [],
|
||||
roleScopes: {
|
||||
companion: ['node.capabilities.get', 'node.location.set', 'node.location.get'],
|
||||
companion: ['node.capabilities.get', 'node.location.set', 'node.location.get', 'node.status.set'],
|
||||
observer: ['node.capabilities.get', 'node.location.get'],
|
||||
automation: ['node.capabilities.get', 'node.location.get'],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user