@ai-setting/roy-agent-core 1.5.37 → 1.5.41

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 (74) hide show
  1. package/dist/config/index.js +4 -3
  2. package/dist/env/agent/index.js +10 -9
  3. package/dist/env/commands/index.js +7 -6
  4. package/dist/env/context/index.js +21 -0
  5. package/dist/env/debug/index.js +4 -3
  6. package/dist/env/event-source/index.js +12 -6
  7. package/dist/env/hook/index.js +2 -1
  8. package/dist/env/index.js +41 -18
  9. package/dist/env/llm/index.js +8 -7
  10. package/dist/env/log-trace/index.js +10 -9
  11. package/dist/env/mcp/index.js +8 -7
  12. package/dist/env/mcp/tool/index.js +4 -4
  13. package/dist/env/memory/index.js +12 -11
  14. package/dist/env/memory/plugin/index.js +4 -4
  15. package/dist/env/plugin/index.js +18 -0
  16. package/dist/env/prompt/index.js +7 -6
  17. package/dist/env/session/index.js +11 -10
  18. package/dist/env/session/storage/index.js +2 -6
  19. package/dist/env/skill/index.js +7 -6
  20. package/dist/env/task/delegate/index.js +6 -5
  21. package/dist/env/task/index.js +10 -8
  22. package/dist/env/task/plugins/index.js +13 -6
  23. package/dist/env/task/storage/index.js +4 -4
  24. package/dist/env/tool/built-in/index.js +3 -3
  25. package/dist/env/tool/index.js +8 -7
  26. package/dist/env/workflow/engine/index.js +5 -5
  27. package/dist/env/workflow/index.js +9 -8
  28. package/dist/env/workflow/storage/index.js +5 -5
  29. package/dist/env/workflow/tools/index.js +3 -3
  30. package/dist/env/workflow/utils/index.js +4 -4
  31. package/dist/index.js +67 -60
  32. package/dist/shared/@ai-setting/{roy-agent-core-44hnfb02.js → roy-agent-core-10n2jh7p.js} +1 -1
  33. package/dist/shared/@ai-setting/{roy-agent-core-xt3fx7m1.js → roy-agent-core-15x8fe5h.js} +38 -56
  34. package/dist/shared/@ai-setting/{roy-agent-core-1akcqxj9.js → roy-agent-core-1bfmxx89.js} +1 -1
  35. package/dist/shared/@ai-setting/{roy-agent-core-ty94k28r.js → roy-agent-core-2jnzv9at.js} +2 -2
  36. package/dist/shared/@ai-setting/{roy-agent-core-cefh9hjv.js → roy-agent-core-4jqq077c.js} +1 -1
  37. package/dist/shared/@ai-setting/{roy-agent-core-xs5rsgat.js → roy-agent-core-58k274fg.js} +108 -23
  38. package/dist/shared/@ai-setting/{roy-agent-core-jfh9q2qh.js → roy-agent-core-7b35emr7.js} +0 -15
  39. package/dist/shared/@ai-setting/{roy-agent-core-3rr5k71j.js → roy-agent-core-8n4bz6y3.js} +1 -1
  40. package/dist/shared/@ai-setting/{roy-agent-core-zpn0bqa8.js → roy-agent-core-9ffsvvcf.js} +1 -1
  41. package/dist/shared/@ai-setting/roy-agent-core-az13yzmc.js +11 -0
  42. package/dist/shared/@ai-setting/{roy-agent-core-0wdjp769.js → roy-agent-core-b4wd9tn6.js} +2 -2
  43. package/dist/shared/@ai-setting/{roy-agent-core-6kvtahqv.js → roy-agent-core-c3ct1346.js} +1 -1
  44. package/dist/shared/@ai-setting/{roy-agent-core-psv4v63c.js → roy-agent-core-c6592r3c.js} +19 -2
  45. package/dist/shared/@ai-setting/{roy-agent-core-c2wjwx16.js → roy-agent-core-c8f2hync.js} +305 -287
  46. package/dist/shared/@ai-setting/roy-agent-core-cevpwnq7.js +147 -0
  47. package/dist/shared/@ai-setting/{roy-agent-core-hkb529dw.js → roy-agent-core-dxbsc1zy.js} +7 -7
  48. package/dist/shared/@ai-setting/{roy-agent-core-vqspcspb.js → roy-agent-core-e130w7mv.js} +3 -3
  49. package/dist/shared/@ai-setting/{roy-agent-core-3jywqmdd.js → roy-agent-core-e9fdm13a.js} +319 -65
  50. package/dist/shared/@ai-setting/{roy-agent-core-j0ke54vy.js → roy-agent-core-ee6nnnqw.js} +5 -5
  51. package/dist/shared/@ai-setting/{roy-agent-core-qdmt6nz7.js → roy-agent-core-eg6nv09z.js} +2 -2
  52. package/dist/shared/@ai-setting/{roy-agent-core-hd1z20yq.js → roy-agent-core-frx4p6d1.js} +1 -1
  53. package/dist/shared/@ai-setting/{roy-agent-core-bvr1761x.js → roy-agent-core-hsxn8m1j.js} +1 -1
  54. package/dist/shared/@ai-setting/{roy-agent-core-86gphny5.js → roy-agent-core-jqy2mdyq.js} +15 -1
  55. package/dist/shared/@ai-setting/{roy-agent-core-c0d3dtjd.js → roy-agent-core-kajktp3d.js} +7 -7
  56. package/dist/shared/@ai-setting/{roy-agent-core-eajcvp4e.js → roy-agent-core-kwhv9dcd.js} +2 -2
  57. package/dist/shared/@ai-setting/{roy-agent-core-r9ezzemr.js → roy-agent-core-m0wp34r4.js} +1 -1
  58. package/dist/shared/@ai-setting/{roy-agent-core-fg1kxf70.js → roy-agent-core-nqgrjja0.js} +5 -5
  59. package/dist/shared/@ai-setting/{roy-agent-core-mx489p7f.js → roy-agent-core-psvwzdhj.js} +263 -33
  60. package/dist/shared/@ai-setting/{roy-agent-core-d7cyjkf7.js → roy-agent-core-pwkk12p4.js} +1 -1
  61. package/dist/shared/@ai-setting/{roy-agent-core-97ma0pr5.js → roy-agent-core-pxcrzyv9.js} +2 -2
  62. package/dist/shared/@ai-setting/{roy-agent-core-zgypchmt.js → roy-agent-core-q5qj0fes.js} +19 -11
  63. package/dist/shared/@ai-setting/{roy-agent-core-sx7wsvnn.js → roy-agent-core-qakqwbbh.js} +2 -2
  64. package/dist/shared/@ai-setting/{roy-agent-core-qfdp3pvq.js → roy-agent-core-rsybkb38.js} +1 -1
  65. package/dist/shared/@ai-setting/roy-agent-core-ty33mnr7.js +14 -0
  66. package/dist/shared/@ai-setting/{roy-agent-core-3prpabp8.js → roy-agent-core-v53rfk99.js} +2 -2
  67. package/dist/shared/@ai-setting/{roy-agent-core-wjd5kars.js → roy-agent-core-wb43x8hd.js} +3 -3
  68. package/dist/shared/@ai-setting/{roy-agent-core-e2vk2qh7.js → roy-agent-core-yc543gnq.js} +6 -6
  69. package/dist/shared/@ai-setting/{roy-agent-core-gf2c2pxr.js → roy-agent-core-ycg9rk6z.js} +3 -3
  70. package/dist/shared/@ai-setting/roy-agent-core-z33en0cz.js +44 -0
  71. package/dist/shared/@ai-setting/{roy-agent-core-by55z88t.js → roy-agent-core-zrja5v78.js} +11 -11
  72. package/dist/shared/@ai-setting/{roy-agent-core-wft9ra24.js → roy-agent-core-zwp3jp02.js} +4 -4
  73. package/package.json +1 -1
  74. package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
