@ai-setting/roy-agent-core 1.7.36 → 1.7.38

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 (82) 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 +24 -14
  7. package/dist/env/hook/index.js +5 -5
  8. package/dist/env/index.js +33 -32
  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 +7 -7
  13. package/dist/env/plugin/index.js +7 -7
  14. package/dist/env/prompt/index.js +7 -7
  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 +7 -6
  18. package/dist/env/task/index.js +12 -11
  19. package/dist/env/task/plugins/index.js +7 -7
  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 +9 -9
  25. package/dist/env/workflow/index.js +17 -17
  26. package/dist/env/workflow/nodes/index.js +2 -2
  27. package/dist/env/workflow/service/index.js +2 -2
  28. package/dist/env/workflow/storage/index.js +3 -3
  29. package/dist/env/workflow/tools/index.js +11 -11
  30. package/dist/env/workflow/utils/index.js +4 -4
  31. package/dist/index.js +53 -43
  32. package/dist/shared/@ai-setting/{roy-agent-core-yf0ex8y1.js → roy-agent-core-333apxaa.js} +1 -1
  33. package/dist/shared/@ai-setting/{roy-agent-core-axh3vn8k.js → roy-agent-core-3m7j2wcb.js} +1 -1
  34. package/dist/shared/@ai-setting/{roy-agent-core-9drbkjfr.js → roy-agent-core-4cj6hram.js} +1 -1
  35. package/dist/shared/@ai-setting/{roy-agent-core-zda3rfr3.js → roy-agent-core-4kbvfnn1.js} +54 -5
  36. package/dist/shared/@ai-setting/{roy-agent-core-821bsh3r.js → roy-agent-core-5gpf5j51.js} +1 -1
  37. package/dist/shared/@ai-setting/{roy-agent-core-jq7g5nxz.js → roy-agent-core-5j4awbgc.js} +3 -3
  38. package/dist/shared/@ai-setting/{roy-agent-core-wgttzq8e.js → roy-agent-core-6vbgswjw.js} +1 -1
  39. package/dist/shared/@ai-setting/{roy-agent-core-52yt7e1t.js → roy-agent-core-83j0v0hs.js} +4 -4
  40. package/dist/shared/@ai-setting/{roy-agent-core-j9ejsmsj.js → roy-agent-core-8nv07zgr.js} +1 -1
  41. package/dist/shared/@ai-setting/{roy-agent-core-0czz1ynz.js → roy-agent-core-970btnjh.js} +5 -5
  42. package/dist/shared/@ai-setting/{roy-agent-core-yw07bvqz.js → roy-agent-core-9cqpdrnk.js} +3 -3
  43. package/dist/shared/@ai-setting/{roy-agent-core-q3zvkbj6.js → roy-agent-core-9qn92jhf.js} +2 -2
  44. package/dist/shared/@ai-setting/{roy-agent-core-t2vwy92b.js → roy-agent-core-9wsy4yfv.js} +1 -1
  45. package/dist/shared/@ai-setting/{roy-agent-core-qhjm0bxm.js → roy-agent-core-a9pbda78.js} +23 -13
  46. package/dist/shared/@ai-setting/{roy-agent-core-2adayzfa.js → roy-agent-core-cd9h49ng.js} +13 -13
  47. package/dist/shared/@ai-setting/{roy-agent-core-ds5f75pg.js → roy-agent-core-ck60j1q9.js} +19 -1
  48. package/dist/shared/@ai-setting/{roy-agent-core-z7q1re07.js → roy-agent-core-dfnyvxr9.js} +3 -3
  49. package/dist/shared/@ai-setting/{roy-agent-core-h1zamsb9.js → roy-agent-core-e02f0ywc.js} +69 -24
  50. package/dist/shared/@ai-setting/{roy-agent-core-gcnvcbft.js → roy-agent-core-e5pnnzdm.js} +29 -7
  51. package/dist/shared/@ai-setting/{roy-agent-core-krmhhje6.js → roy-agent-core-e8rxb9a6.js} +1 -1
  52. package/dist/shared/@ai-setting/{roy-agent-core-1kcstbn3.js → roy-agent-core-ff2ssff5.js} +1 -1
  53. package/dist/shared/@ai-setting/{roy-agent-core-xgarc0t2.js → roy-agent-core-gh6szaj5.js} +5 -5
  54. package/dist/shared/@ai-setting/{roy-agent-core-tft0pa6h.js → roy-agent-core-gpf33hn9.js} +264 -14
  55. package/dist/shared/@ai-setting/{roy-agent-core-zfcwa3w7.js → roy-agent-core-hfmpmt0k.js} +27 -5
  56. package/dist/shared/@ai-setting/{roy-agent-core-qz9jb9sp.js → roy-agent-core-hkj5v9xq.js} +1 -1
  57. package/dist/shared/@ai-setting/{roy-agent-core-anwh7050.js → roy-agent-core-mzyzdf33.js} +3 -3
  58. package/dist/shared/@ai-setting/{roy-agent-core-zma7p5p7.js → roy-agent-core-nz4n1w28.js} +1 -1
  59. package/dist/shared/@ai-setting/{roy-agent-core-hs75rxp3.js → roy-agent-core-p0c98phj.js} +2 -2
  60. package/dist/shared/@ai-setting/{roy-agent-core-1dacps3n.js → roy-agent-core-p2ham63a.js} +2 -2
  61. package/dist/shared/@ai-setting/{roy-agent-core-d5gwqrr5.js → roy-agent-core-pd0exvnq.js} +1 -1
  62. package/dist/shared/@ai-setting/{roy-agent-core-63nkhqa4.js → roy-agent-core-q3vbxprp.js} +5 -5
  63. package/dist/shared/@ai-setting/{roy-agent-core-e3qjt852.js → roy-agent-core-rgpkygbc.js} +1 -1
  64. package/dist/shared/@ai-setting/{roy-agent-core-j6h99erf.js → roy-agent-core-rhfywyz1.js} +1 -1
  65. package/dist/shared/@ai-setting/{roy-agent-core-k5csz66y.js → roy-agent-core-tm57tmds.js} +1 -1
  66. package/dist/shared/@ai-setting/{roy-agent-core-bny3nd8q.js → roy-agent-core-vh10qamt.js} +8 -8
  67. package/dist/shared/@ai-setting/{roy-agent-core-dz3m7dt4.js → roy-agent-core-vn6f4nxv.js} +7 -7
  68. package/dist/shared/@ai-setting/{roy-agent-core-2aq5f4e1.js → roy-agent-core-wacnvjaq.js} +4 -4
  69. package/dist/shared/@ai-setting/{roy-agent-core-dzfyjzgw.js → roy-agent-core-wb1b61f8.js} +20 -2
  70. package/dist/shared/@ai-setting/{roy-agent-core-3x6ej9vm.js → roy-agent-core-wfpzny0h.js} +4 -4
  71. package/dist/shared/@ai-setting/{roy-agent-core-ddq5hcp5.js → roy-agent-core-x6c45yqd.js} +3 -1
  72. package/dist/shared/@ai-setting/roy-agent-core-xyys5m1a.js +159 -0
  73. package/dist/shared/@ai-setting/{roy-agent-core-wphva2vs.js → roy-agent-core-y1n63tse.js} +2 -2
  74. package/dist/shared/@ai-setting/{roy-agent-core-n094tbjh.js → roy-agent-core-y7atw1kw.js} +1 -1
  75. package/dist/shared/@ai-setting/{roy-agent-core-jcdsghyr.js → roy-agent-core-yjjqm4ww.js} +1 -1
  76. package/dist/shared/@ai-setting/{roy-agent-core-743510fc.js → roy-agent-core-yjyvwxs4.js} +2 -2
  77. package/dist/shared/@ai-setting/{roy-agent-core-6thjwx6v.js → roy-agent-core-ym1hwrcm.js} +113 -2
  78. package/dist/shared/@ai-setting/{roy-agent-core-62c1t7wr.js → roy-agent-core-yv4anf1c.js} +2 -2
  79. package/dist/shared/@ai-setting/{roy-agent-core-jxgprc5a.js → roy-agent-core-z4486eek.js} +3 -2
  80. package/dist/shared/@ai-setting/{roy-agent-core-n3pwkwjh.js → roy-agent-core-za09t5g3.js} +1 -1
  81. package/package.json +1 -1
  82. /package/dist/shared/@ai-setting/{roy-agent-core-k5hxvaf0.js → roy-agent-core-3ztzc83c.js} +0 -0
