@ai-setting/roy-agent-core 1.7.59 → 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.
Files changed (138) hide show
  1. package/dist/config/index.js +8 -8
  2. package/dist/env/agent/agent-component.js +41 -0
  3. package/dist/env/agent/index.js +18 -16
  4. package/dist/env/commands/index.js +8 -8
  5. package/dist/env/context/index.js +4 -4
  6. package/dist/env/debug/index.js +8 -8
  7. package/dist/env/error-reply.js +18 -0
  8. package/dist/env/event-source/cli-command-handler.d.ts +90 -0
  9. package/dist/env/event-source/cli-command-handler.js +17 -0
  10. package/dist/env/event-source/event-source-handlers.d.ts +1 -0
  11. package/dist/env/event-source/event-source-handlers.js +58 -0
  12. package/dist/env/event-source/event-store.js +18 -0
  13. package/dist/env/event-source/idempotency-key.js +20 -0
  14. package/dist/env/event-source/index.d.ts +3 -1
  15. package/dist/env/event-source/index.js +37 -22
  16. package/dist/env/event-source/types.d.ts +21 -1
  17. package/dist/env/hook/index.js +6 -6
  18. package/dist/env/index.js +54 -48
  19. package/dist/env/lark-mention-utils.js +9 -0
  20. package/dist/env/llm/index.js +9 -9
  21. package/dist/env/log-trace/index.d.ts +1 -1
  22. package/dist/env/log-trace/index.js +12 -8
  23. package/dist/env/log-trace/logger.d.ts +2 -0
  24. package/dist/env/log-trace/logger.js +39 -0
  25. package/dist/env/mcp/index.js +9 -9
  26. package/dist/env/mcp/tool/index.js +2 -2
  27. package/dist/env/memory/index.js +9 -9
  28. package/dist/env/memory/plugin/index.js +2 -2
  29. package/dist/env/plugin/index.js +9 -9
  30. package/dist/env/prompt/index.js +8 -8
  31. package/dist/env/session/index.js +11 -11
  32. package/dist/env/session/storage/index.js +5 -5
  33. package/dist/env/skill/index.js +8 -8
  34. package/dist/env/task/delegate/delegate-tool.js +42 -0
  35. package/dist/env/task/delegate/index.js +13 -11
  36. package/dist/env/task/index.js +17 -16
  37. package/dist/env/task/mcp/index.d.ts +16 -0
  38. package/dist/env/task/mcp/index.js +222 -0
  39. package/dist/env/task/mcp/task-mcp-server.d.ts +142 -0
  40. package/dist/env/task/plugins/index.d.ts +1 -0
  41. package/dist/env/task/plugins/index.js +47 -12
  42. package/dist/env/task/plugins/lark-card-patch-notifier.js +42 -0
  43. package/dist/env/task/storage/index.js +4 -4
  44. package/dist/env/task/storage/migrations/log-migration.d.ts +19 -0
  45. package/dist/env/task/storage/sqlite-task-store.d.ts +29 -0
  46. package/dist/env/task/task-component.d.ts +48 -3
  47. package/dist/env/task/tools/index.js +4 -4
  48. package/dist/env/task/tools/task-types.d.ts +60 -11
  49. package/dist/env/tool/built-in/index.js +4 -4
  50. package/dist/env/tool/index.js +12 -11
  51. package/dist/env/tool/types.js +1 -0
  52. package/dist/env/workflow/engine/index.js +13 -13
  53. package/dist/env/workflow/hooks/index.js +8 -8
  54. package/dist/env/workflow/index.js +23 -23
  55. package/dist/env/workflow/nodes/index.js +3 -3
  56. package/dist/env/workflow/plugins/index.js +9 -9
  57. package/dist/env/workflow/service/index.js +3 -3
  58. package/dist/env/workflow/storage/index.js +4 -4
  59. package/dist/env/workflow/tools/index.js +15 -15
  60. package/dist/env/workflow/tools/run-workflow.d.ts +30 -0
  61. package/dist/env/workflow/utils/index.js +5 -5
  62. package/dist/env/workflow/utils/session-recovery.d.ts +27 -0
  63. package/dist/index.js +91 -73
  64. package/dist/shared/@ai-setting/{roy-agent-core-ygn5tzt1.js → roy-agent-core-06jakebr.js} +2 -2
  65. package/dist/shared/@ai-setting/{roy-agent-core-m68z3pw1.js → roy-agent-core-084zthqx.js} +1 -1
  66. package/dist/shared/@ai-setting/{roy-agent-core-cyefe8z5.js → roy-agent-core-2hkyp51n.js} +1 -1
  67. package/dist/shared/@ai-setting/{roy-agent-core-029r8kdw.js → roy-agent-core-2pma868e.js} +4 -4
  68. package/dist/shared/@ai-setting/{roy-agent-core-c7w2h47a.js → roy-agent-core-2veqhrxa.js} +3 -3
  69. package/dist/shared/@ai-setting/{roy-agent-core-t64nmayv.js → roy-agent-core-32ck9rqt.js} +2 -2
  70. package/dist/shared/@ai-setting/{roy-agent-core-m97jn2ra.js → roy-agent-core-33hn1beg.js} +1 -1
  71. package/dist/shared/@ai-setting/{roy-agent-core-8p63s836.js → roy-agent-core-386wa4wy.js} +1 -1
  72. package/dist/shared/@ai-setting/{roy-agent-core-kq9pz2a7.js → roy-agent-core-48h4zh60.js} +4 -4
  73. package/dist/shared/@ai-setting/{roy-agent-core-eanq305k.js → roy-agent-core-5bj0xfjk.js} +13 -27
  74. package/dist/shared/@ai-setting/{roy-agent-core-7q4wdze2.js → roy-agent-core-5mrynf9g.js} +1 -1
  75. package/dist/shared/@ai-setting/{roy-agent-core-rt115qfc.js → roy-agent-core-6awgfh3x.js} +14 -4
  76. package/dist/shared/@ai-setting/{roy-agent-core-9zhkdg6w.js → roy-agent-core-6wxww10t.js} +2 -2
  77. package/dist/shared/@ai-setting/{roy-agent-core-baaa4wtp.js → roy-agent-core-79gyka2q.js} +2 -2
  78. package/dist/shared/@ai-setting/{roy-agent-core-ytd5eztz.js → roy-agent-core-7tce05jt.js} +1 -1
  79. package/dist/shared/@ai-setting/{roy-agent-core-x6c45yqd.js → roy-agent-core-99nwgj84.js} +1 -1
  80. package/dist/shared/@ai-setting/roy-agent-core-9nvyffxg.js +414 -0
  81. package/dist/shared/@ai-setting/{roy-agent-core-e1w17tht.js → roy-agent-core-9qgrc9dy.js} +158 -158
  82. package/dist/shared/@ai-setting/{roy-agent-core-2ctyjy62.js → roy-agent-core-a08dpf71.js} +17 -2
  83. package/dist/shared/@ai-setting/{roy-agent-core-e250355z.js → roy-agent-core-a6cz4d23.js} +3 -3
  84. package/dist/shared/@ai-setting/{roy-agent-core-tze5596n.js → roy-agent-core-anb53t3v.js} +3 -3
  85. package/dist/shared/@ai-setting/{roy-agent-core-caevk7xd.js → roy-agent-core-arx535cs.js} +30 -8
  86. package/dist/shared/@ai-setting/{roy-agent-core-vh0qzb24.js → roy-agent-core-as0dd70m.js} +36 -15
  87. package/dist/shared/@ai-setting/{roy-agent-core-w93z6a42.js → roy-agent-core-bpvz1dqr.js} +12 -12
  88. package/dist/shared/@ai-setting/{roy-agent-core-ck60j1q9.js → roy-agent-core-bxkjk7zx.js} +2 -1
  89. package/dist/shared/@ai-setting/{roy-agent-core-hs41gx9w.js → roy-agent-core-c4t4y18j.js} +5 -5
  90. package/dist/shared/@ai-setting/{roy-agent-core-t4x089js.js → roy-agent-core-c57278kx.js} +1 -1
  91. package/dist/shared/@ai-setting/{roy-agent-core-em4hks9t.js → roy-agent-core-c8xvy6hj.js} +4 -4
  92. package/dist/shared/@ai-setting/{roy-agent-core-991pk4ss.js → roy-agent-core-cqpd41gf.js} +18 -16
  93. package/dist/shared/@ai-setting/{roy-agent-core-psg6f1v6.js → roy-agent-core-cxpgd415.js} +6 -6
  94. package/dist/shared/@ai-setting/{roy-agent-core-vgdhxbx3.js → roy-agent-core-dfqhc9ey.js} +2 -2
  95. package/dist/shared/@ai-setting/{roy-agent-core-6bradb0j.js → roy-agent-core-fqandv0a.js} +9 -107
  96. package/dist/shared/@ai-setting/{roy-agent-core-en2xqxs9.js → roy-agent-core-fr296a53.js} +39 -14
  97. package/dist/shared/@ai-setting/{roy-agent-core-rcgvmtms.js → roy-agent-core-gc6wcd7z.js} +1 -1
  98. package/dist/shared/@ai-setting/{roy-agent-core-7nb23tdd.js → roy-agent-core-gjsvehfs.js} +1 -1
  99. package/dist/shared/@ai-setting/{roy-agent-core-0kn3zt1t.js → roy-agent-core-gtdtzbs7.js} +2 -2
  100. package/dist/shared/@ai-setting/{roy-agent-core-84rs0c8d.js → roy-agent-core-gz2jnaan.js} +7 -7
  101. package/dist/shared/@ai-setting/{roy-agent-core-0yn7a78e.js → roy-agent-core-h3fwjbhp.js} +14 -14
  102. package/dist/shared/@ai-setting/{roy-agent-core-4096f575.js → roy-agent-core-hczj1ryh.js} +4 -4
  103. package/dist/shared/@ai-setting/{roy-agent-core-syyw58p9.js → roy-agent-core-hfyxv2kx.js} +2 -2
  104. package/dist/shared/@ai-setting/{roy-agent-core-d75t8gea.js → roy-agent-core-hwkc0bg2.js} +1 -1
  105. package/dist/shared/@ai-setting/{roy-agent-core-vath15kt.js → roy-agent-core-ja4sr63d.js} +6 -6
  106. package/dist/shared/@ai-setting/roy-agent-core-jagkferh.js +16 -0
  107. package/dist/shared/@ai-setting/roy-agent-core-jm136jzh.js +99 -0
  108. package/dist/shared/@ai-setting/{roy-agent-core-14bq77wr.js → roy-agent-core-jw63js86.js} +1 -1
  109. package/dist/shared/@ai-setting/{roy-agent-core-89sxsrc7.js → roy-agent-core-kmvw6b4v.js} +1 -1
  110. package/dist/shared/@ai-setting/{roy-agent-core-47s81t6g.js → roy-agent-core-kvq4a4p6.js} +2 -2
  111. package/dist/shared/@ai-setting/{roy-agent-core-c36335nw.js → roy-agent-core-m3w3ytxt.js} +15 -3
  112. package/dist/shared/@ai-setting/{roy-agent-core-64f22h1g.js → roy-agent-core-m880qz3y.js} +7 -1
  113. package/dist/shared/@ai-setting/{roy-agent-core-2fk8c9ax.js → roy-agent-core-mbwaxqs0.js} +3 -3
  114. package/dist/shared/@ai-setting/{roy-agent-core-jjhw9am6.js → roy-agent-core-mkpsz128.js} +4 -4
  115. package/dist/shared/@ai-setting/{roy-agent-core-20m8je6e.js → roy-agent-core-mrrv80jy.js} +1 -1
  116. package/dist/shared/@ai-setting/{roy-agent-core-6q5m1qk5.js → roy-agent-core-nmn853z0.js} +333 -1183
  117. package/dist/shared/@ai-setting/roy-agent-core-p37kh0kt.js +155 -0
  118. package/dist/shared/@ai-setting/{roy-agent-core-08njdcpj.js → roy-agent-core-p6a4v4fq.js} +1 -1
  119. package/dist/shared/@ai-setting/{roy-agent-core-gksw1gjb.js → roy-agent-core-p8rf4z89.js} +1 -1
  120. package/dist/shared/@ai-setting/roy-agent-core-pnj0zh25.js +0 -0
  121. package/dist/shared/@ai-setting/{roy-agent-core-q4gdfypk.js → roy-agent-core-prnry2mw.js} +3 -3
  122. package/dist/shared/@ai-setting/{roy-agent-core-84xtww7d.js → roy-agent-core-qmqe8ds3.js} +3 -3
  123. package/dist/shared/@ai-setting/{roy-agent-core-txwptxk1.js → roy-agent-core-sj4y3wdm.js} +3 -3
  124. package/dist/shared/@ai-setting/{roy-agent-core-fbjd7bt6.js → roy-agent-core-th92f833.js} +64 -29
  125. package/dist/shared/@ai-setting/{roy-agent-core-yphwdm9x.js → roy-agent-core-v7mwj8eq.js} +2 -2
  126. package/dist/shared/@ai-setting/{roy-agent-core-5f7myqnb.js → roy-agent-core-vvb4cyyy.js} +11 -5
  127. package/dist/shared/@ai-setting/{roy-agent-core-jjxdmedn.js → roy-agent-core-vwzan9v0.js} +2 -2
  128. package/dist/shared/@ai-setting/{roy-agent-core-fw6k4w1h.js → roy-agent-core-w2ev3z5q.js} +12 -14
  129. package/dist/shared/@ai-setting/roy-agent-core-w2h6xt6k.js +473 -0
  130. package/dist/shared/@ai-setting/{roy-agent-core-n0p0hwgd.js → roy-agent-core-wzp4tbsn.js} +1 -1
  131. package/dist/shared/@ai-setting/{roy-agent-core-ge87xbas.js → roy-agent-core-x1d6edkh.js} +1 -1
  132. package/dist/shared/@ai-setting/{roy-agent-core-8bngppw0.js → roy-agent-core-ye4bfzqg.js} +13 -13
  133. package/dist/shared/@ai-setting/{roy-agent-core-geh6j7bw.js → roy-agent-core-zjgckbdd.js} +2 -2
  134. package/dist/shared/@ai-setting/{roy-agent-core-hefarcp0.js → roy-agent-core-zy8vkbnk.js} +1 -1
  135. package/dist/test-utils/child-process-mock.js +23 -0
  136. package/dist/utils/temp-file-manager/index.js +2 -2
  137. package/package.json +76 -1
  138. /package/dist/shared/@ai-setting/{roy-agent-core-3ztzc83c.js → roy-agent-core-5enxfga2.js} +0 -0
