mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-11-30 16:02:58 +08:00
fix: 修复自动化日报
This commit is contained in:
1 parent
028e8b6553
commit
fd7d5016a8
4 files changed
+158
-4
No files matched your search
@@ -337,6 +337,19 @@ export class AutomationActionRunner {
|
||||
return { steps, status: 'failed', errorSummary: reportStep.error }
|
||||
}
|
||||
pngPath = result.pngPath
|
||||
const persisted = await this.persistRunReport(input, result)
|
||||
if (persisted.ok) {
|
||||
// 发出去的图就是日报历史里的那一份(同一文件),避免「历史一张、发出去另一张」。
|
||||
pngPath = persisted.pngPath || pngPath
|
||||
} else {
|
||||
/*
|
||||
* 落库失败**不阻断发送**:日报确实生成了、图片已经在手上,把它扣下不发对用户没有任何好处。
|
||||
* 但也**绝不假装没事** —— 失败会写进步骤细节,用户在执行详情里一眼能看见。
|
||||
* 细节文案刻意不带原始错误串(fs 报错常含本地绝对路径),原始错误只进主进程日志。
|
||||
*/
|
||||
reportStep.detail = '日报已生成,但未写入日报历史。'
|
||||
console.warn('[Automation] 日报历史写入失败:', persisted.error)
|
||||
}
|
||||
markSuccess(reportStep, this.now())
|
||||
}
|
||||
|
||||
@@ -369,6 +382,61 @@ export class AutomationActionRunner {
|
||||
return { steps, status: 'success', pngPath }
|
||||
}
|
||||
|
||||
/**
|
||||
* 把「@我生成日报」产出的日报写进**日报历史**。
|
||||
*
|
||||
* 与定时日报共用同一个 `saveGeneratedReport`(同一条历史、同一个日报页),
|
||||
* 唯一差别是 `source: 'automation'` —— 让用户能区分这条日报是谁触发的。
|
||||
*
|
||||
* 为什么必须在这里补:`run()` 只把 PNG 交给发送,图发出去之后**没有任何地方**
|
||||
* 再碰这份日报。此前只有 `runScheduledReport` 落库,于是消息型规则产出的日报
|
||||
* 在日报历史里**从来没存在过**(发出去的那张图成了孤儿)。
|
||||
*
|
||||
* 失败语义与 `runScheduledReport` **刻意不同**:那边发的是历史里的文件、落库是发送的前置,
|
||||
* 所以落库失败即整次失败;这里图片已经在手上,落库失败只降级成一句提示,不阻断发送。
|
||||
*/
|
||||
private async persistRunReport(
|
||||
input: AutomationRunInput,
|
||||
generated: AgentGroupReportResult
|
||||
): Promise<{ ok: boolean; error?: string; pngPath?: string }> {
|
||||
try {
|
||||
const reportContact = this.resolveReportContact(input.conversationId)
|
||||
let contactAvatar = reportContact?.avatar
|
||||
if (!contactAvatar && reportContact?.m_nsUsrName) {
|
||||
try {
|
||||
const avatars = await this.getContactAvatars([reportContact.m_nsUsrName])
|
||||
contactAvatar = avatars[reportContact.m_nsUsrName]
|
||||
} catch (error) {
|
||||
console.warn('[Automation] 日报群头像补全失败:', error)
|
||||
}
|
||||
}
|
||||
const saved = await this.saveGeneratedReport({
|
||||
contactId: reportContact?.md5 || input.conversationId,
|
||||
contactName:
|
||||
generated.groupName || reportContact?.m_nsNickName || input.sourceDisplayName || '群聊',
|
||||
contactAvatar,
|
||||
source: 'automation',
|
||||
dateRange: generated.reportMetadata?.dateRange || scheduledReportRangeLabel('today'),
|
||||
reportDate: generated.reportMetadata?.reportDate,
|
||||
messageCount: generated.messageCount ?? generated.reportMetadata?.messageCount ?? 0,
|
||||
generatedAt: new Date(this.now()).toISOString(),
|
||||
htmlPath: generated.htmlPath,
|
||||
pngPath: generated.pngPath,
|
||||
duration: generated.duration,
|
||||
modelName: generated.modelName,
|
||||
tokenUsage: generated.tokenUsage,
|
||||
reportSnapshot: generated.reportSnapshot,
|
||||
reportMetadata: generated.reportMetadata
|
||||
})
|
||||
if (!saved.success) {
|
||||
return { ok: false, error: saved.error || '日报历史保存失败' }
|
||||
}
|
||||
return { ok: true, ...(saved.record?.pngPath ? { pngPath: saved.record.pngPath } : {}) }
|
||||
} catch (error) {
|
||||
return { ok: false, error: error instanceof Error ? error.message : String(error) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时日报:把一次「到点触发 / 手动立即执行」跑成一次生成 + 一次发送。
|
||||
*
|
||||
|
||||
@@ -13,7 +13,12 @@ import {
|
||||
} from '../../components/ui'
|
||||
|
||||
type StatusFilter = 'all' | WechatActionStatus
|
||||
type PurposeFilter = 'all' | 'leave_notification' | 'scheduled_report' | 'other'
|
||||
type PurposeFilter =
|
||||
| 'all'
|
||||
| 'leave_notification'
|
||||
| 'scheduled_report'
|
||||
| 'automation_report'
|
||||
| 'other'
|
||||
|
||||
/**
|
||||
* 「退群通知」的发送用途。
|
||||
@@ -32,7 +37,10 @@ const LEAVE_NOTIFICATION_PURPOSES: readonly string[] = [
|
||||
const sourceLabel = (source: ActionLogEntry['source']): string => {
|
||||
if (source === 'member_monitor') return '退群监控'
|
||||
if (source === 'scheduled_report') return '定时日报'
|
||||
// 消息型自动化「@我生成日报」发出的动作。少了这一条会直接显示英文原文 `automation`。
|
||||
if (source === 'automation') return '自动化'
|
||||
if (source === 'user_tts') return '文字转语音'
|
||||
if (source === 'user_manual') return '手动发送'
|
||||
if (source === 'unknown') return '未知来源'
|
||||
return source || '未知来源'
|
||||
}
|
||||
@@ -40,9 +48,21 @@ const sourceLabel = (source: ActionLogEntry['source']): string => {
|
||||
const triggerLabel = (triggerType: ActionLogEntry['triggerType']): string =>
|
||||
triggerType === 'user' ? '用户触发' : '自动化'
|
||||
|
||||
/**
|
||||
* purpose → 中文。
|
||||
*
|
||||
* **每一个有生产者的 purpose 都必须在这里有分支**:`WechatActionPurpose` 是字符串联合,
|
||||
* 漏掉谁,那类记录就会顶着英文原文出现在列表里(筛选项里也找不到对应项)——
|
||||
* 「@我生成日报」的发送记录此前就是这样被用户当成"压根没有"的。
|
||||
* 未知值仍回落到原文,好让将来新增 purpose 时一眼能看出漏了映射。
|
||||
*/
|
||||
const purposeLabel = (purpose: WechatActionPurpose): string => {
|
||||
if (LEAVE_NOTIFICATION_PURPOSES.includes(purpose)) return '退群通知'
|
||||
if (purpose === 'scheduled_report') return '定时日报'
|
||||
if (purpose === 'automation_report') return '生成日报(@我)'
|
||||
if (purpose === 'automation_reply') return '回复确认(@我)'
|
||||
if (purpose === 'manual_report_image') return '日报图片(手动发送)'
|
||||
if (purpose === 'manual_report_postfix') return '日报后置词(手动发送)'
|
||||
if (purpose === 'tts_voice') return '文字转语音'
|
||||
return purpose || '其它动作'
|
||||
}
|
||||
@@ -65,8 +85,11 @@ const statusDetails = (entry: ActionLogEntry): { label: string; className: strin
|
||||
const matchesPurpose = (entry: ActionLogEntry, filter: PurposeFilter): boolean => {
|
||||
if (filter === 'all') return true
|
||||
if (filter === 'other') {
|
||||
// 「其它动作」= 剩下的。独立筛选项必须在这里排掉,否则同一条记录会同时出现在两组里。
|
||||
return (
|
||||
!LEAVE_NOTIFICATION_PURPOSES.includes(entry.purpose) && entry.purpose !== 'scheduled_report'
|
||||
!LEAVE_NOTIFICATION_PURPOSES.includes(entry.purpose) &&
|
||||
entry.purpose !== 'scheduled_report' &&
|
||||
entry.purpose !== 'automation_report'
|
||||
)
|
||||
}
|
||||
if (filter === 'leave_notification') {
|
||||
@@ -154,6 +177,7 @@ export function LogsWorkspace(): React.ReactElement {
|
||||
<SelectItem value="all">全部类型</SelectItem>
|
||||
<SelectItem value="leave_notification">退群通知</SelectItem>
|
||||
<SelectItem value="scheduled_report">定时日报</SelectItem>
|
||||
<SelectItem value="automation_report">生成日报(@我)</SelectItem>
|
||||
<SelectItem value="other">其它动作</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
@@ -7,7 +7,17 @@ import type { ReportTemplateSelectionId } from './report-templates'
|
||||
import type { ReportTemplateRef } from './report-template-package'
|
||||
|
||||
export type ReportAssetStatus = 'ready' | 'missing'
|
||||
export type GeneratedReportSource = 'manual' | 'scheduled'
|
||||
/**
|
||||
* 日报的产出方式。
|
||||
*
|
||||
* - `manual`:用户在日报页手动生成;
|
||||
* - `scheduled`:定时日报(自动化里的时间驱动规则);
|
||||
* - `automation`:消息型自动化「@我生成日报」触发产出。
|
||||
*
|
||||
* 三种都写进**同一条日报历史**(`report-history-service` 是唯一出口),
|
||||
* 这个字段只用于区分「谁触发的」,不参与任何可见性判断。
|
||||
*/
|
||||
export type GeneratedReportSource = 'manual' | 'scheduled' | 'automation'
|
||||
|
||||
export interface GeneratedReportRecord {
|
||||
id: string
|
||||
|
||||
Reference in new issue
Block a user