foliko 1.0.75 → 1.0.76
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 +159 -157
- package/cli/bin/foliko.js +12 -12
- package/cli/src/commands/chat.js +143 -143
- package/cli/src/commands/list.js +93 -93
- package/cli/src/index.js +75 -75
- package/cli/src/ui/chat-ui.js +201 -201
- package/cli/src/utils/ansi.js +40 -40
- package/cli/src/utils/markdown.js +292 -292
- package/examples/ambient-example.js +194 -194
- package/examples/basic.js +115 -115
- package/examples/bootstrap.js +121 -121
- package/examples/mcp-example.js +56 -56
- package/examples/skill-example.js +49 -49
- package/examples/test-chat.js +137 -137
- package/examples/test-mcp.js +85 -85
- package/examples/test-reload.js +59 -59
- package/examples/test-telegram.js +50 -50
- package/examples/test-tg-bot.js +45 -45
- package/examples/test-tg-simple.js +47 -47
- package/examples/test-tg.js +62 -62
- package/examples/test-think.js +43 -43
- package/examples/test-web-plugin.js +103 -103
- package/examples/test-weixin-feishu.js +103 -103
- package/examples/workflow.js +158 -158
- package/package.json +1 -1
- package/plugins/ai-plugin.js +102 -102
- package/plugins/ambient-agent/EventWatcher.js +113 -113
- package/plugins/ambient-agent/ExplorerLoop.js +640 -640
- package/plugins/ambient-agent/GoalManager.js +197 -197
- package/plugins/ambient-agent/Reflector.js +95 -95
- package/plugins/ambient-agent/StateStore.js +90 -90
- package/plugins/ambient-agent/constants.js +101 -101
- package/plugins/ambient-agent/index.js +579 -579
- package/plugins/audit-plugin.js +187 -187
- package/plugins/default-plugins.js +662 -662
- package/plugins/email/constants.js +64 -64
- package/plugins/email/handlers.js +461 -461
- package/plugins/email/index.js +278 -278
- package/plugins/email/monitor.js +269 -269
- package/plugins/email/parser.js +138 -138
- package/plugins/email/reply.js +151 -151
- package/plugins/email/utils.js +124 -124
- package/plugins/feishu-plugin.js +481 -481
- package/plugins/file-system-plugin.js +826 -826
- package/plugins/install-plugin.js +199 -199
- package/plugins/python-executor-plugin.js +367 -367
- package/plugins/python-plugin-loader.js +481 -481
- package/plugins/rules-plugin.js +294 -294
- package/plugins/scheduler-plugin.js +691 -691
- package/plugins/session-plugin.js +369 -369
- package/plugins/shell-executor-plugin.js +197 -197
- package/plugins/storage-plugin.js +240 -240
- package/plugins/subagent-plugin.js +845 -845
- package/plugins/telegram-plugin.js +482 -482
- package/plugins/think-plugin.js +345 -345
- package/plugins/tools-plugin.js +196 -196
- package/plugins/web-plugin.js +606 -606
- package/plugins/weixin-plugin.js +545 -545
- package/src/capabilities/index.js +11 -11
- package/src/capabilities/skill-manager.js +609 -609
- package/src/capabilities/workflow-engine.js +1109 -1109
- package/src/core/agent-chat.js +882 -882
- package/src/core/agent.js +892 -892
- package/src/core/framework.js +465 -465
- package/src/core/index.js +19 -19
- package/src/core/plugin-base.js +219 -219
- package/src/core/plugin-manager.js +863 -863
- package/src/core/provider.js +114 -114
- package/src/core/sub-agent-config.js +264 -264
- package/src/core/system-prompt-builder.js +120 -120
- package/src/core/tool-registry.js +517 -517
- package/src/core/tool-router.js +297 -297
- package/src/executors/executor-base.js +58 -58
- package/src/executors/mcp-executor.js +741 -741
- package/src/index.js +25 -25
- package/src/utils/circuit-breaker.js +301 -301
- package/src/utils/error-boundary.js +363 -363
- package/src/utils/error.js +374 -374
- package/src/utils/event-emitter.js +97 -97
- package/src/utils/id.js +133 -133
- package/src/utils/index.js +217 -217
- package/src/utils/logger.js +181 -181
- package/src/utils/plugin-helpers.js +90 -90
- package/src/utils/retry.js +122 -122
- package/src/utils/sandbox.js +292 -292
- package/test/tool-registry-validation.test.js +218 -218
- package/website/script.js +136 -136
- package/foliko-1.0.75.tgz +0 -0
package/plugins/ai-plugin.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI 插件
|
|
3
|
-
* 提供 AI 对话能力
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const { Plugin } = require('../src/core/plugin-base')
|
|
7
|
-
const { logger } = require('../src/utils/logger')
|
|
8
|
-
const log = logger.child('AIPlugin')
|
|
9
|
-
const { createAI } = require('../src/core/provider')
|
|
10
|
-
|
|
11
|
-
class AIPlugin extends Plugin {
|
|
12
|
-
constructor(config = {}) {
|
|
13
|
-
super()
|
|
14
|
-
this.name = 'ai'
|
|
15
|
-
this.version = '1.0.0'
|
|
16
|
-
this.description = 'AI 对话能力插件'
|
|
17
|
-
this.priority = 1 // 最先加载
|
|
18
|
-
this.system = true
|
|
19
|
-
|
|
20
|
-
this.config = {
|
|
21
|
-
provider: config.provider || 'deepseek',
|
|
22
|
-
model: config.model || 'deepseek-chat',
|
|
23
|
-
apiKey: config.apiKey,
|
|
24
|
-
baseURL: config.baseURL,
|
|
25
|
-
maxSteps: config.maxSteps || 20,
|
|
26
|
-
maxOutputTokens:config.maxOutputTokens||8192
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this._aiClient = null
|
|
30
|
-
this._framework = null
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
install(framework) {
|
|
34
|
-
this._framework = framework
|
|
35
|
-
this._initAIClient()
|
|
36
|
-
return this
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
start(framework) {
|
|
40
|
-
// AI client 已在 install 中初始化
|
|
41
|
-
return this
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
_initAIClient() {
|
|
45
|
-
|
|
46
|
-
if (!this.config.apiKey) {
|
|
47
|
-
log.warn(' No API key provided, AI features disabled')
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
const provider = createAI({
|
|
52
|
-
provider: this.config.provider,
|
|
53
|
-
model: this.config.model,
|
|
54
|
-
apiKey: this.config.apiKey,
|
|
55
|
-
baseURL: this.config.baseURL
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
// 创建模型实例
|
|
59
|
-
this._aiClient = provider(this.config.model)
|
|
60
|
-
log.info(` Initialized ${this.config.provider}/${this.config.model}`)
|
|
61
|
-
} catch (err) {
|
|
62
|
-
log.error(' Failed to initialize AI client:', err.message)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 获取 AI 客户端
|
|
68
|
-
* @returns {Object} AI 模型客户端
|
|
69
|
-
*/
|
|
70
|
-
getAIClient() {
|
|
71
|
-
return this._aiClient
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 获取配置
|
|
76
|
-
* @returns {Object}
|
|
77
|
-
*/
|
|
78
|
-
getConfig() {
|
|
79
|
-
return { ...this.config }
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
reload(framework) {
|
|
83
|
-
log.info(' Reloading...')
|
|
84
|
-
this._framework = framework
|
|
85
|
-
this._initAIClient()
|
|
86
|
-
|
|
87
|
-
// 刷新所有已有 Agent 的 AI client
|
|
88
|
-
for (const agent of framework._agents || []) {
|
|
89
|
-
if (agent._chatHandler) {
|
|
90
|
-
agent._chatHandler.setAIClient(this._aiClient)
|
|
91
|
-
log.info(` Refreshed AI client for agent: ${agent.name}`)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
uninstall(framework) {
|
|
97
|
-
this._aiClient = null
|
|
98
|
-
this._framework = null
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = { AIPlugin }
|
|
1
|
+
/**
|
|
2
|
+
* AI 插件
|
|
3
|
+
* 提供 AI 对话能力
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { Plugin } = require('../src/core/plugin-base')
|
|
7
|
+
const { logger } = require('../src/utils/logger')
|
|
8
|
+
const log = logger.child('AIPlugin')
|
|
9
|
+
const { createAI } = require('../src/core/provider')
|
|
10
|
+
|
|
11
|
+
class AIPlugin extends Plugin {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
super()
|
|
14
|
+
this.name = 'ai'
|
|
15
|
+
this.version = '1.0.0'
|
|
16
|
+
this.description = 'AI 对话能力插件'
|
|
17
|
+
this.priority = 1 // 最先加载
|
|
18
|
+
this.system = true
|
|
19
|
+
|
|
20
|
+
this.config = {
|
|
21
|
+
provider: config.provider || 'deepseek',
|
|
22
|
+
model: config.model || 'deepseek-chat',
|
|
23
|
+
apiKey: config.apiKey,
|
|
24
|
+
baseURL: config.baseURL,
|
|
25
|
+
maxSteps: config.maxSteps || 20,
|
|
26
|
+
maxOutputTokens:config.maxOutputTokens||8192
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this._aiClient = null
|
|
30
|
+
this._framework = null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
install(framework) {
|
|
34
|
+
this._framework = framework
|
|
35
|
+
this._initAIClient()
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
start(framework) {
|
|
40
|
+
// AI client 已在 install 中初始化
|
|
41
|
+
return this
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_initAIClient() {
|
|
45
|
+
|
|
46
|
+
if (!this.config.apiKey) {
|
|
47
|
+
log.warn(' No API key provided, AI features disabled')
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const provider = createAI({
|
|
52
|
+
provider: this.config.provider,
|
|
53
|
+
model: this.config.model,
|
|
54
|
+
apiKey: this.config.apiKey,
|
|
55
|
+
baseURL: this.config.baseURL
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// 创建模型实例
|
|
59
|
+
this._aiClient = provider(this.config.model)
|
|
60
|
+
log.info(` Initialized ${this.config.provider}/${this.config.model}`)
|
|
61
|
+
} catch (err) {
|
|
62
|
+
log.error(' Failed to initialize AI client:', err.message)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 获取 AI 客户端
|
|
68
|
+
* @returns {Object} AI 模型客户端
|
|
69
|
+
*/
|
|
70
|
+
getAIClient() {
|
|
71
|
+
return this._aiClient
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 获取配置
|
|
76
|
+
* @returns {Object}
|
|
77
|
+
*/
|
|
78
|
+
getConfig() {
|
|
79
|
+
return { ...this.config }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
reload(framework) {
|
|
83
|
+
log.info(' Reloading...')
|
|
84
|
+
this._framework = framework
|
|
85
|
+
this._initAIClient()
|
|
86
|
+
|
|
87
|
+
// 刷新所有已有 Agent 的 AI client
|
|
88
|
+
for (const agent of framework._agents || []) {
|
|
89
|
+
if (agent._chatHandler) {
|
|
90
|
+
agent._chatHandler.setAIClient(this._aiClient)
|
|
91
|
+
log.info(` Refreshed AI client for agent: ${agent.name}`)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
uninstall(framework) {
|
|
97
|
+
this._aiClient = null
|
|
98
|
+
this._framework = null
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = { AIPlugin }
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EventWatcher - 订阅框架事件,筛选相关事件
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const { logger } = require('../../src/utils/logger')
|
|
6
|
-
const { DefaultEvents } = require('./constants')
|
|
7
|
-
|
|
8
|
-
const log = logger.child('Ambient:EventWatcher')
|
|
9
|
-
|
|
10
|
-
class EventWatcher {
|
|
11
|
-
constructor(goalManager, framework) {
|
|
12
|
-
this._goalManager = goalManager
|
|
13
|
-
this._framework = framework
|
|
14
|
-
this._handlers = []
|
|
15
|
-
this._relevantEvents = new Set(DefaultEvents)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 启动事件监听
|
|
20
|
-
*/
|
|
21
|
-
start() {
|
|
22
|
-
const events = [
|
|
23
|
-
['tool:result', (data) => this._handleEvent('tool:result', data)],
|
|
24
|
-
['scheduler:reminder', (data) => this._handleEvent('scheduler:reminder', data)],
|
|
25
|
-
['agent:message', (data) => this._handleEvent('agent:message', data)],
|
|
26
|
-
['think:thought_completed', (data) => this._handleEvent('think:thought_completed', data)],
|
|
27
|
-
['scheduler:task_completed', (data) => this._handleEvent('scheduler:task_completed', data)],
|
|
28
|
-
['scheduler:task_failed', (data) => this._handleEvent('scheduler:task_failed', data)],
|
|
29
|
-
['email:received', (data) => this._handleEvent('email:received', data)],
|
|
30
|
-
['webhook:received', (data) => this._handleEvent('webhook:received', data)]
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
-
for (const [event, handler] of events) {
|
|
34
|
-
this._framework.on(event, handler)
|
|
35
|
-
this._handlers.push({ event, handler })
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 停止事件监听
|
|
41
|
-
*/
|
|
42
|
-
stop() {
|
|
43
|
-
for (const { event, handler } of this._handlers) {
|
|
44
|
-
this._framework.off(event, handler)
|
|
45
|
-
}
|
|
46
|
-
this._handlers = []
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 处理事件
|
|
51
|
-
* @param {string} type - 事件类型
|
|
52
|
-
* @param {Object} data - 事件数据
|
|
53
|
-
*/
|
|
54
|
-
_handleEvent(type, data) {
|
|
55
|
-
const activeGoals = this._goalManager.getActiveGoals()
|
|
56
|
-
log.info(`_handleEvent: type=${type}, activeGoals=${activeGoals.length}`)
|
|
57
|
-
|
|
58
|
-
for (const goal of activeGoals) {
|
|
59
|
-
// 检查目标条件是否匹配此事件
|
|
60
|
-
const isRelevant = this._isRelevantToGoal(goal, type, data)
|
|
61
|
-
log.info(`goal=${goal.id}, isRelevant=${isRelevant}, conditions=${JSON.stringify(goal.conditions)}`)
|
|
62
|
-
|
|
63
|
-
if (isRelevant) {
|
|
64
|
-
// 将 data 展平到事件对象中,方便通过 {{_event.xxx}} 访问
|
|
65
|
-
this._goalManager.addEventToGoal(goal.id, { type, ...data })
|
|
66
|
-
log.info(`Event added to goal ${goal.id}`)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 检查是否有 pending 目标需要激活
|
|
71
|
-
const pendingGoals = this._goalManager.getPendingGoals()
|
|
72
|
-
for (const goal of pendingGoals) {
|
|
73
|
-
if (this._isRelevantToGoal(goal, type, data)) {
|
|
74
|
-
// 激活目标
|
|
75
|
-
this._goalManager.activateGoal(goal.id)
|
|
76
|
-
// 添加事件
|
|
77
|
-
this._goalManager.addEventToGoal(goal.id, { type, ...data })
|
|
78
|
-
log.info(`事件触发激活目标: ${goal.id} (事件: ${type})`)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 检查事件是否与目标相关
|
|
85
|
-
* @param {Object} goal - 目标对象
|
|
86
|
-
* @param {string} eventType - 事件类型
|
|
87
|
-
* @param {Object} data - 事件数据
|
|
88
|
-
* @returns {boolean} 是否相关
|
|
89
|
-
*/
|
|
90
|
-
_isRelevantToGoal(goal, eventType, data) {
|
|
91
|
-
// 检查条件中是否有明确的事件类型
|
|
92
|
-
if (goal.conditions && goal.conditions.events) {
|
|
93
|
-
const allowedEvents = Array.isArray(goal.conditions.events)
|
|
94
|
-
? goal.conditions.events
|
|
95
|
-
: [goal.conditions.events]
|
|
96
|
-
if (!allowedEvents.includes(eventType)) {
|
|
97
|
-
return false
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// 检查工具名称过滤器
|
|
101
|
-
if (goal.conditions && goal.conditions.toolNames) {
|
|
102
|
-
const toolNames = Array.isArray(goal.conditions.toolNames)
|
|
103
|
-
? goal.conditions.toolNames
|
|
104
|
-
: [goal.conditions.toolNames]
|
|
105
|
-
if (data && data.toolName && !toolNames.includes(data.toolName)) {
|
|
106
|
-
return false
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return true
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
module.exports = { EventWatcher }
|
|
1
|
+
/**
|
|
2
|
+
* EventWatcher - 订阅框架事件,筛选相关事件
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { logger } = require('../../src/utils/logger')
|
|
6
|
+
const { DefaultEvents } = require('./constants')
|
|
7
|
+
|
|
8
|
+
const log = logger.child('Ambient:EventWatcher')
|
|
9
|
+
|
|
10
|
+
class EventWatcher {
|
|
11
|
+
constructor(goalManager, framework) {
|
|
12
|
+
this._goalManager = goalManager
|
|
13
|
+
this._framework = framework
|
|
14
|
+
this._handlers = []
|
|
15
|
+
this._relevantEvents = new Set(DefaultEvents)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 启动事件监听
|
|
20
|
+
*/
|
|
21
|
+
start() {
|
|
22
|
+
const events = [
|
|
23
|
+
['tool:result', (data) => this._handleEvent('tool:result', data)],
|
|
24
|
+
['scheduler:reminder', (data) => this._handleEvent('scheduler:reminder', data)],
|
|
25
|
+
['agent:message', (data) => this._handleEvent('agent:message', data)],
|
|
26
|
+
['think:thought_completed', (data) => this._handleEvent('think:thought_completed', data)],
|
|
27
|
+
['scheduler:task_completed', (data) => this._handleEvent('scheduler:task_completed', data)],
|
|
28
|
+
['scheduler:task_failed', (data) => this._handleEvent('scheduler:task_failed', data)],
|
|
29
|
+
['email:received', (data) => this._handleEvent('email:received', data)],
|
|
30
|
+
['webhook:received', (data) => this._handleEvent('webhook:received', data)]
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
for (const [event, handler] of events) {
|
|
34
|
+
this._framework.on(event, handler)
|
|
35
|
+
this._handlers.push({ event, handler })
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 停止事件监听
|
|
41
|
+
*/
|
|
42
|
+
stop() {
|
|
43
|
+
for (const { event, handler } of this._handlers) {
|
|
44
|
+
this._framework.off(event, handler)
|
|
45
|
+
}
|
|
46
|
+
this._handlers = []
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 处理事件
|
|
51
|
+
* @param {string} type - 事件类型
|
|
52
|
+
* @param {Object} data - 事件数据
|
|
53
|
+
*/
|
|
54
|
+
_handleEvent(type, data) {
|
|
55
|
+
const activeGoals = this._goalManager.getActiveGoals()
|
|
56
|
+
log.info(`_handleEvent: type=${type}, activeGoals=${activeGoals.length}`)
|
|
57
|
+
|
|
58
|
+
for (const goal of activeGoals) {
|
|
59
|
+
// 检查目标条件是否匹配此事件
|
|
60
|
+
const isRelevant = this._isRelevantToGoal(goal, type, data)
|
|
61
|
+
log.info(`goal=${goal.id}, isRelevant=${isRelevant}, conditions=${JSON.stringify(goal.conditions)}`)
|
|
62
|
+
|
|
63
|
+
if (isRelevant) {
|
|
64
|
+
// 将 data 展平到事件对象中,方便通过 {{_event.xxx}} 访问
|
|
65
|
+
this._goalManager.addEventToGoal(goal.id, { type, ...data })
|
|
66
|
+
log.info(`Event added to goal ${goal.id}`)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 检查是否有 pending 目标需要激活
|
|
71
|
+
const pendingGoals = this._goalManager.getPendingGoals()
|
|
72
|
+
for (const goal of pendingGoals) {
|
|
73
|
+
if (this._isRelevantToGoal(goal, type, data)) {
|
|
74
|
+
// 激活目标
|
|
75
|
+
this._goalManager.activateGoal(goal.id)
|
|
76
|
+
// 添加事件
|
|
77
|
+
this._goalManager.addEventToGoal(goal.id, { type, ...data })
|
|
78
|
+
log.info(`事件触发激活目标: ${goal.id} (事件: ${type})`)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 检查事件是否与目标相关
|
|
85
|
+
* @param {Object} goal - 目标对象
|
|
86
|
+
* @param {string} eventType - 事件类型
|
|
87
|
+
* @param {Object} data - 事件数据
|
|
88
|
+
* @returns {boolean} 是否相关
|
|
89
|
+
*/
|
|
90
|
+
_isRelevantToGoal(goal, eventType, data) {
|
|
91
|
+
// 检查条件中是否有明确的事件类型
|
|
92
|
+
if (goal.conditions && goal.conditions.events) {
|
|
93
|
+
const allowedEvents = Array.isArray(goal.conditions.events)
|
|
94
|
+
? goal.conditions.events
|
|
95
|
+
: [goal.conditions.events]
|
|
96
|
+
if (!allowedEvents.includes(eventType)) {
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// 检查工具名称过滤器
|
|
101
|
+
if (goal.conditions && goal.conditions.toolNames) {
|
|
102
|
+
const toolNames = Array.isArray(goal.conditions.toolNames)
|
|
103
|
+
? goal.conditions.toolNames
|
|
104
|
+
: [goal.conditions.toolNames]
|
|
105
|
+
if (data && data.toolName && !toolNames.includes(data.toolName)) {
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return true
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = { EventWatcher }
|