sync update from LAN repo (source ji @ 85078a31)
This commit is contained in:
1 parent
5d6627af50
commit
e602d88695
864 files changed
+99150
-6346
No files matched your search
@@ -0,0 +1,77 @@
|
||||
"""Seed the built-in public-document agent and its orchestration skill.
|
||||
|
||||
The document engine itself is the separately packaged ``gongwen-assistant``
|
||||
skill. It contains the offline DOCX implementation and is intentionally not
|
||||
duplicated here. This seed provides the small, release-tracked workflow layer
|
||||
that makes a normal agent conversation use that engine consistently.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from deerflow.config.paths import get_paths
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
GONGWEN_AGENT_ID = "gongwen-document-assistant"
|
||||
GONGWEN_WORKFLOW_SKILL = "gongwen-workflow"
|
||||
_ASSETS_DIR = Path(__file__).parent / "_gongwen_seed_assets"
|
||||
_SEED_FILES: tuple[str, ...] = ("config.yaml", "SOUL.md")
|
||||
|
||||
|
||||
def _skills_public_dir() -> Path:
|
||||
from deerflow.skills.storage import get_or_new_skill_storage
|
||||
|
||||
return Path(get_or_new_skill_storage().get_skills_root_path()) / "public"
|
||||
|
||||
|
||||
def _seed_agent() -> bool:
|
||||
agent_dir = get_paths().agent_dir(GONGWEN_AGENT_ID)
|
||||
if agent_dir.exists():
|
||||
return False
|
||||
source = _ASSETS_DIR / GONGWEN_AGENT_ID
|
||||
if not source.is_dir():
|
||||
logger.error("Missing public-document agent seed assets at %s", source)
|
||||
return False
|
||||
agent_dir.mkdir(parents=True, exist_ok=True)
|
||||
for filename in _SEED_FILES:
|
||||
asset = source / filename
|
||||
if asset.is_file():
|
||||
(agent_dir / filename).write_bytes(asset.read_bytes())
|
||||
return True
|
||||
|
||||
|
||||
def _seed_workflow_skill() -> bool:
|
||||
source = _ASSETS_DIR / "skills" / GONGWEN_WORKFLOW_SKILL
|
||||
if not (source / "SKILL.md").is_file():
|
||||
logger.error("Missing public-document workflow skill seed asset at %s", source)
|
||||
return False
|
||||
destination = _skills_public_dir() / GONGWEN_WORKFLOW_SKILL
|
||||
if destination.exists():
|
||||
return False
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copytree(source, destination)
|
||||
return True
|
||||
|
||||
|
||||
def ensure_gongwen_agent() -> bool:
|
||||
"""Create missing built-in public-document assets without overwriting edits."""
|
||||
created_agent = False
|
||||
try:
|
||||
created_agent = _seed_agent()
|
||||
if created_agent:
|
||||
logger.info("Seeded built-in public-document agent '%s'", GONGWEN_AGENT_ID)
|
||||
except Exception:
|
||||
logger.exception("Failed to seed built-in public-document agent")
|
||||
try:
|
||||
if _seed_workflow_skill():
|
||||
logger.info("Seeded built-in public-document workflow skill '%s'", GONGWEN_WORKFLOW_SKILL)
|
||||
except Exception:
|
||||
logger.exception("Failed to seed built-in public-document workflow skill")
|
||||
return created_agent
|
||||
|
||||
|
||||
__all__ = ["GONGWEN_AGENT_ID", "GONGWEN_WORKFLOW_SKILL", "ensure_gongwen_agent"]
|
||||
Reference in new issue
Block a user