Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: 定时任务通道默认

samast5299bcf0cf81
diff --git a/jiuwenclaw/agentserver/interface.py b/jiuwenclaw/agentserver/interface.py
index a5455fa1b4..b8db1f5928 100644
--- a/jiuwenclaw/agentserver/interface.py
+++ b/jiuwenclaw/agentserver/interface.py
@@ -19,7 +19,7 @@ from openjiuwen.core.session.checkpointer import CheckpointerFactory
from openjiuwen.core.session.checkpointer.checkpointer import CheckpointerConfig
from openjiuwen.core.session.checkpointer.persistence import PersistenceCheckpointerProvider
-from jiuwenclaw.gateway.cron import CronController
+from jiuwenclaw.gateway.cron import CronController, CronTargetChannel
from jiuwenclaw.utils import get_root_dir, logger, USER_WORKSPACE_DIR
from jiuwenclaw.config import get_config
from jiuwenclaw.agentserver.react_agent import JiuClawReActAgent
@@ -398,8 +398,15 @@ class JiuWenClaw:
self._instance.ability_manager.remove(tool.name)
# 定时工具
- if session_id.split('_')[0] not in ["heartbeat", "cron"]:
+ channel = session_id.split('_')[0]
+ if channel not in ["heartbeat", "cron"]:
cron_controller = CronController.get_instance()
+
+ if channel == "feishu":
+ cron_controller.set_target_channel(CronTargetChannel.FEISHU)
+ if channel == "sess":
+ cron_controller.set_target_channel(CronTargetChannel.WEB)
+
for cron_tool in cron_controller.get_tools():
Runner.resource_mgr.add_tool(cron_tool)
self._instance.ability_manager.add(cron_tool.card)
@@ -920,8 +927,6 @@ class JiuWenClaw:
except Exception as exc:
logger.warning("[JiuWenClaw] supplement: 读取 todo 列表失败: %s", exc)
- # await self._register_runtime_tools(request.session_id, request.params.get("mode", "plan"))
-
query = request.params.get("query", "")
if self._compaction_manager:
self._compaction_manager.add_message("user", query)
diff --git a/jiuwenclaw/channel/base.py b/jiuwenclaw/channel/base.py
index 84c18b337c..a052ecb3b3 100644
--- a/jiuwenclaw/channel/base.py
+++ b/jiuwenclaw/channel/base.py
@@ -4,6 +4,7 @@ import asyncio
import time
from abc import ABC, abstractmethod
from dataclasses import dataclass
+from enum import Enum
from typing import TYPE_CHECKING, Any, Callable, Awaitable
from jiuwenclaw.utils import logger
@@ -13,6 +14,14 @@ if TYPE_CHECKING:
pass
+class ChannelType(str, Enum):
+ """<UNK>"""
+ WEB = "web"
+ FEISHU = "feishu"
+ XIAOYI = "xiaoyi"
+ DINGTALK = "dingtalk"
+
+
@dataclass
class ChannelMetadata:
"""Channel 元数据."""
diff --git a/jiuwenclaw/gateway/cron/controller.py b/jiuwenclaw/gateway/cron/controller.py
index bfdd424cb2..c05a751647 100644
--- a/jiuwenclaw/gateway/cron/controller.py
+++ b/jiuwenclaw/gateway/cron/controller.py
@@ -19,6 +19,10 @@ class CronController:
def __init__(self, *, store: CronJobStore, scheduler: CronSchedulerService) -> None:
self._store = store
self._scheduler = scheduler
+ self._target_channel: CronTargetChannel = CronTargetChannel.WEB
+
+ def set_target_channel(self, channel: CronTargetChannel) -> None:
+ self._target_channel = channel
@classmethod
def get_instance(
@@ -64,10 +68,9 @@ class CronController:
_DESCRIPTION_TIME_KEYWORDS = ("每天", "每周", "每月", "上午", "下午", "早上", "晚上", "凌晨")
- @staticmethod
- def _normalize_targets(raw: Any) -> str:
+ def _normalize_targets(self, raw: Any) -> str:
"""将 targets 规范为 CronTargetChannel 枚举值,非法则默认 web。"""
- s = str(raw or "").strip() or "web"
+ s = str(raw or "").strip() or self._target_channel.value
try:
CronTargetChannel(s)
return s
@@ -103,17 +106,9 @@ class CronController:
enabled = bool(params.get("enabled", True))
description = str(params.get("description") or "")
wake_offset_seconds = params.get("wake_offset_seconds", None)
- raw_targets = params.get("targets") or "web"
+ raw_targets = params.get("targets")
targets = self._normalize_targets(raw_targets)
- # if not targets:
- # from jiuwenclaw.agentserver.request_context import get_current_request
- # req = get_current_request()
- # if req and (req.channel_id or req.session_id):
- # targets = [
- # {"channel_id": req.channel_id or "web", "session_id": req.session_id},
- # ]
-
self._validate_schedule(cron_expr=cron_expr, timezone=timezone)
description = self._normalize_description(description, name)
@@ -193,7 +188,7 @@ class CronController:
"name": name,
"cron_expr": cron_expr,
"timezone": timezone,
- "targets": targets or 'web',
+ "targets": targets,
"enabled": enabled,
"description": description,
}
@@ -240,7 +235,7 @@ class CronController:
func,
) -> Tool:
card = ToolCard(
- id=f"cron_{name}",
+ id=f"cron_{name}_{self._target_channel}",
name=name,
description=description,
input_params=input_params,
@@ -294,7 +289,7 @@ class CronController:
"type": "string",
"enum": [e.value for e in CronTargetChannel],
"description": "推送频道:web=网页, feishu=飞书",
- "default": CronTargetChannel.WEB.value,
+ "default": self._target_channel.value,
},
"enabled": {
"type": "boolean",