chuk-tool-processor 0.6.4__py3-none-any.whl → 0.9.7__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.
Potentially problematic release.
This version of chuk-tool-processor might be problematic. Click here for more details.
- chuk_tool_processor/core/__init__.py +32 -1
- chuk_tool_processor/core/exceptions.py +225 -13
- chuk_tool_processor/core/processor.py +135 -104
- chuk_tool_processor/execution/strategies/__init__.py +6 -0
- chuk_tool_processor/execution/strategies/inprocess_strategy.py +142 -150
- chuk_tool_processor/execution/strategies/subprocess_strategy.py +202 -206
- chuk_tool_processor/execution/tool_executor.py +82 -84
- chuk_tool_processor/execution/wrappers/__init__.py +42 -0
- chuk_tool_processor/execution/wrappers/caching.py +150 -116
- chuk_tool_processor/execution/wrappers/circuit_breaker.py +370 -0
- chuk_tool_processor/execution/wrappers/rate_limiting.py +76 -43
- chuk_tool_processor/execution/wrappers/retry.py +116 -78
- chuk_tool_processor/logging/__init__.py +23 -17
- chuk_tool_processor/logging/context.py +40 -45
- chuk_tool_processor/logging/formatter.py +22 -21
- chuk_tool_processor/logging/helpers.py +28 -42
- chuk_tool_processor/logging/metrics.py +13 -15
- chuk_tool_processor/mcp/__init__.py +8 -12
- chuk_tool_processor/mcp/mcp_tool.py +158 -114
- chuk_tool_processor/mcp/register_mcp_tools.py +22 -22
- chuk_tool_processor/mcp/setup_mcp_http_streamable.py +57 -17
- chuk_tool_processor/mcp/setup_mcp_sse.py +57 -17
- chuk_tool_processor/mcp/setup_mcp_stdio.py +11 -11
- chuk_tool_processor/mcp/stream_manager.py +333 -276
- chuk_tool_processor/mcp/transport/__init__.py +22 -29
- chuk_tool_processor/mcp/transport/base_transport.py +180 -44
- chuk_tool_processor/mcp/transport/http_streamable_transport.py +505 -325
- chuk_tool_processor/mcp/transport/models.py +100 -0
- chuk_tool_processor/mcp/transport/sse_transport.py +607 -276
- chuk_tool_processor/mcp/transport/stdio_transport.py +597 -116
- chuk_tool_processor/models/__init__.py +21 -1
- chuk_tool_processor/models/execution_strategy.py +16 -21
- chuk_tool_processor/models/streaming_tool.py +28 -25
- chuk_tool_processor/models/tool_call.py +49 -31
- chuk_tool_processor/models/tool_export_mixin.py +22 -8
- chuk_tool_processor/models/tool_result.py +40 -77
- chuk_tool_processor/models/tool_spec.py +350 -0
- chuk_tool_processor/models/validated_tool.py +36 -18
- chuk_tool_processor/observability/__init__.py +30 -0
- chuk_tool_processor/observability/metrics.py +312 -0
- chuk_tool_processor/observability/setup.py +105 -0
- chuk_tool_processor/observability/tracing.py +345 -0
- chuk_tool_processor/plugins/__init__.py +1 -1
- chuk_tool_processor/plugins/discovery.py +11 -11
- chuk_tool_processor/plugins/parsers/__init__.py +1 -1
- chuk_tool_processor/plugins/parsers/base.py +1 -2
- chuk_tool_processor/plugins/parsers/function_call_tool.py +13 -8
- chuk_tool_processor/plugins/parsers/json_tool.py +4 -3
- chuk_tool_processor/plugins/parsers/openai_tool.py +12 -7
- chuk_tool_processor/plugins/parsers/xml_tool.py +4 -4
- chuk_tool_processor/registry/__init__.py +12 -12
- chuk_tool_processor/registry/auto_register.py +22 -30
- chuk_tool_processor/registry/decorators.py +127 -129
- chuk_tool_processor/registry/interface.py +26 -23
- chuk_tool_processor/registry/metadata.py +27 -22
- chuk_tool_processor/registry/provider.py +17 -18
- chuk_tool_processor/registry/providers/__init__.py +16 -19
- chuk_tool_processor/registry/providers/memory.py +18 -25
- chuk_tool_processor/registry/tool_export.py +42 -51
- chuk_tool_processor/utils/validation.py +15 -16
- chuk_tool_processor-0.9.7.dist-info/METADATA +1813 -0
- chuk_tool_processor-0.9.7.dist-info/RECORD +67 -0
- chuk_tool_processor-0.6.4.dist-info/METADATA +0 -697
- chuk_tool_processor-0.6.4.dist-info/RECORD +0 -60
- {chuk_tool_processor-0.6.4.dist-info → chuk_tool_processor-0.9.7.dist-info}/WHEEL +0 -0
- {chuk_tool_processor-0.6.4.dist-info → chuk_tool_processor-0.9.7.dist-info}/top_level.txt +0 -0
|
@@ -8,12 +8,15 @@ validate_arguments(tool_name, fn, args) -> dict
|
|
|
8
8
|
validate_result(tool_name, fn, result) -> Any
|
|
9
9
|
@with_validation -> class decorator
|
|
10
10
|
"""
|
|
11
|
+
|
|
11
12
|
from __future__ import annotations
|
|
13
|
+
|
|
12
14
|
import inspect
|
|
13
|
-
import
|
|
15
|
+
from collections.abc import Callable
|
|
14
16
|
from functools import lru_cache, wraps
|
|
15
|
-
from typing import Any,
|
|
16
|
-
|
|
17
|
+
from typing import Any, get_type_hints
|
|
18
|
+
|
|
19
|
+
from pydantic import BaseModel, ConfigDict, ValidationError, create_model
|
|
17
20
|
|
|
18
21
|
# exception
|
|
19
22
|
from chuk_tool_processor.core.exceptions import ToolValidationError
|
|
@@ -36,19 +39,15 @@ def _arg_model(tool_name: str, fn: Callable) -> type[BaseModel]:
|
|
|
36
39
|
hints.pop("return", None)
|
|
37
40
|
|
|
38
41
|
sig = inspect.signature(fn)
|
|
39
|
-
fields:
|
|
42
|
+
fields: dict[str, tuple[Any, Any]] = {}
|
|
40
43
|
for name, hint in hints.items():
|
|
41
44
|
param = sig.parameters[name]
|
|
42
45
|
default = param.default if param.default is not inspect.Parameter.empty else ...
|
|
43
46
|
fields[name] = (hint, default)
|
|
44
47
|
|
|
45
|
-
return create_model(
|
|
48
|
+
return create_model( # type: ignore[call-overload, no-any-return]
|
|
46
49
|
f"{tool_name}Args",
|
|
47
|
-
__config__=
|
|
48
|
-
"Cfg",
|
|
49
|
-
(),
|
|
50
|
-
{"extra": Extra.forbid}, # disallow unknown keys
|
|
51
|
-
),
|
|
50
|
+
__config__=ConfigDict(extra="forbid"), # disallow unknown keys
|
|
52
51
|
**fields,
|
|
53
52
|
)
|
|
54
53
|
|
|
@@ -71,13 +70,13 @@ def _result_model(tool_name: str, fn: Callable) -> type[BaseModel] | None:
|
|
|
71
70
|
# --------------------------------------------------------------------------- #
|
|
72
71
|
|
|
73
72
|
|
|
74
|
-
def validate_arguments(tool_name: str, fn: Callable, args:
|
|
73
|
+
def validate_arguments(tool_name: str, fn: Callable, args: dict[str, Any]) -> dict[str, Any]:
|
|
75
74
|
"""Validate function arguments against type hints."""
|
|
76
75
|
try:
|
|
77
76
|
model = _arg_model(tool_name, fn)
|
|
78
77
|
return model(**args).model_dump()
|
|
79
78
|
except ValidationError as exc:
|
|
80
|
-
raise ToolValidationError(tool_name, exc.errors()) from exc
|
|
79
|
+
raise ToolValidationError(tool_name, {"errors": exc.errors()}) from exc
|
|
81
80
|
|
|
82
81
|
|
|
83
82
|
def validate_result(tool_name: str, fn: Callable, result: Any) -> Any:
|
|
@@ -86,9 +85,9 @@ def validate_result(tool_name: str, fn: Callable, result: Any) -> Any:
|
|
|
86
85
|
if model is None: # no annotation ⇒ no validation
|
|
87
86
|
return result
|
|
88
87
|
try:
|
|
89
|
-
return model(result=result).result
|
|
88
|
+
return model(result=result).result # type: ignore[attr-defined]
|
|
90
89
|
except ValidationError as exc:
|
|
91
|
-
raise ToolValidationError(tool_name, exc.errors()) from exc
|
|
90
|
+
raise ToolValidationError(tool_name, {"errors": exc.errors()}) from exc
|
|
92
91
|
|
|
93
92
|
|
|
94
93
|
# --------------------------------------------------------------------------- #
|
|
@@ -110,7 +109,7 @@ def with_validation(cls):
|
|
|
110
109
|
# Which method did the user provide?
|
|
111
110
|
fn_name = "_execute" if hasattr(cls, "_execute") else "execute"
|
|
112
111
|
original = getattr(cls, fn_name)
|
|
113
|
-
|
|
112
|
+
|
|
114
113
|
# Ensure the method is async
|
|
115
114
|
if not inspect.iscoroutinefunction(original):
|
|
116
115
|
raise TypeError(f"Tool {cls.__name__} must have an async {fn_name} method")
|
|
@@ -123,4 +122,4 @@ def with_validation(cls):
|
|
|
123
122
|
return validate_result(name, original, res)
|
|
124
123
|
|
|
125
124
|
setattr(cls, fn_name, _validated)
|
|
126
|
-
return cls
|
|
125
|
+
return cls
|