feat: 建立发送网关与动作审计

This commit is contained in:
Wxw-Gu committed 2026-09-02 18:00:39 +08:00
1 parent 76e9e683c4
commit e1f4ec79dd
10 files changed
+1411 -88

No files matched your search

+30
View File
@@ -1,3 +1,5 @@
import type { WechatActionResult } from './wechat-action'
export interface GroupExitMonitorMember {
wxid: string
nickname?: string
@@ -7,6 +9,23 @@ export interface GroupExitMonitorMember {
avatar?: string
}
export type GroupExitNotificationStatus =
| 'not_requested'
| 'pending'
| 'sent'
| 'blocked'
| 'failed'
export interface GroupExitNotificationState {
status: GroupExitNotificationStatus
actionId?: string
decision?: WechatActionResult['decision']
errorCode?: string
reason?: string
startedAt?: string
finishedAt?: string
}
export interface GroupExitMonitorEvent {
id: string
contactId: string
@@ -25,6 +44,9 @@ export interface GroupExitMonitorEvent {
delta: number
message: string
detectedAt: number
/** 可选通知的结果;退群检测与通知发送彼此独立。 */
notificationStatus?: GroupExitNotificationStatus
notification?: GroupExitNotificationState
}
const LEGACY_GROUP_EXIT_NOTIFICATION_TEMPLATE = [
@@ -142,6 +164,14 @@ export function renderGroupExitMonitorNotification(
)
}
/** 主进程中的辅助函数,供生成通知和预览时共用。 */
export function buildMemberLeftNotification(
event: GroupExitMonitorEvent,
template = GROUP_EXIT_NOTIFICATION_TEMPLATE
): string {
return renderGroupExitMonitorNotification(event, template)
}
export interface GroupExitMonitorState {
events: GroupExitMonitorEvent[]
running: boolean
+100
View File
@@ -0,0 +1,100 @@
export type WechatActionOrigin =
| 'member_monitor'
| 'scheduled_report'
| 'user_tts'
| 'unknown'
| (string & {})
export type WechatActionPurpose =
| 'member_left_notification'
| 'scheduled_report'
| 'tts_voice'
| (string & {})
export type WechatActionTriggerType = 'automation' | 'user'
export interface WechatActionRecipient {
type: 'group' | 'contact'
id: string
name?: string
}
export type WechatActionContent =
| { type: 'text'; text: string }
| { type: 'image'; path: string }
| { type: 'voice'; path: string }
export interface WechatActionRequest {
/** 可选的操作编号;未提供时会自动生成。 */
id?: string
/** 用于避免同一自动操作被重复执行的标识。 */
idempotencyKey?: string
origin: WechatActionOrigin
purpose: WechatActionPurpose
triggerType: WechatActionTriggerType
sourceId?: string
executionId?: string
recipient: WechatActionRecipient
content: WechatActionContent
metadata?: Record<string, unknown>
}
export type WechatActionStatus = 'sent' | 'blocked' | 'failed'
export type WechatActionDecision = 'allow' | 'block'
export type WechatActionErrorCode =
| 'INVALID_REQUEST'
| 'INVALID_RECIPIENT'
| 'ACTION_NOT_ALLOWED'
| 'RECIPIENT_SCOPE_VIOLATION'
| 'SEND_CAPABILITY_UNAVAILABLE'
| 'SEND_NOT_READY'
| 'SEND_FAILED'
| 'POLICY_BLOCKED'
| 'UNKNOWN'
| (string & {})
export interface WechatActionResult {
actionId: string
status: WechatActionStatus
decision: WechatActionDecision
errorCode?: WechatActionErrorCode
reason?: string
startedAt: string
finishedAt: string
sendResult?: unknown
}
export interface PolicyDecision {
decision: 'allow' | 'block' | 'require_review'
source: 'deterministic' | 'ai'
reasonCode?: WechatActionErrorCode
reason?: string
}
export interface WechatActionMemberEventReference {
id: string
roomId: string
}
export interface WechatActionAuditRecord {
actionId: string
idempotencyKey?: string
origin: WechatActionOrigin
purpose: WechatActionPurpose
triggerType: WechatActionTriggerType
sourceId?: string
executionId?: string
recipientType: WechatActionRecipient['type']
recipientId: string
contentType: WechatActionContent['type']
contentPreview?: string
contentHash?: string
createdAt: string
startedAt: string
finishedAt: string
decision: WechatActionDecision
decisionReason?: string
sendStatus: WechatActionStatus
errorCode?: WechatActionErrorCode
}