@@ -0,0 +1,147 @@
1
+ import {
2
+ BaseComponent
3
+ } from "./roy-agent-core-4jqq077c.js";
4
+ import {
5
+ globalHookManager
6
+ } from "./roy-agent-core-jqy2mdyq.js";
7
+ import {
8
+ createLogger,
9
+ init_logger
10
+ } from "./roy-agent-core-10n2jh7p.js";
11
+
12
+ // src/env/plugin/plugin-component.ts
13
+ init_logger();
14
+
15
+ class PluginComponent extends BaseComponent {
16
+ name = "plugin";
17
+ version = "1.0.0";
18
+ registry = new Map;
19
+ componentCache = new Map;
20
+ logger = createLogger("plugin");
21
+ configComponent;
22
+ constructor() {
23
+ super();
24
+ }
25
+ async init(config) {
26
+ await super.init(config);
27
+ const options = config?.options;
28
+ if (!options?.configComponent) {
29
+ throw new Error("ConfigComponent is required for PluginComponent initialization");
30
+ }
31
+ this.configComponent = options.configComponent;
32
+ this.setStatus("running");
33
+ this.logger.info("[PluginComponent] Initialized");
34
+ }
35
+ register(plugin) {
36
+ if (this.registry.has(plugin.name)) {
37
+ throw new Error(`Plugin "${plugin.name}" is already registered`);
38
+ }
39
+ const env = this.createPluginEnv(plugin);
40
+ try {
41
+ const result = plugin.init(env);
42
+ if (result instanceof Promise) {
43
+ result.then(() => {
44
+ this.registry.set(plugin.name, plugin);
45
+ this.logger.info(`Registered plugin: ${plugin.name}`);
46
+ }).catch((err) => {
47
+ this.logger.error(`Failed to init plugin ${plugin.name}: ${err}`);
48
+ throw err;
49
+ });
50
+ } else {
51
+ this.registry.set(plugin.name, plugin);
52
+ this.logger.info(`Registered plugin: ${plugin.name}`);
53
+ }
54
+ } catch (err) {
55
+ this.logger.error(`Failed to init plugin ${plugin.name}: ${err}`);
56
+ throw err;
57
+ }
58
+ }
59
+ unregister(name) {
60
+ const plugin = this.registry.get(name);
61
+ if (!plugin) {
62
+ return false;
63
+ }
64
+ try {
65
+ plugin.dispose();
66
+ this.registry.delete(name);
67
+ this.logger.info(`Unregistered plugin: ${name}`);
68
+ return true;
69
+ } catch (err) {
70
+ this.logger.error(`Failed to dispose plugin ${name}: ${err}`);
71
+ return false;
72
+ }
73
+ }
74
+ get(name) {
75
+ return this.registry.get(name);
76
+ }
77
+ list() {
78
+ return Array.from(this.registry.values());
79
+ }
80
+ has(name) {
81
+ return this.registry.has(name);
82
+ }
83
+ getConfig(name) {
84
+ return this.configComponent?.get(`plugin.${name}`);
85
+ }
86
+ registerAll(plugins) {
87
+ for (const plugin of plugins) {
88
+ this.register(plugin);
89
+ }
90
+ }
91
+ async stop() {
92
+ this.setStatus("stopping");
93
+ this.logger.info("[PluginComponent] Stopping...");
94
+ for (const [name, plugin] of this.registry) {
95
+ try {
96
+ const result = plugin.dispose();
97
+ if (result instanceof Promise) {
98
+ await result;
99
+ }
100
+ this.logger.debug(`Disposed plugin: ${name}`);
101
+ } catch (err) {
102
+ this.logger.error(`Failed to dispose plugin ${name}: ${err}`);
103
+ }
104
+ }
105
+ this.registry.clear();
106
+ this.componentCache.clear();
107
+ this.setStatus("stopped");
108
+ this.logger.info("[PluginComponent] Stopped");
109
+ }
110
+ createPluginEnv(plugin) {
111
+ const self = this;
112
+ return {
113
+ getComponent(name) {
114
+ return self.env?.getComponent(name);
115
+ },
116
+ registerAgent(config) {
117
+ const agentComponent = self.env?.getComponent("agent");
118
+ if (agentComponent) {
119
+ agentComponent.registerAgent(config.name, config);
120
+ self.logger.debug(`Registered agent: ${config.name} (for plugin: ${plugin.name})`);
121
+ } else {
122
+ self.logger.warn(`Cannot register agent ${config.name}: AgentComponent not available`);
123
+ }
124
+ },
125
+ registerTool(tool) {
126
+ const toolComponent = self.env?.getComponent("tool");
127
+ if (toolComponent) {
128
+ toolComponent.register(tool);
129
+ self.logger.debug(`Registered tool: ${tool.name} (for plugin: ${plugin.name})`);
130
+ } else {
131
+ self.logger.warn(`Cannot register tool ${tool.name}: ToolComponent not available`);
132
+ }
133
+ },
134
+ registerHook(hook) {
135
+ globalHookManager.register(hook.point, {
136
+ name: `${plugin.name}:${hook.point}`,
137
+ priority: hook.priority ?? plugin.priority,
138
+ execute: hook.handler
139
+ });
140
+ self.logger.debug(`Registered hook: ${hook.point} (for plugin: ${plugin.name})`);
141
+ },
142
+ logger: createLogger(`plugin:${plugin.name}`)
143
+ };
144
+ }
145
+ }
146
+
147
+ export { PluginComponent };
@@ -1,29 +1,29 @@
1
+ import {
2
+ init_decorator
3
+ } from "./roy-agent-core-q5qj0fes.js";
1
4
  import {
2
5
  envKeyToConfigKey
3
6
  } from "./roy-agent-core-qxhq8ven.js";
