feat: Add torch MCP tools for multi-browser control
- Add torchHandlers.ts with 5 tools: - list_torch_clients: list connected browsers with metadata - get_torch_status: show current torch holder - transfer_torch: transfer control to another browser - request_torch: request MCP control - release_torch: release MCP control - Add 'transfer' message type to server torch-handler - Add torch category to all pages - Export helper functions from torch.ts
This commit is contained in:
@@ -102,6 +102,43 @@ export function handleTorchMessage(ws: any, data: any, broadcast: (message: stri
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'transfer': {
|
||||
// Transfer torch to a specific client (only if sender has torch or no one has it)
|
||||
const targetId = data.targetId
|
||||
if (!targetId) {
|
||||
ws.send(JSON.stringify({ type: 'error', message: 'targetId required' }))
|
||||
break
|
||||
}
|
||||
|
||||
// Check if target exists
|
||||
let targetExists = false
|
||||
for (const [, c] of torchClients) {
|
||||
if (c.id === targetId) {
|
||||
targetExists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!targetExists) {
|
||||
ws.send(JSON.stringify({ type: 'error', message: 'Target client not found' }))
|
||||
break
|
||||
}
|
||||
|
||||
// Only allow transfer if sender has torch or no one has it
|
||||
if (torchHolderId !== null && torchHolderId !== client.id) {
|
||||
ws.send(JSON.stringify({ type: 'error', message: 'Cannot transfer - you do not have the torch' }))
|
||||
break
|
||||
}
|
||||
|
||||
const previousHolder = torchHolderId
|
||||
torchHolderId = targetId
|
||||
|
||||
ws.send(JSON.stringify({ type: 'transferred', targetId }))
|
||||
console.log(`[Torch] Transferred by ${client.id}: ${previousHolder} → ${targetId}`)
|
||||
broadcastTorchState(broadcast)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user