@@ -9,7 +9,7 @@ import {
9
9
  searchTasksTool,
10
10
  treeTasksTool,
11
11
  updateTaskTool
12
- } from "./roy-agent-core-zfcwa3w7.js";
12
+ } from "./roy-agent-core-hfmpmt0k.js";
13
13
  import {
14
14
  createOperationTool,
15
15
  deleteOperationTool,
@@ -27,11 +27,11 @@ import {
27
27
  BackgroundTaskManager,
28
28
  createDelegateTool,
29
29
  createStopTool
30
- } from "./roy-agent-core-h1zamsb9.js";
30
+ } from "./roy-agent-core-e02f0ywc.js";
31
31
  import {
32
32
  SQLiteTaskStore,
33
33
  getDefaultTaskDbPath
34
- } from "./roy-agent-core-dzfyjzgw.js";
34
+ } from "./roy-agent-core-wb1b61f8.js";
35
35
  import {
36
36
  TaskHookPoints
37
37
  } from "./roy-agent-core-1pg0fepg.js";
@@ -40,19 +40,19 @@ import {
40
40
  } from "./roy-agent-core-7hh0brvs.js";
41
41
  import {
42
42
  BaseComponent
43
- } from "./roy-agent-core-62c1t7wr.js";
43
+ } from "./roy-agent-core-yv4anf1c.js";
44
44
  import {
45
45
  globalHookManager,
46
46
  init_global_hook_manager
47
- } from "./roy-agent-core-743510fc.js";
47
+ } from "./roy-agent-core-yjyvwxs4.js";
48
48
  import {
49
49
  getEnvContextOrEmpty,
50
50
  init_env_context
51
- } from "./roy-agent-core-jxgprc5a.js";
51
+ } from "./roy-agent-core-z4486eek.js";
52
52
  import {
53
53
  TracedAs,
54
54
  init_decorator
55
- } from "./roy-agent-core-qhjm0bxm.js";
55
+ } from "./roy-agent-core-a9pbda78.js";
56
56
  import {
57
57
  createLogger,
58
58
  init_logger
@@ -3,17 +3,17 @@ import {
3
3
  } from "./roy-agent-core-rmn29nrh.js";
4
4
  import {
5
5
  BaseComponent
6
- } from "./roy-agent-core-62c1t7wr.js";
6
+ } from "./roy-agent-core-yv4anf1c.js";
7
7
  import {
8
8
  globalHookManager,
9
9
  init_global_hook_manager
10
- } from "./roy-agent-core-743510fc.js";
10
+ } from "./roy-agent-core-yjyvwxs4.js";
11
11
  import {
12
12
  init_context
13
- } from "./roy-agent-core-1kcstbn3.js";
13
+ } from "./roy-agent-core-ff2ssff5.js";
14
14
  import {
15
15
  getEnvContextOrEmpty
16
- } from "./roy-agent-core-jxgprc5a.js";
16
+ } from "./roy-agent-core-z4486eek.js";
17
17
  import {
18
18
  createLogger,
19
19
  init_logger
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-qhjm0bxm.js";
4
+ } from "./roy-agent-core-a9pbda78.js";
5
5
  import {
6
6
  createLogger,
7
7
  init_logger
@@ -686,11 +686,29 @@ var init_sqlite_task_store = __esm(() => {
686
686
  createdAt: new Date(row.created_at).toISOString(),
687
687
  updatedAt: new Date(row.updated_at).toISOString(),
688
688
  due_date: row.due_date ? String(row.due_date) : undefined,
689
- tags: row.tags ? JSON.parse(row.tags) : undefined,
689
+ tags: SQLiteTaskStore.parseTagsSafely(row.tags),
690
690
  project_path: String(row.project_path ?? "unknown"),
691
691
  context: row.context
692
692
  };
693
693
  }
694
+ static parseTagsSafely(raw) {
695
+ if (raw === null || raw === undefined || raw === "") {
696
+ return;
697
+ }
698
+ const str = typeof raw === "string" ? raw : String(raw);
699
+ try {
700
+ const parsed = JSON.parse(str);
701
+ if (Array.isArray(parsed)) {
702
+ return parsed;
703
+ }
704
+ if (typeof parsed === "string") {
705
+ return [parsed];
706
+ }
707
+ return;
708
+ } catch {
709
+ return [str];
710
+ }
711
+ }
694
712
  rowToOperation(row) {
695
713
  const milestoneType = row.milestone_type ?? row.action_type;
696
714
  const milestoneTitle = row.milestone_title ?? row.action_title;
@@ -11,20 +11,20 @@ import {
11
11
  } from "./roy-agent-core-7hh0brvs.js";
12
12
  import {
13
13
  BaseComponent
14
- } from "./roy-agent-core-62c1t7wr.js";
14
+ } from "./roy-agent-core-yv4anf1c.js";
15
15
  import {
16
16
  ToolHookPoints,
17
17
  globalHookManager,
18
18
  init_global_hook_manager
19
- } from "./roy-agent-core-743510fc.js";
19
+ } from "./roy-agent-core-yjyvwxs4.js";
20
20
  import {
21
21
  getCurrentTaskId,
22
22
  init_env_context
23
- } from "./roy-agent-core-jxgprc5a.js";
23
+ } from "./roy-agent-core-z4486eek.js";
24
24
  import {
25
25
  TracedAs,
26
26
  init_decorator
27
- } from "./roy-agent-core-qhjm0bxm.js";
27
+ } from "./roy-agent-core-a9pbda78.js";
28
28
  import {
29
29
  createLogger,
30
30
  init_logger
@@ -2,17 +2,19 @@ import {
2
2
  BUILT_IN_EVENT_SOURCE_TYPES,
3
3
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
4
4
  EventSourceInitHooks,
5
+ defaultLarkCliRunner,
5
6
  getDefaultConfigForType,
6
7
  isBuiltInEventSourceType,
7
8
  isValidEventSourceType,
8
9
  validateEventSourceConfig
9
- } from "./roy-agent-core-ds5f75pg.js";
10
+ } from "./roy-agent-core-ck60j1q9.js";
10
11
  import"./roy-agent-core-fs0mn2jk.js";
