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: 现在前端可能被修改过,导致对于定时消息处理存在问题,会把cron message当成普通的chat.final处理

Haowei_Du0361472bcc9d
diff --git a/jiuwenclaw/channel/web_channel.py b/jiuwenclaw/channel/web_channel.py
index 70dd6e1655..e500f533c9 100644
--- a/jiuwenclaw/channel/web_channel.py
+++ b/jiuwenclaw/channel/web_channel.py
@@ -320,6 +320,11 @@ class WebChannel(BaseChannel):
"session_id": msg.session_id,
"content": content,
}
+ # 定时任务推送:附带 cron 元数据,供前端识别并替换占位消息(避免误写入流式气泡)
+ if event_name == "chat.final":
+ cron_extra = msg.payload.get("cron")
+ if isinstance(cron_extra, dict):
+ payload["cron"] = cron_extra
else:
# payload 不是 dict,尝试从 params 提取
content = str((msg.params or {}).get("content", "") or "")
diff --git a/jiuwenclaw/resources/config.yaml b/jiuwenclaw/resources/config.yaml
index 7ae6310daa..6fcf40d24a 100644
--- a/jiuwenclaw/resources/config.yaml
+++ b/jiuwenclaw/resources/config.yaml
@@ -55,7 +55,7 @@ channels:
encrypt_key:
verification_token:
allow_from:
- enable_streaming: true
+ enable_streaming: false
enabled: false
xiaoyi:
# 华为小艺 A2A 配置
@@ -172,6 +172,13 @@ permissions:
mcp_free_search: "allow"
mcp_paid_search: "allow"
mcp_fetch_webpage: "allow"
+ cron_list_jobs: "allow"
+ cron_get_job: "allow"
+ cron_create_job: "allow"
+ cron_update_job: "allow"
+ cron_delete_job: "allow"
+ cron_toggle_job: "allow"
+ cron_preview_job: "allow"
# 外部目录访问 (访问 workspace 外路径时的权限)
external_directory:
diff --git a/jiuwenclaw/web/src/hooks/useWebSocket.ts b/jiuwenclaw/web/src/hooks/useWebSocket.ts
index 7300404bf0..5886a76817 100644
--- a/jiuwenclaw/web/src/hooks/useWebSocket.ts
+++ b/jiuwenclaw/web/src/hooks/useWebSocket.ts
@@ -553,24 +553,75 @@ export function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {
if (!shouldHandleSessionEvent(payload)) return;
const content = normalizeFinalContent(payload);
const { currentStreamId, messages } = useChatStore.getState();
- if (currentStreamId) {
- updateMessage(currentStreamId, { content, isStreaming: false });
+ const payloadSessionId =
+ typeof payload.session_id === 'string' ? payload.session_id.trim() : '';
+ // 仅当有明确会话绑定时才把 final 合并进当前流式气泡。
+ // 定时任务等广播的 session_id 为空/null,若仍走 currentStreamId 会写到错误气泡甚至“无可见更新”。
+ const streamId = currentStreamId;
+ if (streamId && payloadSessionId) {
+ updateMessage(streamId, { content, isStreaming: false });
stopStreaming();
if (content && !content.includes('MEDIA:')) {
- handleTtsPlayback(currentStreamId, content);
+ handleTtsPlayback(streamId, content);
}
return;
}
if (content) {
+ const cronMeta = payload.cron as Record<string, unknown> | undefined;
+ const cronRunId =
+ typeof cronMeta?.run_id === 'string' ? cronMeta.run_id.trim() : '';
+ const isCronPlaceholderContent = /^\[cron\].*正在执行中/.test(content);
+
+ // 正式结果:替换同 run_id 的占位气泡,或最近的 [cron]…正在执行中…
+ if (!isCronPlaceholderContent) {
+ let placeholderId: string | null = null;
+ if (cronRunId) {
+ const byRun = messages.find((m) => m.id === `cron-placeholder-${cronRunId}`);
+ if (byRun) placeholderId = byRun.id;
+ }
+ if (!placeholderId) {
+ for (let i = messages.length - 1; i >= 0; i -= 1) {
+ const msg = messages[i];
+ if (msg.role !== 'assistant' || typeof msg.content !== 'string') continue;
+ if (/^\[cron\].*正在执行中/.test(msg.content)) {
+ placeholderId = msg.id;
+ break;
+ }
+ }
+ }
+ if (placeholderId) {
+ updateMessage(placeholderId, { content, isStreaming: false });
+ if (!content.includes('MEDIA:')) {
+ handleTtsPlayback(placeholderId, content);
+ }
+ return;
+ }
+ }
+
+ const messageId =
+ isCronPlaceholderContent && cronRunId
+ ? `cron-placeholder-${cronRunId}`
+ : cronRunId && !isCronPlaceholderContent
+ ? `cron-final-${cronRunId}`
+ : `msg-${Date.now()}`;
+
+ const existing = messages.find((m) => m.id === messageId);
+ if (existing) {
+ if (existing.content === content) {
+ return;
+ }
+ updateMessage(messageId, { content, isStreaming: false });
+ if (!content.includes('MEDIA:')) {
+ handleTtsPlayback(messageId, content);
+ }
+ return;
+ }
+
// 去重:若上一条已是相同内容的助手消息(同一回复被收到两次),不再追加
const last = messages[messages.length - 1];
- if (
- last?.role === 'assistant' &&
- last.content === content
- ) {
+ if (last?.role === 'assistant' && last.content === content) {
return;
}
- const messageId = `msg-${Date.now()}`;
addMessage({
id: messageId,
role: 'assistant',