@ai-setting/roy-agent-core 1.5.15-test → 1.5.16-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.
- package/dist/config/index.d.ts +1250 -0
- package/dist/config/index.js +32 -0
- package/dist/env/agent/index.d.ts +2279 -0
- package/dist/env/agent/index.js +24 -0
- package/dist/env/commands/index.d.ts +1131 -0
- package/dist/env/commands/index.js +14 -0
- package/dist/env/debug/formatters/index.d.ts +236 -0
- package/dist/env/debug/formatters/index.js +11 -0
- package/dist/env/debug/index.d.ts +1652 -0
- package/dist/env/debug/index.js +26 -0
- package/dist/env/hook/index.d.ts +279 -0
- package/dist/env/hook/index.js +29 -0
- package/dist/env/index.d.ts +3481 -0
- package/dist/env/index.js +82 -0
- package/dist/env/llm/index.d.ts +1760 -0
- package/dist/env/llm/index.js +40 -0
- package/dist/env/log-trace/index.d.ts +1574 -0
- package/dist/env/log-trace/index.js +83 -0
- package/dist/env/mcp/index.d.ts +1331 -0
- package/dist/env/mcp/index.js +39 -0
- package/dist/env/mcp/tool/index.d.ts +183 -0
- package/dist/env/mcp/tool/index.js +14 -0
- package/dist/env/memory/built-in/index.d.ts +232 -0
- package/dist/env/memory/built-in/index.js +11 -0
- package/dist/env/memory/index.d.ts +1799 -0
- package/dist/env/memory/index.js +56 -0
- package/dist/env/memory/plugin/index.d.ts +747 -0
- package/dist/env/memory/plugin/index.js +36 -0
- package/dist/env/prompt/index.d.ts +1164 -0
- package/dist/env/prompt/index.js +20 -0
- package/dist/env/session/index.d.ts +1908 -0
- package/dist/env/session/index.js +25 -0
- package/dist/env/session/storage/index.d.ts +564 -0
- package/dist/env/session/storage/index.js +18 -0
- package/dist/env/skill/index.d.ts +1266 -0
- package/dist/env/skill/index.js +34 -0
- package/dist/env/skill/tool/index.d.ts +193 -0
- package/dist/env/skill/tool/index.js +9 -0
- package/dist/env/task/delegate/index.d.ts +1612 -0
- package/dist/env/task/delegate/index.js +18 -0
- package/dist/env/task/events/index.d.ts +171 -0
- package/dist/env/task/events/index.js +7 -0
- package/dist/env/task/hooks/index.d.ts +624 -0
- package/dist/env/task/hooks/index.js +7 -0
- package/dist/env/task/index.d.ts +1553 -0
- package/dist/env/task/index.js +34 -0
- package/dist/env/task/plugins/index.d.ts +466 -0
- package/dist/env/task/plugins/index.js +23 -0
- package/dist/env/task/storage/index.d.ts +241 -0
- package/dist/env/task/storage/index.js +14 -0
- package/dist/env/task/tools/index.d.ts +1485 -0
- package/dist/env/task/tools/index.js +17 -0
- package/dist/env/task/tools/operation/index.d.ts +1484 -0
- package/dist/env/task/tools/operation/index.js +15 -0
- package/dist/env/tool/built-in/index.d.ts +218 -0
- package/dist/env/tool/built-in/index.js +25 -0
- package/dist/env/tool/index.d.ts +1396 -0
- package/dist/env/tool/index.js +39 -0
- package/dist/env/workflow/decorators/index.d.ts +2161 -0
- package/dist/env/workflow/decorators/index.js +27 -0
- package/dist/env/workflow/engine/index.d.ts +3453 -0
- package/dist/env/workflow/engine/index.js +28 -0
- package/dist/env/workflow/index.d.ts +3546 -0
- package/dist/env/workflow/index.js +136 -0
- package/dist/env/workflow/nodes/index.d.ts +2092 -0
- package/dist/env/workflow/nodes/index.js +19 -0
- package/dist/env/workflow/service/index.d.ts +227 -0
- package/dist/env/workflow/service/index.js +13 -0
- package/dist/env/workflow/storage/index.d.ts +165 -0
- package/dist/env/workflow/storage/index.js +27 -0
- package/dist/env/workflow/tools/index.d.ts +416 -0
- package/dist/env/workflow/tools/index.js +159 -0
- package/dist/env/workflow/types/index.d.ts +2255 -0
- package/dist/env/workflow/types/index.js +98 -0
- package/dist/env/workflow/utils/index.d.ts +2031 -0
- package/dist/env/workflow/utils/index.js +637 -0
- package/dist/index.d.ts +7858 -0
- package/dist/index.js +399 -0
- package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +258 -0
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +36 -0
- package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +349 -0
- package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +117 -0
- package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +200 -0
- package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +299 -0
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +206 -0
- package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +350 -0
- package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +180 -0
- package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +408 -0
- package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +284 -0
- package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +762 -0
- package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +10 -0
- package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +922 -0
- package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +15 -0
- package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +1130 -0
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +653 -0
- package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +93 -0
- package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +872 -0
- package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +64 -0
- package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +378 -0
- package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +492 -0
- package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +52 -0
- package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +171 -0
- package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +862 -0
- package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +1387 -0
- package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +208 -0
- package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +139 -0
- package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +534 -0
- package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +204 -0
- package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +603 -0
- package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +97 -0
- package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +587 -0
- package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +176 -0
- package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +60 -0
- package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +442 -0
- package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +57 -0
- package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +66 -0
- package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +10 -0
- package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +267 -0
- package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +584 -0
- package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +102 -0
- package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +549 -0
- package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +15 -0
- package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +213 -0
- package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +812 -0
- package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +1316 -0
- package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +1205 -0
- package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +328 -0
- package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +20 -0
- package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +2098 -0
- package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +419 -0
- package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +368 -0
- package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +377 -0
- package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +172 -0
- package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +103 -0
- package/package.json +1 -1
|
@@ -0,0 +1,534 @@
|
|
|
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 };
|