@ai-setting/roy-agent-core 1.7.61 → 1.7.62
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 +8 -8
- package/dist/env/agent/agent-component.js +41 -0
- package/dist/env/agent/index.js +18 -16
- package/dist/env/commands/index.js +8 -8
- package/dist/env/context/index.js +4 -4
- package/dist/env/debug/index.js +8 -8
- package/dist/env/error-reply.js +18 -0
- package/dist/env/event-source/cli-command-handler.js +17 -0
- package/dist/env/event-source/event-source-handlers.js +58 -0
- package/dist/env/event-source/event-store.js +18 -0
- package/dist/env/event-source/idempotency-key.js +20 -0
- package/dist/env/event-source/index.js +30 -25
- package/dist/env/hook/index.js +6 -6
- package/dist/env/index.js +52 -46
- package/dist/env/lark-mention-utils.js +9 -0
- package/dist/env/llm/index.js +9 -9
- package/dist/env/log-trace/index.js +8 -8
- package/dist/env/log-trace/logger.js +39 -0
- package/dist/env/mcp/index.js +9 -9
- package/dist/env/mcp/tool/index.js +2 -2
- package/dist/env/memory/index.js +9 -9
- package/dist/env/memory/plugin/index.js +2 -2
- package/dist/env/plugin/index.js +9 -9
- package/dist/env/prompt/index.js +8 -8
- package/dist/env/session/index.js +11 -11
- package/dist/env/session/storage/index.js +5 -5
- package/dist/env/skill/index.js +8 -8
- package/dist/env/task/delegate/delegate-tool.js +42 -0
- package/dist/env/task/delegate/index.js +13 -11
- package/dist/env/task/index.js +16 -15
- package/dist/env/task/mcp/index.js +4 -4
- package/dist/env/task/plugins/index.js +11 -11
- package/dist/env/task/plugins/lark-card-patch-notifier.js +42 -0
- package/dist/env/task/storage/index.js +4 -4
- package/dist/env/task/tools/index.js +4 -4
- package/dist/env/tool/built-in/index.js +4 -4
- package/dist/env/tool/index.js +12 -11
- package/dist/env/tool/types.js +1 -0
- package/dist/env/workflow/engine/index.js +13 -13
- package/dist/env/workflow/hooks/index.js +8 -8
- package/dist/env/workflow/index.js +23 -23
- package/dist/env/workflow/nodes/index.js +3 -3
- package/dist/env/workflow/plugins/index.js +9 -9
- package/dist/env/workflow/service/index.js +3 -3
- package/dist/env/workflow/storage/index.js +4 -4
- package/dist/env/workflow/tools/index.js +15 -15
- package/dist/env/workflow/utils/index.js +5 -5
- package/dist/index.js +70 -62
- package/dist/shared/@ai-setting/{roy-agent-core-dythsgkn.js → roy-agent-core-06jakebr.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-jsn21cb9.js → roy-agent-core-084zthqx.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-x1m0gs0q.js → roy-agent-core-2hkyp51n.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-q212q0w1.js → roy-agent-core-2pma868e.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-vmfk4m1v.js → roy-agent-core-2veqhrxa.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-mw0bc9g6.js → roy-agent-core-32ck9rqt.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-bdzdw1g3.js → roy-agent-core-33hn1beg.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-2qkrpc7m.js → roy-agent-core-386wa4wy.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rnzm0tpf.js → roy-agent-core-48h4zh60.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-yr5eqyhz.js → roy-agent-core-5bj0xfjk.js} +13 -27
- package/dist/shared/@ai-setting/{roy-agent-core-khc23qs1.js → roy-agent-core-5mrynf9g.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-y0k9kaxz.js → roy-agent-core-6awgfh3x.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ygfjgk9b.js → roy-agent-core-6wxww10t.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-xc0es9zc.js → roy-agent-core-79gyka2q.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-expvav8a.js → roy-agent-core-7tce05jt.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-9nvyffxg.js +414 -0
- package/dist/shared/@ai-setting/{roy-agent-core-m2tv4pj0.js → roy-agent-core-9qgrc9dy.js} +158 -158
- package/dist/shared/@ai-setting/{roy-agent-core-z51jktet.js → roy-agent-core-a08dpf71.js} +17 -2
- package/dist/shared/@ai-setting/{roy-agent-core-22r4zmkw.js → roy-agent-core-a6cz4d23.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-0f989bnp.js → roy-agent-core-anb53t3v.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-ymcvsdzn.js → roy-agent-core-as0dd70m.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-nd5171pv.js → roy-agent-core-bpvz1dqr.js} +8 -8
- package/dist/shared/@ai-setting/{roy-agent-core-aa514zm8.js → roy-agent-core-c4t4y18j.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-sf9tsj0g.js → roy-agent-core-c57278kx.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-e6k448ka.js → roy-agent-core-c8xvy6hj.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-gtb4fj8j.js → roy-agent-core-cqpd41gf.js} +12 -10
- package/dist/shared/@ai-setting/{roy-agent-core-qgapy83x.js → roy-agent-core-cxpgd415.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-g44nbgtt.js → roy-agent-core-dfqhc9ey.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-cndvj1hv.js → roy-agent-core-fqandv0a.js} +9 -107
- package/dist/shared/@ai-setting/{roy-agent-core-4m5spt7m.js → roy-agent-core-fr296a53.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-3p59ap0x.js → roy-agent-core-gc6wcd7z.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-s7w47mnn.js → roy-agent-core-gjsvehfs.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9s3payp1.js → roy-agent-core-gtdtzbs7.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-jrksyqb6.js → roy-agent-core-gz2jnaan.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-6cyjps72.js → roy-agent-core-h3fwjbhp.js} +14 -14
- package/dist/shared/@ai-setting/{roy-agent-core-mhppywse.js → roy-agent-core-hczj1ryh.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-qrjs2500.js → roy-agent-core-hfyxv2kx.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-dg286rpd.js → roy-agent-core-hwkc0bg2.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-bc3v8pw4.js → roy-agent-core-ja4sr63d.js} +6 -6
- package/dist/shared/@ai-setting/roy-agent-core-jagkferh.js +16 -0
- package/dist/shared/@ai-setting/roy-agent-core-jm136jzh.js +99 -0
- package/dist/shared/@ai-setting/{roy-agent-core-g5sw19fa.js → roy-agent-core-jw63js86.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-8fy467qs.js → roy-agent-core-kmvw6b4v.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-3bpntd80.js → roy-agent-core-kvq4a4p6.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-yd85623y.js → roy-agent-core-m3w3ytxt.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-64f22h1g.js → roy-agent-core-m880qz3y.js} +7 -1
- package/dist/shared/@ai-setting/{roy-agent-core-5knpegzr.js → roy-agent-core-mbwaxqs0.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-tn96n4wz.js → roy-agent-core-mkpsz128.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-9k8ms63r.js → roy-agent-core-mrrv80jy.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ytnedzks.js → roy-agent-core-nmn853z0.js} +333 -1332
- package/dist/shared/@ai-setting/roy-agent-core-p37kh0kt.js +155 -0
- package/dist/shared/@ai-setting/{roy-agent-core-60p2380d.js → roy-agent-core-p6a4v4fq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-hf0t8agb.js → roy-agent-core-p8rf4z89.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-pnj0zh25.js +0 -0
- package/dist/shared/@ai-setting/{roy-agent-core-dp1hp24k.js → roy-agent-core-prnry2mw.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-qw5fpa24.js → roy-agent-core-qmqe8ds3.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-j0x9yf96.js → roy-agent-core-sj4y3wdm.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-xeqp659x.js → roy-agent-core-th92f833.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-ajmgyawx.js → roy-agent-core-v7mwj8eq.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-5565cvw8.js → roy-agent-core-vvb4cyyy.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-qpqqx1wd.js → roy-agent-core-vwzan9v0.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-pj5tfmn5.js → roy-agent-core-w2ev3z5q.js} +12 -14
- package/dist/shared/@ai-setting/roy-agent-core-w2h6xt6k.js +473 -0
- package/dist/shared/@ai-setting/{roy-agent-core-kfmrfaft.js → roy-agent-core-wzp4tbsn.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-jsdqzfbj.js → roy-agent-core-x1d6edkh.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-n1ck0x1r.js → roy-agent-core-ye4bfzqg.js} +11 -11
- package/dist/shared/@ai-setting/{roy-agent-core-p2dpcyrz.js → roy-agent-core-zjgckbdd.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-a5nh5q6v.js → roy-agent-core-zy8vkbnk.js} +1 -1
- package/dist/test-utils/child-process-mock.js +23 -0
- package/dist/utils/temp-file-manager/index.js +2 -2
- package/package.json +61 -1
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import {
|
|
2
|
+
builtInHandlers
|
|
3
|
+
} from "./roy-agent-core-nmn853z0.js";
|
|
4
|
+
import {
|
|
5
|
+
envKeyToConfigKey
|
|
6
|
+
} from "./roy-agent-core-7hh0brvs.js";
|
|
7
|
+
import {
|
|
8
|
+
BaseComponent
|
|
9
|
+
} from "./roy-agent-core-gtdtzbs7.js";
|
|
10
|
+
import {
|
|
11
|
+
TracedAs,
|
|
12
|
+
init_decorator
|
|
13
|
+
} from "./roy-agent-core-386wa4wy.js";
|
|
14
|
+
import {
|
|
15
|
+
createLogger,
|
|
16
|
+
init_logger
|
|
17
|
+
} from "./roy-agent-core-6awgfh3x.js";
|
|
18
|
+
import {
|
|
19
|
+
__legacyDecorateClassTS,
|
|
20
|
+
__require
|
|
21
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
22
|
+
|
|
23
|
+
// src/env/event-source/event-source-component.ts
|
|
24
|
+
import { join } from "path";
|
|
25
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
26
|
+
init_logger();
|
|
27
|
+
init_decorator();
|
|
28
|
+
|
|
29
|
+
// src/env/event-source/event-source-config-registration.ts
|
|
30
|
+
var EVENT_SOURCE_DEFAULTS = {
|
|
31
|
+
"event-source.enabled": true,
|
|
32
|
+
"event-source.persistenceEnabled": true
|
|
33
|
+
};
|
|
34
|
+
var EVENT_SOURCE_CONFIG_REGISTRATION = {
|
|
35
|
+
name: "event-source",
|
|
36
|
+
sources: [
|
|
37
|
+
{ type: "env", envPrefix: "EVENT_SOURCE", priority: 20, watch: false }
|
|
38
|
+
],
|
|
39
|
+
keys: [
|
|
40
|
+
{ key: "event-source.enabled", sources: ["env", "file"] },
|
|
41
|
+
{ key: "event-source.persistenceEnabled", sources: ["env", "file"] },
|
|
42
|
+
{ key: "event-source.configPath", sources: ["env", "file"] }
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/env/event-source/event-source-component.ts
|
|
47
|
+
var logger = createLogger("event-source");
|
|
48
|
+
|
|
49
|
+
class EventSourceComponent extends BaseComponent {
|
|
50
|
+
name = "event-source";
|
|
51
|
+
version = "1.0.0";
|
|
52
|
+
sources = new Map;
|
|
53
|
+
statuses = new Map;
|
|
54
|
+
handlers = new Map;
|
|
55
|
+
instances = new Map;
|
|
56
|
+
eventHandlers = new Map;
|
|
57
|
+
buffers = new Map;
|
|
58
|
+
configPath = "";
|
|
59
|
+
persistenceEnabled = true;
|
|
60
|
+
configComponent;
|
|
61
|
+
configWatcher;
|
|
62
|
+
async onInit() {
|
|
63
|
+
await this.executeInitHooks();
|
|
64
|
+
await this.loadConfig();
|
|
65
|
+
}
|
|
66
|
+
async init(options) {
|
|
67
|
+
if (options?.env) {
|
|
68
|
+
this.env = options.env;
|
|
69
|
+
}
|
|
70
|
+
this.setStatus("initializing");
|
|
71
|
+
if (options?.name)
|
|
72
|
+
Object.defineProperty(this, "name", { value: options.name, writable: false });
|
|
73
|
+
if (options?.version)
|
|
74
|
+
Object.defineProperty(this, "version", { value: options.version, writable: false });
|
|
75
|
+
if (options?.enabled !== undefined)
|
|
76
|
+
this._enabled = options.enabled;
|
|
77
|
+
const opts = options?.options;
|
|
78
|
+
if (opts?.configComponent) {
|
|
79
|
+
this.configComponent = opts.configComponent;
|
|
80
|
+
await this.registerConfig(opts);
|
|
81
|
+
if (opts.registerBuiltInHandlers !== false) {
|
|
82
|
+
this.registerBuiltInHandlers();
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error("ConfigComponent is required for EventSourceComponent initialization");
|
|
86
|
+
}
|
|
87
|
+
await this.onInit();
|
|
88
|
+
this.setStatus("running");
|
|
89
|
+
}
|
|
90
|
+
async onStart() {}
|
|
91
|
+
async onStop() {
|
|
92
|
+
this.configWatcher?.();
|
|
93
|
+
this.configWatcher = undefined;
|
|
94
|
+
const runningSources = Array.from(this.statuses.entries()).filter(([_, status]) => status === "running").map(([id]) => id);
|
|
95
|
+
for (const id of runningSources) {
|
|
96
|
+
await this.stopSource(id);
|
|
97
|
+
}
|
|
98
|
+
this.sources.clear();
|
|
99
|
+
this.statuses.clear();
|
|
100
|
+
this.instances.clear();
|
|
101
|
+
this.eventHandlers.clear();
|
|
102
|
+
this.handlers.clear();
|
|
103
|
+
this.buffers.clear();
|
|
104
|
+
}
|
|
105
|
+
createDefaultEventHandler(sourceId, sourceType) {
|
|
106
|
+
return (event) => {
|
|
107
|
+
this.getEnv()?.pushEnvEvent(event);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
registerBuiltInHandlers() {
|
|
111
|
+
for (const handler of builtInHandlers) {
|
|
112
|
+
if (!this.handlers.has(handler.type)) {
|
|
113
|
+
this.handlers.set(handler.type, handler);
|
|
114
|
+
logger.debug(`Registered built-in handler: ${handler.type}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async executeInitHooks() {
|
|
119
|
+
const { EventSourceInitHooks } = await import("./roy-agent-core-99nwgj84.js");
|
|
120
|
+
await EventSourceInitHooks.execute(this);
|
|
121
|
+
}
|
|
122
|
+
registerHandler(handler) {
|
|
123
|
+
if (this.handlers.has(handler.type)) {
|
|
124
|
+
logger.warn(`Handler already registered for type: ${handler.type}, overwriting`);
|
|
125
|
+
}
|
|
126
|
+
this.handlers.set(handler.type, handler);
|
|
127
|
+
logger.debug(`Handler registered: ${handler.type}`);
|
|
128
|
+
}
|
|
129
|
+
unregisterHandler(type) {
|
|
130
|
+
const deleted = this.handlers.delete(type);
|
|
131
|
+
if (deleted) {
|
|
132
|
+
logger.debug(`Handler unregistered: ${type}`);
|
|
133
|
+
}
|
|
134
|
+
return deleted;
|
|
135
|
+
}
|
|
136
|
+
getHandler(type) {
|
|
137
|
+
return this.handlers.get(type);
|
|
138
|
+
}
|
|
139
|
+
listHandlers() {
|
|
140
|
+
return Array.from(this.handlers.values());
|
|
141
|
+
}
|
|
142
|
+
async registerConfig(options) {
|
|
143
|
+
const configComponent = options.configComponent;
|
|
144
|
+
if (!configComponent)
|
|
145
|
+
return;
|
|
146
|
+
const { configPath, config } = options;
|
|
147
|
+
const envPrefix = "EVENT_SOURCE";
|
|
148
|
+
configComponent.registerComponent(EVENT_SOURCE_CONFIG_REGISTRATION);
|
|
149
|
+
if (configPath) {
|
|
150
|
+
configComponent.registerSource({
|
|
151
|
+
type: "file",
|
|
152
|
+
relativePath: configPath,
|
|
153
|
+
optional: true,
|
|
154
|
+
watch: false
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
configComponent.registerSource({
|
|
158
|
+
type: "env",
|
|
159
|
+
envPrefix,
|
|
160
|
+
priority: 20,
|
|
161
|
+
watch: false
|
|
162
|
+
});
|
|
163
|
+
await configComponent.load("event-source");
|
|
164
|
+
for (const envKey of Object.keys(process.env)) {
|
|
165
|
+
const configKey = envKeyToConfigKey(envKey, envPrefix, "event-source");
|
|
166
|
+
if (!configKey)
|
|
167
|
+
continue;
|
|
168
|
+
const value = process.env[envKey];
|
|
169
|
+
if (value !== undefined) {
|
|
170
|
+
await configComponent.set(configKey, value);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const [key, value] of Object.entries(EVENT_SOURCE_DEFAULTS)) {
|
|
174
|
+
if (configComponent.get(key) === undefined) {
|
|
175
|
+
await configComponent.set(key, value);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (configComponent.get("event-source.configPath") === undefined) {
|
|
179
|
+
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
180
|
+
const dataDir = join(home, ".roy-agent");
|
|
181
|
+
await configComponent.set("event-source.configPath", join(dataDir, "event-sources.json"));
|
|
182
|
+
}
|
|
183
|
+
if (config) {
|
|
184
|
+
const flatConfig = this.flattenConfig(config);
|
|
185
|
+
for (const [key, value] of Object.entries(flatConfig)) {
|
|
186
|
+
await configComponent.set(key, value);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
this.registerConfigWatcher(configComponent);
|
|
190
|
+
}
|
|
191
|
+
buildConfig() {
|
|
192
|
+
const configComponent = this.configComponent;
|
|
193
|
+
if (!configComponent) {
|
|
194
|
+
return { enabled: true, persistenceEnabled: true, configPath: "" };
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
enabled: configComponent.get("event-source.enabled") ?? true,
|
|
198
|
+
persistenceEnabled: configComponent.get("event-source.persistenceEnabled") ?? true,
|
|
199
|
+
configPath: configComponent.get("event-source.configPath") ?? ""
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
flattenConfig(obj, prefix = "event-source") {
|
|
203
|
+
const result = {};
|
|
204
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
205
|
+
const fullKey = `${prefix}.${key}`;
|
|
206
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
207
|
+
Object.assign(result, this.flattenConfig(value, fullKey));
|
|
208
|
+
} else {
|
|
209
|
+
result[fullKey] = value;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
registerConfigWatcher(configComponent) {
|
|
215
|
+
if (typeof configComponent.watch !== "function")
|
|
216
|
+
return;
|
|
217
|
+
this.configWatcher = configComponent.watch("event-source.*", (event) => {
|
|
218
|
+
this.onConfigChange(event);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
onConfigChange(event) {
|
|
222
|
+
logger.info(`EventSource config changed: ${event.key}`, {
|
|
223
|
+
oldValue: event.oldValue,
|
|
224
|
+
newValue: event.newValue
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
register(config) {
|
|
228
|
+
if (this.sources.has(config.id)) {
|
|
229
|
+
throw new Error(`EventSource already exists: ${config.id}`);
|
|
230
|
+
}
|
|
231
|
+
const handler = this.handlers.get(config.type);
|
|
232
|
+
if (!handler) {
|
|
233
|
+
throw new Error(`No handler registered for event source type: ${config.type}`);
|
|
234
|
+
}
|
|
235
|
+
const errors = handler.validateConfig(config);
|
|
236
|
+
if (errors.length > 0) {
|
|
237
|
+
throw new Error(`Invalid config: ${errors.join(", ")}`);
|
|
238
|
+
}
|
|
239
|
+
this.sources.set(config.id, config);
|
|
240
|
+
this.statuses.set(config.id, "created");
|
|
241
|
+
logger.debug(`EventSource registered: ${config.id} (${config.type})`);
|
|
242
|
+
this.saveConfig().catch((err) => {
|
|
243
|
+
logger.error(`Failed to save config after registering ${config.id}:`, err);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
unregister(id) {
|
|
247
|
+
const status = this.statuses.get(id);
|
|
248
|
+
if (status === "running") {
|
|
249
|
+
this.stopSource(id);
|
|
250
|
+
}
|
|
251
|
+
const existed = this.sources.has(id);
|
|
252
|
+
this.sources.delete(id);
|
|
253
|
+
this.statuses.delete(id);
|
|
254
|
+
this.instances.delete(id);
|
|
255
|
+
this.eventHandlers.delete(id);
|
|
256
|
+
this.buffers.delete(id);
|
|
257
|
+
if (existed) {
|
|
258
|
+
logger.debug(`EventSource unregistered: ${id}`);
|
|
259
|
+
this.saveConfig().catch((err) => {
|
|
260
|
+
logger.error(`Failed to save config after unregistering ${id}:`, err);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
return existed;
|
|
264
|
+
}
|
|
265
|
+
async update(id, partial) {
|
|
266
|
+
if (!partial || Object.keys(partial).length === 0) {
|
|
267
|
+
throw new Error("update() partial must not be empty");
|
|
268
|
+
}
|
|
269
|
+
const existing = this.sources.get(id);
|
|
270
|
+
if (!existing) {
|
|
271
|
+
throw new Error(`EventSource not found: ${id}`);
|
|
272
|
+
}
|
|
273
|
+
if (Object.prototype.hasOwnProperty.call(partial, "type")) {
|
|
274
|
+
if (partial.type !== existing.type) {
|
|
275
|
+
throw new Error(`Cannot update event source type: ${existing.type} -> ${partial.type} (use unregister + register instead)`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const wasRunning = this.statuses.get(id) === "running";
|
|
279
|
+
let stopped = false;
|
|
280
|
+
if (wasRunning) {
|
|
281
|
+
await this.stopSource(id);
|
|
282
|
+
stopped = true;
|
|
283
|
+
}
|
|
284
|
+
const updated = {
|
|
285
|
+
...existing,
|
|
286
|
+
...partial,
|
|
287
|
+
id: existing.id,
|
|
288
|
+
type: existing.type
|
|
289
|
+
};
|
|
290
|
+
const handler = this.handlers.get(existing.type);
|
|
291
|
+
if (handler) {
|
|
292
|
+
const errors = handler.validateConfig(updated);
|
|
293
|
+
if (errors.length > 0) {
|
|
294
|
+
throw new Error(`Invalid config after update: ${errors.join(", ")}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
this.sources.set(id, updated);
|
|
298
|
+
logger.info(`EventSource updated: ${id}`, {
|
|
299
|
+
fields: Object.keys(partial)
|
|
300
|
+
});
|
|
301
|
+
try {
|
|
302
|
+
await this.saveConfig();
|
|
303
|
+
} catch (err) {
|
|
304
|
+
logger.error(`Failed to save config after updating ${id}:`, err);
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
id,
|
|
309
|
+
updated,
|
|
310
|
+
wasRunning,
|
|
311
|
+
stopped,
|
|
312
|
+
restarted: false,
|
|
313
|
+
fields: Object.keys(partial)
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
get(id) {
|
|
317
|
+
return this.sources.get(id);
|
|
318
|
+
}
|
|
319
|
+
list() {
|
|
320
|
+
return Array.from(this.sources.values());
|
|
321
|
+
}
|
|
322
|
+
getStatus(id) {
|
|
323
|
+
if (id === undefined) {
|
|
324
|
+
return this._status;
|
|
325
|
+
}
|
|
326
|
+
return this.statuses.get(id);
|
|
327
|
+
}
|
|
328
|
+
getEventSourceStatus(id) {
|
|
329
|
+
return this.getStatus(id);
|
|
330
|
+
}
|
|
331
|
+
onEvent(id, handler) {
|
|
332
|
+
this.eventHandlers.set(id, handler);
|
|
333
|
+
const instance = this.instances.get(id);
|
|
334
|
+
if (instance) {
|
|
335
|
+
instance.onEvent(handler);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
offEvent(id) {
|
|
339
|
+
this.eventHandlers.delete(id);
|
|
340
|
+
const instance = this.instances.get(id);
|
|
341
|
+
if (instance) {
|
|
342
|
+
instance.offEvent();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async startSource(id) {
|
|
346
|
+
const config = this.sources.get(id);
|
|
347
|
+
if (!config) {
|
|
348
|
+
throw new Error(`EventSource not found: ${id}`);
|
|
349
|
+
}
|
|
350
|
+
const currentStatus = this.statuses.get(id);
|
|
351
|
+
if (currentStatus === "running") {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
this.statuses.set(id, "starting");
|
|
355
|
+
try {
|
|
356
|
+
const handler = this.handlers.get(config.type);
|
|
357
|
+
if (!handler) {
|
|
358
|
+
throw new Error(`No handler registered for event source type: ${config.type}`);
|
|
359
|
+
}
|
|
360
|
+
const instance = handler.createInstance(config);
|
|
361
|
+
this.instances.set(id, instance);
|
|
362
|
+
if (typeof instance.setEnvironment === "function") {
|
|
363
|
+
instance.setEnvironment(this.getEnv());
|
|
364
|
+
}
|
|
365
|
+
const eventHandler = this.eventHandlers.get(id) ?? this.createDefaultEventHandler(id, config.type);
|
|
366
|
+
instance.onEvent(eventHandler);
|
|
367
|
+
await instance.start();
|
|
368
|
+
this.statuses.set(id, "running");
|
|
369
|
+
this.getEnv()?.pushEnvEvent({
|
|
370
|
+
type: "event-source.started",
|
|
371
|
+
payload: { sourceId: id, sourceType: config.type }
|
|
372
|
+
});
|
|
373
|
+
logger.info(`EventSource started: ${id} (${config.type})`);
|
|
374
|
+
} catch (error) {
|
|
375
|
+
this.statuses.set(id, "error");
|
|
376
|
+
logger.error(`EventSource failed to start: ${id}`, error);
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async stopSource(id) {
|
|
381
|
+
const status = this.statuses.get(id);
|
|
382
|
+
logger.info(`[EventSource ${id}] stopSource called, current status: ${status}`);
|
|
383
|
+
if (status === "stopped" || status === "created") {
|
|
384
|
+
logger.info(`[EventSource ${id}] already stopped/created, skipping`);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
this.statuses.set(id, "stopping");
|
|
388
|
+
try {
|
|
389
|
+
const instance = this.instances.get(id);
|
|
390
|
+
if (instance) {
|
|
391
|
+
await instance.stop();
|
|
392
|
+
this.instances.delete(id);
|
|
393
|
+
}
|
|
394
|
+
const config = this.sources.get(id);
|
|
395
|
+
this.statuses.set(id, "stopped");
|
|
396
|
+
this.getEnv()?.pushEnvEvent({
|
|
397
|
+
type: "event-source.stopped",
|
|
398
|
+
payload: { sourceId: id, sourceType: config?.type }
|
|
399
|
+
});
|
|
400
|
+
logger.info(`EventSource stopped: ${id}`);
|
|
401
|
+
} catch (error) {
|
|
402
|
+
this.statuses.set(id, "error");
|
|
403
|
+
logger.error(`EventSource failed to stop: ${id}`, error);
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
getConfigFilePath() {
|
|
408
|
+
if (this.configPath) {
|
|
409
|
+
return this.configPath;
|
|
410
|
+
}
|
|
411
|
+
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
412
|
+
const dataDir = join(home, ".roy-agent");
|
|
413
|
+
if (!existsSync(dataDir)) {
|
|
414
|
+
mkdirSync(dataDir, { recursive: true });
|
|
415
|
+
}
|
|
416
|
+
return join(dataDir, "event-sources.json");
|
|
417
|
+
}
|
|
418
|
+
async saveConfig() {
|
|
419
|
+
if (!this.persistenceEnabled)
|
|
420
|
+
return;
|
|
421
|
+
try {
|
|
422
|
+
const configPath = this.getConfigFilePath();
|
|
423
|
+
const config = {
|
|
424
|
+
version: "1.0.0",
|
|
425
|
+
sources: Array.from(this.sources.values())
|
|
426
|
+
};
|
|
427
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
428
|
+
logger.debug(`Saved ${this.sources.size} event source configurations`);
|
|
429
|
+
} catch (error) {
|
|
430
|
+
logger.error("Failed to save event source configurations:", error);
|
|
431
|
+
throw error;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async loadConfig() {
|
|
435
|
+
if (!this.persistenceEnabled)
|
|
436
|
+
return;
|
|
437
|
+
try {
|
|
438
|
+
const configPath = this.getConfigFilePath();
|
|
439
|
+
if (!existsSync(configPath)) {
|
|
440
|
+
logger.debug(`No event source config file found at ${configPath}`);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
const content = readFileSync(configPath, "utf-8");
|
|
444
|
+
const config = JSON.parse(content);
|
|
445
|
+
if (!config.sources || !Array.isArray(config.sources)) {
|
|
446
|
+
logger.warn("Invalid event source config format, skipping load");
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
let loadedCount = 0;
|
|
450
|
+
for (const source of config.sources) {
|
|
451
|
+
if (!this.sources.has(source.id)) {
|
|
452
|
+
this.sources.set(source.id, source);
|
|
453
|
+
this.statuses.set(source.id, "created");
|
|
454
|
+
loadedCount++;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
logger.info(`Loaded ${loadedCount} event source configurations`);
|
|
458
|
+
} catch (error) {
|
|
459
|
+
logger.error("Failed to load event source configurations:", error);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
__legacyDecorateClassTS([
|
|
464
|
+
TracedAs("event-source.update", { recordParams: false, log: false })
|
|
465
|
+
], EventSourceComponent.prototype, "update", null);
|
|
466
|
+
__legacyDecorateClassTS([
|
|
467
|
+
TracedAs("event_source.start", { recordParams: true, recordResult: false })
|
|
468
|
+
], EventSourceComponent.prototype, "startSource", null);
|
|
469
|
+
__legacyDecorateClassTS([
|
|
470
|
+
TracedAs("event_source.stop", { recordParams: true, recordResult: false })
|
|
471
|
+
], EventSourceComponent.prototype, "stopSource", null);
|
|
472
|
+
|
|
473
|
+
export { EventSourceComponent };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSharedEventStore
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-a08dpf71.js";
|
|
4
4
|
import {
|
|
5
5
|
createCompatibleDatabase,
|
|
6
6
|
init_sqlite_task_store
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-th92f833.js";
|
|
8
8
|
import {
|
|
9
9
|
TaskHookPoints
|
|
10
10
|
} from "./roy-agent-core-1pg0fepg.js";
|
|
@@ -14,31 +14,31 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
LarkCardPatchNotifier,
|
|
16
16
|
humanizeValue
|
|
17
|
-
} from "./roy-agent-core-
|
|
17
|
+
} from "./roy-agent-core-m3w3ytxt.js";
|
|
18
18
|
import {
|
|
19
19
|
validateWorkflowDefinition
|
|
20
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-kmvw6b4v.js";
|
|
21
21
|
import {
|
|
22
22
|
enqueueToAddFakeUserMessage
|
|
23
|
-
} from "./roy-agent-core-
|
|
23
|
+
} from "./roy-agent-core-p8rf4z89.js";
|
|
24
24
|
import {
|
|
25
25
|
BasePlugin
|
|
26
26
|
} from "./roy-agent-core-az13yzmc.js";
|
|
27
27
|
import {
|
|
28
28
|
init_context
|
|
29
|
-
} from "./roy-agent-core-
|
|
29
|
+
} from "./roy-agent-core-33hn1beg.js";
|
|
30
30
|
import {
|
|
31
31
|
getEnvContextOrEmpty
|
|
32
|
-
} from "./roy-agent-core-
|
|
32
|
+
} from "./roy-agent-core-hfyxv2kx.js";
|
|
33
33
|
import {
|
|
34
34
|
TracedAs,
|
|
35
35
|
init_decorator,
|
|
36
36
|
wrapFunction
|
|
37
|
-
} from "./roy-agent-core-
|
|
37
|
+
} from "./roy-agent-core-386wa4wy.js";
|
|
38
38
|
import {
|
|
39
39
|
createLogger,
|
|
40
40
|
init_logger
|
|
41
|
-
} from "./roy-agent-core-
|
|
41
|
+
} from "./roy-agent-core-6awgfh3x.js";
|
|
42
42
|
import {
|
|
43
43
|
__legacyDecorateClassTS,
|
|
44
44
|
__require
|
|
@@ -303,11 +303,11 @@ ${prompt}`;
|
|
|
303
303
|
}
|
|
304
304
|
if (!this._workflowRepo) {
|
|
305
305
|
try {
|
|
306
|
-
const sqlite = await import("./roy-agent-core-
|
|
306
|
+
const sqlite = await import("./roy-agent-core-hczj1ryh.js");
|
|
307
307
|
this.ensureDataDir();
|
|
308
308
|
const db = sqlite.getDatabase();
|
|
309
309
|
sqlite.initializeTables();
|
|
310
|
-
const { WorkflowRepository } = await import("./roy-agent-core-
|
|
310
|
+
const { WorkflowRepository } = await import("./roy-agent-core-mkpsz128.js");
|
|
311
311
|
this._workflowRepo = new WorkflowRepository(db);
|
|
312
312
|
return this._workflowRepo;
|
|
313
313
|
} catch {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
init_hook
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-7tce05jt.js";
|
|
4
4
|
import {
|
|
5
5
|
globalHookManager
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-v7mwj8eq.js";
|
|
7
7
|
import {
|
|
8
8
|
__esm
|
|
9
9
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
|
|
4
|
+
|
|
5
|
+
// src/test-utils/child-process-mock.ts
|
|
6
|
+
var CHILD_PROCESS_EXPORT_NAMES = Object.keys(__require("node:child_process")).filter((name) => name !== "default");
|
|
7
|
+
function createChildProcessMockModule(overrides = {}) {
|
|
8
|
+
const real = __require("node:child_process");
|
|
9
|
+
const mocked = {};
|
|
10
|
+
for (const name of CHILD_PROCESS_EXPORT_NAMES) {
|
|
11
|
+
mocked[name] = overrides[name] ?? real[name];
|
|
12
|
+
}
|
|
13
|
+
for (const [name, value] of Object.entries(overrides)) {
|
|
14
|
+
if (value !== undefined)
|
|
15
|
+
mocked[name] = value;
|
|
16
|
+
}
|
|
17
|
+
mocked.default = { ...mocked };
|
|
18
|
+
return mocked;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
createChildProcessMockModule,
|
|
22
|
+
CHILD_PROCESS_EXPORT_NAMES
|
|
23
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TempFileManager
|
|
3
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
4
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
3
|
+
} from "../../shared/@ai-setting/roy-agent-core-wzp4tbsn.js";
|
|
4
|
+
import"../../shared/@ai-setting/roy-agent-core-6awgfh3x.js";
|
|
5
5
|
import"../../shared/@ai-setting/roy-agent-core-jnszp0jq.js";
|
|
6
6
|
import"../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
|
|
7
7
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-setting/roy-agent-core",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.62",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,6 +28,66 @@
|
|
|
28
28
|
"types": "./dist/env/task/backend/index.d.ts",
|
|
29
29
|
"default": "./dist/env/task/backend/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./env/error-reply": {
|
|
32
|
+
"import": "./dist/env/error-reply.js",
|
|
33
|
+
"types": "./dist/env/error-reply.d.ts",
|
|
34
|
+
"default": "./dist/env/error-reply.js"
|
|
35
|
+
},
|
|
36
|
+
"./env/lark-mention-utils": {
|
|
37
|
+
"import": "./dist/env/lark-mention-utils.js",
|
|
38
|
+
"types": "./dist/env/lark-mention-utils.d.ts",
|
|
39
|
+
"default": "./dist/env/lark-mention-utils.js"
|
|
40
|
+
},
|
|
41
|
+
"./env/tool/types": {
|
|
42
|
+
"import": "./dist/env/tool/types.js",
|
|
43
|
+
"types": "./dist/env/tool/types.d.ts",
|
|
44
|
+
"default": "./dist/env/tool/types.js"
|
|
45
|
+
},
|
|
46
|
+
"./env/event-source/event-store": {
|
|
47
|
+
"import": "./dist/env/event-source/event-store.js",
|
|
48
|
+
"types": "./dist/env/event-source/event-store.d.ts",
|
|
49
|
+
"default": "./dist/env/event-source/event-store.js"
|
|
50
|
+
},
|
|
51
|
+
"./env/event-source/cli-command-handler": {
|
|
52
|
+
"import": "./dist/env/event-source/cli-command-handler.js",
|
|
53
|
+
"types": "./dist/env/event-source/cli-command-handler.d.ts",
|
|
54
|
+
"default": "./dist/env/event-source/cli-command-handler.js"
|
|
55
|
+
},
|
|
56
|
+
"./env/event-source/event-source-handlers": {
|
|
57
|
+
"import": "./dist/env/event-source/event-source-handlers.js",
|
|
58
|
+
"types": "./dist/env/event-source/event-source-handlers.d.ts",
|
|
59
|
+
"default": "./dist/env/event-source/event-source-handlers.js"
|
|
60
|
+
},
|
|
61
|
+
"./env/event-source/idempotency-key": {
|
|
62
|
+
"import": "./dist/env/event-source/idempotency-key.js",
|
|
63
|
+
"types": "./dist/env/event-source/idempotency-key.d.ts",
|
|
64
|
+
"default": "./dist/env/event-source/idempotency-key.js"
|
|
65
|
+
},
|
|
66
|
+
"./env/task/delegate/delegate-tool": {
|
|
67
|
+
"import": "./dist/env/task/delegate/delegate-tool.js",
|
|
68
|
+
"types": "./dist/env/task/delegate/delegate-tool.d.ts",
|
|
69
|
+
"default": "./dist/env/task/delegate/delegate-tool.js"
|
|
70
|
+
},
|
|
71
|
+
"./env/log-trace/logger": {
|
|
72
|
+
"import": "./dist/env/log-trace/logger.js",
|
|
73
|
+
"types": "./dist/env/log-trace/logger.d.ts",
|
|
74
|
+
"default": "./dist/env/log-trace/logger.js"
|
|
75
|
+
},
|
|
76
|
+
"./env/agent/agent-component": {
|
|
77
|
+
"import": "./dist/env/agent/agent-component.js",
|
|
78
|
+
"types": "./dist/env/agent/agent-component.d.ts",
|
|
79
|
+
"default": "./dist/env/agent/agent-component.js"
|
|
80
|
+
},
|
|
81
|
+
"./env/task/plugins/lark-card-patch-notifier": {
|
|
82
|
+
"import": "./dist/env/task/plugins/lark-card-patch-notifier.js",
|
|
83
|
+
"types": "./dist/env/task/plugins/lark-card-patch-notifier.d.ts",
|
|
84
|
+
"default": "./dist/env/task/plugins/lark-card-patch-notifier.js"
|
|
85
|
+
},
|
|
86
|
+
"./test-utils/child-process-mock": {
|
|
87
|
+
"import": "./dist/test-utils/child-process-mock.js",
|
|
88
|
+
"types": "./dist/test-utils/child-process-mock.d.ts",
|
|
89
|
+
"default": "./dist/test-utils/child-process-mock.js"
|
|
90
|
+
},
|
|
31
91
|
"./*": {
|
|
32
92
|
"import": "./dist/*/index.js",
|
|
33
93
|
"types": "./dist/*/index.d.ts"
|