foliko 1.1.67 → 1.1.69
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.
- package/.claude/settings.local.json +19 -10
- package/.dockerignore +45 -45
- package/.env.example +56 -56
- package/CLAUDE.md +2 -2
- package/README.md +13 -13
- package/SPEC.md +3 -3
- package/cli/src/commands/chat.js +2 -20
- package/cli/src/commands/list.js +7 -6
- package/cli/src/commands/plugin.js +3 -2
- package/cli/src/daemon.js +2 -2
- package/cli/src/ui/chat-ui-old.js +15 -4
- package/cli/src/ui/chat-ui.js +236 -203
- package/cli/src/ui/footer-bar.js +20 -46
- package/cli/src/ui/message-bubble.js +24 -2
- package/cli/src/ui/status-bar.js +177 -0
- package/cli/src/utils/config.js +29 -0
- package/cli/src/utils/plugin-config.js +1 -1
- package/docker-compose.yml +33 -33
- package/docs/features.md +120 -120
- package/docs/quick-reference.md +160 -160
- package/docs/user-manual.md +1391 -1391
- package/examples/ambient-example.js +2 -2
- package/examples/bootstrap.js +3 -3
- package/examples/test-chat.js +1 -1
- package/examples/test-reload.js +1 -1
- package/examples/test-telegram.js +1 -1
- package/examples/test-tg-bot.js +1 -1
- package/examples/test-tg-simple.js +2 -2
- package/examples/test-tg.js +1 -1
- package/examples/test-think.js +1 -1
- package/examples/test-weixin-feishu.js +3 -3
- package/package.json +3 -1
- package/plugins/ambient-agent/index.js +1 -1
- package/plugins/audit-plugin.js +84 -29
- package/plugins/coordinator-plugin.js +14 -12
- package/plugins/data-splitter-plugin.js +323 -0
- package/plugins/default-plugins.js +23 -12
- package/plugins/email/index.js +1 -1
- package/plugins/extension-executor-plugin.js +87 -9
- package/plugins/feishu-plugin.js +118 -16
- package/plugins/file-system-plugin.js +68 -50
- package/plugins/gate-trading.js +10 -10
- package/plugins/install-plugin.js +7 -7
- package/plugins/memory-plugin.js +9 -12
- package/plugins/plugin-manager-plugin.js +12 -14
- package/plugins/python-executor-plugin.js +1 -1
- package/plugins/python-plugin-loader.js +1 -1
- package/plugins/qq-plugin.js +151 -24
- package/plugins/rules-plugin.js +8 -8
- package/plugins/scheduler-plugin.js +24 -20
- package/plugins/session-plugin.js +313 -397
- package/plugins/storage-plugin.js +235 -175
- package/plugins/subagent-plugin.js +17 -13
- package/plugins/telegram-plugin.js +116 -17
- package/plugins/think-plugin.js +64 -60
- package/plugins/tools-plugin.js +8 -8
- package/plugins/web-plugin.js +2 -2
- package/plugins/weixin-plugin.js +107 -24
- package/skills/find-skills/AGENTS.md +2 -2
- package/skills/find-skills/SKILL.md +133 -133
- package/skills/foliko-dev/AGENTS.md +236 -236
- package/skills/foliko-dev/SKILL.md +19 -19
- package/skills/mcp-usage/SKILL.md +200 -200
- package/skills/plugin-guide/SKILL.md +4 -4
- package/skills/python-plugin-dev/SKILL.md +5 -5
- package/skills/skill-guide/SKILL.md +104 -6
- package/skills/subagent-guide/SKILL.md +237 -237
- package/skills/workflow-guide/SKILL.md +646 -646
- package/src/capabilities/skill-manager.js +124 -17
- package/src/capabilities/workflow-engine.js +3 -3
- package/src/core/agent-chat.js +72 -26
- package/src/core/agent.js +17 -27
- package/src/core/branch-summary-auto.js +206 -0
- package/src/core/chat-session.js +45 -169
- package/src/core/command-registry.js +200 -0
- package/src/core/constants.js +198 -0
- package/src/core/context-compressor.js +702 -326
- package/src/core/context-manager.js +0 -1
- package/src/core/enhanced-context-compressor.js +210 -0
- package/src/core/framework.js +260 -84
- package/src/core/jsonl-storage.js +253 -0
- package/src/core/plugin-base.js +7 -5
- package/src/core/plugin-manager.js +15 -10
- package/src/core/provider-registry.js +159 -0
- package/src/core/provider.js +2 -0
- package/src/core/session-entry.js +225 -0
- package/src/core/session-manager.js +701 -0
- package/src/core/storage-manager.js +494 -0
- package/src/core/sub-agent-config.js +1 -1
- package/src/core/subagent.js +16 -135
- package/src/core/token-counter.js +177 -58
- package/src/core/tool-executor.js +2 -70
- package/src/core/ui-extension-context.js +174 -0
- package/src/executors/mcp-executor.js +27 -16
- package/src/utils/chat-queue.js +11 -22
- package/src/utils/data-splitter.js +345 -0
- package/src/utils/logger.js +152 -180
- package/src/utils/message-validator.js +283 -0
- package/src/utils/plugin-helpers.js +2 -2
- package/src/utils/retry.js +168 -22
- package/website_v2/docs/api.html +1 -1
- package/website_v2/docs/configuration.html +2 -2
- package/website_v2/docs/plugin-development.html +4 -4
- package/website_v2/docs/project-structure.html +2 -2
- package/website_v2/docs/skill-development.html +2 -2
- package/website_v2/index.html +1 -1
- package/website_v2/styles/animations.css +7 -7
- package/.agent/agents/backend-dev.md +0 -102
- package/.agent/agents/data-analyst.md +0 -117
- package/.agent/agents/devops.md +0 -115
- package/.agent/agents/frontend-dev.md +0 -94
- package/.agent/agents/network-requester.md +0 -44
- package/.agent/agents/poster-designer.md +0 -52
- package/.agent/agents/product-manager.md +0 -85
- package/.agent/agents/qa-engineer.md +0 -100
- package/.agent/agents/security-engineer.md +0 -99
- package/.agent/agents/team-lead.md +0 -137
- package/.agent/agents/ui-designer.md +0 -116
- package/.agent/data/default.json +0 -58
- package/.agent/data/email/processed-emails.json +0 -1
- package/.agent/data/plugins-state.json +0 -199
- package/.agent/data/scheduler/tasks.json +0 -1
- package/.agent/data/web/web-config.json +0 -5
- package/.agent/data/weixin/images/file_1776188148383jpg +0 -0
- package/.agent/data/weixin/images/file_1776188458326.jpg +0 -0
- package/.agent/data/weixin/images/file_1776188689423.jpg +0 -0
- package/.agent/data/weixin/images/file_1776188813604.jpg +0 -0
- package/.agent/data/weixin/images/file_1776189097450.jpg +0 -0
- package/.agent/data/weixin/videos/file_1776188318431.mp4 +0 -0
- package/.agent/data/weixin.json +0 -6
- package/.agent/mcp_config.json +0 -14
- package/.agent/memory/user/mof6gk94-kneeuh.md +0 -9
- package/.agent/package.json +0 -8
- package/.agent/plugins/marknative/README.md +0 -134
- package/.agent/plugins/marknative/fonts/SegoeUI Emoji.ttf +0 -0
- package/.agent/plugins/marknative/fonts.zip +0 -0
- package/.agent/plugins/marknative/index.js +0 -256
- package/.agent/plugins/marknative/package.json +0 -12
- package/.agent/plugins/test-plugin.py +0 -99
- package/.agent/plugins.json +0 -14
- package/.agent/python-scripts/test_sample.py +0 -24
- package/.agent/sessions/cli_default.json +0 -247
- package/.agent/skills/agent-browser/SKILL.md +0 -311
- package/.agent/skills/agent-browser/TEST_PLAN.md +0 -200
- package/.agent/skills/sysinfo/SKILL.md +0 -38
- package/.agent/skills/sysinfo/system-info.sh +0 -130
- package/.agent/skills/workflow/SKILL.md +0 -324
- package/.agent/test-agent.js +0 -35
- package/.agent/weixin.json +0 -6
- package/.agent/workflows/email-digest.json +0 -50
- package/.agent/workflows/file-backup.json +0 -21
- package/.agent/workflows/get-ip-notify.json +0 -32
- package/.agent/workflows/news-aggregator.json +0 -93
- package/.agent/workflows/news-dashboard-v2.json +0 -94
- package/.agent/workflows/notification-batch.json +0 -32
- package/src/core/session-context.js +0 -346
- package/src/core/session-storage.js +0 -295
|
@@ -15,7 +15,7 @@ async function main() {
|
|
|
15
15
|
|
|
16
16
|
// Bootstrap with default plugins (including ambient)
|
|
17
17
|
await framework.bootstrap({
|
|
18
|
-
agentDir: './.
|
|
18
|
+
agentDir: './.foliko',
|
|
19
19
|
aiConfig: {
|
|
20
20
|
provider: 'deepseek',
|
|
21
21
|
model: 'deepseek-chat',
|
|
@@ -181,7 +181,7 @@ async function main() {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
console.log('\n=== All Examples Completed ===');
|
|
184
|
-
console.log('Check .
|
|
184
|
+
console.log('Check .foliko/data/ambient/ for persisted data');
|
|
185
185
|
|
|
186
186
|
// Cleanup
|
|
187
187
|
console.log('\nShutting down...');
|
package/examples/bootstrap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bootstrap 示例
|
|
3
|
-
* 使用 framework.bootstrap() 自动加载 .
|
|
3
|
+
* 使用 framework.bootstrap() 自动加载 .foliko/ 目录配置
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { Framework } = require('../src');
|
|
@@ -13,9 +13,9 @@ async function main() {
|
|
|
13
13
|
const framework = new Framework({ debug: true });
|
|
14
14
|
|
|
15
15
|
// 使用 bootstrap 自动加载所有默认插件
|
|
16
|
-
// 会自动检测 .
|
|
16
|
+
// 会自动检测 .foliko/ 目录下的配置
|
|
17
17
|
await framework.bootstrap({
|
|
18
|
-
agentDir: './.
|
|
18
|
+
agentDir: './.foliko', // 配置目录
|
|
19
19
|
aiConfig: {
|
|
20
20
|
// 可选:覆盖 AI 配置
|
|
21
21
|
provider: 'deepseek',
|
package/examples/test-chat.js
CHANGED
package/examples/test-reload.js
CHANGED
|
@@ -37,7 +37,7 @@ async function test() {
|
|
|
37
37
|
|
|
38
38
|
// 检查配置
|
|
39
39
|
console.log('\n3. 当前配置文件:');
|
|
40
|
-
const configPath = path.resolve('.
|
|
40
|
+
const configPath = path.resolve('.foliko/mcp_config.json');
|
|
41
41
|
if (fs.existsSync(configPath)) {
|
|
42
42
|
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
43
43
|
console.log(JSON.stringify(config, null, 2));
|
|
@@ -5,7 +5,7 @@ async function main() {
|
|
|
5
5
|
const framework = new Framework({ debug: false });
|
|
6
6
|
|
|
7
7
|
await framework.bootstrap({
|
|
8
|
-
agentDir: process.cwd() + '/.
|
|
8
|
+
agentDir: process.cwd() + '/.foliko',
|
|
9
9
|
aiConfig: {
|
|
10
10
|
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
11
11
|
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
package/examples/test-tg-bot.js
CHANGED
|
@@ -7,7 +7,7 @@ async function main() {
|
|
|
7
7
|
const framework = new Framework({ debug: false });
|
|
8
8
|
|
|
9
9
|
await framework.bootstrap({
|
|
10
|
-
agentDir: process.cwd() + '/.
|
|
10
|
+
agentDir: process.cwd() + '/.foliko',
|
|
11
11
|
aiConfig: {
|
|
12
12
|
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
13
13
|
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require('dotenv').config();
|
|
2
2
|
|
|
3
|
-
// 添加 .
|
|
3
|
+
// 添加 .foliko/node_modules 到搜索路径
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const agentNodeModules = path.join(process.cwd(), '.
|
|
5
|
+
const agentNodeModules = path.join(process.cwd(), '.foliko', 'node_modules');
|
|
6
6
|
if (!module.paths.includes(agentNodeModules)) {
|
|
7
7
|
module.paths.unshift(agentNodeModules);
|
|
8
8
|
}
|
package/examples/test-tg.js
CHANGED
|
@@ -5,7 +5,7 @@ async function main() {
|
|
|
5
5
|
const framework = new Framework({ debug: true });
|
|
6
6
|
|
|
7
7
|
await framework.bootstrap({
|
|
8
|
-
agentDir: process.cwd() + '/.
|
|
8
|
+
agentDir: process.cwd() + '/.foliko',
|
|
9
9
|
aiConfig: {
|
|
10
10
|
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
11
11
|
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
package/examples/test-think.js
CHANGED
|
@@ -5,7 +5,7 @@ async function main() {
|
|
|
5
5
|
const framework = new Framework({ debug: false });
|
|
6
6
|
|
|
7
7
|
await framework.bootstrap({
|
|
8
|
-
agentDir: process.cwd() + '/.
|
|
8
|
+
agentDir: process.cwd() + '/.foliko',
|
|
9
9
|
aiConfig: {
|
|
10
10
|
provider: process.env.FOLIKO_PROVIDER || 'minimax',
|
|
11
11
|
model: process.env.FOLIKO_MODEL || 'MiniMax-M2.7',
|
|
@@ -12,7 +12,7 @@ async function main() {
|
|
|
12
12
|
|
|
13
13
|
// Bootstrap 加载默认插件
|
|
14
14
|
await framework.bootstrap({
|
|
15
|
-
agentDir: './.
|
|
15
|
+
agentDir: './.foliko',
|
|
16
16
|
aiConfig: {
|
|
17
17
|
provider: 'deepseek',
|
|
18
18
|
model: 'deepseek-chat',
|
|
@@ -68,7 +68,7 @@ async function main() {
|
|
|
68
68
|
|
|
69
69
|
try {
|
|
70
70
|
// 使用 chat() 而非 chatStream()
|
|
71
|
-
const result = await sessionInfo.
|
|
71
|
+
const result = await sessionInfo.foliko.chat(mockText, {
|
|
72
72
|
sessionId: sessionInfo.sessionId,
|
|
73
73
|
});
|
|
74
74
|
|
|
@@ -83,7 +83,7 @@ async function main() {
|
|
|
83
83
|
console.log('\n--- Test chatStream() for comparison ---');
|
|
84
84
|
try {
|
|
85
85
|
let fullResponse = '';
|
|
86
|
-
for await (const chunk of sessionInfo.
|
|
86
|
+
for await (const chunk of sessionInfo.foliko.chatStream('今天天气怎么样?', {
|
|
87
87
|
sessionId: sessionInfo.sessionId,
|
|
88
88
|
})) {
|
|
89
89
|
if (chunk.type === 'text' && chunk.text) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foliko",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.69",
|
|
4
4
|
"description": "简约的插件化 Agent 框架",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -81,6 +81,8 @@
|
|
|
81
81
|
"node-schedule": "^2.1.1",
|
|
82
82
|
"node-telegram-bot-api": "^0.67.0",
|
|
83
83
|
"nodemailer": "^6.10.0",
|
|
84
|
+
"pino": "^10.3.1",
|
|
85
|
+
"pino-pretty": "^13.1.3",
|
|
84
86
|
"qrcode-terminal": "^0.12.0",
|
|
85
87
|
"remove-markdown": "^0.6.3",
|
|
86
88
|
"zod": "^3.25.76"
|
|
@@ -32,7 +32,7 @@ class AmbientAgentPlugin extends Plugin {
|
|
|
32
32
|
enabled: config.enabled !== false,
|
|
33
33
|
tickInterval: config.tickInterval || 5000, // tick间隔(毫秒)
|
|
34
34
|
cooldownPeriod: config.cooldownPeriod || 3000, // 冷却时间(毫秒)
|
|
35
|
-
persistencePath: config.persistencePath || '.
|
|
35
|
+
persistencePath: config.persistencePath || '.foliko/data/ambient',
|
|
36
36
|
defaultGoals: config.defaultGoals || []
|
|
37
37
|
}
|
|
38
38
|
|
package/plugins/audit-plugin.js
CHANGED
|
@@ -1,36 +1,72 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Audit 审计日志插件
|
|
3
3
|
* 记录所有操作日志,支持日志查询和统计
|
|
4
|
+
* 基于 Pino 日志系统
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
const { Plugin } = require('../src/core/plugin-base')
|
|
8
|
+
const { logger } = require('../src/utils/logger')
|
|
7
9
|
const { z } = require('zod')
|
|
10
|
+
const path = require('path')
|
|
11
|
+
const fs = require('fs')
|
|
12
|
+
const os = require('os')
|
|
8
13
|
|
|
9
14
|
class AuditPlugin extends Plugin {
|
|
10
15
|
constructor(config = {}) {
|
|
11
16
|
super()
|
|
12
17
|
this.name = 'audit'
|
|
13
|
-
this.version = '
|
|
18
|
+
this.version = '2.0.0'
|
|
14
19
|
this.description = '审计日志插件,记录工具调用、技能执行、错误信息等操作历史'
|
|
15
20
|
this.priority = 20
|
|
16
|
-
this.system = true
|
|
21
|
+
this.system = true
|
|
17
22
|
|
|
18
23
|
this.config = {
|
|
19
24
|
maxLogs: config.maxLogs || 1000,
|
|
20
25
|
retentionDays: config.retentionDays || 30,
|
|
21
|
-
logDir: config.logDir || '.agent
|
|
26
|
+
logDir: config.logDir || path.join(os.homedir(), '.vb-agent', 'logs', 'audit')
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
this._framework = null
|
|
25
|
-
this._logs = []
|
|
26
30
|
this._logIdCounter = 0
|
|
31
|
+
this._auditLogger = null
|
|
32
|
+
this._auditLogFile = null
|
|
33
|
+
this._queryLogs = [] // 内存缓存用于查询
|
|
34
|
+
this._initAuditLogger()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 初始化审计日志器
|
|
39
|
+
*/
|
|
40
|
+
_initAuditLogger() {
|
|
41
|
+
const pino = require('pino')
|
|
42
|
+
|
|
43
|
+
// 确保目录存在
|
|
44
|
+
if (!fs.existsSync(this.config.logDir)) {
|
|
45
|
+
fs.mkdirSync(this.config.logDir, { recursive: true })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 审计日志文件名
|
|
49
|
+
const date = new Date().toISOString().split('T')[0]
|
|
50
|
+
this._auditLogFile = path.join(this.config.logDir, `audit-${date}.jsonl`)
|
|
51
|
+
|
|
52
|
+
// 创建文件写入流
|
|
53
|
+
const fileStream = fs.createWriteStream(this._auditLogFile, { flags: 'a' })
|
|
54
|
+
|
|
55
|
+
// 创建专门的审计 logger
|
|
56
|
+
this._auditLogger = pino({
|
|
57
|
+
name: 'audit',
|
|
58
|
+
level: 'info',
|
|
59
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
60
|
+
formatters: {
|
|
61
|
+
level: (label) => label.toUpperCase(),
|
|
62
|
+
},
|
|
63
|
+
}, fileStream)
|
|
27
64
|
}
|
|
28
65
|
|
|
29
66
|
install(framework) {
|
|
30
67
|
this._framework = framework
|
|
31
68
|
|
|
32
69
|
// 监听框架事件
|
|
33
|
-
// tool:call 和 tool-call 两种格式都监听(兼容不同来源)
|
|
34
70
|
framework.on('tool:call', (data) => this._log('tool_call', data))
|
|
35
71
|
framework.on('tool-call', (data) => this._log('tool_call', data))
|
|
36
72
|
framework.on('tool:result', (data) => this._log('tool_result', data))
|
|
@@ -51,10 +87,11 @@ class AuditPlugin extends Plugin {
|
|
|
51
87
|
offset: z.number().optional().describe('偏移量,默认 0')
|
|
52
88
|
}),
|
|
53
89
|
execute: async (args) => {
|
|
54
|
-
|
|
90
|
+
const logs = this._queryLogs
|
|
55
91
|
|
|
92
|
+
let filtered = logs
|
|
56
93
|
if (args.type) {
|
|
57
|
-
|
|
94
|
+
filtered = filtered.filter(log => log.type === args.type)
|
|
58
95
|
}
|
|
59
96
|
|
|
60
97
|
const offset = args.offset || 0
|
|
@@ -62,10 +99,12 @@ class AuditPlugin extends Plugin {
|
|
|
62
99
|
|
|
63
100
|
return {
|
|
64
101
|
success: true,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
102
|
+
data: filtered.slice(-limit - offset, filtered.length - offset),
|
|
103
|
+
metadata: {
|
|
104
|
+
total: filtered.length,
|
|
105
|
+
offset,
|
|
106
|
+
limit
|
|
107
|
+
}
|
|
69
108
|
}
|
|
70
109
|
}
|
|
71
110
|
})
|
|
@@ -78,7 +117,7 @@ class AuditPlugin extends Plugin {
|
|
|
78
117
|
const stats = this.getStats()
|
|
79
118
|
return {
|
|
80
119
|
success: true,
|
|
81
|
-
stats
|
|
120
|
+
data: stats
|
|
82
121
|
}
|
|
83
122
|
}
|
|
84
123
|
})
|
|
@@ -96,8 +135,10 @@ class AuditPlugin extends Plugin {
|
|
|
96
135
|
const result = this.exportLogs(args)
|
|
97
136
|
return {
|
|
98
137
|
success: true,
|
|
99
|
-
|
|
100
|
-
|
|
138
|
+
data: result.logs,
|
|
139
|
+
metadata: {
|
|
140
|
+
count: result.logs.length
|
|
141
|
+
}
|
|
101
142
|
}
|
|
102
143
|
}
|
|
103
144
|
})
|
|
@@ -107,21 +148,30 @@ class AuditPlugin extends Plugin {
|
|
|
107
148
|
|
|
108
149
|
/**
|
|
109
150
|
* 记录日志
|
|
110
|
-
* @private
|
|
111
151
|
*/
|
|
112
152
|
_log(type, data) {
|
|
113
153
|
const log = {
|
|
114
154
|
id: ++this._logIdCounter,
|
|
115
155
|
type,
|
|
116
156
|
data,
|
|
117
|
-
timestamp: new Date()
|
|
157
|
+
timestamp: new Date().toISOString()
|
|
118
158
|
}
|
|
119
159
|
|
|
120
|
-
|
|
160
|
+
// 写入审计日志文件
|
|
161
|
+
if (this._auditLogger) {
|
|
162
|
+
this._auditLogger.info({
|
|
163
|
+
auditId: log.id,
|
|
164
|
+
auditType: log.type,
|
|
165
|
+
auditData: log.data
|
|
166
|
+
}, 'audit event')
|
|
167
|
+
}
|
|
121
168
|
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
169
|
+
// 缓存到内存用于查询
|
|
170
|
+
this._queryLogs.push(log)
|
|
171
|
+
|
|
172
|
+
// 限制缓存数量
|
|
173
|
+
if (this._queryLogs.length > this.config.maxLogs) {
|
|
174
|
+
this._queryLogs = this._queryLogs.slice(-this.config.maxLogs)
|
|
125
175
|
}
|
|
126
176
|
|
|
127
177
|
return log
|
|
@@ -132,16 +182,17 @@ class AuditPlugin extends Plugin {
|
|
|
132
182
|
*/
|
|
133
183
|
getStats() {
|
|
134
184
|
const counts = {}
|
|
135
|
-
for (const log of this.
|
|
185
|
+
for (const log of this._queryLogs) {
|
|
136
186
|
counts[log.type] = (counts[log.type] || 0) + 1
|
|
137
187
|
}
|
|
138
188
|
|
|
139
189
|
return {
|
|
140
|
-
total: this.
|
|
190
|
+
total: this._queryLogs.length,
|
|
141
191
|
maxLogs: this.config.maxLogs,
|
|
142
192
|
counts,
|
|
143
|
-
oldest: this.
|
|
144
|
-
newest: this.
|
|
193
|
+
oldest: this._queryLogs.length > 0 ? this._queryLogs[0].timestamp : null,
|
|
194
|
+
newest: this._queryLogs.length > 0 ? this._queryLogs[this._queryLogs.length - 1].timestamp : null,
|
|
195
|
+
logFile: this._auditLogFile
|
|
145
196
|
}
|
|
146
197
|
}
|
|
147
198
|
|
|
@@ -149,7 +200,7 @@ class AuditPlugin extends Plugin {
|
|
|
149
200
|
* 导出日志
|
|
150
201
|
*/
|
|
151
202
|
exportLogs(options = {}) {
|
|
152
|
-
let logs = [...this.
|
|
203
|
+
let logs = [...this._queryLogs]
|
|
153
204
|
|
|
154
205
|
// 按类型过滤
|
|
155
206
|
if (options.type) {
|
|
@@ -159,12 +210,12 @@ class AuditPlugin extends Plugin {
|
|
|
159
210
|
// 按日期过滤
|
|
160
211
|
if (options.startDate) {
|
|
161
212
|
const start = new Date(options.startDate)
|
|
162
|
-
logs = logs.filter(log => log.timestamp >= start)
|
|
213
|
+
logs = logs.filter(log => new Date(log.timestamp) >= start)
|
|
163
214
|
}
|
|
164
215
|
|
|
165
216
|
if (options.endDate) {
|
|
166
217
|
const end = new Date(options.endDate)
|
|
167
|
-
logs = logs.filter(log => log.timestamp <= end)
|
|
218
|
+
logs = logs.filter(log => new Date(log.timestamp) <= end)
|
|
168
219
|
}
|
|
169
220
|
|
|
170
221
|
return { logs }
|
|
@@ -182,9 +233,13 @@ class AuditPlugin extends Plugin {
|
|
|
182
233
|
}
|
|
183
234
|
|
|
184
235
|
uninstall(framework) {
|
|
185
|
-
this.
|
|
236
|
+
this._queryLogs = []
|
|
237
|
+
if (this._auditLogger) {
|
|
238
|
+
// 关闭文件流
|
|
239
|
+
}
|
|
240
|
+
this._auditLogger = null
|
|
186
241
|
this._framework = null
|
|
187
242
|
}
|
|
188
243
|
}
|
|
189
244
|
|
|
190
|
-
module.exports = AuditPlugin
|
|
245
|
+
module.exports = AuditPlugin
|
|
@@ -156,12 +156,14 @@ class CoordinatorPlugin extends Plugin {
|
|
|
156
156
|
|
|
157
157
|
return {
|
|
158
158
|
success: true,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
data: result.result,
|
|
160
|
+
metadata: {
|
|
161
|
+
workerId: result.workerId,
|
|
162
|
+
status: result.status,
|
|
163
|
+
message: result.status === 'completed'
|
|
164
|
+
? `Worker '${args.worker_name}' completed with result`
|
|
165
|
+
: `Worker '${args.worker_name}' ${result.status}`,
|
|
166
|
+
},
|
|
165
167
|
};
|
|
166
168
|
} catch (err) {
|
|
167
169
|
return { success: false, error: err.message };
|
|
@@ -187,8 +189,8 @@ class CoordinatorPlugin extends Plugin {
|
|
|
187
189
|
const result = await coordinatorManager.sendToWorker(args.worker_name, args.message);
|
|
188
190
|
return {
|
|
189
191
|
success: true,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
+
data: result.message || result,
|
|
193
|
+
metadata: { workerName: args.worker_name },
|
|
192
194
|
};
|
|
193
195
|
} catch (err) {
|
|
194
196
|
return { success: false, error: err.message };
|
|
@@ -214,7 +216,7 @@ class CoordinatorPlugin extends Plugin {
|
|
|
214
216
|
const result = coordinatorManager.stopWorker(args.worker_name, args.reason);
|
|
215
217
|
return {
|
|
216
218
|
success: true,
|
|
217
|
-
|
|
219
|
+
data: result,
|
|
218
220
|
};
|
|
219
221
|
} catch (err) {
|
|
220
222
|
return { success: false, error: err.message };
|
|
@@ -236,8 +238,8 @@ class CoordinatorPlugin extends Plugin {
|
|
|
236
238
|
const workers = coordinatorManager.listWorkers();
|
|
237
239
|
return {
|
|
238
240
|
success: true,
|
|
239
|
-
|
|
240
|
-
workers,
|
|
241
|
+
data: workers,
|
|
242
|
+
metadata: { count: workers.length },
|
|
241
243
|
};
|
|
242
244
|
},
|
|
243
245
|
});
|
|
@@ -262,7 +264,7 @@ class CoordinatorPlugin extends Plugin {
|
|
|
262
264
|
|
|
263
265
|
return {
|
|
264
266
|
success: true,
|
|
265
|
-
worker,
|
|
267
|
+
data: worker,
|
|
266
268
|
};
|
|
267
269
|
},
|
|
268
270
|
});
|