toolplane-python-client 0.1.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.
Files changed (81) hide show
  1. toolplane/__init__.py +106 -0
  2. toolplane/common/__init__.py +93 -0
  3. toolplane/common/base_config.py +129 -0
  4. toolplane/common/base_connection_manager.py +171 -0
  5. toolplane/common/base_session_manager.py +321 -0
  6. toolplane/common/base_tool_manager.py +347 -0
  7. toolplane/common/constants.py +47 -0
  8. toolplane/common/utils.py +310 -0
  9. toolplane/core/__init__.py +67 -0
  10. toolplane/core/config.py +107 -0
  11. toolplane/core/connection.py +285 -0
  12. toolplane/core/errors.py +298 -0
  13. toolplane/core/machine.py +480 -0
  14. toolplane/core/request.py +775 -0
  15. toolplane/core/session.py +332 -0
  16. toolplane/core/session_context.py +514 -0
  17. toolplane/core/task.py +130 -0
  18. toolplane/core/tool.py +329 -0
  19. toolplane/http_core/__init__.py +37 -0
  20. toolplane/http_core/http_config.py +97 -0
  21. toolplane/http_core/http_connection.py +409 -0
  22. toolplane/http_core/http_machine.py +298 -0
  23. toolplane/http_core/http_request.py +748 -0
  24. toolplane/http_core/http_session.py +348 -0
  25. toolplane/http_core/http_session_context.py +491 -0
  26. toolplane/http_core/http_task.py +101 -0
  27. toolplane/http_core/http_tool.py +400 -0
  28. toolplane/interfaces/__init__.py +27 -0
  29. toolplane/interfaces/client_interface.py +122 -0
  30. toolplane/interfaces/connection_interface.py +193 -0
  31. toolplane/interfaces/event_interface.py +290 -0
  32. toolplane/interfaces/request_interface.py +439 -0
  33. toolplane/interfaces/session_interface.py +288 -0
  34. toolplane/interfaces/tool_interface.py +441 -0
  35. toolplane/proto/__init__.py +0 -0
  36. toolplane/proto/service_pb2.py +315 -0
  37. toolplane/proto/service_pb2_grpc.py +2240 -0
  38. toolplane/provider_cli.py +268 -0
  39. toolplane/provider_registry.py +77 -0
  40. toolplane/provider_runtime.py +302 -0
  41. toolplane/toolkits/__init__.py +0 -0
  42. toolplane/toolkits/standalone_tools/__init__.py +0 -0
  43. toolplane/toolkits/standalone_tools/create_directory.py +94 -0
  44. toolplane/toolkits/standalone_tools/create_file.py +124 -0
  45. toolplane/toolkits/standalone_tools/file_search.py +229 -0
  46. toolplane/toolkits/standalone_tools/grep_search.py +372 -0
  47. toolplane/toolkits/standalone_tools/launcher.py +146 -0
  48. toolplane/toolkits/standalone_tools/list_dir.py +395 -0
  49. toolplane/toolkits/standalone_tools/read_file.py +346 -0
  50. toolplane/toolkits/standalone_tools/replace_string_in_file.py +407 -0
  51. toolplane/toolkits/standalone_tools/run_tests.py +66 -0
  52. toolplane/toolkits/standalone_tools/semantic_search.py +485 -0
  53. toolplane/toolkits/standalone_tools/standalone_toolkit.py +979 -0
  54. toolplane/toolkits/standalone_tools/test_failure_analysis.py +618 -0
  55. toolplane/toolkits/standalone_tools/test_standalone_toolkit.py +517 -0
  56. toolplane/toolkits/swe/__init__.py +35 -0
  57. toolplane/toolkits/swe/create_directory.py +15 -0
  58. toolplane/toolkits/swe/create_file.py +15 -0
  59. toolplane/toolkits/swe/descriptions.py +273 -0
  60. toolplane/toolkits/swe/execute_bash.py +93 -0
  61. toolplane/toolkits/swe/file_editor.py +775 -0
  62. toolplane/toolkits/swe/file_search.py +16 -0
  63. toolplane/toolkits/swe/finish.py +50 -0
  64. toolplane/toolkits/swe/grep_search.py +19 -0
  65. toolplane/toolkits/swe/list_dir.py +407 -0
  66. toolplane/toolkits/swe/read_file.py +18 -0
  67. toolplane/toolkits/swe/replace_string_in_file.py +17 -0
  68. toolplane/toolkits/swe/search.py +260 -0
  69. toolplane/toolkits/swe/semantic_search.py +20 -0
  70. toolplane/toolkits/swe/str_replace_editor.py +647 -0
  71. toolplane/toolkits/swe/submit.py +29 -0
  72. toolplane/toolkits/swe/swe_toolkit.py +1296 -0
  73. toolplane/toolplane_client.py +686 -0
  74. toolplane/toolplane_http_client.py +681 -0
  75. toolplane/utils/__init__.py +3 -0
  76. toolplane/utils/schema.py +146 -0
  77. toolplane_python_client-0.1.0.dist-info/METADATA +543 -0
  78. toolplane_python_client-0.1.0.dist-info/RECORD +81 -0
  79. toolplane_python_client-0.1.0.dist-info/WHEEL +5 -0
  80. toolplane_python_client-0.1.0.dist-info/entry_points.txt +2 -0
  81. toolplane_python_client-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,146 @@
