-
Notifications
You must be signed in to change notification settings - Fork 0
Add interactive file read option to fulfill variables #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -159,24 +159,27 @@ def validate_string(value): | |||||
|
|
||||||
| async def collect_var_value_interactive(self, var_name: str) -> str: | ||||||
| """ | ||||||
| Interactive variable collection - user chooses between direct value or MCP tool. | ||||||
| Interactive variable collection - user chooses between direct value, MCP tool, or file. | ||||||
|
|
||||||
| :param var_name: Name of the variable to collect | ||||||
| :return: String value for the variable | ||||||
| """ | ||||||
| # Ask user to choose between direct value or MCP tool | ||||||
| # Ask user to choose between direct value, MCP tool, or file | ||||||
| choice = await questionary.select( | ||||||
| f"How would you like to provide the value for '{var_name}'?", | ||||||
| choices=[ | ||||||
| questionary.Choice("Provide value directly", "direct"), | ||||||
| questionary.Choice("Use MCP tool to fetch value", "mcp"), | ||||||
| questionary.Choice("Read from file", "file"), | ||||||
| ], | ||||||
| ).ask_async() | ||||||
|
|
||||||
| if choice == "direct": | ||||||
| return await self.collect_var_value(var_name) | ||||||
| elif choice == "mcp": | ||||||
| return await self._collect_var_value_from_mcp(var_name) | ||||||
| elif choice == "file": | ||||||
| return await self._collect_var_value_from_file(var_name) | ||||||
| else: | ||||||
| raise ValueError("Invalid choice") | ||||||
|
|
||||||
|
|
@@ -245,6 +248,45 @@ async def _collect_var_value_from_mcp(self, var_name: str) -> str: | |||||
| logging.info(f"Tool result for '{var_name}': {content}") | ||||||
| return content | ||||||
|
|
||||||
| async def _collect_var_value_from_file(self, var_name: str) -> str: | ||||||
| """ | ||||||
| Collect variable value by reading from a file. | ||||||
|
|
||||||
| :param var_name: Name of the variable to collect | ||||||
| :return: String content of the selected file | ||||||
| """ | ||||||
| import os | ||||||
|
|
||||||
| # Use questionary.path to select a file | ||||||
| file_path = await questionary.path( | ||||||
| f"Select a file for variable '{var_name}':", | ||||||
| default="./", | ||||||
| only_directories=False, | ||||||
| ).ask_async() | ||||||
|
|
||||||
| if not file_path: | ||||||
| raise ValueError("No file selected") | ||||||
|
|
||||||
| # Ensure the path exists and is a file | ||||||
| if not os.path.exists(file_path): | ||||||
| raise ValueError(f"File does not exist: {file_path}") | ||||||
|
|
||||||
| if not os.path.isfile(file_path): | ||||||
| raise ValueError(f"Path is not a file: {file_path}") | ||||||
|
|
||||||
| try: | ||||||
| # Try to read the file as UTF-8 | ||||||
| with open(file_path, encoding='utf-8') as f: | ||||||
|
||||||
| with open(file_path, encoding='utf-8') as f: | |
| with open(file_path, 'r', encoding='utf-8') as f: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statement should be moved to the top of the file with other imports rather than inside the function. This follows Python import conventions and improves code organization.