11
12
  export {
12
13
  validateEventSourceConfig,
13
14
  isValidEventSourceType,
14
15
  isBuiltInEventSourceType,
15
16
  getDefaultConfigForType,
17
+ defaultLarkCliRunner,
16
18
  EventSourceInitHooks,
17
19
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
18
20
  BUILT_IN_EVENT_SOURCE_TYPES
@@ -0,0 +1,159 @@
1
+ import {
2
+ TracedAs,
3
+ init_decorator
4
+ } from "./roy-agent-core-a9pbda78.js";
5
+ import {
6
+ __legacyDecorateClassTS,
7
+ __require
8
+ } from "./roy-agent-core-fs0mn2jk.js";
9
+
10
+ // src/env/event-source/event-store.ts
11
+ init_decorator();
12
+ import { randomUUID } from "node:crypto";
13
+ function getDatabaseClass() {
14
+ if (typeof Bun !== "undefined") {
15
+ const { Database } = __require("bun:sqlite");
16
+ return Database;
17
+ } else {
18
+ return __require("better-sqlite3");
19
+ }
20
+ }
21
+ function createCompatibleDatabase(path) {
22
+ const Database = getDatabaseClass();
23
+ const db = new Database(path);
24
+ if (typeof db.run !== "function") {
25
+ db.run = function(sql, ...params) {
26
+ if (params.length > 0) {
27
+ return this.prepare(sql).run(...params);
28
+ } else {
29
+ return this.exec(sql);
30
+ }
31
+ };
32
+ }
33
+ return db;
34
+ }
35
+ class EventStoreImpl {
36
+ db;
37
+ insertStmt;
38
+ getByIdStmt;
39
+ recentStmt;
40
+ constructor(options) {
41
+ this.db = createCompatibleDatabase(options.dbPath);
42
+ try {
43
+ this.db.exec("PRAGMA journal_mode=WAL");
44
+ this.db.exec("PRAGMA synchronous=NORMAL");
45
+ this.db.exec("PRAGMA busy_timeout=5000");
46
+ } catch {}
47
+ this.db.exec(`CREATE TABLE IF NOT EXISTS event_store (
48
+ event_id TEXT PRIMARY KEY,
49
+ es_type TEXT NOT NULL,
50
+ sender_id TEXT NOT NULL,
51
+ text TEXT,
52
+ metadata TEXT NOT NULL,
53
+ raw_event TEXT,
54
+ created_at INTEGER NOT NULL
55
+ );`);
56
+ this.db.exec(`CREATE INDEX IF NOT EXISTS idx_es_sender_time
57
+ ON event_store (es_type, sender_id, created_at DESC);`);
58
+ this.insertStmt = this.db.prepare(`INSERT INTO event_store (event_id, es_type, sender_id, text, metadata, raw_event, created_at)
59
+ VALUES (?, ?, ?, ?, ?, ?, ?)`);
60
+ this.getByIdStmt = this.db.prepare(`SELECT event_id, es_type, sender_id, text, metadata, raw_event, created_at
61
+ FROM event_store WHERE event_id = ?`);
62
+ this.recentStmt = this.db.prepare(`SELECT event_id, es_type, sender_id, text, metadata, raw_event, created_at
63
+ FROM event_store
64
+ WHERE es_type = ? AND sender_id = ?
65
+ ORDER BY created_at DESC
66
+ LIMIT ?`);
67
+ }
68
+ async insertTriggerEvent(input, esType) {
69
+ const eventId = `evt_${Date.now()}_${randomUUID()}`;
70
+ const createdAt = Date.now();
71
+ const metadataJson = JSON.stringify(input.metadata ?? {});
72
+ const rawEventJson = input.rawEvent === undefined ? null : safeStringify(input.rawEvent);
73
+ this.insertStmt.run(eventId, esType, input.senderId, input.text ?? null, metadataJson, rawEventJson, createdAt);
74
+ return eventId;
75
+ }
76
+ async getEventById(eventId) {
77
+ const row = this.getByIdStmt.get(eventId);
78
+ if (!row)
79
+ return null;
80
+ return rowToPersistedEvent(row);
81
+ }
82
+ async getRecentEvents(esType, senderId, limit) {
83
+ const rows = this.recentStmt.all(esType, senderId, limit);
84
+ return rows.map((r) => rowToPersistedEvent(r));
85
+ }
86
+ close() {
87
+ this.db.close();
88
+ }
89
+ }
90
+ __legacyDecorateClassTS([
91
+ TracedAs("event_store.insert_trigger", { recordParams: true, recordResult: true })
92
+ ], EventStoreImpl.prototype, "insertTriggerEvent", null);
93
+ __legacyDecorateClassTS([
94
+ TracedAs("event_store.query_by_id", { recordParams: true, recordResult: false })
95
+ ], EventStoreImpl.prototype, "getEventById", null);
96
+ function rowToPersistedEvent(row) {
97
+ let metadata;
98
+ try {
99
+ metadata = row.metadata ? JSON.parse(row.metadata) : {};
100
+ } catch {
101
+ metadata = {};
102
+ }
103
+ let rawEvent;
104
+ if (row.raw_event) {
105
+ try {
106
+ rawEvent = JSON.parse(row.raw_event);
107
+ } catch {
108
+ rawEvent = null;
109
+ }
110
+ } else {
111
+ rawEvent = null;
112
+ }
113
+ return {
114
+ eventId: row.event_id,
115
+ esType: row.es_type,
116
+ senderId: row.sender_id,
117
+ text: row.text ?? null,
118
+ metadata,
119
+ rawEvent,
120
+ createdAt: typeof row.created_at === "bigint" ? Number(row.created_at) : row.created_at
121
+ };
122
+ }
123
+ function safeStringify(obj) {
124
+ const seen = new WeakSet;
125
+ try {
126
+ return JSON.stringify(obj, (_key, value) => {
127
+ if (typeof value === "function")
128
+ return "[Function]";
129
+ if (value === undefined)
130
+ return "[undefined]";
131
+ if (value === null)
132
+ return null;
133
+ if (value instanceof Error)
134
+ return `${value.name}: ${value.message}`;
135
+ if (typeof value === "object") {
136
+ if (seen.has(value))
137
+ return "[Circular]";
138
+ seen.add(value);
139
+ }
140
+ if (typeof value === "bigint")
141
+ return value.toString();
142
+ return value;
143
+ });
144
+ } catch {
145
+ return "{}";
146
+ }
147
+ }
148
+ var sharedEventStore = null;
149
+ function setSharedEventStore(store) {
150
+ sharedEventStore = store;
151
+ }
152
+ function getSharedEventStore() {
153
+ return sharedEventStore;
154
+ }
155
+ function resetSharedEventStore() {
156
+ sharedEventStore = null;
157
+ }
158
+
159
+ export { EventStoreImpl, setSharedEventStore, getSharedEventStore, resetSharedEventStore };
@@ -3,10 +3,10 @@ import {
3
3
  hasDecoratorNodes,
4
4
  init_node_registry_helper,
5
5
  registerDecoratorNodeType
6
- } from "./roy-agent-core-qz9jb9sp.js";
6
+ } from "./roy-agent-core-hkj5v9xq.js";
7
7
  import"./roy-agent-core-1ce3fqrk.js";
