@@ -181,6 +181,11 @@ base mixin DartToolingDaemonSupport
181
181
return _flutterDriverNotRegistered;
182
182
}
183
183
final vm = await vmService.getVM ();
184
+ final timeout = request.arguments? ['timeout' ] as String ? ;
185
+ final isScreenshot = request.arguments? ['command' ] == 'screenshot' ;
186
+ if (isScreenshot) {
187
+ request.arguments? .putIfAbsent ('format' , () => '4' /*png*/ );
188
+ }
184
189
final result = await vmService
185
190
.callServiceExtension (
186
191
_flutterDriverService,
@@ -189,17 +194,27 @@ base mixin DartToolingDaemonSupport
189
194
)
190
195
.timeout (
191
196
Duration (
192
- milliseconds:
193
- (request.arguments ? [ 'timeout' ] as int ? ) ??
194
- _defaultTimeoutMs,
197
+ milliseconds: timeout != null
198
+ ? int . parse (timeout)
199
+ : _defaultTimeoutMs,
195
200
),
196
201
onTimeout: () => Response .parse ({
197
202
'isError' : true ,
198
203
'error' : 'Timed out waiting for Flutter Driver response.' ,
199
204
})! ,
200
205
);
201
206
return CallToolResult (
202
- content: [Content .text (text: jsonEncode (result.json))],
207
+ content: [
208
+ isScreenshot && result.json? ['isError' ] == false
209
+ ? Content .image (
210
+ data:
211
+ (result.json! ['response' ]
212
+ as Map <String , Object ?>)['data' ]
213
+ as String ,
214
+ mimeType: 'image/png' ,
215
+ )
216
+ : Content .text (text: jsonEncode (result.json)),
217
+ ],
203
218
isError: result.json? ['isError' ] as bool ? ,
204
219
);
205
220
},
@@ -461,15 +476,14 @@ base mixin DartToolingDaemonSupport
461
476
callback: (vmService) async {
462
477
final vm = await vmService.getVM ();
463
478
final isolateId = vm.isolates! .first.id;
479
+ final summaryOnly = request.arguments? ['summaryOnly' ] as bool ? ?? false ;
464
480
try {
465
481
final result = await vmService.callServiceExtension (
466
482
'$_inspectorServiceExtensionPrefix .getRootWidgetTree' ,
467
483
isolateId: isolateId,
468
484
args: {
469
485
'groupName' : inspectorObjectGroup,
470
- // TODO: consider making these configurable or using defaults that
471
- // are better for the LLM.
472
- 'isSummaryTree' : 'true' ,
486
+ 'isSummaryTree' : summaryOnly ? 'true' : 'false' ,
473
487
'withPreviews' : 'true' ,
474
488
'fullDetails' : 'false' ,
475
489
},
@@ -647,19 +661,19 @@ base mixin DartToolingDaemonSupport
647
661
inputSchema: Schema .object (
648
662
additionalProperties: true ,
649
663
description:
650
- 'The flutter driver command to run. Command arguments should be '
651
- 'passed as additional properties to this map. \n\n When searching for '
652
- 'widgets, you should first inspect the widget tree in order to '
653
- 'figure out how to find the widget instead of just guessing tooltip '
654
- 'text or other things .' ,
664
+ 'Command arguments are passed as additional properties to this map. '
665
+ 'To specify a widgets, you should first use the '
666
+ '"${ getWidgetTreeTool . name }" tool to inspect the widget tree for the '
667
+ 'value id of the widget and then use the "ByValueKey" finder type '
668
+ 'with that id .' ,
655
669
properties: {
656
670
'command' : Schema .string (
657
671
// Commented out values are flutter_driver commands that are not
658
672
// supported, but may be in the future.
659
673
enumValues: [
660
674
'get_health' ,
661
- 'get_layer_tree' ,
662
- 'get_render_tree' ,
675
+ // 'get_layer_tree',
676
+ // 'get_render_tree',
663
677
'enter_text' ,
664
678
'send_text_input_action' ,
665
679
'get_text' ,
@@ -680,39 +694,40 @@ base mixin DartToolingDaemonSupport
680
694
// 'get_semantics_id',
681
695
'get_offset' ,
682
696
'get_diagnostics_tree' ,
683
- // 'screenshot',
697
+ 'screenshot' ,
684
698
],
685
699
description: 'The name of the driver command' ,
686
700
),
687
- 'alignment' : Schema .num (
701
+ 'alignment' : Schema .string (
688
702
description:
689
- 'How the widget should be aligned. '
690
- 'Required for the scrollIntoView command ' ,
703
+ 'Required for the scrollIntoView command, how the widget should '
704
+ 'be aligned ' ,
691
705
),
692
- 'duration' : Schema .int (
706
+ 'duration' : Schema .string (
693
707
description:
694
- 'The duration of the scrolling action in microseconds. '
695
- 'Required for the scroll command ' ,
708
+ 'Required for the scroll command, the duration of the '
709
+ 'scrolling action in microseconds as a stringified integer. ' ,
696
710
),
697
- 'dx' : Schema .int (
711
+ 'dx' : Schema .string (
698
712
description:
699
- 'Delta X offset for move event. Required for the scroll command' ,
713
+ 'Required for the scroll command, the delta X offset for move '
714
+ 'event as a stringified double' ,
700
715
),
701
- 'dy' : Schema .int (
716
+ 'dy' : Schema .string (
702
717
description:
703
- 'Delta Y offset for move event. Required for the scroll command' ,
718
+ 'Required for the scroll command, the delta Y offset for move '
719
+ 'event as a stringified double' ,
704
720
),
705
- 'frequency' : Schema .int (
721
+ 'frequency' : Schema .string (
706
722
description:
707
- 'The frequency in Hz of the generated move events. '
708
- 'Required for the scroll command ' ,
723
+ 'Required for the scroll command, the frequency in Hz of the '
724
+ 'generated move events as a stringified integer ' ,
709
725
),
710
726
'finderType' : Schema .string (
711
727
description:
712
- 'The kind of finder to use, if required for the command. '
713
728
'Required for get_text, scroll, scroll_into_view, tap, waitFor, '
714
729
'waitForAbsent, waitForTappable, get_offset, and '
715
- 'get_diagnostics_tree' ,
730
+ 'get_diagnostics_tree. The kind of finder to use. ' ,
716
731
enumValues: [
717
732
'ByType' ,
718
733
'ByValueKey' ,
@@ -733,10 +748,11 @@ base mixin DartToolingDaemonSupport
733
748
description:
734
749
'Required for the ByValueKey finder, the type of the key' ,
735
750
),
736
- 'isRegExp' : Schema .bool (
751
+ 'isRegExp' : Schema .string (
737
752
description:
738
753
'Used by the BySemanticsLabel finder, indicates whether '
739
754
'the value should be treated as a regex' ,
755
+ enumValues: ['true' , 'false' ],
740
756
),
741
757
'label' : Schema .string (
742
758
description:
@@ -745,8 +761,8 @@ base mixin DartToolingDaemonSupport
745
761
),
746
762
'text' : Schema .string (
747
763
description:
748
- 'The relevant text for the command. Required for the ByText and '
749
- 'ByTooltipMessage finders, as well as the enter_text command.' ,
764
+ 'Required for the ByText and ByTooltipMessage finders, as well '
765
+ 'as the enter_text command. The relevant text for the command ' ,
750
766
),
751
767
'type' : Schema .string (
752
768
description:
@@ -807,9 +823,7 @@ base mixin DartToolingDaemonSupport
807
823
'complete. Defaults to $_defaultTimeoutMs .' ,
808
824
),
809
825
'offsetType' : Schema .string (
810
- description:
811
- 'Offset types that can be requested by get_offset. '
812
- 'Required for get_offset.' ,
826
+ description: 'Required for get_offset, the offset type to get' ,
813
827
enumValues: [
814
828
'topLeft' ,
815
829
'topRight' ,
@@ -820,22 +834,26 @@ base mixin DartToolingDaemonSupport
820
834
),
821
835
'diagnosticsType' : Schema .string (
822
836
description:
823
- 'The type of diagnostics tree to request. '
824
- 'Required for get_diagnostics_tree ' ,
837
+ 'Required for get_diagnostics_tree, the type of diagnostics tree '
838
+ 'to request ' ,
825
839
enumValues: ['renderObject' , 'widget' ],
826
840
),
827
- 'subtreeDepth' : Schema .int (
841
+ 'subtreeDepth' : Schema .string (
828
842
description:
829
- 'How many levels of children to include in the result. '
830
- 'Required for get_diagnostics_tree ' ,
843
+ 'Required for get_diagnostics_tree, how many levels of children '
844
+ 'to include in the result, as a stringified integer ' ,
831
845
),
832
- 'includeProperties' : Schema .bool (
846
+ 'includeProperties' : Schema .string (
833
847
description:
834
848
'Whether the properties of a diagnostics node should be included '
835
849
'in get_diagnostics_tree results' ,
850
+ enumValues: const ['true' , 'false' ],
836
851
),
837
- 'enabled' : Schema .bool (
838
- description: 'Used by set_text_entry_emulation, defaults to false' ,
852
+ 'enabled' : Schema .string (
853
+ description:
854
+ 'Used by set_text_entry_emulation, defaults to '
855
+ 'false' ,
856
+ enumValues: const ['true' , 'false' ],
839
857
),
840
858
},
841
859
required : ['command' ],
@@ -920,7 +938,15 @@ base mixin DartToolingDaemonSupport
920
938
'Retrieves the widget tree from the active Flutter application. '
921
939
'Requires "${connectTool .name }" to be successfully called first.' ,
922
940
annotations: ToolAnnotations (title: 'Get widget tree' , readOnlyHint: true ),
923
- inputSchema: Schema .object (),
941
+ inputSchema: Schema .object (
942
+ properties: {
943
+ 'summaryOnly' : Schema .bool (
944
+ description:
945
+ 'Defaults to false. If true, only widgets created by user code '
946
+ 'are returned.' ,
947
+ ),
948
+ },
949
+ ),
924
950
);
925
951
926
952
@visibleForTesting
0 commit comments