Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(skill): read existing settings as TOML

Rudy Celekli0e23c6645d97
diff --git a/docs/skill/mpt_agent.py b/docs/skill/mpt_agent.py
index bd11039c..ae1ef342 100644
--- a/docs/skill/mpt_agent.py
+++ b/docs/skill/mpt_agent.py
@@ -11,6 +11,7 @@ import shutil
import subprocess
import sys
import tempfile
+import tomllib
import urllib.error
import urllib.request
import uuid
@@ -179,14 +180,20 @@ def ensure_config(root: Path) -> Path:
def _plain_config_value(text: str, key: str) -> str:
- """Read a simple top-level TOML value without printing its contents."""
- match = re.search(rf"(?m)^{re.escape(key)}\s*=\s*(.*)$", text)
- if not match:
- return ""
- value = match.group(1).split("#", 1)[0].strip()
- if value.startswith('"') and value.endswith('"'):
- return value[1:-1]
- return value
+ """Read app settings with the same TOML syntax as the backend loader."""
+ try:
+ document = tomllib.loads(text)
+ except tomllib.TOMLDecodeError as exc:
+ # Configuration can contain credentials; do not echo its source text.
+ raise SkillError("configuration is not valid TOML") from exc
+ settings = document.get("app", document)
+ if not isinstance(settings, dict):
+ raise SkillError("configuration app settings must be a TOML table")
+ value = settings.get(key, "")
+ # Existing readiness/list consumers expect an unquoted string or JSON array.
+ if isinstance(value, str):
+ return value
+ return json.dumps(value, ensure_ascii=False)
def _replace_config_value(text: str, key: str, value: object) -> str:
diff --git a/test/services/test_mpt_agent_skill.py b/test/services/test_mpt_agent_skill.py
index 0273c524..88b3dfc6 100644
--- a/test/services/test_mpt_agent_skill.py
+++ b/test/services/test_mpt_agent_skill.py
@@ -63,6 +63,33 @@ class TestMptAgentSkill(unittest.TestCase):
def __exit__(self, exc_type, exc_value, traceback):
return False
+ def test_toml_literal_provider_and_multiline_key_arrays(self):
+ # These are valid TOML configurations understood by the backend loader.
+ for text in (
+ "[app]\nllm_provider = 'ollama'\npexels_api_keys = [\n 'fixture#key', # comment\n]\n",
+ '[app]\n"llm_provider" = "ollama"\npexels_api_keys = ["fixture#key"]\n',
+ ):
+ with self.subTest(text=text), tempfile.TemporaryDirectory() as directory:
+ config_path = Path(directory) / "config.toml"
+ config_path.write_text(text, encoding="utf-8")
+ with patch.dict(os.environ, {}, clear=True):
+ self.assertEqual(mpt_agent.reuse_existing_llm_provider(config_path), "ollama")
+ self.assertEqual(mpt_agent.missing_config(config_path, ["--video-source", "local", "--video-materials", directory]), ("ollama", []))
+ with patch.object(mpt_agent, "_validate_pexels_key", return_value="valid") as validate:
+ self.assertTrue(mpt_agent.validate_pexels_config(config_path, []))
+ validate.assert_called_once_with("fixture#key")
+ self.assertEqual(config_path.read_text(encoding="utf-8"), text)
+
+ def test_config_reader_uses_app_table_not_unrelated_provider_fields(self):
+ text = "[other]\nllm_provider = 'moonshot'\n[app]\nllm_provider = 'ollama'\n"
+ self.assertEqual(mpt_agent._plain_config_value(text, "llm_provider"), "ollama")
+
+ def test_config_reader_reports_invalid_toml_without_echoing_contents(self):
+ with self.assertRaises(mpt_agent.SkillError) as error:
+ mpt_agent._plain_config_value("[app]\nllm_provider = 'fixture\n", "llm_provider")
+ self.assertNotIn("fixture", str(error.exception))
+ self.assertIn("TOML", str(error.exception))
+
def test_skill_runs_helper_from_its_working_directory(self):
"""确保 Windows Agent 不会在命令中嵌入易被破坏的绝对路径。"""
text = SKILL_DOCUMENT.read_text(encoding="utf-8")