|
@@ -1,21 +1,18 @@
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
-import logging
|
|
|
|
|
import os
|
|
import os
|
|
|
from collections.abc import Mapping
|
|
from collections.abc import Mapping
|
|
|
from dataclasses import dataclass
|
|
from dataclasses import dataclass
|
|
|
from typing import Any
|
|
from typing import Any
|
|
|
|
|
|
|
|
-from gateway.core.channels.backends.echo_executor import EchoExecutorBackend
|
|
|
|
|
from gateway.core.channels.backends.memory_trace import MemoryTraceBackend
|
|
from gateway.core.channels.backends.memory_trace import MemoryTraceBackend
|
|
|
from gateway.core.channels.feishu.connector import FeishuConnector, WebhookParseError
|
|
from gateway.core.channels.feishu.connector import FeishuConnector, WebhookParseError
|
|
|
|
|
+from gateway.core.channels.feishu.http_run_executor import FeishuHttpRunApiExecutor
|
|
|
from gateway.core.channels.feishu.identity import DefaultUserIdentityResolver
|
|
from gateway.core.channels.feishu.identity import DefaultUserIdentityResolver
|
|
|
from gateway.core.channels.feishu.router import FeishuMessageRouter
|
|
from gateway.core.channels.feishu.router import FeishuMessageRouter
|
|
|
from gateway.core.channels.manager import ChannelRegistry
|
|
from gateway.core.channels.manager import ChannelRegistry
|
|
|
from gateway.core.channels.types import RouteResult
|
|
from gateway.core.channels.types import RouteResult
|
|
|
|
|
|
|
|
-logger = logging.getLogger(__name__)
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
@dataclass
|
|
|
class FeishuChannelConfig:
|
|
class FeishuChannelConfig:
|
|
@@ -26,14 +23,17 @@ class FeishuChannelConfig:
|
|
|
auto_create_trace: bool = True
|
|
auto_create_trace: bool = True
|
|
|
workspace_prefix: str = "feishu"
|
|
workspace_prefix: str = "feishu"
|
|
|
default_agent_type: str = "personal_assistant"
|
|
default_agent_type: str = "personal_assistant"
|
|
|
- echo_replies: bool = True
|
|
|
|
|
- echo_prefix: str = "[Gateway] "
|
|
|
|
|
dispatch_reactions: bool = False
|
|
dispatch_reactions: bool = False
|
|
|
dispatch_card_actions: bool = False
|
|
dispatch_card_actions: bool = False
|
|
|
|
|
+ agent_api_base_url: str = "http://127.0.0.1:8000"
|
|
|
|
|
+ agent_run_model: str = "gpt-4o"
|
|
|
|
|
+ agent_run_max_iterations: int = 200
|
|
|
|
|
+ agent_run_temperature: float = 0.3
|
|
|
|
|
+ feishu_run_notify_on_submit: bool = True
|
|
|
|
|
|
|
|
|
|
|
|
|
class FeishuChannelManager(ChannelRegistry):
|
|
class FeishuChannelManager(ChannelRegistry):
|
|
|
- """飞书渠道:组装连接器、Trace 后端、执行器与消息路由;继承 ``ChannelRegistry`` 的注册/启停能力。"""
|
|
|
|
|
|
|
+ """飞书渠道:组装连接器、Trace 后端、HTTP Run API 执行器与消息路由。"""
|
|
|
|
|
|
|
|
def __init__(self, config: FeishuChannelConfig | None = None) -> None:
|
|
def __init__(self, config: FeishuChannelConfig | None = None) -> None:
|
|
|
super().__init__()
|
|
super().__init__()
|
|
@@ -45,11 +45,16 @@ class FeishuChannelManager(ChannelRegistry):
|
|
|
timeout=self._config.http_timeout,
|
|
timeout=self._config.http_timeout,
|
|
|
)
|
|
)
|
|
|
self._trace_backend = MemoryTraceBackend()
|
|
self._trace_backend = MemoryTraceBackend()
|
|
|
- self._executor = EchoExecutorBackend(
|
|
|
|
|
- prefix=self._config.echo_prefix,
|
|
|
|
|
- enabled=self._config.echo_replies,
|
|
|
|
|
- )
|
|
|
|
|
self._identity = DefaultUserIdentityResolver()
|
|
self._identity = DefaultUserIdentityResolver()
|
|
|
|
|
+ self._executor = FeishuHttpRunApiExecutor(
|
|
|
|
|
+ base_url=self._config.agent_api_base_url,
|
|
|
|
|
+ timeout=self._config.http_timeout,
|
|
|
|
|
+ identity_resolver=self._identity,
|
|
|
|
|
+ model=self._config.agent_run_model,
|
|
|
|
|
+ max_iterations=self._config.agent_run_max_iterations,
|
|
|
|
|
+ temperature=self._config.agent_run_temperature,
|
|
|
|
|
+ notify_on_submit=self._config.feishu_run_notify_on_submit,
|
|
|
|
|
+ )
|
|
|
self._router = FeishuMessageRouter(
|
|
self._router = FeishuMessageRouter(
|
|
|
connector=self._connector,
|
|
connector=self._connector,
|
|
|
trace_backend=self._trace_backend,
|
|
trace_backend=self._trace_backend,
|
|
@@ -81,10 +86,15 @@ class FeishuChannelManager(ChannelRegistry):
|
|
|
FeishuChannelConfig(
|
|
FeishuChannelConfig(
|
|
|
feishu_http_base_url=os.getenv("FEISHU_HTTP_BASE_URL", "http://127.0.0.1:4380").strip(),
|
|
feishu_http_base_url=os.getenv("FEISHU_HTTP_BASE_URL", "http://127.0.0.1:4380").strip(),
|
|
|
http_timeout=float(os.getenv("FEISHU_HTTP_TIMEOUT", "120")),
|
|
http_timeout=float(os.getenv("FEISHU_HTTP_TIMEOUT", "120")),
|
|
|
- echo_replies=os.getenv("CHANNELS_ECHO_REPLIES", "true").lower() in ("1", "true", "yes"),
|
|
|
|
|
- echo_prefix=os.getenv("CHANNELS_ECHO_PREFIX", "[Gateway] "),
|
|
|
|
|
dispatch_reactions=os.getenv("CHANNELS_DISPATCH_REACTIONS", "false").lower() in ("1", "true", "yes"),
|
|
dispatch_reactions=os.getenv("CHANNELS_DISPATCH_REACTIONS", "false").lower() in ("1", "true", "yes"),
|
|
|
- dispatch_card_actions=os.getenv("CHANNELS_DISPATCH_CARD_ACTIONS", "false").lower() in ("1", "true", "yes"),
|
|
|
|
|
|
|
+ dispatch_card_actions=os.getenv("CHANNELS_DISPATCH_CARD_ACTIONS", "false").lower()
|
|
|
|
|
+ in ("1", "true", "yes"),
|
|
|
|
|
+ agent_api_base_url=os.getenv("GATEWAY_AGENT_API_BASE_URL", "http://127.0.0.1:8000").strip(),
|
|
|
|
|
+ agent_run_model=os.getenv("FEISHU_AGENT_RUN_MODEL", "gpt-4o").strip(),
|
|
|
|
|
+ agent_run_max_iterations=int(os.getenv("FEISHU_AGENT_RUN_MAX_ITERATIONS", "200")),
|
|
|
|
|
+ agent_run_temperature=float(os.getenv("FEISHU_AGENT_RUN_TEMPERATURE", "0.3")),
|
|
|
|
|
+ feishu_run_notify_on_submit=os.getenv("CHANNELS_FEISHU_RUN_NOTIFY", "true").lower()
|
|
|
|
|
+ in ("1", "true", "yes"),
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
|
|
|