@ai-setting/roy-agent-core 1.7.49 → 1.7.51

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 (87) hide show
  1. package/dist/config/index.js +7 -7
  2. package/dist/env/agent/index.js +10 -10
  3. package/dist/env/commands/index.js +7 -7
  4. package/dist/env/context/index.js +3 -3
  5. package/dist/env/debug/index.js +7 -7
  6. package/dist/env/event-source/index.js +17 -14
  7. package/dist/env/hook/index.js +9 -6
  8. package/dist/env/index.js +38 -34
  9. package/dist/env/llm/index.js +7 -7
  10. package/dist/env/log-trace/index.js +7 -7
  11. package/dist/env/mcp/index.js +7 -7
  12. package/dist/env/memory/index.js +11 -11
  13. package/dist/env/plugin/index.js +7 -7
  14. package/dist/env/prompt/index.js +8 -8
  15. package/dist/env/session/index.js +7 -7
  16. package/dist/env/skill/index.js +7 -7
  17. package/dist/env/task/delegate/index.js +8 -8
  18. package/dist/env/task/index.js +17 -17
  19. package/dist/env/task/plugins/index.js +10 -9
  20. package/dist/env/task/storage/index.js +2 -2
  21. package/dist/env/task/tools/index.js +3 -3
  22. package/dist/env/tool/built-in/index.js +2 -2
  23. package/dist/env/tool/index.js +8 -8
  24. package/dist/env/workflow/engine/index.js +12 -9
  25. package/dist/env/workflow/hooks/index.js +25 -0
  26. package/dist/env/workflow/index.js +19 -17
  27. package/dist/env/workflow/nodes/index.js +2 -2
  28. package/dist/env/workflow/plugins/index.js +18 -0
  29. package/dist/env/workflow/service/index.js +2 -2
  30. package/dist/env/workflow/storage/index.js +3 -3
  31. package/dist/env/workflow/tools/index.js +11 -11
  32. package/dist/env/workflow/utils/index.js +24 -4
  33. package/dist/index.js +79 -70
  34. package/dist/shared/@ai-setting/{roy-agent-core-3ajh3cdj.js → roy-agent-core-0cfaqnz9.js} +1 -1
  35. package/dist/shared/@ai-setting/{roy-agent-core-trd6my5j.js → roy-agent-core-1cv9j4dg.js} +3 -3
  36. package/dist/shared/@ai-setting/{roy-agent-core-48f17g3x.js → roy-agent-core-2gay3sjt.js} +1 -1
  37. package/dist/shared/@ai-setting/{roy-agent-core-e302nvzt.js → roy-agent-core-2k4xffaa.js} +3 -3
  38. package/dist/shared/@ai-setting/{roy-agent-core-1pjct4nj.js → roy-agent-core-35s1w7tc.js} +230 -96
  39. package/dist/shared/@ai-setting/{roy-agent-core-hqtp5m8v.js → roy-agent-core-39xejr39.js} +13 -13
  40. package/dist/shared/@ai-setting/{roy-agent-core-v6zdngr7.js → roy-agent-core-3tv1q6f2.js} +8 -8
  41. package/dist/shared/@ai-setting/{roy-agent-core-mqaht7mm.js → roy-agent-core-4z3rq5gw.js} +2 -2
  42. package/dist/shared/@ai-setting/{roy-agent-core-fm77q3tn.js → roy-agent-core-5apmk4qw.js} +1 -1
  43. package/dist/shared/@ai-setting/{roy-agent-core-xmfyt3dg.js → roy-agent-core-6167phd4.js} +2 -2
  44. package/dist/shared/@ai-setting/{roy-agent-core-wt37tszm.js → roy-agent-core-7evvpfwc.js} +1 -1
  45. package/dist/shared/@ai-setting/{roy-agent-core-azdsyhvx.js → roy-agent-core-7g03zkkb.js} +1 -1
  46. package/dist/shared/@ai-setting/{roy-agent-core-v2d0bt7e.js → roy-agent-core-8s9jd2qy.js} +1 -1
  47. package/dist/shared/@ai-setting/{roy-agent-core-8pqq9yjt.js → roy-agent-core-978b6wfx.js} +1 -1
  48. package/dist/shared/@ai-setting/roy-agent-core-9csa89jx.js +46 -0
  49. package/dist/shared/@ai-setting/{roy-agent-core-x8ebdrtn.js → roy-agent-core-9faekt5n.js} +9 -5
  50. package/dist/shared/@ai-setting/{roy-agent-core-cnsjr3ws.js → roy-agent-core-9jzysq50.js} +2 -2
  51. package/dist/shared/@ai-setting/{roy-agent-core-5ja22qkf.js → roy-agent-core-ak4dc3kg.js} +1 -1
  52. package/dist/shared/@ai-setting/{roy-agent-core-ncaqkyfj.js → roy-agent-core-athdr2m0.js} +1 -1
  53. package/dist/shared/@ai-setting/{roy-agent-core-bt6h398s.js → roy-agent-core-dsevjbck.js} +20 -7
  54. package/dist/shared/@ai-setting/{roy-agent-core-5hjtbvxf.js → roy-agent-core-dv714bqh.js} +1 -1
  55. package/dist/shared/@ai-setting/{roy-agent-core-k0mx0tkh.js → roy-agent-core-dwx9hjwx.js} +1 -1
  56. package/dist/shared/@ai-setting/roy-agent-core-fs36xgcs.js +13 -0
  57. package/dist/shared/@ai-setting/{roy-agent-core-ydwtpzyf.js → roy-agent-core-fvs48d38.js} +4 -4
  58. package/dist/shared/@ai-setting/{roy-agent-core-223v204d.js → roy-agent-core-gdsqp6j8.js} +139 -15
  59. package/dist/shared/@ai-setting/{roy-agent-core-emjpkx9s.js → roy-agent-core-k8b440n3.js} +1 -1
  60. package/dist/shared/@ai-setting/{roy-agent-core-5vf48m39.js → roy-agent-core-kyasfzeh.js} +75 -754
  61. package/dist/shared/@ai-setting/roy-agent-core-na73mym1.js +367 -0
  62. package/dist/shared/@ai-setting/{roy-agent-core-j783tcqb.js → roy-agent-core-nde5gzta.js} +1 -1
  63. package/dist/shared/@ai-setting/{roy-agent-core-e2569ptp.js → roy-agent-core-ne2t1pay.js} +2 -2
  64. package/dist/shared/@ai-setting/{roy-agent-core-k0sy76cw.js → roy-agent-core-p2r27era.js} +17 -13
  65. package/dist/shared/@ai-setting/{roy-agent-core-xvf97xs4.js → roy-agent-core-p8ak03s0.js} +3 -3
  66. package/dist/shared/@ai-setting/{roy-agent-core-56j2q0w6.js → roy-agent-core-qamktze3.js} +1 -1
  67. package/dist/shared/@ai-setting/{roy-agent-core-khx0h4j2.js → roy-agent-core-qcspfszy.js} +11 -4
  68. package/dist/shared/@ai-setting/{roy-agent-core-rqyxdrxg.js → roy-agent-core-qm9jda8p.js} +1 -1
  69. package/dist/shared/@ai-setting/{roy-agent-core-yq45m8mm.js → roy-agent-core-rnwr39b0.js} +2 -2
  70. package/dist/shared/@ai-setting/{roy-agent-core-ed4tbkyj.js → roy-agent-core-rx16h2m1.js} +7 -3
  71. package/dist/shared/@ai-setting/{roy-agent-core-sea232w4.js → roy-agent-core-s214vmmd.js} +13 -13
  72. package/dist/shared/@ai-setting/{roy-agent-core-ecb8am8s.js → roy-agent-core-skzjs973.js} +5 -5
  73. package/dist/shared/@ai-setting/{roy-agent-core-zc9k2n3c.js → roy-agent-core-stnddvx9.js} +4 -4
  74. package/dist/shared/@ai-setting/{roy-agent-core-f51kwn6m.js → roy-agent-core-t37wbysj.js} +4 -4
  75. package/dist/shared/@ai-setting/{roy-agent-core-xn12d221.js → roy-agent-core-tdbv7ff4.js} +5 -3
  76. package/dist/shared/@ai-setting/{roy-agent-core-yes3mr8n.js → roy-agent-core-tjg71zqp.js} +1 -1
  77. package/dist/shared/@ai-setting/{roy-agent-core-yge38dkn.js → roy-agent-core-vrsxhw9e.js} +1 -1
  78. package/dist/shared/@ai-setting/{roy-agent-core-kazn764f.js → roy-agent-core-vvxb9522.js} +20 -7
  79. package/dist/shared/@ai-setting/{roy-agent-core-vrj9c5y6.js → roy-agent-core-wwytg8rv.js} +14 -7
  80. package/dist/shared/@ai-setting/roy-agent-core-wxsgay02.js +302 -0
  81. package/dist/shared/@ai-setting/{roy-agent-core-c0mnxxck.js → roy-agent-core-x8n1r7h4.js} +1 -1
  82. package/dist/shared/@ai-setting/{roy-agent-core-m9drr1fd.js → roy-agent-core-yd21n6c7.js} +2 -2
  83. package/dist/shared/@ai-setting/{roy-agent-core-zff8vvs5.js → roy-agent-core-yhsssn86.js} +1 -1
  84. package/dist/shared/@ai-setting/roy-agent-core-zd077w51.js +1037 -0
  85. package/dist/shared/@ai-setting/{roy-agent-core-2bbj3jqd.js → roy-agent-core-zd3ddm4k.js} +1 -1
  86. package/package.json +1 -1
  87. package/dist/shared/@ai-setting/roy-agent-core-98wwn2px.js +0 -35
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-xmfyt3dg.js";
4
+ } from "./roy-agent-core-6167phd4.js";
5
5
  import"./roy-agent-core-1db4vpc6.js";
