@ai-setting/roy-agent-core 1.4.13 → 1.4.14

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 (103) hide show
  1. package/dist/packages/core/src/config/index.js +32 -0
  2. package/dist/packages/core/src/env/agent/index.js +24 -0
  3. package/dist/packages/core/src/env/commands/index.js +14 -0
  4. package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
  5. package/dist/packages/core/src/env/debug/index.js +26 -0
  6. package/dist/packages/core/src/env/hook/index.js +29 -0
  7. package/dist/packages/core/src/env/index.js +81 -0
  8. package/dist/packages/core/src/env/llm/index.js +40 -0
  9. package/dist/packages/core/src/env/log-trace/index.js +83 -0
  10. package/dist/packages/core/src/env/mcp/index.js +39 -0
  11. package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
  12. package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
  13. package/dist/packages/core/src/env/memory/index.js +56 -0
  14. package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
  15. package/dist/packages/core/src/env/prompt/index.js +20 -0
  16. package/dist/packages/core/src/env/session/index.js +25 -0
  17. package/dist/packages/core/src/env/session/storage/index.js +18 -0
  18. package/dist/packages/core/src/env/skill/index.js +34 -0
  19. package/dist/packages/core/src/env/skill/tool/index.js +9 -0
  20. package/dist/packages/core/src/env/task/delegate/index.js +18 -0
  21. package/dist/packages/core/src/env/task/hooks/index.js +7 -0
  22. package/dist/packages/core/src/env/task/index.js +30 -0
  23. package/dist/packages/core/src/env/task/plugins/index.js +23 -0
  24. package/dist/packages/core/src/env/task/storage/index.js +14 -0
  25. package/dist/packages/core/src/env/task/tools/index.js +17 -0
  26. package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
  27. package/dist/{shared/chunk-1d4rwms4.js → packages/core/src/env/tool/built-in/index.js} +4 -4
  28. package/dist/packages/core/src/env/tool/index.js +39 -0
  29. package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
  30. package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
  31. package/dist/packages/core/src/env/workflow/index.js +132 -0
  32. package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
  33. package/dist/packages/core/src/env/workflow/service/index.js +13 -0
  34. package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
  35. package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
  36. package/dist/packages/core/src/env/workflow/types/index.js +94 -0
  37. package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
  38. package/dist/packages/core/src/index.js +398 -0
  39. package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
  40. package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
  41. package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
  42. package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
  43. package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
  44. package/dist/shared/{chunk-ze20rksg.js → @ai-setting/roy-agent-core-0sgn3de4.js} +2 -2
  45. package/dist/shared/@ai-setting/roy-agent-core-12x57kf1.js +286 -0
  46. package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
  47. package/dist/shared/{chunk-q9j99fsm.js → @ai-setting/roy-agent-core-1k28kg7h.js} +6 -6
  48. package/dist/shared/{chunk-2b5kbhx3.js → @ai-setting/roy-agent-core-1z1zv5g8.js} +9 -117
  49. package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
  50. package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
  51. package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
  52. package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
  53. package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
  54. package/dist/shared/{chunk-25x2pdtp.js → @ai-setting/roy-agent-core-4ws8atva.js} +2 -2
  55. package/dist/shared/@ai-setting/roy-agent-core-5fbp24se.js +603 -0
  56. package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
  57. package/dist/shared/{chunk-rncy3rtd.js → @ai-setting/roy-agent-core-6j0zcmwk.js} +128 -1122
  58. package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
  59. package/dist/shared/{chunk-yqmx37vm.js → @ai-setting/roy-agent-core-7vrk3add.js} +2 -2
  60. package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
  61. package/dist/shared/@ai-setting/roy-agent-core-8mbmrwzs.js +171 -0
  62. package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
  63. package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
  64. package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
  65. package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
  66. package/dist/shared/@ai-setting/roy-agent-core-fq5mtxsy.js +341 -0
  67. package/dist/shared/@ai-setting/roy-agent-core-fvd9g6k8.js +1205 -0
  68. package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
  69. package/dist/shared/@ai-setting/roy-agent-core-gy0wp5h7.js +213 -0
  70. package/dist/shared/{chunk-mf5xqbdh.js → @ai-setting/roy-agent-core-hyza1gm7.js} +3 -2
  71. package/dist/shared/{chunk-1qwabsm0.js → @ai-setting/roy-agent-core-j8zx62zr.js} +2 -2
  72. package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
  73. package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
  74. package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
  75. package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
  76. package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
  77. package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
  78. package/dist/shared/{chunk-1aakcfp1.js → @ai-setting/roy-agent-core-nczzf0ms.js} +3 -3
  79. package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
  80. package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
  82. package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
  83. package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
  84. package/dist/shared/{chunk-9qzt1v1p.js → @ai-setting/roy-agent-core-qg9tcaph.js} +3 -2
  85. package/dist/shared/{chunk-91bas8w5.js → @ai-setting/roy-agent-core-qhyerewk.js} +5 -5
  86. package/dist/shared/{chunk-1pf5mfgd.js → @ai-setting/roy-agent-core-qxybm159.js} +3 -3
  87. package/dist/shared/{chunk-g6j5n3gv.js → @ai-setting/roy-agent-core-rh9dpkpw.js} +10 -10
  88. package/dist/shared/{chunk-0q6s9wm6.js → @ai-setting/roy-agent-core-rr9p1g43.js} +7 -51
  89. package/dist/shared/@ai-setting/roy-agent-core-sbzvpfn7.js +284 -0
  90. package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
  91. package/dist/shared/{chunk-t1rh6jtm.js → @ai-setting/roy-agent-core-tkr5ynkh.js} +8 -13
  92. package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-w75rafhy.js +202 -0
  94. package/dist/shared/@ai-setting/roy-agent-core-w76hqkmg.js +584 -0
  95. package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
  96. package/dist/shared/{chunk-a9qmy3sc.js → @ai-setting/roy-agent-core-yn761yve.js} +7 -4
  97. package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
  98. package/dist/shared/@ai-setting/roy-agent-core-yt8wdh2w.js +206 -0
  99. package/package.json +8 -7
  100. package/dist/index.d.ts +0 -7825
  101. package/dist/index.js +0 -16551
  102. package/dist/shared/chunk-hs7tbmje.js +0 -24
  103. /package/dist/shared/{chunk-wbkh7wat.js → @ai-setting/roy-agent-core-fs0mn2jk.js} +0 -0
