front/xhs-agent-desktop/engine/xhs_bridge/publish_scheduler.py
zzh 5a26ae0048 feat: 小红书模块迁移、登录重构与 xhs-agent-desktop 桌面 Agent
- 新增小红书前端模块(启动服务、内容分析、爆款创作、发布记录、技能卡片、拟人设置、AI 助手)

- 新增 xhs-agent-desktop 独立桌面 Agent,对接 OMS 任务调度

- 登录页重构,整合微信登录与 OMS JWT 认证

- 订单、渠道、用户中心等页面与 API 增强

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 16:13:13 +08:00

65 lines
1.6 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from xhs_bridge.human_guard import PUBLISH_TOOLS
from xhs_bridge.publish_history_store import PublishHistoryStore
if TYPE_CHECKING:
from xhs_bridge.gui.app_context import AppContext
def process_due_scheduled(ctx: AppContext) -> None:
"""检查并执行到期的定时发布(每次最多一条)。"""
if ctx.is_task_running():
return
store = PublishHistoryStore()
due = store.list_due_scheduled()
if not due:
return
rec = due[0]
if rec.tool_name not in PUBLISH_TOOLS:
store.mark_published(rec.id, "未知发布类型", success=False)
return
status = ctx.service().status()
if not status.get("engine_running"):
return
if not store.mark_publishing(rec.id):
return
arguments = dict(rec.arguments or {})
record_id = rec.id
tool_name = rec.tool_name
def task():
return ctx.service().call_tool(
tool_name,
arguments,
check_license=True,
on_progress=None,
record_history=False,
)
def on_ok(result: object) -> None:
text = str(result)
ok = "❌" not in text and "失败" not in text
store.mark_published(record_id, text, success=ok)
def on_err(msg: str) -> None:
store.mark_published(record_id, msg, success=False)
ctx.run_task(
task,
on_ok,
on_err=on_err,
title=f"定时发布 — {tool_name}",
request={"record_id": record_id, "arguments": arguments},
log_response=True,
set_busy=False,
block_if_busy=False,
)