MCPcopy Index your code
hub / github.com/callstack/agent-device / handleReadCommand

Function handleReadCommand

src/core/dispatch-interactions.ts:1043–1094  ·  view source on GitHub ↗
(
  device: DeviceInfo,
  positionals: string[],
  context: DispatchContext | undefined,
)

Source from the content-addressed store, hash-verified

1041}
1042
1043export async function handleReadCommand(
1044 device: DeviceInfo,
1045 positionals: string[],
1046 context: DispatchContext | undefined,
1047): Promise<Record<string, unknown>> {
1048 const { x, y } = readPoint(positionals, 'read requires x y');
1049 if (device.platform === 'android') {
1050 const { readAndroidTextAtPoint } = await import('../platforms/android/input-actions.ts');
1051 const text = await readAndroidTextAtPoint(device, x, y);
1052 return { action: 'read', text: text ?? '' };
1053 }
1054 if (device.platform === 'linux') {
1055 const { readLinuxTextAtPoint } = await import('../platforms/linux/snapshot.ts');
1056 const text = await readLinuxTextAtPoint(x, y, context?.surface);
1057 return { action: 'read', text };
1058 }
1059 if (isMacOs(device) && context?.surface && context.surface !== 'app') {
1060 const { runMacOsReadTextAction } = await import('../platforms/apple/os/macos/helper.ts');
1061 const result = await runMacOsReadTextAction(x, y, {
1062 bundleId: context.appBundleId,
1063 surface: context.surface,
1064 });
1065 return { action: 'read', text: result.text };
1066 }
1067 // macOS app sessions run through the XCUITest runner; only desktop/menubar surfaces use the helper.
1068 const { runAppleRunnerCommand } = await import('../platforms/apple/core/runner/runner-client.ts');
1069 const result = await runAppleRunnerCommand(
1070 device,
1071 {
1072 command: 'readText',
1073 x,
1074 y,
1075 appBundleId: context?.appBundleId,
1076 },
1077 {
1078 verbose: context?.verbose,
1079 logPath: context?.logPath,
1080 traceLogPath: context?.traceLogPath,
1081 requestId: context?.requestId,
1082 iosXctestrunFile: context?.iosXctestrunFile,
1083 iosXctestDerivedDataPath: context?.iosXctestDerivedDataPath,
1084 iosXctestEnvDir: context?.iosXctestEnvDir,
1085 },
1086 );
1087 const text =
1088 typeof result.text === 'string'
1089 ? result.text
1090 : typeof result.message === 'string'
1091 ? result.message
1092 : '';
1093 return { action: 'read', text };
1094}
1095
1096function findMistargetedTypeRef(positionals: string[]): string | null {
1097 return findMistargetedTypeRefToken(positionals[0]);

Callers 1

dispatch.tsFile · 0.90

Calls 6

isMacOsFunction · 0.90
readAndroidTextAtPointFunction · 0.85
readLinuxTextAtPointFunction · 0.85
runMacOsReadTextActionFunction · 0.85
runAppleRunnerCommandFunction · 0.85
readPointFunction · 0.70

Tested by

no test coverage detected