@ai-setting/roy-agent-core 1.5.13-test → 1.5.15-test

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 (141) hide show
  1. package/package.json +1 -1
  2. package/dist/config/index.d.ts +0 -1250
  3. package/dist/config/index.js +0 -32
  4. package/dist/env/agent/index.d.ts +0 -2279
  5. package/dist/env/agent/index.js +0 -24
  6. package/dist/env/commands/index.d.ts +0 -1131
  7. package/dist/env/commands/index.js +0 -14
  8. package/dist/env/debug/formatters/index.d.ts +0 -236
  9. package/dist/env/debug/formatters/index.js +0 -11
  10. package/dist/env/debug/index.d.ts +0 -1652
  11. package/dist/env/debug/index.js +0 -26
  12. package/dist/env/hook/index.d.ts +0 -279
  13. package/dist/env/hook/index.js +0 -29
  14. package/dist/env/index.d.ts +0 -3481
  15. package/dist/env/index.js +0 -82
  16. package/dist/env/llm/index.d.ts +0 -1760
  17. package/dist/env/llm/index.js +0 -40
  18. package/dist/env/log-trace/index.d.ts +0 -1574
  19. package/dist/env/log-trace/index.js +0 -83
  20. package/dist/env/mcp/index.d.ts +0 -1331
  21. package/dist/env/mcp/index.js +0 -39
  22. package/dist/env/mcp/tool/index.d.ts +0 -183
  23. package/dist/env/mcp/tool/index.js +0 -14
  24. package/dist/env/memory/built-in/index.d.ts +0 -232
  25. package/dist/env/memory/built-in/index.js +0 -11
  26. package/dist/env/memory/index.d.ts +0 -1799
  27. package/dist/env/memory/index.js +0 -56
  28. package/dist/env/memory/plugin/index.d.ts +0 -747
  29. package/dist/env/memory/plugin/index.js +0 -36
  30. package/dist/env/prompt/index.d.ts +0 -1164
  31. package/dist/env/prompt/index.js +0 -20
  32. package/dist/env/session/index.d.ts +0 -1908
  33. package/dist/env/session/index.js +0 -25
  34. package/dist/env/session/storage/index.d.ts +0 -564
  35. package/dist/env/session/storage/index.js +0 -18
  36. package/dist/env/skill/index.d.ts +0 -1266
  37. package/dist/env/skill/index.js +0 -34
  38. package/dist/env/skill/tool/index.d.ts +0 -193
  39. package/dist/env/skill/tool/index.js +0 -9
  40. package/dist/env/task/delegate/index.d.ts +0 -1612
  41. package/dist/env/task/delegate/index.js +0 -18
  42. package/dist/env/task/events/index.d.ts +0 -171
  43. package/dist/env/task/events/index.js +0 -7
  44. package/dist/env/task/hooks/index.d.ts +0 -624
  45. package/dist/env/task/hooks/index.js +0 -7
  46. package/dist/env/task/index.d.ts +0 -1553
  47. package/dist/env/task/index.js +0 -34
  48. package/dist/env/task/plugins/index.d.ts +0 -466
  49. package/dist/env/task/plugins/index.js +0 -23
  50. package/dist/env/task/storage/index.d.ts +0 -241
  51. package/dist/env/task/storage/index.js +0 -14
  52. package/dist/env/task/tools/index.d.ts +0 -1485
  53. package/dist/env/task/tools/index.js +0 -17
  54. package/dist/env/task/tools/operation/index.d.ts +0 -1484
  55. package/dist/env/task/tools/operation/index.js +0 -15
  56. package/dist/env/tool/built-in/index.d.ts +0 -218
  57. package/dist/env/tool/built-in/index.js +0 -25
  58. package/dist/env/tool/index.d.ts +0 -1396
  59. package/dist/env/tool/index.js +0 -39
  60. package/dist/env/workflow/decorators/index.d.ts +0 -2161
  61. package/dist/env/workflow/decorators/index.js +0 -27
  62. package/dist/env/workflow/engine/index.d.ts +0 -3453
  63. package/dist/env/workflow/engine/index.js +0 -28
  64. package/dist/env/workflow/index.d.ts +0 -3546
  65. package/dist/env/workflow/index.js +0 -136
  66. package/dist/env/workflow/nodes/index.d.ts +0 -2092
  67. package/dist/env/workflow/nodes/index.js +0 -19
  68. package/dist/env/workflow/service/index.d.ts +0 -227
  69. package/dist/env/workflow/service/index.js +0 -13
  70. package/dist/env/workflow/storage/index.d.ts +0 -165
  71. package/dist/env/workflow/storage/index.js +0 -27
  72. package/dist/env/workflow/tools/index.d.ts +0 -416
  73. package/dist/env/workflow/tools/index.js +0 -159
  74. package/dist/env/workflow/types/index.d.ts +0 -2255
  75. package/dist/env/workflow/types/index.js +0 -98
  76. package/dist/env/workflow/utils/index.d.ts +0 -2031
  77. package/dist/env/workflow/utils/index.js +0 -637
  78. package/dist/index.d.ts +0 -7858
  79. package/dist/index.js +0 -399
  80. package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +0 -258
  81. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
  82. package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +0 -349
  83. package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +0 -117
  84. package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +0 -11
  85. package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +0 -393
  86. package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +0 -200
  87. package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +0 -299
  88. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
  89. package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +0 -393
  90. package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
  91. package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +0 -180
  92. package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +0 -408
  93. package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +0 -284
  94. package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +0 -762
  95. package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +0 -10
  96. package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +0 -14
  97. package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +0 -922
  98. package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +0 -15
  99. package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +0 -1130
  100. package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
  101. package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +0 -653
  102. package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +0 -93
  103. package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +0 -872
  104. package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
  105. package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +0 -64
  106. package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +0 -378
  107. package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +0 -492
  108. package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +0 -52
  109. package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +0 -171
  110. package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +0 -862
  111. package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
  112. package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +0 -208
  113. package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +0 -139
  114. package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +0 -534
  115. package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +0 -204
  116. package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
  117. package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +0 -97
  118. package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +0 -587
  119. package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +0 -176
  120. package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +0 -60
  121. package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +0 -442
  122. package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +0 -57
  123. package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +0 -66
  124. package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +0 -10
  125. package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +0 -267
  126. package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +0 -584
  127. package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +0 -102
  128. package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +0 -549
  129. package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +0 -15
  130. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
  131. package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +0 -812
  132. package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +0 -1316
  133. package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +0 -1205
  134. package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +0 -328
  135. package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +0 -20
  136. package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +0 -2098
  137. package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +0 -419
  138. package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +0 -368
  139. package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +0 -377
  140. package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +0 -172
  141. package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +0 -103