@@ -0,0 +1,513 @@
1
+ import {
2
+ SQLiteTaskStore,
3
+ getDefaultTaskDbPath
4
+ } from "./roy-agent-core-8wzz66qe.js";
5
+ import {
6
+ completeTaskTool,
7
+ createTaskTool,
8
+ deleteTaskTool,
9
+ getTaskTool,
10
+ listTasksTool,
11
+ updateTaskTool
12
+ } from "./roy-agent-core-12x57kf1.js";
13
+ import {
14
+ createOperationTool,
15
+ deleteOperationTool,
16
+ getOperationTool,
17
+ listOperationsTool,
18
+ updateOperationTool
19
+ } from "./roy-agent-core-gy0wp5h7.js";
20
+ import {
21
+ BackgroundTaskManager,
22
+ createDelegateTool,
23
+ createStopTool
24
+ } from "./roy-agent-core-t22nqt4d.js";
25
+ import {
26
+ TaskHookPoints
27
+ } from "./roy-agent-core-pzk1syce.js";
28
+ import {
29
+ envKeyToConfigKey
30
+ } from "./roy-agent-core-jv3b7v9w.js";
31
+ import {
32
+ BaseComponent
33
+ } from "./roy-agent-core-m2x48hw6.js";
34
+ import {
35
+ globalHookManager
36
+ } from "./roy-agent-core-w75rafhy.js";
37
+ import {
38
+ createLogger,
39
+ init_logger
40
+ } from "./roy-agent-core-yn761yve.js";
41
+
42
+ // packages/core/src/env/task/task-component.ts
43
+ init_logger();
44
+
45
+ // packages/core/src/env/task/task-config-registration.ts
46
+ var TASK_DEFAULTS = {
47
+ "task.storage.type": "sqlite",
48
+ "task.storage.dbPath": undefined
49
+ };
50
+ var TASK_CONFIG_REGISTRATION = {
51
+ name: "task",
52
+ sources: [
53
+ { type: "env", envPrefix: "TASK", priority: 20, watch: false }
54
+ ],
55
+ keys: [
56
+ { key: "task.storage.type", sources: ["env", "file"] },
57
+ { key: "task.storage.dbPath", sources: ["env", "file"] }
58
+ ]
59
+ };
60
+
61
+ // packages/core/src/env/task/tag-service.ts
62
+ init_logger();
63
+ var logger = createLogger("task:tag");
64
+
65
+ class DefaultTagService {
66
+ store;
67
+ constructor(store) {
68
+ this.store = store;
69
+ }
70
+ async createTag(name) {
71
+ const tag = await this.store.createTag(name);
72
+ logger.debug(`[TagService] Created tag: ${tag.name} (id=${tag.id})`);
73
+ return tag;
74
+ }
75
+ async getTag(id) {
76
+ return this.store.getTag(id);
77
+ }
78
+ async getTagByName(name) {
79
+ return this.store.getTagByName(name);
80
+ }
81
+ async listTags(options) {
82
+ return this.store.listTags(options);
83
+ }
84
+ async searchTags(options) {
85
+ return this.store.searchTags(options);
86
+ }
87
+ async deleteTag(id) {
88
+ const result = await this.store.deleteTag(id);
89
+ if (result) {
90
+ logger.debug(`[TagService] Deleted tag id=${id}`);
91
+ }
92
+ return result;
93
+ }
94
+ async addTagsToTask(taskId, tagIds) {
95
+ await this.store.addTagsToTask(taskId, tagIds);
96
+ logger.debug(`[TagService] Added ${tagIds.length} tags to task ${taskId}`);
97
+ }
98
+ async removeTagsFromTask(taskId, tagIds) {
99
+ await this.store.removeTagsFromTask(taskId, tagIds);
100
+ logger.debug(`[TagService] Removed ${tagIds.length} tags from task ${taskId}`);
101
+ }
102
+ async getTagsForTask(taskId) {
103
+ return this.store.getTagsForTask(taskId);
104
+ }
105
+ async getTaskIdsByTags(tagNames) {
106
+ return this.store.getTaskIdsByTags(tagNames);
107
+ }
108
+ async findSimilarTasks(taskId, limit = 5) {
109
+ return this.store.findSimilarTasks(taskId, limit);
110
+ }
111
+ async searchTasks(query, limit = 20) {
112
+ return this.store.searchTasks(query, limit);
113
+ }
114
+ async searchTasksByKeywords(keywords, options) {
115
+ return this.store.searchTasksByKeywords(keywords, options);
116
+ }
117
+ async findSimilarTasksByKeywords(keywords, options) {
118
+ return this.store.findSimilarTasksByKeywords(keywords, options);
119
+ }
120
+ async syncTagsToTask(taskId, tagNames) {
121
+ const tagIds = [];
122
+ for (const name of tagNames) {
123
+ let tag = await this.store.getTagByName(name);
124
+ if (!tag) {
125
+ tag = await this.store.createTag(name);
126
+ }
127
+ tagIds.push(tag.id);
128
+ }
129
+ const currentTags = await this.store.getTagsForTask(taskId);
130
+ const currentTagIds = new Set(currentTags.map((t) => t.id));
131
+ const newTagIds = new Set(tagIds);
132
+ const toAdd = tagIds.filter((id) => !currentTagIds.has(id));
133
+ const toRemove = currentTags.filter((t) => !newTagIds.has(t.id)).map((t) => t.id);
134
+ if (toRemove.length > 0) {
135
+ await this.store.removeTagsFromTask(taskId, toRemove);
136
+ }
137
+ if (toAdd.length > 0) {
138
+ await this.store.addTagsToTask(taskId, toAdd);
139
+ }
140
+ await this.store.updateTaskTags(taskId, tagNames);
141
+ logger.info(`[TagService] Synced tags for task ${taskId}: ${tagNames.join(", ")}`);
142
+ }
143
+ }
144
+
145
+ // packages/core/src/env/task/task-component.ts
146
+ var logger2 = createLogger("task");
147
+
148
+ class TaskComponent extends BaseComponent {
149
+ name = "task";
150
+ version = "1.0.0";
151
+ store;
152
+ config;
153
+ toolComponent;
154
+ backgroundTaskManager;
155
+ configComponent;
156
+ tagService;
157
+ plugins = new Map;
158
+ constructor() {
159
+ super();
160
+ }
161
+ async init(config) {
162
+ await super.init(config);
163
+ const options = config?.options;
164
+ if (!options?.configComponent) {
165
+ throw new Error("ConfigComponent is required for TaskComponent initialization");
166
+ }
167
+ this.configComponent = options.configComponent;
168
+ await this.registerConfig(options);
169
+ this.setStatus("running");
170
+ logger2.info("[TaskComponent] Initialized");
171
+ }
172
+ async registerConfig(options) {
173
+ const configComponent = this.configComponent;
174
+ if (!configComponent)
175
+ return;
176
+ const { configPath, envPrefix, config } = options;
177
+ const prefix = envPrefix ?? "TASK";
178
+ configComponent.registerComponent(TASK_CONFIG_REGISTRATION);
179
+ if (configPath) {
180
+ configComponent.registerSource({
181
+ type: "file",
182
+ relativePath: configPath,
183
+ optional: true,
184
+ watch: false
185
+ });
186
+ }
187
+ configComponent.registerSource({
188
+ type: "env",
189
+ envPrefix: prefix,
190
+ priority: 20,
191
+ watch: false
192
+ });
193
+ await configComponent.load("task");
194
+ for (const envKey of Object.keys(process.env)) {
195
+ const configKey = envKeyToConfigKey(envKey, prefix, "task");
196
+ if (!configKey)
197
+ continue;
198
+ const value = process.env[envKey];
199
+ if (value !== undefined) {
200
+ await configComponent.set(configKey, value);
201
+ }
202
+ }
203
+ for (const [key, value] of Object.entries(TASK_DEFAULTS)) {
204
+ if (configComponent.get(key) === undefined) {
205
+ await configComponent.set(key, value);
206
+ }
207
+ }
208
+ if (configComponent.get("task.storage.dbPath") === undefined) {
209
+ await configComponent.set("task.storage.dbPath", getDefaultTaskDbPath());
210
+ }
211
+ if (config) {
212
+ const flatConfig = this.flattenConfig(config);
213
+ for (const [key, value] of Object.entries(flatConfig)) {
214
+ await configComponent.set(key, value);
215
+ }
216
+ }
217
+ this.registerConfigWatcher(configComponent);
218
+ await this.initStore();
219
+ this.tagService = new DefaultTagService(this.store);
220
+ }
221
+ async initStore() {
222
+ const configComponent = this.configComponent;
223
+ if (!configComponent)
224
+ return;
225
+ const storageType = configComponent.get("task.storage.type") ?? "sqlite";
226
+ const dbPath = configComponent.get("task.storage.dbPath");
227
+ if (storageType === "sqlite") {
228
+ this.store = new SQLiteTaskStore(dbPath);
229
+ logger2.info(`[TaskComponent] Using SQLite storage: ${dbPath || "default path"}`);
230
+ } else {
231
+ this.store = new SQLiteTaskStore;
232
+ logger2.info("[TaskComponent] Using SQLite storage (default)");
233
+ }
234
+ }
235
+ flattenConfig(obj, prefix = "task") {
236
+ const result = {};
237
+ for (const [key, value] of Object.entries(obj)) {
238
+ const fullKey = `${prefix}.${key}`;
239
+ if (value && typeof value === "object" && !Array.isArray(value)) {
240
+ Object.assign(result, this.flattenConfig(value, fullKey));
241
+ } else {
242
+ result[fullKey] = value;
243
+ }
244
+ }
245
+ return result;
246
+ }
247
+ registerConfigWatcher(configComponent) {
248
+ if (typeof configComponent.watch !== "function") {
249
+ return;
250
+ }
251
+ this.configWatcher = configComponent.watch("task.*", (event) => {
252
+ this.onConfigChange(event);
253
+ });
254
+ }
255
+ onConfigChange(event) {
256
+ logger2.info(`[TaskComponent] Config changed: ${event.key}`, {
257
+ oldValue: event.oldValue,
258
+ newValue: event.newValue
259
+ });
260
+ if (event.key === "task.storage.type" || event.key === "task.storage.dbPath") {
261
+ this.initStore();
262
+ }
263
+ }
264
+ configWatcher;
265
+ async start() {
266
+ await super.start();
267
+ this.backgroundTaskManager = new BackgroundTaskManager(this.env);
268
+ this.toolComponent = this.env?.getComponent("tool");
269
+ if (this.toolComponent) {
270
+ await this.registerTools();
271
+ } else {
272
+ logger2.warn("[TaskComponent] ToolComponent not found, skipping tool registration");
273
+ }
274
+ }
275
+ async stop() {
276
+ if (this.configWatcher) {
277
+ this.configWatcher();
278
+ this.configWatcher = undefined;
279
+ }
280
+ if (this.backgroundTaskManager) {
281
+ this.backgroundTaskManager.dispose();
282
+ }
283
+ if (this.store) {
284
+ await this.store.close();
285
+ }
286
+ await super.stop();
287
+ }
288
+ async registerTools() {
289
+ if (!this.toolComponent)
290
+ return;
291
+ const taskToolsList = [
292
+ createTaskTool(this),
293
+ getTaskTool(this),
294
+ listTasksTool(this),
295
+ updateTaskTool(this),
296
+ deleteTaskTool(this),
297
+ completeTaskTool(this)
298
+ ];
299
+ const operationToolsList = [
300
+ createOperationTool(this),
301
+ getOperationTool(this),
302
+ listOperationsTool(this),
303
+ updateOperationTool(this),
304
+ deleteOperationTool(this)
305
+ ];
306
+ const delegateTools = [
307
+ createDelegateTool(this),
308
+ createStopTool(this.backgroundTaskManager)
309
+ ];
310
+ for (const tool of [...taskToolsList, ...operationToolsList, ...delegateTools]) {
311
+ this.toolComponent.register(tool);
312
+ logger2.info(`[TaskComponent] Registered tool: ${tool.name}`);
313
+ }
314
+ }
315
+ async executeHook(hookPoint, data, metadata = {}) {
316
+ const ctx = {
317
+ component: { name: this.name, version: this.version },
318
+ data,
319
+ metadata,
320
+ phase: hookPoint.includes("before") ? "before" : "after",
321
+ hookPoint
322
+ };
323
+ await globalHookManager.execute(hookPoint, ctx, metadata);
324
+ }
325
+ async createTask(options) {
326
+ const sessionId = options.sessionId;
327
+ const createCtx = {
328
+ options: { ...options },
329
+ sessionId,
330
+ tagService: this.tagService
331
+ };
332
+ await this.executeHook(TaskHookPoints.BEFORE_CREATE, createCtx);
333
+ const task = await this.store.createTask(createCtx.options);
334
+ await this.store.createOperation({
335
+ taskId: task.id,
336
+ sessionId,
337
+ actionType: "create",
338
+ actionTitle: `Task created: ${task.title}`,
339
+ actionDescription: task.description || ""
340
+ });
341
+ const resultCtx = {
342
+ task,
343
+ sessionId,
344
+ tagService: this.tagService
345
+ };
346
+ await this.executeHook(TaskHookPoints.AFTER_CREATE, resultCtx);
347
+ logger2.info(`[TaskComponent] Task created: ${task.id} - ${task.title}`);
348
+ return task;
349
+ }
350
+ async getTask(id) {
351
+ return this.store.getTask(id);
352
+ }
353
+ async getTaskWithOperations(id) {
354
+ const task = await this.store.getTask(id);
355
+ if (!task)
356
+ return;
357
+ const operations = await this.store.listOperations({ taskId: id });
358
+ return { task, operations };
359
+ }
360
+ async updateTask(id, options) {
361
+ const updateCtx = {
362
+ id,
363
+ options: { ...options },
364
+ tagService: this.tagService
365
+ };
366
+ await this.executeHook(TaskHookPoints.BEFORE_UPDATE, updateCtx);
367
+ const task = await this.store.updateTask(id, updateCtx.options);
368
+ if (task) {
369
+ const resultCtx = {
370
+ task,
371
+ changes: options,
372
+ tagService: this.tagService
373
+ };
374
+ await this.executeHook(TaskHookPoints.AFTER_UPDATE, resultCtx);
375
+ logger2.info(`[TaskComponent] Task updated: ${id}`);
376
+ }
377
+ return task;
378
+ }
379
+ async deleteTask(id) {
380
+ const deleteCtx = { id };
381
+ await this.executeHook(TaskHookPoints.BEFORE_DELETE, deleteCtx);
382
+ const result = await this.store.deleteTask(id);
383
+ const resultCtx = { id, deleted: result };
384
+ await this.executeHook(TaskHookPoints.AFTER_DELETE, resultCtx);
385
+ if (result) {
386
+ logger2.info(`[TaskComponent] Task deleted: ${id}`);
387
+ }
388
+ return result;
389
+ }
390
+ async listTasks(options) {
391
+ return this.store.listTasks(options);
392
+ }
393
+ async completeTask(id, sessionId) {
394
+ const task = await this.store.updateTask(id, {
395
+ status: "completed",
396
+ progress: 100
397
+ });
398
+ if (task) {
399
+ await this.createOperation({
400
+ taskId: id,
401
+ sessionId,
402
+ actionType: "completed",
403
+ actionTitle: "Task completed"
404
+ });
405
+ logger2.info(`[TaskComponent] Task completed: ${id}`);
406
+ }
407
+ return task;
408
+ }
409
+ async createOperation(options) {
410
+ const createCtx = {
411
+ options: { ...options }
412
+ };
413
+ await this.executeHook(TaskHookPoints.OPERATION_BEFORE_CREATE, createCtx);
414
+ const op = await this.store.createOperation(createCtx.options);
415
+ const resultCtx = { operation: op };
416
+ await this.executeHook(TaskHookPoints.OPERATION_AFTER_CREATE, resultCtx);
417
+ logger2.info(`[TaskComponent] Operation created: ${op.id} for task ${op.taskId}`);
418
+ return op;
419
+ }
420
+ async getOperation(id) {
421
+ return this.store.getOperation(id);
422
+ }
423
+ async updateOperation(id, updates) {
424
+ return this.store.updateOperation(id, updates);
425
+ }
426
+ async deleteOperation(id) {
427
+ return this.store.deleteOperation(id);
428
+ }
429
+ async listOperations(options) {
430
+ return this.store.listOperations(options);
431
+ }
432
+ getTagService() {
433
+ return this.tagService;
434
+ }
435
+ registerPlugin(plugin) {
436
+ this.plugins.set(plugin.name, plugin);
437
+ const llmComponent = this.env?.getComponent("llm");
438
+ plugin.setComponents?.(llmComponent, this);
439
+ const getRequiredAgents = plugin.constructor.getRequiredAgents;
440
+ if (typeof getRequiredAgents === "function") {
441
+ const agentComponent = this.env?.getComponent("agent");
442
+ if (agentComponent) {
443
+ try {
444
+ const agents = getRequiredAgents();
445
+ for (const agentConfig of agents) {
446
+ agentComponent.registerAgent(agentConfig.name, agentConfig);
447
+ }
448
+ } catch (err) {
449
+ logger2.warn(`Failed to auto-register agents for plugin ${plugin.name}: ${err}`);
450
+ }
451
+ }
452
+ }
453
+ for (const hook of plugin.hooks) {
454
+ const pluginConfig = plugin.config;
455
+ const priority = hook.priority ?? pluginConfig?.priority ?? 0;
456
+ const hookName = `${this.name}:${plugin.name}:${hook.point}`;
457
+ const pluginRef = plugin;
458
+ globalHookManager.register(hook.point, {
459
+ name: hookName,
460
+ priority,
461
+ execute: async (ctx) => {
462
+ const pluginCtx = {
463
+ component: ctx.component,
464
+ data: ctx.data,
465
+ metadata: ctx.metadata,
466
+ phase: ctx.phase,
467
+ hookPoint: hook.point
468
+ };
469
+ await pluginRef.execute(pluginCtx);
470
+ }
471
+ });
472
+ }
473
+ logger2.info(`[TaskComponent] Registered plugin: ${plugin.name}`, {
474
+ hooks: plugin.hooks.map((h) => h.point)
475
+ });
476
+ }
477
+ unregisterPlugin(name) {
478
+ const plugin = this.plugins.get(name);
479
+ if (!plugin)
480
+ return false;
481
+ for (const hook of plugin.hooks) {
482
+ globalHookManager.unregister(hook.point, `${this.name}:${name}`);
483
+ }
484
+ this.plugins.delete(name);
485
+ logger2.info(`[TaskComponent] Unregistered plugin: ${name}`);
486
+ return true;
487
+ }
488
+ listPlugins() {
489
+ return Array.from(this.plugins.values());
490
+ }
491
+ }
492
+ // packages/core/src/env/task/types.ts
493
+ import { z } from "zod";
494
+ var TaskStatusEnum = z.enum(["todo", "active", "completed", "paused", "cancelled"]);
495
+ var TaskPriorityEnum = z.enum(["low", "medium", "high"]);
496
+ var ActionTypeEnum = z.enum([
497
+ "create",
498
+ "progress",
499
+ "milestone",
500
+ "problem",
501
+ "solution",
502
+ "decision",
503
+ "review",
504
+ "completed",
505
+ "workflow_extracted"
506
+ ]);
507
+ var TaskConfigSchema = z.object({
508
+ storage: z.object({
509
+ type: z.enum(["memory", "sqlite"]).default("sqlite"),
510
+ dbPath: z.string().optional()
511
+ }).default({})
512
+ }).default({});
513
+ export { TaskComponent, TaskStatusEnum, TaskPriorityEnum, ActionTypeEnum, TaskConfigSchema };
@@ -0,0 +1,60 @@
1
+ // packages/core/src/env/skill/types.ts
2
+ import { z } from "zod";
3
+ var SkillToolSchema = z.object({
4
+ skill: z.string().describe("Skill name to load")
5
+ });
6
+
7
+ // packages/core/src/env/skill/tool/skill-tool.ts
8
+ function buildSkillDescription(items) {
9
+ const lines = [
10
+ "Load a skill by name. Available skills:",
11
+ "",
12
+ "## Available Skills",
13
+ ""
14
+ ];
15
+ if (items.length === 0) {
16
+ lines.push("No skills available.");
17
+ } else {
18
+ for (const item of items) {
19
+ lines.push(`- **${item.name}**: "${item.description}"`);
20
+ }
21
+ }
22
+ lines.push("");
23
+ lines.push("Use the 'skill' parameter to specify which skill to load.");
24
+ return lines.join(`
25
+ `);
26
+ }
27
+ function createSkillTool(getSkillList, getSkill) {
28
+ return {
29
+ name: "skill",
30
+ description: buildSkillDescription(getSkillList()),
31
+ parameters: SkillToolSchema,
32
+ execute: async (args, ctx) => {
33
+ const params = SkillToolSchema.parse(args);
34
+ try {
35
+ const entry = getSkill(params.skill);
36
+ if (!entry) {
37
+ return {
38
+ success: false,
39
+ output: "",
40
+ error: `Skill not found: ${params.skill}`,
41
+ metadata: { execution_time_ms: 0 }
42
+ };
43
+ }
44
+ return {
45
+ success: true,
46
+ output: entry.content,
47
+ metadata: { execution_time_ms: 0 }
48
+ };
49
+ } catch (error) {
50
+ return {
51
+ success: false,
52
+ output: "",
53
+ error: error instanceof Error ? error.message : String(error),
54
+ metadata: { execution_time_ms: 0 }
55
+ };
56
+ }
57
+ }
58
+ };
59
+ }
60
+ export { SkillToolSchema, buildSkillDescription, createSkillTool };
@@ -0,0 +1,97 @@
1
+ import {
2
+ createHook
3
+ } from "./roy-agent-core-084qqd7t.js";
4
+ import {
5
+ HookManager
6
+ } from "./roy-agent-core-w75rafhy.js";
7
+
8
+ // packages/core/src/env/component.ts
9
+ class BaseComponent {
10
+ _status = "created";
11
+ _enabled = true;
12
+ env;
13
+ hookManager;
14
+ constructor() {
15
+ this.hookManager = new HookManager;
16
+ }
17
+ getStatus() {
18
+ return this._status;
19
+ }
20
+ getConfig() {
21
+ return {
22
+ name: this.name,
23
+ version: this.version,
24
+ enabled: this._enabled,
25
+ env: this.env
26
+ };
27
+ }
28
+ isEnvInitialized() {
29
+ return this._status !== "created";
30
+ }
31
+ setStatus(status) {
32
+ this._status = status;
33
+ }
34
+ getEnv() {
35
+ return this.env;
36
+ }
37
+ async init(config) {
38
+ if (config?.env) {
39
+ this.env = config.env;
40
+ }
41
+ this.setStatus("initializing");
42
+ try {
43
+ if (config?.name)
44
+ Object.defineProperty(this, "name", { value: config.name, writable: false });
45
+ if (config?.version)
46
+ Object.defineProperty(this, "version", { value: config.version, writable: false });
47
+ } catch {}
48
+ if (config?.enabled !== undefined)
49
+ this._enabled = config.enabled;
50
+ this.hookManager.setComponentInfo(this.name, this.version);
51
+ await this.onInit();
52
+ this.setStatus("running");
53
+ }
54
+ async start() {
55
+ if (this._started)
56
+ return;
57
+ this._started = true;
58
+ await this.onStart();
59
+ this.setStatus("running");
60
+ }
61
+ async stop() {
62
+ this.setStatus("stopping");
63
+ this.hookManager.clear();
64
+ await this.onStop();
65
+ this.setStatus("stopped");
66
+ }
67
+ async onInit() {}
68
+ async onStart() {}
69
+ async onStop() {}
70
+ registerHook(hookPoint, hook) {
71
+ this.hookManager.register(hookPoint, hook);
72
+ }
73
+ addHook(hookPoint, name, fn, priority) {
74
+ this.hookManager.register(hookPoint, createHook({ name, priority }, fn));
75
+ }
76
+ removeHook(hookPoint, name) {
77
+ return this.hookManager.unregister(hookPoint, name);
78
+ }
79
+ async executeHooks(hookPoint, data, metadata) {
80
+ await this.hookManager.execute(hookPoint, data, metadata);
81
+ }
82
+ getConfigComponent() {
83
+ return this.env?.getComponent("config");
84
+ }
85
+ getRuntimeConfig(key, defaultValue) {
86
+ const configComponent = this.getConfigComponent();
87
+ if (configComponent) {
88
+ const value = configComponent.get(key);
89
+ if (value !== undefined) {
90
+ return value;
91
+ }
92
+ }
93
+ return defaultValue;
94
+ }
95
+ }
96
+
97
+ export { BaseComponent };