fix:基本实现相关功能

This commit is contained in:
2026-01-08 00:12:19 +08:00
commit f361a7027b
68 changed files with 10920 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
/**
* 对应数据库中的批次记录 (主任务)
*/
export interface IReadingReflectionTaskBatch {
id: string
bookName: string
totalCount: number
status: string
progress: number
createdAt: Date
items?: IReadingReflectionTaskItem[]
}
/**
* 对应数据库中的具体任务项 (子任务)
*/
export interface IReadingReflectionTaskItem {
id: string
status: 'PENDING' | 'WRITING' | 'COMPLETED' | 'FAILED'
progress: number
content?: string
title?: string
summary?: string
keywords?: string[]
}

View File

@@ -0,0 +1,36 @@
import { z } from 'zod'
/**
* 读者职业枚举
*/
export type Occupation = 'student' | 'teacher' | 'professional' | 'researcher' | 'other'
/**
* 读书心得生成请求任务模型
*/
export const ReadingReflectionsTaskSchema = z.object({
bookName: z.string().min(1, '书名不能为空'),
author: z.string().optional(),
description: z.string(),
occupation: z.enum(['student', 'teacher', 'professional', 'researcher', 'other']),
prompt: z.string(),
wordCount: z.number().default(1000),
quantity: z.number().min(1).max(5).default(1),
language: z.enum(['zh', 'en']).optional(),
tone: z.string().optional()
})
export type ReadingReflectionsTask = z.infer<typeof ReadingReflectionsTaskSchema>
/**
* 任务响应结果模型
*/
export interface ReadingReflectionsResponse {
taskId: string
reflections: Array<{
title: string // 心得标题
content: string // 心得正文
keywords: string[] // 提取的关键词
summary: string // 内容摘要
}>
status: 'pending' | 'completed' | 'failed'
}

View File

@@ -0,0 +1,28 @@
import log from 'electron-log/main'
import { EventEmitter } from 'events'
export const logEvent = new EventEmitter()
// 自定义不同级别的颜色(仅对控制台有效)
log.transports.console.level = 'debug'
log.hooks.push((message, transport) => {
if (transport === log.transports.console) {
if (message.level === 'error') {
message.data[0] = `\x1b[31m${message.data[0]}\x1b[0m` // 红色
} else if (message.level === 'info') {
message.data[0] = `\x1b[32m${message.data[0]}\x1b[0m` // 绿色
}
}
return message
})
/**
* 发布日志
* @param message 日志信息
* */
log.hooks.push((message) => {
logEvent.emit('log', message)
return message
})
export default log