@ai-setting/roy-agent-core 1.7.8 → 1.7.10

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.
@@ -11,7 +11,7 @@ import {
11
11
  larkCliHandler,
12
12
  resolveBountyIMSystemPrompt,
13
13
  timerHandler
14
- } from "../../shared/@ai-setting/roy-agent-core-w4dy6zzf.js";
14
+ } from "../../shared/@ai-setting/roy-agent-core-7zy1mpmw.js";
15
15
  import"../../shared/@ai-setting/roy-agent-core-pz2n121t.js";
16
16
  import {
17
17
  BUILT_IN_EVENT_SOURCE_TYPES,
package/dist/env/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  EventSourceComponent,
16
16
  builtInHandlers,
17
17
  larkCliHandler
18
- } from "../shared/@ai-setting/roy-agent-core-w4dy6zzf.js";
18
+ } from "../shared/@ai-setting/roy-agent-core-7zy1mpmw.js";
19
19
  import"../shared/@ai-setting/roy-agent-core-pz2n121t.js";
20
20
  import {
21
21
  EventSourceInitHooks,
@@ -29,7 +29,7 @@ import"../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
29
29
  import"../shared/@ai-setting/roy-agent-core-skqt40yy.js";
30
30
  import {
31
31
  WorkflowComponent
32
- } from "../shared/@ai-setting/roy-agent-core-7bskb5j2.js";
32
+ } from "../shared/@ai-setting/roy-agent-core-0phpmeqj.js";
33
33
  import"../shared/@ai-setting/roy-agent-core-7xek618f.js";
34
34
  import"../shared/@ai-setting/roy-agent-core-h0x19xgn.js";
35
35
  import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
@@ -38,13 +38,13 @@ import"../shared/@ai-setting/roy-agent-core-v13dq3nc.js";
38
38
  import"../shared/@ai-setting/roy-agent-core-wgp3q62x.js";
39
39
  import"../shared/@ai-setting/roy-agent-core-hhrg314p.js";
40
40
  import"../shared/@ai-setting/roy-agent-core-j9ybhwnq.js";
41
- import"../shared/@ai-setting/roy-agent-core-cpfdvzqk.js";
41
+ import"../shared/@ai-setting/roy-agent-core-wrjm9etv.js";
42
42
  import"../shared/@ai-setting/roy-agent-core-6atd905e.js";
43
43
  import"../shared/@ai-setting/roy-agent-core-ec4djnzd.js";
44
44
  import"../shared/@ai-setting/roy-agent-core-hmqmznjc.js";
45
45
  import"../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
46
46
  import"../shared/@ai-setting/roy-agent-core-w8rv08d3.js";
47
- import"../shared/@ai-setting/roy-agent-core-h1cb2jzh.js";
47
+ import"../shared/@ai-setting/roy-agent-core-rfwshpd0.js";
48
48
  import"../shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
49
49
  import"../shared/@ai-setting/roy-agent-core-0v74marc.js";
50
50
  import"../shared/@ai-setting/roy-agent-core-jrj30vq3.js";
@@ -5,12 +5,12 @@ import {
5
5
  Scheduler,
6
6
  WorkflowEngine,
7
7
  init_engine
8
- } from "../../../shared/@ai-setting/roy-agent-core-cpfdvzqk.js";
8
+ } from "../../../shared/@ai-setting/roy-agent-core-wrjm9etv.js";
9
9
  import"../../../shared/@ai-setting/roy-agent-core-6atd905e.js";
10
10
  import"../../../shared/@ai-setting/roy-agent-core-ec4djnzd.js";
11
11
  import"../../../shared/@ai-setting/roy-agent-core-hmqmznjc.js";
12
12
  import"../../../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
13
- import"../../../shared/@ai-setting/roy-agent-core-h1cb2jzh.js";
13
+ import"../../../shared/@ai-setting/roy-agent-core-rfwshpd0.js";
14
14
  import"../../../shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