6
6
  import"./roy-agent-core-ze068vc9.js";
7
7
  import"./roy-agent-core-e25xkv53.js";
8
- import"./roy-agent-core-mqaht7mm.js";
9
- import"./roy-agent-core-emjpkx9s.js";
10
- import"./roy-agent-core-fm77q3tn.js";
11
- import"./roy-agent-core-bt6h398s.js";
8
+ import"./roy-agent-core-4z3rq5gw.js";
9
+ import"./roy-agent-core-k8b440n3.js";
10
+ import"./roy-agent-core-5apmk4qw.js";
11
+ import"./roy-agent-core-dsevjbck.js";
12
12
  import"./roy-agent-core-8seq65bp.js";
13
13
  import"./roy-agent-core-jnszp0jq.js";
14
14
  import"./roy-agent-core-fs0mn2jk.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  builtInPrompts
3
- } from "./roy-agent-core-223v204d.js";
3
+ } from "./roy-agent-core-gdsqp6j8.js";
4
4
  import {
5
5
  getXDGPath
6
6
  } from "./roy-agent-core-qxnbvgwe.js";
@@ -10,14 +10,14 @@ import {
10
10
  } from "./roy-agent-core-7hh0brvs.js";
11
11
  import {
12
12
  BaseComponent
13
- } from "./roy-agent-core-xn12d221.js";
13
+ } from "./roy-agent-core-tdbv7ff4.js";
14
14
  import {
15
15
  createHook
16
- } from "./roy-agent-core-khx0h4j2.js";
16
+ } from "./roy-agent-core-qcspfszy.js";
17
17
  import {
18
18
  globalHookManager,
19
19
  init_global_hook_manager
20
- } from "./roy-agent-core-mqaht7mm.js";
20
+ } from "./roy-agent-core-4z3rq5gw.js";
21
21
  import {
22
22
  createLogger,
23
23
  init_logger
@@ -3,17 +3,17 @@ import {
3
3
  } from "./roy-agent-core-az13yzmc.js";
4
4
  import {
5
5
  BaseComponent
6
- } from "./roy-agent-core-xn12d221.js";
6
+ } from "./roy-agent-core-tdbv7ff4.js";
7
7
  import {
8
8
  globalHookManager,
9
9
  init_global_hook_manager
10
- } from "./roy-agent-core-mqaht7mm.js";
10
+ } from "./roy-agent-core-4z3rq5gw.js";
11
11
  import {
12
12
  init_context
13
- } from "./roy-agent-core-emjpkx9s.js";
13
+ } from "./roy-agent-core-k8b440n3.js";
14
14
  import {
15
15
  getEnvContextOrEmpty
16
- } from "./roy-agent-core-fm77q3tn.js";
16
+ } from "./roy-agent-core-5apmk4qw.js";
17
17
  import {
18
18
  createLogger,
19
19
  init_logger
@@ -1,11 +1,13 @@
1
1
  import {
2
- createHook
3
- } from "./roy-agent-core-khx0h4j2.js";
2
+ createHook,
3
+ init_hook
4
+ } from "./roy-agent-core-qcspfszy.js";
4
5
  import {
5
6
  HookManager
6
- } from "./roy-agent-core-mqaht7mm.js";
7
+ } from "./roy-agent-core-4z3rq5gw.js";
7
8
 
