@ai-setting/roy-agent-core 1.5.106 → 1.5.107
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/dist/env/event-source/index.js +3 -3
- package/dist/env/index.js +6 -6
- package/dist/env/plugin/index.js +104 -2
- package/dist/env/prompt/index.js +2 -2
- package/dist/env/task/delegate/index.js +2 -2
- package/dist/env/task/index.js +3 -3
- package/dist/env/task/plugins/index.js +2 -2
- package/dist/index.js +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-hq4pqava.js → roy-agent-core-0azsw550.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-gabw591f.js → roy-agent-core-44tqfctj.js} +6 -0
- package/dist/shared/@ai-setting/{roy-agent-core-gdhcj2x4.js → roy-agent-core-5zbfs2v9.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-jy5hkjtb.js → roy-agent-core-7aqhafd9.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-g17zc2kf.js → roy-agent-core-n6dgm687.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-1qbny05x.js → roy-agent-core-rj9qpdm5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ws76avbn.js → roy-agent-core-z7dxedn6.js} +87 -2
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
larkCliHandler,
|
|
11
11
|
resolveBountyIMSystemPrompt,
|
|
12
12
|
timerHandler
|
|
13
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
13
|
+
} from "../../shared/@ai-setting/roy-agent-core-0azsw550.js";
|
|
14
14
|
import {
|
|
15
15
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
16
16
|
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
@@ -21,12 +21,12 @@ import {
|
|
|
21
21
|
validateEventSourceConfig
|
|
22
22
|
} from "../../shared/@ai-setting/roy-agent-core-ds5f75pg.js";
|
|
23
23
|
import"../../shared/@ai-setting/roy-agent-core-wmkx79b1.js";
|
|
24
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
24
|
+
import"../../shared/@ai-setting/roy-agent-core-5zbfs2v9.js";
|
|
25
25
|
import"../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
26
26
|
import"../../shared/@ai-setting/roy-agent-core-8wd3qwx5.js";
|
|
27
27
|
import"../../shared/@ai-setting/roy-agent-core-4yq23m5g.js";
|
|
28
28
|
import"../../shared/@ai-setting/roy-agent-core-xjdcx45t.js";
|
|
29
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
29
|
+
import"../../shared/@ai-setting/roy-agent-core-44tqfctj.js";
|
|
30
30
|
import"../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
31
31
|
import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
|
|
32
32
|
import"../../shared/@ai-setting/roy-agent-core-pf1c360e.js";
|
package/dist/env/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
EventSourceComponent,
|
|
6
6
|
builtInHandlers,
|
|
7
7
|
larkCliHandler
|
|
8
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
8
|
+
} from "../shared/@ai-setting/roy-agent-core-0azsw550.js";
|
|
9
9
|
import {
|
|
10
10
|
EventSourceInitHooks,
|
|
11
11
|
getDefaultConfigForType,
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
import"../shared/@ai-setting/roy-agent-core-wmkx79b1.js";
|
|
17
17
|
import {
|
|
18
18
|
PluginComponent
|
|
19
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
20
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
19
|
+
} from "../shared/@ai-setting/roy-agent-core-z7dxedn6.js";
|
|
20
|
+
import"../shared/@ai-setting/roy-agent-core-5zbfs2v9.js";
|
|
21
21
|
import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
22
22
|
import {
|
|
23
23
|
WorkflowComponent
|
|
@@ -49,12 +49,12 @@ import"../shared/@ai-setting/roy-agent-core-xjdcx45t.js";
|
|
|
49
49
|
import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
50
50
|
import {
|
|
51
51
|
TaskComponent
|
|
52
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
52
|
+
} from "../shared/@ai-setting/roy-agent-core-n6dgm687.js";
|
|
53
53
|
import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
|
|
54
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
54
|
+
import"../shared/@ai-setting/roy-agent-core-7aqhafd9.js";
|
|
55
55
|
import"../shared/@ai-setting/roy-agent-core-pzeexnhf.js";
|
|
56
56
|
import"../shared/@ai-setting/roy-agent-core-9xby523m.js";
|
|
57
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
57
|
+
import"../shared/@ai-setting/roy-agent-core-44tqfctj.js";
|
|
58
58
|
import"../shared/@ai-setting/roy-agent-core-k31c3kvz.js";
|
|
59
59
|
import {
|
|
60
60
|
XDG_PATHS,
|
package/dist/env/plugin/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
EventBusNotificationChannel,
|
|
2
3
|
PluginComponent
|
|
3
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
4
|
+
} from "../../shared/@ai-setting/roy-agent-core-z7dxedn6.js";
|
|
4
5
|
import {
|
|
5
6
|
BasePlugin
|
|
6
7
|
} from "../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
@@ -10,11 +11,112 @@ import"../../shared/@ai-setting/roy-agent-core-gp872e7m.js";
|
|
|
10
11
|
import"../../shared/@ai-setting/roy-agent-core-zttjq1h3.js";
|
|
11
12
|
import"../../shared/@ai-setting/roy-agent-core-scp0afxg.js";
|
|
12
13
|
import"../../shared/@ai-setting/roy-agent-core-cg146hmg.js";
|
|
13
|
-
import
|
|
14
|
+
import {
|
|
15
|
+
createLogger,
|
|
16
|
+
init_logger
|
|
17
|
+
} from "../../shared/@ai-setting/roy-agent-core-vyygk314.js";
|
|
14
18
|
import"../../shared/@ai-setting/roy-agent-core-7z9b1fm8.js";
|
|
15
19
|
import"../../shared/@ai-setting/roy-agent-core-c6592r3c.js";
|
|
16
20
|
import"../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
|
|
21
|
+
// src/env/plugin/lark-cli-notification-channel.ts
|
|
22
|
+
init_logger();
|
|
23
|
+
import { spawn } from "node:child_process";
|
|
24
|
+
var logger = createLogger("plugin:notification:lark-cli");
|
|
25
|
+
|
|
26
|
+
class LarkCliNotificationChannel {
|
|
27
|
+
name = "lark-cli";
|
|
28
|
+
canRoute(_options, _extras, envContext) {
|
|
29
|
+
const channel = envContext.replyChannel;
|
|
30
|
+
if (!channel) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (!channel.type || !channel.type.toLowerCase().includes("lark")) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (!channel.chatId && !channel.messageId) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
async send(options, extras, envContext) {
|
|
42
|
+
const replyChannel = envContext.replyChannel;
|
|
43
|
+
if (!replyChannel) {
|
|
44
|
+
logger.debug(`[lark-cli] No replyChannel for plugin '${extras.pluginName}', skip`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const chatId = replyChannel.chatId;
|
|
48
|
+
const messageId = replyChannel.messageId;
|
|
49
|
+
const profile = replyChannel.profile;
|
|
50
|
+
if (!chatId && !messageId) {
|
|
51
|
+
logger.debug(`[lark-cli] replyChannel has no chatId/messageId for plugin '${extras.pluginName}', skip`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const message = `${options.title}
|
|
55
|
+
|
|
56
|
+
${options.content}`;
|
|
57
|
+
try {
|
|
58
|
+
await this.spawnLarkMessage({ chatId, messageId, content: message, profile });
|
|
59
|
+
logger.info(`[lark-cli] Notification sent for plugin '${extras.pluginName}': ${options.type}`);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
logger.warn(`[lark-cli] Failed to send notification for plugin '${extras.pluginName}' (${options.type}): ${err}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
spawnLarkMessage(options) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const { chatId, messageId, content, profile } = options;
|
|
67
|
+
let args;
|
|
68
|
+
if (messageId) {
|
|
69
|
+
args = [
|
|
70
|
+
"im",
|
|
71
|
+
"+messages-reply",
|
|
72
|
+
"--message-id",
|
|
73
|
+
messageId,
|
|
74
|
+
"--markdown",
|
|
75
|
+
content,
|
|
76
|
+
"--as",
|
|
77
|
+
"bot"
|
|
78
|
+
];
|
|
79
|
+
} else {
|
|
80
|
+
args = [
|
|
81
|
+
"im",
|
|
82
|
+
"+messages-send",
|
|
83
|
+
"--chat-id",
|
|
84
|
+
chatId,
|
|
85
|
+
"--markdown",
|
|
86
|
+
content
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
if (profile) {
|
|
90
|
+
args.unshift("--profile", profile);
|
|
91
|
+
}
|
|
92
|
+
const proc = spawn("lark-cli", args, {
|
|
93
|
+
shell: false,
|
|
94
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
95
|
+
});
|
|
96
|
+
let stdout = "";
|
|
97
|
+
let stderr = "";
|
|
98
|
+
proc.stdout?.on("data", (data) => {
|
|
99
|
+
stdout += data.toString();
|
|
100
|
+
});
|
|
101
|
+
proc.stderr?.on("data", (data) => {
|
|
102
|
+
stderr += data.toString();
|
|
103
|
+
});
|
|
104
|
+
proc.on("close", (code) => {
|
|
105
|
+
if (code === 0) {
|
|
106
|
+
resolve();
|
|
107
|
+
} else {
|
|
108
|
+
reject(new Error(`lark-cli exited with code ${code}: ${stderr}`));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
proc.on("error", (error) => {
|
|
112
|
+
reject(error);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
17
117
|
export {
|
|
18
118
|
PluginComponent,
|
|
119
|
+
LarkCliNotificationChannel,
|
|
120
|
+
EventBusNotificationChannel,
|
|
19
121
|
BasePlugin
|
|
20
122
|
};
|
package/dist/env/prompt/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
PromptConfigSchema,
|
|
4
4
|
PromptPathSchema,
|
|
5
5
|
PromptRenderer
|
|
6
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
7
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
6
|
+
} from "../../shared/@ai-setting/roy-agent-core-rj9qpdm5.js";
|
|
7
|
+
import"../../shared/@ai-setting/roy-agent-core-44tqfctj.js";
|
|
8
8
|
import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
|
|
9
9
|
import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
|
|
10
10
|
import"../../shared/@ai-setting/roy-agent-core-pf1c360e.js";
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
BackgroundTaskManager,
|
|
4
4
|
createDelegateTool,
|
|
5
5
|
createStopTool
|
|
6
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
6
|
+
} from "../../../shared/@ai-setting/roy-agent-core-7aqhafd9.js";
|
|
7
7
|
import"../../../shared/@ai-setting/roy-agent-core-pzeexnhf.js";
|
|
8
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
8
|
+
import"../../../shared/@ai-setting/roy-agent-core-44tqfctj.js";
|
|
9
9
|
import"../../../shared/@ai-setting/roy-agent-core-k31c3kvz.js";
|
|
10
10
|
import"../../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
|
|
11
11
|
import"../../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
package/dist/env/task/index.js
CHANGED
|
@@ -5,17 +5,17 @@ import {
|
|
|
5
5
|
TaskPriorityEnum,
|
|
6
6
|
TaskStatusEnum,
|
|
7
7
|
TaskTypeEnum
|
|
8
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
8
|
+
} from "../../shared/@ai-setting/roy-agent-core-n6dgm687.js";
|
|
9
9
|
import {
|
|
10
10
|
TaskEntityEventTypes
|
|
11
11
|
} from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
|
|
12
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
12
|
+
import"../../shared/@ai-setting/roy-agent-core-7aqhafd9.js";
|
|
13
13
|
import"../../shared/@ai-setting/roy-agent-core-pzeexnhf.js";
|
|
14
14
|
import {
|
|
15
15
|
SQLiteTaskStore,
|
|
16
16
|
getDefaultTaskDbPath
|
|
17
17
|
} from "../../shared/@ai-setting/roy-agent-core-9xby523m.js";
|
|
18
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
18
|
+
import"../../shared/@ai-setting/roy-agent-core-44tqfctj.js";
|
|
19
19
|
import"../../shared/@ai-setting/roy-agent-core-k31c3kvz.js";
|
|
20
20
|
import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
|
|
21
21
|
import"../../shared/@ai-setting/roy-agent-core-0ye4q2jj.js";
|
|
@@ -7,14 +7,14 @@ import {
|
|
|
7
7
|
formatExtractorInput,
|
|
8
8
|
formatExtractorInputFromDescription,
|
|
9
9
|
parseExtractorOutput
|
|
10
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
10
|
+
} from "../../../shared/@ai-setting/roy-agent-core-5zbfs2v9.js";
|
|
11
11
|
import"../../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
12
12
|
import"../../../shared/@ai-setting/roy-agent-core-8wd3qwx5.js";
|
|
13
13
|
import"../../../shared/@ai-setting/roy-agent-core-4yq23m5g.js";
|
|
14
14
|
import {
|
|
15
15
|
createAutoTaskPlugin
|
|
16
16
|
} from "../../../shared/@ai-setting/roy-agent-core-xjdcx45t.js";
|
|
17
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
17
|
+
import"../../../shared/@ai-setting/roy-agent-core-44tqfctj.js";
|
|
18
18
|
import"../../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
19
19
|
import"../../../shared/@ai-setting/roy-agent-core-zttjq1h3.js";
|
|
20
20
|
import"../../../shared/@ai-setting/roy-agent-core-scp0afxg.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PromptComponent,
|
|
3
3
|
PromptStore
|
|
4
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
4
|
+
} from "./shared/@ai-setting/roy-agent-core-rj9qpdm5.js";
|
|
5
5
|
import {
|
|
6
6
|
LLMComponent,
|
|
7
7
|
LLMConfigSchema,
|
|
@@ -74,7 +74,7 @@ import {
|
|
|
74
74
|
larkCliHandler,
|
|
75
75
|
resolveBountyIMSystemPrompt,
|
|
76
76
|
timerHandler
|
|
77
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
77
|
+
} from "./shared/@ai-setting/roy-agent-core-0azsw550.js";
|
|
78
78
|
import {
|
|
79
79
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
80
80
|
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
@@ -90,10 +90,10 @@ import {
|
|
|
90
90
|
} from "./shared/@ai-setting/roy-agent-core-wmkx79b1.js";
|
|
91
91
|
import {
|
|
92
92
|
PluginComponent
|
|
93
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
93
|
+
} from "./shared/@ai-setting/roy-agent-core-z7dxedn6.js";
|
|
94
94
|
import {
|
|
95
95
|
TaskTagPlugin
|
|
96
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
96
|
+
} from "./shared/@ai-setting/roy-agent-core-5zbfs2v9.js";
|
|
97
97
|
import {
|
|
98
98
|
BasePlugin
|
|
99
99
|
} from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
@@ -150,9 +150,9 @@ import {
|
|
|
150
150
|
} from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
151
151
|
import {
|
|
152
152
|
TaskComponent
|
|
153
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
153
|
+
} from "./shared/@ai-setting/roy-agent-core-n6dgm687.js";
|
|
154
154
|
import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
|
|
155
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
155
|
+
import"./shared/@ai-setting/roy-agent-core-7aqhafd9.js";
|
|
156
156
|
import"./shared/@ai-setting/roy-agent-core-pzeexnhf.js";
|
|
157
157
|
import {
|
|
158
158
|
SQLiteTaskStore,
|
|
@@ -161,7 +161,7 @@ import {
|
|
|
161
161
|
import {
|
|
162
162
|
getBuiltInPrompt,
|
|
163
163
|
getBuiltInPromptNames
|
|
164
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
164
|
+
} from "./shared/@ai-setting/roy-agent-core-44tqfctj.js";
|
|
165
165
|
import {
|
|
166
166
|
AgentRegistry
|
|
167
167
|
} from "./shared/@ai-setting/roy-agent-core-k31c3kvz.js";
|
|
@@ -210,6 +210,12 @@ delegate_task(
|
|
|
210
210
|
5. **次选 strict-task-agent** — 需要严格 Plan→Execute→Verify 纪律时使用
|
|
211
211
|
6. **始终包含任务生命周期** — 每次委托时,指示子智能体使用 \`task_create\` → \`task_update\` → \`task_operation_create\` → \`task_complete\`
|
|
212
212
|
7. **简单回复** — 对于问候、简单问答或结果总结,可以直接回复
|
|
213
|
+
8. **⚠️ 不要 sleep 等待后台任务结果** — \`delegate_task\` 总是后台模式(参见下方"子代理通知自主处理规则"),委托后**立即返回**。**禁止**调用 \`sleep\`、\`wait\`、\`sleep N\` 等任何同步等待命令试图"等子智能体跑完"。原因:
|
|
214
|
+
- \`sleep\` 会阻塞当前 ReAct 循环,导致**无法及时接收**后台进程或子智能体的通知消息
|
|
215
|
+
- 后台任务完成后系统会**自动推送通知**(completed / failed / progress / timeout)
|
|
216
|
+
- 父 agent 收到通知后**自主处理**(见下一节),无需主动 sleep 轮询
|
|
217
|
+
- 错误做法:\`sleep 60 && task_get <id>\`、\`while !task_complete; do sleep 5; done\`
|
|
218
|
+
- 正确做法:\`delegate_task(...)\` → 立即返回 → 等待系统通知 → 收到通知后自主处理
|
|
213
219
|
|
|
214
220
|
## 子代理通知自主处理规则
|
|
215
221
|
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./roy-agent-core-pzeexnhf.js";
|
|
5
5
|
import {
|
|
6
6
|
builtInPrompts
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-44tqfctj.js";
|
|
8
8
|
import {
|
|
9
9
|
DEFAULT_SUBAGENT_PROMPT
|
|
10
10
|
} from "./roy-agent-core-k31c3kvz.js";
|
|
@@ -254,7 +254,7 @@ ${originalPrompt}
|
|
|
254
254
|
`;
|
|
255
255
|
}
|
|
256
256
|
var DEFAULT_TIMEOUT = 1800000;
|
|
257
|
-
var PROGRESS_INTERVAL =
|
|
257
|
+
var PROGRESS_INTERVAL = 1200000;
|
|
258
258
|
|
|
259
259
|
class BackgroundTaskManager {
|
|
260
260
|
env;
|
|
@@ -8,18 +8,71 @@ import {
|
|
|
8
8
|
globalHookManager,
|
|
9
9
|
init_global_hook_manager
|
|
10
10
|
} from "./roy-agent-core-gp872e7m.js";
|
|
11
|
+
import {
|
|
12
|
+
init_context
|
|
13
|
+
} from "./roy-agent-core-zttjq1h3.js";
|
|
14
|
+
import {
|
|
15
|
+
getEnvContextOrEmpty
|
|
16
|
+
} from "./roy-agent-core-scp0afxg.js";
|
|
11
17
|
import {
|
|
12
18
|
createLogger,
|
|
13
19
|
init_logger
|
|
14
20
|
} from "./roy-agent-core-vyygk314.js";
|
|
15
21
|
|
|
22
|
+
// src/env/plugin/event-bus-notification-channel.ts
|
|
23
|
+
init_logger();
|
|
24
|
+
var logger = createLogger("plugin:notification:event-bus");
|
|
25
|
+
|
|
26
|
+
class EventBusNotificationChannel {
|
|
27
|
+
name = "event-bus";
|
|
28
|
+
canRoute(_options, _extras, _envContext) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
async send(options, extras, _envContext) {
|
|
32
|
+
const envInstance = extras.envInstance;
|
|
33
|
+
if (!envInstance) {
|
|
34
|
+
logger.debug(`[event-bus] No envInstance for plugin '${extras.pluginName}', skip notification '${options.type}'`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const pushFn = envInstance.pushEnvEvent;
|
|
38
|
+
if (typeof pushFn !== "function") {
|
|
39
|
+
logger.debug(`[event-bus] envInstance.pushEnvEvent is not a function for plugin '${extras.pluginName}', skip notification '${options.type}'`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const eventType = `plugin.notification.${options.type}`;
|
|
43
|
+
const event = {
|
|
44
|
+
id: generateEventId(),
|
|
45
|
+
type: eventType,
|
|
46
|
+
timestamp: Date.now(),
|
|
47
|
+
metadata: {
|
|
48
|
+
source: `plugin:${extras.pluginName}`,
|
|
49
|
+
...options.metadata || {}
|
|
50
|
+
},
|
|
51
|
+
payload: {
|
|
52
|
+
title: options.title,
|
|
53
|
+
content: options.content
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
pushFn.call(envInstance, event);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
logger.warn(`[event-bus] pushEnvEvent threw for plugin '${extras.pluginName}' notification '${options.type}': ${err}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function generateEventId() {
|
|
64
|
+
const ts = Date.now().toString(36);
|
|
65
|
+
const rand = Math.random().toString(36).slice(2, 10);
|
|
66
|
+
return `${ts}-${rand}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
16
69
|
// src/env/plugin/plugin-component.ts
|
|
17
70
|
init_global_hook_manager();
|
|
18
71
|
init_logger();
|
|
72
|
+
init_context();
|
|
19
73
|
import { existsSync, readFileSync } from "node:fs";
|
|
20
74
|
import { join } from "node:path";
|
|
21
75
|
import { homedir } from "node:os";
|
|
22
|
-
|
|
23
76
|
class PluginComponent extends BaseComponent {
|
|
24
77
|
name = "plugin";
|
|
25
78
|
version = "1.0.0";
|
|
@@ -27,6 +80,9 @@ class PluginComponent extends BaseComponent {
|
|
|
27
80
|
componentCache = new Map;
|
|
28
81
|
logger = createLogger("plugin");
|
|
29
82
|
configComponent;
|
|
83
|
+
notificationChannels = [
|
|
84
|
+
new EventBusNotificationChannel
|
|
85
|
+
];
|
|
30
86
|
constructor() {
|
|
31
87
|
super();
|
|
32
88
|
}
|
|
@@ -185,6 +241,27 @@ class PluginComponent extends BaseComponent {
|
|
|
185
241
|
await this.register(plugin);
|
|
186
242
|
}
|
|
187
243
|
}
|
|
244
|
+
setNotificationChannels(channels) {
|
|
245
|
+
this.notificationChannels = [...channels];
|
|
246
|
+
this.logger.info(`[PluginComponent] Notification channels updated: ${this.notificationChannels.map((c) => c.name).join(", ") || "(none)"}`);
|
|
247
|
+
}
|
|
248
|
+
getNotificationChannelNames() {
|
|
249
|
+
return this.notificationChannels.map((c) => c.name);
|
|
250
|
+
}
|
|
251
|
+
async routeNotification(options, extras, envContext) {
|
|
252
|
+
for (const channel of this.notificationChannels) {
|
|
253
|
+
try {
|
|
254
|
+
if (!channel.canRoute(options, extras, envContext)) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
await channel.send(options, extras, envContext);
|
|
258
|
+
return;
|
|
259
|
+
} catch (err) {
|
|
260
|
+
this.logger.warn(`[PluginComponent] Notification channel '${channel.name}' send threw: ${err}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
this.logger.warn(`[PluginComponent] No notification channel can route '${options.type}' (plugin: ${extras.pluginName})`);
|
|
264
|
+
}
|
|
188
265
|
async stop() {
|
|
189
266
|
this.setStatus("stopping");
|
|
190
267
|
this.logger.info("[PluginComponent] Stopping...");
|
|
@@ -236,9 +313,17 @@ class PluginComponent extends BaseComponent {
|
|
|
236
313
|
});
|
|
237
314
|
self.logger.debug(`Registered hook: ${hook.point} (for plugin: ${plugin.name})`);
|
|
238
315
|
},
|
|
316
|
+
async notify(options) {
|
|
317
|
+
const envContext = getEnvContextOrEmpty();
|
|
318
|
+
const extras = {
|
|
319
|
+
pluginName: plugin.name,
|
|
320
|
+
envInstance: self.env
|
|
321
|
+
};
|
|
322
|
+
await self.routeNotification(options, extras, envContext);
|
|
323
|
+
},
|
|
239
324
|
logger: createLogger(`plugin:${plugin.name}`)
|
|
240
325
|
};
|
|
241
326
|
}
|
|
242
327
|
}
|
|
243
328
|
|
|
244
|
-
export { PluginComponent };
|
|
329
|
+
export { EventBusNotificationChannel, PluginComponent };
|