4
7
  import {
5
8
  BaseComponent
6
- } from "./roy-agent-core-cefh9hjv.js";
7
- import {
8
- init_decorator
9
- } from "./roy-agent-core-zgypchmt.js";
9
+ } from "./roy-agent-core-4jqq077c.js";
10
10
  import {
11
11
  createLogger,
12
12
  init_logger,
13
13
  setConfigComponent,
14
14
  setQuietMode
15
- } from "./roy-agent-core-44hnfb02.js";
15
+ } from "./roy-agent-core-10n2jh7p.js";
16
16
  import {
17
17
  getTracerProvider,
18
18
  init_propagation,
19
19
  init_tracer_provider,
20
20
  init_types,
21
21
  propagation
22
- } from "./roy-agent-core-xs5rsgat.js";
22
+ } from "./roy-agent-core-58k274fg.js";
23
23
  import {
24
24
  SQLiteSpanStorage,
25
25
  init_span_storage
26
- } from "./roy-agent-core-psv4v63c.js";
26
+ } from "./roy-agent-core-c6592r3c.js";
27
27
  import {
28
28
  __require
29
29
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -8,15 +8,15 @@ import {
8
8
  } from "./roy-agent-core-qxhq8ven.js";
9
9
  import {
10
10
  BaseComponent
11
- } from "./roy-agent-core-cefh9hjv.js";
11
+ } from "./roy-agent-core-4jqq077c.js";
12
12
  import {
13
13
  ToolHookPoints,
14
14
  globalHookManager
15
- } from "./roy-agent-core-86gphny5.js";
15
+ } from "./roy-agent-core-jqy2mdyq.js";
16
16
  import {
17
17
  createLogger,
18
18
  init_logger
19
- } from "./roy-agent-core-44hnfb02.js";
19
+ } from "./roy-agent-core-10n2jh7p.js";
20
20
  import {
21
21
  __require
22
22
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -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-44hnfb02.js";
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("task:plugin:tag");
194
+ var logger = createLogger("plugin:task-tag");
204
195
 
205
- class TaskTagPlugin extends TaskPlugin {
206
- name = "TaskTagPlugin";
207
- hooks = [
208
- { point: TaskHookPoints.DELEGATE_BEFORE, priority: 20 },
209
- { point: TaskHookPoints.OPERATION_AFTER_CREATE, priority: 10 }
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
- constructor(config = {}) {
214
- super({ enabled: true, priority: 0, ...config });
203
+ tagService = null;
204
+ constructor() {
205
+ super();
215
206
  }
216
- static getRequiredAgents() {
217
- return [createWorkflowExtractorAgent()];
218
- }
219
- setComponents(_llmComponent, taskComponent) {
220
- this.taskComponent = taskComponent;
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
- async execute(ctx) {
226
- if (!this.config.enabled)
227
- return;
228
- switch (ctx.hookPoint) {
229
- case TaskHookPoints.DELEGATE_BEFORE:
230
- await this.onDelegateBefore(ctx);
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 { taskId, tagService, prompt } = ctx.data;
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 tagServiceForSearch = tagService;
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
- ctx.data.prompt = `${hint}
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.taskComponent?.env?.getComponent("session");
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.taskComponent?.env?.getComponent("workflow");
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-wft9ra24.js");
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-bcbqy27c.js");
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,268 @@ ${prompt}`;
382
380
  }
383
381
  ensureDataDir() {
384
382
  const { join } = __require("path");
385
- const { mkdirSync, existsSync } = __require("fs");
386
- const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
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
- export { TaskPlugin, WORKFLOW_EXTRACTOR_PROMPT, createWorkflowExtractorAgent, formatExtractorInput, formatExtractorInputFromDescription, parseExtractorOutput, TaskTagPlugin };
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
+ let args;
526
+ if (messageId) {
527
+ args = [
528
+ "im",
529
+ "+messages-reply",
530
+ "--message-id",
531
+ messageId,
532
+ "--markdown",
533
+ content,
534
+ "--as",
535
+ "bot"
536
+ ];
537
+ } else {
538
+ args = [
539
+ "im",
540
+ "+messages-send",
541
+ "--chat-id",
542
+ chatId,
543
+ "--markdown",
544
+ content
545
+ ];
546
+ }
547
+ const proc = spawn("lark-cli", args, {
548
+ shell: false,
549
+ stdio: ["pipe", "pipe", "pipe"]
550
+ });
551
+ let stdout = "";
552
+ let stderr = "";
553
+ proc.stdout?.on("data", (data) => {
554
+ stdout += data.toString();
555
+ });
556
+ proc.stderr?.on("data", (data) => {
557
+ stderr += data.toString();
558
+ });
559
+ proc.on("close", (code) => {
560
+ if (code === 0) {
561
+ logger2.debug(`lark-cli output: ${stdout}`);
562
+ resolve();
563
+ } else {
564
+ reject(new Error(`lark-cli exited with code ${code}: ${stderr}`));
565
+ }
566
+ });
567
+ proc.on("error", (error) => {
568
+ reject(error);
569
+ });
570
+ });
571
+ }
572
+ shouldNotify(type) {
573
+ const { notifyTypes } = this.config;
574
+ if (notifyTypes && notifyTypes.length === 0)
575
+ return true;
576
+ if (notifyTypes)
577
+ return notifyTypes.includes(type);
578
+ return type === "task_completed" /* TASK_COMPLETED */;
579
+ }
580
+ getNotifyTitle(type) {
581
+ const template = this.config.templates?.[type];
582
+ if (template)
583
+ return template;
584
+ switch (type) {
585
+ case "task_created" /* TASK_CREATED */:
586
+ return "\uD83D\uDCDD 任务已创建";
587
+ case "task_completed" /* TASK_COMPLETED */:
588
+ return "✅ 任务已完成";
589
+ case "task_updated" /* TASK_UPDATED */:
590
+ return "\uD83D\uDCCB 任务已更新";
591
+ case "task_failed" /* TASK_FAILED */:
592
+ return "❌ 任务执行失败";
593
+ default:
594
+ return "\uD83D\uDCEC 任务通知";
595
+ }
596
+ }
597
+ formatTaskCreated(task) {
598
+ const lines = [];
599
+ if (task.title) {
600
+ lines.push(`- **标题**: ${task.title}`);
601
+ }
602
+ if (task.description) {
603
+ const desc = task.description.substring(0, 100) + (task.description.length > 100 ? "..." : "");
604
+ lines.push(`- **描述**: ${desc}`);
605
+ }
606
+ if (task.priority) {
607
+ lines.push(`- **优先级**: ${task.priority}`);
608
+ }
609
+ return lines.join(`
610
+ `);
611
+ }
612
+ formatTaskUpdate(task, changes) {
613
+ const lines = [];
614
+ if (task.title) {
615
+ lines.push(`- **标题**: ${task.title}`);
616
+ }
617
+ lines.push(`- **ID**: ${task.id}`);
618
+ if (changes?.status) {
619
+ lines.push(`- **状态**: ${changes.status}`);
620
+ }
621
+ if (changes?.progress !== undefined) {
622
+ lines.push(`- **进度**: ${changes.progress}%`);
623
+ }
624
+ if (changes?.current_status) {
625
+ lines.push(`- **当前状态**: ${changes.current_status}`);
626
+ }
627
+ const changeKeys = Object.keys(changes || {}).filter((k) => !["status", "progress", "current_status"].includes(k));
628
+ if (changeKeys.length > 0) {
629
+ lines.push(`- **变更**: ${changeKeys.join(", ")}`);
630
+ }
631
+ return lines.join(`
632
+ `);
633
+ }
634
+ }
635
+ __legacyDecorateClassTS([
636
+ TracedAs("lark-cli-task-notify.execute")
637
+ ], LarkCliTaskNotifyHook.prototype, "execute", null);
638
+ __legacyDecorateClassTS([
639
+ TracedAs("lark-cli-task-notify.sendNotify")
640
+ ], LarkCliTaskNotifyHook.prototype, "sendNotify", null);
641
+ __legacyDecorateClassTS([
642
+ TracedAs("lark-cli-task-notify.sendLarkMessage")
643
+ ], LarkCliTaskNotifyHook.prototype, "sendLarkMessage", null);
644
+ function createLarkCliTaskNotifyHook(config = {}) {
645
+ return new LarkCliTaskNotifyHook(config);
646
+ }
647
+ export { WORKFLOW_EXTRACTOR_PROMPT, createWorkflowExtractorAgent, formatExtractorInput, formatExtractorInputFromDescription, parseExtractorOutput, TaskTagPlugin, NotifyType, LarkCliTaskNotifyHook, createLarkCliTaskNotifyHook };
@@ -2,17 +2,17 @@ import {
2
2
  ContextError,
3
3
  ErrorCodes
4
4
  } from "./roy-agent-core-ctdhjv68.js";
5
- import {
6
- BaseComponent
7
- } from "./roy-agent-core-cefh9hjv.js";
8
5
  import {
9
6
  TracedAs,
10
7
  init_decorator
11
- } from "./roy-agent-core-zgypchmt.js";
8
+ } from "./roy-agent-core-q5qj0fes.js";
9
+ import {
10
+ BaseComponent
11
+ } from "./roy-agent-core-4jqq077c.js";
12
12
  import {
13
13
  createLogger,
14
14
  init_logger
15
- } from "./roy-agent-core-44hnfb02.js";
15
+ } from "./roy-agent-core-10n2jh7p.js";
16
16
  import {
17
17
  __legacyDecorateClassTS
18
18
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -6,11 +6,11 @@ import {
6
6
  } from "./roy-agent-core-qxhq8ven.js";
7
7
  import {
8
8
  BaseComponent
9
- } from "./roy-agent-core-cefh9hjv.js";
9
+ } from "./roy-agent-core-4jqq077c.js";
10
10
  import {
11
11
  createLogger,
12
12
  init_logger
13
- } from "./roy-agent-core-44hnfb02.js";
13
+ } from "./roy-agent-core-10n2jh7p.js";
14
14
 
15
15
  // src/env/memory/types.ts
16
16
  import { z } from "zod";