8
9
  // src/env/component.ts
10
+ init_hook();
9
11
  class BaseComponent {
10
12
  _status = "created";
11
13
  _enabled = true;
@@ -11,7 +11,7 @@ import {
11
11
  import {
12
12
  TracedAs,
13
13
  init_decorator
14
- } from "./roy-agent-core-bt6h398s.js";
14
+ } from "./roy-agent-core-dsevjbck.js";
15
15
  import {
16
16
  __esm,
17
17
  __legacyDecorateClassTS
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  TracedAs,
11
11
  init_decorator
12
- } from "./roy-agent-core-bt6h398s.js";
12
+ } from "./roy-agent-core-dsevjbck.js";
13
13
  import {
14
14
  createLogger,
15
15
  init_logger
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  isValidSessionId
3
- } from "./roy-agent-core-m9drr1fd.js";
3
+ } from "./roy-agent-core-yd21n6c7.js";
4
4
  import {
5
5
  TAG_MAX_COUNT,
6
6
  TAG_MIN_COUNT
7
- } from "./roy-agent-core-wt37tszm.js";
7
+ } from "./roy-agent-core-7evvpfwc.js";
8
8
  import {
9
9
  validateWorkflowDefinition
10
- } from "./roy-agent-core-98wwn2px.js";
10
+ } from "./roy-agent-core-na73mym1.js";
11
11
  import {
12
12
  getCurrentBgTaskId
13
13
  } from "./roy-agent-core-c1v263jn.js";
