handle method

  1. @override
Future<StructuredResponse> handle(
  1. GlintSession session,
  2. CallToolRequest request
)
override

Implementation

@override
Future<StructuredResponse> handle(GlintSession session, CallToolRequest request) async {
  final args = request.arguments ?? const {};
  final op = args['op'] as String?;
  if (!_ops.contains(op)) return _bad('op must be ${_ops.join(', ')}; got ${op ?? 'nothing'}');
  if (!session.isAttached || session.active?.deviceMode == true) {
    return StructuredResponse.error(
      summary: 'attach a Flutter app first: map reads the map through the app',
      errorKind: GlintErrorKind.sessionNotAttached,
      nextSteps: const ['attach'],
    );
  }
  final before = await _read(session, argInt(args, 'index') ?? 0);
  if (before == null) {
    return StructuredResponse.error(
      summary: 'no Google map on screen',
      errorKind: GlintErrorKind.targetNotFound,
      detail: 'map reads google_maps_flutter maps; other map packages are not read yet',
      nextSteps: const ['get_scene to see the screen'],
    );
  }
  if (before.center == null) {
    return StructuredResponse.error(
      summary: 'the map has not answered with its camera (${before.note ?? 'not ready'})',
      errorKind: GlintErrorKind.targetNeverReady,
      nextSteps: const ['wait a moment for the map to load, then retry'],
    );
  }
  return switch (op) {
    'read' => _reply(session, 'map', before, before),
    'tap' => await _tap(session, args, before),
    'pan' => await _pan(session, request, args, before),
    _ => await _zoom(session, args, before),
  };
}