MCPcopy Create free account
hub / github.com/Snapchat/Valdi / resolveClientId

Function resolveClientId

npm_modules/cli/src/utils/daemonClient.ts:463–502  ·  view source on GitHub ↗
(
  conn: DaemonConnection,
  clientIdOverride?: string,
)

Source from the content-addressed store, hash-verified

461 * Priority: explicit --client flag → saved config → auto (single device) → prompt.
462 */
463export async function resolveClientId(
464 conn: DaemonConnection,
465 clientIdOverride?: string,
466): Promise<string> {
467 const clients = await conn.listConnectedClients();
468
469 if (clients.length === 0) {
470 throw new CliError(
471 'No devices connected to the Valdi daemon.\n' +
472 'Make sure the Valdi app is running and connected to the hot-reloader.',
473 );
474 }
475
476 if (clientIdOverride) {
477 if (!clients.some((c) => c.client_id === clientIdOverride)) {
478 throw new CliError(
479 `Client "${clientIdOverride}" not found. Run "valdi inspect devices" to see connected clients.`,
480 );
481 }
482 return clientIdOverride;
483 }
484
485 const config = loadInspectConfig();
486 if (config.selectedClientId && clients.some((c) => c.client_id === config.selectedClientId)) {
487 return config.selectedClientId;
488 }
489
490 if (clients.length === 1) {
491 return clients[0]!.client_id;
492 }
493
494 // Multiple devices — prompt
495 return getUserChoice(
496 clients.map((c) => ({
497 name: `${c.application_id} (${c.platform}) [${c.client_id}]`,
498 value: c.client_id,
499 })),
500 'Multiple devices connected. Select one:',
501 );
502}

Callers 4

inspectHeapFunction · 0.90
inspectSnapshotFunction · 0.90
inspectTreeFunction · 0.90
inspectContextsFunction · 0.90

Calls 4

getUserChoiceFunction · 0.90
loadInspectConfigFunction · 0.85
listConnectedClientsMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected