holon-sh 0.0.1.dev25__tar.gz → 0.0.1.dev26__tar.gz
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.
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/PKG-INFO +1 -1
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/client.py +17 -7
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/pyproject.toml +1 -1
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/tests/test_runtime.py +13 -2
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/.gitignore +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/LICENSE +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/README.md +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/context.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/__init__.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/events/__init__.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/events/_client.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/events/_server.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/events/_wire.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/files/__init__.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/files/_client.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/files/_server.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/ext/files/_wire.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/py.typed +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/holon/serve.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/scripts/verify_distribution.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/tests/fixtures/caller/holon/apps/__init__.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/tests/test_elicit.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/tests/test_events.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/tests/test_files.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/tests/test_package.py +0 -0
- {holon_sh-0.0.1.dev25 → holon_sh-0.0.1.dev26}/tests/test_serve.py +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
import os
|
|
4
5
|
from collections.abc import AsyncIterator, Awaitable, Callable, Mapping, Sequence
|
|
5
6
|
from contextlib import asynccontextmanager
|
|
@@ -110,6 +111,12 @@ class CallOptions(TypedDict, total=False):
|
|
|
110
111
|
elicit: Callable[[ElicitRequestParams], Awaitable[ElicitResult]]
|
|
111
112
|
|
|
112
113
|
|
|
114
|
+
def _text(result: CallToolResult) -> str | None:
|
|
115
|
+
return next(
|
|
116
|
+
(part.text for part in result.content if isinstance(part, TextContent)), None
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
113
120
|
class ToolCallError(RuntimeError):
|
|
114
121
|
"""Raised by ``tools.<name>`` when a tool fails or needs input.
|
|
115
122
|
|
|
@@ -130,10 +137,7 @@ class ToolCallError(RuntimeError):
|
|
|
130
137
|
)
|
|
131
138
|
else:
|
|
132
139
|
message = "tool failed"
|
|
133
|
-
detail =
|
|
134
|
-
(part.text for part in result.content if isinstance(part, TextContent)),
|
|
135
|
-
"",
|
|
136
|
-
)
|
|
140
|
+
detail = _text(result) or ""
|
|
137
141
|
if detail:
|
|
138
142
|
message = f"{message}: {detail}"
|
|
139
143
|
super().__init__(f"{app}.{tool}: {message}")
|
|
@@ -207,9 +211,10 @@ class _App:
|
|
|
207
211
|
if contract is None
|
|
208
212
|
else {tool["name"]: tool for tool in contract["tools"]}
|
|
209
213
|
)
|
|
214
|
+
parsed = set((contract or {}).get("responses", ()))
|
|
210
215
|
self.tools = SimpleNamespace(
|
|
211
216
|
**{
|
|
212
|
-
name: partial(self._call_tool, tool)
|
|
217
|
+
name: partial(self._call_tool, tool, name in parsed)
|
|
213
218
|
for name, tool in self._definitions.items()
|
|
214
219
|
if not name.startswith("_")
|
|
215
220
|
}
|
|
@@ -346,6 +351,7 @@ class _App:
|
|
|
346
351
|
async def _call_tool(
|
|
347
352
|
self,
|
|
348
353
|
tool: dict[str, Any],
|
|
354
|
+
parsed: bool,
|
|
349
355
|
options: CallOptions | None = None,
|
|
350
356
|
/,
|
|
351
357
|
**arguments: object,
|
|
@@ -353,6 +359,9 @@ class _App:
|
|
|
353
359
|
result = await self.call_tool(tool["name"], options, **arguments)
|
|
354
360
|
if isinstance(result, InputRequiredResult) or result.is_error:
|
|
355
361
|
raise ToolCallError(self._name, tool["name"], result)
|
|
362
|
+
if parsed:
|
|
363
|
+
text = _text(result)
|
|
364
|
+
return None if text is None else json.loads(text)
|
|
356
365
|
return result.structured_content if "outputSchema" in tool else result
|
|
357
366
|
|
|
358
367
|
|
|
@@ -360,8 +369,9 @@ class Apps:
|
|
|
360
369
|
"""An application's dependencies, as generated clients use them.
|
|
361
370
|
|
|
362
371
|
Applications use ``apps`` or ``create_apps`` from ``holon.apps``. Each dependency is ``apps.<name>``
|
|
363
|
-
or ``apps[name]``: its ``tools.<name>`` return structured output or
|
|
364
|
-
and its ``call_tool``
|
|
372
|
+
or ``apps[name]``: its ``tools.<name>`` return structured output, or the parsed JSON text of a tool
|
|
373
|
+
the contract lists under ``responses``, or raise :class:`ToolCallError`, and its ``call_tool``
|
|
374
|
+
returns the full result.
|
|
365
375
|
|
|
366
376
|
Args:
|
|
367
377
|
identity: Application name, version, and ``requires``.
|
|
@@ -58,8 +58,10 @@ def test_clients_preserve_mcp_results_and_validate(monkeypatch):
|
|
|
58
58
|
return InputRequiredResult(
|
|
59
59
|
request_state="opaque", _meta={"preserved": True}
|
|
60
60
|
)
|
|
61
|
+
if id == "empty":
|
|
62
|
+
return CallToolResult(content=[])
|
|
61
63
|
return CallToolResult(
|
|
62
|
-
content=[TextContent(type="text", text="
|
|
64
|
+
content=[TextContent(type="text", text='{"order": "unchecked"}')],
|
|
63
65
|
structured_content={"total": "bad" if id == "bad" else limit},
|
|
64
66
|
)
|
|
65
67
|
|
|
@@ -147,7 +149,16 @@ def test_clients_preserve_mcp_results_and_validate(monkeypatch):
|
|
|
147
149
|
k: v for k, v in CONTRACT["tools"][0].items() if k != "outputSchema"
|
|
148
150
|
}
|
|
149
151
|
plain = Apps(identity, {"orders": {"tools": [tool]}}, bindings)
|
|
150
|
-
assert (await plain.orders.tools.read(id="good")).content[0].text ==
|
|
152
|
+
assert (await plain.orders.tools.read(id="good")).content[0].text == (
|
|
153
|
+
'{"order": "unchecked"}'
|
|
154
|
+
)
|
|
155
|
+
parsed = Apps(
|
|
156
|
+
identity, {"orders": {"tools": [tool], "responses": ["read"]}}, bindings
|
|
157
|
+
)
|
|
158
|
+
assert await parsed.orders.tools.read(id="good") == {"order": "unchecked"}
|
|
159
|
+
assert await parsed.orders.tools.read(id="empty") is None
|
|
160
|
+
with pytest.raises(ToolCallError):
|
|
161
|
+
await parsed.orders.tools.read(id="error")
|
|
151
162
|
with pytest.raises(RuntimeError):
|
|
152
163
|
await Apps(undeclared, {}).missing.call_tool("read")
|
|
153
164
|
script = {**identity, "requires": {}}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|