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
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
const fs = require('fs')
|
|
7
7
|
const path = require('path')
|
|
8
8
|
const { Plugin } = require('../src/core/plugin-base')
|
|
9
|
+
const { logger } = require('../src/utils/logger')
|
|
10
|
+
const log = logger.child('SubAgent')
|
|
9
11
|
const { z } = require('zod')
|
|
10
12
|
const { Agent } = require('../src/core/agent')
|
|
11
13
|
|
|
@@ -19,17 +21,15 @@ class SubAgentPlugin extends Plugin {
|
|
|
19
21
|
|
|
20
22
|
this.system = true
|
|
21
23
|
|
|
24
|
+
this.role= config.role || config.name
|
|
25
|
+
this.tools = config.tools || {}
|
|
26
|
+
this.parentTools = config.parentTools || []
|
|
27
|
+
this.llmConfig = config.llmConfig || null
|
|
28
|
+
|
|
22
29
|
// 子Agent配置
|
|
23
30
|
// tools: { toolName: toolFn } 自定义工具(只属于此子Agent)
|
|
24
31
|
// parentTools: ['read_file'] 从父Agent继承的工具名称列表
|
|
25
|
-
this.config = {
|
|
26
|
-
name: config.name, // 子Agent名称
|
|
27
|
-
role: config.role || config.name, // 角色描述
|
|
28
|
-
description: config.description || '', // 供主Agent智能选择
|
|
29
|
-
tools: config.tools || {}, // 自定义工具 { name: toolDef }
|
|
30
|
-
parentTools: config.parentTools || [], // 从父Agent继承的工具名称列表
|
|
31
|
-
llmConfig: config.llmConfig || null // 独立LLM配置
|
|
32
|
-
}
|
|
32
|
+
this.config = {}
|
|
33
33
|
|
|
34
34
|
this._framework = null
|
|
35
35
|
this._agent = null
|
|
@@ -60,10 +60,11 @@ class SubAgentPlugin extends Plugin {
|
|
|
60
60
|
if (!parentAgent) {
|
|
61
61
|
// 父agent还没创建,监听事件等其创建
|
|
62
62
|
if (this._framework) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
this._framework.on('agent:created', (agent) => {
|
|
64
|
+
if (this._framework._mainAgent && agent === this._framework._mainAgent) {
|
|
65
|
+
// 父agent已创建,更新父agent引用
|
|
66
|
+
this._parentAgent = agent
|
|
67
|
+
// 重新尝试创建子agent
|
|
67
68
|
this._doCreateSubAgent(agent)
|
|
68
69
|
// 注册委托工具
|
|
69
70
|
this._registerDelegateTool()
|
|
@@ -90,58 +91,39 @@ class SubAgentPlugin extends Plugin {
|
|
|
90
91
|
|
|
91
92
|
// 确定LLM配置
|
|
92
93
|
const aiPlugin = this._framework.pluginManager.get('ai')
|
|
93
|
-
const llmConfig = this.
|
|
94
|
+
const llmConfig = this.llmConfig || (aiPlugin ? aiPlugin.getConfig() : {})
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
|
|
97
|
+
// 创建子Agent,使用完整的 md 文件内容作为系统提示词
|
|
98
|
+
this._agent = this._framework.createSubAgent({
|
|
99
|
+
name: this.name,
|
|
100
|
+
systemPrompt: this._getFullSystemPrompt(),
|
|
99
101
|
model: llmConfig.model,
|
|
100
102
|
provider: llmConfig.provider,
|
|
101
103
|
apiKey: llmConfig.apiKey,
|
|
102
|
-
baseURL: llmConfig.baseURL
|
|
104
|
+
baseURL: llmConfig.baseURL,
|
|
105
|
+
tools: this.tools||{}, // 自定义工具
|
|
106
|
+
parentTools: parentTools
|
|
103
107
|
})
|
|
104
108
|
|
|
105
109
|
// 注册从父Agent继承的工具
|
|
106
|
-
for (const tool of parentTools) {
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// 注册自定义工具(只属于此子Agent,不污染全局)
|
|
111
|
-
// tools 格式: { toolName: toolDef }
|
|
112
|
-
if (this.config.tools && typeof this.config.tools === 'object') {
|
|
113
|
-
for (const [toolName, toolDef] of Object.entries(this.config.tools)) {
|
|
114
|
-
const tool = typeof toolDef === 'function' ? toolDef() : toolDef
|
|
115
|
-
if (typeof tool === 'object' && tool.name) {
|
|
116
|
-
this._framework.registerTool(tool)
|
|
117
|
-
} else {
|
|
118
|
-
// 假设是简化的工具定义,需要补充 name
|
|
119
|
-
this._framework.registerTool({ name: toolName, ...tool })
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
110
|
+
// for (const tool of parentTools) {
|
|
111
|
+
// this._framework.registerTool(tool)
|
|
112
|
+
// }
|
|
123
113
|
|
|
124
|
-
//
|
|
114
|
+
// Register custom tools (only for this subAgent, won't pollute global)
|
|
115
|
+
// tools format: { toolName: toolDef }
|
|
116
|
+
|
|
125
117
|
this._parentAgent = parentAgent
|
|
126
118
|
|
|
127
119
|
// 注册子Agent到父Agent
|
|
128
|
-
parentAgent.registerSubAgent(this.
|
|
120
|
+
parentAgent.registerSubAgent(this.name, this._agent, this.role, this.description)
|
|
129
121
|
|
|
130
122
|
// 监听子Agent的chunk事件并转发给父Agent
|
|
131
123
|
this._agent.on('chunk', (chunk) => {
|
|
132
|
-
chunk.fromSubAgent = this.
|
|
124
|
+
chunk.fromSubAgent = this.name
|
|
133
125
|
parentAgent.emit('chunk', chunk)
|
|
134
126
|
})
|
|
135
|
-
|
|
136
|
-
const parentToolNames = parentTools.map(t => t.name)
|
|
137
|
-
const customToolNames = Object.keys(this.config.tools || {})
|
|
138
|
-
//console.log(`[SubAgent:${this.config.name}] Created with ${parentToolNames.length} parent tools + ${customToolNames.length} custom tools`)
|
|
139
|
-
// if (parentToolNames.length > 0) {
|
|
140
|
-
// console.log(` Parent tools: ${parentToolNames.join(', ')}`)
|
|
141
|
-
// }
|
|
142
|
-
// if (customToolNames.length > 0) {
|
|
143
|
-
// console.log(` Custom tools: ${customToolNames.join(', ')}`)
|
|
144
|
-
// }
|
|
145
127
|
}
|
|
146
128
|
|
|
147
129
|
/**
|
|
@@ -154,7 +136,6 @@ class SubAgentPlugin extends Plugin {
|
|
|
154
136
|
}
|
|
155
137
|
|
|
156
138
|
// 尝试从framework获取主agent
|
|
157
|
-
// 在foliko中,主agent通常是通过framework.createAgent创建的
|
|
158
139
|
if (this._framework._mainAgent) {
|
|
159
140
|
return this._framework._mainAgent
|
|
160
141
|
}
|
|
@@ -176,12 +157,12 @@ class SubAgentPlugin extends Plugin {
|
|
|
176
157
|
const toolMap = new Map(allTools.map(t => [t.name, t]))
|
|
177
158
|
|
|
178
159
|
// 如果没有指定 parentTools,返回全部
|
|
179
|
-
if (!this.
|
|
160
|
+
if (!this.parentTools || this.parentTools.length === 0) {
|
|
180
161
|
return allTools
|
|
181
162
|
}
|
|
182
163
|
// 过滤指定工具
|
|
183
164
|
const filtered = []
|
|
184
|
-
for (const toolName of this.
|
|
165
|
+
for (const toolName of this.parentTools) {
|
|
185
166
|
const tool = toolMap.get(toolName)
|
|
186
167
|
if (tool) {
|
|
187
168
|
filtered.push(tool)
|
|
@@ -198,9 +179,9 @@ class SubAgentPlugin extends Plugin {
|
|
|
198
179
|
* 构建系统提示
|
|
199
180
|
*/
|
|
200
181
|
_buildSystemPrompt() {
|
|
201
|
-
return `你是 ${this.
|
|
182
|
+
return `你是 ${this.role}。
|
|
202
183
|
|
|
203
|
-
角色描述:${this.
|
|
184
|
+
角色描述:${this.description || '一个专业的子Agent'}
|
|
204
185
|
|
|
205
186
|
当你被调用时,你应该:
|
|
206
187
|
1. 仔细理解任务要求
|
|
@@ -217,8 +198,8 @@ class SubAgentPlugin extends Plugin {
|
|
|
217
198
|
const framework = this._framework
|
|
218
199
|
if (!framework) return
|
|
219
200
|
|
|
220
|
-
const agentName = this.
|
|
221
|
-
const role = this.
|
|
201
|
+
const agentName = this.name
|
|
202
|
+
const role = this.role
|
|
222
203
|
|
|
223
204
|
const toolDef = {
|
|
224
205
|
name: agentName,
|
|
@@ -245,7 +226,7 @@ class SubAgentPlugin extends Plugin {
|
|
|
245
226
|
})
|
|
246
227
|
|
|
247
228
|
try {
|
|
248
|
-
const result = await this._agent.
|
|
229
|
+
const result = await this._agent.chat(args.task)
|
|
249
230
|
// 发射子Agent完成处理事件
|
|
250
231
|
parentAgent.emit('subagent:chat:end', {
|
|
251
232
|
parentAgent,
|
|
@@ -276,12 +257,12 @@ class SubAgentPlugin extends Plugin {
|
|
|
276
257
|
}
|
|
277
258
|
|
|
278
259
|
// 注册到框架(供后续创建的 Agent 同步)
|
|
279
|
-
framework.registerTool(toolDef)
|
|
260
|
+
// framework.registerTool(toolDef)
|
|
280
261
|
|
|
281
|
-
// 如果主 Agent 已存在,直接注册到它
|
|
282
|
-
if (framework._mainAgent) {
|
|
283
|
-
|
|
284
|
-
}
|
|
262
|
+
// // 如果主 Agent 已存在,直接注册到它
|
|
263
|
+
// if (framework._mainAgent) {
|
|
264
|
+
// framework._mainAgent.registerTool(toolDef)
|
|
265
|
+
// }
|
|
285
266
|
|
|
286
267
|
//console.log(`[SubAgent:${this.config.name}] Delegate tool registered`)
|
|
287
268
|
}
|
|
@@ -295,12 +276,77 @@ class SubAgentPlugin extends Plugin {
|
|
|
295
276
|
|
|
296
277
|
/**
|
|
297
278
|
* 调用子Agent处理任务
|
|
279
|
+
* 延迟创建 Agent,使用完整的 md 文件内容作为系统提示词
|
|
298
280
|
*/
|
|
299
281
|
async chat(task) {
|
|
282
|
+
// 延迟创建 Agent(如果尚未创建)
|
|
300
283
|
if (!this._agent) {
|
|
301
|
-
|
|
284
|
+
await this._createSubAgentForChat();
|
|
285
|
+
} else {
|
|
286
|
+
// 每次调用时更新系统提示词,确保使用最新的 md 文件内容
|
|
287
|
+
this._updateAgentSystemPrompt();
|
|
288
|
+
}
|
|
289
|
+
return this._agent.chat(task)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* 创建用于聊天的高完整度 Agent
|
|
294
|
+
* 使用 SubAgentConfig 读取完整的 md 文件内容
|
|
295
|
+
*/
|
|
296
|
+
async _createSubAgentForChat() {
|
|
297
|
+
const parentAgent = this._getParentAgent();
|
|
298
|
+
if (!parentAgent) {
|
|
299
|
+
throw new Error(`SubAgent ${this.name}: parent agent not found`);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 使用 SubAgentConfig 获取完整的系统提示词
|
|
303
|
+
const systemPrompt = this._getFullSystemPrompt();
|
|
304
|
+
const parentTools = this._getParentTools(parentAgent)
|
|
305
|
+
// 获取 LLM 配置
|
|
306
|
+
const aiPlugin = this._framework.pluginManager.get('ai');
|
|
307
|
+
const llmConfig = this.llmConfig || (aiPlugin ? aiPlugin.getConfig() : {});
|
|
308
|
+
|
|
309
|
+
// 创建 Agent,使用完整的 md 内容作为系统提示词
|
|
310
|
+
this._agent = this._framework.createSubAgent({
|
|
311
|
+
name: this.name,
|
|
312
|
+
systemPrompt: systemPrompt,
|
|
313
|
+
model: llmConfig.model,
|
|
314
|
+
provider: llmConfig.provider,
|
|
315
|
+
apiKey: llmConfig.apiKey,
|
|
316
|
+
baseURL: llmConfig.baseURL,
|
|
317
|
+
tools: this.tools||{}, // 自定义工具
|
|
318
|
+
parentTools: parentTools
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// 注册到父 Agent
|
|
322
|
+
this._parentAgent = parentAgent;
|
|
323
|
+
parentAgent.registerSubAgent(this.name, this._agent, this.role, this.description);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* 获取完整的系统提示词(从 md 文件读取)
|
|
328
|
+
*/
|
|
329
|
+
_getFullSystemPrompt() {
|
|
330
|
+
// 尝试从 SubAgentConfigManager 获取完整内容
|
|
331
|
+
const configManager = this._framework._subAgentConfigManager;
|
|
332
|
+
if (configManager) {
|
|
333
|
+
const config = configManager.get(this.name);
|
|
334
|
+
if (config) {
|
|
335
|
+
return config.getSystemPrompt();
|
|
336
|
+
}
|
|
302
337
|
}
|
|
303
|
-
|
|
338
|
+
|
|
339
|
+
// 回退到默认的 _buildSystemPrompt
|
|
340
|
+
return this._buildSystemPrompt();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 更新 Agent 的系统提示词
|
|
345
|
+
*/
|
|
346
|
+
_updateAgentSystemPrompt() {
|
|
347
|
+
if (!this._agent) return;
|
|
348
|
+
const systemPrompt = this._getFullSystemPrompt();
|
|
349
|
+
this._agent.setSystemPrompt(systemPrompt);
|
|
304
350
|
}
|
|
305
351
|
|
|
306
352
|
reload(framework) {
|
|
@@ -310,7 +356,7 @@ class SubAgentPlugin extends Plugin {
|
|
|
310
356
|
|
|
311
357
|
uninstall(framework) {
|
|
312
358
|
if (this._parentAgent) {
|
|
313
|
-
this._parentAgent.unregisterSubAgent(this.
|
|
359
|
+
this._parentAgent.unregisterSubAgent(this.name)
|
|
314
360
|
}
|
|
315
361
|
if (this._agent) {
|
|
316
362
|
this._agent.destroy()
|
|
@@ -330,11 +376,13 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
330
376
|
this.name = 'subagent-manager'
|
|
331
377
|
this.version = '1.0.0'
|
|
332
378
|
this.description = '子Agent管理器,统一管理多个子Agent'
|
|
333
|
-
this.priority = 10
|
|
334
379
|
|
|
380
|
+
this.systemPrompt= `你是一个子Agent管理器,负责管理多个子Agent。每个子Agent都有独立的工具集和角色描述。当需要处理特定任务时,你会选择合适的子Agent来执行。`
|
|
381
|
+
|
|
382
|
+
this.priority = 10
|
|
383
|
+
this.agents = config.agents || [] // 预定义的子Agent配置列表
|
|
335
384
|
this.config = {
|
|
336
385
|
agentsDir: config.agentsDir || null, // 子Agent配置目录
|
|
337
|
-
agents: config.agents || [] // 子Agent配置列表
|
|
338
386
|
}
|
|
339
387
|
|
|
340
388
|
this._framework = null
|
|
@@ -353,7 +401,7 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
353
401
|
this._loadAgentsFromDir()
|
|
354
402
|
|
|
355
403
|
// 创建所有配置的子Agent
|
|
356
|
-
for (const agentConfig of this.
|
|
404
|
+
for (const agentConfig of this.agents) {
|
|
357
405
|
const plugin = new SubAgentPlugin(agentConfig)
|
|
358
406
|
plugin.install(framework)
|
|
359
407
|
plugin.start(framework)
|
|
@@ -391,9 +439,9 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
391
439
|
inputSchema: z.object({}),
|
|
392
440
|
execute: async () => {
|
|
393
441
|
const agents = Array.from(this._subAgents.values()).map(p => ({
|
|
394
|
-
name: p.
|
|
395
|
-
role: p.
|
|
396
|
-
description: p.
|
|
442
|
+
name: p.name,
|
|
443
|
+
role: p.role,
|
|
444
|
+
description: p.description,
|
|
397
445
|
toolCount: p._agent ? p._agent.getTools().length : 0
|
|
398
446
|
}))
|
|
399
447
|
return { success: true, agents }
|
|
@@ -414,7 +462,7 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
414
462
|
}
|
|
415
463
|
|
|
416
464
|
try {
|
|
417
|
-
const result = await plugin.
|
|
465
|
+
const result = await plugin.chat(args.task)
|
|
418
466
|
return {
|
|
419
467
|
success: true,
|
|
420
468
|
agent: args.agentName,
|
|
@@ -441,7 +489,7 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
441
489
|
}
|
|
442
490
|
})
|
|
443
491
|
|
|
444
|
-
//
|
|
492
|
+
//log.info(' Management tools registered to agent')
|
|
445
493
|
}
|
|
446
494
|
|
|
447
495
|
/**
|
|
@@ -454,9 +502,9 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
454
502
|
inputSchema: z.object({}),
|
|
455
503
|
execute: async () => {
|
|
456
504
|
const agents = Array.from(this._subAgents.values()).map(p => ({
|
|
457
|
-
name: p.
|
|
458
|
-
role: p.
|
|
459
|
-
description: p.
|
|
505
|
+
name: p.name,
|
|
506
|
+
role: p.role,
|
|
507
|
+
description: p.description,
|
|
460
508
|
toolCount: p._agent ? p._agent.getTools().length : 0
|
|
461
509
|
}))
|
|
462
510
|
return { success: true, agents }
|
|
@@ -477,7 +525,7 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
477
525
|
}
|
|
478
526
|
|
|
479
527
|
try {
|
|
480
|
-
const result = await plugin.
|
|
528
|
+
const result = await plugin.chat(args.task)
|
|
481
529
|
return {
|
|
482
530
|
success: true,
|
|
483
531
|
agent: args.agentName,
|
|
@@ -504,7 +552,7 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
504
552
|
}
|
|
505
553
|
})
|
|
506
554
|
|
|
507
|
-
//
|
|
555
|
+
//log.info(' Management tools registered to framework')
|
|
508
556
|
}
|
|
509
557
|
|
|
510
558
|
/**
|
|
@@ -512,14 +560,14 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
512
560
|
*/
|
|
513
561
|
_loadAgentsFromDir() {
|
|
514
562
|
const agentsDir = this.config.agentsDir
|
|
515
|
-
//
|
|
563
|
+
//log.info(' _loadAgentsFromDir called, agentsDir:', agentsDir)
|
|
516
564
|
if (!agentsDir || !fs.existsSync(agentsDir)) {
|
|
517
|
-
|
|
565
|
+
log.info(' agentsDir not found or does not exist')
|
|
518
566
|
return
|
|
519
567
|
}
|
|
520
568
|
|
|
521
569
|
const entries = fs.readdirSync(agentsDir, { withFileTypes: true })
|
|
522
|
-
//
|
|
570
|
+
//log.info(' Found entries:', entries.length)
|
|
523
571
|
|
|
524
572
|
for (const entry of entries) {
|
|
525
573
|
if (entry.isFile() && (entry.name.endsWith('.js') || entry.name.endsWith('.json') || entry.name.endsWith('.md'))) {
|
|
@@ -527,7 +575,7 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
527
575
|
const filePath = path.join(agentsDir, entry.name)
|
|
528
576
|
|
|
529
577
|
// 跳过与已有配置同名的
|
|
530
|
-
if (this.
|
|
578
|
+
if (this.agents.some(a => a.name === baseName)) {
|
|
531
579
|
continue
|
|
532
580
|
}
|
|
533
581
|
|
|
@@ -539,7 +587,7 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
539
587
|
} else if (entry.name.endsWith('.md')) {
|
|
540
588
|
// 解析 markdown 文件,提取 JSON 配置
|
|
541
589
|
agentConfig = this._parseMarkdownConfig(filePath, baseName)
|
|
542
|
-
//
|
|
590
|
+
//log.info(' Parsed md:', baseName, agentConfig)
|
|
543
591
|
} else {
|
|
544
592
|
// 清除缓存并加载
|
|
545
593
|
delete require.cache[require.resolve(filePath)]
|
|
@@ -549,13 +597,13 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
549
597
|
|
|
550
598
|
if (agentConfig && agentConfig.name) {
|
|
551
599
|
agentConfig._fromDir = true
|
|
552
|
-
this.
|
|
553
|
-
//
|
|
600
|
+
this.agents.push(agentConfig)
|
|
601
|
+
//log.info(' Loaded agent:', agentConfig.name)
|
|
554
602
|
} else {
|
|
555
|
-
|
|
603
|
+
log.warn(' Agent config has no name:', baseName, agentConfig)
|
|
556
604
|
}
|
|
557
605
|
} catch (err) {
|
|
558
|
-
|
|
606
|
+
log.warn(` Failed to load agent config from ${filePath}:`, err.message, err.stack)
|
|
559
607
|
}
|
|
560
608
|
}
|
|
561
609
|
}
|
|
@@ -571,14 +619,14 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
571
619
|
*/
|
|
572
620
|
_parseMarkdownConfig(filePath, defaultName) {
|
|
573
621
|
const content = fs.readFileSync(filePath, 'utf-8')
|
|
574
|
-
//
|
|
622
|
+
//log.info(' _parseMarkdownConfig:', filePath)
|
|
575
623
|
|
|
576
624
|
// 尝试从 code block 中提取 JSON
|
|
577
625
|
const jsonMatch = content.match(/```(?:json)?\s*\n([\s\S]*?)\n\s*```/)
|
|
578
626
|
if (jsonMatch) {
|
|
579
627
|
try {
|
|
580
628
|
const config = JSON.parse(jsonMatch[1].trim())
|
|
581
|
-
//
|
|
629
|
+
//log.info(' Found JSON in code block')
|
|
582
630
|
return config
|
|
583
631
|
} catch (err) {
|
|
584
632
|
// JSON 解析失败,继续
|
|
@@ -588,11 +636,11 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
588
636
|
// 尝试从 frontmatter 格式中提取
|
|
589
637
|
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/)
|
|
590
638
|
if (frontmatterMatch) {
|
|
591
|
-
//
|
|
639
|
+
//log.info(' Found frontmatter')
|
|
592
640
|
const frontmatterContent = frontmatterMatch[1]
|
|
593
641
|
const parsed = this._parseYamlLike(frontmatterContent)
|
|
594
642
|
if (parsed && parsed.name) {
|
|
595
|
-
//
|
|
643
|
+
//log.info(' Parsed frontmatter:', parsed)
|
|
596
644
|
return { name: parsed.name || defaultName, ...parsed }
|
|
597
645
|
}
|
|
598
646
|
}
|
|
@@ -608,6 +656,13 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
608
656
|
return config
|
|
609
657
|
}
|
|
610
658
|
|
|
659
|
+
/**
|
|
660
|
+
* 获取所有 subAgent 的基本信息列表
|
|
661
|
+
*/
|
|
662
|
+
getAllSubAgents() {
|
|
663
|
+
return Array.from(this._subAgents.values());
|
|
664
|
+
}
|
|
665
|
+
|
|
611
666
|
/**
|
|
612
667
|
* 解析类似 YAML 的配置
|
|
613
668
|
*/
|
|
@@ -731,7 +786,7 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
731
786
|
}
|
|
732
787
|
|
|
733
788
|
if (hasChanges) {
|
|
734
|
-
//
|
|
789
|
+
//log.info(' File changes detected, reloading...')
|
|
735
790
|
this._updateFileStates()
|
|
736
791
|
this.reload(this._framework)
|
|
737
792
|
}
|
|
@@ -759,7 +814,12 @@ class SubAgentManagerPlugin extends Plugin {
|
|
|
759
814
|
this._subAgents.clear()
|
|
760
815
|
|
|
761
816
|
// 清空从目录加载的配置,重新加载
|
|
762
|
-
this.
|
|
817
|
+
this.agents = this.agents.filter(a => !a._fromDir)
|
|
818
|
+
|
|
819
|
+
// 刷新 SubAgentConfigManager(如果存在)
|
|
820
|
+
if (framework._subAgentConfigManager) {
|
|
821
|
+
framework._subAgentConfigManager.refresh()
|
|
822
|
+
}
|
|
763
823
|
|
|
764
824
|
// 重新创建
|
|
765
825
|
this.start(framework)
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
const { Plugin } = require('../src/core/plugin-base')
|
|
13
|
+
const { logger } = require('../src/utils/logger')
|
|
14
|
+
const log = logger.child('Telegram')
|
|
13
15
|
const { z } = require('zod')
|
|
14
16
|
|
|
15
17
|
// 转义 MarkdownV2 特殊字符
|
|
@@ -27,6 +29,11 @@ class TelegramPlugin extends Plugin {
|
|
|
27
29
|
this.priority = 80
|
|
28
30
|
this.enabled = false
|
|
29
31
|
this.systemPrompt = `你是一个有帮助的AI助手。回复内容不要使用markdown格式文本。
|
|
32
|
+
|
|
33
|
+
**重要:** 子Agent 匹配规则必须遵守:
|
|
34
|
+
- 根据【子 Agent 匹配表】,将任务委托给最匹配的子Agent处理
|
|
35
|
+
- 使用 subagent_call 工具并指定 agentName 来委托任务
|
|
36
|
+
- 只有当没有匹配的子Agent时,才直接调用工具
|
|
30
37
|
|
|
31
38
|
**命令执行规范:**
|
|
32
39
|
- 执行 npx skills add / npx skills remove / npx skills list 命令时,必须自动添加参数:-a openclaw -y
|
|
@@ -54,7 +61,7 @@ class TelegramPlugin extends Plugin {
|
|
|
54
61
|
|
|
55
62
|
start(framework) {
|
|
56
63
|
if (!this.config.botToken) {
|
|
57
|
-
|
|
64
|
+
log.warn(' No bot token. Set TELEGRAM_BOT_TOKEN env var.')
|
|
58
65
|
return this
|
|
59
66
|
}
|
|
60
67
|
|
|
@@ -64,7 +71,7 @@ class TelegramPlugin extends Plugin {
|
|
|
64
71
|
if (this._sessionPlugin) {
|
|
65
72
|
this._sessionDeleteHandler = (sessionId) => {
|
|
66
73
|
if (sessionId.startsWith('telegram_')) {
|
|
67
|
-
|
|
74
|
+
log.info(` Session deleted: ${sessionId}`)
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
77
|
this._sessionPlugin.on('session:deleted', this._sessionDeleteHandler)
|
|
@@ -79,25 +86,25 @@ class TelegramPlugin extends Plugin {
|
|
|
79
86
|
const TelegramBot = require('node-telegram-bot-api')
|
|
80
87
|
this._bot = new TelegramBot(this.config.botToken, { polling: true })
|
|
81
88
|
|
|
82
|
-
|
|
89
|
+
log.info(' Bot started successfully')
|
|
83
90
|
|
|
84
91
|
this._bot.setMyCommands([
|
|
85
92
|
{ command: 'start', description: '显示帮助信息' },
|
|
86
93
|
{ command: 'clear', description: '清除对话历史' },
|
|
87
94
|
{ command: 'history', description: '查看对话状态' }
|
|
88
95
|
]).catch((err) => {
|
|
89
|
-
|
|
96
|
+
log.error(' Failed to register commands:', err.message)
|
|
90
97
|
})
|
|
91
98
|
|
|
92
99
|
this._bot.on('message', (msg) => this._handleMessage(msg))
|
|
93
100
|
this._bot.on('edit_message', (msg) => this._handleEdit(msg))
|
|
94
101
|
this._bot.on('callback_query', (query) => this._handleCallback(query))
|
|
95
|
-
this._bot.on('polling_error', (err) =>
|
|
96
|
-
this._bot.on('error', (err) =>
|
|
102
|
+
this._bot.on('polling_error', (err) => log.error(' Polling error:', err.message))
|
|
103
|
+
this._bot.on('error', (err) => log.error(' Bot error:', err.message))
|
|
97
104
|
|
|
98
105
|
if (this._framework) {
|
|
99
106
|
this._framework.on('agent:created', (agent) => {
|
|
100
|
-
|
|
107
|
+
log.info(' New agent created:', agent.name)
|
|
101
108
|
})
|
|
102
109
|
|
|
103
110
|
// 监听统一通知事件
|
|
@@ -111,7 +118,7 @@ class TelegramPlugin extends Plugin {
|
|
|
111
118
|
})
|
|
112
119
|
}
|
|
113
120
|
} catch (err) {
|
|
114
|
-
|
|
121
|
+
log.error(' Failed to initialize bot:', err.message)
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
|
|
@@ -122,7 +129,7 @@ class TelegramPlugin extends Plugin {
|
|
|
122
129
|
const { title, message, source, level } = data
|
|
123
130
|
|
|
124
131
|
if (!this._bot) {
|
|
125
|
-
|
|
132
|
+
log.warn(' Bot not ready, cannot send notification')
|
|
126
133
|
return
|
|
127
134
|
}
|
|
128
135
|
|
|
@@ -151,7 +158,7 @@ class TelegramPlugin extends Plugin {
|
|
|
151
158
|
}
|
|
152
159
|
|
|
153
160
|
if (!chatId) {
|
|
154
|
-
|
|
161
|
+
log.warn(' No telegram session found for notification')
|
|
155
162
|
return
|
|
156
163
|
}
|
|
157
164
|
|
|
@@ -167,9 +174,9 @@ class TelegramPlugin extends Plugin {
|
|
|
167
174
|
|
|
168
175
|
try {
|
|
169
176
|
await this._bot.sendMessage(chatId, notificationText)
|
|
170
|
-
|
|
177
|
+
log.info(` Notification sent to chat ${chatId}`)
|
|
171
178
|
} catch (err) {
|
|
172
|
-
|
|
179
|
+
log.error(` Failed to send notification:`, err.message)
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
182
|
|
|
@@ -188,9 +195,9 @@ class TelegramPlugin extends Plugin {
|
|
|
188
195
|
|
|
189
196
|
try {
|
|
190
197
|
await this._bot.sendMessage(chatId, notificationText)
|
|
191
|
-
|
|
198
|
+
log.info(` Webhook notification sent to chat ${chatId}`)
|
|
192
199
|
} catch (err) {
|
|
193
|
-
|
|
200
|
+
log.error(` Failed to send webhook notification:`, err.message)
|
|
194
201
|
}
|
|
195
202
|
}
|
|
196
203
|
|
|
@@ -299,7 +306,7 @@ class TelegramPlugin extends Plugin {
|
|
|
299
306
|
reply_to_message_id: replyToMessageId
|
|
300
307
|
})
|
|
301
308
|
} catch (err) {
|
|
302
|
-
|
|
309
|
+
log.error(' Send thinking error:', err.message)
|
|
303
310
|
return
|
|
304
311
|
}
|
|
305
312
|
|
|
@@ -330,7 +337,7 @@ class TelegramPlugin extends Plugin {
|
|
|
330
337
|
parse_mode: 'MarkdownV2'
|
|
331
338
|
})
|
|
332
339
|
} catch (err) {
|
|
333
|
-
|
|
340
|
+
log.error(' Chat error:', err)
|
|
334
341
|
await this._bot.editMessageText(escapeMarkdown(`❌ 发生错误:${err.message}`), {
|
|
335
342
|
chat_id: chatId,
|
|
336
343
|
message_id: thinkingMsg.message_id
|
|
@@ -365,7 +372,7 @@ class TelegramPlugin extends Plugin {
|
|
|
365
372
|
await this._processChat(chatId, `图片:${filePath}, ${caption}`, msg.message_id)
|
|
366
373
|
}
|
|
367
374
|
} catch (err) {
|
|
368
|
-
|
|
375
|
+
log.error(' Failed to save photo:', err.message)
|
|
369
376
|
await this._sendMessage(chatId, '图片保存失败: ' + err.message, msg.message_id)
|
|
370
377
|
}
|
|
371
378
|
}
|
|
@@ -388,7 +395,7 @@ class TelegramPlugin extends Plugin {
|
|
|
388
395
|
await this._processChat(chatId, `文件:${filePath}, ${caption}`, msg.message_id)
|
|
389
396
|
}
|
|
390
397
|
} catch (err) {
|
|
391
|
-
|
|
398
|
+
log.error(' Failed to save document:', err.message)
|
|
392
399
|
await this._sendMessage(chatId, '文件保存失败: ' + err.message, msg.message_id)
|
|
393
400
|
}
|
|
394
401
|
}
|
|
@@ -445,7 +452,7 @@ class TelegramPlugin extends Plugin {
|
|
|
445
452
|
if (this._bot) {
|
|
446
453
|
this._bot.stopPolling()
|
|
447
454
|
this._bot = null
|
|
448
|
-
|
|
455
|
+
log.info(' Bot stopped')
|
|
449
456
|
}
|
|
450
457
|
}
|
|
451
458
|
|
package/plugins/think-plugin.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { Plugin } = require('../src/core/plugin-base')
|
|
7
|
+
const { logger } = require('../src/utils/logger')
|
|
8
|
+
const log = logger.child('Think')
|
|
7
9
|
const { z } = require('zod')
|
|
8
10
|
|
|
9
11
|
class ThinkPlugin extends Plugin {
|
|
@@ -239,7 +241,7 @@ ${topic || '接下来的行动'}
|
|
|
239
241
|
})
|
|
240
242
|
}
|
|
241
243
|
} catch (err) {
|
|
242
|
-
|
|
244
|
+
log.error(' Auto-reflect error:', err.message)
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
247
|
|
|
@@ -272,7 +274,7 @@ ${topic || '接下来的行动'}
|
|
|
272
274
|
this._continuousTimer = setTimeout(runThink, interval)
|
|
273
275
|
}
|
|
274
276
|
} catch (err) {
|
|
275
|
-
|
|
277
|
+
log.error(' Continuous think error:', err.message)
|
|
276
278
|
}
|
|
277
279
|
}
|
|
278
280
|
|