1
+ import inspect
2
+ from typing import Any, Dict, List, Optional, Union
3
+
4
+ from typing_extensions import get_args, get_origin, get_type_hints
5
+
6
+ __all__ = ["generate_schema_from_function", "type_to_json_schema"]
7
+
8
+
9
+ def generate_schema_from_function(func):
10
+ """
11
+ Generate a JSON schema for a function based on type hints and docstring.
12
+
13
+ Args:
14
+ func (Callable): Function to generate schema for
15
+
16
+ Returns:
17
+ Dict: JSON schema for the function
18
+ """
19
+ sig = inspect.signature(func)
20
+ type_hints = get_type_hints(func)
21
+
22
+ # Parse the docstring to get parameter descriptions
23
+ docstring = inspect.getdoc(func) or ""
24
+ param_descriptions = {}
25
+ description = ""
26
+
27
+ lines = docstring.split("\n")
28
+ in_params = False
29
+ current_param = None
30
+
31
+ for line in lines:
32
+ line = line.strip()
33
+ if not line:
34
+ continue
35
+
36
+ if line.lower().startswith("parameters:") or line.lower().startswith("args:"):
37
+ in_params = True
38
+ continue
39
+
40
+ if in_params:
41
+ # Check if this line defines a new parameter
42
+ if ":" in line and line[0].isalnum():
43
+ parts = line.split(":", 1)
44
+ current_param = parts[0].strip()
45
+ param_descriptions[current_param] = parts[1].strip()
46
+ elif current_param and line[0].isspace():
47
+ # Continuation of previous parameter description
48
+ param_descriptions[current_param] += " " + line.strip()
49
+ elif not description:
50
+ # First line(s) before parameters is the description
51
+ description += line + " "
52
+
53
+ # Build the schema
54
+ properties = {}
55
+ required = []
56
+
57
+ for param_name, param in sig.parameters.items():
58
+ if param_name == "self":
59
+ continue
60
+
61
+ param_type = type_hints.get(param_name, Any)
62
+ param_schema = type_to_json_schema(param_type)
63
+
64
+ # Add description if available
65
+ if param_name in param_descriptions:
66
+ param_schema["description"] = param_descriptions[param_name]
67
+
68
+ properties[param_name] = param_schema
69
+
70
+ # If the parameter has no default value, it's required
71
+ if param.default is inspect.Parameter.empty:
72
+ required.append(param_name)
73
+
74
+ schema = {"type": "object", "properties": properties}
75
+
76
+ if required:
77
+ schema["required"] = required
78
+
79
+ return {
80
+ "name": func.__name__,
81
+ "description": description.strip(),
82
+ "schema": schema,
83
+ }
84
+
85
+
86
+ def type_to_json_schema(type_hint):
87
+ """
88
+ Convert a Python type hint to a JSON schema type.
89
+
90
+ Args:
91
+ type_hint: Python type hint
92
+
93
+ Returns:
94
+ Dict: JSON schema type definition
95
+ """
96
+ origin = get_origin(type_hint)
97
+ args = get_args(type_hint)
98
+
99
+ # Handle Union types (Optional is Union[type, None])
100
+ if origin is Union:
101
+ if len(args) == 2 and type(None) in args:
102
+ # Handle Optional[type]
103
+ for arg in args:
104
+ if arg is not type(None):
105
+ schema = type_to_json_schema(arg)
106
+ schema["nullable"] = True
107
+ return schema
108
+ else:
109
+ # General Union - not fully supported in JSON Schema
110
+ return {"type": "object"}
111
+
112
+ # Handle List types
113
+ if origin is list or origin is List:
114
+ if args:
115
+ return {"type": "array", "items": type_to_json_schema(args[0])}
116
+ else:
117
+ return {"type": "array"}
118
+
119
+ # Handle Dict types
120
+ if origin is dict or origin is Dict:
121
+ return {"type": "object"}
122
+
123
+ # Handle primitive types
124
+ if type_hint is str or type_hint is Optional[str]:
125
+ return {"type": "string"}
126
+ elif type_hint is int or type_hint is Optional[int]:
127
+ return {"type": "integer"}
128
+ elif type_hint is float or type_hint is Optional[float]:
129
+ return {"type": "number"}
130
+ elif type_hint is bool or type_hint is Optional[bool]:
131
+ return {"type": "boolean"}
132
+ elif (
133
+ type_hint is list
134
+ or type_hint is List
135
+ or type_hint is Optional[list]
136
+ or type_hint is Optional[List]
137
+ ):
138
+ return {"type": "array"}
139
+ elif (
140
+ type_hint is dict
141
+ or type_hint is Dict
142
+ or type_hint is Optional[dict]
143
+ or type_hint is Optional[Dict]
144
+ ):
145
+ return {"type": "object"} # Default to object for complex types
146
+ return {"type": "object"}