2026-04-04 16:29:37 +00:00
|
|
|
from fastapi import APIRouter, HTTPException
|
2026-03-31 04:31:47 +00:00
|
|
|
|
2026-04-13 08:36:58 +00:00
|
|
|
from core.speech_service import inspect_speech_model_status
|
2026-03-31 04:31:47 +00:00
|
|
|
from core.utils import _get_default_system_timezone
|
2026-04-04 16:29:37 +00:00
|
|
|
from schemas.system import SystemTemplatesUpdateRequest
|
2026-04-14 02:04:12 +00:00
|
|
|
from services.platform_settings_service import get_platform_settings_snapshot, get_speech_runtime_settings
|
2026-03-31 04:31:47 +00:00
|
|
|
from services.template_service import (
|
|
|
|
|
get_agent_md_templates,
|
|
|
|
|
get_topic_presets,
|
|
|
|
|
update_agent_md_templates,
|
|
|
|
|
update_topic_presets,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
@router.get("/api/system/defaults")
|
|
|
|
|
def get_system_defaults():
|
|
|
|
|
md_templates = get_agent_md_templates()
|
|
|
|
|
platform_settings = get_platform_settings_snapshot()
|
|
|
|
|
speech_settings = get_speech_runtime_settings()
|
2026-04-13 08:36:58 +00:00
|
|
|
model_status = inspect_speech_model_status()
|
2026-03-31 04:31:47 +00:00
|
|
|
return {
|
|
|
|
|
"templates": md_templates,
|
|
|
|
|
"limits": {
|
|
|
|
|
"upload_max_mb": platform_settings.upload_max_mb,
|
|
|
|
|
},
|
|
|
|
|
"workspace": {
|
|
|
|
|
"download_extensions": list(platform_settings.workspace_download_extensions),
|
|
|
|
|
"allowed_attachment_extensions": list(platform_settings.allowed_attachment_extensions),
|
|
|
|
|
},
|
|
|
|
|
"bot": {
|
|
|
|
|
"system_timezone": _get_default_system_timezone(),
|
|
|
|
|
},
|
|
|
|
|
"chat": {
|
|
|
|
|
"pull_page_size": platform_settings.chat_pull_page_size,
|
|
|
|
|
"page_size": platform_settings.page_size,
|
|
|
|
|
"command_auto_unlock_seconds": platform_settings.command_auto_unlock_seconds,
|
|
|
|
|
},
|
2026-04-14 02:04:12 +00:00
|
|
|
"topic_presets": get_topic_presets()["presets"],
|
2026-03-31 04:31:47 +00:00
|
|
|
"speech": {
|
|
|
|
|
"enabled": speech_settings["enabled"],
|
|
|
|
|
"model": speech_settings["model"],
|
|
|
|
|
"device": speech_settings["device"],
|
|
|
|
|
"max_audio_seconds": speech_settings["max_audio_seconds"],
|
|
|
|
|
"default_language": speech_settings["default_language"],
|
2026-04-13 08:36:58 +00:00
|
|
|
"ready": model_status["ready"],
|
|
|
|
|
"message": model_status["message"],
|
|
|
|
|
"expected_path": model_status["expected_path"],
|
2026-03-31 04:31:47 +00:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@router.get("/api/system/templates")
|
|
|
|
|
def get_system_templates():
|
|
|
|
|
return {
|
|
|
|
|
"agent_md_templates": get_agent_md_templates(),
|
|
|
|
|
"topic_presets": get_topic_presets(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@router.put("/api/system/templates")
|
|
|
|
|
def update_system_templates(payload: SystemTemplatesUpdateRequest):
|
|
|
|
|
if payload.agent_md_templates is not None:
|
|
|
|
|
update_agent_md_templates(payload.agent_md_templates.model_dump())
|
|
|
|
|
|
|
|
|
|
if payload.topic_presets is not None:
|
|
|
|
|
try:
|
|
|
|
|
update_topic_presets(payload.topic_presets)
|
|
|
|
|
except ValueError as exc:
|
|
|
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"status": "ok",
|
|
|
|
|
"agent_md_templates": get_agent_md_templates(),
|
|
|
|
|
"topic_presets": get_topic_presets(),
|
|
|
|
|
}
|