| 45 | } |
| 46 | |
| 47 | function resolveClientId( |
| 48 | server: ReactotronServer, |
| 49 | requestedClientId?: string |
| 50 | ): { clientId?: string; error?: string } { |
| 51 | const connections = server.connections as any[] |
| 52 | |
| 53 | if (connections.length === 0) { |
| 54 | return { error: "No apps connected to Reactotron." } |
| 55 | } |
| 56 | |
| 57 | if (connections.length > 1 && !requestedClientId) { |
| 58 | const apps = connections.map((c) => `${c.name} (${c.platform}): ${c.clientId}`).join(", ") |
| 59 | return { error: `Multiple apps connected. Specify clientId. Available: ${apps}` } |
| 60 | } |
| 61 | |
| 62 | return { clientId: requestedClientId || connections[0]?.clientId } |
| 63 | } |
| 64 | |
| 65 | function textResult(data: unknown, guidance?: string) { |
| 66 | return { content: [{ type: "text" as const, text: safeSerialize(data, MAX_RESPONSE_CHARS, guidance) }] } |