@ai-setting/roy-agent-core 1.5.85 → 1.5.86

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.
@@ -1,10 +1,12 @@
1
- import"../../shared/@ai-setting/roy-agent-core-2grcjaad.js";
1
+ import"../../shared/@ai-setting/roy-agent-core-4f3976cd.js";
2
2
  import {
3
3
  EventSourceComponent,
4
+ TimerInstance,
4
5
  builtInHandlers,
5
6
  getBuiltInHandler,
6
- larkCliHandler
7
- } from "../../shared/@ai-setting/roy-agent-core-ya1ayt1k.js";
7
+ larkCliHandler,
8
+ timerHandler
9
+ } from "../../shared/@ai-setting/roy-agent-core-6mk0m4t3.js";
8
10
  import {
9
11
  BUILT_IN_EVENT_SOURCE_TYPES,
10
12
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
@@ -13,7 +15,7 @@ import {
13
15
  isBuiltInEventSourceType,
14
16
  isValidEventSourceType,
15
17
  validateEventSourceConfig
16
- } from "../../shared/@ai-setting/roy-agent-core-xb4hvk1m.js";
18
+ } from "../../shared/@ai-setting/roy-agent-core-qhhxx2x2.js";
17
19
  import"../../shared/@ai-setting/roy-agent-core-v8xa6vs8.js";
18
20
  import"../../shared/@ai-setting/roy-agent-core-7fdzfsm6.js";
19
21
  import"../../shared/@ai-setting/roy-agent-core-az13yzmc.js";
@@ -31,12 +33,14 @@ import"../../shared/@ai-setting/roy-agent-core-c6592r3c.js";
31
33
  import"../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
32
34
  export {
33
35
  validateEventSourceConfig,
36
+ timerHandler,
34
37
  larkCliHandler,
35
38
  isValidEventSourceType,
36
39
  isBuiltInEventSourceType,
37
40
  getDefaultConfigForType,
38
41
  getBuiltInHandler,
39
42
  builtInHandlers,
43
+ TimerInstance,
40
44
  EventSourceInitHooks,
41
45
  EventSourceComponent,
42
46
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
package/dist/env/index.js CHANGED
@@ -5,14 +5,14 @@ import {
5
5
  EventSourceComponent,
6
6
  builtInHandlers,
7
7
  larkCliHandler
8
- } from "../shared/@ai-setting/roy-agent-core-ya1ayt1k.js";
8
+ } from "../shared/@ai-setting/roy-agent-core-6mk0m4t3.js";
9
9
  import {
10
10
  EventSourceInitHooks,
11
11
  getDefaultConfigForType,
12
12
  isBuiltInEventSourceType,
13
13
  isValidEventSourceType,
14
14
  validateEventSourceConfig
15
- } from "../shared/@ai-setting/roy-agent-core-xb4hvk1m.js";
15
+ } from "../shared/@ai-setting/roy-agent-core-qhhxx2x2.js";
16
16
  import"../shared/@ai-setting/roy-agent-core-v8xa6vs8.js";
17
17
  import {
18
18
  PluginComponent
@@ -44,9 +44,9 @@ import"../shared/@ai-setting/roy-agent-core-r0m0at3x.js";
44
44
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
45
45
  import {
46
46
  TaskComponent
47
- } from "../shared/@ai-setting/roy-agent-core-dv12wpdv.js";
47
+ } from "../shared/@ai-setting/roy-agent-core-bk5g94yd.js";
48
48
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
49
- import"../shared/@ai-setting/roy-agent-core-0kt57b72.js";
49
+ import"../shared/@ai-setting/roy-agent-core-bgw4dq11.js";
50
50
  import"../shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
51
51
  import"../shared/@ai-setting/roy-agent-core-7z4xtrmw.js";
52
52
  import {
@@ -3,7 +3,7 @@ import {
3
3
  BackgroundTaskManager,
4
4
  createDelegateTool,
5
5
  createStopTool
6
- } from "../../../shared/@ai-setting/roy-agent-core-0kt57b72.js";
6
+ } from "../../../shared/@ai-setting/roy-agent-core-bgw4dq11.js";
7
7
  import"../../../shared/@ai-setting/roy-agent-core-7z4xtrmw.js";
