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

Function isCommand

src/commands/interaction/runtime/selector-read.ts:251–328  ·  view source on GitHub ↗
(
  runtime,
  options,
)

Source from the content-addressed store, hash-verified

249};
250
251export const isCommand: RuntimeCommand<IsCommandOptions, IsCommandResult> = async (
252 runtime,
253 options,
254): Promise<IsCommandResult> => {
255 if (!isSupportedPredicate(options.predicate)) {
256 throw new AppError(
257 'INVALID_ARGS',
258 'is requires predicate: visible|hidden|exists|editable|selected|text',
259 );
260 }
261 if (options.predicate === 'text' && !options.expectedText) {
262 throw new AppError('INVALID_ARGS', 'is text requires expected text value');
263 }
264 const includeRects = predicateNeedsRects(options.predicate);
265 const capture = await captureSelectorSnapshot(runtime, options, {
266 updateSession: true,
267 includeRects,
268 });
269 const chain = parseSelectorChain(options.selector);
270
271 if (options.predicate === 'exists') {
272 const matched = findSelectorChainMatch(capture.snapshot.nodes, chain, {
273 platform: runtime.backend.platform,
274 });
275 if (!matched) {
276 throw new AppError('COMMAND_FAILED', formatSelectorFailure(chain, [], { unique: false }));
277 }
278 return {
279 predicate: options.predicate,
280 pass: true,
281 selector: matched.selector.raw,
282 matches: matched.matches,
283 selectorChain: chain.selectors.map((entry) => entry.raw),
284 };
285 }
286
287 const resolved = resolveSelectorChain(capture.snapshot.nodes, chain, {
288 platform: runtime.backend.platform,
289 requireRect: false,
290 requireUnique: true,
291 disambiguateAmbiguous: false,
292 });
293 if (!resolved) {
294 throw new AppError('COMMAND_FAILED', formatSelectorFailure(chain, [], { unique: true }), {
295 command: 'is',
296 reason: 'selector_not_found',
297 predicate: options.predicate,
298 selector: chain.raw,
299 });
300 }
301 const result = evaluateIsPredicate({
302 predicate: options.predicate,
303 node: resolved.node,
304 nodes: capture.snapshot.nodes,
305 expectedText: options.expectedText,
306 platform: runtime.backend.platform,
307 });
308 if (!result.pass) {

Callers 2

isVisibleCommandFunction · 0.85
isHiddenCommandFunction · 0.85

Calls 8

isSupportedPredicateFunction · 0.90
captureSelectorSnapshotFunction · 0.90
parseSelectorChainFunction · 0.90
findSelectorChainMatchFunction · 0.90
formatSelectorFailureFunction · 0.90
resolveSelectorChainFunction · 0.90
evaluateIsPredicateFunction · 0.90
predicateNeedsRectsFunction · 0.85

Tested by

no test coverage detected