|
1 | 1 | import { dispatchCommand, resolveTargetDevice } from '../../core/dispatch.ts'; |
2 | | -import { findBestMatchesByLocator, type FindLocator } from '../../utils/finders.ts'; |
| 2 | +import { findBestMatchesByLocator, parseFindArgs, type FindLocator } from '../../utils/finders.ts'; |
3 | 3 | import { centerOfRect, type SnapshotState } from '../../utils/snapshot.ts'; |
4 | | -import { AppError } from '../../utils/errors.ts'; |
5 | 4 | import type { DaemonRequest, DaemonResponse } from '../types.ts'; |
6 | 5 | import { SessionStore } from '../session-store.ts'; |
7 | 6 | import { contextFromFlags } from '../context.ts'; |
8 | 7 | import { ensureDeviceReady } from '../device-ready.ts'; |
9 | 8 | import { extractNodeText, findNearestHittableAncestor } from '../snapshot-processing.ts'; |
10 | | -import { parseTimeout } from './parse-utils.ts'; |
11 | 9 | import { readTextForNode } from './interaction-read.ts'; |
12 | 10 | import { captureSnapshot } from './snapshot-capture.ts'; |
13 | 11 | import { errorResponse } from './response.ts'; |
14 | 12 | import { getActiveAndroidSnapshotFreshness } from '../android-snapshot-freshness.ts'; |
15 | 13 |
|
| 14 | +export { parseFindArgs } from '../../utils/finders.ts'; |
| 15 | + |
16 | 16 | type FindContext = { |
17 | 17 | req: DaemonRequest; |
18 | 18 | sessionName: string; |
@@ -381,60 +381,6 @@ function buildAmbiguousMatchError( |
381 | 381 | ); |
382 | 382 | } |
383 | 383 |
|
384 | | -type FindAction = |
385 | | - | { kind: 'click' } |
386 | | - | { kind: 'focus' } |
387 | | - | { kind: 'fill'; value: string } |
388 | | - | { kind: 'type'; value: string } |
389 | | - | { kind: 'get_text' } |
390 | | - | { kind: 'get_attrs' } |
391 | | - | { kind: 'exists' } |
392 | | - | { kind: 'wait'; timeoutMs?: number }; |
393 | | - |
394 | | -export function parseFindArgs(args: string[]): { |
395 | | - locator: FindLocator; |
396 | | - query: string; |
397 | | - action: FindAction['kind']; |
398 | | - value?: string; |
399 | | - timeoutMs?: number; |
400 | | -} { |
401 | | - const locatorTokens: FindLocator[] = ['text', 'label', 'value', 'role', 'id']; |
402 | | - let locator: FindLocator = 'any'; |
403 | | - let queryIndex = 0; |
404 | | - if (locatorTokens.includes(args[0] as FindLocator)) { |
405 | | - locator = args[0] as FindLocator; |
406 | | - queryIndex = 1; |
407 | | - } |
408 | | - const query = args[queryIndex] ?? ''; |
409 | | - const actionTokens = args.slice(queryIndex + 1); |
410 | | - if (actionTokens.length === 0) { |
411 | | - return { locator, query, action: 'click' }; |
412 | | - } |
413 | | - const action = actionTokens[0].toLowerCase(); |
414 | | - if (action === 'get') { |
415 | | - const sub = actionTokens[1]?.toLowerCase(); |
416 | | - if (sub === 'text') return { locator, query, action: 'get_text' }; |
417 | | - if (sub === 'attrs') return { locator, query, action: 'get_attrs' }; |
418 | | - throw new AppError('INVALID_ARGS', 'find get only supports text or attrs'); |
419 | | - } |
420 | | - if (action === 'wait') { |
421 | | - const timeoutMs = parseTimeout(actionTokens[1]); |
422 | | - return { locator, query, action: 'wait', timeoutMs: timeoutMs ?? undefined }; |
423 | | - } |
424 | | - if (action === 'exists') return { locator, query, action: 'exists' }; |
425 | | - if (action === 'click') return { locator, query, action: 'click' }; |
426 | | - if (action === 'focus') return { locator, query, action: 'focus' }; |
427 | | - if (action === 'fill') { |
428 | | - const value = actionTokens.slice(1).join(' '); |
429 | | - return { locator, query, action: 'fill', value }; |
430 | | - } |
431 | | - if (action === 'type') { |
432 | | - const value = actionTokens.slice(1).join(' '); |
433 | | - return { locator, query, action: 'type', value }; |
434 | | - } |
435 | | - throw new AppError('INVALID_ARGS', `Unsupported find action: ${actionTokens[0]}`); |
436 | | -} |
437 | | - |
438 | 384 | function shouldScopeFind(locator: FindLocator): boolean { |
439 | 385 | return locator !== 'role'; |
440 | 386 | } |
0 commit comments