@ai-setting/roy-agent-core 1.5.36 → 1.5.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/index.js +4 -3
- package/dist/env/agent/index.js +10 -9
- package/dist/env/commands/index.js +7 -6
- package/dist/env/context/index.js +21 -0
- package/dist/env/debug/index.js +4 -3
- package/dist/env/event-source/index.js +12 -6
- package/dist/env/hook/index.js +2 -1
- package/dist/env/index.js +41 -18
- package/dist/env/llm/index.js +8 -7
- package/dist/env/log-trace/index.js +10 -9
- package/dist/env/mcp/index.js +8 -7
- package/dist/env/mcp/tool/index.js +4 -4
- package/dist/env/memory/index.js +12 -11
- package/dist/env/memory/plugin/index.js +4 -4
- package/dist/env/plugin/index.js +18 -0
- package/dist/env/prompt/index.js +7 -6
- package/dist/env/session/index.js +11 -10
- package/dist/env/session/storage/index.js +2 -6
- package/dist/env/skill/index.js +7 -6
- package/dist/env/task/delegate/index.js +6 -5
- package/dist/env/task/index.js +10 -8
- package/dist/env/task/plugins/index.js +13 -6
- package/dist/env/task/storage/index.js +4 -4
- package/dist/env/tool/built-in/index.js +3 -3
- package/dist/env/tool/index.js +8 -7
- package/dist/env/workflow/engine/index.js +5 -5
- package/dist/env/workflow/index.js +9 -8
- package/dist/env/workflow/storage/index.js +5 -5
- package/dist/env/workflow/tools/index.js +3 -3
- package/dist/env/workflow/utils/index.js +4 -4
- package/dist/index.js +67 -60
- package/dist/shared/@ai-setting/{roy-agent-core-44hnfb02.js → roy-agent-core-10n2jh7p.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xt3fx7m1.js → roy-agent-core-15x8fe5h.js} +38 -56
- package/dist/shared/@ai-setting/{roy-agent-core-1akcqxj9.js → roy-agent-core-1bfmxx89.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ty94k28r.js → roy-agent-core-2jnzv9at.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-3jywqmdd.js → roy-agent-core-2x07feb7.js} +317 -65
- package/dist/shared/@ai-setting/{roy-agent-core-cefh9hjv.js → roy-agent-core-4jqq077c.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xs5rsgat.js → roy-agent-core-58k274fg.js} +108 -23
- package/dist/shared/@ai-setting/{roy-agent-core-np1w5dpe.js → roy-agent-core-728h32vx.js} +268 -35
- package/dist/shared/@ai-setting/{roy-agent-core-jfh9q2qh.js → roy-agent-core-7b35emr7.js} +0 -15
- package/dist/shared/@ai-setting/{roy-agent-core-3rr5k71j.js → roy-agent-core-8n4bz6y3.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-zpn0bqa8.js → roy-agent-core-9ffsvvcf.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-az13yzmc.js +11 -0
- package/dist/shared/@ai-setting/{roy-agent-core-0wdjp769.js → roy-agent-core-b4wd9tn6.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-6kvtahqv.js → roy-agent-core-c3ct1346.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-psv4v63c.js → roy-agent-core-c6592r3c.js} +19 -2
- package/dist/shared/@ai-setting/{roy-agent-core-c2wjwx16.js → roy-agent-core-c8f2hync.js} +305 -287
- package/dist/shared/@ai-setting/roy-agent-core-cevpwnq7.js +147 -0
- package/dist/shared/@ai-setting/{roy-agent-core-hkb529dw.js → roy-agent-core-dxbsc1zy.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-vqspcspb.js → roy-agent-core-e130w7mv.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-j0ke54vy.js → roy-agent-core-ee6nnnqw.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-qdmt6nz7.js → roy-agent-core-eg6nv09z.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-hd1z20yq.js → roy-agent-core-frx4p6d1.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-bvr1761x.js → roy-agent-core-hsxn8m1j.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-86gphny5.js → roy-agent-core-jqy2mdyq.js} +15 -1
- package/dist/shared/@ai-setting/{roy-agent-core-c0d3dtjd.js → roy-agent-core-kajktp3d.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-eajcvp4e.js → roy-agent-core-kwhv9dcd.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-r9ezzemr.js → roy-agent-core-m0wp34r4.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fg1kxf70.js → roy-agent-core-nqgrjja0.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-d7cyjkf7.js → roy-agent-core-pwkk12p4.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-97ma0pr5.js → roy-agent-core-pxcrzyv9.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-zgypchmt.js → roy-agent-core-q5qj0fes.js} +19 -11
- package/dist/shared/@ai-setting/{roy-agent-core-sx7wsvnn.js → roy-agent-core-qakqwbbh.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-qfdp3pvq.js → roy-agent-core-rsybkb38.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-ty33mnr7.js +14 -0
- package/dist/shared/@ai-setting/{roy-agent-core-3prpabp8.js → roy-agent-core-v53rfk99.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-wjd5kars.js → roy-agent-core-wb43x8hd.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-e2vk2qh7.js → roy-agent-core-yc543gnq.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-gf2c2pxr.js → roy-agent-core-ycg9rk6z.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-z33en0cz.js +44 -0
- package/dist/shared/@ai-setting/{roy-agent-core-by55z88t.js → roy-agent-core-zrja5v78.js} +11 -11
- package/dist/shared/@ai-setting/{roy-agent-core-wft9ra24.js → roy-agent-core-zwp3jp02.js} +4 -4
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
BackgroundTaskManager,
|
|
3
3
|
createDelegateTool,
|
|
4
4
|
createStopTool
|
|
5
|
-
} from "./roy-agent-core-
|
|
5
|
+
} from "./roy-agent-core-v53rfk99.js";
|
|
6
6
|
import {
|
|
7
7
|
SQLiteTaskStore,
|
|
8
8
|
getDefaultTaskDbPath
|
|
9
|
-
} from "./roy-agent-core-
|
|
9
|
+
} from "./roy-agent-core-hsxn8m1j.js";
|
|
10
10
|
import {
|
|
11
11
|
completeTaskTool,
|
|
12
12
|
createTaskTool,
|
|
@@ -28,19 +28,26 @@ import {
|
|
|
28
28
|
import {
|
|
29
29
|
TaskEntityEventTypes
|
|
30
30
|
} from "./roy-agent-core-8gxth0eh.js";
|
|
31
|
+
import {
|
|
32
|
+
TracedAs,
|
|
33
|
+
init_decorator
|
|
34
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
31
35
|
import {
|
|
32
36
|
envKeyToConfigKey
|
|
33
37
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
34
38
|
import {
|
|
35
39
|
BaseComponent
|
|
36
|
-
} from "./roy-agent-core-
|
|
40
|
+
} from "./roy-agent-core-4jqq077c.js";
|
|
37
41
|
import {
|
|
38
42
|
globalHookManager
|
|
39
|
-
} from "./roy-agent-core-
|
|
43
|
+
} from "./roy-agent-core-jqy2mdyq.js";
|
|
40
44
|
import {
|
|
41
45
|
createLogger,
|
|
42
46
|
init_logger
|
|
43
|
-
} from "./roy-agent-core-
|
|
47
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
48
|
+
import {
|
|
49
|
+
__legacyDecorateClassTS
|
|
50
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
44
51
|
|
|
45
52
|
// src/env/task/task-component.ts
|
|
46
53
|
init_logger();
|
|
@@ -146,6 +153,7 @@ class DefaultTagService {
|
|
|
146
153
|
}
|
|
147
154
|
|
|
148
155
|
// src/env/task/task-component.ts
|
|
156
|
+
init_decorator();
|
|
149
157
|
var logger2 = createLogger("task");
|
|
150
158
|
|
|
151
159
|
class TaskComponent extends BaseComponent {
|
|
@@ -410,7 +418,7 @@ class TaskComponent extends BaseComponent {
|
|
|
410
418
|
return this.store.listTasks(options);
|
|
411
419
|
}
|
|
412
420
|
async completeTask(id, sessionId) {
|
|
413
|
-
const task = await this.
|
|
421
|
+
const task = await this.updateTask(id, {
|
|
414
422
|
status: "completed",
|
|
415
423
|
progress: 100
|
|
416
424
|
});
|
|
@@ -453,63 +461,37 @@ class TaskComponent extends BaseComponent {
|
|
|
453
461
|
getTagService() {
|
|
454
462
|
return this.tagService;
|
|
455
463
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
});
|
|
464
|
+
registerHook(hookPoint, hook) {
|
|
465
|
+
globalHookManager.register(hookPoint, hook);
|
|
466
|
+
this.plugins.set(this.makePluginKey(hookPoint, hook.name), hook);
|
|
467
|
+
logger2.debug(`[TaskComponent] Registered hook: ${hook.name} at ${hookPoint}`);
|
|
468
|
+
}
|
|
469
|
+
registerHooks(hooks) {
|
|
470
|
+
for (const { hookPoint, hook } of hooks) {
|
|
471
|
+
this.registerHook(hookPoint, hook);
|
|
493
472
|
}
|
|
494
|
-
logger2.info(`[TaskComponent] Registered plugin: ${plugin.name}`, {
|
|
495
|
-
hooks: plugin.hooks.map((h) => h.point)
|
|
496
|
-
});
|
|
497
473
|
}
|
|
498
|
-
|
|
499
|
-
const
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
globalHookManager.unregister(hook.point, `${this.name}:${name}`);
|
|
474
|
+
unregisterHook(hookPoint, hookName) {
|
|
475
|
+
const removed = globalHookManager.unregister(hookPoint, hookName);
|
|
476
|
+
if (removed) {
|
|
477
|
+
this.plugins.delete(this.makePluginKey(hookPoint, hookName));
|
|
478
|
+
logger2.info(`[TaskComponent] Unregistered hook: ${hookName} from ${hookPoint}`);
|
|
504
479
|
}
|
|
505
|
-
|
|
506
|
-
logger2.info(`[TaskComponent] Unregistered plugin: ${name}`);
|
|
507
|
-
return true;
|
|
480
|
+
return removed;
|
|
508
481
|
}
|
|
509
|
-
|
|
482
|
+
listHooks() {
|
|
510
483
|
return Array.from(this.plugins.values());
|
|
511
484
|
}
|
|
485
|
+
makePluginKey(hookPoint, hookName) {
|
|
486
|
+
return `${hookPoint}::${hookName}`;
|
|
487
|
+
}
|
|
488
|
+
countHooks(hookPoint) {
|
|
489
|
+
return globalHookManager.count(hookPoint);
|
|
490
|
+
}
|
|
512
491
|
}
|
|
492
|
+
__legacyDecorateClassTS([
|
|
493
|
+
TracedAs("task.component.executeHook", { recordParams: true })
|
|
494
|
+
], TaskComponent.prototype, "executeHook", null);
|
|
513
495
|
// src/env/task/types.ts
|
|
514
496
|
import { z } from "zod";
|
|
515
497
|
var TaskStatusEnum = z.enum(["todo", "active", "completed", "paused", "cancelled"]);
|
|
@@ -23,11 +23,11 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
TracedAs,
|
|
25
25
|
init_decorator
|
|
26
|
-
} from "./roy-agent-core-
|
|
26
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
27
27
|
import {
|
|
28
28
|
createLogger,
|
|
29
29
|
init_logger
|
|
30
|
-
} from "./roy-agent-core-
|
|
30
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
31
31
|
import {
|
|
32
32
|
__esm,
|
|
33
33
|
__export,
|
|
@@ -1,34 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BasePlugin
|
|
3
|
+
} from "./roy-agent-core-az13yzmc.js";
|
|
1
4
|
import {
|
|
2
5
|
TaskHookPoints
|
|
3
6
|
} from "./roy-agent-core-92z6t4he.js";
|
|
7
|
+
import {
|
|
8
|
+
TracedAs,
|
|
9
|
+
init_decorator
|
|
10
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
11
|
+
import {
|
|
12
|
+
getEnvContextOrEmpty
|
|
13
|
+
} from "./roy-agent-core-z33en0cz.js";
|
|
4
14
|
import {
|
|
5
15
|
createLogger,
|
|
6
16
|
init_logger
|
|
7
|
-
} from "./roy-agent-core-
|
|
17
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
8
18
|
import {
|
|
19
|
+
__legacyDecorateClassTS,
|
|
9
20
|
__require
|
|
10
21
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
11
22
|
|
|
12
|
-
// src/env/task/plugins/task-plugin.ts
|
|
13
|
-
class TaskPlugin {
|
|
14
|
-
config;
|
|
15
|
-
constructor(config = {}) {
|
|
16
|
-
this.config = { enabled: true, priority: 0, ...config };
|
|
17
|
-
}
|
|
18
|
-
getHookPoints() {
|
|
19
|
-
return this.hooks.map((h) => h.point);
|
|
20
|
-
}
|
|
21
|
-
getPriorityForHook(hookPoint) {
|
|
22
|
-
const hook = this.hooks.find((h) => h.point === hookPoint);
|
|
23
|
-
return hook?.priority ?? this.config.priority ?? 0;
|
|
24
|
-
}
|
|
25
|
-
isEnabled() {
|
|
26
|
-
return this.config.enabled ?? true;
|
|
27
|
-
}
|
|
28
|
-
setEnabled(enabled) {
|
|
29
|
-
this.config.enabled = enabled;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
23
|
// src/env/task/plugins/task-tag-plugin.ts
|
|
33
24
|
init_logger();
|
|
34
25
|
|
|
@@ -200,42 +191,49 @@ async function parseExtractorOutput(output) {
|
|
|
200
191
|
}
|
|
201
192
|
|
|
202
193
|
// src/env/task/plugins/task-tag-plugin.ts
|
|
203
|
-
var logger = createLogger("
|
|
194
|
+
var logger = createLogger("plugin:task-tag");
|
|
204
195
|
|
|
205
|
-
class TaskTagPlugin extends
|
|
206
|
-
name = "
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
];
|
|
196
|
+
class TaskTagPlugin extends BasePlugin {
|
|
197
|
+
name = "task-tag";
|
|
198
|
+
version = "1.0.0";
|
|
199
|
+
description = "Inject similar task information into delegate prompt and extract workflow on task completion";
|
|
200
|
+
env;
|
|
211
201
|
taskComponent = null;
|
|
212
202
|
agentComponent = null;
|
|
213
|
-
|
|
214
|
-
|
|
203
|
+
tagService = null;
|
|
204
|
+
constructor() {
|
|
205
|
+
super();
|
|
215
206
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (taskComponent?.env) {
|
|
222
|
-
this.agentComponent = taskComponent.env.getComponent("agent");
|
|
207
|
+
init(env) {
|
|
208
|
+
this.env = env;
|
|
209
|
+
this.taskComponent = env.getComponent("task");
|
|
210
|
+
if (this.taskComponent && typeof this.taskComponent.getTagService === "function") {
|
|
211
|
+
this.tagService = this.taskComponent.getTagService();
|
|
223
212
|
}
|
|
213
|
+
this.agentComponent = env.getComponent("agent");
|
|
214
|
+
env.registerHook({
|
|
215
|
+
point: TaskHookPoints.DELEGATE_BEFORE,
|
|
216
|
+
priority: 20,
|
|
217
|
+
handler: this.onDelegateBefore.bind(this)
|
|
218
|
+
});
|
|
219
|
+
env.registerHook({
|
|
220
|
+
point: TaskHookPoints.OPERATION_AFTER_CREATE,
|
|
221
|
+
priority: 10,
|
|
222
|
+
handler: this.onOperationAfterCreate.bind(this)
|
|
223
|
+
});
|
|
224
|
+
env.registerAgent(createWorkflowExtractorAgent());
|
|
225
|
+
logger.info("[TaskTagPlugin] Initialized");
|
|
224
226
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
break;
|
|
232
|
-
case TaskHookPoints.OPERATION_AFTER_CREATE:
|
|
233
|
-
await this.onOperationAfterCreate(ctx);
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
227
|
+
dispose() {
|
|
228
|
+
this.env = null;
|
|
229
|
+
this.taskComponent = null;
|
|
230
|
+
this.agentComponent = null;
|
|
231
|
+
this.tagService = null;
|
|
232
|
+
logger.info("[TaskTagPlugin] Disposed");
|
|
236
233
|
}
|
|
237
234
|
async onDelegateBefore(ctx) {
|
|
238
|
-
const
|
|
235
|
+
const data = ctx.data;
|
|
236
|
+
const { taskId, prompt } = data;
|
|
239
237
|
if (!taskId || !this.taskComponent) {
|
|
240
238
|
return;
|
|
241
239
|
}
|
|
@@ -246,15 +244,14 @@ class TaskTagPlugin extends TaskPlugin {
|
|
|
246
244
|
const keywords = this.extractKeywords(currentTask);
|
|
247
245
|
if (keywords.length === 0)
|
|
248
246
|
return;
|
|
249
|
-
const
|
|
250
|
-
const similarTasks = await tagServiceForSearch?.findSimilarTasksByKeywords?.(keywords, {
|
|
247
|
+
const similarTasks = await this.tagService?.findSimilarTasksByKeywords?.(keywords, {
|
|
251
248
|
limit: 5,
|
|
252
249
|
excludeTaskId: taskId
|
|
253
250
|
}) ?? [];
|
|
254
251
|
if (similarTasks.length === 0)
|
|
255
252
|
return;
|
|
256
253
|
const hint = this.formatSimilarTasks(similarTasks);
|
|
257
|
-
|
|
254
|
+
data.prompt = `${hint}
|
|
258
255
|
|
|
259
256
|
---
|
|
260
257
|
|
|
@@ -314,7 +311,7 @@ ${prompt}`;
|
|
|
314
311
|
return;
|
|
315
312
|
const operations = await this.taskComponent?.listOperations({ taskId }) ?? [];
|
|
316
313
|
const allSessionIds = [...new Set([sessionId, ...operations.map((op) => op.sessionId).filter(Boolean)])];
|
|
317
|
-
const sessionComponent = this.
|
|
314
|
+
const sessionComponent = this.env.getComponent("session");
|
|
318
315
|
const allMessages = [];
|
|
319
316
|
for (const sid of allSessionIds) {
|
|
320
317
|
try {
|
|
@@ -355,23 +352,24 @@ ${prompt}`;
|
|
|
355
352
|
actionTitle: `Workflow extracted: ${workflow.name}`,
|
|
356
353
|
actionDescription: workflow.id
|
|
357
354
|
});
|
|
358
|
-
logger.info(`Workflow extracted: ${workflow.id}`);
|
|
355
|
+
logger.info(`[TaskTagPlugin] Workflow extracted: ${workflow.id}`);
|
|
359
356
|
} catch (error) {
|
|
360
|
-
logger.warn(`Workflow extraction failed: ${error}`);
|
|
357
|
+
logger.warn(`[TaskTagPlugin] Workflow extraction failed: ${error}`);
|
|
361
358
|
}
|
|
362
359
|
}
|
|
360
|
+
_workflowRepo = null;
|
|
363
361
|
async getWorkflowRepository() {
|
|
364
|
-
const workflowComponent = this.
|
|
362
|
+
const workflowComponent = this.env.getComponent("workflow");
|
|
365
363
|
if (workflowComponent?.workflowService?.workflowRepository) {
|
|
366
364
|
return workflowComponent.workflowService.workflowRepository;
|
|
367
365
|
}
|
|
368
366
|
if (!this._workflowRepo) {
|
|
369
367
|
try {
|
|
370
|
-
const sqlite = await import("./roy-agent-core-
|
|
368
|
+
const sqlite = await import("./roy-agent-core-zwp3jp02.js");
|
|
371
369
|
this.ensureDataDir();
|
|
372
370
|
const db = sqlite.getDatabase();
|
|
373
371
|
sqlite.initializeTables();
|
|
374
|
-
const { WorkflowRepository } = await import("./roy-agent-core-
|
|
372
|
+
const { WorkflowRepository } = await import("./roy-agent-core-ty33mnr7.js");
|
|
375
373
|
this._workflowRepo = new WorkflowRepository(db);
|
|
376
374
|
return this._workflowRepo;
|
|
377
375
|
} catch {
|
|
@@ -382,12 +380,266 @@ ${prompt}`;
|
|
|
382
380
|
}
|
|
383
381
|
ensureDataDir() {
|
|
384
382
|
const { join } = __require("path");
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
const dataDir = join(home, ".local", "share", "roy-agent");
|
|
388
|
-
if (!existsSync(dataDir))
|
|
389
|
-
mkdirSync(dataDir, { recursive: true });
|
|
383
|
+
const dataDir = join(process.env.XDG_DATA_HOME || join(process.env.HOME || "", ".local/share"), "roy-agent");
|
|
384
|
+
__require("fs").mkdirSync(dataDir, { recursive: true });
|
|
390
385
|
}
|
|
391
|
-
_workflowRepo = null;
|
|
392
386
|
}
|
|
393
|
-
|
|
387
|
+
// src/env/task/plugins/lark-cli-task-notify-plugin.ts
|
|
388
|
+
init_decorator();
|
|
389
|
+
init_logger();
|
|
390
|
+
import { spawn } from "child_process";
|
|
391
|
+
var logger2 = createLogger("lark-cli:task-notify");
|
|
392
|
+
function isTaskNotifyDebugEnabled() {
|
|
393
|
+
return process.env.ROY_TASK_NOTIFY_DEBUG === "1" || process.env.ROY_TRACE_DEBUG === "1";
|
|
394
|
+
}
|
|
395
|
+
var NotifyType;
|
|
396
|
+
((NotifyType2) => {
|
|
397
|
+
NotifyType2["TASK_CREATED"] = "task_created";
|
|
398
|
+
NotifyType2["TASK_COMPLETED"] = "task_completed";
|
|
399
|
+
NotifyType2["TASK_UPDATED"] = "task_updated";
|
|
400
|
+
NotifyType2["TASK_FAILED"] = "task_failed";
|
|
401
|
+
})(NotifyType ||= {});
|
|
402
|
+
|
|
403
|
+
class LarkCliTaskNotifyHook {
|
|
404
|
+
name;
|
|
405
|
+
priority;
|
|
406
|
+
description;
|
|
407
|
+
pluginName;
|
|
408
|
+
sourceId;
|
|
409
|
+
config;
|
|
410
|
+
constructor(config = {}) {
|
|
411
|
+
this.name = config.pluginName || "LarkCliTaskNotifyHook";
|
|
412
|
+
this.priority = config.priority ?? 5;
|
|
413
|
+
this.description = "LarkCli 任务通知 Hook";
|
|
414
|
+
this.pluginName = config.pluginName;
|
|
415
|
+
this.sourceId = config.sourceId;
|
|
416
|
+
this.config = {
|
|
417
|
+
enabled: true,
|
|
418
|
+
priority: 5,
|
|
419
|
+
notifyTypes: ["task_completed" /* TASK_COMPLETED */],
|
|
420
|
+
...config
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
async execute(ctx) {
|
|
424
|
+
if (!this.config.enabled) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const env = getEnvContextOrEmpty();
|
|
428
|
+
if (this.pluginName && this.sourceId) {
|
|
429
|
+
const key = `${this.sourceId}:${this.pluginName}`;
|
|
430
|
+
if (env.pluginEnabled && env.pluginEnabled[key] !== true) {
|
|
431
|
+
logger2.debug(`Plugin not enabled for source: ${key}`);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
switch (ctx.hookPoint) {
|
|
436
|
+
case TaskHookPoints.AFTER_CREATE:
|
|
437
|
+
await this.onAfterCreate(ctx);
|
|
438
|
+
break;
|
|
439
|
+
case TaskHookPoints.AFTER_UPDATE:
|
|
440
|
+
await this.onAfterUpdate(ctx);
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async onAfterCreate(ctx) {
|
|
445
|
+
const { task } = ctx.data;
|
|
446
|
+
if (!this.shouldNotify("task_created" /* TASK_CREATED */))
|
|
447
|
+
return;
|
|
448
|
+
await this.sendNotify({
|
|
449
|
+
type: "task_created" /* TASK_CREATED */,
|
|
450
|
+
title: `\uD83D\uDCDD 任务已创建`,
|
|
451
|
+
content: this.formatTaskCreated(task)
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
async onAfterUpdate(ctx) {
|
|
455
|
+
const hookCtx = ctx.data;
|
|
456
|
+
const innerData = hookCtx.data;
|
|
457
|
+
if (!innerData) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const { task, changes } = innerData;
|
|
461
|
+
if (!task) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
let notifyType;
|
|
465
|
+
let notifyChanges = changes || {};
|
|
466
|
+
if (changes?.status === "completed" || changes?.progress === 100) {
|
|
467
|
+
notifyType = "task_completed" /* TASK_COMPLETED */;
|
|
468
|
+
} else if (changes?.status) {
|
|
469
|
+
notifyType = "task_updated" /* TASK_UPDATED */;
|
|
470
|
+
} else if (task.status === "completed" || task.progress === 100) {
|
|
471
|
+
notifyType = "task_completed" /* TASK_COMPLETED */;
|
|
472
|
+
notifyChanges = { status: task.status, progress: task.progress };
|
|
473
|
+
} else if (changes && Object.keys(changes).length > 0) {
|
|
474
|
+
notifyType = "task_updated" /* TASK_UPDATED */;
|
|
475
|
+
} else {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (!this.shouldNotify(notifyType)) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
await this.sendNotify({
|
|
482
|
+
type: notifyType,
|
|
483
|
+
title: this.getNotifyTitle(notifyType),
|
|
484
|
+
content: this.formatTaskUpdate(task, notifyChanges),
|
|
485
|
+
_hookContext: ctx
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
async sendNotify(options) {
|
|
489
|
+
const { type, title, content, _hookContext } = options;
|
|
490
|
+
const env = getEnvContextOrEmpty();
|
|
491
|
+
let replyChannel = env.replyChannel;
|
|
492
|
+
const envContextFromMetadata = env.metadata?.envContext;
|
|
493
|
+
if (!replyChannel && envContextFromMetadata) {
|
|
494
|
+
replyChannel = envContextFromMetadata.replyChannel;
|
|
495
|
+
}
|
|
496
|
+
if (!replyChannel && _hookContext?.metadata?.envContext) {
|
|
497
|
+
replyChannel = _hookContext.metadata.envContext.replyChannel;
|
|
498
|
+
}
|
|
499
|
+
const chatId = replyChannel?.chatId;
|
|
500
|
+
const messageId = replyChannel?.messageId;
|
|
501
|
+
if (!chatId && !messageId) {
|
|
502
|
+
logger2.debug(`No replyChannel available for ${type}`);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const message = `${title}
|
|
506
|
+
|
|
507
|
+
${content}`;
|
|
508
|
+
try {
|
|
509
|
+
if (isTaskNotifyDebugEnabled()) {
|
|
510
|
+
logger2.debug(`Sending message - messageId: ${messageId}`);
|
|
511
|
+
}
|
|
512
|
+
await this.sendLarkMessage({
|
|
513
|
+
chatId,
|
|
514
|
+
messageId,
|
|
515
|
+
content: message
|
|
516
|
+
});
|
|
517
|
+
logger2.info(`Notification sent: ${type}`);
|
|
518
|
+
} catch (error) {
|
|
519
|
+
logger2.error(`Failed to send notification: ${error}`);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
sendLarkMessage(options) {
|
|
523
|
+
return new Promise((resolve, reject) => {
|
|
524
|
+
const { chatId, messageId, content } = options;
|
|
525
|
+
const contentJson = JSON.stringify({ text: content });
|
|
526
|
+
let args;
|
|
527
|
+
if (messageId) {
|
|
528
|
+
args = [
|
|
529
|
+
"im",
|
|
530
|
+
"+messages-reply",
|
|
531
|
+
"--message-id",
|
|
532
|
+
messageId,
|
|
533
|
+
"--text",
|
|
534
|
+
contentJson,
|
|
535
|
+
"--as",
|
|
536
|
+
"bot"
|
|
537
|
+
];
|
|
538
|
+
} else {
|
|
539
|
+
args = [
|
|
540
|
+
"im",
|
|
541
|
+
"+messages-send",
|
|
542
|
+
"--chat-id",
|
|
543
|
+
chatId,
|
|
544
|
+
"--text",
|
|
545
|
+
contentJson
|
|
546
|
+
];
|
|
547
|
+
}
|
|
548
|
+
const proc = spawn("lark-cli", args, {
|
|
549
|
+
shell: false,
|
|
550
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
551
|
+
});
|
|
552
|
+
let stdout = "";
|
|
553
|
+
let stderr = "";
|
|
554
|
+
proc.stdout?.on("data", (data) => {
|
|
555
|
+
stdout += data.toString();
|
|
556
|
+
});
|
|
557
|
+
proc.stderr?.on("data", (data) => {
|
|
558
|
+
stderr += data.toString();
|
|
559
|
+
});
|
|
560
|
+
proc.on("close", (code) => {
|
|
561
|
+
if (code === 0) {
|
|
562
|
+
logger2.debug(`lark-cli output: ${stdout}`);
|
|
563
|
+
resolve();
|
|
564
|
+
} else {
|
|
565
|
+
reject(new Error(`lark-cli exited with code ${code}: ${stderr}`));
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
proc.on("error", (error) => {
|
|
569
|
+
reject(error);
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
shouldNotify(type) {
|
|
574
|
+
const { notifyTypes } = this.config;
|
|
575
|
+
if (notifyTypes && notifyTypes.length === 0)
|
|
576
|
+
return true;
|
|
577
|
+
if (notifyTypes)
|
|
578
|
+
return notifyTypes.includes(type);
|
|
579
|
+
return type === "task_completed" /* TASK_COMPLETED */;
|
|
580
|
+
}
|
|
581
|
+
getNotifyTitle(type) {
|
|
582
|
+
const template = this.config.templates?.[type];
|
|
583
|
+
if (template)
|
|
584
|
+
return template;
|
|
585
|
+
switch (type) {
|
|
586
|
+
case "task_created" /* TASK_CREATED */:
|
|
587
|
+
return "\uD83D\uDCDD 任务已创建";
|
|
588
|
+
case "task_completed" /* TASK_COMPLETED */:
|
|
589
|
+
return "✅ 任务已完成";
|
|
590
|
+
case "task_updated" /* TASK_UPDATED */:
|
|
591
|
+
return "\uD83D\uDCCB 任务已更新";
|
|
592
|
+
case "task_failed" /* TASK_FAILED */:
|
|
593
|
+
return "❌ 任务执行失败";
|
|
594
|
+
default:
|
|
595
|
+
return "\uD83D\uDCEC 任务通知";
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
formatTaskCreated(task) {
|
|
599
|
+
const lines = [
|
|
600
|
+
`**标题**: ${task.title || "无标题"}`
|
|
601
|
+
];
|
|
602
|
+
if (task.description) {
|
|
603
|
+
lines.push(`**描述**: ${task.description.substring(0, 100)}${task.description.length > 100 ? "..." : ""}`);
|
|
604
|
+
}
|
|
605
|
+
if (task.priority) {
|
|
606
|
+
lines.push(`**优先级**: ${task.priority}`);
|
|
607
|
+
}
|
|
608
|
+
return lines.join(`
|
|
609
|
+
`);
|
|
610
|
+
}
|
|
611
|
+
formatTaskUpdate(task, changes) {
|
|
612
|
+
const lines = [
|
|
613
|
+
`**标题**: ${task.title || "无标题"}`,
|
|
614
|
+
`**ID**: ${task.id}`
|
|
615
|
+
];
|
|
616
|
+
if (changes?.status) {
|
|
617
|
+
lines.push(`**状态**: ${changes.status}`);
|
|
618
|
+
}
|
|
619
|
+
if (changes?.progress !== undefined) {
|
|
620
|
+
lines.push(`**进度**: ${changes.progress}%`);
|
|
621
|
+
}
|
|
622
|
+
if (changes?.current_status) {
|
|
623
|
+
lines.push(`**当前状态**: ${changes.current_status}`);
|
|
624
|
+
}
|
|
625
|
+
const changeKeys = Object.keys(changes || {}).filter((k) => !["status", "progress", "current_status"].includes(k));
|
|
626
|
+
if (changeKeys.length > 0) {
|
|
627
|
+
lines.push(`**变更**: ${changeKeys.join(", ")}`);
|
|
628
|
+
}
|
|
629
|
+
return lines.join(`
|
|
630
|
+
`);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
__legacyDecorateClassTS([
|
|
634
|
+
TracedAs("lark-cli-task-notify.execute")
|
|
635
|
+
], LarkCliTaskNotifyHook.prototype, "execute", null);
|
|
636
|
+
__legacyDecorateClassTS([
|
|
637
|
+
TracedAs("lark-cli-task-notify.sendNotify")
|
|
638
|
+
], LarkCliTaskNotifyHook.prototype, "sendNotify", null);
|
|
639
|
+
__legacyDecorateClassTS([
|
|
640
|
+
TracedAs("lark-cli-task-notify.sendLarkMessage")
|
|
641
|
+
], LarkCliTaskNotifyHook.prototype, "sendLarkMessage", null);
|
|
642
|
+
function createLarkCliTaskNotifyHook(config = {}) {
|
|
643
|
+
return new LarkCliTaskNotifyHook(config);
|
|
644
|
+
}
|
|
645
|
+
export { WORKFLOW_EXTRACTOR_PROMPT, createWorkflowExtractorAgent, formatExtractorInput, formatExtractorInputFromDescription, parseExtractorOutput, TaskTagPlugin, NotifyType, LarkCliTaskNotifyHook, createLarkCliTaskNotifyHook };
|