@@ -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,7 +1,7 @@
1
1
  import {
2
2
  createLogger,
3
3
  init_logger
4
- } from "./roy-agent-core-rt115qfc.js";
4
+ } from "./roy-agent-core-6awgfh3x.js";
5
5
 
6
6
  // src/utils/temp-file-manager/index.ts
7
7
  init_logger();
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  safeParseToolArgs
3
- } from "./roy-agent-core-e1w17tht.js";
3
+ } from "./roy-agent-core-9qgrc9dy.js";
4
4
 
5
5
  // src/env/session/session-message-converter.ts
6
6
  import { randomUUID } from "crypto";
@@ -1,10 +1,10 @@
1
+ import {
2
+ getSharedEventStore
3
+ } from "./roy-agent-core-a08dpf71.js";
1
4
  import {
2
5
  createCompatibleDatabase,
3
6
  init_sqlite_task_store
4
- } from "./roy-agent-core-fbjd7bt6.js";
5
- import {
6
- getSharedEventStore
7
- } from "./roy-agent-core-2ctyjy62.js";
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-c36335nw.js";
17
+ } from "./roy-agent-core-m3w3ytxt.js";
18
18
  import {
19
19
  validateWorkflowDefinition
20
- } from "./roy-agent-core-89sxsrc7.js";
20
+ } from "./roy-agent-core-kmvw6b4v.js";
21
21
  import {
22
22
  enqueueToAddFakeUserMessage
23
- } from "./roy-agent-core-gksw1gjb.js";
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-m97jn2ra.js";
29
+ } from "./roy-agent-core-33hn1beg.js";
30
30
  import {
31
31
  getEnvContextOrEmpty
32
- } from "./roy-agent-core-syyw58p9.js";
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-8p63s836.js";
37
+ } from "./roy-agent-core-386wa4wy.js";
38
38
  import {
39
39
  createLogger,
40
40
  init_logger
41
- } from "./roy-agent-core-rt115qfc.js";
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-4096f575.js");
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-jjhw9am6.js");
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-ytd5eztz.js";
3
+ } from "./roy-agent-core-7tce05jt.js";
4
4
  import {
5
5
  globalHookManager
6
- } from "./roy-agent-core-yphwdm9x.js";
6
+ } from "./roy-agent-core-v7mwj8eq.js";
7
7
  import {
8
8
  __esm
9
9
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  init_workflow_hook_points
3
- } from "./roy-agent-core-geh6j7bw.js";
3
+ } from "./roy-agent-core-zjgckbdd.js";
4
4
  import {
5
5
  __esm
6
6
  } 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-n0p0hwgd.js";
4
- import"../../shared/@ai-setting/roy-agent-core-rt115qfc.js";
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 {