@@ -1,534 +0,0 @@
1
- import {
2
- BackgroundTaskManager,
3
- createDelegateTool,
4
- createStopTool
5
- } from "./roy-agent-core-vf215qfv.js";
6
- import {
7
- SQLiteTaskStore,
8
- getDefaultTaskDbPath
9
- } from "./roy-agent-core-bvr1761x.js";
10
- import {
11
- completeTaskTool,
12
- createTaskTool,
13
- deleteTaskTool,
14
- getTaskTool,
15
- listTasksTool,
16
- updateTaskTool
17
- } from "./roy-agent-core-wa1kzqky.js";
18
- import {
19
- createOperationTool,
20
- deleteOperationTool,
21
- getOperationTool,
22
- listOperationsTool,
23
- updateOperationTool
24
- } from "./roy-agent-core-t94ktchq.js";
25
- import {
26
- TaskHookPoints
27
- } from "./roy-agent-core-92z6t4he.js";
28
- import {
29
- TaskEntityEventTypes
30
- } from "./roy-agent-core-8gxth0eh.js";
31
- import {
32
- envKeyToConfigKey
33
- } from "./roy-agent-core-qxhq8ven.js";
34
- import {
35
- BaseComponent
36
- } from "./roy-agent-core-kkbwepqb.js";
37
- import {
38
- globalHookManager
39
- } from "./roy-agent-core-gjq1yk68.js";
40
- import {
41
- createLogger,
42
- init_logger
43
- } from "./roy-agent-core-44hnfb02.js";
44
-
45
- // src/env/task/task-component.ts
46
- init_logger();
47
-
48
- // src/env/task/task-config-registration.ts
49
- var TASK_DEFAULTS = {
50
- "task.storage.type": "sqlite",
51
- "task.storage.dbPath": undefined
52
- };
53
- var TASK_CONFIG_REGISTRATION = {
54
- name: "task",
55
- sources: [
56
- { type: "env", envPrefix: "TASK", priority: 20, watch: false }
57
- ],
58
- keys: [
59
- { key: "task.storage.type", sources: ["env", "file"] },
60
- { key: "task.storage.dbPath", sources: ["env", "file"] }
61
- ]
62
- };
63
-
64
- // src/env/task/tag-service.ts
65
- init_logger();
66
- var logger = createLogger("task:tag");
67
-
68
- class DefaultTagService {
69
- store;
70
- constructor(store) {
71
- this.store = store;
72
- }
73
- async createTag(name) {
74
- const tag = await this.store.createTag(name);
75
- logger.debug(`[TagService] Created tag: ${tag.name} (id=${tag.id})`);
76
- return tag;
77
- }
78
- async getTag(id) {
79
- return this.store.getTag(id);
80
- }
81
- async getTagByName(name) {
82
- return this.store.getTagByName(name);
83
- }
84
- async listTags(options) {
85
- return this.store.listTags(options);
86
- }
87
- async searchTags(options) {
88
- return this.store.searchTags(options);
89
- }
90
- async deleteTag(id) {
91
- const result = await this.store.deleteTag(id);
92
- if (result) {
93
- logger.debug(`[TagService] Deleted tag id=${id}`);
94
- }
95
- return result;
96
- }
97
- async addTagsToTask(taskId, tagIds) {
98
- await this.store.addTagsToTask(taskId, tagIds);
99
- logger.debug(`[TagService] Added ${tagIds.length} tags to task ${taskId}`);
100
- }
101
- async removeTagsFromTask(taskId, tagIds) {
102
- await this.store.removeTagsFromTask(taskId, tagIds);
103
- logger.debug(`[TagService] Removed ${tagIds.length} tags from task ${taskId}`);
104
- }
105
- async getTagsForTask(taskId) {
106
- return this.store.getTagsForTask(taskId);
107
- }
108
- async getTaskIdsByTags(tagNames) {
109
- return this.store.getTaskIdsByTags(tagNames);
110
- }
111
- async findSimilarTasks(taskId, limit = 5) {
112
- return this.store.findSimilarTasks(taskId, limit);
113
- }
114
- async searchTasks(query, limit = 20) {
115
- return this.store.searchTasks(query, limit);
116
- }
117
- async searchTasksByKeywords(keywords, options) {
118
- return this.store.searchTasksByKeywords(keywords, options);
119
- }
120
- async findSimilarTasksByKeywords(keywords, options) {
121
- return this.store.findSimilarTasksByKeywords(keywords, options);
122
- }
123
- async syncTagsToTask(taskId, tagNames) {
124
- const tagIds = [];
125
- for (const name of tagNames) {
126
- let tag = await this.store.getTagByName(name);
127
- if (!tag) {
128
- tag = await this.store.createTag(name);
129
- }
130
- tagIds.push(tag.id);
131
- }
132
- const currentTags = await this.store.getTagsForTask(taskId);
133
- const currentTagIds = new Set(currentTags.map((t) => t.id));
134
- const newTagIds = new Set(tagIds);
135
- const toAdd = tagIds.filter((id) => !currentTagIds.has(id));
136
- const toRemove = currentTags.filter((t) => !newTagIds.has(t.id)).map((t) => t.id);
137
- if (toRemove.length > 0) {
138
- await this.store.removeTagsFromTask(taskId, toRemove);
139
- }
140
- if (toAdd.length > 0) {
141
- await this.store.addTagsToTask(taskId, toAdd);
142
- }
143
- await this.store.updateTaskTags(taskId, tagNames);
144
- logger.info(`[TagService] Synced tags for task ${taskId}: ${tagNames.join(", ")}`);
145
- }
146
- }
147
-
148
- // src/env/task/task-component.ts
149
- var logger2 = createLogger("task");
150
-
151
- class TaskComponent extends BaseComponent {
152
- name = "task";
153
- version = "1.0.0";
154
- store;
155
- config;
156
- toolComponent;
157
- backgroundTaskManager;
158
- configComponent;
159
- tagService;
160
- plugins = new Map;
161
- publishEvent(type, payload, sessionId) {
162
- if (this.env?.pushEnvEvent) {
163
- this.env.pushEnvEvent({
164
- type,
165
- payload,
166
- metadata: {
167
- source: "task.component",
168
- trigger_session_id: sessionId
169
- }
170
- });
171
- logger2.info(`[TaskComponent] Event published: ${type}`);
172
- }
173
- }
174
- constructor() {
175
- super();
176
- }
177
- async init(config) {
178
- await super.init(config);
179
- const options = config?.options;
180
- if (!options?.configComponent) {
181
- throw new Error("ConfigComponent is required for TaskComponent initialization");
182
- }
183
- this.configComponent = options.configComponent;
184
- await this.registerConfig(options);
185
- this.setStatus("running");
186
- logger2.info("[TaskComponent] Initialized");
187
- }
188
- async registerConfig(options) {
189
- const configComponent = this.configComponent;
190
- if (!configComponent)
191
- return;
192
- const { configPath, envPrefix, config } = options;
193
- const prefix = envPrefix ?? "TASK";
194
- configComponent.registerComponent(TASK_CONFIG_REGISTRATION);
195
- if (configPath) {
196
- configComponent.registerSource({
197
- type: "file",
198
- relativePath: configPath,
199
- optional: true,
200
- watch: false
201
- });
202
- }
203
- configComponent.registerSource({
204
- type: "env",
205
- envPrefix: prefix,
206
- priority: 20,
207
- watch: false
208
- });
209
- await configComponent.load("task");
210
- for (const envKey of Object.keys(process.env)) {
211
- const configKey = envKeyToConfigKey(envKey, prefix, "task");
212
- if (!configKey)
213
- continue;
214
- const value = process.env[envKey];
215
- if (value !== undefined) {
216
- await configComponent.set(configKey, value);
217
- }
218
- }
219
- for (const [key, value] of Object.entries(TASK_DEFAULTS)) {
220
- if (configComponent.get(key) === undefined) {
221
- await configComponent.set(key, value);
222
- }
223
- }
224
- if (configComponent.get("task.storage.dbPath") === undefined) {
225
- await configComponent.set("task.storage.dbPath", getDefaultTaskDbPath());
226
- }
227
- if (config) {
228
- const flatConfig = this.flattenConfig(config);
229
- for (const [key, value] of Object.entries(flatConfig)) {
230
- await configComponent.set(key, value);
231
- }
232
- }
233
- this.registerConfigWatcher(configComponent);
234
- await this.initStore();
235
- this.tagService = new DefaultTagService(this.store);
236
- }
237
- async initStore() {
238
- const configComponent = this.configComponent;
239
- if (!configComponent)
240
- return;
241
- const storageType = configComponent.get("task.storage.type") ?? "sqlite";
242
- const dbPath = configComponent.get("task.storage.dbPath");
243
- if (storageType === "sqlite") {
244
- this.store = new SQLiteTaskStore(dbPath);
245
- logger2.info(`[TaskComponent] Using SQLite storage: ${dbPath || "default path"}`);
246
- } else {
247
- this.store = new SQLiteTaskStore;
248
- logger2.info("[TaskComponent] Using SQLite storage (default)");
249
- }
250
- }
251
- flattenConfig(obj, prefix = "task") {
252
- const result = {};
253
- for (const [key, value] of Object.entries(obj)) {
254
- const fullKey = `${prefix}.${key}`;
255
- if (value && typeof value === "object" && !Array.isArray(value)) {
256
- Object.assign(result, this.flattenConfig(value, fullKey));
257
- } else {
258
- result[fullKey] = value;
259
- }
260
- }
261
- return result;
262
- }
263
- registerConfigWatcher(configComponent) {
264
- if (typeof configComponent.watch !== "function") {
265
- return;
266
- }
267
- this.configWatcher = configComponent.watch("task.*", (event) => {
268
- this.onConfigChange(event);
269
- });
270
- }
271
- onConfigChange(event) {
272
- logger2.info(`[TaskComponent] Config changed: ${event.key}`, {
273
- oldValue: event.oldValue,
274
- newValue: event.newValue
275
- });
276
- if (event.key === "task.storage.type" || event.key === "task.storage.dbPath") {
277
- this.initStore();
278
- }
279
- }
280
- configWatcher;
281
- async start() {
282
- await super.start();
283
- this.backgroundTaskManager = new BackgroundTaskManager(this.env);
284
- this.toolComponent = this.env?.getComponent("tool");
285
- if (this.toolComponent) {
286
- await this.registerTools();
287
- } else {
288
- logger2.warn("[TaskComponent] ToolComponent not found, skipping tool registration");
289
- }
290
- }
291
- async stop() {
292
- if (this.configWatcher) {
293
- this.configWatcher();
294
- this.configWatcher = undefined;
295
- }
296
- if (this.backgroundTaskManager) {
297
- this.backgroundTaskManager.dispose();
298
- }
299
- if (this.store) {
300
- await this.store.close();
301
- }
302
- await super.stop();
303
- }
304
- async registerTools() {
305
- if (!this.toolComponent)
306
- return;
307
- const taskToolsList = [
308
- createTaskTool(this),
309
- getTaskTool(this),
310
- listTasksTool(this),
311
- updateTaskTool(this),
312
- deleteTaskTool(this),
313
- completeTaskTool(this)
314
- ];
315
- const operationToolsList = [
316
- createOperationTool(this),
317
- getOperationTool(this),
318
- listOperationsTool(this),
319
- updateOperationTool(this),
320
- deleteOperationTool(this)
321
- ];
322
- const delegateTools = [
323
- createDelegateTool(this),
324
- createStopTool(this.backgroundTaskManager)
325
- ];
326
- for (const tool of [...taskToolsList, ...operationToolsList, ...delegateTools]) {
327
- this.toolComponent.register(tool);
328
- logger2.info(`[TaskComponent] Registered tool: ${tool.name}`);
329
- }
330
- }
331
- async executeHook(hookPoint, data, metadata = {}) {
332
- const ctx = {
333
- component: { name: this.name, version: this.version },
334
- data,
335
- metadata,
336
- phase: hookPoint.includes("before") ? "before" : "after",
337
- hookPoint
338
- };
339
- await globalHookManager.execute(hookPoint, ctx, metadata);
340
- }
341
- async createTask(options) {
342
- const sessionId = options.sessionId;
343
- const createCtx = {
344
- options: { ...options },
345
- sessionId,
346
- tagService: this.tagService
347
- };
348
- await this.executeHook(TaskHookPoints.BEFORE_CREATE, createCtx);
349
- const task = await this.store.createTask(createCtx.options);
350
- await this.store.createOperation({
351
- taskId: task.id,
352
- sessionId,
353
- actionType: "create",
354
- actionTitle: `Task created: ${task.title}`,
355
- actionDescription: task.description || ""
356
- });
357
- const resultCtx = {
358
- task,
359
- sessionId,
360
- tagService: this.tagService
361
- };
362
- await this.executeHook(TaskHookPoints.AFTER_CREATE, resultCtx);
363
- this.publishEvent(TaskEntityEventTypes.CREATED, { task, sessionId }, sessionId);
364
- logger2.info(`[TaskComponent] Task created: ${task.id} - ${task.title}`);
365
- return task;
366
- }
367
- async getTask(id) {
368
- return this.store.getTask(id);
369
- }
370
- async getTaskWithOperations(id) {
371
- const task = await this.store.getTask(id);
372
- if (!task)
373
- return;
374
- const operations = await this.store.listOperations({ taskId: id });
375
- return { task, operations };
376
- }
377
- async updateTask(id, options) {
378
- const updateCtx = {
379
- id,
380
- options: { ...options },
381
- tagService: this.tagService
382
- };
383
- await this.executeHook(TaskHookPoints.BEFORE_UPDATE, updateCtx);
384
- const task = await this.store.updateTask(id, updateCtx.options);
385
- if (task) {
386
- const resultCtx = {
387
- task,
388
- changes: options,
389
- tagService: this.tagService
390
- };
391
- await this.executeHook(TaskHookPoints.AFTER_UPDATE, resultCtx);
392
- this.publishEvent(TaskEntityEventTypes.UPDATED, { task, changes: options, sessionId: "" }, "");
393
- logger2.info(`[TaskComponent] Task updated: ${id}`);
394
- }
395
- return task;
396
- }
397
- async deleteTask(id) {
398
- const deleteCtx = { id };
399
- await this.executeHook(TaskHookPoints.BEFORE_DELETE, deleteCtx);
400
- const result = await this.store.deleteTask(id);
401
- const resultCtx = { id, deleted: result };
402
- await this.executeHook(TaskHookPoints.AFTER_DELETE, resultCtx);
403
- if (result) {
404
- this.publishEvent(TaskEntityEventTypes.DELETED, { taskId: id, sessionId: "" }, "");
405
- logger2.info(`[TaskComponent] Task deleted: ${id}`);
406
- }
407
- return result;
408
- }
409
- async listTasks(options) {
410
- return this.store.listTasks(options);
411
- }
412
- async completeTask(id, sessionId) {
413
- const task = await this.store.updateTask(id, {
414
- status: "completed",
415
- progress: 100
416
- });
417
- if (task) {
418
- await this.createOperation({
419
- taskId: id,
420
- sessionId,
421
- actionType: "completed",
422
- actionTitle: "Task completed"
423
- });
424
- this.publishEvent(TaskEntityEventTypes.COMPLETED, { task, sessionId }, sessionId);
425
- logger2.info(`[TaskComponent] Task completed: ${id}`);
426
- }
427
- return task;
428
- }
429
- async createOperation(options) {
430
- const createCtx = {
431
- options: { ...options }
432
- };
433
- await this.executeHook(TaskHookPoints.OPERATION_BEFORE_CREATE, createCtx);
434
- const op = await this.store.createOperation(createCtx.options);
435
- const resultCtx = { operation: op };
436
- await this.executeHook(TaskHookPoints.OPERATION_AFTER_CREATE, resultCtx);
437
- this.publishEvent(TaskEntityEventTypes.OPERATION_ADDED, { operation: op, taskId: op.taskId }, op.sessionId);
438
- logger2.info(`[TaskComponent] Operation created: ${op.id} for task ${op.taskId}`);
439
- return op;
440
- }
441
- async getOperation(id) {
442
- return this.store.getOperation(id);
443
- }
444
- async updateOperation(id, updates) {
445
- return this.store.updateOperation(id, updates);
446
- }
447
- async deleteOperation(id) {
448
- return this.store.deleteOperation(id);
449
- }
450
- async listOperations(options) {
451
- return this.store.listOperations(options);
452
- }
453
- getTagService() {
454
- return this.tagService;
455
- }
456
- registerPlugin(plugin) {
457
- this.plugins.set(plugin.name, plugin);
458
- const llmComponent = this.env?.getComponent("llm");
459
- plugin.setComponents?.(llmComponent, this);
460
- const getRequiredAgents = plugin.constructor.getRequiredAgents;
461
- if (typeof getRequiredAgents === "function") {
462
- const agentComponent = this.env?.getComponent("agent");
463
- if (agentComponent) {
464
- try {
465
- const agents = getRequiredAgents();
466
- for (const agentConfig of agents) {
467
- agentComponent.registerAgent(agentConfig.name, agentConfig);
468
- }
469
- } catch (err) {
470
- logger2.warn(`Failed to auto-register agents for plugin ${plugin.name}: ${err}`);
471
- }
472
- }
473
- }
474
- for (const hook of plugin.hooks) {
475
- const pluginConfig = plugin.config;
476
- const priority = hook.priority ?? pluginConfig?.priority ?? 0;
477
- const hookName = `${this.name}:${plugin.name}:${hook.point}`;
478
- const pluginRef = plugin;
479
- globalHookManager.register(hook.point, {
480
- name: hookName,
481
- priority,
482
- execute: async (ctx) => {
483
- const pluginCtx = {
484
- component: ctx.component,
485
- data: ctx.data,
486
- metadata: ctx.metadata,
487
- phase: ctx.phase,
488
- hookPoint: hook.point
489
- };
490
- await pluginRef.execute(pluginCtx);
491
- }
492
- });
493
- }
494
- logger2.info(`[TaskComponent] Registered plugin: ${plugin.name}`, {
495
- hooks: plugin.hooks.map((h) => h.point)
496
- });
497
- }
498
- unregisterPlugin(name) {
499
- const plugin = this.plugins.get(name);
500
- if (!plugin)
501
- return false;
502
- for (const hook of plugin.hooks) {
503
- globalHookManager.unregister(hook.point, `${this.name}:${name}`);
504
- }
505
- this.plugins.delete(name);
506
- logger2.info(`[TaskComponent] Unregistered plugin: ${name}`);
507
- return true;
508
- }
509
- listPlugins() {
510
- return Array.from(this.plugins.values());
511
- }
512
- }
513
- // src/env/task/types.ts
514
- import { z } from "zod";
515
- var TaskStatusEnum = z.enum(["todo", "active", "completed", "paused", "cancelled"]);
516
- var TaskPriorityEnum = z.enum(["low", "medium", "high"]);
517
- var ActionTypeEnum = z.enum([
518
- "create",
519
- "progress",
520
- "milestone",
521
- "problem",
522
- "solution",
523
- "decision",
524
- "review",
525
- "completed",
526
- "workflow_extracted"
527
- ]);
528
- var TaskConfigSchema = z.object({
529
- storage: z.object({
530
- type: z.enum(["memory", "sqlite"]).default("sqlite"),
531
- dbPath: z.string().optional()
532
- }).default({})
533
- }).default({});
534
- export { TaskComponent, TaskStatusEnum, TaskPriorityEnum, ActionTypeEnum, TaskConfigSchema };