mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 07:13:17 +08:00
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。 Made-with: Cursor
26 lines
1.3 KiB
Python
26 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from .config import resolve_webhooks_plugin_config
|
|
from .http import TaskFlowWebhookTarget, create_taskflow_webhook_request_handler
|
|
|
|
|
|
def register_webhook_routes(api) -> None:
|
|
routes = resolve_webhooks_plugin_config(plugin_config=getattr(api, "plugin_config", {}) or {})
|
|
if not routes:
|
|
return
|
|
targets_by_path: dict[str, list[TaskFlowWebhookTarget]] = {}
|
|
handler = create_taskflow_webhook_request_handler(cfg=getattr(api, "config", {}) or {}, targets_by_path=targets_by_path)
|
|
for route in routes:
|
|
task_flow = api.runtime.task_flow.bind_session(session_key=route.session_key)
|
|
target = TaskFlowWebhookTarget(
|
|
route_id=route.route_id,
|
|
path=route.path,
|
|
secret_input=route.secret,
|
|
secret_config_path=f"plugins.entries.webhooks.routes.{route.route_id}.secret",
|
|
default_controller_id=route.controller_id,
|
|
task_flow=task_flow,
|
|
)
|
|
targets_by_path.setdefault(target.path, []).append(target)
|
|
api.register_http_route(path=target.path, auth="plugin", match="exact", replace_existing=True, handler=handler)
|
|
api.logger.info(f"[webhooks] registered route {route.route_id} on {route.path} for session {route.session_key}")
|
|
|