janito 3.2.0__py3-none-any.whl → 3.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- janito/README.md +0 -3
- janito/cli/chat_mode/bindings.py +0 -26
- janito/cli/chat_mode/session.py +1 -12
- janito/cli/chat_mode/shell/commands/security/allowed_sites.py +33 -47
- janito/cli/cli_commands/list_plugins.py +43 -52
- janito/cli/core/getters.py +0 -3
- janito/cli/core/model_guesser.py +24 -40
- janito/cli/main_cli.py +12 -9
- janito/cli/prompt_core.py +9 -20
- janito/drivers/openai/driver.py +0 -1
- janito/drivers/zai/driver.py +0 -1
- janito/hello.txt +0 -0
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +16 -32
- janito/llm/auth_utils.py +5 -14
- janito/llm/driver.py +0 -8
- janito/plugins/__init__.py +12 -31
- janito/plugins/auto_loader.py +11 -12
- janito/plugins/auto_loader_fixed.py +11 -12
- janito/{plugin_system → plugins}/base.py +2 -5
- janito/plugins/builtin.py +1 -15
- janito/plugins/core_adapter.py +11 -89
- janito/plugins/core_loader.py +120 -0
- janito/plugins/core_loader_fixed.py +125 -0
- janito/plugins/discovery.py +5 -5
- janito/plugins/discovery_core.py +9 -14
- janito/plugins/manager.py +1 -1
- janito/providers/__init__.py +0 -1
- janito/tools/__init__.py +7 -31
- janito/tools/adapters/__init__.py +1 -6
- janito/tools/adapters/local/__init__.py +70 -7
- janito/{plugins/tools → tools/adapters/local}/ask_user.py +3 -3
- janito/{plugins/tools → tools/adapters/local}/create_file.py +6 -6
- janito/{plugins/tools → tools/adapters/local}/fetch_url.py +3 -3
- janito/{plugins/tools → tools/adapters/local}/replace_text_in_file.py +4 -4
- janito/{plugins/tools → tools/adapters/local}/show_image.py +6 -15
- janito/{plugins/core/imagedisplay/tools → tools/adapters/local}/show_image_grid.py +5 -13
- janito/tools/function_adapter.py +65 -0
- janito/tools/loop_protection_decorator.py +117 -114
- {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/METADATA +2 -1
- {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/RECORD +85 -156
- janito/cli/cli_commands/check_tools.py +0 -212
- janito/llm/cancellation_manager.py +0 -63
- janito/llm/enter_cancellation.py +0 -107
- janito/plugin_system/__init__.py +0 -10
- janito/plugin_system/core_loader.py +0 -217
- janito/plugin_system/core_loader_fixed.py +0 -225
- janito/plugins/core/__init__.py +0 -7
- janito/plugins/core/codeanalyzer/__init__.py +0 -43
- janito/plugins/core/filemanager/__init__.py +0 -124
- janito/plugins/core/filemanager/tools/create_file.py +0 -87
- janito/plugins/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins/core/imagedisplay/__init__.py +0 -14
- janito/plugins/core/imagedisplay/plugin.py +0 -51
- janito/plugins/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins/core/system/__init__.py +0 -23
- janito/plugins/dev/__init__.py +0 -7
- janito/plugins/dev/pythondev/__init__.py +0 -37
- janito/plugins/dev/visualization/__init__.py +0 -23
- janito/plugins/example_plugin.py +0 -108
- janito/plugins/tools/__init__.py +0 -10
- janito/plugins/tools/copy_file.py +0 -87
- janito/plugins/tools/core_tools_plugin.py +0 -87
- janito/plugins/tools/create_directory.py +0 -70
- janito/plugins/tools/decorators.py +0 -19
- janito/plugins/tools/delete_text_in_file.py +0 -134
- janito/plugins/tools/find_files.py +0 -143
- janito/plugins/tools/get_file_outline/__init__.py +0 -7
- janito/plugins/tools/get_file_outline/core.py +0 -122
- janito/plugins/tools/get_file_outline/java_outline.py +0 -47
- janito/plugins/tools/get_file_outline/markdown_outline.py +0 -14
- janito/plugins/tools/get_file_outline/python_outline.py +0 -303
- janito/plugins/tools/get_file_outline/search_outline.py +0 -36
- janito/plugins/tools/move_file.py +0 -131
- janito/plugins/tools/open_html_in_browser.py +0 -51
- janito/plugins/tools/open_url.py +0 -37
- janito/plugins/tools/python_code_run.py +0 -172
- janito/plugins/tools/python_command_run.py +0 -171
- janito/plugins/tools/python_file_run.py +0 -172
- janito/plugins/tools/read_chart.py +0 -259
- janito/plugins/tools/read_files.py +0 -58
- janito/plugins/tools/remove_directory.py +0 -55
- janito/plugins/tools/remove_file.py +0 -58
- janito/plugins/tools/run_bash_command.py +0 -183
- janito/plugins/tools/run_powershell_command.py +0 -218
- janito/plugins/tools/search_text/__init__.py +0 -7
- janito/plugins/tools/search_text/core.py +0 -205
- janito/plugins/tools/search_text/match_lines.py +0 -67
- janito/plugins/tools/search_text/pattern_utils.py +0 -73
- janito/plugins/tools/search_text/traverse_directory.py +0 -145
- janito/plugins/tools/show_image_grid.py +0 -85
- janito/plugins/tools/validate_file_syntax/__init__.py +0 -7
- janito/plugins/tools/validate_file_syntax/core.py +0 -114
- janito/plugins/tools/validate_file_syntax/css_validator.py +0 -35
- janito/plugins/tools/validate_file_syntax/html_validator.py +0 -100
- janito/plugins/tools/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins/tools/validate_file_syntax/js_validator.py +0 -27
- janito/plugins/tools/validate_file_syntax/json_validator.py +0 -6
- janito/plugins/tools/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins/tools/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins/tools/validate_file_syntax/python_validator.py +0 -5
- janito/plugins/tools/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins/tools/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins/tools/view_file.py +0 -172
- janito/plugins/ui/__init__.py +0 -7
- janito/plugins/ui/userinterface/__init__.py +0 -16
- janito/plugins/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins/web/__init__.py +0 -7
- janito/plugins/web/webtools/__init__.py +0 -33
- janito/plugins/web/webtools/tools/fetch_url.py +0 -458
- janito/providers/together/__init__.py +0 -1
- janito/providers/together/model_info.py +0 -69
- janito/providers/together/provider.py +0 -108
- janito/tools/cli_initializer.py +0 -88
- janito/tools/initialize.py +0 -70
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/copy_file.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/create_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/delete_text_in_file.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/find_files.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/java_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/python_outline.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/get_file_outline/search_outline.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/move_file.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_html_in_browser.py +0 -0
- /janito/{plugins/web/webtools/tools → tools/adapters/local}/open_url.py +0 -0
- /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_code_run.py +0 -0
- /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_command_run.py +0 -0
- /janito/{plugins/dev/pythondev/tools → tools/adapters/local}/python_file_run.py +0 -0
- /janito/{plugins/dev/visualization/tools → tools/adapters/local}/read_chart.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/read_files.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/remove_file.py +0 -0
- /janito/{plugins/core/system/tools → tools/adapters/local}/run_bash_command.py +0 -0
- /janito/{plugins/core/system/tools → tools/adapters/local}/run_powershell_command.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/__init__.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/core.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/match_lines.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/pattern_utils.py +0 -0
- /janito/{plugins/core/codeanalyzer/tools → tools/adapters/local}/search_text/traverse_directory.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/core.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/validate_file_syntax/yaml_validator.py +0 -0
- /janito/{plugins/core/filemanager/tools → tools/adapters/local}/view_file.py +0 -0
- {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/WHEEL +0 -0
- {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/entry_points.txt +0 -0
- {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.2.0.dist-info → janito-3.4.0.dist-info}/top_level.txt +0 -0
@@ -1,32 +0,0 @@
|
|
1
|
-
from janito.i18n import tr
|
2
|
-
import re
|
3
|
-
|
4
|
-
|
5
|
-
def validate_ps1(path: str) -> str:
|
6
|
-
with open(path, "r", encoding="utf-8") as f:
|
7
|
-
content = f.read()
|
8
|
-
errors = []
|
9
|
-
# Unmatched curly braces
|
10
|
-
if content.count("{") != content.count("}"):
|
11
|
-
errors.append("Unmatched curly braces { }")
|
12
|
-
# Unmatched parentheses
|
13
|
-
if content.count("(") != content.count(")"):
|
14
|
-
errors.append("Unmatched parentheses ( )")
|
15
|
-
# Unmatched brackets
|
16
|
-
if content.count("[") != content.count("]"):
|
17
|
-
errors.append("Unmatched brackets [ ]")
|
18
|
-
# Unclosed string literals
|
19
|
-
for quote in ["'", '"']:
|
20
|
-
unescaped = re.findall(rf"(?<!\\){quote}", content)
|
21
|
-
if len(unescaped) % 2 != 0:
|
22
|
-
errors.append(f"Unclosed string literal ({quote}) detected")
|
23
|
-
# Unclosed block comments <# ... #>
|
24
|
-
if content.count("<#") != content.count("#>"):
|
25
|
-
errors.append("Unclosed block comment (<# ... #>)")
|
26
|
-
if errors:
|
27
|
-
msg = tr(
|
28
|
-
"⚠️ Warning: PowerShell syntax issues found:\n{errors}",
|
29
|
-
errors="\n".join(errors),
|
30
|
-
)
|
31
|
-
return msg
|
32
|
-
return "✅ OK"
|
@@ -1,172 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.report_events import ReportAction
|
3
|
-
from janito.plugins.tools.decorators import register_core_tool
|
4
|
-
from janito.tools.tool_utils import pluralize
|
5
|
-
from janito.i18n import tr
|
6
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
7
|
-
|
8
|
-
|
9
|
-
@register_core_tool
|
10
|
-
class ViewFile(ToolBase):
|
11
|
-
"""
|
12
|
-
Read lines from a file. You can specify a line range, or read the entire file by simply omitting the from_line and to_line parameters.
|
13
|
-
|
14
|
-
Args:
|
15
|
-
path (str): Path to the file to read lines from.
|
16
|
-
from_line (int, optional): Starting line number (1-based). Omit to start from the first line.
|
17
|
-
to_line (int, optional): Ending line number (1-based). Omit to read to the end of the file.
|
18
|
-
|
19
|
-
To read the full file, just provide path and leave from_line and to_line unset.
|
20
|
-
|
21
|
-
Returns:
|
22
|
-
str: File content with a header indicating the file name and line range. Example:
|
23
|
-
- "---\nFile: /path/to/file.py | Lines: 1-10 (of 100)\n---\n<lines...>"
|
24
|
-
- "---\nFile: /path/to/file.py | All lines (total: 100 (all))\n---\n<all lines...>"
|
25
|
-
- "Error reading file: <error message>"
|
26
|
-
- "❗ not found"
|
27
|
-
"""
|
28
|
-
|
29
|
-
permissions = ToolPermissions(read=True)
|
30
|
-
tool_name = "view_file"
|
31
|
-
|
32
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="path")
|
33
|
-
def run(self, path: str, from_line: int = None, to_line: int = None) -> str:
|
34
|
-
import os
|
35
|
-
from janito.tools.tool_utils import display_path
|
36
|
-
from janito.tools.path_utils import expand_path
|
37
|
-
|
38
|
-
path = expand_path(path)
|
39
|
-
disp_path = display_path(path)
|
40
|
-
self.report_action(
|
41
|
-
tr("📖 View '{disp_path}'", disp_path=disp_path),
|
42
|
-
ReportAction.READ,
|
43
|
-
)
|
44
|
-
try:
|
45
|
-
if os.path.isdir(path):
|
46
|
-
return self._list_directory(path, disp_path)
|
47
|
-
lines = self._read_file_lines(path)
|
48
|
-
selected, selected_len, total_lines = self._select_lines(
|
49
|
-
lines, from_line, to_line
|
50
|
-
)
|
51
|
-
self._report_success(selected_len, from_line, to_line, total_lines)
|
52
|
-
header = self._format_header(
|
53
|
-
disp_path, from_line, to_line, selected_len, total_lines
|
54
|
-
)
|
55
|
-
return header + "".join(selected)
|
56
|
-
except FileNotFoundError as e:
|
57
|
-
self.report_warning(tr("❗ not found"))
|
58
|
-
return f"Error reading file: {e}"
|
59
|
-
except Exception as e:
|
60
|
-
self.report_error(tr(" ❌ Error: {error}", error=e))
|
61
|
-
return tr("Error reading file: {error}", error=e)
|
62
|
-
|
63
|
-
def _list_directory(self, path, disp_path):
|
64
|
-
import os
|
65
|
-
|
66
|
-
try:
|
67
|
-
entries = os.listdir(path)
|
68
|
-
entries.sort()
|
69
|
-
# Suffix subdirectories with '/'
|
70
|
-
formatted_entries = []
|
71
|
-
for entry in entries:
|
72
|
-
full_path = os.path.join(path, entry)
|
73
|
-
if os.path.isdir(full_path):
|
74
|
-
formatted_entries.append(entry + "/")
|
75
|
-
else:
|
76
|
-
formatted_entries.append(entry)
|
77
|
-
header = (
|
78
|
-
f"--- view_file: {disp_path} [directory, {len(entries)} entries] ---\n"
|
79
|
-
)
|
80
|
-
listing = "\n".join(formatted_entries)
|
81
|
-
self.report_success(tr("📁 Directory ({count} items)", count=len(entries)))
|
82
|
-
return header + listing + "\n"
|
83
|
-
except Exception as e:
|
84
|
-
self.report_error(tr(" ❌ Error listing directory: {error}", error=e))
|
85
|
-
return tr("Error listing directory: {error}", error=e)
|
86
|
-
|
87
|
-
def _read_file_lines(self, path):
|
88
|
-
"""Read all lines from the file."""
|
89
|
-
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
90
|
-
return f.readlines()
|
91
|
-
|
92
|
-
def _select_lines(self, lines, from_line, to_line):
|
93
|
-
"""Select the requested lines and return them with their count and total lines."""
|
94
|
-
selected = lines[
|
95
|
-
(from_line - 1 if from_line else 0) : (to_line if to_line else None)
|
96
|
-
]
|
97
|
-
selected_len = len(selected)
|
98
|
-
total_lines = len(lines)
|
99
|
-
return selected, selected_len, total_lines
|
100
|
-
|
101
|
-
def _report_success(self, selected_len, from_line, to_line, total_lines):
|
102
|
-
"""Report the success message after reading lines."""
|
103
|
-
if from_line and to_line:
|
104
|
-
requested = to_line - from_line + 1
|
105
|
-
at_end = to_line >= total_lines or selected_len < requested
|
106
|
-
if at_end:
|
107
|
-
self.report_success(
|
108
|
-
tr(
|
109
|
-
" ✅ {selected_len} {line_word} (end)",
|
110
|
-
selected_len=selected_len,
|
111
|
-
line_word=pluralize("line", selected_len),
|
112
|
-
)
|
113
|
-
)
|
114
|
-
elif to_line < total_lines:
|
115
|
-
self.report_success(
|
116
|
-
tr(
|
117
|
-
" ✅ {selected_len} {line_word} ({remaining} to end)",
|
118
|
-
selected_len=selected_len,
|
119
|
-
line_word=pluralize("line", selected_len),
|
120
|
-
remaining=total_lines - to_line,
|
121
|
-
)
|
122
|
-
)
|
123
|
-
else:
|
124
|
-
self.report_success(
|
125
|
-
tr(
|
126
|
-
" ✅ {selected_len} {line_word} (all)",
|
127
|
-
selected_len=selected_len,
|
128
|
-
line_word=pluralize("line", selected_len),
|
129
|
-
)
|
130
|
-
)
|
131
|
-
|
132
|
-
def _format_header(self, disp_path, from_line, to_line, selected_len, total_lines):
|
133
|
-
"""Format the header for the output."""
|
134
|
-
if from_line and to_line:
|
135
|
-
requested = to_line - from_line + 1
|
136
|
-
at_end = selected_len < requested or to_line >= total_lines
|
137
|
-
if at_end:
|
138
|
-
return tr(
|
139
|
-
"---\n{disp_path} {from_line}-{to_line} (end)\n---\n",
|
140
|
-
disp_path=disp_path,
|
141
|
-
from_line=from_line,
|
142
|
-
to_line=to_line,
|
143
|
-
)
|
144
|
-
else:
|
145
|
-
return tr(
|
146
|
-
"---\n{disp_path} {from_line}-{to_line} (of {total_lines})\n---\n",
|
147
|
-
disp_path=disp_path,
|
148
|
-
from_line=from_line,
|
149
|
-
to_line=to_line,
|
150
|
-
total_lines=total_lines,
|
151
|
-
)
|
152
|
-
elif from_line:
|
153
|
-
return tr(
|
154
|
-
"---\n{disp_path} {from_line}-END (of {total_lines})\n---\n",
|
155
|
-
disp_path=disp_path,
|
156
|
-
from_line=from_line,
|
157
|
-
total_lines=total_lines,
|
158
|
-
)
|
159
|
-
else:
|
160
|
-
return tr(
|
161
|
-
"---\n{disp_path} All lines (total: {total_lines} (all))\n---\n",
|
162
|
-
disp_path=disp_path,
|
163
|
-
total_lines=total_lines,
|
164
|
-
)
|
165
|
-
|
166
|
-
def _handle_read_error(self, e):
|
167
|
-
"""Handle file read errors and report appropriately."""
|
168
|
-
if isinstance(e, FileNotFoundError):
|
169
|
-
self.report_error(tr("❗ not found"), ReportAction.READ)
|
170
|
-
return tr("❗ not found")
|
171
|
-
self.report_error(tr(" ❌ Error: {error}", error=e), ReportAction.READ)
|
172
|
-
return tr("Error reading file: {error}", error=e)
|
janito/plugins/ui/__init__.py
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
User Interface Plugin
|
3
|
-
|
4
|
-
User interaction and input tools.
|
5
|
-
"""
|
6
|
-
|
7
|
-
|
8
|
-
def ask_user(question: str) -> str:
|
9
|
-
"""Prompt user for input/clarification"""
|
10
|
-
return f"ask_user(question='{question}')"
|
11
|
-
|
12
|
-
|
13
|
-
# Plugin metadata
|
14
|
-
__plugin_name__ = "ui.userinterface"
|
15
|
-
__plugin_description__ = "User interaction and input"
|
16
|
-
__plugin_tools__ = [ask_user]
|
@@ -1,110 +0,0 @@
|
|
1
|
-
from janito.tools.tool_base import ToolBase, ToolPermissions
|
2
|
-
from janito.tools.adapters.local.adapter import register_local_tool
|
3
|
-
from janito.tools.loop_protection_decorator import protect_against_loops
|
4
|
-
|
5
|
-
from rich import print as rich_print
|
6
|
-
from janito.i18n import tr
|
7
|
-
from rich.panel import Panel
|
8
|
-
from prompt_toolkit import PromptSession
|
9
|
-
from prompt_toolkit.key_binding import KeyBindings
|
10
|
-
from prompt_toolkit.enums import EditingMode
|
11
|
-
from prompt_toolkit.formatted_text import HTML
|
12
|
-
from janito.cli.chat_mode.prompt_style import chat_shell_style
|
13
|
-
from prompt_toolkit.styles import Style
|
14
|
-
|
15
|
-
toolbar_style = Style.from_dict({"bottom-toolbar": "fg:yellow bg:darkred"})
|
16
|
-
|
17
|
-
|
18
|
-
@register_local_tool
|
19
|
-
class AskUserTool(ToolBase):
|
20
|
-
"""
|
21
|
-
Prompts the user for clarification or input with a question.
|
22
|
-
|
23
|
-
Args:
|
24
|
-
question (str): The question to ask the user. This parameter is required and should be a string containing the prompt or question to display to the user.
|
25
|
-
Returns:
|
26
|
-
str: The user's response as a string. Example:
|
27
|
-
- "Yes"
|
28
|
-
- "No"
|
29
|
-
- "Some detailed answer..."
|
30
|
-
"""
|
31
|
-
|
32
|
-
permissions = ToolPermissions(read=True)
|
33
|
-
tool_name = "ask_user"
|
34
|
-
|
35
|
-
@protect_against_loops(max_calls=5, time_window=10.0, key_field="question")
|
36
|
-
def run(self, question: str) -> str:
|
37
|
-
|
38
|
-
print() # Print an empty line before the question panel
|
39
|
-
rich_print(Panel.fit(question, title=tr("Question"), style="cyan"))
|
40
|
-
|
41
|
-
bindings = KeyBindings()
|
42
|
-
mode = {"multiline": False}
|
43
|
-
|
44
|
-
@bindings.add("c-r")
|
45
|
-
def _(event):
|
46
|
-
pass
|
47
|
-
|
48
|
-
@bindings.add("f12")
|
49
|
-
def _(event):
|
50
|
-
buf = event.app.current_buffer
|
51
|
-
buf.text = "Do It"
|
52
|
-
buf.validate_and_handle()
|
53
|
-
|
54
|
-
@bindings.add("f2")
|
55
|
-
def _(event):
|
56
|
-
buf = event.app.current_buffer
|
57
|
-
buf.text = "F2"
|
58
|
-
buf.validate_and_handle()
|
59
|
-
|
60
|
-
# Use shared CLI styles
|
61
|
-
|
62
|
-
# prompt_style contains the prompt area and input background
|
63
|
-
# toolbar_style contains the bottom-toolbar styling
|
64
|
-
|
65
|
-
# Use the shared chat_shell_style for input styling only
|
66
|
-
style = chat_shell_style
|
67
|
-
|
68
|
-
def get_toolbar():
|
69
|
-
f12_hint = " F2: F2 | F12: Do It"
|
70
|
-
if mode["multiline"]:
|
71
|
-
return HTML(
|
72
|
-
f"<b>Multiline mode (Esc+Enter to submit). Type /single to switch.</b>{f12_hint}"
|
73
|
-
)
|
74
|
-
else:
|
75
|
-
return HTML(
|
76
|
-
f"<b>Single-line mode (Enter to submit). Type /multi for multiline.</b>{f12_hint}"
|
77
|
-
)
|
78
|
-
|
79
|
-
session = PromptSession(
|
80
|
-
multiline=False,
|
81
|
-
key_bindings=bindings,
|
82
|
-
editing_mode=EditingMode.EMACS,
|
83
|
-
bottom_toolbar=get_toolbar,
|
84
|
-
style=style,
|
85
|
-
)
|
86
|
-
|
87
|
-
prompt_icon = HTML("<inputline>💬 </inputline>")
|
88
|
-
|
89
|
-
while True:
|
90
|
-
response = session.prompt(prompt_icon)
|
91
|
-
if not mode["multiline"] and response.strip() == "/multi":
|
92
|
-
mode["multiline"] = True
|
93
|
-
session.multiline = True
|
94
|
-
continue
|
95
|
-
elif mode["multiline"] and response.strip() == "/single":
|
96
|
-
mode["multiline"] = False
|
97
|
-
session.multiline = False
|
98
|
-
continue
|
99
|
-
else:
|
100
|
-
sanitized = response.strip()
|
101
|
-
try:
|
102
|
-
sanitized.encode("utf-8")
|
103
|
-
except UnicodeEncodeError:
|
104
|
-
sanitized = sanitized.encode("utf-8", errors="replace").decode(
|
105
|
-
"utf-8"
|
106
|
-
)
|
107
|
-
rich_print(
|
108
|
-
"[yellow]Warning: Some characters in your input were not valid UTF-8 and have been replaced.[/yellow]"
|
109
|
-
)
|
110
|
-
return sanitized
|
janito/plugins/web/__init__.py
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Web Tools Plugin
|
3
|
-
|
4
|
-
Web scraping, browsing, and URL operations.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Optional, Dict, List
|
8
|
-
|
9
|
-
|
10
|
-
def fetch_url(
|
11
|
-
url: str,
|
12
|
-
search_strings: Optional[List[str]] = None,
|
13
|
-
max_length: int = 5000,
|
14
|
-
timeout: int = 10,
|
15
|
-
) -> str:
|
16
|
-
"""Download web pages with advanced options"""
|
17
|
-
return f"fetch_url(url='{url}', search={len(search_strings or [])} terms)"
|
18
|
-
|
19
|
-
|
20
|
-
def open_url(url: str) -> str:
|
21
|
-
"""Open URLs in default browser"""
|
22
|
-
return f"open_url(url='{url}')"
|
23
|
-
|
24
|
-
|
25
|
-
def open_html_in_browser(path: str) -> str:
|
26
|
-
"""Open local HTML files in browser"""
|
27
|
-
return f"open_html_in_browser(path='{path}')"
|
28
|
-
|
29
|
-
|
30
|
-
# Plugin metadata
|
31
|
-
__plugin_name__ = "web.webtools"
|
32
|
-
__plugin_description__ = "Web scraping, browsing, and URL operations"
|
33
|
-
__plugin_tools__ = [fetch_url, open_url, open_html_in_browser]
|