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

Function resolveContextId

npm_modules/cli/src/utils/daemonClient.ts:425–457  ·  view source on GitHub ↗
(
  conn: DaemonConnection,
  clientId: string,
  contextIdOverride?: string,
)

Source from the content-addressed store, hash-verified

423 * Priority: explicit contextId argument → auto (single context) → prompt.
424 */
425export async function resolveContextId(
426 conn: DaemonConnection,
427 clientId: string,
428 contextIdOverride?: string,
429): Promise<string> {
430 const contexts = await conn.listContexts(clientId);
431
432 if (contexts.length === 0) {
433 throw new CliError('No contexts found on the connected device.');
434 }
435
436 if (contextIdOverride) {
437 if (!contexts.some((c) => c.id === contextIdOverride)) {
438 throw new CliError(
439 `Context "${contextIdOverride}" not found. Run "valdi inspect contexts" to see available contexts.`,
440 );
441 }
442 return contextIdOverride;
443 }
444
445 if (contexts.length === 1) {
446 return contexts[0]!.id;
447 }
448
449 // Multiple contexts — prompt
450 return getUserChoice(
451 contexts.map((c) => ({
452 name: `${c.rootComponentName} [${c.id}]`,
453 value: c.id,
454 })),
455 'Multiple contexts found. Select one:',
456 );
457}
458
459/**
460 * Resolve which connected client to target.

Callers 2

inspectSnapshotFunction · 0.90
inspectTreeFunction · 0.90

Calls 3

getUserChoiceFunction · 0.90
listContextsMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected