janito 3.3.0__py3-none-any.whl → 3.5.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 +3 -0
- janito/cli/chat_mode/bindings.py +50 -0
- janito/cli/chat_mode/session.py +12 -1
- janito/cli/chat_mode/shell/commands/multi.py +5 -0
- janito/cli/chat_mode/shell/commands/security/allowed_sites.py +47 -33
- janito/cli/cli_commands/list_plugins.py +13 -8
- janito/cli/core/model_guesser.py +40 -24
- janito/cli/prompt_core.py +47 -9
- janito/cli/rich_terminal_reporter.py +2 -2
- janito/hello.txt +0 -0
- janito/i18n/it.py +46 -46
- janito/llm/agent.py +32 -16
- janito/llm/cancellation_manager.py +63 -0
- janito/llm/driver.py +8 -0
- janito/llm/enter_cancellation.py +107 -0
- janito/{plugin_system_backup_20250825_070018 → plugin_system}/core_loader.py +76 -3
- janito/{plugin_system_backup_20250825_070018 → plugin_system}/core_loader_fixed.py +79 -3
- janito/plugins/__init__.py +29 -21
- janito/{plugins_backup_20250825_070018 → plugins}/auto_loader.py +12 -11
- janito/plugins/builtin.py +1 -1
- janito/plugins/core/filemanager/tools/copy_file.py +1 -25
- janito/plugins/core/filemanager/tools/create_directory.py +1 -28
- janito/plugins/core/filemanager/tools/create_file.py +3 -27
- janito/plugins/core/filemanager/tools/delete_text_in_file.py +0 -1
- janito/plugins/core/imagedisplay/plugin.py +1 -1
- janito/plugins/core_adapter.py +131 -0
- janito/plugins/discovery.py +3 -3
- janito/{plugins_backup_20250825_070018 → plugins}/discovery_core.py +14 -9
- janito/plugins/example_plugin.py +1 -1
- janito/plugins/manager.py +1 -1
- janito/{plugins_backup_20250825_070018 → plugins}/tools/core_tools_plugin.py +9 -10
- janito/{plugins_backup_20250825_070018 → plugins}/tools/create_file.py +2 -2
- janito/{plugins_backup_20250825_070018 → plugins}/tools/delete_text_in_file.py +0 -1
- janito/providers/__init__.py +1 -0
- janito/providers/together/__init__.py +1 -0
- janito/providers/together/model_info.py +69 -0
- janito/providers/together/provider.py +108 -0
- janito/tools/base.py +1 -31
- janito/tools/cli_initializer.py +1 -1
- janito/tools/initialize.py +1 -1
- janito/tools/loop_protection_decorator.py +114 -117
- janito/tools/tool_base.py +114 -142
- janito/tools/tools_schema.py +6 -12
- janito-3.5.0.dist-info/METADATA +229 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/RECORD +98 -162
- janito/plugins/__main__.py +0 -85
- janito/plugins/base.py +0 -57
- janito/plugins/core_loader.py +0 -144
- janito/plugins_backup_20250825_070018/__init__.py +0 -36
- janito/plugins_backup_20250825_070018/builtin.py +0 -102
- janito/plugins_backup_20250825_070018/config.py +0 -84
- janito/plugins_backup_20250825_070018/core/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/core/codeanalyzer/__init__.py +0 -43
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/get_file_outline/core.py +0 -122
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/codeanalyzer/tools/search_text/core.py +0 -205
- janito/plugins_backup_20250825_070018/core/filemanager/__init__.py +0 -124
- janito/plugins_backup_20250825_070018/core/filemanager/tools/copy_file.py +0 -87
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_directory.py +0 -70
- janito/plugins_backup_20250825_070018/core/filemanager/tools/create_file.py +0 -87
- janito/plugins_backup_20250825_070018/core/filemanager/tools/delete_text_in_file.py +0 -135
- janito/plugins_backup_20250825_070018/core/filemanager/tools/find_files.py +0 -143
- janito/plugins_backup_20250825_070018/core/filemanager/tools/move_file.py +0 -131
- janito/plugins_backup_20250825_070018/core/filemanager/tools/read_files.py +0 -58
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_directory.py +0 -55
- janito/plugins_backup_20250825_070018/core/filemanager/tools/remove_file.py +0 -58
- janito/plugins_backup_20250825_070018/core/filemanager/tools/replace_text_in_file.py +0 -270
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/filemanager/tools/validate_file_syntax/core.py +0 -114
- janito/plugins_backup_20250825_070018/core/filemanager/tools/view_file.py +0 -172
- janito/plugins_backup_20250825_070018/core/imagedisplay/__init__.py +0 -14
- janito/plugins_backup_20250825_070018/core/imagedisplay/plugin.py +0 -51
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/__init__.py +0 -1
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image.py +0 -83
- janito/plugins_backup_20250825_070018/core/imagedisplay/tools/show_image_grid.py +0 -84
- janito/plugins_backup_20250825_070018/core/system/__init__.py +0 -23
- janito/plugins_backup_20250825_070018/core/system/tools/run_bash_command.py +0 -183
- janito/plugins_backup_20250825_070018/core/system/tools/run_powershell_command.py +0 -218
- janito/plugins_backup_20250825_070018/core_adapter.py +0 -55
- janito/plugins_backup_20250825_070018/dev/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/dev/pythondev/__init__.py +0 -37
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_code_run.py +0 -172
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_command_run.py +0 -171
- janito/plugins_backup_20250825_070018/dev/pythondev/tools/python_file_run.py +0 -172
- janito/plugins_backup_20250825_070018/dev/visualization/__init__.py +0 -23
- janito/plugins_backup_20250825_070018/dev/visualization/tools/read_chart.py +0 -259
- janito/plugins_backup_20250825_070018/discovery.py +0 -289
- janito/plugins_backup_20250825_070018/example_plugin.py +0 -108
- janito/plugins_backup_20250825_070018/manager.py +0 -243
- janito/plugins_backup_20250825_070018/tools/get_file_outline/java_outline.py +0 -47
- janito/plugins_backup_20250825_070018/tools/get_file_outline/markdown_outline.py +0 -14
- janito/plugins_backup_20250825_070018/tools/get_file_outline/python_outline.py +0 -303
- janito/plugins_backup_20250825_070018/tools/get_file_outline/search_outline.py +0 -36
- janito/plugins_backup_20250825_070018/tools/search_text/match_lines.py +0 -67
- janito/plugins_backup_20250825_070018/tools/search_text/pattern_utils.py +0 -73
- janito/plugins_backup_20250825_070018/tools/search_text/traverse_directory.py +0 -145
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/css_validator.py +0 -35
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/html_validator.py +0 -100
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/jinja2_validator.py +0 -50
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/js_validator.py +0 -27
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/json_validator.py +0 -6
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/markdown_validator.py +0 -109
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/ps1_validator.py +0 -32
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/python_validator.py +0 -5
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/xml_validator.py +0 -11
- janito/plugins_backup_20250825_070018/tools/validate_file_syntax/yaml_validator.py +0 -6
- janito/plugins_backup_20250825_070018/ui/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/ui/userinterface/__init__.py +0 -16
- janito/plugins_backup_20250825_070018/ui/userinterface/tools/ask_user.py +0 -110
- janito/plugins_backup_20250825_070018/web/__init__.py +0 -7
- janito/plugins_backup_20250825_070018/web/webtools/__init__.py +0 -33
- janito/plugins_backup_20250825_070018/web/webtools/tools/fetch_url.py +0 -458
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_html_in_browser.py +0 -51
- janito/plugins_backup_20250825_070018/web/webtools/tools/open_url.py +0 -37
- janito/tools/function_adapter.py +0 -176
- janito-3.3.0.dist-info/METADATA +0 -83
- /janito/{plugin_system_backup_20250825_070018 → plugin_system}/__init__.py +0 -0
- /janito/{plugin_system_backup_20250825_070018 → plugin_system}/base.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/auto_loader_fixed.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/ask_user.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/copy_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/create_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/decorators.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/fetch_url.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/find_files.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/get_file_outline/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/get_file_outline/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/java_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/markdown_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/python_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/get_file_outline/search_outline.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/move_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/open_html_in_browser.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/open_url.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_code_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_command_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/python_file_run.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/read_chart.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/read_files.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/remove_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/remove_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/replace_text_in_file.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/run_bash_command.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/run_powershell_command.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/search_text/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/search_text/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/match_lines.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/pattern_utils.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/codeanalyzer → plugins}/tools/search_text/traverse_directory.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/show_image.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/show_image_grid.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/validate_file_syntax/__init__.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/validate_file_syntax/core.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/css_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/html_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/jinja2_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/js_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/json_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/markdown_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/ps1_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/python_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/xml_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018/core/filemanager → plugins}/tools/validate_file_syntax/yaml_validator.py +0 -0
- /janito/{plugins_backup_20250825_070018 → plugins}/tools/view_file.py +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/WHEEL +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/entry_points.txt +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/licenses/LICENSE +0 -0
- {janito-3.3.0.dist-info → janito-3.5.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
"""
|
2
|
+
Core plugin adapter for legacy plugin system.
|
3
|
+
|
4
|
+
This module provides proper Plugin class implementations for core plugins
|
5
|
+
that use the function-based approach instead of class-based.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from janito.plugin_system.base import Plugin, PluginMetadata
|
9
|
+
from typing import List, Type
|
10
|
+
from janito.tools.tool_base import ToolBase, ToolPermissions
|
11
|
+
|
12
|
+
|
13
|
+
class CorePluginAdapter(Plugin):
|
14
|
+
"""Adapter for core plugins using function-based tools."""
|
15
|
+
|
16
|
+
def __init__(self, plugin_name: str, description: str, tools_module):
|
17
|
+
super().__init__()
|
18
|
+
self._plugin_name = plugin_name
|
19
|
+
self._description = description
|
20
|
+
self._tools_module = tools_module
|
21
|
+
self._tool_classes = []
|
22
|
+
|
23
|
+
# Set the metadata attribute that Plugin expects
|
24
|
+
self.metadata = self.get_metadata()
|
25
|
+
|
26
|
+
def get_metadata(self) -> PluginMetadata:
|
27
|
+
return PluginMetadata(
|
28
|
+
name=self._plugin_name,
|
29
|
+
version="1.0.0",
|
30
|
+
description=self._description,
|
31
|
+
author="Janito",
|
32
|
+
license="MIT",
|
33
|
+
)
|
34
|
+
|
35
|
+
def get_tools(self) -> List[Type[ToolBase]]:
|
36
|
+
return self._tool_classes
|
37
|
+
|
38
|
+
def _create_tool_class(self, func):
|
39
|
+
"""Create a ToolBase class from a function."""
|
40
|
+
resolved_tool_name = getattr(func, "tool_name", func.__name__)
|
41
|
+
|
42
|
+
# Create a proper tool class with explicit parameters and documentation
|
43
|
+
import inspect
|
44
|
+
from typing import get_type_hints
|
45
|
+
|
46
|
+
func_sig = inspect.signature(func)
|
47
|
+
type_hints = get_type_hints(func)
|
48
|
+
|
49
|
+
# Build parameter definitions for the run method
|
50
|
+
param_defs = []
|
51
|
+
param_docs = []
|
52
|
+
for name, param in func_sig.parameters.items():
|
53
|
+
type_hint = type_hints.get(name, str)
|
54
|
+
if param.default == inspect.Parameter.empty:
|
55
|
+
param_defs.append(f"{name}: {type_hint.__name__}")
|
56
|
+
else:
|
57
|
+
param_defs.append(f"{name}: {type_hint.__name__} = {repr(param.default)}")
|
58
|
+
|
59
|
+
# Add parameter documentation
|
60
|
+
param_docs.append(f" {name}: {type_hint.__name__} - Parameter {name}")
|
61
|
+
|
62
|
+
# Get function docstring or create one
|
63
|
+
func_doc = func.__doc__ or f"Execute {resolved_tool_name} tool"
|
64
|
+
|
65
|
+
# Create the tool class with proper signature and documentation
|
66
|
+
exec_globals = {
|
67
|
+
'ToolBase': ToolBase,
|
68
|
+
'ToolPermissions': ToolPermissions,
|
69
|
+
'func': func,
|
70
|
+
'inspect': inspect,
|
71
|
+
'str': str,
|
72
|
+
'List': list,
|
73
|
+
'Dict': dict,
|
74
|
+
'Optional': type(None),
|
75
|
+
}
|
76
|
+
|
77
|
+
param_docs_str = '\n'.join(param_docs)
|
78
|
+
|
79
|
+
class_def = f'''
|
80
|
+
class DynamicTool(ToolBase):
|
81
|
+
"""
|
82
|
+
{func_doc}
|
83
|
+
|
84
|
+
Parameters:
|
85
|
+
{param_docs_str}
|
86
|
+
|
87
|
+
Returns:
|
88
|
+
str: Execution result
|
89
|
+
"""
|
90
|
+
tool_name = "{resolved_tool_name}"
|
91
|
+
permissions = ToolPermissions(read=True, write=True, execute=True)
|
92
|
+
|
93
|
+
def __init__(self):
|
94
|
+
super().__init__()
|
95
|
+
|
96
|
+
def run(self, {', '.join(param_defs)}) -> str:
|
97
|
+
kwargs = locals()
|
98
|
+
sig = inspect.signature(func)
|
99
|
+
|
100
|
+
# Filter kwargs to only include parameters the function accepts
|
101
|
+
filtered_kwargs = {{}}
|
102
|
+
for name, param in sig.parameters.items():
|
103
|
+
if name in kwargs and kwargs[name] is not None:
|
104
|
+
filtered_kwargs[name] = kwargs[name]
|
105
|
+
|
106
|
+
result = func(**filtered_kwargs)
|
107
|
+
return str(result) if result is not None else ""
|
108
|
+
'''
|
109
|
+
|
110
|
+
exec(class_def, exec_globals)
|
111
|
+
return exec_globals['DynamicTool']
|
112
|
+
|
113
|
+
return DynamicTool
|
114
|
+
|
115
|
+
def initialize(self):
|
116
|
+
"""Initialize the plugin by creating tool classes."""
|
117
|
+
# Get tools from the module
|
118
|
+
tools = getattr(self._tools_module, "__plugin_tools__", [])
|
119
|
+
|
120
|
+
self._tool_classes = []
|
121
|
+
for tool_func in tools:
|
122
|
+
if callable(tool_func):
|
123
|
+
tool_class = self._create_tool_class(tool_func)
|
124
|
+
self._tool_classes.append(tool_class)
|
125
|
+
|
126
|
+
|
127
|
+
def create_core_plugin(
|
128
|
+
plugin_name: str, description: str, tools_module
|
129
|
+
) -> CorePluginAdapter:
|
130
|
+
"""Create a core plugin adapter."""
|
131
|
+
return CorePluginAdapter(plugin_name, description, tools_module)
|
janito/plugins/discovery.py
CHANGED
@@ -31,9 +31,9 @@ from pathlib import Path
|
|
31
31
|
from typing import Optional, List
|
32
32
|
import logging
|
33
33
|
|
34
|
-
from .base import Plugin
|
34
|
+
from janito.plugin_system.base import Plugin
|
35
35
|
from .builtin import load_builtin_plugin, BuiltinPluginRegistry
|
36
|
-
from .core_loader import load_core_plugin
|
36
|
+
from janito.plugin_system.core_loader import load_core_plugin
|
37
37
|
|
38
38
|
logger = logging.getLogger(__name__)
|
39
39
|
|
@@ -157,7 +157,7 @@ def _load_plugin_from_file(
|
|
157
157
|
|
158
158
|
# Check for package-based plugin with __plugin_name__ metadata
|
159
159
|
if hasattr(module, "__plugin_name__"):
|
160
|
-
from .base import PluginMetadata
|
160
|
+
from janito.plugin_system.base import PluginMetadata
|
161
161
|
|
162
162
|
# Create a dynamic plugin class
|
163
163
|
class PackagePlugin(Plugin):
|
@@ -17,11 +17,11 @@ from .core_adapter import CorePluginAdapter
|
|
17
17
|
def _load_core_plugin(package_path: Path, plugin_name: str) -> Optional[Plugin]:
|
18
18
|
"""
|
19
19
|
Load a core plugin from a package directory.
|
20
|
-
|
20
|
+
|
21
21
|
Args:
|
22
22
|
package_path: Path to the __init__.py file
|
23
23
|
plugin_name: Full plugin name (e.g., core.filemanager)
|
24
|
-
|
24
|
+
|
25
25
|
Returns:
|
26
26
|
Plugin instance if loaded successfully
|
27
27
|
"""
|
@@ -30,20 +30,25 @@ def _load_core_plugin(package_path: Path, plugin_name: str) -> Optional[Plugin]:
|
|
30
30
|
spec = importlib.util.spec_from_file_location(plugin_name, package_path)
|
31
31
|
if spec is None or spec.loader is None:
|
32
32
|
return None
|
33
|
-
|
33
|
+
|
34
34
|
module = importlib.util.module_from_spec(spec)
|
35
35
|
spec.loader.exec_module(module)
|
36
|
-
|
36
|
+
|
37
37
|
# Get plugin metadata
|
38
38
|
plugin_name_attr = getattr(module, "__plugin_name__", plugin_name)
|
39
|
-
description = getattr(
|
40
|
-
|
39
|
+
description = getattr(
|
40
|
+
module, "__plugin_description__", f"Core plugin: {plugin_name}"
|
41
|
+
)
|
42
|
+
|
41
43
|
# Create and return the core plugin adapter
|
42
44
|
plugin = CorePluginAdapter(plugin_name_attr, description, module)
|
43
45
|
plugin.initialize() # Initialize to set up tools
|
44
46
|
return plugin
|
45
|
-
|
47
|
+
|
46
48
|
except Exception as e:
|
47
49
|
import logging
|
48
|
-
|
49
|
-
|
50
|
+
|
51
|
+
logging.getLogger(__name__).error(
|
52
|
+
f"Failed to load core plugin {plugin_name}: {e}"
|
53
|
+
)
|
54
|
+
return None
|
janito/plugins/example_plugin.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Example plugin demonstrating the plugin system.
|
3
3
|
"""
|
4
4
|
|
5
|
-
from .base import Plugin, PluginMetadata, PluginResource
|
5
|
+
from janito.plugin_system.base import Plugin, PluginMetadata, PluginResource
|
6
6
|
from janito.tools.tool_base import ToolBase, ToolPermissions
|
7
7
|
from typing import Dict, Any
|
8
8
|
|
janito/plugins/manager.py
CHANGED
@@ -10,7 +10,7 @@ from pathlib import Path
|
|
10
10
|
from typing import Dict, List, Optional, Any
|
11
11
|
import logging
|
12
12
|
|
13
|
-
from .base import Plugin, PluginMetadata
|
13
|
+
from janito.plugin_system.base import Plugin, PluginMetadata
|
14
14
|
from .discovery import discover_plugins
|
15
15
|
from .config import load_plugins_config, get_user_plugins_dir
|
16
16
|
from .builtin import BuiltinPluginRegistry, load_builtin_plugin
|
@@ -6,16 +6,6 @@ from functools import wraps
|
|
6
6
|
from typing import Type
|
7
7
|
from janito.plugin_system.base import Plugin, PluginMetadata
|
8
8
|
|
9
|
-
# Registry for core tools
|
10
|
-
_core_tools_registry = []
|
11
|
-
|
12
|
-
|
13
|
-
def register_core_tool(cls: Type):
|
14
|
-
"""Decorator to register a core tool."""
|
15
|
-
_core_tools_registry.append(cls)
|
16
|
-
return cls
|
17
|
-
|
18
|
-
|
19
9
|
from .ask_user import AskUser
|
20
10
|
from .copy_file import CopyFile
|
21
11
|
from .create_directory import CreateDirectory
|
@@ -44,6 +34,15 @@ from .get_file_outline.core import GetFileOutline
|
|
44
34
|
from .search_text.core import SearchText
|
45
35
|
from .decorators import get_core_tools
|
46
36
|
|
37
|
+
# Registry for core tools
|
38
|
+
_core_tools_registry = []
|
39
|
+
|
40
|
+
|
41
|
+
def register_core_tool(cls: Type):
|
42
|
+
"""Decorator to register a core tool."""
|
43
|
+
_core_tools_registry.append(cls)
|
44
|
+
return cls
|
45
|
+
|
47
46
|
|
48
47
|
class CoreToolsPlugin(Plugin):
|
49
48
|
"""Core tools plugin providing essential janito functionality."""
|
@@ -55,7 +55,7 @@ class CreateFile(ToolBase):
|
|
55
55
|
or file exists (when overwrite=False).
|
56
56
|
|
57
57
|
Security Features:
|
58
|
-
- Loop protection:
|
58
|
+
- Loop protection: Prevents repeated create calls for the same file path within a short window (1 allowed per 10 seconds)
|
59
59
|
- Path traversal prevention: Validates and sanitizes file paths
|
60
60
|
- Permission checking: Respects file system permissions
|
61
61
|
- Atomic writes: Prevents partial file creation on errors
|
@@ -84,7 +84,7 @@ class CreateFile(ToolBase):
|
|
84
84
|
permissions = ToolPermissions(write=True)
|
85
85
|
tool_name = "create_file"
|
86
86
|
|
87
|
-
@protect_against_loops(max_calls=
|
87
|
+
@protect_against_loops(max_calls=1, time_window=3600.0, key_field="path")
|
88
88
|
def run(self, path: str, content: str, overwrite: bool = False) -> str:
|
89
89
|
path = expand_path(path)
|
90
90
|
disp_path = display_path(path)
|
@@ -15,7 +15,6 @@ class DeleteTextInFile(ToolBase):
|
|
15
15
|
path (str): Path to the file to modify.
|
16
16
|
start_marker (str): The starting delimiter string.
|
17
17
|
end_marker (str): The ending delimiter string.
|
18
|
-
backup (bool, optional): Deprecated. No backups are created anymore and this flag is ignored. Defaults to False.
|
19
18
|
|
20
19
|
Returns:
|
21
20
|
str: Status message indicating the result.
|
janito/providers/__init__.py
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
# Together AI provider for Janito
|
@@ -0,0 +1,69 @@
|
|
1
|
+
"""
|
2
|
+
Model specifications for Together AI provider.
|
3
|
+
"""
|
4
|
+
|
5
|
+
MODEL_SPECS = {
|
6
|
+
"allenai/OLMo-2-0325-32B-Instruct": {
|
7
|
+
"max_tokens": 32768,
|
8
|
+
"max_input_tokens": 32768,
|
9
|
+
"max_output_tokens": 32768,
|
10
|
+
"description": "OLMo 2 32B Instruct - Fully open language model from AllenAI",
|
11
|
+
"supports_tools": True,
|
12
|
+
"supports_system_prompt": True,
|
13
|
+
"supports_streaming": True,
|
14
|
+
},
|
15
|
+
"allenai/OLMo-2-1124-7B-Instruct": {
|
16
|
+
"max_tokens": 32768,
|
17
|
+
"max_input_tokens": 32768,
|
18
|
+
"max_output_tokens": 32768,
|
19
|
+
"description": "OLMo 2 7B Instruct - Fully open language model from AllenAI",
|
20
|
+
"supports_tools": True,
|
21
|
+
"supports_system_prompt": True,
|
22
|
+
"supports_streaming": True,
|
23
|
+
},
|
24
|
+
"allenai/OLMo-2-0425-1B": {
|
25
|
+
"max_tokens": 32768,
|
26
|
+
"max_input_tokens": 32768,
|
27
|
+
"max_output_tokens": 32768,
|
28
|
+
"description": "OLMo 2 1B - Fully open language model from AllenAI",
|
29
|
+
"supports_tools": True,
|
30
|
+
"supports_system_prompt": True,
|
31
|
+
"supports_streaming": True,
|
32
|
+
},
|
33
|
+
"meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo": {
|
34
|
+
"max_tokens": 8192,
|
35
|
+
"max_input_tokens": 128000,
|
36
|
+
"max_output_tokens": 8192,
|
37
|
+
"description": "Llama 3.1 8B Instruct Turbo",
|
38
|
+
"supports_tools": True,
|
39
|
+
"supports_system_prompt": True,
|
40
|
+
"supports_streaming": True,
|
41
|
+
},
|
42
|
+
"meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo": {
|
43
|
+
"max_tokens": 8192,
|
44
|
+
"max_input_tokens": 128000,
|
45
|
+
"max_output_tokens": 8192,
|
46
|
+
"description": "Llama 3.1 70B Instruct Turbo",
|
47
|
+
"supports_tools": True,
|
48
|
+
"supports_system_prompt": True,
|
49
|
+
"supports_streaming": True,
|
50
|
+
},
|
51
|
+
"mistralai/Mixtral-8x7B-Instruct-v0.1": {
|
52
|
+
"max_tokens": 32768,
|
53
|
+
"max_input_tokens": 32768,
|
54
|
+
"max_output_tokens": 32768,
|
55
|
+
"description": "Mixtral 8x7B Instruct",
|
56
|
+
"supports_tools": True,
|
57
|
+
"supports_system_prompt": True,
|
58
|
+
"supports_streaming": True,
|
59
|
+
},
|
60
|
+
"deepseek-ai/deepseek-llm-67b-chat": {
|
61
|
+
"max_tokens": 4096,
|
62
|
+
"max_input_tokens": 4096,
|
63
|
+
"max_output_tokens": 4096,
|
64
|
+
"description": "DeepSeek LLM 67B Chat",
|
65
|
+
"supports_tools": True,
|
66
|
+
"supports_system_prompt": True,
|
67
|
+
"supports_streaming": True,
|
68
|
+
},
|
69
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
from janito.llm.provider import LLMProvider
|
2
|
+
from janito.llm.model import LLMModelInfo
|
3
|
+
from janito.llm.auth import LLMAuthManager
|
4
|
+
from janito.llm.driver_config import LLMDriverConfig
|
5
|
+
from janito.drivers.openai.driver import OpenAIModelDriver
|
6
|
+
from janito.tools import get_local_tools_adapter
|
7
|
+
from janito.providers.registry import LLMProviderRegistry
|
8
|
+
from .model_info import MODEL_SPECS
|
9
|
+
from queue import Queue
|
10
|
+
|
11
|
+
available = OpenAIModelDriver.available
|
12
|
+
unavailable_reason = OpenAIModelDriver.unavailable_reason
|
13
|
+
|
14
|
+
|
15
|
+
class TogetherProvider(LLMProvider):
|
16
|
+
name = 'together'
|
17
|
+
NAME = 'together'
|
18
|
+
MAINTAINER = 'Janito Team'
|
19
|
+
MODEL_SPECS = MODEL_SPECS
|
20
|
+
DEFAULT_MODEL = 'allenai/OLMo-2-0325-32B-Instruct'
|
21
|
+
|
22
|
+
def __init__(
|
23
|
+
self, auth_manager: LLMAuthManager = None, config: LLMDriverConfig = None
|
24
|
+
):
|
25
|
+
self._tools_adapter = get_local_tools_adapter()
|
26
|
+
self._driver = None
|
27
|
+
|
28
|
+
if not self.available:
|
29
|
+
return
|
30
|
+
|
31
|
+
self._initialize_config(auth_manager, config)
|
32
|
+
self._setup_model_config()
|
33
|
+
|
34
|
+
def _initialize_config(self, auth_manager, config):
|
35
|
+
self.auth_manager = auth_manager or LLMAuthManager()
|
36
|
+
self._api_key = self.auth_manager.get_credentials(type(self).NAME)
|
37
|
+
if not self._api_key:
|
38
|
+
from janito.llm.auth_utils import handle_missing_api_key
|
39
|
+
handle_missing_api_key(self.name, 'TOGETHER_API_KEY')
|
40
|
+
|
41
|
+
self._driver_config = config or LLMDriverConfig(model=None)
|
42
|
+
if not self._driver_config.model:
|
43
|
+
self._driver_config.model = self.DEFAULT_MODEL
|
44
|
+
if not self._driver_config.api_key:
|
45
|
+
self._driver_config.api_key = self._api_key
|
46
|
+
|
47
|
+
self._driver_config.base_url = 'https://api.together.xyz/v1'
|
48
|
+
|
49
|
+
def _setup_model_config(self):
|
50
|
+
model_name = self._driver_config.model
|
51
|
+
model_spec = self.MODEL_SPECS.get(model_name)
|
52
|
+
|
53
|
+
if hasattr(self._driver_config, 'max_tokens'):
|
54
|
+
self._driver_config.max_tokens = None
|
55
|
+
if hasattr(self._driver_config, 'max_completion_tokens'):
|
56
|
+
self._driver_config.max_completion_tokens = None
|
57
|
+
|
58
|
+
if model_spec:
|
59
|
+
max_tokens = getattr(model_spec, 'max_tokens', None)
|
60
|
+
if max_tokens and max_tokens != 'N/A':
|
61
|
+
self._driver_config.max_tokens = int(max_tokens)
|
62
|
+
|
63
|
+
self.fill_missing_device_info(self._driver_config)
|
64
|
+
|
65
|
+
@property
|
66
|
+
def driver(self) -> OpenAIModelDriver:
|
67
|
+
if not self.available:
|
68
|
+
raise ImportError(f'TogetherProvider unavailable: {self.unavailable_reason}')
|
69
|
+
return self._driver
|
70
|
+
|
71
|
+
@property
|
72
|
+
def available(self):
|
73
|
+
return available
|
74
|
+
|
75
|
+
@property
|
76
|
+
def unavailable_reason(self):
|
77
|
+
return unavailable_reason
|
78
|
+
|
79
|
+
def create_driver(self):
|
80
|
+
driver = OpenAIModelDriver(
|
81
|
+
tools_adapter=self._tools_adapter, provider_name=self.NAME
|
82
|
+
)
|
83
|
+
driver.config = self._driver_config
|
84
|
+
return driver
|
85
|
+
|
86
|
+
def create_agent(self, tools_adapter=None, agent_name: str = None, **kwargs):
|
87
|
+
from janito.llm.agent import LLMAgent
|
88
|
+
if tools_adapter is None:
|
89
|
+
tools_adapter = get_local_tools_adapter()
|
90
|
+
raise NotImplementedError(
|
91
|
+
'create_agent must be constructed via new factory using input/output queues and config.'
|
92
|
+
)
|
93
|
+
|
94
|
+
@property
|
95
|
+
def model_name(self):
|
96
|
+
return self._driver_config.model
|
97
|
+
|
98
|
+
@property
|
99
|
+
def driver_config(self):
|
100
|
+
return self._driver_config
|
101
|
+
|
102
|
+
def execute_tool(self, tool_name: str, event_bus, *args, **kwargs):
|
103
|
+
self._tools_adapter.event_bus = event_bus
|
104
|
+
return self._tools_adapter.execute_by_name(tool_name, *args, **kwargs)
|
105
|
+
|
106
|
+
|
107
|
+
LLMProviderRegistry.register(TogetherProvider.NAME, TogetherProvider)
|
108
|
+
|
janito/tools/base.py
CHANGED
@@ -1,35 +1,5 @@
|
|
1
1
|
class BaseTool:
|
2
|
-
"""
|
3
|
-
Base class for all tools.
|
4
|
-
|
5
|
-
Parameters:
|
6
|
-
path (str): Target file path for file operations
|
7
|
-
content (str): File content to write or process
|
8
|
-
overwrite (bool): Whether to overwrite existing files (default: False)
|
9
|
-
sources (str): Source file(s) to copy from
|
10
|
-
target (str): Destination path for copy operations
|
11
|
-
recursive (bool): Whether to process directories recursively
|
12
|
-
from_line (int): Starting line number for file reading
|
13
|
-
to_line (int): Ending line number for file reading
|
14
|
-
search_text (str): Text to search for in files
|
15
|
-
replacement_text (str): Text to replace search matches with
|
16
|
-
use_regex (bool): Whether to treat search as regex pattern
|
17
|
-
case_sensitive (bool): Whether search should be case sensitive
|
18
|
-
max_depth (int): Maximum directory depth to search
|
19
|
-
include_gitignored (bool): Whether to include .gitignored files
|
20
|
-
timeout (int): Timeout in seconds for operations
|
21
|
-
require_confirmation (bool): Whether to require user confirmation
|
22
|
-
data (dict): Chart data for visualization tools
|
23
|
-
title (str): Chart title
|
24
|
-
width (int): Chart width in pixels
|
25
|
-
height (int): Chart height in pixels
|
26
|
-
query (str): Search query for text search
|
27
|
-
paths (str): Directory or file paths to search in
|
28
|
-
src_path (str): Source path for move operations
|
29
|
-
dest_path (str): Destination path for move operations
|
30
|
-
code (str): Python code to execute
|
31
|
-
pattern (str): File pattern to match (e.g., '*.py')
|
32
|
-
"""
|
2
|
+
"""Base class for all tools."""
|
33
3
|
|
34
4
|
tool_name: str = ""
|
35
5
|
|
janito/tools/cli_initializer.py
CHANGED
@@ -17,7 +17,7 @@ def initialize_cli_tools():
|
|
17
17
|
"""Initialize tools for CLI usage, avoiding circular imports."""
|
18
18
|
try:
|
19
19
|
from janito.tools.adapters.local.adapter import LocalToolsAdapter
|
20
|
-
from janito.
|
20
|
+
from janito.plugin_system.core_loader_fixed import load_core_plugin
|
21
21
|
from janito.tools.permissions import set_global_allowed_permissions
|
22
22
|
from janito.tools.tool_base import ToolPermissions
|
23
23
|
|
janito/tools/initialize.py
CHANGED
@@ -9,7 +9,7 @@ import sys
|
|
9
9
|
from pathlib import Path
|
10
10
|
from typing import List, Optional
|
11
11
|
|
12
|
-
from janito.
|
12
|
+
from janito.plugin_system.core_loader_fixed import load_core_plugin
|
13
13
|
from janito.tools.adapters.local.adapter import LocalToolsAdapter
|
14
14
|
|
15
15
|
|