@@ -18,7 +18,7 @@ import {
18
18
  import {
19
19
  TracedAs,
20
20
  init_decorator
21
- } from "./roy-agent-core-bt6h398s.js";
21
+ } from "./roy-agent-core-dsevjbck.js";
22
22
  import {
23
23
  createLogger,
24
24
  init_logger
@@ -485,7 +485,7 @@ var WorkflowValidateInputSchema = z6.object({
485
485
  function createWorkflowValidateTool(_workflowService) {
486
486
  return {
487
487
  name: "workflow_validate",
488
- description: `Validate a workflow definition (YAML or JSON) without persisting it. ` + `Checks for: duplicate node IDs, missing dependencies, cycles, empty node IDs. ` + `Returns { valid: boolean, errors: string[], workflowName?, nodeCount }. ` + `Use this BEFORE workflow_add to ensure the workflow is structurally sound.`,
488
+ description: `Validate a workflow definition (YAML or JSON) without persisting it. ` + `Checks (1) DAG structure: duplicate node IDs, missing dependencies, cycles, empty node IDs; ` + `(2) template-reference contracts: whether {{nodes.X.<field>}} matches node X's output shape ` + `(e.g. {{nodes.<toolNode>.result}} is an ERROR — tool nodes expose ".output", not ".result"). ` + `Returns { valid, errors: string[], warnings?: string[], infos?: string[], workflowName?, ` + `nodeCount, errorCount, warningCount }. ` + `Use this BEFORE workflow_add; fix EVERY error (and evaluate each warning) before registering.`,
489
489
  parameters: WorkflowValidateInputSchema,
490
490
  execute: async (args, _ctx) => {
491
491
  try {
@@ -524,16 +524,29 @@ function createWorkflowValidateTool(_workflowService) {
524
524
  }
525
525
  const result = validateWorkflowDefinition(definition);
526
526
  const nodeCount = Array.isArray(definition.nodes) ? definition.nodes.length : 0;
527
+ const warnings = result.warnings ?? [];
528
+ const infos = result.infos ?? [];
527
529
  const output = {
528
530
  valid: result.valid,
529
531
  errors: result.errors,
532
+ warnings,
533
+ infos,
530
534
  workflowName: definition.name,
531
- nodeCount
535
+ nodeCount,
536
+ errorCount: result.errors.length,
537
+ warningCount: warnings.length
532
538
  };
539
+ const errorText = result.valid ? undefined : `Validation failed (${result.errors.length} error(s)):
540
+ ` + result.errors.map((e, i) => ` ${i + 1}. ${e}`).join(`
541
+ `) + (warnings.length > 0 ? `
542
+
543
+ Advisory warnings (${warnings.length}) — evaluate and fix where sensible:
544
+ ` + warnings.map((w, i) => ` - ${w}`).join(`
545
+ `) : "");
533
546
  return {
534
547
  success: result.valid,
535
548
  output: JSON.stringify(output, null, 2),
536
- error: result.valid ? undefined : `Validation failed: ${result.errors.join("; ")}`,
549
+ error: errorText,
537
550
  metadata: { execution_time_ms: 0 }
538
551
  };
539
552
  } catch (error) {
@@ -6,10 +6,13 @@ import {
6
6
  createLarkCliTaskNotifyHook,
7
7
  createPerTaskGroupChatPlugin,
8
8
  mergeChatOwnership
9
- } from "./roy-agent-core-5vf48m39.js";
9
+ } from "./roy-agent-core-kyasfzeh.js";
10
10
  import {
11
11
  getSharedEventStore
12
- } from "./roy-agent-core-zff8vvs5.js";
12
+ } from "./roy-agent-core-yhsssn86.js";
13
+ import {
14
+ createLarkCliWorkflowNotifyHook
15
+ } from "./roy-agent-core-wxsgay02.js";
13
16
  import {
14
17
  normalizeLarkAtMentions
15
18
  } from "./roy-agent-core-64f22h1g.js";
@@ -18,24 +21,24 @@ import {
18
21
  } from "./roy-agent-core-7hh0brvs.js";
19
22
  import {
20
23
  BaseComponent
21
- } from "./roy-agent-core-xn12d221.js";
24
+ } from "./roy-agent-core-tdbv7ff4.js";
22
25
  import {
23
26
  globalHookManager,
24
27
  init_global_hook_manager
25
- } from "./roy-agent-core-mqaht7mm.js";
28
+ } from "./roy-agent-core-4z3rq5gw.js";
26
29
  import {
27
30
  init_context
28
- } from "./roy-agent-core-emjpkx9s.js";
31
+ } from "./roy-agent-core-k8b440n3.js";
29
32
  import {
30
33
  createEnvContext,
31
34
  normalizeParentTaskId,
32
35
  runWithEnvContext
33
- } from "./roy-agent-core-fm77q3tn.js";
36
+ } from "./roy-agent-core-5apmk4qw.js";
34
37
  import {
35
38
  TracedAs,
36
39
  init_decorator,
37
40
  wrapFunction
38
- } from "./roy-agent-core-bt6h398s.js";
41
+ } from "./roy-agent-core-dsevjbck.js";
39
42
  import {
40
43
  createLogger,
41
44
  getTracerProvider,
@@ -846,6 +849,7 @@ function isPluginDebugEnabled() {
846
849
  }
847
850
  var BUILT_IN_PLUGIN_FACTORIES = {
848
851
  LarkCliTaskNotifyPlugin: (cfg) => createLarkCliTaskNotifyHook(cfg),
852
+ LarkCliWorkflowNotifyPlugin: (cfg) => createLarkCliWorkflowNotifyHook(cfg),
849
853
  PerTaskGroupChatPlugin: (cfg) => createPerTaskGroupChatPlugin(cfg),
850
854
  "task-tag": () => new TaskTagPlugin
851
855
  };
@@ -1208,6 +1212,9 @@ class LarkCliInstance {
1208
1212
  if (Array.isArray(plugin.hooks)) {
1209
1213
  return plugin.hooks.map((h) => h.point || h);
1210
1214
  }
1215
+ if (Array.isArray(plugin.hookPoints)) {
1216
+ return plugin.hookPoints.map((h) => h.point || h);
1217
+ }
1211
1218
  if (typeof plugin.execute === "function" && plugin.hookPoint) {
1212
1219
  return [plugin.hookPoint];
1213
1220
  }
@@ -0,0 +1,302 @@
1
+ import {
2
+ LarkCardPatchNotifier,
3
+ formatDurationMs
4
+ } from "./roy-agent-core-zd077w51.js";
5
+ import {
6
+ WorkflowHookPoints,
7
+ init_workflow_hook_points
8
+ } from "./roy-agent-core-9csa89jx.js";
9
+ import {
10
+ init_context
11
+ } from "./roy-agent-core-k8b440n3.js";
12
+ import {
13
+ getEnvContextOrEmpty
14
+ } from "./roy-agent-core-5apmk4qw.js";
15
+ import {
16
+ TracedAs,
17
+ init_decorator
18
+ } from "./roy-agent-core-dsevjbck.js";
19
+ import {
20
+ createLogger,
21
+ init_logger
22
+ } from "./roy-agent-core-8seq65bp.js";
23
+ import {
24
+ __legacyDecorateClassTS
25
+ } from "./roy-agent-core-fs0mn2jk.js";
26
+
27
+ // src/env/workflow/plugins/lark-cli-workflow-notify-plugin.ts
28
+ init_decorator();
29
+ init_logger();
30
+ init_context();
31
+ init_workflow_hook_points();
32
+ var logger = createLogger("lark-cli:workflow-notify");
33
+
34
+ class LarkCliWorkflowNotifyHook {
35
+ name;
36
+ priority;
37
+ description;
38
+ pluginName;
39
+ sourceId;
40
+ hookPoints = [
41
+ WorkflowHookPoints.BEFORE_RUN,
42
+ WorkflowHookPoints.AFTER_RUN,
43
+ WorkflowHookPoints.BEFORE_NODE,
44
+ WorkflowHookPoints.AFTER_NODE
45
+ ];
46
+ config;
47
+ cardNotifier;
48
+ cardMessageIds = new Map;
49
+ lastNodeNotifyTimestamps = new Map;
50
+ static CARD_START_FAILED_SENTINEL = "__wf_card_start_failed__";
51
+ static CARD_START_INFLIGHT_SENTINEL = "__wf_card_start_inflight__";
52
+ constructor(config = {}) {
53
+ this.name = config.pluginName || "LarkCliWorkflowNotifyPlugin";
54
+ this.priority = config.priority ?? 5;
55
+ this.description = "LarkCli workflow 进展通知 Hook(卡片模式)";
56
+ this.pluginName = config.pluginName;
57
+ this.sourceId = config.sourceId;
58
+ this.config = {
59
+ enabled: true,
60
+ priority: 5,
61
+ ...config
62
+ };
63
+ this.cardNotifier = config.cardNotifier ?? new LarkCardPatchNotifier;
64
+ }
65
+ async execute(ctx) {
66
+ if (!this.config.enabled)
67
+ return;
68
+ const env = getEnvContextOrEmpty();
69
+ if (this.pluginName && this.sourceId) {
70
+ const key = `${this.sourceId}:${this.pluginName}`;
71
+ if (env.pluginEnabled && env.pluginEnabled[key] !== true) {
72
+ logger.debug(`Plugin not enabled for source: ${key}`);
73
+ return;
74
+ }
75
+ }
76
+ switch (ctx.hookPoint) {
77
+ case WorkflowHookPoints.BEFORE_RUN:
78
+ await this.onBeforeRun(ctx);
79
+ break;
80
+ case WorkflowHookPoints.AFTER_RUN:
81
+ await this.onAfterRun(ctx);
82
+ break;
83
+ case WorkflowHookPoints.BEFORE_NODE:
84
+ await this.onBeforeNode(ctx);
85
+ break;
86
+ case WorkflowHookPoints.AFTER_NODE:
87
+ await this.onAfterNode(ctx);
88
+ break;
89
+ default:
90
+ logger.debug(`ignored hook point: ${ctx.hookPoint}`);
91
+ }
92
+ }
93
+ async onBeforeRun(ctx) {
94
+ const data = ctx.data;
95
+ if (!data?.runId)
96
+ return;
97
+ await this.sendCardStart(data);
98
+ }
99
+ async onBeforeNode(ctx) {
100
+ const data = ctx.data;
101
+ if (!data?.runId)
102
+ return;
103
+ if (this.shouldThrottleNodeStart(data.runId))
104
+ return;
105
+ const timestamp = new Date().toISOString();
106
+ await this.patchCard(data, {
107
+ currentNode: data.nodeId,
108
+ currentNodeType: data.nodeType,
109
+ processSteps: [
110
+ {
111
+ title: `${data.nodeId} 开始`,
112
+ timestamp,
113
+ category: data.nodeType
114
+ }
115
+ ]
116
+ });
117
+ }
118
+ async onAfterNode(ctx) {
119
+ const data = ctx.data;
120
+ if (!data?.runId)
121
+ return;
122
+ const timestamp = new Date().toISOString();
123
+ const nodeStatus = String(data.status);
124
+ const succeeded = nodeStatus === "completed" || nodeStatus === "skipped";
125
+ const statusText = succeeded ? "完成" : "失败";
126
+ const durationText = formatDurationMs(data.durationMs);
127
+ const description = data.error ?? (durationText ? `耗时 ${durationText}` : succeeded ? undefined : `节点状态:${nodeStatus}`);
128
+ const processSteps = [
129
+ {
130
+ title: `${data.nodeId} ${statusText}`,
131
+ timestamp,
132
+ endTimestamp: timestamp,
133
+ description,
134
+ category: data.nodeType
135
+ }
136
+ ];
137
+ const milestones = succeeded || !data.error ? [] : [
138
+ {
139
+ title: `节点失败:${data.nodeId}`,
140
+ timestamp,
141
+ description: data.error
142
+ }
143
+ ];
144
+ await this.patchCard(data, {
145
+ currentNode: data.nodeId,
146
+ currentNodeType: data.nodeType,
147
+ milestones,
148
+ processSteps
149
+ });
150
+ }
151
+ async onAfterRun(ctx) {
152
+ const data = ctx.data;
153
+ if (!data?.runId)
154
+ return;
155
+ const messageId = this.cardMessageIds.get(data.runId);
156
+ if (!messageId || messageId === LarkCliWorkflowNotifyHook.CARD_START_FAILED_SENTINEL || messageId === LarkCliWorkflowNotifyHook.CARD_START_INFLIGHT_SENTINEL) {
157
+ logger.debug(`onAfterRun: no card for run ${data.runId}, skip`);
158
+ return;
159
+ }
160
+ const status = this.mapRunStatus(data.status);
161
+ const target = this.resolveTarget();
162
+ const profile = target.profile;
163
+ try {
164
+ await this.cardNotifier.finishWorkflow({
165
+ messageId,
166
+ chatId: target.chatId,
167
+ profile,
168
+ status,
169
+ meta: this.buildWorkflowMeta(data),
170
+ completedNodes: data.completedNodes,
171
+ totalNodes: data.totalNodes,
172
+ durationMs: data.durationMs,
173
+ error: data.error ?? data.stopReason,
174
+ finalStep: data.status === "completed" ? undefined : data.stopReason
175
+ });
176
+ this.cardMessageIds.delete(data.runId);
177
+ this.lastNodeNotifyTimestamps.delete(`node:${data.runId}`);
178
+ } catch (err) {
179
+ logger.error(`sendCardFinish failed for workflow run ${data.runId}: ${err.message}`);
180
+ }
181
+ }
182
+ async sendCardStart(data) {
183
+ if (!this.cardNotifier)
184
+ return;
185
+ const claim = this.cardMessageIds.get(data.runId);
186
+ if (claim) {
187
+ logger.debug(`sendCardStart: run ${data.runId} 已有首卡(${claim})→ 跳过重复建卡`);
188
+ return;
189
+ }
190
+ this.cardMessageIds.set(data.runId, LarkCliWorkflowNotifyHook.CARD_START_INFLIGHT_SENTINEL);
191
+ const target = this.resolveTarget();
192
+ if (!target.chatId) {
193
+ this.cardMessageIds.delete(data.runId);
194
+ logger.debug(`sendCardStart: no chatId for run ${data.runId}, skip`);
195
+ return;
196
+ }
197
+ try {
198
+ const res = await this.cardNotifier.startWorkflow({
199
+ chatId: target.chatId,
200
+ profile: target.profile,
201
+ meta: this.buildWorkflowMeta(data),
202
+ totalNodes: data.totalNodes,
203
+ completedNodes: data.completedNodes ?? 0,
204
+ milestones: [
205
+ {
206
+ title: "Workflow 启动",
207
+ timestamp: new Date().toISOString(),
208
+ description: data.workflowName
209
+ }
210
+ ]
211
+ });
212
+ this.cardMessageIds.set(data.runId, res.messageId);
213
+ logger.debug(`sendCardStart: run ${data.runId} → message ${res.messageId} ` + `(pinned=${res.pinned}) chat=${target.chatId}`);
214
+ } catch (err) {
215
+ this.cardMessageIds.set(data.runId, LarkCliWorkflowNotifyHook.CARD_START_FAILED_SENTINEL);
216
+ logger.error(`sendCardStart failed for run ${data.runId}: ${err.message}`);
217
+ }
218
+ }
219
+ async patchCard(data, extra) {
220
+ if (!this.cardNotifier)
221
+ return;
222
+ const messageId = this.cardMessageIds.get(data.runId);
223
+ if (!messageId) {
224
+ logger.debug(`patchCard: no card for run ${data.runId}, skip`);
225
+ return;
226
+ }
227
+ if (messageId === LarkCliWorkflowNotifyHook.CARD_START_FAILED_SENTINEL || messageId === LarkCliWorkflowNotifyHook.CARD_START_INFLIGHT_SENTINEL) {
228
+ logger.debug(`patchCard: card not ready for run ${data.runId} (${messageId}), skip`);
229
+ return;
230
+ }
231
+ const target = this.resolveTarget();
232
+ if (!target.chatId) {
233
+ logger.debug(`patchCard: no chatId for run ${data.runId}, skip`);
234
+ return;
235
+ }
236
+ try {
237
+ await this.cardNotifier.updateWorkflow({
238
+ messageId,
239
+ chatId: target.chatId,
240
+ profile: target.profile,
241
+ status: "running",
242
+ meta: this.buildWorkflowMeta(data),
243
+ completedNodes: data.completedNodes,
244
+ totalNodes: data.totalNodes,
245
+ currentNode: extra.currentNode,
246
+ currentNodeType: extra.currentNodeType,
247
+ milestones: extra.milestones,
248
+ processSteps: extra.processSteps
249
+ });
250
+ } catch (err) {
251
+ logger.error(`patchCard failed for run ${data.runId}: ${err.message}`);
252
+ }
253
+ }
254
+ resolveTarget() {
255
+ const env = getEnvContextOrEmpty();
256
+ const rc = env.replyChannel;
257
+ return {
258
+ chatId: rc?.chatId,
259
+ profile: rc?.profile
260
+ };
261
+ }
262
+ buildWorkflowMeta(data) {
263
+ const run = data;
264
+ return {
265
+ runId: data.runId,
266
+ workflowName: data.workflowName,
267
+ workflowId: run.workflowId,
268
+ input: run.input
269
+ };
270
+ }
271
+ mapRunStatus(status) {
272
+ switch (String(status)) {
273
+ case "completed":
274
+ return "completed";
275
+ case "stopped":
276
+ return "stopped";
277
+ default:
278
+ return "failed";
279
+ }
280
+ }
281
+ shouldThrottleNodeStart(runId) {
282
+ const throttleMs = this.config.nodeThrottleMs ?? 3000;
283
+ if (throttleMs <= 0)
284
+ return false;
285
+ const key = `node:${runId}`;
286
+ const now = Date.now();
287
+ const last = this.lastNodeNotifyTimestamps.get(key);
288
+ if (last && now - last < throttleMs) {
289
+ logger.debug(`[throttle] skip before.node patch for run ${runId} (${now - last}ms ago)`);
290
+ return true;
291
+ }
292
+ this.lastNodeNotifyTimestamps.set(key, now);
293
+ return false;
294
+ }
295
+ }
296
+ __legacyDecorateClassTS([
297
+ TracedAs("lark-cli-workflow-notify.execute")
298
+ ], LarkCliWorkflowNotifyHook.prototype, "execute", null);
299
+ function createLarkCliWorkflowNotifyHook(config = {}) {
300
+ return new LarkCliWorkflowNotifyHook(config);
301
+ }
302
+ export { LarkCliWorkflowNotifyHook, createLarkCliWorkflowNotifyHook };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-bt6h398s.js";
4
+ } from "./roy-agent-core-dsevjbck.js";
5
5
  import {
6
6
  __esm,
7
7
  __legacyDecorateClassTS
@@ -16,11 +16,11 @@ import {
16
16
  } from "./roy-agent-core-7hh0brvs.js";
17
17
  import {
18
18
  BaseComponent
19
- } from "./roy-agent-core-xn12d221.js";
19
+ } from "./roy-agent-core-tdbv7ff4.js";
20
20
  import {
21
21
  TracedAs,
22
22
  init_decorator
23
- } from "./roy-agent-core-bt6h398s.js";
23
+ } from "./roy-agent-core-dsevjbck.js";
24
24
  import {
25
25
  createLogger,
26
26
  init_logger
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-bt6h398s.js";
4
+ } from "./roy-agent-core-dsevjbck.js";
5
5
  import {
6
6
  __legacyDecorateClassTS,
7
7
  __require