foliko 1.1.65 → 1.1.67
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/.agent/agents/network-requester.md +44 -0
- package/.agent/agents/poster-designer.md +52 -0
- package/.agent/agents/ui-designer.md +1 -1
- package/.agent/data/default.json +45 -407
- package/.agent/data/email/processed-emails.json +1 -0
- package/.agent/data/plugins-state.json +99 -215
- package/.agent/data/web/web-config.json +5 -0
- 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/mcp_config.json +5 -17
- package/.agent/memory/user/mof6gk94-kneeuh.md +9 -0
- package/.agent/package.json +4 -2
- package/.agent/plugins/marknative/README.md +134 -0
- package/.agent/plugins/marknative/fonts/SegoeUI Emoji.ttf +0 -0
- package/.agent/plugins/marknative/fonts.zip +0 -0
- package/.agent/plugins/marknative/index.js +256 -0
- package/.agent/plugins/marknative/package.json +12 -0
- package/.agent/plugins/test-plugin.py +99 -0
- package/.agent/plugins.json +11 -5
- package/.agent/python-scripts/test_sample.py +24 -0
- package/.agent/sessions/cli_default.json +98 -442
- package/.agent/skills/agent-browser/SKILL.md +311 -0
- package/.agent/skills/agent-browser/TEST_PLAN.md +200 -0
- package/.agent/skills/sysinfo/SKILL.md +38 -0
- package/.agent/skills/sysinfo/system-info.sh +130 -0
- package/.agent/skills/workflow/SKILL.md +324 -0
- package/.agent/test-agent.js +35 -0
- package/.agent/weixin.json +6 -0
- package/.agent/workflows/email-digest.json +50 -0
- package/.agent/workflows/file-backup.json +21 -0
- package/.agent/workflows/get-ip-notify.json +32 -0
- package/.agent/workflows/news-aggregator.json +93 -0
- package/.agent/workflows/news-dashboard-v2.json +94 -0
- package/.agent/workflows/notification-batch.json +32 -0
- package/.env.example +56 -56
- package/README.md +441 -441
- package/cli/src/ui/chat-ui.js +165 -84
- package/cli/src/ui/footer-bar.js +32 -7
- package/cli/src/ui/message-bubble.js +2 -24
- package/package.json +1 -1
- package/plugins/audit-plugin.js +7 -11
- package/plugins/coordinator-plugin.js +12 -14
- package/plugins/default-plugins.js +1 -12
- package/plugins/extension-executor-plugin.js +2 -2
- package/plugins/file-system-plugin.js +50 -68
- package/plugins/gate-trading.js +10 -10
- package/plugins/install-plugin.js +3 -3
- package/plugins/memory-plugin.js +11 -8
- package/plugins/plugin-manager-plugin.js +11 -9
- package/plugins/qq-plugin.js +8 -8
- package/plugins/rules-plugin.js +7 -7
- package/plugins/scheduler-plugin.js +18 -22
- package/plugins/session-plugin.js +14 -14
- package/plugins/storage-plugin.js +10 -11
- package/plugins/subagent-plugin.js +9 -13
- package/plugins/think-plugin.js +59 -63
- package/plugins/tools-plugin.js +8 -8
- package/plugins/weixin-plugin.js +5 -5
- package/skills/find-skills/AGENTS.md +162 -162
- package/skills/find-skills/SKILL.md +133 -133
- package/src/capabilities/skill-manager.js +15 -23
- package/src/capabilities/workflow-engine.js +2 -2
- package/src/core/agent-chat.js +26 -70
- package/src/core/agent.js +27 -17
- package/src/core/chat-session.js +161 -7
- package/src/core/context-compressor.js +181 -6
- package/src/core/framework.js +6 -125
- package/src/core/plugin-base.js +5 -7
- package/src/core/subagent.js +135 -16
- package/src/core/tool-executor.js +70 -2
- package/src/executors/mcp-executor.js +10 -12
- package/src/utils/chat-queue.js +22 -11
- package/src/utils/retry.js +22 -168
- package/website_v2/styles/animations.css +7 -7
- package/.agent/.shared/ui-ux-pro-max/data/charts.csv +0 -26
- package/.agent/.shared/ui-ux-pro-max/data/colors.csv +0 -97
- package/.agent/.shared/ui-ux-pro-max/data/icons.csv +0 -101
- package/.agent/.shared/ui-ux-pro-max/data/landing.csv +0 -31
- package/.agent/.shared/ui-ux-pro-max/data/products.csv +0 -97
- package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +0 -24
- package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +0 -45
- package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +0 -53
- package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +0 -56
- package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +0 -53
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +0 -53
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +0 -51
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +0 -59
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +0 -52
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +0 -54
- package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +0 -61
- package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +0 -54
- package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +0 -51
- package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +0 -50
- package/.agent/.shared/ui-ux-pro-max/data/styles.csv +0 -59
- package/.agent/.shared/ui-ux-pro-max/data/typography.csv +0 -58
- package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +0 -101
- package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +0 -100
- package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +0 -31
- package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-313.pyc +0 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/core.py +0 -258
- package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +0 -1067
- package/.agent/.shared/ui-ux-pro-max/scripts/search.py +0 -106
- package/.agent/ARCHITECTURE.md +0 -288
- package/.agent/data/ambient/goals.json +0 -1
- package/.agent/data/puppeteer-sessions/undefined.json +0 -6
- package/.agent/data/weixin-media/2026-04-08/img_1775618677512.jpg +0 -0
- package/.agent/data/weixin-media/2026-04-08/img_1775619073340.jpg +0 -0
- package/.agent/data/weixin-media/2026-04-08/img_1775619097536.jpg +0 -0
- package/.agent/data/weixin-media/2026-04-08/img_1775619209388.jpg +0 -0
- package/.agent/memory/feedback/mnygjgox-ualjip.md +0 -11
- package/.agent/memory/feedback/mnzugpej-esdwsr.md +0 -9
- package/.agent/memory/feedback/mo2quxke-saxs56.md +0 -9
- package/.agent/memory/feedback/mo9l6nw9-sm1ye2.md +0 -13
- package/.agent/memory/feedback/mo9uxkb3-bbxz3x.md +0 -9
- package/.agent/memory/feedback/mo9wpqy0-ftsez9.md +0 -13
- package/.agent/memory/feedback/mo9x2ps4-p7huqq.md +0 -11
- package/.agent/memory/feedback/mo9x2uay-z7ndjn.md +0 -9
- package/.agent/memory/feedback/mo9x2y7d-9wecyx.md +0 -9
- package/.agent/memory/feedback/mo9x39q3-nn7myt.md +0 -9
- package/.agent/memory/feedback/mo9xfir9-4g8a8j.md +0 -9
- package/.agent/memory/feedback/mo9xfui8-ujqrc6.md +0 -9
- package/.agent/memory/feedback/mocnx1wx-qtxxlh.md +0 -9
- package/.agent/memory/project/mnqx54u5-loqtoe.md +0 -9
- package/.agent/memory/project/mnqx84cv-mx6dmd.md +0 -9
- package/.agent/memory/project/mnsacuyr-hgtk5n.md +0 -20
- package/.agent/memory/project/mnu5hy2x-bjsg7u.md +0 -9
- package/.agent/memory/project/mny28ot4-8qe9au.md +0 -9
- package/.agent/memory/project/mnztftxj-af82rh.md +0 -9
- package/.agent/memory/project/mo0y04d0-bmaefl.md +0 -9
- package/.agent/memory/project/mo2iztxb-3c7v81.md +0 -9
- package/.agent/memory/project/mo2ssa5x-tpi1p3.md +0 -9
- package/.agent/memory/reference/mnre3cww-penbo1.md +0 -9
- package/.agent/memory/reference/mns9wn48-luerua.md +0 -14
- package/.agent/memory/reference/mns9yz5c-thc2s0.md +0 -16
- package/.agent/memory/reference/mnsfy4um-910f1o.md +0 -23
- package/.agent/memory/reference/mnsg37dp-lmfj18.md +0 -32
- package/.agent/memory/reference/mnsll60q-0j911u.md +0 -36
- package/.agent/memory/reference/mnsmlb5y-nej31u.md +0 -16
- package/.agent/memory/reference/mnssle72-yrot96.md +0 -9
- package/.agent/memory/reference/mnygj8nb-bjthmc.md +0 -20
- package/.agent/memory/reference/mnzfvs4m-ufyg9a.md +0 -12
- package/.agent/memory/user/mnsfuon6-l416q1.md +0 -21
- package/.agent/memory/user/mnsg9kut-95m7rf.md +0 -20
- package/.agent/memory/user/mnu2eo1v-yy6fhe.md +0 -9
- package/.agent/memory/user/mnu2etuo-8u8jk8.md +0 -9
- package/.agent/memory/user/mnx0rk6g-gsznjj.md +0 -9
- package/.agent/memory/user/mnyf1riz-4yo5yz.md +0 -9
- package/.agent/memory/user/mnzuh4cw-zvee8w.md +0 -13
- package/.agent/memory/user/mnzvewyj-jl67cq.md +0 -9
- package/.agent/memory/user/mnzwh9xo-43ys3f.md +0 -9
- package/.agent/memory/user/mo0ycvpn-eebsxc.md +0 -9
- package/.agent/memory/user/mo2k8c8n-132r2u.md +0 -9
- package/.agent/memory/user/mo6y2dei-5cf537.md +0 -13
- package/.agent/memory/user/mo9xsdo6-8vylww.md +0 -13
- package/.agent/plugins/puppeteer-plugin/README.md +0 -147
- package/.agent/plugins/puppeteer-plugin/index.js +0 -1422
- package/.agent/plugins/puppeteer-plugin/package.json +0 -9
- package/.agent/rules/GEMINI.md +0 -273
- package/.agent/rules/allow-rule.md +0 -77
- package/.agent/rules/log-rule.md +0 -83
- package/.agent/rules/security-rule.md +0 -93
- package/.agent/scripts/auto_preview.py +0 -148
- package/.agent/scripts/checklist.py +0 -217
- package/.agent/scripts/session_manager.py +0 -120
- package/.agent/scripts/verify_all.py +0 -327
- package/.agent/sessions/test-session.json +0 -16
- package/.agent/skills/doc.md +0 -177
- package/.agent/skills/fk-poster/SKILL.md +0 -1129
- package/.agent/skills/fkbuilder/SKILL.md +0 -730
- package/.agent/skills/mmx-cli/SKILL.md +0 -169
- package/.agent/workflows/brainstorm.md +0 -113
- package/.agent/workflows/create.md +0 -59
- package/.agent/workflows/debug.md +0 -103
- package/.agent/workflows/deploy.md +0 -176
- package/.agent/workflows/enhance.md +0 -63
- package/.agent/workflows/orchestrate.md +0 -237
- package/.agent/workflows/plan.md +0 -89
- package/.agent/workflows/preview.md +0 -81
- package/.agent/workflows/simple-test.md +0 -42
- package/.agent/workflows/status.md +0 -86
- package/.agent/workflows/structured-orchestrate.md +0 -180
- package/.agent/workflows/test.md +0 -144
- package/.agent/workflows/ui-ux-pro-max.md +0 -296
- package/cli/src/ui/status-bar.js +0 -177
- package/plugins/data-splitter-plugin.js +0 -323
- package/src/core/constants.js +0 -198
- package/src/utils/data-splitter.js +0 -345
- package/src/utils/message-validator.js +0 -283
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DataSplitterPlugin — 大数据自动分拆插件
|
|
3
|
-
*
|
|
4
|
-
* 功能:
|
|
5
|
-
* 1. 注册 `split_and_process` 工具:AI 可主动调用,将大文本分拆给子 Agent 处理
|
|
6
|
-
* 2. 注册 `get_content_preview` 工具:获取大内容的前 N 行,判断是否需要分拆
|
|
7
|
-
* 3. 自动检测工具返回的大数据,触发透明分拆
|
|
8
|
-
* 4. 系统提示词中告知 AI 大数据处理能力
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const { Plugin } = require('../src/core/plugin-base');
|
|
12
|
-
const { z } = require('zod');
|
|
13
|
-
const { logger } = require('../src/utils/logger');
|
|
14
|
-
const { DataSplitter } = require('../src/utils/data-splitter');
|
|
15
|
-
|
|
16
|
-
// 超过此大小的工具结果自动触发分拆(字符数,默认 100K tokens ≈ 200K chars)
|
|
17
|
-
const AUTO_SPLIT_THRESHOLD = 50000;
|
|
18
|
-
|
|
19
|
-
class DataSplitterPlugin extends Plugin {
|
|
20
|
-
constructor(config = {}) {
|
|
21
|
-
super();
|
|
22
|
-
this.name = 'data-splitter';
|
|
23
|
-
this.version = '1.0.0';
|
|
24
|
-
this.description = '大数据自动分拆处理:读取大文件或抓取网页时,自动分拆为多个子Agent并行处理';
|
|
25
|
-
this.priority = 5;
|
|
26
|
-
|
|
27
|
-
this._framework = null;
|
|
28
|
-
this._splitter = null;
|
|
29
|
-
|
|
30
|
-
// 配置
|
|
31
|
-
this.config = {
|
|
32
|
-
autoSplitThreshold: config.autoSplitThreshold || AUTO_SPLIT_THRESHOLD,
|
|
33
|
-
chunkSize: config.chunkSize || 60000,
|
|
34
|
-
maxConcurrent: config.maxConcurrent || 3,
|
|
35
|
-
...config,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
install(framework) {
|
|
40
|
-
this._framework = framework;
|
|
41
|
-
this._splitter = new DataSplitter(framework, {
|
|
42
|
-
chunkSize: this.config.chunkSize,
|
|
43
|
-
safeThreshold: this.config.autoSplitThreshold,
|
|
44
|
-
maxConcurrent: this.config.maxConcurrent,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
start(framework) {
|
|
51
|
-
// 注册大数据处理工具
|
|
52
|
-
this._registerSplitTools();
|
|
53
|
-
|
|
54
|
-
// 注册系统提示词
|
|
55
|
-
this.registerPromptPart('data-splitter-rules', 85, () => this._getPromptRules());
|
|
56
|
-
|
|
57
|
-
// 注册工具结果监听器(自动检测大结果)
|
|
58
|
-
this._registerAutoSplitHook();
|
|
59
|
-
|
|
60
|
-
logger.info('[DataSplitterPlugin] 已启动,阈值:', this.config.autoSplitThreshold);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 注册分拆工具
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
_registerSplitTools() {
|
|
68
|
-
const framework = this._framework;
|
|
69
|
-
|
|
70
|
-
// ─── 工具1: split_and_process — AI 主动调用分拆 ───
|
|
71
|
-
framework.registerTool({
|
|
72
|
-
name: 'split_and_process',
|
|
73
|
-
description: `将大文本内容按大小分块,创建多个子 Agent 并行处理每块内容,最后自动汇总结果。
|
|
74
|
-
当你读取文件或抓取网页返回的内容超过 10 万字符时,应该使用此工具来分拆处理。
|
|
75
|
-
它会将内容拆成多块,每块由一个子 Agent 独立处理,最后给你一个汇总。`,
|
|
76
|
-
inputSchema: z.object({
|
|
77
|
-
content: z.string().describe('要分拆处理的大文本内容(如果超过 100K 字符建议使用此工具)'),
|
|
78
|
-
taskDescription: z.string().describe('每个子 Agent 要执行的任务描述,例如"提取所有函数定义"、"总结内容要点"等'),
|
|
79
|
-
chunkSize: z.number().optional().default(60000).describe('每块最大字符数,默认 60000'),
|
|
80
|
-
maxConcurrent: z.number().optional().default(3).describe('最大并行子 Agent 数,默认 3'),
|
|
81
|
-
}),
|
|
82
|
-
execute: async (args, ctx) => {
|
|
83
|
-
const { content, taskDescription, chunkSize, maxConcurrent } = args;
|
|
84
|
-
const splitter = this._getSplitter(ctx);
|
|
85
|
-
|
|
86
|
-
if (!content || content.length === 0) {
|
|
87
|
-
return { success: false, error: '内容为空,无需处理' };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const stats = splitter.getContentStats(content);
|
|
91
|
-
if (!splitter.needsSplit(content)) {
|
|
92
|
-
// 内容较小,直接返回
|
|
93
|
-
return {
|
|
94
|
-
success: true,
|
|
95
|
-
data: content,
|
|
96
|
-
metadata: {
|
|
97
|
-
needsSplit: false,
|
|
98
|
-
stats,
|
|
99
|
-
message: '内容大小在安全范围内,无需分拆处理。可直接使用原始内容。'
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 生成上下文中的 sessionId 用于取消信号
|
|
105
|
-
const sessionCtx = ctx?.getCurrentSessionContext?.();
|
|
106
|
-
const signal = sessionCtx?.abortSignal;
|
|
107
|
-
|
|
108
|
-
logger.info(
|
|
109
|
-
`[split_and_process] 开始分拆: ${stats.chars} 字符, ` +
|
|
110
|
-
`${stats.chunks} 块, 任务="${taskDescription?.slice(0, 40)}..."`
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const startTime = Date.now();
|
|
114
|
-
const chunks = splitter.splitContent(content, chunkSize);
|
|
115
|
-
const result = await splitter.dispatchToSubAgents({
|
|
116
|
-
chunks,
|
|
117
|
-
taskDescription,
|
|
118
|
-
maxConcurrent: maxConcurrent || this.config.maxConcurrent,
|
|
119
|
-
signal,
|
|
120
|
-
});
|
|
121
|
-
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
success: true,
|
|
125
|
-
data: result.summary,
|
|
126
|
-
metadata: {
|
|
127
|
-
needsSplit: true,
|
|
128
|
-
stats: { ...stats, actualChunks: chunks.length },
|
|
129
|
-
totalChunks: chunks.length,
|
|
130
|
-
successfulChunks: result.results.filter((r) => r.success).length,
|
|
131
|
-
failedChunks: result.errors.length,
|
|
132
|
-
durationSec: parseFloat(duration),
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// ─── 工具2: get_content_preview — 获取大内容预览信息 ───
|
|
139
|
-
framework.registerTool({
|
|
140
|
-
name: 'get_content_preview',
|
|
141
|
-
description: `获取大文本内容的预览信息(前 20 行 + 统计),判断是否需要分拆处理。
|
|
142
|
-
适合在读取大文件或抓取网页后用于检查内容大小。`,
|
|
143
|
-
inputSchema: z.object({
|
|
144
|
-
content: z.string().describe('要预览的大文本内容'),
|
|
145
|
-
previewLines: z.number().optional().default(20).describe('预览前 N 行,默认 20'),
|
|
146
|
-
}),
|
|
147
|
-
execute: async (args) => {
|
|
148
|
-
const { content, previewLines = 20 } = args;
|
|
149
|
-
const splitter = this._getSplitter();
|
|
150
|
-
|
|
151
|
-
const stats = splitter.getContentStats(content);
|
|
152
|
-
const lines = content.split('\n');
|
|
153
|
-
const preview = lines.slice(0, previewLines).join('\n');
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
success: true,
|
|
157
|
-
data: preview || '(空内容)',
|
|
158
|
-
metadata: {
|
|
159
|
-
stats,
|
|
160
|
-
needsSplit: splitter.needsSplit(content),
|
|
161
|
-
totalLines: lines.length,
|
|
162
|
-
suggestion: splitter.needsSplit(content)
|
|
163
|
-
? `内容较大 (${stats.chars} 字符, 约 ${stats.estimatedTokens} tokens),建议使用 split_and_process 分拆处理`
|
|
164
|
-
: '内容大小在安全范围内',
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* 获取系统提示词
|
|
173
|
-
* @private
|
|
174
|
-
*/
|
|
175
|
-
_getPromptRules() {
|
|
176
|
-
return `## 大数据处理能力
|
|
177
|
-
|
|
178
|
-
你具备自动处理大文件和大网页的能力:
|
|
179
|
-
|
|
180
|
-
1. **内容预览**:当工具返回的内容很大时,先用 \`get_content_preview\` 查看统计信息
|
|
181
|
-
2. **分拆处理**:如果内容超过 10 万字符,用 \`split_and_process\` 将内容分块,每块交给独立的子 Agent 并行处理
|
|
182
|
-
3. **自动汇总**:\`split_and_process\` 会自动汇总所有子 Agent 的处理结果,你只需基于汇总结果回答即可
|
|
183
|
-
4. **性能提示**:分拆处理会并行运行多个子 Agent,处理大文件时效率很高
|
|
184
|
-
|
|
185
|
-
### 使用建议
|
|
186
|
-
- 读取大文件(> 100KB)时:先读取,如果内容太大,用 \`split_and_process\` 分拆分析
|
|
187
|
-
- 抓取网页时:如果页面内容过多,用 \`split_and_process\` 分拆提取
|
|
188
|
-
- 分拆时指定清晰的任务描述,例如"提取所有关键代码函数"、"总结每段内容要点"`;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 注册自动分拆钩子
|
|
193
|
-
* 监听 tool:result 事件,如果结果太大自动触发分拆
|
|
194
|
-
* @private
|
|
195
|
-
*/
|
|
196
|
-
_registerAutoSplitHook() {
|
|
197
|
-
const framework = this._framework;
|
|
198
|
-
|
|
199
|
-
// 监听工具结果,检测大数据
|
|
200
|
-
this._toolResultHandler = (data) => {
|
|
201
|
-
const { name, result } = data;
|
|
202
|
-
|
|
203
|
-
// 跳过已经标记为分拆结果的工具
|
|
204
|
-
if (name === 'split_and_process') return;
|
|
205
|
-
|
|
206
|
-
// 检查工具返回的内容是否过大(优先使用 data 字段)
|
|
207
|
-
let checkContent = '';
|
|
208
|
-
if (result && typeof result === 'object' && result.data) {
|
|
209
|
-
checkContent = typeof result.data === 'string' ? result.data : JSON.stringify(result.data);
|
|
210
|
-
} else {
|
|
211
|
-
checkContent = typeof result === 'string' ? result : JSON.stringify(result);
|
|
212
|
-
}
|
|
213
|
-
if (!checkContent || checkContent.length < this.config.autoSplitThreshold) return;
|
|
214
|
-
|
|
215
|
-
// 不阻塞执行,只在日志中记录建议
|
|
216
|
-
logger.info(
|
|
217
|
-
`[DataSplitter] 检测到大数据工具结果: ${name}, ` +
|
|
218
|
-
`${checkContent.length} 字符, 建议使用 split_and_process 分拆处理`
|
|
219
|
-
);
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
framework.on('tool:result', this._toolResultHandler);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* 获取 DataSplitter 实例
|
|
227
|
-
* @private
|
|
228
|
-
*/
|
|
229
|
-
_getSplitter(ctx) {
|
|
230
|
-
return this._splitter || new DataSplitter(this._framework, this.config);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
reload(framework) {
|
|
234
|
-
// 清理旧监听器
|
|
235
|
-
if (this._toolResultHandler) {
|
|
236
|
-
framework.off('tool:result', this._toolResultHandler);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
this._framework = framework;
|
|
240
|
-
this._splitter = new DataSplitter(framework, this.config);
|
|
241
|
-
|
|
242
|
-
// 重新注册
|
|
243
|
-
if (framework._mainAgent) {
|
|
244
|
-
this.start(framework);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// 请求刷新 mainAgent 的 system prompt
|
|
248
|
-
if (framework._mainAgent) {
|
|
249
|
-
framework._mainAgent._refreshContext();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
uninstall(framework) {
|
|
254
|
-
if (this._toolResultHandler) {
|
|
255
|
-
framework.off('tool:result', this._toolResultHandler);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* 自动检测工具结果是否过大,并透明处理
|
|
262
|
-
* 在 agent-chat 中调用
|
|
263
|
-
*
|
|
264
|
-
* @param {string} toolName - 工具名称
|
|
265
|
-
* @param {*} result - 工具返回结果
|
|
266
|
-
* @param {Object} framework - Framework 实例
|
|
267
|
-
* @returns {Promise<{ wasSplit: boolean, result: *, splitterResult?: Object }>}
|
|
268
|
-
*/
|
|
269
|
-
async function autoSplitToolResult(toolName, result, framework) {
|
|
270
|
-
// 跳过某些工具
|
|
271
|
-
const skipTools = ['split_and_process', 'get_content_preview'];
|
|
272
|
-
if (skipTools.includes(toolName)) return { wasSplit: false, result };
|
|
273
|
-
|
|
274
|
-
// 无 framework 时无法创建子 Agent,跳过
|
|
275
|
-
if (!framework || typeof framework.createSubAgent !== 'function') {
|
|
276
|
-
return { wasSplit: false, result };
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// 提取用于判断大小的内容
|
|
280
|
-
// 优先使用 result.data(统一格式),再回退到整个结果字符串
|
|
281
|
-
let checkContent = '';
|
|
282
|
-
if (typeof result === 'object' && result !== null && result.data) {
|
|
283
|
-
checkContent = typeof result.data === 'string' ? result.data : JSON.stringify(result.data);
|
|
284
|
-
} else {
|
|
285
|
-
checkContent = typeof result === 'string' ? result : JSON.stringify(result);
|
|
286
|
-
}
|
|
287
|
-
if (!checkContent || checkContent.length < AUTO_SPLIT_THRESHOLD) {
|
|
288
|
-
return { wasSplit: false, result };
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const splitter = new DataSplitter(framework);
|
|
292
|
-
const taskDescription = `从以下内容中提取关键信息(代码、配置、数据等),以结构化方式输出。`;
|
|
293
|
-
|
|
294
|
-
logger.info(
|
|
295
|
-
`[DataSplitter] 自动分拆工具 "${toolName}": ${checkContent.length} 字符`
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
try {
|
|
299
|
-
const chunks = splitter.splitContent(checkContent);
|
|
300
|
-
const splitResult = await splitter.dispatchToSubAgents({
|
|
301
|
-
chunks,
|
|
302
|
-
taskDescription,
|
|
303
|
-
maxConcurrent: 3,
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
return {
|
|
307
|
-
wasSplit: true,
|
|
308
|
-
// 返回原始结果 + 分拆汇总,AI 可以同时看到两者
|
|
309
|
-
result: {
|
|
310
|
-
_autoSplit: true,
|
|
311
|
-
_originalSize: checkContent.length,
|
|
312
|
-
_summary: splitResult.summary,
|
|
313
|
-
_originalResult: result, // 保留原始结果供参考
|
|
314
|
-
},
|
|
315
|
-
splitterResult: splitResult,
|
|
316
|
-
};
|
|
317
|
-
} catch (err) {
|
|
318
|
-
logger.warn(`[DataSplitter] 自动分拆失败: ${err.message}`);
|
|
319
|
-
return { wasSplit: false, result };
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
module.exports = { DataSplitterPlugin, autoSplitToolResult };
|
package/src/core/constants.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Foliko Framework 统一常量
|
|
3
|
-
*
|
|
4
|
-
* 集中管理所有 magic numbers / strings,消除散落各处的重复值。
|
|
5
|
-
* 所有模块应引用此文件而非硬编码。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const path = require('path');
|
|
9
|
-
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// AI 模型与提供者
|
|
12
|
-
// ============================================================================
|
|
13
|
-
|
|
14
|
-
/** 默认 AI 提供者 */
|
|
15
|
-
const DEFAULT_PROVIDER = 'deepseek';
|
|
16
|
-
|
|
17
|
-
/** 默认 AI 模型 */
|
|
18
|
-
const DEFAULT_MODEL = 'deepseek-chat';
|
|
19
|
-
|
|
20
|
-
/** 默认 Max Output Tokens */
|
|
21
|
-
const DEFAULT_MAX_OUTPUT_TOKENS = 8192;
|
|
22
|
-
|
|
23
|
-
/** 默认 Temperature */
|
|
24
|
-
const DEFAULT_TEMPERATURE = 0.3;
|
|
25
|
-
|
|
26
|
-
/** 默认 Max Steps(工具调用最大轮数) */
|
|
27
|
-
const DEFAULT_MAX_STEPS = 20;
|
|
28
|
-
|
|
29
|
-
/** 需要禁用 temperature 的 thinking mode 模型列表 */
|
|
30
|
-
const THINKING_MODELS = [
|
|
31
|
-
'deepseek-v4-pro',
|
|
32
|
-
'deepseek-v4-flash',
|
|
33
|
-
'deepseek-reasoner',
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
// ============================================================================
|
|
37
|
-
// Session 上下文
|
|
38
|
-
// ============================================================================
|
|
39
|
-
|
|
40
|
-
/** Session TTL:默认 30 分钟 */
|
|
41
|
-
const DEFAULT_SESSION_TTL_MS = 30 * 60 * 1000;
|
|
42
|
-
|
|
43
|
-
/** Session 清理检查间隔 */
|
|
44
|
-
const DEFAULT_SESSION_CLEANUP_INTERVAL_MS = 60 * 1000;
|
|
45
|
-
|
|
46
|
-
/** 每个 Session 最大消息数 */
|
|
47
|
-
const DEFAULT_MAX_MESSAGES_PER_SESSION = 1000;
|
|
48
|
-
|
|
49
|
-
// ============================================================================
|
|
50
|
-
// 上下文压缩
|
|
51
|
-
// ============================================================================
|
|
52
|
-
|
|
53
|
-
/** 保留最近的 N 条消息 */
|
|
54
|
-
const KEEP_RECENT_MESSAGES = 20;
|
|
55
|
-
|
|
56
|
-
/** 智能压缩启用 */
|
|
57
|
-
const ENABLE_SMART_COMPRESS = true;
|
|
58
|
-
|
|
59
|
-
/** 压缩超时(毫秒) */
|
|
60
|
-
const COMPRESSION_TIMEOUT_MS = 1_200_000;
|
|
61
|
-
|
|
62
|
-
/** 工具结果最大字符数 */
|
|
63
|
-
const MAX_TOOL_RESULT_SIZE = 4000;
|
|
64
|
-
|
|
65
|
-
// ============================================================================
|
|
66
|
-
// 消息队列
|
|
67
|
-
// ============================================================================
|
|
68
|
-
|
|
69
|
-
/** 默认最大并发数 */
|
|
70
|
-
const DEFAULT_MAX_CONCURRENT = 1;
|
|
71
|
-
|
|
72
|
-
/** 默认重试次数 */
|
|
73
|
-
const DEFAULT_RETRY_ATTEMPTS = 3;
|
|
74
|
-
|
|
75
|
-
/** 默认重试延迟(毫秒) */
|
|
76
|
-
const DEFAULT_RETRY_DELAY_MS = 2000;
|
|
77
|
-
|
|
78
|
-
// ============================================================================
|
|
79
|
-
// System Prompt 优先级
|
|
80
|
-
// ============================================================================
|
|
81
|
-
|
|
82
|
-
const PROMPT_PRIORITY = {
|
|
83
|
-
DATETIME: 50,
|
|
84
|
-
ORIGINAL_PROMPT: 100,
|
|
85
|
-
SHARED_PROMPT: 200,
|
|
86
|
-
METADATA: 300,
|
|
87
|
-
TOOLS: 400,
|
|
88
|
-
SKILLS: 500,
|
|
89
|
-
SUB_AGENTS: 600,
|
|
90
|
-
CAPABILITIES: 700,
|
|
91
|
-
MCP_TOOLS: 750,
|
|
92
|
-
EXTENSION_TOOLS: 800,
|
|
93
|
-
TOOL_CORE_RULES: 95,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// ============================================================================
|
|
97
|
-
// 熔断器
|
|
98
|
-
// ============================================================================
|
|
99
|
-
|
|
100
|
-
/** 熔断器默认失败阈值 */
|
|
101
|
-
const DEFAULT_CIRCUIT_FAILURE_THRESHOLD = 3;
|
|
102
|
-
|
|
103
|
-
/** 熔断器默认成功阈值 */
|
|
104
|
-
const DEFAULT_CIRCUIT_SUCCESS_THRESHOLD = 2;
|
|
105
|
-
|
|
106
|
-
/** 熔断器默认超时(毫秒) */
|
|
107
|
-
const DEFAULT_CIRCUIT_TIMEOUT_MS = 60_000;
|
|
108
|
-
|
|
109
|
-
// ============================================================================
|
|
110
|
-
// 插件
|
|
111
|
-
// ============================================================================
|
|
112
|
-
|
|
113
|
-
/** 默认插件优先级 */
|
|
114
|
-
const DEFAULT_PLUGIN_PRIORITY = 100;
|
|
115
|
-
|
|
116
|
-
/** 系统插件名称集合 */
|
|
117
|
-
const SYSTEM_PLUGINS = new Set([
|
|
118
|
-
'ai', 'defaults', 'tools', 'skill-manager', 'session',
|
|
119
|
-
'storage', 'audit', 'rules', 'file-system',
|
|
120
|
-
]);
|
|
121
|
-
|
|
122
|
-
/** Agent 配置目录名 */
|
|
123
|
-
const AGENT_DIR = '.agent';
|
|
124
|
-
|
|
125
|
-
// ============================================================================
|
|
126
|
-
// Session 存储
|
|
127
|
-
// ============================================================================
|
|
128
|
-
|
|
129
|
-
/** 默认 Session 存储类型 */
|
|
130
|
-
const DEFAULT_SESSION_STORAGE_TYPE = 'file';
|
|
131
|
-
|
|
132
|
-
/** 默认 Session 存储目录 */
|
|
133
|
-
const DEFAULT_SESSION_STORAGE_DIR = path.join(AGENT_DIR, 'sessions');
|
|
134
|
-
|
|
135
|
-
// ============================================================================
|
|
136
|
-
// Token 计数(估算系数)
|
|
137
|
-
// ============================================================================
|
|
138
|
-
|
|
139
|
-
/** 每字符对应的 token 数(中文系数更大) */
|
|
140
|
-
const TOKENS_PER_CHAR = 0.25;
|
|
141
|
-
|
|
142
|
-
/** 每工具对应的 token 数 */
|
|
143
|
-
const TOKENS_PER_TOOL = 500;
|
|
144
|
-
|
|
145
|
-
/** 每消息固定开销 token */
|
|
146
|
-
const TOKENS_PER_MESSAGE_OVERHEAD = 4;
|
|
147
|
-
|
|
148
|
-
// ============================================================================
|
|
149
|
-
// 导出
|
|
150
|
-
// ============================================================================
|
|
151
|
-
|
|
152
|
-
module.exports = {
|
|
153
|
-
// AI
|
|
154
|
-
DEFAULT_PROVIDER,
|
|
155
|
-
DEFAULT_MODEL,
|
|
156
|
-
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
157
|
-
DEFAULT_TEMPERATURE,
|
|
158
|
-
DEFAULT_MAX_STEPS,
|
|
159
|
-
THINKING_MODELS,
|
|
160
|
-
|
|
161
|
-
// Session
|
|
162
|
-
DEFAULT_SESSION_TTL_MS,
|
|
163
|
-
DEFAULT_SESSION_CLEANUP_INTERVAL_MS,
|
|
164
|
-
DEFAULT_MAX_MESSAGES_PER_SESSION,
|
|
165
|
-
|
|
166
|
-
// Compression
|
|
167
|
-
KEEP_RECENT_MESSAGES,
|
|
168
|
-
ENABLE_SMART_COMPRESS,
|
|
169
|
-
COMPRESSION_TIMEOUT_MS,
|
|
170
|
-
MAX_TOOL_RESULT_SIZE,
|
|
171
|
-
|
|
172
|
-
// Queue
|
|
173
|
-
DEFAULT_MAX_CONCURRENT,
|
|
174
|
-
DEFAULT_RETRY_ATTEMPTS,
|
|
175
|
-
DEFAULT_RETRY_DELAY_MS,
|
|
176
|
-
|
|
177
|
-
// Priority
|
|
178
|
-
PROMPT_PRIORITY,
|
|
179
|
-
|
|
180
|
-
// Circuit Breaker
|
|
181
|
-
DEFAULT_CIRCUIT_FAILURE_THRESHOLD,
|
|
182
|
-
DEFAULT_CIRCUIT_SUCCESS_THRESHOLD,
|
|
183
|
-
DEFAULT_CIRCUIT_TIMEOUT_MS,
|
|
184
|
-
|
|
185
|
-
// Plugin
|
|
186
|
-
DEFAULT_PLUGIN_PRIORITY,
|
|
187
|
-
SYSTEM_PLUGINS,
|
|
188
|
-
AGENT_DIR,
|
|
189
|
-
|
|
190
|
-
// Storage
|
|
191
|
-
DEFAULT_SESSION_STORAGE_TYPE,
|
|
192
|
-
DEFAULT_SESSION_STORAGE_DIR,
|
|
193
|
-
|
|
194
|
-
// Token
|
|
195
|
-
TOKENS_PER_CHAR,
|
|
196
|
-
TOKENS_PER_TOOL,
|
|
197
|
-
TOKENS_PER_MESSAGE_OVERHEAD,
|
|
198
|
-
};
|