Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(voice): app-action results stay valid JSON, files are not read as text

rubenluetke10-beepcc8a5124fd95
diff --git a/jarvis/app_actions/catalog.py b/jarvis/app_actions/catalog.py
index 61c55acc09..a3ae288cdb 100644
--- a/jarvis/app_actions/catalog.py
+++ b/jarvis/app_actions/catalog.py
@@ -186,6 +186,8 @@ def _entry(
or is_excluded(path)
or operation.get("x-jarvis-exclude")
or _carries_secret(operation, components)
+ # A file upload has no JSON body a model could fill; it only failed.
+ or "multipart/form-data" in ((operation.get("requestBody") or {}).get("content") or {})
):
return None
properties: dict[str, Any] = {}
diff --git a/jarvis/plugins/tool/app_action.py b/jarvis/plugins/tool/app_action.py
index 2cd9129cc1..b2617f5388 100644
--- a/jarvis/plugins/tool/app_action.py
+++ b/jarvis/plugins/tool/app_action.py
@@ -257,6 +257,10 @@ class RunAppActionTool:
)
except httpx.HTTPError as exc:
return None, f"transport error: {exc}"
+ kind = resp.headers.get("content-type", "")
+ if resp.content and not kind.startswith(("application/json", "text/")):
+ # An image or download read as text is noise; say what came back.
+ return resp.status_code, {"content_type": kind, "bytes": len(resp.content)}
try:
data = resp.json() if resp.content else None
except ValueError:
@@ -268,7 +272,33 @@ def _trim(data: Any) -> Any:
from jarvis.plugins.tool.app_command import _without_snapshots
data = _without_snapshots(data)
- text = json.dumps(data, ensure_ascii=False, default=str)
- if len(text) <= _MAX_RESPONSE_CHARS:
+ if _size(data) <= _MAX_RESPONSE_CHARS:
return data
- return {"truncated": True, "preview": text[:_MAX_RESPONSE_CHARS]}
+ # Shorten structurally so the model still gets valid JSON: long lists keep
+ # their first items plus a count, long strings their start. Cutting the
+ # serialized text mid-item handed over broken data.
+ for keep in (20, 8, 3, 1):
+ shortened = _shorten(data, keep)
+ if _size(shortened) <= _MAX_RESPONSE_CHARS:
+ return {"truncated": True, "data": shortened}
+ return {
+ "truncated": True,
+ "note": "The response is too large; narrow the request with its parameters.",
+ }
+
+
+def _size(data: Any) -> int:
+ return len(json.dumps(data, ensure_ascii=False, default=str))
+
+
+def _shorten(data: Any, keep: int, depth: int = 0) -> Any:
+ if depth > 6:
+ return "..."
+ if isinstance(data, list):
+ items = [_shorten(item, keep, depth + 1) for item in data[:keep]]
+ return items + ([f"... {len(data) - keep} more"] if len(data) > keep else [])
+ if isinstance(data, dict):
+ return {k: _shorten(v, keep, depth + 1) for k, v in data.items()}
+ if isinstance(data, str) and len(data) > 200 * keep:
+ return data[: 200 * keep] + "..."
+ return data
diff --git a/tests/unit/app_actions/test_app_actions.py b/tests/unit/app_actions/test_app_actions.py
index 6109d7febe..991c401b60 100644
--- a/tests/unit/app_actions/test_app_actions.py
+++ b/tests/unit/app_actions/test_app_actions.py
@@ -6,7 +6,7 @@ from typing import Any
import httpx
import pytest
-from fastapi import FastAPI
+from fastapi import FastAPI, UploadFile
from pydantic import BaseModel
from jarvis.app_actions import catalog as catalog_mod
@@ -234,3 +234,28 @@ async def test_a_misspelled_parameter_is_refused_before_anything_runs(app: FastA
assert "limt" in (result.error or "") and "limit" in (result.error or "")
ran = await tool.execute({"action_id": action_id, "params": {"limit": 3}}, None)
assert ran.success and ran.output["response"]["limit"] == 3
+
+
+def test_a_long_response_is_shortened_into_valid_json() -> None:
+ import json
+
+ from jarvis.plugins.tool.app_action import _MAX_RESPONSE_CHARS, _trim
+
+ big = {"items": [{"name": f"skill-{i}", "notes": "x" * 300} for i in range(500)]}
+ trimmed = _trim(big)
+ assert trimmed["truncated"] is True
+ assert len(json.dumps(trimmed)) <= _MAX_RESPONSE_CHARS + 100
+ assert trimmed["data"]["items"][0]["name"] == "skill-0"
+ assert trimmed["data"]["items"][-1].endswith("more")
+
+
+def test_a_file_upload_is_not_offered_as_an_action() -> None:
+
+ application = FastAPI()
+
+ @application.post("/api/skills/upload")
+ async def upload(file: UploadFile) -> dict[str, Any]:
+ return {}
+
+ paths = {e.path for e in build_catalog(application.openapi()).values()}
+ assert "/api/skills/upload" not in paths