refactor(trigger): name CLI trigger source as local

maintainer edit: cron is also a trigger source, so keep the new CLI-delivered source explicitly named as local trigger across backend, WebUI, docs, and tests.
This commit is contained in:
chengyongru authored and Xubin Ren committed 2026-07-02 13:32:46 +08:00
1 parent 1ed2c9a213
commit 2ebf5c4972
40 files changed
+353 -253

No files matched your search

+24 -24
View File
@@ -26,7 +26,7 @@ from websockets.http11 import Response
from nanobot.command.builtin import builtin_command_palette
from nanobot.cron.session_turns import is_bound_cron_job
from nanobot.cron.types import CronJob, CronSchedule
from nanobot.triggers.types import ExternalTrigger
from nanobot.triggers.local_types import LocalTrigger
from nanobot.utils.subagent_channel_display import scrub_subagent_messages_for_channel
from nanobot.webui.file_preview import WebUIFilePreviewError, file_preview_payload
from nanobot.webui.gateway_tokens import GatewayTokenStore, token_response_payload
@@ -90,7 +90,7 @@ if TYPE_CHECKING:
from nanobot.bus.queue import MessageBus
from nanobot.cron.service import CronService
from nanobot.session.manager import SessionManager
from nanobot.triggers.store import ExternalTriggerStore
from nanobot.triggers.local_store import LocalTriggerStore
def _decode_api_key(raw_key: str) -> str | None:
@@ -155,7 +155,7 @@ class GatewayHTTPHandler:
skills_workspace_path: Path,
disabled_skills: set[str] | None = None,
cron_service: CronService | None = None,
external_trigger_store: ExternalTriggerStore | None = None,
local_trigger_store: LocalTriggerStore | None = None,
cron_pending_job_ids: Callable[[str], set[str]] | None = None,
log: Any = logger,
) -> None:
@@ -170,7 +170,7 @@ class GatewayHTTPHandler:
self.skills_workspace_path = skills_workspace_path
self.disabled_skills = disabled_skills or set()
self.cron_service = cron_service
self.external_trigger_store = external_trigger_store
self.local_trigger_store = local_trigger_store
self.cron_pending_job_ids = cron_pending_job_ids
self._log = log
self._runtime_surface = runtime_surface
@@ -494,7 +494,7 @@ class GatewayHTTPHandler:
session_automations_payload(
self.cron_service,
decoded_key,
external_trigger_store=self.external_trigger_store,
local_trigger_store=self.local_trigger_store,
pending_job_ids=pending_job_ids,
)
)
@@ -514,7 +514,7 @@ class GatewayHTTPHandler:
automation_jobs = session_automation_jobs(
self.cron_service,
decoded_key,
external_trigger_store=self.external_trigger_store,
local_trigger_store=self.local_trigger_store,
)
if automation_jobs and delete_automations not in {"1", "true", "yes"}:
return _http_json_response(
@@ -526,9 +526,9 @@ class GatewayHTTPHandler:
)
if automation_jobs:
for job in automation_jobs:
if isinstance(job, ExternalTrigger):
if self.external_trigger_store is not None:
self.external_trigger_store.delete(job.id)
if isinstance(job, LocalTrigger):
if self.local_trigger_store is not None:
self.local_trigger_store.delete(job.id)
elif self.cron_service is not None:
self.cron_service.remove_job(job.id)
deleted = self.session_manager.delete_session(decoded_key)
@@ -567,7 +567,7 @@ class GatewayHTTPHandler:
return _http_json_response(
all_automations_payload(
self.cron_service,
external_trigger_store=self.external_trigger_store,
local_trigger_store=self.local_trigger_store,
session_manager=self.session_manager,
pending_job_ids=self._pending_cron_job_ids_for_all(),
)
@@ -580,16 +580,16 @@ class GatewayHTTPHandler:
) -> Response:
if not self.check_api_token(request):
return _http_error(401, "Unauthorized")
if self.cron_service is None and self.external_trigger_store is None:
if self.cron_service is None and self.local_trigger_store is None:
return _http_error(503, "automation service unavailable")
query = _parse_query(request.path)
job_id = (_query_first(query, "id") or _query_first(query, "job_id") or "").strip()
if not job_id:
return _http_error(400, "missing automation id")
trigger = self.external_trigger_store.get(job_id) if self.external_trigger_store else None
trigger = self.local_trigger_store.get(job_id) if self.local_trigger_store else None
if trigger is not None:
return self._handle_external_trigger_action(request, action, trigger)
return self._handle_local_trigger_action(request, action, trigger)
if self.cron_service is None:
return _http_error(404, "automation not found")
@@ -638,34 +638,34 @@ class GatewayHTTPHandler:
return self._handle_webui_automations(request)
def _handle_external_trigger_action(
def _handle_local_trigger_action(
self,
request: WsRequest,
action: str,
trigger: ExternalTrigger,
trigger: LocalTrigger,
) -> Response:
if self.external_trigger_store is None:
if self.local_trigger_store is None:
return _http_error(503, "trigger service unavailable")
if action == "enable":
if self.external_trigger_store.enable(trigger.id, enabled=True) is None:
if self.local_trigger_store.enable(trigger.id, enabled=True) is None:
return _http_error(404, "automation not found")
elif action == "disable":
if self.external_trigger_store.enable(trigger.id, enabled=False) is None:
if self.local_trigger_store.enable(trigger.id, enabled=False) is None:
return _http_error(404, "automation not found")
elif action == "delete":
if not self.external_trigger_store.delete(trigger.id):
if not self.local_trigger_store.delete(trigger.id):
return _http_error(404, "automation not found")
elif action == "run":
return _http_error(409, "external trigger requires a CLI message")
return _http_error(409, "local trigger requires a CLI message")
elif action == "update":
values = _automation_values_from_request(request)
if values is None:
return _http_error(400, "invalid automation update payload")
parsed = _parse_external_trigger_update(values)
parsed = _parse_local_trigger_update(values)
if isinstance(parsed, str):
return _http_error(400, parsed)
if parsed:
if self.external_trigger_store.update(trigger.id, **parsed) is None:
if self.local_trigger_store.update(trigger.id, **parsed) is None:
return _http_error(404, "automation not found")
else:
return _http_error(404, "unknown automation action")
@@ -884,7 +884,7 @@ def _parse_automation_update(
return update
def _parse_external_trigger_update(values: dict[str, Any]) -> dict[str, Any] | str:
def _parse_local_trigger_update(values: dict[str, Any]) -> dict[str, Any] | str:
update: dict[str, Any] = {}
if "name" in values:
raw_name = values.get("name")
@@ -896,7 +896,7 @@ def _parse_external_trigger_update(values: dict[str, Any]) -> dict[str, Any] | s
update["name"] = name
forbidden = [key for key in ("message", "schedule") if key in values]
if forbidden:
return "external trigger updates only support name"
return "local trigger updates only support name"
return update