foliko 1.1.92 → 2.0.0
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 +2 -1
- package/CLAUDE.md +56 -30
- package/REFACTORING_PLAN.md +645 -0
- package/docs/architecture.md +131 -0
- package/docs/migration.md +57 -0
- package/docs/public-api.md +138 -0
- package/docs/usage.md +385 -0
- package/examples/ambient-example.js +20 -137
- package/examples/basic.js +21 -48
- package/examples/bootstrap.js +16 -74
- package/examples/mcp-example.js +6 -29
- package/examples/skill-example.js +6 -19
- package/examples/workflow.js +8 -56
- package/package.json +8 -4
- package/plugins/README.md +49 -0
- package/plugins/{ambient-agent → ambient}/EventWatcher.js +1 -1
- package/plugins/{ambient-agent → ambient}/ExplorerLoop.js +3 -3
- package/plugins/{ambient-agent → ambient}/GoalManager.js +2 -2
- package/plugins/ambient/README.md +14 -0
- package/plugins/{ambient-agent → ambient}/Reflector.js +1 -1
- package/plugins/{ambient-agent → ambient}/StateStore.js +1 -1
- package/plugins/{ambient-agent → ambient}/index.js +2 -2
- package/plugins/{ai-plugin.js → core/ai/index.js} +14 -30
- package/plugins/{audit-plugin.js → core/audit/index.js} +3 -30
- package/plugins/{coordinator-plugin.js → core/coordinator/index.js} +3 -35
- package/plugins/core/default/bootstrap.js +202 -0
- package/plugins/core/default/config.js +220 -0
- package/plugins/core/default/index.js +58 -0
- package/plugins/core/mcp/index.js +1 -0
- package/plugins/{python-plugin-loader.js → core/python-loader/index.js} +7 -187
- package/plugins/{rules-plugin.js → core/rules/index.js} +121 -64
- package/plugins/{scheduler-plugin.js → core/scheduler/index.js} +12 -114
- package/plugins/{session-plugin.js → core/session/index.js} +9 -73
- package/{src/capabilities/skill-manager.js → plugins/core/skill-manager/index.js} +64 -18
- package/plugins/{storage-plugin.js → core/storage/index.js} +5 -29
- package/plugins/{subagent-plugin.js → core/sub-agent/index.js} +10 -171
- package/plugins/{think-plugin.js → core/think/index.js} +24 -91
- package/{src/capabilities/workflow-engine.js → plugins/core/workflow/index.js} +87 -85
- package/plugins/default-plugins.js +6 -720
- package/plugins/{data-splitter-plugin.js → executors/data-splitter/index.js} +9 -83
- package/plugins/{extension-executor-plugin.js → executors/extension/index.js} +13 -97
- package/plugins/{python-executor-plugin.js → executors/python/index.js} +6 -31
- package/plugins/{shell-executor-plugin.js → executors/shell/index.js} +2 -5
- package/plugins/install/README.md +9 -0
- package/plugins/{install-plugin.js → install/index.js} +3 -3
- package/plugins/{file-system-plugin.js → io/file-system/index.js} +34 -236
- package/plugins/{web-plugin.js → io/web/index.js} +11 -113
- package/plugins/memory/README.md +13 -0
- package/plugins/{memory-plugin.js → memory/index.js} +4 -18
- package/plugins/messaging/email/README.md +19 -0
- package/plugins/{email → messaging/email}/index.js +2 -2
- package/plugins/{feishu-plugin.js → messaging/feishu/index.js} +3 -3
- package/plugins/{qq-plugin.js → messaging/qq/index.js} +5 -16
- package/plugins/{telegram-plugin.js → messaging/telegram/index.js} +3 -3
- package/plugins/{weixin-plugin.js → messaging/weixin/index.js} +15 -15
- package/plugins/{plugin-manager-plugin.js → plugin-manager/index.js} +36 -180
- package/plugins/{tools-plugin.js → tools/index.js} +68 -116
- package/plugins/trading/README.md +15 -0
- package/plugins/{gate-trading.js → trading/index.js} +8 -8
- package/{examples → sandbox}/test-concurrent-chat.js +2 -2
- package/{examples → sandbox}/test-long-chat.js +2 -2
- package/{examples → sandbox}/test-session-chat.js +2 -2
- package/{examples → sandbox}/test-web-plugin.js +1 -1
- package/{examples → sandbox}/test-weixin-feishu.js +2 -2
- package/src/agent/base.js +56 -0
- package/src/{core/agent-chat.js → agent/chat.js} +11 -11
- package/src/{core/coordinator-manager.js → agent/coordinator.js} +3 -3
- package/src/agent/index.js +111 -0
- package/src/agent/main.js +337 -0
- package/src/agent/prompt.js +78 -0
- package/src/agent/sub.js +198 -0
- package/src/agent/worker.js +104 -0
- package/{cli/bin/foliko.js → src/cli/bin.js} +1 -1
- package/{cli/src → src/cli}/commands/chat.js +25 -21
- package/{cli/src → src/cli}/index.js +1 -0
- package/{cli/src → src/cli}/ui/chat-ui-old.js +40 -178
- package/{cli/src → src/cli}/ui/chat-ui.js +3 -3
- package/{cli/src → src/cli}/ui/components/footer-bar.js +1 -1
- package/src/{core → common}/constants.js +3 -0
- package/src/common/errors.js +402 -0
- package/src/{utils → common}/logger.js +33 -0
- package/src/{utils/chat-queue.js → common/queue.js} +2 -2
- package/src/config/plugin-config.js +50 -0
- package/src/context/agent.js +32 -0
- package/src/context/compaction-prompts.js +170 -0
- package/src/context/compaction-utils.js +191 -0
- package/src/context/compressor.js +413 -0
- package/src/context/index.js +9 -0
- package/src/{core/context-manager.js → context/manager.js} +1 -1
- package/src/context/request.js +50 -0
- package/src/context/session.js +33 -0
- package/src/context/storage.js +30 -0
- package/src/executors/mcp-client.js +153 -0
- package/src/executors/mcp-desc.js +236 -0
- package/src/executors/mcp-executor.js +91 -956
- package/src/{core → framework}/command-registry.js +1 -1
- package/src/framework/framework.js +300 -0
- package/src/framework/index.js +18 -0
- package/src/framework/lifecycle.js +203 -0
- package/src/framework/loader.js +78 -0
- package/src/framework/registry.js +86 -0
- package/src/{core/ui-extension-context.js → framework/ui-extension.js} +1 -1
- package/src/index.js +130 -15
- package/src/llm/index.js +26 -0
- package/src/llm/provider.js +212 -0
- package/src/llm/registry.js +11 -0
- package/src/{core/token-counter.js → llm/tokens.js} +4 -37
- package/src/{core/plugin-base.js → plugin/base.js} +10 -136
- package/src/plugin/index.js +14 -0
- package/src/plugin/loader.js +101 -0
- package/src/plugin/manager.js +261 -0
- package/src/{core → session}/branch-summary-auto.js +2 -2
- package/src/{core/chat-session.js → session/chat.js} +2 -2
- package/src/session/index.js +7 -0
- package/src/{core/session-manager.js → session/session.js} +2 -2
- package/src/session/ttl.js +92 -0
- package/src/{core/jsonl-storage.js → storage/jsonl.js} +1 -1
- package/src/tool/executor.js +85 -0
- package/src/tool/index.js +15 -0
- package/src/tool/registry.js +143 -0
- package/src/{core/tool-router.js → tool/router.js} +17 -124
- package/src/tool/schema.js +108 -0
- package/src/utils/data-splitter.js +1 -1
- package/src/utils/download.js +1 -1
- package/src/utils/index.js +6 -6
- package/src/utils/message-validator.js +1 -1
- package/tests/core/context-storage.test.js +46 -0
- package/tests/core/llm.test.js +54 -0
- package/tests/core/plugin.test.js +42 -0
- package/tests/core/tool.test.js +60 -0
- package/tests/setup.js +10 -0
- package/tests/smoke.test.js +58 -0
- package/vitest.config.js +9 -0
- package/cli/src/daemon.js +0 -149
- package/docs/CONTEXT_DESIGN.md +0 -1596
- package/docs/ai-sdk-optimization.md +0 -655
- package/docs/features.md +0 -120
- package/docs/qq-bot.md +0 -976
- package/docs/quick-reference.md +0 -160
- package/docs/user-manual.md +0 -1391
- package/images/geometric_shapes.jpg +0 -0
- package/images/sunset_mountain_lake.jpg +0 -0
- package/skills/poster-guide/SKILL.md +0 -792
- package/src/capabilities/index.js +0 -11
- package/src/core/agent.js +0 -808
- package/src/core/context-compressor.js +0 -959
- package/src/core/enhanced-context-compressor.js +0 -210
- package/src/core/framework.js +0 -1422
- package/src/core/index.js +0 -30
- package/src/core/plugin-manager.js +0 -961
- package/src/core/provider-registry.js +0 -159
- package/src/core/provider.js +0 -156
- package/src/core/request-context.js +0 -98
- package/src/core/subagent.js +0 -442
- package/src/core/system-prompt-builder.js +0 -120
- package/src/core/tool-executor.js +0 -202
- package/src/core/tool-registry.js +0 -517
- package/src/core/worker-agent.js +0 -192
- package/src/executors/executor-base.js +0 -58
- package/src/utils/error-boundary.js +0 -363
- package/src/utils/error.js +0 -374
- package/system.md +0 -1645
- package/website_v2/README.md +0 -57
- package/website_v2/SPEC.md +0 -1
- package/website_v2/docs/api.html +0 -128
- package/website_v2/docs/configuration.html +0 -147
- package/website_v2/docs/plugin-development.html +0 -129
- package/website_v2/docs/project-structure.html +0 -89
- package/website_v2/docs/skill-development.html +0 -85
- package/website_v2/index.html +0 -489
- package/website_v2/scripts/main.js +0 -93
- package/website_v2/styles/animations.css +0 -8
- package/website_v2/styles/docs.css +0 -83
- package/website_v2/styles/main.css +0 -417
- package/xhs_auth.json +0 -268
- package//346/265/267/346/212/245/346/217/222/344/273/266.md +0 -621
- /package/plugins/{ambient-agent → ambient}/constants.js +0 -0
- /package/plugins/{email → messaging/email}/constants.js +0 -0
- /package/plugins/{email → messaging/email}/handlers.js +0 -0
- /package/plugins/{email → messaging/email}/monitor.js +0 -0
- /package/plugins/{email → messaging/email}/parser.js +0 -0
- /package/plugins/{email → messaging/email}/reply.js +0 -0
- /package/plugins/{email → messaging/email}/utils.js +0 -0
- /package/{examples → sandbox}/test-chat.js +0 -0
- /package/{examples → sandbox}/test-mcp.js +0 -0
- /package/{examples → sandbox}/test-reload.js +0 -0
- /package/{examples → sandbox}/test-telegram.js +0 -0
- /package/{examples → sandbox}/test-tg-bot.js +0 -0
- /package/{examples → sandbox}/test-tg-simple.js +0 -0
- /package/{examples → sandbox}/test-tg.js +0 -0
- /package/{examples → sandbox}/test-think.js +0 -0
- /package/src/{core/sub-agent-config.js → agent/sub-config.js} +0 -0
- /package/{cli/src → src/cli}/commands/daemon.js +0 -0
- /package/{cli/src → src/cli}/commands/list.js +0 -0
- /package/{cli/src → src/cli}/commands/plugin.js +0 -0
- /package/{cli/src → src/cli}/ui/components/agent-mention-provider.js +0 -0
- /package/{cli/src → src/cli}/ui/components/chained-autocomplete-provider.js +0 -0
- /package/{cli/src → src/cli}/ui/components/message-bubble.js +0 -0
- /package/{cli/src → src/cli}/ui/components/status-bar.js +0 -0
- /package/{cli/src → src/cli}/utils/ansi.js +0 -0
- /package/{cli/src → src/cli}/utils/config.js +0 -0
- /package/{cli/src → src/cli}/utils/markdown.js +0 -0
- /package/{cli/src → src/cli}/utils/plugin-config.js +0 -0
- /package/{cli/src → src/cli}/utils/render-diff.js +0 -0
- /package/src/{utils/circuit-breaker.js → common/circuit.js} +0 -0
- /package/src/{utils/edit-diff.js → common/diff.js} +0 -0
- /package/src/{utils/event-emitter.js → common/events.js} +0 -0
- /package/src/{utils → common}/id.js +0 -0
- /package/src/{utils → common}/retry.js +0 -0
- /package/src/{core/notification-manager.js → notification/manager.js} +0 -0
- /package/src/{core/session-entry.js → session/entry.js} +0 -0
- /package/src/{core/storage-manager.js → storage/manager.js} +0 -0
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* ToolsPlugin - 内置工具插件
|
|
3
|
+
* 提供热重载、插件管理、工具列表等内置工具
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const { Plugin } = require('
|
|
7
|
-
const { logger } = require('
|
|
8
|
-
const
|
|
9
|
-
const
|
|
6
|
+
const { Plugin } = require('../../src/plugin/base');
|
|
7
|
+
const { logger } = require('../../src/common/logger');
|
|
8
|
+
const { z } = require('zod');
|
|
9
|
+
const log = logger.child('Tools');
|
|
10
10
|
|
|
11
11
|
class ToolsPlugin extends Plugin {
|
|
12
12
|
constructor(config = {}) {
|
|
13
|
-
super()
|
|
14
|
-
this.name = 'tools'
|
|
15
|
-
this.version = '1.0.0'
|
|
16
|
-
this.description = '内置工具插件,提供热重载和工具管理功能'
|
|
17
|
-
this.priority = 10
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
this._framework = null
|
|
13
|
+
super();
|
|
14
|
+
this.name = 'tools';
|
|
15
|
+
this.version = '1.0.0';
|
|
16
|
+
this.description = '内置工具插件,提供热重载和工具管理功能';
|
|
17
|
+
this.priority = 10;
|
|
18
|
+
this.system = true;
|
|
19
|
+
this._framework = null;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
install(framework) {
|
|
25
|
-
this._framework = framework
|
|
26
|
-
this._registerBuiltinTools()
|
|
27
|
-
return this
|
|
23
|
+
this._framework = framework;
|
|
24
|
+
this._registerBuiltinTools();
|
|
25
|
+
return this;
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
start(framework) {
|
|
31
|
-
// 注册工具调用核心规则提示词
|
|
32
29
|
this.registerPromptPart('tool-core-rules', 95, () => this._getToolCoreRules());
|
|
33
30
|
}
|
|
34
31
|
|
|
@@ -62,165 +59,120 @@ class ToolsPlugin extends Plugin {
|
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
_registerBuiltinTools() {
|
|
65
|
-
const framework = this._framework
|
|
62
|
+
const framework = this._framework;
|
|
66
63
|
|
|
67
|
-
// 热重载插件工具
|
|
68
64
|
framework.registerTool({
|
|
69
65
|
name: 'reload_plugins',
|
|
70
66
|
description: '热重载插件。可以重载单个指定插件,或重载所有插件。',
|
|
71
67
|
inputSchema: z.object({
|
|
72
|
-
pluginName: z.string().optional().describe('可选:指定要重载的插件名称,不指定则重载所有插件')
|
|
68
|
+
pluginName: z.string().optional().describe('可选:指定要重载的插件名称,不指定则重载所有插件'),
|
|
73
69
|
}),
|
|
74
70
|
execute: async (args) => {
|
|
75
71
|
try {
|
|
76
72
|
if (args.pluginName) {
|
|
77
|
-
await framework.reloadPlugin(args.pluginName)
|
|
78
|
-
return {
|
|
79
|
-
success: true,
|
|
80
|
-
data: `Plugin '${args.pluginName}' reloaded successfully`
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
await framework.reloadAllPlugins()
|
|
84
|
-
return {
|
|
85
|
-
success: true,
|
|
86
|
-
data: 'All plugins reloaded successfully'
|
|
87
|
-
}
|
|
73
|
+
await framework.reloadPlugin(args.pluginName);
|
|
74
|
+
return { success: true, data: `Plugin '${args.pluginName}' reloaded successfully` };
|
|
88
75
|
}
|
|
76
|
+
await framework.reloadAllPlugins();
|
|
77
|
+
return { success: true, data: 'All plugins reloaded successfully' };
|
|
89
78
|
} catch (err) {
|
|
90
|
-
return {
|
|
91
|
-
success: false,
|
|
92
|
-
error: err.message
|
|
93
|
-
}
|
|
79
|
+
return { success: false, error: err.message };
|
|
94
80
|
}
|
|
95
|
-
}
|
|
96
|
-
})
|
|
81
|
+
},
|
|
82
|
+
});
|
|
97
83
|
|
|
98
|
-
// 列出所有插件工具(包括未加载的)
|
|
99
84
|
framework.registerTool({
|
|
100
85
|
name: 'list_plugins',
|
|
101
86
|
description: '列出所有插件(包括未加载的)',
|
|
102
87
|
inputSchema: z.object({}),
|
|
103
88
|
execute: async () => {
|
|
104
|
-
const plugins = framework.pluginManager.getAllKnown()
|
|
105
|
-
return {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
name: p.name,
|
|
109
|
-
status: p.status,
|
|
110
|
-
enabled: p.enabled,
|
|
111
|
-
version: p.version,
|
|
112
|
-
system: p.system
|
|
113
|
-
}))
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
})
|
|
89
|
+
const plugins = framework.pluginManager.getAllKnown();
|
|
90
|
+
return { success: true, data: plugins };
|
|
91
|
+
},
|
|
92
|
+
});
|
|
117
93
|
|
|
118
|
-
// 启用插件工具
|
|
119
94
|
framework.registerTool({
|
|
120
95
|
name: 'enable_plugin',
|
|
121
96
|
description: '启用指定插件',
|
|
122
|
-
inputSchema: z.object({
|
|
123
|
-
name: z.string().describe('插件名称')
|
|
124
|
-
}),
|
|
97
|
+
inputSchema: z.object({ name: z.string().describe('插件名称') }),
|
|
125
98
|
execute: async (args) => {
|
|
126
99
|
try {
|
|
127
|
-
await framework.enablePlugin(args.name)
|
|
128
|
-
return { success: true, data: `插件 '${args.name}' 已启用` }
|
|
100
|
+
await framework.enablePlugin(args.name);
|
|
101
|
+
return { success: true, data: `插件 '${args.name}' 已启用` };
|
|
129
102
|
} catch (err) {
|
|
130
|
-
return { success: false, error: err.message }
|
|
103
|
+
return { success: false, error: err.message };
|
|
131
104
|
}
|
|
132
|
-
}
|
|
133
|
-
})
|
|
105
|
+
},
|
|
106
|
+
});
|
|
134
107
|
|
|
135
|
-
// 禁用插件工具
|
|
136
108
|
framework.registerTool({
|
|
137
109
|
name: 'disable_plugin',
|
|
138
110
|
description: '禁用指定插件',
|
|
139
|
-
inputSchema: z.object({
|
|
140
|
-
name: z.string().describe('插件名称')
|
|
141
|
-
}),
|
|
111
|
+
inputSchema: z.object({ name: z.string().describe('插件名称') }),
|
|
142
112
|
execute: async (args) => {
|
|
143
113
|
try {
|
|
144
|
-
await framework.disablePlugin(args.name)
|
|
145
|
-
return { success: true, data: `插件 '${args.name}' 已禁用` }
|
|
114
|
+
await framework.disablePlugin(args.name);
|
|
115
|
+
return { success: true, data: `插件 '${args.name}' 已禁用` };
|
|
146
116
|
} catch (err) {
|
|
147
|
-
return { success: false, error: err.message }
|
|
117
|
+
return { success: false, error: err.message };
|
|
148
118
|
}
|
|
149
|
-
}
|
|
150
|
-
})
|
|
119
|
+
},
|
|
120
|
+
});
|
|
151
121
|
|
|
152
|
-
// 获取工具列表
|
|
153
122
|
framework.registerTool({
|
|
154
123
|
name: 'list_tools',
|
|
155
124
|
description: '列出所有已注册的工具',
|
|
156
125
|
inputSchema: z.object({}),
|
|
157
126
|
execute: async () => {
|
|
158
|
-
const tools = framework.getTools()
|
|
159
|
-
return {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
name: t.name,
|
|
163
|
-
description: t.description
|
|
164
|
-
}))
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
})
|
|
127
|
+
const tools = framework.getTools();
|
|
128
|
+
return { success: true, data: tools.map(t => ({ name: t.name, description: t.description })) };
|
|
129
|
+
},
|
|
130
|
+
});
|
|
168
131
|
|
|
169
|
-
// 获取插件配置
|
|
170
132
|
framework.registerTool({
|
|
171
133
|
name: 'get_plugin_config',
|
|
172
134
|
description: '获取指定插件的当前配置',
|
|
173
|
-
inputSchema: z.object({
|
|
174
|
-
name: z.string().describe('插件名称')
|
|
175
|
-
}),
|
|
135
|
+
inputSchema: z.object({ name: z.string().describe('插件名称') }),
|
|
176
136
|
execute: async (args) => {
|
|
177
|
-
const plugin = framework.pluginManager.get(args.name)
|
|
178
|
-
if (!plugin) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
success: true,
|
|
183
|
-
data: plugin.config || {}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
})
|
|
137
|
+
const plugin = framework.pluginManager.get(args.name);
|
|
138
|
+
if (!plugin) return { success: false, error: `Plugin '${args.name}' not found` };
|
|
139
|
+
return { success: true, data: plugin.config || {} };
|
|
140
|
+
},
|
|
141
|
+
});
|
|
187
142
|
|
|
188
|
-
// 更新插件配置
|
|
189
143
|
framework.registerTool({
|
|
190
144
|
name: 'update_plugin_config',
|
|
191
145
|
description: '更新指定插件的配置,会合并到现有配置并持久化保存',
|
|
192
146
|
inputSchema: z.object({
|
|
193
147
|
name: z.string().describe('插件名称'),
|
|
194
|
-
config: z.record(z.any()).describe('要更新的配置(会合并到现有配置)')
|
|
148
|
+
config: z.record(z.any()).describe('要更新的配置(会合并到现有配置)'),
|
|
195
149
|
}),
|
|
196
150
|
execute: async (args) => {
|
|
197
151
|
try {
|
|
198
|
-
const newConfig = framework.updatePluginConfig(args.name, args.config)
|
|
199
|
-
return { success: true, data: `插件 '${args.name}' 配置已更新`, metadata: { config: newConfig } }
|
|
152
|
+
const newConfig = framework.updatePluginConfig(args.name, args.config);
|
|
153
|
+
return { success: true, data: `插件 '${args.name}' 配置已更新`, metadata: { config: newConfig } };
|
|
200
154
|
} catch (err) {
|
|
201
|
-
return { success: false, error: err.message }
|
|
155
|
+
return { success: false, error: err.message };
|
|
202
156
|
}
|
|
203
|
-
}
|
|
204
|
-
})
|
|
157
|
+
},
|
|
158
|
+
});
|
|
205
159
|
}
|
|
206
160
|
|
|
207
161
|
reload(framework) {
|
|
208
|
-
|
|
209
|
-
this.
|
|
210
|
-
this._registerBuiltinTools()
|
|
162
|
+
this._framework = framework;
|
|
163
|
+
this._registerBuiltinTools();
|
|
211
164
|
}
|
|
212
165
|
|
|
213
166
|
uninstall(framework) {
|
|
214
|
-
|
|
215
|
-
framework.toolRegistry.unregister('
|
|
216
|
-
framework.toolRegistry.unregister('
|
|
217
|
-
framework.toolRegistry.unregister('
|
|
218
|
-
framework.toolRegistry.unregister('
|
|
219
|
-
framework.toolRegistry.unregister('
|
|
220
|
-
framework.toolRegistry.unregister('
|
|
221
|
-
|
|
222
|
-
this._framework = null
|
|
167
|
+
framework.toolRegistry.unregister('reload_plugins');
|
|
168
|
+
framework.toolRegistry.unregister('list_plugins');
|
|
169
|
+
framework.toolRegistry.unregister('list_tools');
|
|
170
|
+
framework.toolRegistry.unregister('enable_plugin');
|
|
171
|
+
framework.toolRegistry.unregister('disable_plugin');
|
|
172
|
+
framework.toolRegistry.unregister('get_plugin_config');
|
|
173
|
+
framework.toolRegistry.unregister('update_plugin_config');
|
|
174
|
+
this._framework = null;
|
|
223
175
|
}
|
|
224
176
|
}
|
|
225
177
|
|
|
226
|
-
module.exports = ToolsPlugin
|
|
178
|
+
module.exports = ToolsPlugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Plugin } = require('
|
|
1
|
+
const { Plugin } = require('../../src/plugin/base')
|
|
2
2
|
class GateTradingPlugin extends Plugin {
|
|
3
3
|
constructor(config = {}) {
|
|
4
4
|
super();
|
|
@@ -6,7 +6,7 @@ class GateTradingPlugin extends Plugin {
|
|
|
6
6
|
this.version = '1.1.0';
|
|
7
7
|
this.description = 'Gate.io 加密货币交易插件(支持现货+合约)';
|
|
8
8
|
this.priority = 100;
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
// 从 .env 文件读取密钥
|
|
11
11
|
const fs = require('fs');
|
|
12
12
|
const path = require('path');
|
|
@@ -423,7 +423,7 @@ class GateTradingPlugin extends Plugin {
|
|
|
423
423
|
this._checkAuth();
|
|
424
424
|
const futuresApi = this._createFuturesApi();
|
|
425
425
|
const settle = args.settle.toLowerCase();
|
|
426
|
-
|
|
426
|
+
|
|
427
427
|
// 构造订单对象 - settle 不能在订单内部
|
|
428
428
|
const order = {
|
|
429
429
|
contract: args.contract,
|
|
@@ -433,7 +433,7 @@ class GateTradingPlugin extends Plugin {
|
|
|
433
433
|
};
|
|
434
434
|
if (args.price) order.price = args.price;
|
|
435
435
|
if (args.reduce_only !== undefined) order.reduce_only = args.reduce_only;
|
|
436
|
-
|
|
436
|
+
|
|
437
437
|
// SDK签名: createFuturesOrder(settle, futuresOrder, opts)
|
|
438
438
|
const result = await futuresApi.createFuturesOrder(settle, order);
|
|
439
439
|
const r = result.body;
|
|
@@ -449,7 +449,7 @@ class GateTradingPlugin extends Plugin {
|
|
|
449
449
|
fill_price: r.fill_price,
|
|
450
450
|
create_time: r.create_time,
|
|
451
451
|
};
|
|
452
|
-
} catch (error) {
|
|
452
|
+
} catch (error) {
|
|
453
453
|
return { success: false, error: error.message }; }
|
|
454
454
|
},
|
|
455
455
|
});
|
|
@@ -522,13 +522,13 @@ class GateTradingPlugin extends Plugin {
|
|
|
522
522
|
this._checkAuth();
|
|
523
523
|
const futuresApi = this._createFuturesApi();
|
|
524
524
|
const settle = (args.settle || 'USDT').toLowerCase();
|
|
525
|
-
|
|
525
|
+
|
|
526
526
|
// SDK签名: listFuturesOrders(settle, status, opts)
|
|
527
527
|
// status: open = 未完成, finished = 已完成
|
|
528
528
|
const status = 'open';
|
|
529
529
|
const opts = {};
|
|
530
530
|
if (args.contract) opts.contract = args.contract;
|
|
531
|
-
|
|
531
|
+
|
|
532
532
|
const result = await futuresApi.listFuturesOrders(settle, status, opts);
|
|
533
533
|
const orders = (Array.isArray(result.body) ? result.body : []);
|
|
534
534
|
return {
|
|
@@ -565,7 +565,7 @@ class GateTradingPlugin extends Plugin {
|
|
|
565
565
|
const futuresApi = this._createFuturesApi();
|
|
566
566
|
const settle = (args.settle || 'USDT').toLowerCase();
|
|
567
567
|
const { info_type, contract } = args;
|
|
568
|
-
|
|
568
|
+
|
|
569
569
|
if (info_type === 'book' || !info_type) {
|
|
570
570
|
// SDK签名: listFuturesOrderBook(settle, contract, opts)
|
|
571
571
|
const book = await futuresApi.listFuturesOrderBook(settle, contract || 'BTC_USDT');
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const { Framework } = require('../src');
|
|
6
|
-
const AIPlugin = require('../plugins/ai
|
|
7
|
-
const SessionPlugin = require('../plugins/session
|
|
6
|
+
const AIPlugin = require('../plugins/core/ai');
|
|
7
|
+
const SessionPlugin = require('../plugins/core/session');
|
|
8
8
|
require('dotenv').config();
|
|
9
9
|
|
|
10
10
|
async function main() {
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const { Framework } = require('../src');
|
|
6
|
-
const AIPlugin = require('../plugins/ai
|
|
7
|
-
const SessionPlugin = require('../plugins/session
|
|
6
|
+
const AIPlugin = require('../plugins/core/ai');
|
|
7
|
+
const SessionPlugin = require('../plugins/core/session');
|
|
8
8
|
require('dotenv').config();
|
|
9
9
|
|
|
10
10
|
async function main() {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { Framework } = require('../src');
|
|
7
|
-
const AIPlugin = require('../plugins/ai
|
|
8
|
-
const SessionPlugin = require('../plugins/session
|
|
7
|
+
const AIPlugin = require('../plugins/core/ai');
|
|
8
|
+
const SessionPlugin = require('../plugins/core/session');
|
|
9
9
|
require('dotenv').config();
|
|
10
10
|
|
|
11
11
|
async function main() {
|
|
@@ -21,14 +21,14 @@ async function main() {
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
// 加载微信插件
|
|
24
|
-
const { WeixinPlugin } = require('../plugins/weixin
|
|
24
|
+
const { WeixinPlugin } = require('../plugins/messaging/weixin');
|
|
25
25
|
const weixinPlugin = new WeixinPlugin({
|
|
26
26
|
forceLogin: false,
|
|
27
27
|
allowedUsers: [], // 空数组表示允许所有人
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
// 加载飞书插件
|
|
31
|
-
const { FeishuPlugin } = require('../plugins/feishu
|
|
31
|
+
const { FeishuPlugin } = require('../plugins/messaging/feishu');
|
|
32
32
|
const feishuPlugin = new FeishuPlugin({
|
|
33
33
|
// appId: 'your-app-id',
|
|
34
34
|
// appSecret: 'your-app-secret',
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BaseAgent - 所有 Agent 类型的公共基类
|
|
5
|
+
* 提供事件、状态、prompt 部分注册等公共功能
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { EventEmitter } = require('../common/events');
|
|
9
|
+
const { SystemPromptBuilder } = require('./prompt');
|
|
10
|
+
|
|
11
|
+
class BaseAgent extends EventEmitter {
|
|
12
|
+
constructor(framework, config = {}) {
|
|
13
|
+
super();
|
|
14
|
+
this.framework = framework;
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.name = config.name || 'Agent';
|
|
17
|
+
this._status = 'idle';
|
|
18
|
+
this._promptBuilder = new SystemPromptBuilder();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// === Status ===
|
|
22
|
+
|
|
23
|
+
getStatus() { return this._status; }
|
|
24
|
+
|
|
25
|
+
resetStatus() {
|
|
26
|
+
this._status = 'idle';
|
|
27
|
+
this.emit('status', { status: 'idle' });
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// === Prompt Parts ===
|
|
32
|
+
|
|
33
|
+
registerPromptPart(name, priority, provider) {
|
|
34
|
+
this._promptBuilder.register(name, priority, provider);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
unregisterPromptPart(name) {
|
|
39
|
+
this._promptBuilder.unregister(name);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
invalidatePromptPart(name) {
|
|
44
|
+
this._promptBuilder.invalidate(name);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// === Destroy ===
|
|
49
|
+
|
|
50
|
+
destroy() {
|
|
51
|
+
this.removeAllListeners();
|
|
52
|
+
this.emit('destroyed');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { BaseAgent };
|
|
@@ -8,23 +8,23 @@
|
|
|
8
8
|
* - ContextCompressor: 上下文压缩
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const { EventEmitter } = require('../
|
|
12
|
-
const { logger } = require('../
|
|
11
|
+
const { EventEmitter } = require('../common/events');
|
|
12
|
+
const { logger } = require('../common/logger');
|
|
13
13
|
const fs = require('fs');
|
|
14
14
|
const {
|
|
15
15
|
tool: aiTool,
|
|
16
16
|
ToolLoopAgent,
|
|
17
17
|
isLoopFinished,
|
|
18
18
|
} = require('ai');
|
|
19
|
-
const { autoSplitToolResult } = require('../../plugins/data-splitter
|
|
19
|
+
const { autoSplitToolResult } = require('../../plugins/executors/data-splitter');
|
|
20
20
|
const { cleanResponse } = require('../utils');
|
|
21
|
-
const { ChatQueueManager } = require('../
|
|
22
|
-
const { TokenCounter } = require('
|
|
23
|
-
const { isThinkingModel } = require('
|
|
21
|
+
const { ChatQueueManager } = require('../common/queue');
|
|
22
|
+
const { TokenCounter } = require('../llm/tokens');
|
|
23
|
+
const { isThinkingModel } = require('../llm/provider');
|
|
24
24
|
// 新模块
|
|
25
|
-
const { ChatSession } = require('
|
|
26
|
-
const { ToolExecutor } = require('
|
|
27
|
-
const { ContextCompressor } = require('
|
|
25
|
+
const { ChatSession } = require('../session/chat');
|
|
26
|
+
const { ToolExecutor } = require('../tool/executor');
|
|
27
|
+
const { ContextCompressor } = require('../context/compressor');
|
|
28
28
|
const {
|
|
29
29
|
DEFAULT_MAX_OUTPUT_TOKENS,
|
|
30
30
|
DEFAULT_TEMPERATURE,
|
|
@@ -32,7 +32,7 @@ const {
|
|
|
32
32
|
DEFAULT_MAX_CONCURRENT,
|
|
33
33
|
DEFAULT_RETRY_ATTEMPTS,
|
|
34
34
|
DEFAULT_RETRY_DELAY_MS,
|
|
35
|
-
} = require('
|
|
35
|
+
} = require('../common/constants');
|
|
36
36
|
|
|
37
37
|
class AgentChatHandler extends EventEmitter {
|
|
38
38
|
/**
|
|
@@ -254,7 +254,7 @@ class AgentChatHandler extends EventEmitter {
|
|
|
254
254
|
* @private
|
|
255
255
|
*/
|
|
256
256
|
_createAIProvider() {
|
|
257
|
-
const { createAI, createModel } = require('
|
|
257
|
+
const { createAI, createModel } = require('../llm/provider');
|
|
258
258
|
const aiProvider = createAI({
|
|
259
259
|
provider: this.provider,
|
|
260
260
|
model: this.model,
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* 管理Worker的创建、消息传递、生命周期
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const { EventEmitter } = require('../
|
|
7
|
-
const { WorkerAgent } = require('
|
|
8
|
-
const { logger } = require('../
|
|
6
|
+
const { EventEmitter } = require('../common/events');
|
|
7
|
+
const { WorkerAgent } = require('../agent/worker');
|
|
8
|
+
const { logger } = require('../common/logger');
|
|
9
9
|
|
|
10
10
|
const log = logger.child('CoordinatorManager');
|
|
11
11
|
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { BaseAgent } = require('./base');
|
|
4
|
+
const { MainAgent } = require('./main');
|
|
5
|
+
const { SubAgent } = require('./sub');
|
|
6
|
+
const { WorkerAgent } = require('./worker');
|
|
7
|
+
const { SystemPromptBuilder } = require('./prompt');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create a MainAgent instance
|
|
11
|
+
* @param {Framework} framework
|
|
12
|
+
* @param {Object} config
|
|
13
|
+
* @returns {MainAgent}
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Create a MainAgent with AI config merge
|
|
17
|
+
* @param {Framework} framework
|
|
18
|
+
* @param {Object} config
|
|
19
|
+
* @returns {MainAgent}
|
|
20
|
+
*/
|
|
21
|
+
function createAgent(framework, config = {}) {
|
|
22
|
+
const merged = _mergeAIConfig(framework, config);
|
|
23
|
+
const agent = new MainAgent(framework, merged);
|
|
24
|
+
framework._agents.push(agent);
|
|
25
|
+
if (!framework._mainAgent) {
|
|
26
|
+
framework._mainAgent = agent;
|
|
27
|
+
}
|
|
28
|
+
framework.emit('agent:created', agent);
|
|
29
|
+
return agent;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a SubAgent
|
|
34
|
+
*/
|
|
35
|
+
function createSubAgent(framework, config = {}) {
|
|
36
|
+
const aiPlugin = framework.pluginManager?.get('ai');
|
|
37
|
+
const aiConfig = aiPlugin ? aiPlugin.getConfig() : {};
|
|
38
|
+
const mergedConfig = { ...aiConfig, ...(config.llmConfig || {}) };
|
|
39
|
+
const subagent = new SubAgent({
|
|
40
|
+
name: `subagent_${config.name}`,
|
|
41
|
+
role: config.role || config.name,
|
|
42
|
+
description: config.description || '',
|
|
43
|
+
systemPrompt: config.systemPrompt,
|
|
44
|
+
model: mergedConfig.model || 'deepseek-chat',
|
|
45
|
+
provider: mergedConfig.provider || 'deepseek',
|
|
46
|
+
apiKey: mergedConfig.apiKey,
|
|
47
|
+
baseURL: mergedConfig.baseURL,
|
|
48
|
+
providerOptions: { maxOutputTokens: mergedConfig.maxOutputTokens || 8192, temperature: mergedConfig.temperature || 0.3 },
|
|
49
|
+
tools: config.tools || {},
|
|
50
|
+
parentTools: config.parentTools,
|
|
51
|
+
framework,
|
|
52
|
+
maxRetries: config.maxRetries,
|
|
53
|
+
disableTools: config.disableTools,
|
|
54
|
+
});
|
|
55
|
+
_syncPromptParts(framework, subagent);
|
|
56
|
+
framework._agents.push(subagent);
|
|
57
|
+
framework.emit('agent:created', subagent);
|
|
58
|
+
return subagent;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a Session-bound Agent
|
|
63
|
+
*/
|
|
64
|
+
function createSessionAgent(framework, sessionId, config = {}) {
|
|
65
|
+
return createAgent(framework, { name: `session_${sessionId}`, ...config, sessionId });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Merge AI plugin config into agent config
|
|
70
|
+
*/
|
|
71
|
+
function _mergeAIConfig(framework, target) {
|
|
72
|
+
if (target.apiKey) return target;
|
|
73
|
+
const aiPlugin = framework.pluginManager?.get('ai');
|
|
74
|
+
if (!aiPlugin) return target;
|
|
75
|
+
return {
|
|
76
|
+
...target,
|
|
77
|
+
apiKey: target.apiKey || aiPlugin.config?.apiKey,
|
|
78
|
+
provider: target.provider || aiPlugin.config?.provider,
|
|
79
|
+
model: target.model || aiPlugin.config?.model,
|
|
80
|
+
baseURL: target.baseURL || aiPlugin.config?.baseURL,
|
|
81
|
+
providerOptions: target.providerOptions || aiPlugin.config?.providerOptions || {},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Sync main agent prompt parts to subagent
|
|
87
|
+
*/
|
|
88
|
+
function _syncPromptParts(framework, subagent) {
|
|
89
|
+
if (!framework._mainAgent?._systemPromptBuilder?._parts) return;
|
|
90
|
+
const mainParts = framework._mainAgent._systemPromptBuilder._parts;
|
|
91
|
+
const registeredNames = new Set(subagent._promptParts?.map(p => p.name) || []);
|
|
92
|
+
for (const [name, part] of mainParts) {
|
|
93
|
+
if (['original-prompt', 'shared-prompt', 'datetime', 'metadata', 'capabilities'].includes(name)) continue;
|
|
94
|
+
if (!registeredNames.has(name)) {
|
|
95
|
+
subagent.registerPromptPart(name, part.priority, part.provider);
|
|
96
|
+
registeredNames.add(name);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = {
|
|
102
|
+
BaseAgent,
|
|
103
|
+
MainAgent,
|
|
104
|
+
SubAgent,
|
|
105
|
+
WorkerAgent,
|
|
106
|
+
SystemPromptBuilder,
|
|
107
|
+
createAgent,
|
|
108
|
+
createSubAgent,
|
|
109
|
+
createSessionAgent,
|
|
110
|
+
_syncPromptParts,
|
|
111
|
+
};
|