|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:async'; |
| 6 | + |
| 7 | +import 'package:dart_mcp/server.dart'; |
| 8 | +import 'package:meta/meta.dart'; |
| 9 | + |
| 10 | +/// A mixin which adds support for various dart and flutter specific prompts. |
| 11 | +base mixin DashPrompts on PromptsSupport { |
| 12 | + @override |
| 13 | + FutureOr<InitializeResult> initialize(InitializeRequest request) { |
| 14 | + addPrompt(flutterDriverUserJourneyTest, _flutterDriverUserJourneyPrompt); |
| 15 | + return super.initialize(request); |
| 16 | + } |
| 17 | + |
| 18 | + /// Creates the flutter driver user journey prompt based on a request. |
| 19 | + GetPromptResult _flutterDriverUserJourneyPrompt(GetPromptRequest request) { |
| 20 | + return GetPromptResult( |
| 21 | + messages: [ |
| 22 | + PromptMessage( |
| 23 | + role: Role.user, |
| 24 | + content: flutterDriverUserJourneyPromptContent, |
| 25 | + ), |
| 26 | + ], |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + @visibleForTesting |
| 31 | + static final flutterDriverUserJourneyTest = Prompt( |
| 32 | + name: 'flutter_driver_user_journey_test', |
| 33 | + title: 'User journey flutter driver test', |
| 34 | + description: ''' |
| 35 | +Prompts the LLM to attempt to accomplish a user journey in the running app using |
| 36 | +flutter driver. If successful, it will then translate the steps it followed into |
| 37 | +a flutter driver test and write that to disk. |
| 38 | +''', |
| 39 | + ); |
| 40 | + |
| 41 | + @visibleForTesting |
| 42 | + static final flutterDriverUserJourneyPromptContent = Content.text( |
| 43 | + text: ''' |
| 44 | +Perform the following tasks in order: |
| 45 | +
|
| 46 | +- Prompt the user to navigate to the home page of the app. |
| 47 | +- Prompt the user for a user journey that they would like to write a test for. |
| 48 | +- Attempt to complete the given user journey using flutter driver to inspect the |
| 49 | + widget tree and interact with the application. Only durable interactions |
| 50 | + should be performed, do not use temporary IDs to select or interact with |
| 51 | + widgets, but instead select them based on text, type, tooltip, etc. Avoid |
| 52 | + reading in files to accomplish this task, just inspect the live state of the |
| 53 | + app and widget tree. If you get stuck, feel free to ask the user for help. |
| 54 | +- If you are able to successfully complete the journey, then create a flutter |
| 55 | + driver based test with an appropriate name, which performs all the same |
| 56 | + actions that you performed. Include the original user journey as a comment |
| 57 | + in the test file. |
| 58 | +''', |
| 59 | + ); |
| 60 | +} |
0 commit comments