mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat: support install browser in chat
This commit is contained in:
@@ -487,6 +487,19 @@ class CloudClient(LinkAIClient):
|
||||
session_id = f"session_{session_id}"
|
||||
logger.info(f"[CloudClient] on_chat: session={session_id}, channel={channel_type}, query={query[:80]}")
|
||||
|
||||
# Intercept cow/slash commands before the agent runs
|
||||
try:
|
||||
from plugins import PluginManager
|
||||
mgr = PluginManager()
|
||||
plugin = mgr.plugins.get("cow_cli")
|
||||
if plugin and hasattr(plugin, "execute"):
|
||||
result = plugin.execute(query, session_id=session_id)
|
||||
if result is not None:
|
||||
send_chunk_fn({"chunk_type": "content", "delta": result, "segment_id": 0})
|
||||
return
|
||||
except Exception as e:
|
||||
logger.warning(f"[CloudClient] cow_cli intercept failed: {e}")
|
||||
|
||||
svc = self.chat_service
|
||||
if svc is None:
|
||||
raise RuntimeError("ChatService not available")
|
||||
@@ -629,9 +642,9 @@ def get_deployment_id() -> str:
|
||||
|
||||
|
||||
def get_website_base_url() -> str:
|
||||
"""Return the public URL prefix that maps to the workspace websites/ dir.
|
||||
"""Return the URL prefix that maps to the workspace websites/ dir.
|
||||
|
||||
Returns empty string when cloud deployment is not configured.
|
||||
Do nothing when in local env.
|
||||
"""
|
||||
deployment_id = get_deployment_id()
|
||||
if not deployment_id:
|
||||
@@ -648,6 +661,42 @@ def get_website_base_url() -> str:
|
||||
return f"https://app.{domain}/{deployment_id}"
|
||||
|
||||
|
||||
# Subdir under websites/ used by the send tool
|
||||
COW_SEND_WEB_SUBDIR = "cow-send"
|
||||
|
||||
|
||||
def copy_send_file(src_path: str, workspace_root: str) -> str:
|
||||
"""Copy *src_path* into ``websites/cow-send/`` and return its URL.
|
||||
|
||||
Returns empty string in local env.
|
||||
"""
|
||||
import shutil
|
||||
import uuid
|
||||
|
||||
from common.utils import expand_path
|
||||
|
||||
base = get_website_base_url()
|
||||
if not base or not src_path or not os.path.isfile(src_path):
|
||||
return ""
|
||||
ws = os.path.abspath(expand_path(workspace_root))
|
||||
send_dir = os.path.join(ws, "websites", COW_SEND_WEB_SUBDIR)
|
||||
try:
|
||||
os.makedirs(send_dir, exist_ok=True)
|
||||
except OSError:
|
||||
return ""
|
||||
ext = os.path.splitext(src_path)[1].lower()
|
||||
if len(ext) > 12 or not ext.replace(".", "").isalnum():
|
||||
ext = ""
|
||||
dest_name = f"{uuid.uuid4().hex}{ext}"
|
||||
dest_path = os.path.join(send_dir, dest_name)
|
||||
try:
|
||||
shutil.copy2(src_path, dest_path)
|
||||
except OSError as e:
|
||||
logger.warning(f"[cloud] copy_send_file: copy failed: {e}")
|
||||
return ""
|
||||
return f"{base}/{COW_SEND_WEB_SUBDIR}/{dest_name}"
|
||||
|
||||
|
||||
def build_website_prompt(workspace_dir: str) -> list:
|
||||
"""Build system prompt lines for cloud website/file sharing rules.
|
||||
|
||||
@@ -668,8 +717,8 @@ def build_website_prompt(workspace_dir: str) -> list:
|
||||
f" - 例如: `websites/my-app/index.html` → `{base_url}/my-app/index.html`",
|
||||
"",
|
||||
"2. **生成文件分享** (PPT、PDF、图片、音视频等): 当你为用户生成了需要下载或查看的文件时,**可以**将文件保存到 `websites/` 目录中",
|
||||
f" - 例如: 生成的PPT保存到 `websites/files/report.pptx` → 下载链接为 `{base_url}/files/report.pptx`",
|
||||
" - 你仍然可以同时使用 `send` 工具发送文件(在飞书、钉钉等IM渠道中有效),但**必须同时在回复文本中提供下载链接**作为兜底,因为部分渠道(如网页端)无法通过 send 接收本地文件",
|
||||
f" - 例如: 生成的PPT保存到 `websites/files/report.pptx` → 下载链接为 `{base_url}/files/report.pptx`",
|
||||
" - 你仍然可以同时使用 `send` 工具发送文件(在微信、飞书、钉钉、web等渠道中有效),但**必须同时在回复文本中提供下载链接**作为兜底,因为部分渠道无法通过 send 接收本地文件",
|
||||
"",
|
||||
"3. **必须发送链接**: 无论是网页还是文件,生成后**必须将完整的访问/下载链接直接写在回复文本中发送给用户**",
|
||||
"",
|
||||
|
||||
Reference in New Issue
Block a user