8
8
  import"../../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
9
9
  import"../../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
@@ -5,11 +5,11 @@ import {
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum,
7
7
  TaskTypeEnum
8
- } from "../../shared/@ai-setting/roy-agent-core-dv12wpdv.js";
8
+ } from "../../shared/@ai-setting/roy-agent-core-bk5g94yd.js";
9
9
  import {
10
10
  TaskEntityEventTypes
11
11
  } from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
12
- import"../../shared/@ai-setting/roy-agent-core-0kt57b72.js";
12
+ import"../../shared/@ai-setting/roy-agent-core-bgw4dq11.js";
13
13
  import {
14
14
  SQLiteTaskStore,
15
15
  getDefaultTaskDbPath
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  closeDatabase
38
38
  } from "./shared/@ai-setting/roy-agent-core-h4h55x4h.js";
39
39
  import"./shared/@ai-setting/roy-agent-core-3sv590cv.js";
40
- import"./shared/@ai-setting/roy-agent-core-2grcjaad.js";
40
+ import"./shared/@ai-setting/roy-agent-core-4f3976cd.js";
41
41
  import {
42
42
  MemoryComponent
43
43
  } from "./shared/@ai-setting/roy-agent-core-2h38rvyj.js";
@@ -61,10 +61,12 @@ import {
61
61
  } from "./shared/@ai-setting/roy-agent-core-29fh9mxg.js";
62
62
  import {
63
63
  EventSourceComponent,
64
+ TimerInstance,
64
65
  builtInHandlers,
65
66
  getBuiltInHandler,
66
- larkCliHandler
67
- } from "./shared/@ai-setting/roy-agent-core-ya1ayt1k.js";
67
+ larkCliHandler,
68
+ timerHandler
69
+ } from "./shared/@ai-setting/roy-agent-core-6mk0m4t3.js";
68
70
  import {
69
71
  BUILT_IN_EVENT_SOURCE_TYPES,
70
72
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
@@ -73,7 +75,7 @@ import {
73
75
  isBuiltInEventSourceType,
74
76
  isValidEventSourceType,
75
77
  validateEventSourceConfig
76
- } from "./shared/@ai-setting/roy-agent-core-xb4hvk1m.js";
78
+ } from "./shared/@ai-setting/roy-agent-core-qhhxx2x2.js";
77
79
  import {
78
80
  LogTraceComponent,
79
81
  LogTraceConfigSchema
@@ -130,9 +132,9 @@ import {
130
132
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
131
133
  import {
132
134
  TaskComponent
133
- } from "./shared/@ai-setting/roy-agent-core-dv12wpdv.js";
135
+ } from "./shared/@ai-setting/roy-agent-core-bk5g94yd.js";
134
136
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
135
- import"./shared/@ai-setting/roy-agent-core-0kt57b72.js";
137
+ import"./shared/@ai-setting/roy-agent-core-bgw4dq11.js";
136
138
  import {
137
139
  SQLiteTaskStore,
138
140
  getDefaultTaskDbPath
@@ -346,6 +348,7 @@ export {
346
348
  writeFileTool,
347
349
  wrapFunction,
348
350
  validateEventSourceConfig,
351
+ timerHandler,
349
352
  setQuietMode,
350
353
  setConfigComponent as setLoggerConfigComponent,
351
354
  setLogDirOverride,
@@ -405,6 +408,7 @@ export {
405
408
  ToolRegistry,
406
409
  ToolError,
407
410
  ToolComponent,
411
+ TimerInstance,
408
412
  TaskTagPlugin,
409
413
  TaskHookPoints,
410
414
  TaskComponent,
@@ -20,7 +20,8 @@ import {
20
20
  runWithEnvContext
21
21
  } from "./roy-agent-core-y5d04fm3.js";
22
22
  import {
23
- TracedAs
23
+ TracedAs,
24
+ init_decorator
24
25
  } from "./roy-agent-core-k05v31rc.js";
25
26
  import {
26
27
  createLogger,
@@ -34,6 +35,163 @@ import {
34
35
  __require
35
36
  } from "./roy-agent-core-fs0mn2jk.js";
36
37
 
38
+ // src/env/event-source/timer-handler.ts
39
+ init_decorator();
40
+ var DEFAULT_TIMER_INTERVAL_MS = 10 * 60 * 1000;
41
+ var SELF_REMINDER_MESSAGE = `[Timer Self-Reminder]
42
+ 请读取最近 1 周处理的 task 信息,分析用户当前的工作目标和重点任务。
43
+ 基于分析结果,自主构建有价值的任务来推进用户目标。
44
+
45
+ 分析维度:
46
+ 1. 最近完成的 task 类型和主题
47
+ 2. 进行中的 task 状态和阻塞点
48
+ 3. 用户的工作模式和偏好
49
+ 4. 可以主动优化的领域
50
+
51
+ 请根据分析结果,创建 1-3 个有价值的任务并执行。`;
52
+ var TIMER_OPTIONS_KEY_GET_MANAGER = "getBackgroundTaskManager";
53
+
54
+ class TimerInstance {
55
+ config;
56
+ interval;
57
+ sessionId;
58
+ getRunningTasks;
59
+ customPrompt;
60
+ status = "created";
61
+ timerId;
62
+ eventHandler;
63
+ constructor(config, getRunningTasks) {
64
+ this.config = config;
65
+ this.interval = typeof config.interval === "number" && config.interval > 0 ? config.interval : DEFAULT_TIMER_INTERVAL_MS;
66
+ this.sessionId = `timer-${config.id}-${process.pid}`;
67
+ const optionsPrompt = config.options?.prompt;
68
+ if (typeof optionsPrompt === "string" && optionsPrompt.trim().length > 0) {
69
+ this.customPrompt = optionsPrompt;
70
+ }
71
+ if (getRunningTasks) {
72
+ this.getRunningTasks = getRunningTasks;
73
+ } else {
74
+ const factory = config.options?.[TIMER_OPTIONS_KEY_GET_MANAGER];
75
+ if (typeof factory === "function") {
76
+ const manager = factory();
77
+ this.getRunningTasks = () => manager.listTasks();
78
+ } else {
79
+ this.getRunningTasks = () => [];
80
+ }
81
+ }
82
+ }
83
+ async start() {
84
+ if (this.status === "running")
85
+ return;
86
+ this.timerId = setInterval(() => {
87
+ this.tick();
88
+ }, this.interval);
89
+ this.status = "running";
90
+ }
91
+ async stop() {
92
+ if (this.timerId !== undefined) {
93
+ clearInterval(this.timerId);
94
+ this.timerId = undefined;
95
+ }
96
+ this.status = "stopped";
97
+ }
98
+ getStatus() {
99
+ return this.status;
100
+ }
101
+ onEvent(handler) {
102
+ this.eventHandler = handler;
103
+ }
104
+ offEvent() {
105
+ this.eventHandler = undefined;
106
+ }
107
+ tick() {
108
+ let allTasks;
109
+ try {
110
+ allTasks = this.getRunningTasks();
111
+ } catch (error) {
112
+ console.warn(`[TimerInstance] Failed to get running tasks, skipping tick: ${error}`);
113
+ return;
114
+ }
115
+ const hasRunning = Array.isArray(allTasks) && allTasks.some((t) => t.status === "running");
116
+ if (hasRunning) {
117
+ return;
118
+ }
119
+ const event = this.buildSelfReminderEvent();
120
+ this.eventHandler?.(event);
121
+ }
122
+ buildSelfReminderEvent() {
123
+ const timestamp = Date.now();
124
+ const message = this.customPrompt ?? SELF_REMINDER_MESSAGE;
125
+ return {
126
+ id: `es-${this.config.id}-${timestamp}-${Math.random().toString(36).slice(2, 8)}`,
127
+ type: "event-source.event.timer",
128
+ timestamp,
129
+ metadata: {
130
+ source: "event-source",
131
+ sourceId: this.config.id,
132
+ sourceMessageType: "timer.selfReminder",
133
+ sessionId: this.sessionId
134
+ },
135
+ payload: {
136
+ sourceId: this.config.id,
137
+ sourceType: "timer",
138
+ rawEvent: {
139
+ type: "timer.selfReminder",
140
+ triggeredAt: timestamp
141
+ },
142
+ message,
143
+ metadata: {
144
+ eventType: "timer.selfReminder",
145
+ sourceId: this.config.id,
146
+ sourceType: "timer",
147
+ timestamp
148
+ },
149
+ timestamp
150
+ }
151
+ };
152
+ }
153
+ }
154
+ __legacyDecorateClassTS([
155
+ TracedAs("timer.tick", { recordParams: false, log: false })
156
+ ], TimerInstance.prototype, "tick", null);
157
+ __legacyDecorateClassTS([
158
+ TracedAs("timer.buildSelfReminderEvent", { recordParams: false, log: false })
159
+ ], TimerInstance.prototype, "buildSelfReminderEvent", null);
160
+ var timerHandler = {
161
+ type: "timer",
162
+ validateConfig(config) {
163
+ const errors = [];
164
+ const { interval } = config;
165
+ if (interval !== undefined && interval !== null) {
166
+ if (typeof interval !== "number" || !Number.isFinite(interval)) {
167
+ errors.push("Timer interval must be a finite number");
168
+ } else if (interval <= 0) {
169
+ errors.push("Timer interval must be a positive number (milliseconds)");
170
+ }
171
+ }
172
+ return errors;
173
+ },
174
+ createInstance(config) {
175
+ return new TimerInstance(config);
176
+ },
177
+ getOptions() {
178
+ return [
179
+ {
180
+ name: "interval",
181
+ description: `Timer interval in milliseconds (default: ${DEFAULT_TIMER_INTERVAL_MS} = 10 minutes)`,
182
+ required: false,
183
+ type: "number"
184
+ },
185
+ {
186
+ name: "prompt",
187
+ description: "Custom prompt message for SelfReminder events (replaces default message)",
188
+ required: false,
189
+ type: "string"
190
+ }
191
+ ];
192
+ }
193
+ };
194
+
37
195
  // src/env/event-source/event-source-handlers.ts
38
196
  init_global_hook_manager();
39
197
  import { spawn } from "child_process";
@@ -543,7 +701,8 @@ var larkCliHandler = {
543
701
  }
544
702
  };
545
703
  var builtInHandlers = [
546
- larkCliHandler
704
+ larkCliHandler,
705
+ timerHandler
547
706
  ];
548
707
  function getBuiltInHandler(type) {
549
708
  return builtInHandlers.find((h) => h.type === type);
@@ -553,6 +712,7 @@ function getBuiltInHandler(type) {
553
712
  import { join } from "path";
554
713
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
555
714
  init_logger();
715
+ init_decorator();
556
716
 
557
717
  // src/env/event-source/event-source-config-registration.ts
558
718
  var EVENT_SOURCE_DEFAULTS = {
@@ -644,7 +804,7 @@ class EventSourceComponent extends BaseComponent {
644
804
  }
645
805
  }
646
806
  async executeInitHooks() {
647
- const { EventSourceInitHooks } = await import("./roy-agent-core-9mj7vzsm.js");
807
+ const { EventSourceInitHooks } = await import("./roy-agent-core-vneyghpg.js");
648
808
  await EventSourceInitHooks.execute(this);
649
809
  }
650
810
  registerHandler(handler) {
@@ -790,6 +950,57 @@ class EventSourceComponent extends BaseComponent {
790
950
  }
791
951
  return existed;
792
952
  }
953
+ async update(id, partial) {
954
+ if (!partial || Object.keys(partial).length === 0) {
955
+ throw new Error("update() partial must not be empty");
956
+ }
957
+ const existing = this.sources.get(id);
958
+ if (!existing) {
959
+ throw new Error(`EventSource not found: ${id}`);
960
+ }
961
+ if (Object.prototype.hasOwnProperty.call(partial, "type")) {
962
+ if (partial.type !== existing.type) {
963
+ throw new Error(`Cannot update event source type: ${existing.type} -> ${partial.type} (use unregister + register instead)`);
964
+ }
965
+ }
966
+ const wasRunning = this.statuses.get(id) === "running";
967
+ let stopped = false;
968
+ if (wasRunning) {
969
+ await this.stopSource(id);
970
+ stopped = true;
971
+ }
972
+ const updated = {
973
+ ...existing,
974
+ ...partial,
975
+ id: existing.id,
976
+ type: existing.type
977
+ };
978
+ const handler = this.handlers.get(existing.type);
979
+ if (handler) {
980
+ const errors = handler.validateConfig(updated);
981
+ if (errors.length > 0) {
982
+ throw new Error(`Invalid config after update: ${errors.join(", ")}`);
983
+ }
984
+ }
985
+ this.sources.set(id, updated);
986
+ logger.info(`EventSource updated: ${id}`, {
987
+ fields: Object.keys(partial)
988
+ });
989
+ try {
990
+ await this.saveConfig();
991
+ } catch (err) {
992
+ logger.error(`Failed to save config after updating ${id}:`, err);
993
+ throw err;
994
+ }
995
+ return {
996
+ id,
997
+ updated,
998
+ wasRunning,
999
+ stopped,
1000
+ restarted: false,
1001
+ fields: Object.keys(partial)
1002
+ };
1003
+ }
793
1004
  get(id) {
794
1005
  return this.sources.get(id);
795
1006
  }
@@ -931,5 +1142,8 @@ class EventSourceComponent extends BaseComponent {
931
1142
  }
932
1143
  }
933
1144
  }
1145
+ __legacyDecorateClassTS([
1146
+ TracedAs("event-source.update", { recordParams: false, log: false })
1147
+ ], EventSourceComponent.prototype, "update", null);
934
1148
 
935
- export { larkCliHandler, builtInHandlers, getBuiltInHandler, EventSourceComponent };
1149
+ export { TimerInstance, timerHandler, larkCliHandler, builtInHandlers, getBuiltInHandler, EventSourceComponent };
@@ -238,7 +238,7 @@ ${originalPrompt}
238
238
  `;
239
239
  }
240
240
  var DEFAULT_TIMEOUT = 1800000;
241
- var PROGRESS_INTERVAL = 120000;
241
+ var PROGRESS_INTERVAL = 600000;
242
242
 
243
243
  class BackgroundTaskManager {
244
244
  env;
@@ -5,7 +5,7 @@ import {
5
5
  BackgroundTaskManager,
6
6
  createDelegateTool,
7
7
  createStopTool
8
- } from "./roy-agent-core-0kt57b72.js";
8
+ } from "./roy-agent-core-bgw4dq11.js";
9
9
  import {
10
10
  SQLiteTaskStore,
11
11
  getDefaultTaskDbPath
@@ -1,6 +1,7 @@
1
1
  // src/env/event-source/types.ts
2
2
  var BUILT_IN_EVENT_SOURCE_TYPES = {
3
- LARK_CLI: "lark-cli"
3
+ LARK_CLI: "lark-cli",
4
+ TIMER: "timer"
4
5
  };
5
6
  var BUILT_IN_EVENT_SOURCE_TYPE_LIST = Object.values(BUILT_IN_EVENT_SOURCE_TYPES);
6
7
 
@@ -6,7 +6,7 @@ import {
6
6
  isBuiltInEventSourceType,
7
7
  isValidEventSourceType,
8
8
  validateEventSourceConfig
9
- } from "./roy-agent-core-xb4hvk1m.js";
9
+ } from "./roy-agent-core-qhhxx2x2.js";
10
10
  import"./roy-agent-core-fs0mn2jk.js";
11
11
  export {
12
12
  validateEventSourceConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.85",
3
+ "version": "1.5.86",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",