Skip to content

Personal AI, On Personal Devices

Python

fix: normalize TOML arrays to comma-separated strings for str-typed config fields

Jon Saad-Falcon04205d8f87b2
diff --git a/src/openjarvis/core/config.py b/src/openjarvis/core/config.py
index 1067c1a4..55c36164 100644
--- a/src/openjarvis/core/config.py
+++ b/src/openjarvis/core/config.py
@@ -1100,7 +1100,8 @@ def _apply_toml_section(target: Any, section: Dict[str, Any]) -> None:
"""Overlay TOML key/value pairs onto a dataclass instance.
Recursively handles nested dicts when the target attribute is itself
- a dataclass.
+ a dataclass. Normalises TOML arrays to comma-separated strings when
+ the target field is annotated as ``str``.
"""
for key, value in section.items():
if hasattr(target, key):
@@ -1111,6 +1112,11 @@ def _apply_toml_section(target: Any, section: Dict[str, Any]) -> None:
else:
setattr(target, key, value)
else:
+ # Normalise TOML arrays → comma-separated string when field is str
+ if isinstance(value, list) and hasattr(target, "__dataclass_fields__"):
+ field_obj = target.__dataclass_fields__.get(key)
+ if field_obj is not None and field_obj.type in ("str", str):
+ value = ",".join(str(v) for v in value)
setattr(target, key, value)
diff --git a/src/openjarvis/scheduler/scheduler.py b/src/openjarvis/scheduler/scheduler.py
index 3e04b5ef..8702ee21 100644
--- a/src/openjarvis/scheduler/scheduler.py
+++ b/src/openjarvis/scheduler/scheduler.py
@@ -218,8 +218,13 @@ class TaskScheduler:
try:
if self._system is not None:
+ raw_tools = (
+ task.tools
+ if isinstance(task.tools, list)
+ else task.tools.split(",")
+ )
tools_list = (
- [t.strip() for t in task.tools.split(",") if t.strip()]
+ [t.strip() for t in raw_tools if t.strip()]
if task.tools
else []
)
diff --git a/tests/core/test_config.py b/tests/core/test_config.py
index 28407d26..7034cb46 100644
--- a/tests/core/test_config.py
+++ b/tests/core/test_config.py
@@ -449,6 +449,17 @@ class TestSchedulerConfig:
# ---------------------------------------------------------------------------
+class TestApplyTomlSectionListNormalization:
+ def test_apply_toml_section_list_to_str_field(self) -> None:
+ """TOML arrays assigned to str-typed fields should be joined with ','."""
+ from openjarvis.core.config import ToolsConfig, _apply_toml_section
+
+ target = ToolsConfig()
+ _apply_toml_section(target, {"enabled": ["code_interpreter", "web_search", "file_read"]})
+ assert isinstance(target.enabled, str)
+ assert target.enabled == "code_interpreter,web_search,file_read"
+
+
class TestWhatsAppBaileysChannelConfig:
def test_defaults(self) -> None:
wc = WhatsAppBaileysChannelConfig()