feat: Add torch client identity, early connection and auto-request

- Named clients persisted in localStorage, editable from dropdown
- Auto-request: clients can auto-receive torch when no holder exists
- Early torch init in App.vue (fires before WebMCP, awaited later)
- Deferred torch connection in toolRegistry for race condition safety
- TorchButton rewritten as dropdown with name editor, toggle, client list
- Server broadcasts client names, supports update-name message
- MCP tool handlers display client names
This commit is contained in:
2026-02-14 23:30:56 -06:00
parent 3f15aa590b
commit 2a80b7751b
8 changed files with 597 additions and 135 deletions

View File

@@ -22,11 +22,14 @@ function connectToTorchServer(): Promise<void> {
torchWs.onopen = () => {
console.log('[Torch] Connected to server')
// Register this client
const torchStore = useTorchStore()
// Register this client with name and autoRequest
torchWs?.send(JSON.stringify({
type: 'register',
userAgent: navigator.userAgent,
hostname: window.location.hostname
hostname: window.location.hostname,
name: torchStore.clientName || 'Anonymous',
autoRequest: torchStore.autoRequest
}))
resolve()
}
@@ -93,6 +96,12 @@ async function handleMessage(data: any) {
console.log('[Torch] Got torch, connecting to MCP')
await connectToMCP()
}
// Auto-request: if no one holds the torch and we have autoRequest enabled
if (!hasTorchNow && data.holderId === null && torchStore.autoRequest) {
console.log('[Torch] Auto-requesting torch (no holder)')
requestTorch()
}
break
}
@@ -157,6 +166,18 @@ export async function transferTorch(targetId: string): Promise<boolean> {
return true
}
/**
* Update client name on server
*/
export function updateName(name: string): void {
const torchStore = useTorchStore()
torchStore.setClientName(name)
if (torchWs?.readyState === WebSocket.OPEN) {
torchWs.send(JSON.stringify({ type: 'update-name', name }))
}
}
/**
* Get list of connected clients
*/