foliko 1.0.73 → 1.0.75
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/.shared/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
- package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
- package/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
- 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 +258 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/search.py +106 -0
- package/.agent/ARCHITECTURE.md +288 -0
- package/.agent/agents/ambient-agent.md +57 -0
- package/.agent/agents/debugger.md +55 -0
- package/.agent/agents/email-assistant.md +49 -0
- package/.agent/agents/file-manager.md +42 -0
- package/.agent/agents/python-developer.md +60 -0
- package/.agent/agents/scheduler.md +59 -0
- package/.agent/agents/web-developer.md +45 -0
- package/.agent/data/default.json +29 -0
- package/.agent/data/plugins-state.json +255 -0
- package/.agent/mcp_config.json +4 -0
- package/.agent/mcp_config_updated.json +12 -0
- package/.agent/plugins.json +5 -0
- package/.agent/rules/GEMINI.md +273 -0
- package/.agent/rules/allow-rule.md +77 -0
- package/.agent/rules/log-rule.md +83 -0
- package/.agent/rules/security-rule.md +93 -0
- package/.agent/scripts/auto_preview.py +148 -0
- package/.agent/scripts/checklist.py +217 -0
- package/.agent/scripts/session_manager.py +120 -0
- package/.agent/scripts/verify_all.py +327 -0
- package/.agent/skills/api-patterns/SKILL.md +81 -0
- package/.agent/skills/api-patterns/api-style.md +42 -0
- package/.agent/skills/api-patterns/auth.md +24 -0
- package/.agent/skills/api-patterns/documentation.md +26 -0
- package/.agent/skills/api-patterns/graphql.md +41 -0
- package/.agent/skills/api-patterns/rate-limiting.md +31 -0
- package/.agent/skills/api-patterns/response.md +37 -0
- package/.agent/skills/api-patterns/rest.md +40 -0
- package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
- package/.agent/skills/api-patterns/security-testing.md +122 -0
- package/.agent/skills/api-patterns/trpc.md +41 -0
- package/.agent/skills/api-patterns/versioning.md +22 -0
- package/.agent/skills/app-builder/SKILL.md +75 -0
- package/.agent/skills/app-builder/agent-coordination.md +71 -0
- package/.agent/skills/app-builder/feature-building.md +53 -0
- package/.agent/skills/app-builder/project-detection.md +34 -0
- package/.agent/skills/app-builder/scaffolding.md +118 -0
- package/.agent/skills/app-builder/tech-stack.md +40 -0
- package/.agent/skills/app-builder/templates/SKILL.md +39 -0
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
- package/.agent/skills/architecture/SKILL.md +55 -0
- package/.agent/skills/architecture/context-discovery.md +43 -0
- package/.agent/skills/architecture/examples.md +94 -0
- package/.agent/skills/architecture/pattern-selection.md +68 -0
- package/.agent/skills/architecture/patterns-reference.md +50 -0
- package/.agent/skills/architecture/trade-off-analysis.md +77 -0
- package/.agent/skills/clean-code/SKILL.md +201 -0
- package/.agent/skills/doc.md +177 -0
- package/.agent/skills/frontend-design/SKILL.md +418 -0
- package/.agent/skills/frontend-design/animation-guide.md +331 -0
- package/.agent/skills/frontend-design/color-system.md +311 -0
- package/.agent/skills/frontend-design/decision-trees.md +418 -0
- package/.agent/skills/frontend-design/motion-graphics.md +306 -0
- package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/.agent/skills/frontend-design/typography-system.md +345 -0
- package/.agent/skills/frontend-design/ux-psychology.md +1116 -0
- package/.agent/skills/frontend-design/visual-effects.md +383 -0
- package/.agent/skills/i18n-localization/SKILL.md +154 -0
- package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
- package/.agent/skills/mcp-builder/SKILL.md +176 -0
- package/.agent/skills/web-design-guidelines/SKILL.md +57 -0
- package/.agent/workflows/brainstorm.md +113 -0
- package/.agent/workflows/create.md +59 -0
- package/.agent/workflows/debug.md +103 -0
- package/.agent/workflows/deploy.md +176 -0
- package/.agent/workflows/enhance.md +63 -0
- package/.agent/workflows/orchestrate.md +237 -0
- package/.agent/workflows/plan.md +89 -0
- package/.agent/workflows/preview.md +81 -0
- package/.agent/workflows/simple-test.md +42 -0
- package/.agent/workflows/status.md +86 -0
- package/.agent/workflows/structured-orchestrate.md +180 -0
- package/.agent/workflows/test.md +144 -0
- package/.agent/workflows/ui-ux-pro-max.md +296 -0
- package/.claude/settings.local.json +157 -149
- package/.editorconfig +56 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc +7 -0
- package/.prettierignore +29 -0
- package/.prettierrc +11 -0
- package/CLAUDE.md +2 -0
- package/README.md +64 -55
- package/SPEC.md +102 -61
- package/cli/bin/foliko.js +4 -4
- package/cli/src/commands/chat.js +53 -51
- package/cli/src/commands/list.js +40 -37
- package/cli/src/index.js +18 -18
- package/cli/src/ui/chat-ui.js +78 -76
- package/cli/src/utils/ansi.js +15 -15
- package/cli/src/utils/markdown.js +112 -116
- package/docker-compose.yml +1 -1
- package/docs/ai-sdk-optimization.md +655 -636
- package/docs/features.md +80 -80
- package/docs/quick-reference.md +49 -46
- package/docs/user-manual.md +411 -380
- package/examples/ambient-example.js +95 -97
- package/examples/basic.js +115 -110
- package/examples/bootstrap.js +52 -43
- package/examples/mcp-example.js +56 -53
- package/examples/skill-example.js +49 -49
- package/examples/test-chat.js +60 -58
- package/examples/test-mcp.js +49 -43
- package/examples/test-reload.js +38 -40
- package/examples/test-telegram.js +3 -3
- package/examples/test-tg-bot.js +7 -4
- package/examples/test-tg-simple.js +4 -3
- package/examples/test-tg.js +3 -3
- package/examples/test-think.js +13 -7
- package/examples/test-web-plugin.js +61 -56
- package/examples/test-weixin-feishu.js +40 -37
- package/examples/workflow.js +49 -49
- package/foliko-1.0.75.tgz +0 -0
- package/package.json +37 -3
- package/plugins/ai-plugin.js +7 -5
- package/plugins/ambient-agent/EventWatcher.js +113 -0
- package/plugins/ambient-agent/ExplorerLoop.js +640 -0
- package/plugins/ambient-agent/GoalManager.js +197 -0
- package/plugins/ambient-agent/Reflector.js +95 -0
- package/plugins/ambient-agent/StateStore.js +90 -0
- package/plugins/ambient-agent/constants.js +101 -0
- package/plugins/ambient-agent/index.js +579 -0
- package/plugins/default-plugins.js +62 -49
- package/plugins/email/constants.js +64 -0
- package/plugins/email/handlers.js +461 -0
- package/plugins/email/index.js +278 -0
- package/plugins/email/monitor.js +269 -0
- package/plugins/email/parser.js +138 -0
- package/plugins/email/reply.js +151 -0
- package/plugins/email/utils.js +124 -0
- package/plugins/feishu-plugin.js +23 -19
- package/plugins/file-system-plugin.js +469 -120
- package/plugins/install-plugin.js +6 -4
- package/plugins/python-executor-plugin.js +3 -1
- package/plugins/python-plugin-loader.js +10 -8
- package/plugins/rules-plugin.js +5 -3
- package/plugins/scheduler-plugin.js +18 -16
- package/plugins/session-plugin.js +3 -1
- package/plugins/storage-plugin.js +5 -3
- package/plugins/subagent-plugin.js +152 -92
- package/plugins/telegram-plugin.js +26 -19
- package/plugins/think-plugin.js +4 -2
- package/plugins/tools-plugin.js +3 -1
- package/plugins/web-plugin.js +15 -13
- package/plugins/weixin-plugin.js +43 -36
- package/reports/system-health-report-20260401.md +79 -0
- package/skills/ambient-agent/SKILL.md +49 -39
- package/skills/foliko-dev/AGENTS.md +64 -61
- package/skills/foliko-dev/SKILL.md +125 -119
- package/skills/mcp-usage/SKILL.md +19 -17
- package/skills/python-plugin-dev/SKILL.md +16 -15
- package/skills/skill-guide/SKILL.md +12 -12
- package/skills/subagent-guide/SKILL.md +237 -0
- package/skills/workflow-guide/SKILL.md +90 -45
- package/skills/workflow-troubleshooting/DEBUGGING.md +36 -21
- package/skills/workflow-troubleshooting/SKILL.md +156 -79
- package/src/capabilities/index.js +4 -4
- package/src/capabilities/skill-manager.js +211 -197
- package/src/capabilities/workflow-engine.js +461 -547
- package/src/core/agent-chat.js +426 -279
- package/src/core/agent.js +453 -248
- package/src/core/framework.js +183 -149
- package/src/core/index.js +8 -8
- package/src/core/plugin-base.js +52 -52
- package/src/core/plugin-manager.js +377 -281
- package/src/core/provider.js +35 -32
- package/src/core/sub-agent-config.js +264 -0
- package/src/core/system-prompt-builder.js +120 -0
- package/src/core/tool-registry.js +416 -33
- package/src/core/tool-router.js +149 -68
- package/src/executors/executor-base.js +58 -58
- package/src/executors/mcp-executor.js +269 -257
- package/src/index.js +5 -17
- package/src/utils/circuit-breaker.js +301 -0
- package/src/utils/error-boundary.js +363 -0
- package/src/utils/error.js +374 -0
- package/src/utils/event-emitter.js +20 -20
- package/src/utils/id.js +133 -0
- package/src/utils/index.js +217 -3
- package/src/utils/logger.js +181 -0
- package/src/utils/plugin-helpers.js +90 -0
- package/src/utils/retry.js +122 -0
- package/src/utils/sandbox.js +292 -0
- package/test/tool-registry-validation.test.js +218 -0
- package/test_report.md +70 -0
- package/website/docs/api.html +169 -107
- package/website/docs/configuration.html +296 -144
- package/website/docs/plugin-development.html +154 -85
- package/website/docs/project-structure.html +110 -109
- package/website/docs/skill-development.html +117 -61
- package/website/index.html +209 -205
- package/website/script.js +20 -17
- package/website/styles.css +1 -1
- package/plugins/ambient-agent-plugin.js +0 -1565
- package/plugins/email.js +0 -1142
package/src/core/framework.js
CHANGED
|
@@ -3,22 +3,23 @@
|
|
|
3
3
|
* 管理所有子系统,提供统一入口
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const path = require('path')
|
|
7
|
-
const { AsyncLocalStorage } = require('async_hooks')
|
|
8
|
-
const { EventEmitter } = require('../utils/event-emitter')
|
|
9
|
-
const { PluginManager } = require('./plugin-manager')
|
|
10
|
-
const { ToolRegistry } = require('./tool-registry')
|
|
11
|
-
const { Agent } = require('./agent')
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { AsyncLocalStorage } = require('async_hooks');
|
|
8
|
+
const { EventEmitter } = require('../utils/event-emitter');
|
|
9
|
+
const { PluginManager } = require('./plugin-manager');
|
|
10
|
+
const { ToolRegistry } = require('./tool-registry');
|
|
11
|
+
const { Agent } = require('./agent');
|
|
12
|
+
const { SubAgentConfigManager } = require('./sub-agent-config');
|
|
12
13
|
|
|
13
14
|
// 添加框架目录的 node_modules 到全局搜索路径
|
|
14
15
|
// 让项目插件能 require 框架内置的包(如 zod)
|
|
15
|
-
const frameworkNodeModules = path.join(__dirname, '..', '..', 'node_modules')
|
|
16
|
+
const frameworkNodeModules = path.join(__dirname, '..', '..', 'node_modules');
|
|
16
17
|
if (!module.paths.includes(frameworkNodeModules)) {
|
|
17
|
-
module.paths.unshift(frameworkNodeModules)
|
|
18
|
+
module.paths.unshift(frameworkNodeModules);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
// AsyncLocalStorage 实现真正的上下文隔离(支持并行处理)
|
|
21
|
-
const asyncLocalStorage = new AsyncLocalStorage()
|
|
22
|
+
const asyncLocalStorage = new AsyncLocalStorage();
|
|
22
23
|
|
|
23
24
|
class Framework extends EventEmitter {
|
|
24
25
|
/**
|
|
@@ -26,30 +27,62 @@ class Framework extends EventEmitter {
|
|
|
26
27
|
* @param {boolean} [config.debug=false] - 调试模式
|
|
27
28
|
*/
|
|
28
29
|
constructor(config = {}) {
|
|
29
|
-
super()
|
|
30
|
+
super();
|
|
30
31
|
|
|
31
|
-
this._debug = config.debug || false
|
|
32
|
-
this._ready = false
|
|
33
|
-
this._readyPromise = null
|
|
34
|
-
this._resolveReady = null
|
|
32
|
+
this._debug = config.debug || false;
|
|
33
|
+
this._ready = false;
|
|
34
|
+
this._readyPromise = null;
|
|
35
|
+
this._resolveReady = null;
|
|
35
36
|
|
|
36
37
|
// 初始化子系统
|
|
37
|
-
this.toolRegistry = new ToolRegistry()
|
|
38
|
-
this.pluginManager = new PluginManager(this)
|
|
38
|
+
this.toolRegistry = new ToolRegistry();
|
|
39
|
+
this.pluginManager = new PluginManager(this);
|
|
39
40
|
|
|
40
41
|
// Agent 管理
|
|
41
|
-
this._agents = []
|
|
42
|
-
this._mainAgent = null
|
|
42
|
+
this._agents = []; // 所有创建的 agent
|
|
43
|
+
this._mainAgent = null; // 主 agent
|
|
44
|
+
|
|
45
|
+
// 子代理配置管理器
|
|
46
|
+
this._subAgentConfigManager = null;
|
|
43
47
|
|
|
44
48
|
// 执行上下文(工具调用时可用)
|
|
45
|
-
this._executionContext = null
|
|
49
|
+
this._executionContext = null;
|
|
46
50
|
|
|
47
51
|
// 事件转发
|
|
48
52
|
this.toolRegistry.on('tool:registered', (tool) => {
|
|
49
|
-
this.emit('tool:registered', tool)
|
|
50
|
-
})
|
|
53
|
+
this.emit('tool:registered', tool);
|
|
54
|
+
});
|
|
51
55
|
|
|
52
|
-
this._registerBuiltinTools()
|
|
56
|
+
this._registerBuiltinTools();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 从 AI 插件合并配置到目标配置对象
|
|
61
|
+
* @param {Object} target - 目标配置对象
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
_mergeAIConfig(target) {
|
|
65
|
+
if (target.apiKey) return target; // 已有 apiKey 不需要合并
|
|
66
|
+
|
|
67
|
+
const aiPlugin = this.pluginManager.get('ai');
|
|
68
|
+
if (!aiPlugin) return target;
|
|
69
|
+
|
|
70
|
+
const defaults = {
|
|
71
|
+
apiKey: aiPlugin.config.apiKey,
|
|
72
|
+
provider: aiPlugin.config.provider,
|
|
73
|
+
model: aiPlugin.config.model,
|
|
74
|
+
baseURL: aiPlugin.config.baseURL,
|
|
75
|
+
providerOptions: aiPlugin.config.providerOptions || {},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
...target,
|
|
80
|
+
apiKey: target.apiKey || defaults.apiKey,
|
|
81
|
+
provider: target.provider || defaults.provider,
|
|
82
|
+
model: target.model || defaults.model,
|
|
83
|
+
baseURL: target.baseURL || defaults.baseURL,
|
|
84
|
+
providerOptions: target.providerOptions || defaults.providerOptions,
|
|
85
|
+
};
|
|
53
86
|
}
|
|
54
87
|
|
|
55
88
|
/**
|
|
@@ -57,17 +90,17 @@ class Framework extends EventEmitter {
|
|
|
57
90
|
* @param {Plugin|Object} plugin - 插件
|
|
58
91
|
*/
|
|
59
92
|
registerPlugin(plugin) {
|
|
60
|
-
this.pluginManager.register(plugin)
|
|
61
|
-
return this
|
|
93
|
+
this.pluginManager.register(plugin);
|
|
94
|
+
return this;
|
|
62
95
|
}
|
|
63
96
|
|
|
64
97
|
/**
|
|
65
|
-
*
|
|
98
|
+
* 加载并启动插件)
|
|
66
99
|
* @param {Plugin|Object} plugin - 插件
|
|
67
100
|
*/
|
|
68
101
|
async loadPlugin(plugin) {
|
|
69
|
-
await this.pluginManager.load(plugin)
|
|
70
|
-
return this
|
|
102
|
+
await this.pluginManager.load(plugin);
|
|
103
|
+
return this;
|
|
71
104
|
}
|
|
72
105
|
|
|
73
106
|
/**
|
|
@@ -75,8 +108,8 @@ class Framework extends EventEmitter {
|
|
|
75
108
|
* @param {string} name - 插件名称
|
|
76
109
|
*/
|
|
77
110
|
async unloadPlugin(name) {
|
|
78
|
-
await this.pluginManager.unload(name)
|
|
79
|
-
return this
|
|
111
|
+
await this.pluginManager.unload(name);
|
|
112
|
+
return this;
|
|
80
113
|
}
|
|
81
114
|
|
|
82
115
|
/**
|
|
@@ -84,16 +117,16 @@ class Framework extends EventEmitter {
|
|
|
84
117
|
* @param {string} name - 插件名称
|
|
85
118
|
*/
|
|
86
119
|
async reloadPlugin(name) {
|
|
87
|
-
await this.pluginManager.reload(name)
|
|
88
|
-
return this
|
|
120
|
+
await this.pluginManager.reload(name);
|
|
121
|
+
return this;
|
|
89
122
|
}
|
|
90
123
|
|
|
91
124
|
/**
|
|
92
|
-
*
|
|
125
|
+
* 重载所有插件)
|
|
93
126
|
*/
|
|
94
127
|
async reloadAllPlugins() {
|
|
95
|
-
await this.pluginManager.reloadAll()
|
|
96
|
-
return this
|
|
128
|
+
await this.pluginManager.reloadAll();
|
|
129
|
+
return this;
|
|
97
130
|
}
|
|
98
131
|
|
|
99
132
|
/**
|
|
@@ -101,8 +134,8 @@ class Framework extends EventEmitter {
|
|
|
101
134
|
* @param {string} name - 插件名称
|
|
102
135
|
*/
|
|
103
136
|
async enablePlugin(name) {
|
|
104
|
-
await this.pluginManager.enable(name)
|
|
105
|
-
return this
|
|
137
|
+
await this.pluginManager.enable(name);
|
|
138
|
+
return this;
|
|
106
139
|
}
|
|
107
140
|
|
|
108
141
|
/**
|
|
@@ -110,8 +143,8 @@ class Framework extends EventEmitter {
|
|
|
110
143
|
* @param {string} name - 插件名称
|
|
111
144
|
*/
|
|
112
145
|
async disablePlugin(name) {
|
|
113
|
-
await this.pluginManager.disable(name)
|
|
114
|
-
return this
|
|
146
|
+
await this.pluginManager.disable(name);
|
|
147
|
+
return this;
|
|
115
148
|
}
|
|
116
149
|
|
|
117
150
|
/**
|
|
@@ -120,7 +153,7 @@ class Framework extends EventEmitter {
|
|
|
120
153
|
* @param {Object} config - 新配置
|
|
121
154
|
*/
|
|
122
155
|
updatePluginConfig(name, config) {
|
|
123
|
-
return this.pluginManager.updatePluginConfig(name, config)
|
|
156
|
+
return this.pluginManager.updatePluginConfig(name, config);
|
|
124
157
|
}
|
|
125
158
|
|
|
126
159
|
/**
|
|
@@ -128,16 +161,48 @@ class Framework extends EventEmitter {
|
|
|
128
161
|
* @param {Object} tool - 工具定义
|
|
129
162
|
*/
|
|
130
163
|
registerTool(tool) {
|
|
131
|
-
this.toolRegistry.register(tool)
|
|
132
|
-
return this
|
|
164
|
+
this.toolRegistry.register(tool);
|
|
165
|
+
return this;
|
|
133
166
|
}
|
|
134
167
|
|
|
135
168
|
/**
|
|
136
|
-
*
|
|
169
|
+
* 获取所有工具)
|
|
137
170
|
* @returns {Array<Object>}
|
|
138
171
|
*/
|
|
139
172
|
getTools() {
|
|
140
|
-
return this.toolRegistry.getAll()
|
|
173
|
+
return this.toolRegistry.getAll();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ============================================================================
|
|
177
|
+
// 事件描述注册(供 Ambient Agent 使用)
|
|
178
|
+
// ============================================================================
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 注册事件描述
|
|
182
|
+
* @param {string} eventType - 事件类型,如 'tool:result'
|
|
183
|
+
* @param {string} description - 事件描述
|
|
184
|
+
* @param {Object} schema - 事件参数 Schema(可选)
|
|
185
|
+
*/
|
|
186
|
+
registerEventDescription(eventType, description, schema = null) {
|
|
187
|
+
this.pluginManager.registerEventDescription(eventType, description, schema);
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 获取所有已注册的事件描述
|
|
193
|
+
* @returns {Map<string, Object>} 事件描述 Map
|
|
194
|
+
*/
|
|
195
|
+
getEventDescriptions() {
|
|
196
|
+
return this.pluginManager.getEventDescriptions();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 获取单个事件描述
|
|
201
|
+
* @param {string} eventType - 事件类型
|
|
202
|
+
* @returns {Object|null} 事件描述
|
|
203
|
+
*/
|
|
204
|
+
getEventDescription(eventType) {
|
|
205
|
+
return this.pluginManager.getEventDescription(eventType);
|
|
141
206
|
}
|
|
142
207
|
|
|
143
208
|
/**
|
|
@@ -146,7 +211,7 @@ class Framework extends EventEmitter {
|
|
|
146
211
|
* @param {Object} args - 参数
|
|
147
212
|
*/
|
|
148
213
|
async executeTool(name, args) {
|
|
149
|
-
return this.toolRegistry.execute(name, args, this)
|
|
214
|
+
return this.toolRegistry.execute(name, args, this);
|
|
150
215
|
}
|
|
151
216
|
|
|
152
217
|
/**
|
|
@@ -156,7 +221,7 @@ class Framework extends EventEmitter {
|
|
|
156
221
|
* @returns {Promise}
|
|
157
222
|
*/
|
|
158
223
|
runWithContext(context, fn) {
|
|
159
|
-
return asyncLocalStorage.run(context, fn)
|
|
224
|
+
return asyncLocalStorage.run(context, fn);
|
|
160
225
|
}
|
|
161
226
|
|
|
162
227
|
/**
|
|
@@ -164,7 +229,7 @@ class Framework extends EventEmitter {
|
|
|
164
229
|
* @returns {Object|null}
|
|
165
230
|
*/
|
|
166
231
|
getExecutionContext() {
|
|
167
|
-
return asyncLocalStorage.getStore() || null
|
|
232
|
+
return asyncLocalStorage.getStore() || null;
|
|
168
233
|
}
|
|
169
234
|
|
|
170
235
|
/**
|
|
@@ -182,61 +247,45 @@ class Framework extends EventEmitter {
|
|
|
182
247
|
* @param {Object} config - Agent 配置
|
|
183
248
|
*/
|
|
184
249
|
createAgent(config) {
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
const aiPlugin = this.pluginManager.get('ai')
|
|
188
|
-
if (aiPlugin) {
|
|
189
|
-
config.apiKey = aiPlugin.config.apiKey
|
|
190
|
-
config.provider = config.provider || aiPlugin.config.provider
|
|
191
|
-
config.model = config.model || aiPlugin.config.model
|
|
192
|
-
config.baseURL = config.baseURL || aiPlugin.config.baseURL
|
|
193
|
-
}
|
|
194
|
-
}
|
|
250
|
+
// 合并 AI 插件配置
|
|
251
|
+
config = this._mergeAIConfig(config);
|
|
195
252
|
|
|
196
|
-
const agent = new Agent(this, config)
|
|
253
|
+
const agent = new Agent(this, config);
|
|
197
254
|
|
|
198
255
|
// 跟踪 agent
|
|
199
|
-
this._agents.push(agent)
|
|
256
|
+
this._agents.push(agent);
|
|
200
257
|
if (!this._mainAgent) {
|
|
201
|
-
this._mainAgent = agent
|
|
258
|
+
this._mainAgent = agent;
|
|
202
259
|
}
|
|
203
260
|
|
|
204
|
-
this.emit('agent:created', agent)
|
|
205
|
-
return agent
|
|
261
|
+
this.emit('agent:created', agent);
|
|
262
|
+
return agent;
|
|
206
263
|
}
|
|
207
264
|
|
|
208
265
|
/**
|
|
209
|
-
* 为指定 session
|
|
266
|
+
* 为指定 session 创建独立 Agent 实例
|
|
210
267
|
* @param {string} sessionId - session ID
|
|
211
268
|
* @param {Object} config - Agent 配置
|
|
212
269
|
*/
|
|
213
270
|
createSessionAgent(sessionId, config = {}) {
|
|
214
271
|
const agentConfig = {
|
|
215
272
|
name: `session_${sessionId}`,
|
|
216
|
-
...config
|
|
217
|
-
}
|
|
273
|
+
...config,
|
|
274
|
+
};
|
|
218
275
|
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
agentConfig.provider = agentConfig.provider || aiPlugin.config.provider
|
|
225
|
-
agentConfig.model = agentConfig.model || aiPlugin.config.model
|
|
226
|
-
agentConfig.baseURL = agentConfig.baseURL || aiPlugin.config.baseURL,
|
|
227
|
-
agentConfig.providerOptions||aiPlugin.config.providerOptions||{}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const agent = new Agent(this, agentConfig)
|
|
231
|
-
this._agents.push(agent)
|
|
276
|
+
// 合并 AI 插件配置
|
|
277
|
+
const merged = this._mergeAIConfig(agentConfig);
|
|
278
|
+
|
|
279
|
+
const agent = new Agent(this, merged);
|
|
280
|
+
this._agents.push(agent);
|
|
232
281
|
|
|
233
|
-
// 如果提供了 systemPrompt
|
|
234
|
-
if (
|
|
235
|
-
agent.setSystemPrompt(
|
|
282
|
+
// 如果提供了 systemPrompt,需要替换 AgentChatHandler
|
|
283
|
+
if (merged.systemPrompt) {
|
|
284
|
+
agent.setSystemPrompt(merged.systemPrompt);
|
|
236
285
|
}
|
|
237
286
|
|
|
238
|
-
this.emit('agent:created', agent)
|
|
239
|
-
return agent
|
|
287
|
+
this.emit('agent:created', agent);
|
|
288
|
+
return agent;
|
|
240
289
|
}
|
|
241
290
|
|
|
242
291
|
/**
|
|
@@ -244,9 +293,9 @@ class Framework extends EventEmitter {
|
|
|
244
293
|
* @param {Object} config - 子Agent配置
|
|
245
294
|
* @param {string} config.name - 子Agent名称
|
|
246
295
|
* @param {string} config.role - 角色描述(用于智能选择)
|
|
247
|
-
* @param {string} [config.description] - 供主Agent
|
|
296
|
+
* @param {string} [config.description] - 供主Agent理解的描述)
|
|
248
297
|
* @param {Object} [config.tools] - 自定义工具 { name: toolDef }
|
|
249
|
-
* @param {string[]} [config.parentTools] - 从父Agent
|
|
298
|
+
* @param {string[]} [config.parentTools] - 从父Agent继承的工具名称列表)
|
|
250
299
|
* @param {Object} [config.llmConfig] - 独立LLM配置
|
|
251
300
|
* @returns {Agent} 创建的子Agent
|
|
252
301
|
*/
|
|
@@ -256,32 +305,23 @@ class Framework extends EventEmitter {
|
|
|
256
305
|
role,
|
|
257
306
|
description = '',
|
|
258
307
|
tools = {},
|
|
259
|
-
parentTools,
|
|
260
|
-
llmConfig = null
|
|
261
|
-
} = config
|
|
308
|
+
parentTools, // 如果不传,默认继承主agent所有工具
|
|
309
|
+
llmConfig = null,
|
|
310
|
+
} = config;
|
|
262
311
|
|
|
263
312
|
// 构建子Agent配置
|
|
264
313
|
const agentConfig = {
|
|
265
314
|
name: `subagent_${name}`,
|
|
266
315
|
role: role,
|
|
267
|
-
systemPrompt: role,
|
|
268
|
-
...(llmConfig || {})
|
|
269
|
-
}
|
|
316
|
+
systemPrompt: role, // 使用 role 作为 systemPrompt
|
|
317
|
+
...(llmConfig || {}), // 如果提供了独立LLM配置,合并
|
|
318
|
+
};
|
|
270
319
|
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
const aiPlugin = this.pluginManager.get('ai')
|
|
274
|
-
if (aiPlugin) {
|
|
275
|
-
agentConfig.apiKey = aiPlugin.config.apiKey
|
|
276
|
-
agentConfig.provider = agentConfig.provider || aiPlugin.config.provider
|
|
277
|
-
agentConfig.model = agentConfig.model || aiPlugin.config.model
|
|
278
|
-
agentConfig.baseURL = agentConfig.baseURL || aiPlugin.config.baseURL
|
|
279
|
-
agentConfig.providerOptions = agentConfig.providerOptions || aiPlugin.config.providerOptions || {}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
320
|
+
// 合并 AI 插件配置
|
|
321
|
+
const merged = this._mergeAIConfig(agentConfig);
|
|
282
322
|
|
|
283
323
|
// 创建 Agent
|
|
284
|
-
const agent = new Agent(this,
|
|
324
|
+
const agent = new Agent(this, merged);
|
|
285
325
|
|
|
286
326
|
// 注册自定义工具
|
|
287
327
|
for (const [toolName, toolDef] of Object.entries(tools)) {
|
|
@@ -290,33 +330,33 @@ class Framework extends EventEmitter {
|
|
|
290
330
|
name: toolName,
|
|
291
331
|
description: toolDef.description || '',
|
|
292
332
|
inputSchema: toolDef.inputSchema,
|
|
293
|
-
execute: toolDef.execute
|
|
294
|
-
})
|
|
333
|
+
execute: toolDef.execute,
|
|
334
|
+
});
|
|
295
335
|
}
|
|
296
336
|
}
|
|
297
337
|
|
|
298
338
|
// 从父Agent继承工具
|
|
299
339
|
if (this._mainAgent) {
|
|
300
|
-
const parentToolsDefs = this._mainAgent.getTools()
|
|
340
|
+
const parentToolsDefs = this._mainAgent.getTools();
|
|
301
341
|
if (parentTools === undefined) {
|
|
302
342
|
// 如果没有指定 parentTools,默认继承所有工具
|
|
303
343
|
for (const toolDef of parentToolsDefs) {
|
|
304
|
-
agent.registerTool(toolDef)
|
|
344
|
+
agent.registerTool(toolDef);
|
|
305
345
|
}
|
|
306
346
|
} else if (Array.isArray(parentTools) && parentTools.length > 0) {
|
|
307
347
|
// 指定了要继承的工具列表
|
|
308
348
|
for (const toolName of parentTools) {
|
|
309
|
-
const toolDef = parentToolsDefs.find(t => t.name === toolName)
|
|
349
|
+
const toolDef = parentToolsDefs.find((t) => t.name === toolName);
|
|
310
350
|
if (toolDef) {
|
|
311
|
-
agent.registerTool(toolDef)
|
|
351
|
+
agent.registerTool(toolDef);
|
|
312
352
|
}
|
|
313
353
|
}
|
|
314
354
|
}
|
|
315
355
|
}
|
|
316
356
|
|
|
317
|
-
this._agents.push(agent)
|
|
318
|
-
this.emit('agent:created', agent)
|
|
319
|
-
return agent
|
|
357
|
+
this._agents.push(agent);
|
|
358
|
+
this.emit('agent:created', agent);
|
|
359
|
+
return agent;
|
|
320
360
|
}
|
|
321
361
|
|
|
322
362
|
/**
|
|
@@ -324,40 +364,44 @@ class Framework extends EventEmitter {
|
|
|
324
364
|
* @returns {Object|undefined}
|
|
325
365
|
*/
|
|
326
366
|
getAIPlugin() {
|
|
327
|
-
return this.pluginManager.get('ai')
|
|
367
|
+
return this.pluginManager.get('ai');
|
|
328
368
|
}
|
|
329
369
|
|
|
330
370
|
/**
|
|
331
371
|
* Bootstrap - 使用默认配置启动框架
|
|
332
|
-
* 自动加载 .agent/
|
|
372
|
+
* 自动加载 .agent/ 目录下的配置和所有默认插件)
|
|
333
373
|
* @param {Object} config - 配置
|
|
334
374
|
* @param {string} [config.agentDir='.agent'] - Agent 配置目录
|
|
335
375
|
* @param {Object} [config.aiConfig] - AI 配置(可选,覆盖文件配置)
|
|
336
376
|
* @returns {Promise<Framework>}
|
|
337
377
|
*/
|
|
338
378
|
async bootstrap(config = {}) {
|
|
339
|
-
const {
|
|
379
|
+
const {
|
|
380
|
+
bootstrapDefaults,
|
|
381
|
+
DefaultPlugins,
|
|
382
|
+
loadAgentConfig,
|
|
383
|
+
} = require('../../plugins/default-plugins');
|
|
340
384
|
|
|
341
385
|
// 先加载默认插件配置
|
|
342
386
|
const defaultsPlugin = new DefaultPlugins({
|
|
343
|
-
agentDir: config.agentDir || '.agent'
|
|
344
|
-
})
|
|
387
|
+
agentDir: config.agentDir || '.agent',
|
|
388
|
+
});
|
|
345
389
|
|
|
346
|
-
await this.loadPlugin(defaultsPlugin)
|
|
390
|
+
await this.loadPlugin(defaultsPlugin);
|
|
347
391
|
|
|
348
392
|
// 获取配置
|
|
349
|
-
const agentConfig = defaultsPlugin.getConfig()
|
|
393
|
+
const agentConfig = defaultsPlugin.getConfig();
|
|
350
394
|
|
|
351
395
|
// 如果提供了 AI 配置,覆盖文件配置
|
|
352
396
|
if (config.aiConfig) {
|
|
353
|
-
agentConfig.ai = { ...agentConfig.ai, ...config.aiConfig }
|
|
397
|
+
agentConfig.ai = { ...agentConfig.ai, ...config.aiConfig };
|
|
354
398
|
}
|
|
355
399
|
|
|
356
400
|
// 加载所有默认插件(传入已加载的配置避免重复加载)
|
|
357
|
-
await bootstrapDefaults(this, { _config: agentConfig, _skipConfigLoad: true })
|
|
401
|
+
await bootstrapDefaults(this, { _config: agentConfig, _skipConfigLoad: true });
|
|
358
402
|
|
|
359
|
-
this._setReady()
|
|
360
|
-
return this
|
|
403
|
+
this._setReady();
|
|
404
|
+
return this;
|
|
361
405
|
}
|
|
362
406
|
|
|
363
407
|
/**
|
|
@@ -365,17 +409,17 @@ class Framework extends EventEmitter {
|
|
|
365
409
|
*/
|
|
366
410
|
async ready() {
|
|
367
411
|
if (this._ready) {
|
|
368
|
-
return this
|
|
412
|
+
return this;
|
|
369
413
|
}
|
|
370
414
|
|
|
371
415
|
if (!this._readyPromise) {
|
|
372
416
|
this._readyPromise = new Promise((resolve) => {
|
|
373
|
-
this._resolveReady = resolve
|
|
374
|
-
})
|
|
417
|
+
this._resolveReady = resolve;
|
|
418
|
+
});
|
|
375
419
|
}
|
|
376
420
|
|
|
377
|
-
await this._readyPromise
|
|
378
|
-
return this
|
|
421
|
+
await this._readyPromise;
|
|
422
|
+
return this;
|
|
379
423
|
}
|
|
380
424
|
|
|
381
425
|
/**
|
|
@@ -383,21 +427,11 @@ class Framework extends EventEmitter {
|
|
|
383
427
|
* @private
|
|
384
428
|
*/
|
|
385
429
|
_setReady() {
|
|
386
|
-
this._ready = true
|
|
430
|
+
this._ready = true;
|
|
387
431
|
if (this._resolveReady) {
|
|
388
|
-
this._resolveReady(this)
|
|
389
|
-
}
|
|
390
|
-
this.emit('framework:ready', this)
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* 调试日志
|
|
395
|
-
* @private
|
|
396
|
-
*/
|
|
397
|
-
_log(...args) {
|
|
398
|
-
if (this._debug) {
|
|
399
|
-
console.log('[Framework]', ...args)
|
|
432
|
+
this._resolveReady(this);
|
|
400
433
|
}
|
|
434
|
+
this.emit('framework:ready', this);
|
|
401
435
|
}
|
|
402
436
|
|
|
403
437
|
/**
|
|
@@ -405,27 +439,27 @@ class Framework extends EventEmitter {
|
|
|
405
439
|
* @private
|
|
406
440
|
*/
|
|
407
441
|
_registerBuiltinTools() {
|
|
408
|
-
// 内置工具会在 Agent
|
|
442
|
+
// 内置工具会在 Agent 创建时添加)
|
|
409
443
|
}
|
|
410
444
|
|
|
411
445
|
/**
|
|
412
|
-
*
|
|
446
|
+
* 销毁框架)
|
|
413
447
|
*/
|
|
414
448
|
async destroy() {
|
|
415
|
-
//
|
|
416
|
-
const plugins = this.pluginManager.getAll()
|
|
449
|
+
// 卸载所有插件)
|
|
450
|
+
const plugins = this.pluginManager.getAll();
|
|
417
451
|
for (const { name } of plugins) {
|
|
418
|
-
await this.pluginManager.unload(name)
|
|
452
|
+
await this.pluginManager.unload(name);
|
|
419
453
|
}
|
|
420
454
|
|
|
421
455
|
// 清空工具
|
|
422
|
-
this.toolRegistry.clear()
|
|
456
|
+
this.toolRegistry.clear();
|
|
423
457
|
|
|
424
458
|
// 清空事件
|
|
425
|
-
this.removeAllListeners()
|
|
459
|
+
this.removeAllListeners();
|
|
426
460
|
|
|
427
|
-
this.emit('framework:destroyed')
|
|
461
|
+
this.emit('framework:destroyed');
|
|
428
462
|
}
|
|
429
463
|
}
|
|
430
464
|
|
|
431
|
-
module.exports = { Framework }
|
|
465
|
+
module.exports = { Framework };
|
package/src/core/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* 核心模块统一导出
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const { Framework } = require('./framework')
|
|
6
|
-
const { Agent } = require('./agent')
|
|
7
|
-
const { Plugin } = require('./plugin-base')
|
|
8
|
-
const { PluginManager } = require('./plugin-manager')
|
|
9
|
-
const { ToolRegistry } = require('./tool-registry')
|
|
10
|
-
const { EventEmitter } = require('../utils/event-emitter')
|
|
5
|
+
const { Framework } = require('./framework');
|
|
6
|
+
const { Agent } = require('./agent');
|
|
7
|
+
const { Plugin } = require('./plugin-base');
|
|
8
|
+
const { PluginManager } = require('./plugin-manager');
|
|
9
|
+
const { ToolRegistry } = require('./tool-registry');
|
|
10
|
+
const { EventEmitter } = require('../utils/event-emitter');
|
|
11
11
|
|
|
12
12
|
module.exports = {
|
|
13
13
|
Framework,
|
|
@@ -15,5 +15,5 @@ module.exports = {
|
|
|
15
15
|
Plugin,
|
|
16
16
|
PluginManager,
|
|
17
17
|
ToolRegistry,
|
|
18
|
-
EventEmitter
|
|
19
|
-
}
|
|
18
|
+
EventEmitter,
|
|
19
|
+
};
|