8
8
  import"./roy-agent-core-ddwa0n6h.js";
9
- import"./roy-agent-core-qhjm0bxm.js";
9
+ import"./roy-agent-core-a9pbda78.js";
10
10
  import"./roy-agent-core-8seq65bp.js";
11
11
  import"./roy-agent-core-jnszp0jq.js";
12
12
  import"./roy-agent-core-fs0mn2jk.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  init_global_hook_manager,
3
3
  init_hook_manager
4
- } from "./roy-agent-core-743510fc.js";
4
+ } from "./roy-agent-core-yjyvwxs4.js";
5
5
 
6
6
  // src/env/hook/types.ts
7
7
  function createHook(meta, fn) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-qhjm0bxm.js";
4
+ } from "./roy-agent-core-a9pbda78.js";
5
5
  import {
6
6
  __esm,
7
7
  __legacyDecorateClassTS
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  init_context
3
- } from "./roy-agent-core-1kcstbn3.js";
3
+ } from "./roy-agent-core-ff2ssff5.js";
4
4
  import {
5
5
  getEnvContext
6
- } from "./roy-agent-core-jxgprc5a.js";
6
+ } from "./roy-agent-core-z4486eek.js";
7
7
  import {
8
8
  __esm
9
9
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -12,11 +12,11 @@ import {
12
12
  } from "./roy-agent-core-7hh0brvs.js";
13
13
  import {
14
14
  BaseComponent
15
- } from "./roy-agent-core-62c1t7wr.js";
15
+ } from "./roy-agent-core-yv4anf1c.js";
16
16
  import {
17
17
  TracedAs,
18
18
  init_decorator
19
- } from "./roy-agent-core-qhjm0bxm.js";
19
+ } from "./roy-agent-core-a9pbda78.js";
20
20
  import {
21
21
  createLogger,
22
22
  init_logger
@@ -334,6 +334,103 @@ class SessionComponent extends BaseComponent {
334
334
  }
335
335
  return success ?? false;
336
336
  }
