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

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 (55) hide show
  1. package/dist/config/index.js +6 -6
  2. package/dist/env/agent/index.js +7 -7
  3. package/dist/env/commands/index.js +6 -6
  4. package/dist/env/context/index.js +2 -2
  5. package/dist/env/debug/index.js +6 -6
  6. package/dist/env/event-source/index.js +8 -8
  7. package/dist/env/hook/index.js +4 -4
  8. package/dist/env/index.js +21 -21
  9. package/dist/env/llm/index.js +6 -6
  10. package/dist/env/log-trace/index.js +6 -6
  11. package/dist/env/mcp/index.js +6 -6
  12. package/dist/env/memory/index.js +6 -6
  13. package/dist/env/plugin/index.js +6 -6
  14. package/dist/env/prompt/index.js +6 -6
  15. package/dist/env/session/index.js +6 -6
  16. package/dist/env/skill/index.js +6 -6
  17. package/dist/env/task/delegate/index.js +4 -4
  18. package/dist/env/task/index.js +8 -8
  19. package/dist/env/task/plugins/index.js +3 -3
  20. package/dist/env/task/tools/index.js +2 -2
  21. package/dist/env/tool/index.js +6 -6
  22. package/dist/env/workflow/engine/index.js +5 -5
  23. package/dist/env/workflow/index.js +10 -10
  24. package/dist/env/workflow/tools/index.js +7 -7
  25. package/dist/index.js +28 -28
  26. package/dist/shared/@ai-setting/{roy-agent-core-krmhhje6.js → roy-agent-core-1btakphh.js} +1 -1
  27. package/dist/shared/@ai-setting/{roy-agent-core-2aq5f4e1.js → roy-agent-core-1nvqn17p.js} +4 -4
  28. package/dist/shared/@ai-setting/{roy-agent-core-dz3m7dt4.js → roy-agent-core-1q6gjxba.js} +5 -5
  29. package/dist/shared/@ai-setting/{roy-agent-core-zma7p5p7.js → roy-agent-core-1vj7dd14.js} +1 -1
  30. package/dist/shared/@ai-setting/{roy-agent-core-z7q1re07.js → roy-agent-core-2qke91fm.js} +3 -3
  31. package/dist/shared/@ai-setting/{roy-agent-core-j6h99erf.js → roy-agent-core-2wbdfrtg.js} +1 -1
  32. package/dist/shared/@ai-setting/{roy-agent-core-t2vwy92b.js → roy-agent-core-462v5d24.js} +1 -1
  33. package/dist/shared/@ai-setting/{roy-agent-core-821bsh3r.js → roy-agent-core-88tfzaxg.js} +1 -1
  34. package/dist/shared/@ai-setting/{roy-agent-core-0czz1ynz.js → roy-agent-core-a8zf7ts4.js} +4 -4
  35. package/dist/shared/@ai-setting/{roy-agent-core-bny3nd8q.js → roy-agent-core-bb57xjfh.js} +5 -5
  36. package/dist/shared/@ai-setting/{roy-agent-core-1dacps3n.js → roy-agent-core-dfay0w56.js} +1 -1
  37. package/dist/shared/@ai-setting/{roy-agent-core-gcnvcbft.js → roy-agent-core-e4v61k3j.js} +24 -2
  38. package/dist/shared/@ai-setting/{roy-agent-core-tft0pa6h.js → roy-agent-core-em8618g6.js} +57 -8
  39. package/dist/shared/@ai-setting/{roy-agent-core-743510fc.js → roy-agent-core-fym6zz5a.js} +2 -2
  40. package/dist/shared/@ai-setting/{roy-agent-core-anwh7050.js → roy-agent-core-fytqnxrd.js} +2 -2
  41. package/dist/shared/@ai-setting/{roy-agent-core-62c1t7wr.js → roy-agent-core-m7dppx2p.js} +2 -2
  42. package/dist/shared/@ai-setting/{roy-agent-core-axh3vn8k.js → roy-agent-core-mdaew65f.js} +1 -1
  43. package/dist/shared/@ai-setting/{roy-agent-core-3x6ej9vm.js → roy-agent-core-mwaesrpc.js} +3 -3
  44. package/dist/shared/@ai-setting/{roy-agent-core-2adayzfa.js → roy-agent-core-mxwaq8ey.js} +4 -4
  45. package/dist/shared/@ai-setting/{roy-agent-core-jxgprc5a.js → roy-agent-core-n82acszf.js} +2 -1
  46. package/dist/shared/@ai-setting/{roy-agent-core-52yt7e1t.js → roy-agent-core-pxyyrxnn.js} +1 -1
  47. package/dist/shared/@ai-setting/{roy-agent-core-hs75rxp3.js → roy-agent-core-q8vew3zh.js} +1 -1
  48. package/dist/shared/@ai-setting/{roy-agent-core-zfcwa3w7.js → roy-agent-core-qhtejtpc.js} +27 -5
  49. package/dist/shared/@ai-setting/{roy-agent-core-6thjwx6v.js → roy-agent-core-rx8whb18.js} +112 -1
  50. package/dist/shared/@ai-setting/{roy-agent-core-xgarc0t2.js → roy-agent-core-s53yya0w.js} +4 -4
  51. package/dist/shared/@ai-setting/{roy-agent-core-n094tbjh.js → roy-agent-core-w457586k.js} +1 -1
  52. package/dist/shared/@ai-setting/{roy-agent-core-1kcstbn3.js → roy-agent-core-whta3f53.js} +1 -1
  53. package/dist/shared/@ai-setting/{roy-agent-core-63nkhqa4.js → roy-agent-core-x4wev4rn.js} +1 -1
  54. package/dist/shared/@ai-setting/{roy-agent-core-h1zamsb9.js → roy-agent-core-zekkw27m.js} +3 -3
  55. package/package.json +1 -1
@@ -2,7 +2,7 @@ import {
2
2
  TaskTagPlugin,
3
3
  createLarkCliTaskNotifyHook,
4
4
  createPerTaskGroupChatPlugin
5
- } from "./roy-agent-core-gcnvcbft.js";
5
+ } from "./roy-agent-core-e4v61k3j.js";
6
6
  import {
7
7
  normalizeLarkAtMentions
8
8
  } from "./roy-agent-core-rmn29nrh.js";
@@ -11,18 +11,18 @@ 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-m7dppx2p.js";
15
15
  import {
16
16
  globalHookManager,
17
17
  init_global_hook_manager
18
- } from "./roy-agent-core-743510fc.js";
18
+ } from "./roy-agent-core-fym6zz5a.js";
19
19
  import {
20
20
  init_context
21
- } from "./roy-agent-core-1kcstbn3.js";
21
+ } from "./roy-agent-core-whta3f53.js";
22
22
  import {
23
23
  createEnvContext,
24
24
  runWithEnvContext
25
- } from "./roy-agent-core-jxgprc5a.js";
25
+ } from "./roy-agent-core-n82acszf.js";
26
26
  import {
27
27
  TracedAs,
28
28
  init_decorator
@@ -832,6 +832,9 @@ var bountyCliHandler = {
832
832
  // src/env/event-source/event-source-handlers.ts
833
833
  init_logger();
834
834
  var logger = createLogger("lark-cli:event-source");
835
+ function isPluginDebugEnabled() {
836
+ return process.env.ROY_TASK_NOTIFY_DEBUG === "1" || process.env.ROY_TRACE_DEBUG === "1";
837
+ }
835
838
  var BUILT_IN_PLUGIN_FACTORIES = {
836
839
  LarkCliTaskNotifyPlugin: (cfg) => createLarkCliTaskNotifyHook(cfg),
837
840
  PerTaskGroupChatPlugin: (cfg) => createPerTaskGroupChatPlugin(cfg),
@@ -1148,6 +1151,7 @@ class LarkCliInstance {
1148
1151
  registerPluginHooks(plugin) {
1149
1152
  const pluginName = plugin.name || "unknown";
1150
1153
  this.injectTaskUpdater(plugin);
1154
+ this.injectSessionComponent(plugin);
1151
1155
  if (typeof plugin.init === "function") {
1152
1156
  const pluginEnv = {
1153
1157
  getComponent: () => null,
@@ -1233,6 +1237,48 @@ class LarkCliInstance {
1233
1237
  };
1234
1238
  plugin.setTaskUpdater(taskUpdater);
1235
1239
  }
1240
+ injectSessionComponent(plugin) {
1241
+ if (typeof plugin.setSessionComponent !== "function") {
1242
+ return;
1243
+ }
1244
+ if (typeof plugin.hasSessionComponent === "function" && plugin.hasSessionComponent()) {
1245
+ return;
1246
+ }
1247
+ if (!this.environment?.getComponent) {
1248
+ if (isPluginDebugEnabled()) {
1249
+ console.debug(`[LarkCliInstance] ${plugin.name || "plugin"} has setSessionComponent but ` + `environment not injected (setEnvironment not called). ` + `chat↔task 绑定将不会写入。`);
1250
+ }
1251
+ return;
1252
+ }
1253
+ const sessionComponent = this.environment.getComponent("session");
1254
+ if (!sessionComponent?.upsertChatTaskBinding) {
1255
+ if (isPluginDebugEnabled()) {
1256
+ console.debug(`[LarkCliInstance] ${plugin.name || "plugin"} has setSessionComponent but ` + `sessionComponent or upsertChatTaskBinding not found via env.getComponent('session'). ` + `chat↔task 绑定将不会写入。`);
1257
+ }
1258
+ return;
1259
+ }
1260
+ plugin.setSessionComponent(sessionComponent);
1261
+ if (isPluginDebugEnabled()) {
1262
+ console.debug(`[LarkCliInstance] SessionComponent injected for plugin ${plugin.name || "unknown"} ` + `(sourceId=${this.config.id})`);
1263
+ }
1264
+ }
1265
+ async resolveChatTaskBinding(chatId) {
1266
+ if (!chatId)
1267
+ return null;
1268
+ const sessionComponent = this.environment?.getComponent?.("session");
1269
+ if (!sessionComponent?.getChatTaskBinding)
1270
+ return null;
1271
+ try {
1272
+ const binding = await sessionComponent.getChatTaskBinding(chatId);
1273
+ if (binding && binding.status === "ready" && typeof binding.taskId === "number" && binding.taskId > 0) {
1274
+ return binding.taskId;
1275
+ }
1276
+ return null;
1277
+ } catch (err) {
1278
+ logger.warn(`[LarkCliInstance] resolveChatTaskBinding failed for chatId=${chatId}: ${err}. ` + `群消息将不会注入 parentTaskId。`);
1279
+ return null;
1280
+ }
1281
+ }
1236
1282
  unloadPlugins() {
1237
1283
  for (const plugin of this.loadedPlugins) {
1238
1284
  for (const hook of plugin.hooks) {
@@ -1252,7 +1298,7 @@ class LarkCliInstance {
1252
1298
  }
1253
1299
  }
1254
1300
  }
1255
- handleEvent(rawData) {
1301
+ async handleEvent(rawData) {
1256
1302
  let dedupKey;
1257
1303
  try {
1258
1304
  const parsed = JSON.parse(rawData);
@@ -1319,6 +1365,7 @@ class LarkCliInstance {
1319
1365
  eventSourceId: this.config.id
1320
1366
  };
1321
1367
  const { metadata, replyChannel, recommendedAction } = extractMetadata(enrichedEvent, eventType);
1368
+ const parentTaskId = await this.resolveChatTaskBinding(metadata?.chatId);
1322
1369
  const message = JSON.stringify({
1323
1370
  rawData,
1324
1371
  recommendedAction
@@ -1341,7 +1388,8 @@ class LarkCliInstance {
1341
1388
  plugins,
1342
1389
  pluginEnabled,
1343
1390
  replyChannel,
1344
- agent
1391
+ agent,
1392
+ parentTaskId: parentTaskId ?? undefined
1345
1393
  },
1346
1394
  payload: {
1347
1395
  sourceId: this.config.id,
@@ -1351,7 +1399,8 @@ class LarkCliInstance {
1351
1399
  metadata,
1352
1400
  replyChannel,
1353
1401
  recommendedAction,
1354
- timestamp
1402
+ timestamp,
1403
+ parentTaskId: parentTaskId ?? undefined
1355
1404
  }
1356
1405
  };
1357
1406
  const userId = this.extractUserId(rawEvent);
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  init_context
3
- } from "./roy-agent-core-1kcstbn3.js";
3
+ } from "./roy-agent-core-whta3f53.js";
4
4
  import {
5
5
  getEnvContext
6
- } from "./roy-agent-core-jxgprc5a.js";
6
+ } from "./roy-agent-core-n82acszf.js";
7
7
  import {
8
8
  __esm
9
9
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -19,12 +19,12 @@ import {
19
19
  } from "./roy-agent-core-7hh0brvs.js";
20
20
  import {
21
21
  BaseComponent
22
- } from "./roy-agent-core-62c1t7wr.js";
22
+ } from "./roy-agent-core-m7dppx2p.js";
23
23
  import {
24
24
  LLMHookPoints,
25
25
  globalHookManager,
26
26
  init_global_hook_manager
27
- } from "./roy-agent-core-743510fc.js";
27
+ } from "./roy-agent-core-fym6zz5a.js";
28
28
  import {
29
29
  TracedAs,
30
30
  init_decorator,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createHook
3
- } from "./roy-agent-core-n094tbjh.js";
3
+ } from "./roy-agent-core-w457586k.js";
4
4
  import {
5
5
  HookManager
6
- } from "./roy-agent-core-743510fc.js";
6
+ } from "./roy-agent-core-fym6zz5a.js";
7
7
 
8
8
  // src/env/component.ts
9
9
  class BaseComponent {
@@ -6,7 +6,7 @@ import {
6
6
  } from "./roy-agent-core-7hh0brvs.js";
7
7
  import {
8
8
  BaseComponent
9
- } from "./roy-agent-core-62c1t7wr.js";
9
+ } from "./roy-agent-core-m7dppx2p.js";
10
10
  import {
11
11
  createLogger,
12
12
  init_logger
@@ -11,16 +11,16 @@ 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-m7dppx2p.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-fym6zz5a.js";
20
20
  import {
21
21
  getCurrentTaskId,
22
22
  init_env_context
23
- } from "./roy-agent-core-jxgprc5a.js";
23
+ } from "./roy-agent-core-n82acszf.js";
24
24
  import {
25
25
  TracedAs,
26
26
  init_decorator
@@ -13,7 +13,7 @@ import {
13
13
  createWorkflowSearchTool,
14
14
  createWorkflowTagListTool,
15
15
  createWorkflowValidateTool
16
- } from "./roy-agent-core-52yt7e1t.js";
16
+ } from "./roy-agent-core-pxyyrxnn.js";
17
17
  import {
18
18
  WorkflowService
19
19
  } from "./roy-agent-core-j9ejsmsj.js";
@@ -21,10 +21,10 @@ import {
21
21
  WorkflowEngine,
22
22
  exports_engine,
23
23
  init_engine
24
- } from "./roy-agent-core-63nkhqa4.js";
24
+ } from "./roy-agent-core-x4wev4rn.js";
25
25
  import {
26
26
  BaseComponent
27
- } from "./roy-agent-core-62c1t7wr.js";
27
+ } from "./roy-agent-core-m7dppx2p.js";
28
28
  import {
29
29
  createLogger,
30
30
  init_logger
@@ -141,7 +141,7 @@ class WorkflowComponent extends BaseComponent {
141
141
  if (!agentRunner && this._workflowEnv) {
142
142
  const agentComponent = this._workflowEnv.getComponent("agent");
143
143
  if (agentComponent) {
144
- const { AgentComponentAdapter } = await import("./roy-agent-core-xgarc0t2.js");
144
+ const { AgentComponentAdapter } = await import("./roy-agent-core-s53yya0w.js");
145
145
  agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent);
146
146
  }
147
147
  }
@@ -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) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isValidSessionId
3
- } from "./roy-agent-core-6thjwx6v.js";
3
+ } from "./roy-agent-core-rx8whb18.js";
4
4
  import {
5
5
  TAG_MAX_COUNT,
6
6
  TAG_MIN_COUNT
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  globalHookManager,
11
11
  init_global_hook_manager
12
- } from "./roy-agent-core-743510fc.js";
12
+ } from "./roy-agent-core-fym6zz5a.js";
13
13
  import {
14
14
  TracedAs,
15
15
  init_decorator,
@@ -1,7 +1,8 @@
1
1
  import {
2
+ getEnvContextOrEmpty,
2
3
  init_env_context,
3
4
  setCurrentTaskId
4
- } from "./roy-agent-core-jxgprc5a.js";
5
+ } from "./roy-agent-core-n82acszf.js";
5
6
  import {
6
7
  createLogger,
7
8
  init_logger
@@ -333,6 +334,25 @@ function createTaskTool(taskComponent) {
333
334
  rather than rejected, to preserve backward compatibility. The
334
335
  auto-injection of \`created_at\` / \`worktree_path\` is best-effort.
335
336
 
337
+ ## Task Binding Inheritance (Task #4023)
338
+
339
+ When this tool is called from inside a per-task group chat, the
340
+ event-source handler resolves the chat↔task binding and injects the
341
+ bound task id into \`EnvContext.parentTaskId\`. This tool reads that
342
+ value and uses it as the default \`parent_task_id\`, so the LLM
343
+ doesn't need to know the task tree to attach subtasks to the
344
+ correct parent.
345
+
346
+ Priority order (highest → lowest):
347
+ 1. Caller's explicit \`parent_task_id\` (always wins)
348
+ 2. \`EnvContext.parentTaskId\` injected from chat binding
349
+ 3. No parent (creates a root task, as before)
350
+
351
+ When the env-injected parent doesn't exist in the DB, the tool
352
+ fails fast (does not silently create an orphan). When the
353
+ env-injected value is 0 / negative / non-integer, it's treated as
354
+ missing — only positive integers are honored.
355
+
336
356
  `,
337
357
  parameters: CreateTaskToolSchema,
338
358
  execute: async (args, ctx) => {
@@ -340,12 +360,14 @@ function createTaskTool(taskComponent) {
340
360
  const sessionId = ctx.session_id || "unknown";
341
361
  const detectedWorktree = detectWorktree();
342
362
  let enrichedContext = params.context;
363
+ const envParentTaskId = getEnvContextOrEmpty().parentTaskId;
364
+ const effectiveParentTaskId = params.parent_task_id !== undefined && params.parent_task_id !== null ? params.parent_task_id : envParentTaskId !== undefined && envParentTaskId !== null && Number.isInteger(envParentTaskId) && envParentTaskId > 0 ? envParentTaskId : undefined;
343
365
  let inheritedProjectPath = params.project_path && params.project_path.trim() !== "" ? params.project_path : undefined;
344
366
  let inheritedTags = params.tags;
345
367
  let inheritedContext;
346
- if (params.parent_task_id !== undefined && params.parent_task_id !== null) {
368
+ if (effectiveParentTaskId !== undefined) {
347
369
  try {
348
- const parent = await taskComponent.getTask(params.parent_task_id);
370
+ const parent = await taskComponent.getTask(effectiveParentTaskId);
349
371
  if (parent) {
350
372
  const inherited = inheritChildContext({
351
373
  parent: {
@@ -370,7 +392,7 @@ function createTaskTool(taskComponent) {
370
392
  inheritedContext = inherited.context;
371
393
  }
372
394
  } catch (err) {
373
- logger2.debug(`[task_create] failed to pre-load parent #${params.parent_task_id} for context inheritance: ${err instanceof Error ? err.message : String(err)}`);
395
+ logger2.debug(`[task_create] failed to pre-load parent #${effectiveParentTaskId} for context inheritance: ${err instanceof Error ? err.message : String(err)}`);
374
396
  }
375
397
  }
376
398
  try {
@@ -399,7 +421,7 @@ function createTaskTool(taskComponent) {
399
421
  }
400
422
  try {
401
423
  const task = await taskComponent.createTask({
402
- parent_task_id: params.parent_task_id,
424
+ parent_task_id: effectiveParentTaskId,
403
425
  title: params.title,
404
426
  description: params.description,
405
427
  priority: params.priority,
@@ -12,7 +12,7 @@ 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-m7dppx2p.js";
16
16
  import {
17
17
  TracedAs,
18
18
  init_decorator
@@ -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,12 +1,12 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-hs75rxp3.js";
4
+ } from "./roy-agent-core-q8vew3zh.js";
5
5
  import"./roy-agent-core-1db4vpc6.js";
6
6
  import"./roy-agent-core-e25xkv53.js";
7
- import"./roy-agent-core-743510fc.js";
8
- import"./roy-agent-core-1kcstbn3.js";
9
- import"./roy-agent-core-jxgprc5a.js";
7
+ import"./roy-agent-core-fym6zz5a.js";
8
+ import"./roy-agent-core-whta3f53.js";
9
+ import"./roy-agent-core-n82acszf.js";
10
10
  import"./roy-agent-core-qhjm0bxm.js";
11
11
  import"./roy-agent-core-8seq65bp.js";
12
12
  import"./roy-agent-core-jnszp0jq.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-fym6zz5a.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
  init_env_context,
3
3
  init_env_event
4
- } from "./roy-agent-core-jxgprc5a.js";
4
+ } from "./roy-agent-core-n82acszf.js";
5
5
  import {
6
6
  __esm
7
7
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  AgentComponentAdapter,
9
9
  init_agent_component_adapter
10
- } from "./roy-agent-core-hs75rxp3.js";
10
+ } from "./roy-agent-core-q8vew3zh.js";
11
11
  import {
12
12
  PythonCallNode,
13
13
  SkillNode,
@@ -17,14 +17,14 @@ import {
17
17
  import {
18
18
  globalHookManager,
19
19
  init_global_hook_manager
20
- } from "./roy-agent-core-743510fc.js";
20
+ } from "./roy-agent-core-fym6zz5a.js";
21
21
  import {
22
22
  init_context
23
- } from "./roy-agent-core-1kcstbn3.js";
23
+ } from "./roy-agent-core-whta3f53.js";
24
24
  import {
25
25
  getCurrentTaskId,
26
26
  getEnvContext
27
- } from "./roy-agent-core-jxgprc5a.js";
27
+ } from "./roy-agent-core-n82acszf.js";
28
28
  import {
29
29
  TracedAs,
30
30
  init_decorator,
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.37",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",