15
15
  import {
16
16
  DAGManager
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  WorkflowComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-7bskb5j2.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-0phpmeqj.js";
4
4
  import"../../shared/@ai-setting/roy-agent-core-7xek618f.js";
5
5
  import {
6
6
  Edge,
@@ -19,13 +19,13 @@ import"../../shared/@ai-setting/roy-agent-core-v13dq3nc.js";
19
19
  import"../../shared/@ai-setting/roy-agent-core-wgp3q62x.js";
20
20
  import"../../shared/@ai-setting/roy-agent-core-hhrg314p.js";
21
21
  import"../../shared/@ai-setting/roy-agent-core-j9ybhwnq.js";
22
- import"../../shared/@ai-setting/roy-agent-core-cpfdvzqk.js";
22
+ import"../../shared/@ai-setting/roy-agent-core-wrjm9etv.js";
23
23
  import"../../shared/@ai-setting/roy-agent-core-6atd905e.js";
24
24
  import"../../shared/@ai-setting/roy-agent-core-ec4djnzd.js";
25
25
  import"../../shared/@ai-setting/roy-agent-core-hmqmznjc.js";
26
26
  import"../../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
27
27
  import"../../shared/@ai-setting/roy-agent-core-w8rv08d3.js";
28
- import"../../shared/@ai-setting/roy-agent-core-h1cb2jzh.js";
28
+ import"../../shared/@ai-setting/roy-agent-core-rfwshpd0.js";
29
29
  import"../../shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
30
30
  import"../../shared/@ai-setting/roy-agent-core-0v74marc.js";
31
31
  import {
@@ -6,7 +6,7 @@ import {
6
6
  init_template_resolver,
7
7
  resolveTemplateString,
8
8
  resolveTemplates
9
- } from "../../../shared/@ai-setting/roy-agent-core-h1cb2jzh.js";
9
+ } from "../../../shared/@ai-setting/roy-agent-core-rfwshpd0.js";
10
10
  import {
11
11
  getFromMapWithNormalization,
12
12
  init_node_id_utils
package/dist/index.js CHANGED
@@ -92,7 +92,7 @@ import {
92
92
  larkCliHandler,
93
93
  resolveBountyIMSystemPrompt,
94
94
  timerHandler
95
- } from "./shared/@ai-setting/roy-agent-core-w4dy6zzf.js";
95
+ } from "./shared/@ai-setting/roy-agent-core-7zy1mpmw.js";
96
96
  import {
97
97
  LogTraceComponent,
98
98
  LogTraceConfigSchema
@@ -119,7 +119,7 @@ import {
119
119
  } from "./shared/@ai-setting/roy-agent-core-skqt40yy.js";
120
120
  import {
121
121
  WorkflowComponent
122
- } from "./shared/@ai-setting/roy-agent-core-7bskb5j2.js";
122
+ } from "./shared/@ai-setting/roy-agent-core-0phpmeqj.js";
123
123
  import {
124
124
  init_node_registry_helper,
125
125
  registerDecoratorNodeType
@@ -141,13 +141,13 @@ import {
141
141
  } from "./shared/@ai-setting/roy-agent-core-wgp3q62x.js";
142
142
  import"./shared/@ai-setting/roy-agent-core-hhrg314p.js";
143
143
  import"./shared/@ai-setting/roy-agent-core-j9ybhwnq.js";
144
- import"./shared/@ai-setting/roy-agent-core-cpfdvzqk.js";
144
+ import"./shared/@ai-setting/roy-agent-core-wrjm9etv.js";
145
145
  import"./shared/@ai-setting/roy-agent-core-6atd905e.js";
146
146
  import"./shared/@ai-setting/roy-agent-core-ec4djnzd.js";
147
147
  import"./shared/@ai-setting/roy-agent-core-hmqmznjc.js";
148
148
  import"./shared/@ai-setting/roy-agent-core-1db4vpc6.js";
149
149
  import"./shared/@ai-setting/roy-agent-core-w8rv08d3.js";
150
- import"./shared/@ai-setting/roy-agent-core-h1cb2jzh.js";
150
+ import"./shared/@ai-setting/roy-agent-core-rfwshpd0.js";
151
151
  import"./shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
152
152
  import"./shared/@ai-setting/roy-agent-core-0v74marc.js";
153
153
  import"./shared/@ai-setting/roy-agent-core-jrj30vq3.js";
@@ -21,7 +21,7 @@ import {
21
21
  WorkflowEngine,
22
22
  exports_engine,
23
23
  init_engine
24
- } from "./roy-agent-core-cpfdvzqk.js";
24
+ } from "./roy-agent-core-wrjm9etv.js";
25
25
  import {
26
26
  BaseComponent
27
27
  } from "./roy-agent-core-pde8hkq4.js";
@@ -588,8 +588,238 @@ var bountyIMHandler = {
588
588
 
589
589
  // src/env/event-source/event-source-handlers.ts
590
590
  init_global_hook_manager();
591
- import { spawn } from "child_process";
591
+ import { spawn as spawn2 } from "child_process";
592
592
  init_context();
593
+
594
+ // src/env/event-source/bounty-cli-handler.ts
595
+ import { spawn } from "child_process";
596
+ function readBountyCliConfig(config) {
597
+ const topChannel = config.channel;
598
+ const topProfile = config.profile;
599
+ const topCommand = config.command;
600
+ const optionsChannel = config.options?.channel;
601
+ const optionsProfile = config.options?.profile;
602
+ return {
603
+ channel: topChannel || optionsChannel,
604
+ profile: topProfile || optionsProfile,
605
+ customCommand: topCommand
606
+ };
607
+ }
608
+ function buildDefaultCommand(profile, channel) {
609
+ const profileFlag = profile ? `--profile ${profile} ` : "";
610
+ return `bounty ${profileFlag}event consume --channel ${channel}`;
611
+ }
612
+ function translateEvent(raw, fallbackChannel) {
613
+ const eventId = String(raw.event_id ?? "");
614
+ const eventType = String(raw.event_type ?? "");
615
+ const sourceTime = raw.source_time ? String(raw.source_time) : undefined;
616
+ const appId = raw.app_id ? String(raw.app_id) : undefined;
617
+ const tenantKey = raw.tenant_key ? String(raw.tenant_key) : undefined;
618
+ const payload = raw.payload ?? {};
619
+ const mmPost = payload;
620
+ const messageId = mmPost.id;
621
+ const channelId = mmPost.channel_id;
622
+ const channelName = mmPost.channel_name ?? fallbackChannel;
623
+ const userId = mmPost.user_id;
624
+ const metadata = {
625
+ sourceType: "bounty-cli",
626
+ eventId,
627
+ eventType,
628
+ sourceTime,
629
+ appId,
630
+ tenantKey,
631
+ channelName,
632
+ chatType: "mattermost",
633
+ payload
634
+ };
635
+ metadata.userId = userId;
636
+ metadata.message = mmPost.message;
637
+ const replyChannel = {
638
+ type: "bounty-cli",
639
+ appId,
640
+ params: {
641
+ channelId,
642
+ channelName
643
+ },
644
+ chatId: channelId,
645
+ messageId
646
+ };
647
+ return { metadata, replyChannel };
648
+ }
649
+ function buildBountyCliRecommendedAction(input) {
650
+ const { profile, channelName } = input;
651
+ const profileFlag = profile ? ` --profile ${profile}` : "";
652
+ return {
653
+ description: "Reply to a bounty-cli (Mattermost) event via the `bounty event publish` subcommand.",
654
+ command: `bounty${profileFlag} event publish --channel ${channelName} --text "<reply text>"`,
655
+ notes: [
656
+ `--channel accepts both channel NAME (e.g. ${channelName}) and channel ID.`,
657
+ profile ? `Use --profile ${profile} if you have multiple Mattermost accounts configured.` : "Omit --profile if you only have one Mattermost account."
658
+ ]
659
+ };
660
+ }
661
+
662
+ class BountyCliInstance {
663
+ config;
664
+ status = "created";
665
+ child;
666
+ buffer = "";
667
+ eventHandler;
668
+ constructor(config) {
669
+ this.config = config;
670
+ }
671
+ getStatus() {
672
+ return this.status;
673
+ }
674
+ setEventHandler(handler) {
675
+ this.eventHandler = handler;
676
+ }
677
+ setStatus(status) {
678
+ this.status = status;
679
+ }
680
+ async start() {
681
+ if (this.status === "running")
682
+ return;
683
+ this.setStatus("starting");
684
+ const { channel, profile, customCommand } = readBountyCliConfig(this.config);
685
+ if (!channel && !customCommand) {
686
+ throw new Error("bounty-cli event source requires 'channel' (or 'command') in config");
687
+ }
688
+ const command = customCommand || buildDefaultCommand(profile, channel);
689
+ this.child = spawn(`exec ${command}`, [], {
690
+ shell: true,
691
+ stdio: ["pipe", "pipe", "pipe"],
692
+ windowsHide: true
693
+ });
694
+ let stdoutBuffer = "";
695
+ let stderrBuffer = "";
696
+ this.child.stdout?.on("data", (data) => {
697
+ const str = data.toString();
698
+ stdoutBuffer += str;
699
+ this.processStdout(stdoutBuffer, channel ?? "");
700
+ stdoutBuffer = "";
701
+ });
702
+ this.child.stderr?.on("data", (data) => {
703
+ const output = data.toString();
704
+ stderrBuffer += output;
705
+ this.processStderr(stderrBuffer);
706
+ stderrBuffer = "";
707
+ });
708
+ this.child.on("exit", (code, signal) => {
709
+ if (code !== 0 && signal !== "SIGINT" && signal !== "SIGTERM") {
710
+ this.setStatus("error");
711
+ } else {
712
+ this.setStatus("stopped");
713
+ }
714
+ });
715
+ this.child.on("error", (err) => {
716
+ console.error(`[bounty-cli] spawn error: ${err.message}`);
717
+ this.setStatus("error");
718
+ });
719
+ this.setStatus("running");
720
+ }
721
+ processStdout(buffer, fallbackChannel) {
722
+ const lines = buffer.split(`
723
+ `);
724
+ const tail = lines.pop() ?? "";
725
+ this.buffer = tail;
726
+ for (const line of lines) {
727
+ const trimmed = line.trim();
728
+ if (!trimmed)
729
+ continue;
730
+ this.handleEventLine(trimmed, fallbackChannel);
731
+ }
732
+ }
733
+ processStderr(buffer) {
734
+ const lines = buffer.split(`
735
+ `);
736
+ const tail = lines.pop() ?? "";
737
+ for (const line of lines) {
738
+ const trimmed = line.trim();
739
+ if (!trimmed)
740
+ continue;
741
+ if (trimmed.startsWith("{") && trimmed.includes("event_id")) {
742
+ this.handleEventLine(trimmed, readBountyCliConfig(this.config).channel ?? "");
743
+ }
744
+ }
745
+ if (tail.trim().length > 0) {
746
+ this.buffer = tail;
747
+ } else {
748
+ this.buffer = "";
749
+ }
750
+ }
751
+ handleEventLine(line, fallbackChannel) {
752
+ let raw;
753
+ try {
754
+ raw = JSON.parse(line);
755
+ } catch {
756
+ console.error(`[bounty-cli] failed to parse event line: ${line.slice(0, 200)}`);
757
+ return;
758
+ }
759
+ const { metadata, replyChannel } = translateEvent(raw, fallbackChannel);
760
+ const event = {
761
+ metadata,
762
+ rawEvent: raw,
763
+ replyChannel,
764
+ recommendedAction: buildBountyCliRecommendedAction({
765
+ profile: readBountyCliConfig(this.config).profile,
766
+ channelName: String(metadata.channelName ?? fallbackChannel)
767
+ })
768
+ };
769
+ if (this.eventHandler) {
770
+ try {
771
+ this.eventHandler(event);
772
+ } catch (err) {
773
+ console.error(`[bounty-cli] event handler threw: ${err}`);
774
+ }
775
+ }
776
+ }
777
+ async stop() {
778
+ if (this.status === "stopped" || this.status === "created")
779
+ return;
780
+ if (this.child && !this.child.killed) {
781
+ this.child.kill("SIGINT");
782
+ await new Promise((resolve) => {
783
+ const timer = setTimeout(() => {
784
+ if (this.child && !this.child.killed) {
785
+ this.child.kill("SIGKILL");
786
+ }
787
+ resolve();
788
+ }, 3000);
789
+ if (this.child) {
790
+ this.child.on("exit", () => {
791
+ clearTimeout(timer);
792
+ resolve();
793
+ });
794
+ } else {
795
+ clearTimeout(timer);
796
+ resolve();
797
+ }
798
+ });
799
+ }
800
+ this.setStatus("stopped");
801
+ }
802
+ }
803
+ var bountyCliHandler = {
804
+ type: "bounty-cli",
805
+ validateConfig(config) {
806
+ const errors = [];
807
+ if (!config.id)
808
+ errors.push("EventSource ID is required");
809
+ if (!config.name)
810
+ errors.push("EventSource name is required");
811
+ const { channel, customCommand } = readBountyCliConfig(config);
812
+ if (!channel && !customCommand) {
813
+ errors.push("Bounty CLI 'channel' (top-level channel or options.channel) is required");
814
+ }
815
+ return errors;
816
+ },
817
+ createInstance(config) {
818
+ return new BountyCliInstance(config);
819
+ }
820
+ };
821
+
822
+ // src/env/event-source/event-source-handlers.ts
593
823
  var BUILT_IN_PLUGIN_FACTORIES = {
594
824
  LarkCliTaskNotifyPlugin: (cfg) => createLarkCliTaskNotifyHook(cfg),
595
825
  "task-tag": () => new TaskTagPlugin
@@ -739,7 +969,7 @@ class LarkCliInstance {
739
969
  } else {
740
970
  command = `lark-cli ${profileFlag}event consume im.message.receive_v1 --as bot`;
741
971
  }
742
- this.child = spawn("exec " + command, [], {
972
+ this.child = spawn2("exec " + command, [], {
743
973
  shell: true,
744
974
  stdio: ["pipe", "pipe", "pipe"],
745
975
  windowsHide: true
@@ -1132,7 +1362,7 @@ class LarkCliInstance {
1132
1362
  if (profile) {
1133
1363
  args.unshift("--profile", profile);
1134
1364
  }
1135
- const proc = spawn("lark-cli", args, {
1365
+ const proc = spawn2("lark-cli", args, {
1136
1366
  shell: false,
1137
1367
  stdio: ["pipe", "pipe", "pipe"]
1138
1368
  });
@@ -1177,7 +1407,8 @@ var larkCliHandler = {
1177
1407
  var builtInHandlers = [
1178
1408
  larkCliHandler,
1179
1409
  timerHandler,
1180
- bountyIMHandler
1410
+ bountyIMHandler,
1411
+ bountyCliHandler
1181
1412
  ];
1182
1413
  function getBuiltInHandler(type) {
1183
1414
  return builtInHandlers.find((h) => h.type === type);
@@ -283,7 +283,7 @@ var init_template_resolver = __esm(() => {
283
283
  }
284
284
  stringify(value, originalTemplate) {
285
285
  if (value === undefined) {
286
- return originalTemplate;
286
+ return "";
287
287
  }
288
288
  if (typeof value === "string") {
289
289
  return value;
@@ -29,7 +29,7 @@ import {
29
29
  import {
30
30
  TemplateResolver,
31
31
  init_template_resolver
32
- } from "./roy-agent-core-h1cb2jzh.js";
32
+ } from "./roy-agent-core-rfwshpd0.js";
33
33
  import {
34
34
  DAGManager,
35
35
  init_dag_manager
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.7.8",
3
+ "version": "1.7.10",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",
@@ -86,4 +86,4 @@
86
86
  "bugs": {
87
87
  "url": "https://github.com/ai-setting/roy-agent/issues"
88
88
  }
89
- }
89
+ }