deepfish-ai 1.0.13 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,119 +0,0 @@
1
- /**
2
- * @Author: Roman 306863030@qq.com
3
- * @Date: 2026-03-16 09:18:05
4
- * @LastEditors: Roman 306863030@qq.com
5
- * @LastEditTime: 2026-03-17 10:01:45
6
- * @FilePath: \src\core\ai-services\AiWorker\AiRecorder.js
7
- * @Description: 对话历史记录、恢复
8
- * @
9
- */
10
- const fs = require("fs-extra");
11
- const path = require("path");
12
- const inquirer = require("inquirer");
13
- const dayjs = require("dayjs");
14
- const { GlobalVariable } = require("../../globalVariable");
15
-
16
- class AiRecorder {
17
- constructor(aiCli) {
18
- this.aiCli = aiCli;
19
- }
20
-
21
- record(messages) {
22
- if (!GlobalVariable.isRecordHistory) {
23
- return false;
24
- }
25
- const recordDir = path.join(process.cwd(), "ai-history");
26
- const recordFile = path.join(recordDir, "history.json");
27
-
28
- try {
29
- fs.ensureDirSync(recordDir);
30
- const recordData = {
31
- timestamp: dayjs().format("YYYY-MM-DD HH:mm:ss"),
32
- messages: messages,
33
- };
34
-
35
- fs.writeJSONSync(recordFile, recordData, { spaces: 2 });
36
- return true;
37
- } catch (error) {
38
- console.error("Failed to record:", error.message);
39
- return false;
40
- }
41
- }
42
-
43
- async recover() {
44
- if (!GlobalVariable.isRecordHistory) {
45
- return null;
46
- }
47
- const recordDir = path.join(process.cwd(), "ai-history");
48
- const recordFile = path.join(recordDir, "history.json");
49
-
50
- try {
51
- const exists = fs.pathExistsSync(recordFile);
52
- if (!exists) {
53
- return null;
54
- }
55
- const recordData = fs.readJSONSync(recordFile);
56
- const answer = await inquirer.default.prompt([
57
- {
58
- type: "confirm",
59
- name: "recover",
60
- message: "发现之前的任务记录,是否恢复?",
61
- default: true,
62
- },
63
- ]);
64
- if (answer.recover) {
65
- return {
66
- messages: recordData.messages,
67
- };
68
- } else {
69
- return null;
70
- }
71
- } catch (error) {
72
- console.error("Failed to recover:", error.message);
73
- return null;
74
- }
75
- }
76
-
77
- // 记录message以及压缩后的messages
78
- log(message) {
79
- if (GlobalVariable.isLog) {
80
- const time = dayjs();
81
- const logDir = path.join(
82
- process.cwd(),
83
- `ai-log/${time.format("YYYY-MM-DD")}`,
84
- );
85
- const logFile = path.join(logDir, `log-${time.format("HH")}.txt`);
86
-
87
- try {
88
- fs.ensureDirSync(logDir);
89
- if (typeof message === "object" && !Array.isArray(message)) {
90
- message = JSON.stringify(message);
91
- } else if (Array.isArray(message)) {
92
- message = '###压缩上下文###' + "\n" + JSON.stringify(message);
93
- }
94
- const logEntry = `[${new Date().toISOString()}] ${message}\n`;
95
- fs.appendFileSync(logFile, logEntry);
96
- return true;
97
- } catch (error) {
98
- console.error("Failed to log:", error.message);
99
- return false;
100
- }
101
- }
102
- }
103
-
104
- clear() {
105
- const recordDir = path.join(process.cwd(), "ai-history");
106
- try {
107
- const exists = fs.pathExistsSync(recordDir);
108
- if (exists) {
109
- fs.removeSync(recordDir);
110
- }
111
- return true;
112
- } catch (error) {
113
- console.error("Failed to clear:", error.message);
114
- return false;
115
- }
116
- }
117
- }
118
-
119
- module.exports = AiRecorder;