337
+ chatBindingCache = new Map;
338
+ static CHAT_BINDING_CACHE_TTL_MS = 60000;
339
+ static CHAT_BINDING_CACHE_MAX = 1000;
340
+ async upsertChatTaskBinding(opts) {
341
+ if (!opts.chatId || typeof opts.chatId !== "string") {
342
+ throw new Error("upsertChatTaskBinding: chatId is required (non-empty string)");
343
+ }
344
+ if (typeof opts.taskId !== "number" || !Number.isInteger(opts.taskId) || opts.taskId <= 0) {
345
+ throw new Error(`upsertChatTaskBinding: taskId must be a positive integer, got ${JSON.stringify(opts.taskId)}`);
346
+ }
347
+ const now = new Date().toISOString();
348
+ const desiredStatus = opts.status ?? "ready";
349
+ const existing = await this.getChatTaskBinding(opts.chatId);
350
+ let rebindCount = existing?.rebindCount ?? 0;
351
+ let resolvedTaskId = opts.taskId;
352
+ if (existing && existing.taskId !== opts.taskId) {
353
+ rebindCount += 1;
354
+ resolvedTaskId = existing.taskId;
355
+ logger.warn(`[SessionComponent] upsertChatTaskBinding: rebind detected for chatId=${opts.chatId}: ` + `existing taskId=${existing.taskId}, requested taskId=${opts.taskId}; ` + `keeping existing. rebindCount=${rebindCount}`);
356
+ }
357
+ const binding = {
358
+ chatId: opts.chatId,
359
+ taskId: resolvedTaskId,
360
+ profile: opts.profile,
361
+ boundAt: now,
362
+ status: desiredStatus,
363
+ errorMessage: opts.errorMessage ?? null,
364
+ rebindCount
365
+ };
366
+ const session = await this.get(opts.chatId);
367
+ if (session) {
368
+ const mergedMetadata = {
369
+ ...session.metadata ?? {},
370
+ larkChat: binding
371
+ };
372
+ await this.update(opts.chatId, { metadata: mergedMetadata });
373
+ } else {
374
+ const newMetadata = {
375
+ larkChat: binding
376
+ };
377
+ await this.create({
378
+ id: opts.chatId,
379
+ title: `lark-chat:${opts.chatId}`,
380
+ directory: ".",
381
+ metadata: newMetadata
382
+ });
383
+ }
384
+ this.chatBindingCache.set(opts.chatId, {
385
+ binding,
386
+ cachedAt: Date.now()
387
+ });
388
+ this.evictStaleChatBindingCache();
389
+ logger.info(`[SessionComponent] upsertChatTaskBinding: chatId=${opts.chatId} → taskId=${resolvedTaskId} ` + `status=${binding.status} rebindCount=${rebindCount}`);
390
+ return binding;
391
+ }
392
+ async getChatTaskBinding(chatId) {
393
+ if (!chatId)
394
+ return null;
395
+ const cached = this.chatBindingCache.get(chatId);
396
+ if (cached) {
397
+ const age = Date.now() - cached.cachedAt;
398
+ if (age < SessionComponent.CHAT_BINDING_CACHE_TTL_MS) {
399
+ return cached.binding;
400
+ }
401
+ this.chatBindingCache.delete(chatId);
402
+ }
403
+ const session = await this.get(chatId);
404
+ if (!session) {
405
+ return null;
406
+ }
407
+ const binding = session.metadata?.larkChat;
408
+ if (!binding || typeof binding !== "object") {
409
+ return null;
410
+ }
411
+ this.chatBindingCache.set(chatId, {
412
+ binding,
413
+ cachedAt: Date.now()
414
+ });
415
+ this.evictStaleChatBindingCache();
416
+ return binding;
417
+ }
418
+ evictStaleChatBindingCache() {
419
+ if (this.chatBindingCache.size <= SessionComponent.CHAT_BINDING_CACHE_MAX)
420
+ return;
421
+ const now = Date.now();
422
+ for (const [k, v] of this.chatBindingCache) {
423
+ if (now - v.cachedAt >= SessionComponent.CHAT_BINDING_CACHE_TTL_MS) {
424
+ this.chatBindingCache.delete(k);
425
+ }
426
+ }
427
+ while (this.chatBindingCache.size > SessionComponent.CHAT_BINDING_CACHE_MAX) {
428
+ const firstKey = this.chatBindingCache.keys().next().value;
429
+ if (!firstKey)
430
+ break;
431
+ this.chatBindingCache.delete(firstKey);
432
+ }
433
+ }
337
434
  getActiveSession() {
338
435
  if (!this.activeSessionId)
339
436
  return;
@@ -858,6 +955,20 @@ class SessionComponent extends BaseComponent {
858
955
  };
859
956
  }
