MCPcopy
hub / github.com/claude-code-best/claude-code / usePipeRouter

Function usePipeRouter

src/hooks/usePipeRouter.ts:31–151  ·  view source on GitHub ↗
({ store, setAppState, addNotification }: Deps)

Source from the content-addressed store, hash-verified

29 * Returns true if routed to at least one pipe (skip local execution).
30 */
31export function usePipeRouter({ store, setAppState, addNotification }: Deps): {
32 routeToSelectedPipes: (input: string) => boolean
33} {
34 const routeToSelectedPipes = useCallback(
35 (input: string): boolean => {
36 if (!feature('UDS_INBOX')) return false
37 if (!input.trim() || input.trim().startsWith('/')) return false
38
39 /* eslint-disable @typescript-eslint/no-require-imports */
40 const pipeState = store.getState().pipeIpc
41 const selectedPipes: string[] = pipeState?.selectedPipes ?? []
42 const routeMode: 'selected' | 'local' = pipeState?.routeMode ?? 'selected'
43
44 if (selectedPipes.length === 0 || routeMode === 'local') return false
45
46 const { getConnectedSlaveTargets } =
47 require('./useMasterMonitor.js') as typeof import('./useMasterMonitor.js')
48 const { getPipeIpc } =
49 require('../utils/pipeTransport.js') as typeof import('../utils/pipeTransport.js')
50 /* eslint-enable @typescript-eslint/no-require-imports */
51
52 const targets = getConnectedSlaveTargets(selectedPipes)
53 const pipeIpcForDisplay = getPipeIpc(store.getState())
54 const discovered: Array<{
55 pipeName: string
56 role: string
57 ip: string
58 hostname: string
59 }> = pipeIpcForDisplay.discoveredPipes ?? []
60
61 const sentTargetNames: string[] = []
62 const sentTargetLabels: string[] = []
63 const failedTargetNames: string[] = []
64
65 for (const { name, client } of targets) {
66 try {
67 client.send({ type: 'prompt', data: input.trim() })
68 sentTargetNames.push(name)
69 // Build display label: [role] hostname/ip for LAN, [role] for local
70 const info = discovered.find((d: any) => d.pipeName === name)
71 if (info) {
72 const isLan = info.ip && info.ip !== pipeIpcForDisplay.localIp
73 sentTargetLabels.push(
74 isLan
75 ? `[${info.role}] ${info.hostname}/${info.ip}`
76 : `[${info.role}]`,
77 )
78 } else {
79 sentTargetLabels.push(name)
80 }
81 } catch {
82 failedTargetNames.push(name)
83 }
84 }
85
86 if (sentTargetNames.length > 0) {
87 const promptText = input.trim()
88 const promptTimestamp = new Date().toISOString()

Callers 1

REPLFunction · 0.85

Calls 6

getConnectedSlaveTargetsFunction · 0.85
getPipeIpcFunction · 0.85
getStateMethod · 0.80
sendMethod · 0.65
setAppStateFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected