@ai-setting/roy-agent-core 1.5.37 → 1.5.41
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/config/index.js +4 -3
- package/dist/env/agent/index.js +10 -9
- package/dist/env/commands/index.js +7 -6
- package/dist/env/context/index.js +21 -0
- package/dist/env/debug/index.js +4 -3
- package/dist/env/event-source/index.js +12 -6
- package/dist/env/hook/index.js +2 -1
- package/dist/env/index.js +41 -18
- package/dist/env/llm/index.js +8 -7
- package/dist/env/log-trace/index.js +10 -9
- package/dist/env/mcp/index.js +8 -7
- package/dist/env/mcp/tool/index.js +4 -4
- package/dist/env/memory/index.js +12 -11
- package/dist/env/memory/plugin/index.js +4 -4
- package/dist/env/plugin/index.js +18 -0
- package/dist/env/prompt/index.js +7 -6
- package/dist/env/session/index.js +11 -10
- package/dist/env/session/storage/index.js +2 -6
- package/dist/env/skill/index.js +7 -6
- package/dist/env/task/delegate/index.js +6 -5
- package/dist/env/task/index.js +10 -8
- package/dist/env/task/plugins/index.js +13 -6
- package/dist/env/task/storage/index.js +4 -4
- package/dist/env/tool/built-in/index.js +3 -3
- package/dist/env/tool/index.js +8 -7
- package/dist/env/workflow/engine/index.js +5 -5
- package/dist/env/workflow/index.js +9 -8
- package/dist/env/workflow/storage/index.js +5 -5
- package/dist/env/workflow/tools/index.js +3 -3
- package/dist/env/workflow/utils/index.js +4 -4
- package/dist/index.js +67 -60
- package/dist/shared/@ai-setting/{roy-agent-core-44hnfb02.js → roy-agent-core-10n2jh7p.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xt3fx7m1.js → roy-agent-core-15x8fe5h.js} +38 -56
- package/dist/shared/@ai-setting/{roy-agent-core-1akcqxj9.js → roy-agent-core-1bfmxx89.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ty94k28r.js → roy-agent-core-2jnzv9at.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-cefh9hjv.js → roy-agent-core-4jqq077c.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xs5rsgat.js → roy-agent-core-58k274fg.js} +108 -23
- package/dist/shared/@ai-setting/{roy-agent-core-jfh9q2qh.js → roy-agent-core-7b35emr7.js} +0 -15
- package/dist/shared/@ai-setting/{roy-agent-core-3rr5k71j.js → roy-agent-core-8n4bz6y3.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-zpn0bqa8.js → roy-agent-core-9ffsvvcf.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-az13yzmc.js +11 -0
- package/dist/shared/@ai-setting/{roy-agent-core-0wdjp769.js → roy-agent-core-b4wd9tn6.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-6kvtahqv.js → roy-agent-core-c3ct1346.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-psv4v63c.js → roy-agent-core-c6592r3c.js} +19 -2
- package/dist/shared/@ai-setting/{roy-agent-core-c2wjwx16.js → roy-agent-core-c8f2hync.js} +305 -287
- package/dist/shared/@ai-setting/roy-agent-core-cevpwnq7.js +147 -0
- package/dist/shared/@ai-setting/{roy-agent-core-hkb529dw.js → roy-agent-core-dxbsc1zy.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-vqspcspb.js → roy-agent-core-e130w7mv.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-3jywqmdd.js → roy-agent-core-e9fdm13a.js} +319 -65
- package/dist/shared/@ai-setting/{roy-agent-core-j0ke54vy.js → roy-agent-core-ee6nnnqw.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-qdmt6nz7.js → roy-agent-core-eg6nv09z.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-hd1z20yq.js → roy-agent-core-frx4p6d1.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-bvr1761x.js → roy-agent-core-hsxn8m1j.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-86gphny5.js → roy-agent-core-jqy2mdyq.js} +15 -1
- package/dist/shared/@ai-setting/{roy-agent-core-c0d3dtjd.js → roy-agent-core-kajktp3d.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-eajcvp4e.js → roy-agent-core-kwhv9dcd.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-r9ezzemr.js → roy-agent-core-m0wp34r4.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fg1kxf70.js → roy-agent-core-nqgrjja0.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-mx489p7f.js → roy-agent-core-psvwzdhj.js} +263 -33
- package/dist/shared/@ai-setting/{roy-agent-core-d7cyjkf7.js → roy-agent-core-pwkk12p4.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-97ma0pr5.js → roy-agent-core-pxcrzyv9.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-zgypchmt.js → roy-agent-core-q5qj0fes.js} +19 -11
- package/dist/shared/@ai-setting/{roy-agent-core-sx7wsvnn.js → roy-agent-core-qakqwbbh.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-qfdp3pvq.js → roy-agent-core-rsybkb38.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-ty33mnr7.js +14 -0
- package/dist/shared/@ai-setting/{roy-agent-core-3prpabp8.js → roy-agent-core-v53rfk99.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-wjd5kars.js → roy-agent-core-wb43x8hd.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-e2vk2qh7.js → roy-agent-core-yc543gnq.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-gf2c2pxr.js → roy-agent-core-ycg9rk6z.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-z33en0cz.js +44 -0
- package/dist/shared/@ai-setting/{roy-agent-core-by55z88t.js → roy-agent-core-zrja5v78.js} +11 -11
- package/dist/shared/@ai-setting/{roy-agent-core-wft9ra24.js → roy-agent-core-zwp3jp02.js} +4 -4
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEnvContext
|
|
3
|
+
} from "./roy-agent-core-z33en0cz.js";
|
|
4
|
+
|
|
1
5
|
// src/env/hook/hook-manager.ts
|
|
2
6
|
class HookManager {
|
|
3
7
|
_hooks = new Map;
|
|
@@ -34,6 +38,13 @@ class HookManager {
|
|
|
34
38
|
const hooks = this._hooks.get(hookPoint);
|
|
35
39
|
if (!hooks || hooks.length === 0)
|
|
36
40
|
return;
|
|
41
|
+
const envContext = getEnvContext();
|
|
42
|
+
if (envContext) {
|
|
43
|
+
metadata.envContext = envContext;
|
|
44
|
+
if (!metadata.pluginEnabled && envContext.pluginEnabled) {
|
|
45
|
+
metadata.pluginEnabled = envContext.pluginEnabled;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
37
48
|
const sortedHooks = this.sortHooks(hooks);
|
|
38
49
|
const ctx = this.createContext(hookPoint, data, metadata, "before");
|
|
39
50
|
const pluginEnabled = metadata.pluginEnabled || {};
|
|
@@ -135,7 +146,10 @@ class HookManager {
|
|
|
135
146
|
}
|
|
136
147
|
async safeExecute(hook, ctx) {
|
|
137
148
|
try {
|
|
138
|
-
|
|
149
|
+
const result = hook.execute(ctx);
|
|
150
|
+
if (result && typeof result === "object" && typeof result.then === "function") {
|
|
151
|
+
await result;
|
|
152
|
+
}
|
|
139
153
|
} catch (error) {
|
|
140
154
|
console.error(`Hook "${hook.name}" failed:`, error);
|
|
141
155
|
}
|
|
@@ -2,25 +2,25 @@ import {
|
|
|
2
2
|
ContextError,
|
|
3
3
|
ErrorCodes
|
|
4
4
|
} from "./roy-agent-core-ctdhjv68.js";
|
|
5
|
+
import {
|
|
6
|
+
TracedAs,
|
|
7
|
+
init_decorator
|
|
8
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
5
9
|
import {
|
|
6
10
|
envKeyToConfigKey,
|
|
7
11
|
toEnvKey
|
|
8
12
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
9
13
|
import {
|
|
10
14
|
BaseComponent
|
|
11
|
-
} from "./roy-agent-core-
|
|
15
|
+
} from "./roy-agent-core-4jqq077c.js";
|
|
12
16
|
import {
|
|
13
17
|
LLMHookPoints,
|
|
14
18
|
globalHookManager
|
|
15
|
-
} from "./roy-agent-core-
|
|
16
|
-
import {
|
|
17
|
-
TracedAs,
|
|
18
|
-
init_decorator
|
|
19
|
-
} from "./roy-agent-core-zgypchmt.js";
|
|
19
|
+
} from "./roy-agent-core-jqy2mdyq.js";
|
|
20
20
|
import {
|
|
21
21
|
createLogger,
|
|
22
22
|
init_logger
|
|
23
|
-
} from "./roy-agent-core-
|
|
23
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
24
24
|
import {
|
|
25
25
|
__legacyDecorateClassTS,
|
|
26
26
|
__require
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TracedAs,
|
|
3
3
|
init_decorator
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
5
5
|
import {
|
|
6
6
|
createLogger,
|
|
7
7
|
init_logger
|
|
8
|
-
} from "./roy-agent-core-
|
|
8
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
9
9
|
import {
|
|
10
10
|
__legacyDecorateClassTS
|
|
11
11
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./roy-agent-core-rvv6ydff.js";
|
|
5
5
|
import {
|
|
6
6
|
BaseComponent
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-4jqq077c.js";
|
|
8
8
|
import {
|
|
9
9
|
__require
|
|
10
10
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -141,7 +141,7 @@ class SpanDbReader {
|
|
|
141
141
|
}
|
|
142
142
|
async initSqliteStorage() {
|
|
143
143
|
try {
|
|
144
|
-
const { SQLiteSpanStorage } = await import("./roy-agent-core-
|
|
144
|
+
const { SQLiteSpanStorage } = await import("./roy-agent-core-m0wp34r4.js");
|
|
145
145
|
this.storage = new SQLiteSpanStorage(this.dbPath);
|
|
146
146
|
await this.storage.initialize();
|
|
147
147
|
} catch (error) {
|
|
@@ -590,7 +590,7 @@ class DebugComponent extends BaseComponent {
|
|
|
590
590
|
}
|
|
591
591
|
async getLiveTrace(traceId) {
|
|
592
592
|
try {
|
|
593
|
-
const { getTracerProvider } = await import("./roy-agent-core-
|
|
593
|
+
const { getTracerProvider } = await import("./roy-agent-core-qakqwbbh.js");
|
|
594
594
|
const provider = getTracerProvider();
|
|
595
595
|
if (!provider.isInitialized()) {
|
|
596
596
|
await provider.initialize();
|
|
@@ -635,7 +635,7 @@ class DebugComponent extends BaseComponent {
|
|
|
635
635
|
}
|
|
636
636
|
async listLiveTraces(limit = 20) {
|
|
637
637
|
try {
|
|
638
|
-
const { getTracerProvider } = await import("./roy-agent-core-
|
|
638
|
+
const { getTracerProvider } = await import("./roy-agent-core-qakqwbbh.js");
|
|
639
639
|
const provider = getTracerProvider();
|
|
640
640
|
if (!provider.isInitialized()) {
|
|
641
641
|
await provider.initialize();
|
|
@@ -653,7 +653,7 @@ class DebugComponent extends BaseComponent {
|
|
|
653
653
|
}
|
|
654
654
|
async formatLiveTrace(traceId) {
|
|
655
655
|
try {
|
|
656
|
-
const { getTracerProvider } = await import("./roy-agent-core-
|
|
656
|
+
const { getTracerProvider } = await import("./roy-agent-core-qakqwbbh.js");
|
|
657
657
|
const provider = getTracerProvider();
|
|
658
658
|
if (!provider.isInitialized()) {
|
|
659
659
|
await provider.initialize();
|
|
@@ -1,22 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TaskTagPlugin,
|
|
3
|
+
createLarkCliTaskNotifyHook
|
|
4
|
+
} from "./roy-agent-core-e9fdm13a.js";
|
|
1
5
|
import {
|
|
2
6
|
envKeyToConfigKey
|
|
3
7
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
4
8
|
import {
|
|
5
9
|
BaseComponent
|
|
6
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-4jqq077c.js";
|
|
7
11
|
import {
|
|
8
12
|
globalHookManager
|
|
9
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-jqy2mdyq.js";
|
|
14
|
+
import {
|
|
15
|
+
createEnvContext,
|
|
16
|
+
runWithEnvContext
|
|
17
|
+
} from "./roy-agent-core-z33en0cz.js";
|
|
10
18
|
import {
|
|
11
19
|
createLogger,
|
|
12
20
|
init_logger
|
|
13
|
-
} from "./roy-agent-core-
|
|
21
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
22
|
+
import {
|
|
23
|
+
getTracerProvider
|
|
24
|
+
} from "./roy-agent-core-58k274fg.js";
|
|
14
25
|
import {
|
|
15
26
|
__require
|
|
16
27
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
17
28
|
|
|
18
29
|
// src/env/event-source/event-source-handlers.ts
|
|
19
30
|
import { spawn } from "child_process";
|
|
31
|
+
var BUILT_IN_PLUGIN_FACTORIES = {
|
|
32
|
+
LarkCliTaskNotifyPlugin: (cfg) => createLarkCliTaskNotifyHook(cfg),
|
|
33
|
+
"task-tag": () => new TaskTagPlugin
|
|
34
|
+
};
|
|
35
|
+
function generateTraceId() {
|
|
36
|
+
const chars = "0123456789abcdef";
|
|
37
|
+
let traceId = "";
|
|
38
|
+
for (let i = 0;i < 32; i++) {
|
|
39
|
+
traceId += chars[Math.floor(Math.random() * chars.length)];
|
|
40
|
+
}
|
|
41
|
+
return traceId;
|
|
42
|
+
}
|
|
20
43
|
function matchEventType(eventType, patterns) {
|
|
21
44
|
for (const pattern of patterns) {
|
|
22
45
|
if (pattern === "*")
|
|
@@ -35,26 +58,39 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
35
58
|
const event = rawEvent;
|
|
36
59
|
const metadata = {};
|
|
37
60
|
const larkInnerEvent = event.event;
|
|
38
|
-
const header = event.header;
|
|
39
|
-
const message = larkInnerEvent?.message || event.message;
|
|
61
|
+
const header = larkInnerEvent?.header || event.header;
|
|
40
62
|
const sender = larkInnerEvent?.sender || event.sender;
|
|
41
63
|
const senderId = sender?.sender_id;
|
|
64
|
+
let messageData;
|
|
65
|
+
if (larkInnerEvent?.message) {
|
|
66
|
+
messageData = larkInnerEvent.message;
|
|
67
|
+
} else if (typeof event.message === "object" && event.message !== null) {
|
|
68
|
+
messageData = event.message;
|
|
69
|
+
} else {
|
|
70
|
+
messageData = {
|
|
71
|
+
message_id: event.message_id || event.id,
|
|
72
|
+
chat_id: event.chat_id,
|
|
73
|
+
chat_type: event.chat_type,
|
|
74
|
+
message_type: event.message_type,
|
|
75
|
+
content: event.content
|
|
76
|
+
};
|
|
77
|
+
}
|
|
42
78
|
if (header) {
|
|
43
79
|
metadata.eventType = header.event_type;
|
|
44
80
|
metadata.appId = header.app_id;
|
|
45
81
|
metadata.tenantKey = header.tenant_key;
|
|
46
82
|
}
|
|
47
|
-
if (
|
|
48
|
-
metadata.chatId =
|
|
49
|
-
metadata.chatType =
|
|
50
|
-
metadata.messageId =
|
|
51
|
-
metadata.messageType =
|
|
83
|
+
if (messageData) {
|
|
84
|
+
metadata.chatId = messageData.chat_id;
|
|
85
|
+
metadata.chatType = messageData.chat_type;
|
|
86
|
+
metadata.messageId = messageData.message_id;
|
|
87
|
+
metadata.messageType = messageData.message_type;
|
|
52
88
|
}
|
|
53
89
|
if (senderId) {
|
|
54
90
|
metadata.senderId = senderId.open_id || senderId.user_id || senderId.union_id;
|
|
55
91
|
}
|
|
56
92
|
let recommendedAction;
|
|
57
|
-
if (eventType === "im.message.receive_v1") {
|
|
93
|
+
if (eventType === "im.message.receive_v1" || event.type === "im.message.receive_v1") {
|
|
58
94
|
recommendedAction = {
|
|
59
95
|
action: '处理飞书消息并以机器人身份回复,比如lark-cli im +messages-reply --message-id "xxxxid" --as bot --text "回复内容"',
|
|
60
96
|
replyTo: {
|
|
@@ -67,8 +103,8 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
67
103
|
const replyChannel = {
|
|
68
104
|
type: "lark-cli",
|
|
69
105
|
appId: metadata.appId,
|
|
70
|
-
chatId:
|
|
71
|
-
messageId:
|
|
106
|
+
chatId: messageData?.chat_id,
|
|
107
|
+
messageId: messageData?.message_id
|
|
72
108
|
};
|
|
73
109
|
return { metadata, replyChannel, recommendedAction };
|
|
74
110
|
}
|
|
@@ -164,39 +200,107 @@ class LarkCliInstance {
|
|
|
164
200
|
for (const pluginName of plugins) {
|
|
165
201
|
const plugin = await this.importPlugin(pluginName);
|
|
166
202
|
if (plugin) {
|
|
203
|
+
const hookPoints = this.getPluginHookPoints(plugin);
|
|
167
204
|
this.registerPluginHooks(plugin);
|
|
168
205
|
this.loadedPlugins.push({
|
|
169
206
|
name: pluginName,
|
|
170
|
-
hooks:
|
|
207
|
+
hooks: hookPoints.map((h) => ({ point: h, name: `${pluginName}:${h}` }))
|
|
171
208
|
});
|
|
172
209
|
}
|
|
173
210
|
}
|
|
174
211
|
}
|
|
212
|
+
getPluginHookPoints(plugin) {
|
|
213
|
+
if (Array.isArray(plugin.hooks)) {
|
|
214
|
+
return plugin.hooks.map((h) => h.point || h);
|
|
215
|
+
}
|
|
216
|
+
if (typeof plugin.execute === "function" && plugin.hookPoint) {
|
|
217
|
+
return [plugin.hookPoint];
|
|
218
|
+
}
|
|
219
|
+
if (plugin.name && typeof plugin.execute === "function") {
|
|
220
|
+
return ["task:after.create", "task:after.update"];
|
|
221
|
+
}
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
175
224
|
async importPlugin(name) {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
225
|
+
const factory = BUILT_IN_PLUGIN_FACTORIES[name];
|
|
226
|
+
if (!factory) {
|
|
227
|
+
console.error(`[LarkCliInstance] Unknown plugin: ${name}`);
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
180
230
|
try {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
231
|
+
return factory({
|
|
232
|
+
sourceId: this.config.id,
|
|
233
|
+
pluginName: name
|
|
234
|
+
});
|
|
184
235
|
} catch (error) {
|
|
185
|
-
console.error(`[LarkCliInstance] Failed to
|
|
236
|
+
console.error(`[LarkCliInstance] Failed to instantiate plugin ${name}:`, error);
|
|
186
237
|
return null;
|
|
187
238
|
}
|
|
188
239
|
}
|
|
189
240
|
registerPluginHooks(plugin) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
241
|
+
const pluginName = plugin.name || "unknown";
|
|
242
|
+
if (typeof plugin.init === "function") {
|
|
243
|
+
const pluginEnv = {
|
|
244
|
+
getComponent: () => null,
|
|
245
|
+
registerAgent: () => {},
|
|
246
|
+
registerTool: () => {},
|
|
247
|
+
registerHook: (hook) => {
|
|
248
|
+
globalHookManager.register(hook.point, {
|
|
249
|
+
name: `${pluginName}:${hook.point}`,
|
|
250
|
+
priority: hook.priority ?? 0,
|
|
251
|
+
pluginName,
|
|
252
|
+
sourceId: this.config.id,
|
|
253
|
+
execute: hook.handler
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
logger: {
|
|
257
|
+
debug: (...args) => console.debug(`[plugin:${pluginName}]`, ...args),
|
|
258
|
+
info: (...args) => console.info(`[plugin:${pluginName}]`, ...args),
|
|
259
|
+
warn: (...args) => console.warn(`[plugin:${pluginName}]`, ...args),
|
|
260
|
+
error: (...args) => console.error(`[plugin:${pluginName}]`, ...args)
|
|
198
261
|
}
|
|
199
|
-
}
|
|
262
|
+
};
|
|
263
|
+
plugin.init(pluginEnv);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (typeof plugin.execute === "function") {
|
|
267
|
+
if (plugin.hookPoint) {
|
|
268
|
+
globalHookManager.register(plugin.hookPoint, {
|
|
269
|
+
name: `${pluginName}:${plugin.hookPoint}`,
|
|
270
|
+
priority: plugin.priority ?? 0,
|
|
271
|
+
pluginName,
|
|
272
|
+
sourceId: this.config.id,
|
|
273
|
+
execute: plugin.execute
|
|
274
|
+
});
|
|
275
|
+
} else {
|
|
276
|
+
const hookPoints = this.getPluginHookPoints(plugin);
|
|
277
|
+
for (const hookPoint of hookPoints) {
|
|
278
|
+
globalHookManager.register(hookPoint, {
|
|
279
|
+
name: `${pluginName}:${hookPoint}`,
|
|
280
|
+
priority: plugin.priority ?? 0,
|
|
281
|
+
pluginName,
|
|
282
|
+
sourceId: this.config.id,
|
|
283
|
+
execute: plugin.execute.bind(plugin)
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (Array.isArray(plugin.hooks)) {
|
|
290
|
+
for (const hook of plugin.hooks) {
|
|
291
|
+
const hookPoint = hook.point || hook;
|
|
292
|
+
const priority = hook.priority ?? 0;
|
|
293
|
+
globalHookManager.register(hookPoint, {
|
|
294
|
+
name: `${pluginName}:${hookPoint}`,
|
|
295
|
+
priority,
|
|
296
|
+
pluginName,
|
|
297
|
+
sourceId: this.config.id,
|
|
298
|
+
execute: async (ctx) => {
|
|
299
|
+
await plugin.execute(ctx);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
200
304
|
}
|
|
201
305
|
}
|
|
202
306
|
unloadPlugins() {
|
|
@@ -219,6 +323,20 @@ class LarkCliInstance {
|
|
|
219
323
|
}
|
|
220
324
|
}
|
|
221
325
|
handleEvent(rawData) {
|
|
326
|
+
const provider = getTracerProvider();
|
|
327
|
+
const tracer = provider.getTracer("roy-tracer");
|
|
328
|
+
const rootTraceId = generateTraceId();
|
|
329
|
+
const rootSpanId = tracer.generateSpanId();
|
|
330
|
+
const rootContext = {
|
|
331
|
+
traceId: rootTraceId,
|
|
332
|
+
spanId: rootSpanId,
|
|
333
|
+
parentSpanId: undefined
|
|
334
|
+
};
|
|
335
|
+
const rootSpan = tracer.startSpan("lark-cli.handleEvent", {
|
|
336
|
+
context: rootContext,
|
|
337
|
+
attributes: { rawData: rawData.substring(0, 500) }
|
|
338
|
+
});
|
|
339
|
+
provider.setGlobalContext(rootSpan.spanContext);
|
|
222
340
|
try {
|
|
223
341
|
let rawEvent;
|
|
224
342
|
try {
|
|
@@ -246,6 +364,11 @@ class LarkCliInstance {
|
|
|
246
364
|
recommendedAction
|
|
247
365
|
});
|
|
248
366
|
const timestamp = Date.now();
|
|
367
|
+
const plugins = this.config.handleRule?.plugins || [];
|
|
368
|
+
const pluginEnabled = {};
|
|
369
|
+
for (const pluginName of plugins) {
|
|
370
|
+
pluginEnabled[`${this.config.id}:${pluginName}`] = true;
|
|
371
|
+
}
|
|
249
372
|
const evt = {
|
|
250
373
|
id: `es-${this.config.id}-${timestamp}`,
|
|
251
374
|
type: "event-source.event.lark-cli",
|
|
@@ -253,7 +376,10 @@ class LarkCliInstance {
|
|
|
253
376
|
metadata: {
|
|
254
377
|
source: "event-source",
|
|
255
378
|
sourceId: this.config.id,
|
|
256
|
-
sourceMessageType: eventType
|
|
379
|
+
sourceMessageType: eventType,
|
|
380
|
+
plugins,
|
|
381
|
+
pluginEnabled,
|
|
382
|
+
replyChannel
|
|
257
383
|
},
|
|
258
384
|
payload: {
|
|
259
385
|
sourceId: this.config.id,
|
|
@@ -266,10 +392,114 @@ class LarkCliInstance {
|
|
|
266
392
|
timestamp
|
|
267
393
|
}
|
|
268
394
|
};
|
|
269
|
-
this.
|
|
395
|
+
const userId = this.extractUserId(rawEvent);
|
|
396
|
+
const envReplyChannel = this.buildReplyChannel(replyChannel);
|
|
397
|
+
const envContext = createEnvContext({
|
|
398
|
+
envEvent: evt,
|
|
399
|
+
sourceId: this.config.id,
|
|
400
|
+
userId,
|
|
401
|
+
replyChannel: envReplyChannel,
|
|
402
|
+
pluginEnabled,
|
|
403
|
+
plugins
|
|
404
|
+
});
|
|
405
|
+
runWithEnvContext(envContext, () => {
|
|
406
|
+
this.eventHandler?.(evt);
|
|
407
|
+
});
|
|
270
408
|
} catch (error) {
|
|
271
409
|
console.error(`[LarkCliInstance] Error handling event: ${error}`);
|
|
410
|
+
rootSpan.setAttribute("error", String(error));
|
|
411
|
+
} finally {
|
|
412
|
+
rootSpan.end();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
extractUserId(rawEvent) {
|
|
416
|
+
const event = rawEvent;
|
|
417
|
+
const innerEvent = event.event;
|
|
418
|
+
const message = innerEvent?.message || event.message;
|
|
419
|
+
const sender = innerEvent?.sender || event.sender || message?.sender;
|
|
420
|
+
const senderId = sender?.sender_id;
|
|
421
|
+
return senderId?.open_id || senderId?.user_id || senderId?.union_id || "unknown";
|
|
422
|
+
}
|
|
423
|
+
buildReplyChannel(replyChannel) {
|
|
424
|
+
if (!replyChannel || !replyChannel.chatId && !replyChannel.messageId) {
|
|
425
|
+
return;
|
|
272
426
|
}
|
|
427
|
+
return {
|
|
428
|
+
type: replyChannel.type,
|
|
429
|
+
messageId: replyChannel.messageId,
|
|
430
|
+
chatId: replyChannel.chatId,
|
|
431
|
+
userId: replyChannel.params?.userId,
|
|
432
|
+
identity: "bot",
|
|
433
|
+
sendText: async (text) => {
|
|
434
|
+
await this.sendLarkMessage({
|
|
435
|
+
chatId: replyChannel.chatId,
|
|
436
|
+
userId: replyChannel.params?.userId,
|
|
437
|
+
content: text,
|
|
438
|
+
as: "bot"
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
sendMarkdown: async (markdown) => {
|
|
442
|
+
await this.sendLarkMessage({
|
|
443
|
+
chatId: replyChannel.chatId,
|
|
444
|
+
userId: replyChannel.params?.userId,
|
|
445
|
+
content: markdown,
|
|
446
|
+
as: "bot"
|
|
447
|
+
});
|
|
448
|
+
},
|
|
449
|
+
sendMessage: async (content) => {
|
|
450
|
+
await this.sendLarkMessage({
|
|
451
|
+
chatId: replyChannel.chatId,
|
|
452
|
+
userId: replyChannel.params?.userId,
|
|
453
|
+
content: JSON.stringify(content),
|
|
454
|
+
as: "bot"
|
|
455
|
+
});
|
|
456
|
+
},
|
|
457
|
+
reply: async (content) => {
|
|
458
|
+
if (replyChannel.messageId) {
|
|
459
|
+
await this.sendLarkMessage({
|
|
460
|
+
messageId: replyChannel.messageId,
|
|
461
|
+
content: JSON.stringify(content),
|
|
462
|
+
as: "bot"
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
async sendLarkMessage(options) {
|
|
469
|
+
return new Promise((resolve, reject) => {
|
|
470
|
+
const { chatId, userId, messageId, content, as: identity } = options;
|
|
471
|
+
const args = ["im", "+messages-send", "--as", identity];
|
|
472
|
+
if (messageId) {
|
|
473
|
+
args.push("+messages-reply", "--message-id", messageId, "--text", content);
|
|
474
|
+
} else if (chatId) {
|
|
475
|
+
args.push("--chat-id", chatId, "--text", content);
|
|
476
|
+
} else if (userId) {
|
|
477
|
+
args.push("--user-id", userId, "--text", content);
|
|
478
|
+
} else {
|
|
479
|
+
reject(new Error("No target specified for sending message"));
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const proc = spawn("lark-cli", args, {
|
|
483
|
+
shell: false,
|
|
484
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
485
|
+
});
|
|
486
|
+
let stdout = "";
|
|
487
|
+
let stderr = "";
|
|
488
|
+
proc.stdout?.on("data", (data) => {
|
|
489
|
+
stdout += data.toString();
|
|
490
|
+
});
|
|
491
|
+
proc.stderr?.on("data", (data) => {
|
|
492
|
+
stderr += data.toString();
|
|
493
|
+
});
|
|
494
|
+
proc.on("close", (code) => {
|
|
495
|
+
if (code === 0) {
|
|
496
|
+
resolve();
|
|
497
|
+
} else {
|
|
498
|
+
reject(new Error(`lark-cli exited with code ${code}: ${stderr}`));
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
proc.on("error", reject);
|
|
502
|
+
});
|
|
273
503
|
}
|
|
274
504
|
}
|
|
275
505
|
var larkCliHandler = {
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
7
7
|
import {
|
|
8
8
|
BaseComponent
|
|
9
|
-
} from "./roy-agent-core-
|
|
9
|
+
} from "./roy-agent-core-4jqq077c.js";
|
|
10
10
|
import {
|
|
11
11
|
createLogger,
|
|
12
12
|
init_logger
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
14
14
|
|
|
15
15
|
// src/env/skill/skill-component.ts
|
|
16
16
|
init_logger();
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
getMaxOutput,
|
|
4
4
|
init_logger,
|
|
5
5
|
simplifyFilePath
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
7
7
|
import {
|
|
8
8
|
getTracerProvider,
|
|
9
9
|
init_tracer_provider
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-58k274fg.js";
|
|
11
11
|
import {
|
|
12
12
|
__esm
|
|
13
13
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -135,30 +135,38 @@ function wrapFunction(fn, name, options) {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
const callerLocation = getCallerLocation();
|
|
138
|
-
logFn("enter", args, callerLocation);
|
|
139
138
|
const span = tracer.startSpan(name, { attributes });
|
|
139
|
+
logFn("enter", args, callerLocation);
|
|
140
140
|
try {
|
|
141
141
|
const result = fn.call(this, ...args);
|
|
142
142
|
if (result && typeof result === "object" && typeof result.then === "function") {
|
|
143
143
|
return result.then((resolved) => {
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
if (span) {
|
|
145
|
+
span.setAttribute("result", JSON.stringify(truncate(resolved)));
|
|
146
|
+
span.end(resolved);
|
|
147
|
+
}
|
|
146
148
|
logFn("quit", options?.recordResult ? resolved : undefined, callerLocation);
|
|
147
149
|
return resolved;
|
|
148
150
|
}, (rejected) => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
if (span) {
|
|
152
|
+
span.setAttribute("error", String(rejected));
|
|
153
|
+
span.end(undefined, rejected instanceof Error ? rejected : new Error(String(rejected)));
|
|
154
|
+
}
|
|
151
155
|
logFn("error", rejected.message, callerLocation);
|
|
152
156
|
throw rejected;
|
|
153
157
|
});
|
|
154
158
|
}
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
if (span) {
|
|
160
|
+
span.setAttribute("result", JSON.stringify(truncate(result)));
|
|
161
|
+
span.end(result);
|
|
162
|
+
}
|
|
157
163
|
logFn("quit", options?.recordResult ? result : undefined, callerLocation);
|
|
158
164
|
return result;
|
|
159
165
|
} catch (error) {
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
if (span) {
|
|
167
|
+
span.setAttribute("error", String(error));
|
|
168
|
+
span.end(undefined, error instanceof Error ? error : new Error(String(error)));
|
|
169
|
+
}
|
|
162
170
|
logFn("error", error.message, callerLocation);
|
|
163
171
|
throw error;
|
|
164
172
|
}
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
getTracerProvider,
|
|
4
4
|
init_tracer_provider,
|
|
5
5
|
resetTracerProvider
|
|
6
|
-
} from "./roy-agent-core-
|
|
7
|
-
import"./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-58k274fg.js";
|
|
7
|
+
import"./roy-agent-core-c6592r3c.js";
|
|
8
8
|
import"./roy-agent-core-fs0mn2jk.js";
|
|
9
9
|
init_tracer_provider();
|
|
10
10
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WorkflowRepository,
|
|
3
|
+
rowToWorkflow
|
|
4
|
+
} from "./roy-agent-core-8n4bz6y3.js";
|
|
5
|
+
import"./roy-agent-core-9ffsvvcf.js";
|
|
6
|
+
import"./roy-agent-core-rvxg1wps.js";
|
|
7
|
+
import"./roy-agent-core-10n2jh7p.js";
|
|
8
|
+
import"./roy-agent-core-58k274fg.js";
|
|
9
|
+
import"./roy-agent-core-c6592r3c.js";
|
|
10
|
+
import"./roy-agent-core-fs0mn2jk.js";
|
|
11
|
+
export {
|
|
12
|
+
rowToWorkflow,
|
|
13
|
+
WorkflowRepository
|
|
14
|
+
};
|