860
957
  }
958
+ __legacyDecorateClassTS([
959
+ TracedAs("session.upsertChatTaskBinding", {
960
+ recordParams: false,
961
+ recordResult: false,
962
+ log: true
963
+ })
964
+ ], SessionComponent.prototype, "upsertChatTaskBinding", null);
965
+ __legacyDecorateClassTS([
966
+ TracedAs("session.getChatTaskBinding", {
967
+ recordParams: false,
968
+ recordResult: false,
969
+ log: false
970
+ })
971
+ ], SessionComponent.prototype, "getChatTaskBinding", null);
861
972
  __legacyDecorateClassTS([
862
973
  TracedAs("session.generateCompactHint")
863
974
  ], SessionComponent.prototype, "generateCompactHint", null);
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createHook
3
- } from "./roy-agent-core-n094tbjh.js";
3
+ } from "./roy-agent-core-y7atw1kw.js";
4
4
  import {
5
5
  HookManager
6
- } from "./roy-agent-core-743510fc.js";
6
+ } from "./roy-agent-core-yjyvwxs4.js";
7
7
 
8
8
  // src/env/component.ts
9
9
  class BaseComponent {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  init_decorator,
3
3
  wrapFunction
4
- } from "./roy-agent-core-qhjm0bxm.js";
4
+ } from "./roy-agent-core-a9pbda78.js";
5
5
  import {
6
6
  createLogger,
7
7
  init_logger
@@ -141,7 +141,8 @@ function createEnvContext(options) {
141
141
  replyChannel,
142
142
  pluginEnabled: options.pluginEnabled,
143
143
  plugins: options.plugins,
144
- timestamp: options.timestamp ?? Date.now()
144
+ timestamp: options.timestamp ?? Date.now(),
145
+ parentTaskId: options.parentTaskId
145
146
  };
146
147
  }
147
148
  function mergeEnvContext(partial) {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  TracedAs,
6
6
  init_decorator
7
- } from "./roy-agent-core-qhjm0bxm.js";
7
+ } from "./roy-agent-core-a9pbda78.js";
8
8
  import {
9
9
  createLogger,
10
10
  init_logger
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.7.36",
3
+ "version": "1.7.38",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",