@ai-setting/roy-agent-core 1.7.77 → 1.7.88
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.
- package/dist/config/config-protection.d.ts +89 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +23 -7
- package/dist/env/agent/agent-component.d.ts +43 -22
- package/dist/env/agent/agent-component.js +13 -12
- package/dist/env/agent/index.js +13 -12
- package/dist/env/agent/types.d.ts +46 -12
- package/dist/env/commands/index.js +7 -7
- package/dist/env/context/index.js +3 -3
- package/dist/env/debug/index.js +7 -7
- package/dist/env/error-reply.d.ts +6 -0
- package/dist/env/error-reply.js +1 -1
- package/dist/env/event-source/bounty-im-handler.d.ts +8 -0
- package/dist/env/event-source/es-command.d.ts +39 -0
- package/dist/env/event-source/es-plugins.d.ts +68 -0
- package/dist/env/event-source/event-source-component.d.ts +15 -0
- package/dist/env/event-source/event-source-handlers.d.ts +84 -0
- package/dist/env/event-source/event-source-handlers.js +40 -23
- package/dist/env/event-source/event-store.js +2 -2
- package/dist/env/event-source/index.d.ts +5 -1
- package/dist/env/event-source/index.js +75 -23
- package/dist/env/event-source/timer-handler.d.ts +98 -0
- package/dist/env/event-source/types.d.ts +154 -2
- package/dist/env/event-source/wecom-card-action-handler.d.ts +373 -0
- package/dist/env/event-source/wecom-card-builder.d.ts +426 -0
- package/dist/env/event-source/wecom-cli-handler.d.ts +291 -0
- package/dist/env/event-source/wecom-cli-sender.d.ts +88 -0
- package/dist/env/event-source/wecom-media.d.ts +130 -0
- package/dist/env/event-source/wecom-respond-registry.d.ts +151 -0
- package/dist/env/event-source/wecom-respond-registry.js +33 -0
- package/dist/env/event-source/wecom-session-card-sender.d.ts +135 -0
- package/dist/env/event-source/wecom-session-card-sender.js +153 -0
- package/dist/env/event-source/wecom-ws-bridge.d.ts +213 -0
- package/dist/env/hook/index.js +5 -5
- package/dist/env/index.js +51 -45
- package/dist/env/llm/index.js +9 -8
- package/dist/env/log-trace/index.js +7 -7
- package/dist/env/log-trace/trace-filters.d.ts +6 -1
- package/dist/env/mcp/index.js +7 -7
- package/dist/env/memory/index.js +7 -7
- package/dist/env/plugin/index.js +7 -7
- package/dist/env/prompt/index.js +8 -8
- package/dist/env/prompt/prompts-index.d.ts +1 -1
- package/dist/env/session/group-session-link.d.ts +99 -0
- package/dist/env/session/index.js +11 -10
- package/dist/env/session/session-component.d.ts +89 -0
- package/dist/env/session/storage/index.js +5 -4
- package/dist/env/session/types.d.ts +10 -0
- package/dist/env/skill/index.js +7 -7
- package/dist/env/task/delegate/delegate-channel-hint.d.ts +39 -0
- package/dist/env/task/delegate/delegate-tool.d.ts +132 -7
- package/dist/env/task/delegate/delegate-tool.js +13 -9
- package/dist/env/task/delegate/index.js +8 -8
- package/dist/env/task/index.js +18 -18
- package/dist/env/task/mcp/index.js +4 -4
- package/dist/env/task/plugins/card-subject.d.ts +117 -0
- package/dist/env/task/plugins/index.d.ts +2 -0
- package/dist/env/task/plugins/index.js +39 -16
- package/dist/env/task/plugins/lark-card-action-handler.d.ts +261 -6
- package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +542 -2
- package/dist/env/task/plugins/lark-card-patch-notifier.js +12 -2
- package/dist/env/task/plugins/lark-card-state-store.d.ts +60 -0
- package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +61 -0
- package/dist/env/task/plugins/sub-session-activity.d.ts +415 -0
- package/dist/env/task/plugins/wecom-card-state-store.d.ts +121 -0
- package/dist/env/task/plugins/wecom-session-card-store.d.ts +134 -0
- package/dist/env/task/plugins/wecom-session-card-store.js +23 -0
- package/dist/env/task/plugins/wecom-task-notify-plugin.d.ts +264 -0
- package/dist/env/task/storage/index.js +3 -3
- package/dist/env/task/tools/index.js +4 -4
- package/dist/env/tool/built-in/index.d.ts +2 -0
- package/dist/env/tool/built-in/index.js +9 -2
- package/dist/env/tool/index.js +14 -9
- package/dist/env/tool/types.d.ts +25 -0
- package/dist/env/tool/validator.d.ts +8 -0
- package/dist/env/workflow/engine/index.js +12 -12
- package/dist/env/workflow/hooks/index.js +7 -7
- package/dist/env/workflow/index.js +24 -23
- package/dist/env/workflow/nodes/index.js +2 -2
- package/dist/env/workflow/plugins/index.js +10 -8
- package/dist/env/workflow/service/index.js +2 -2
- package/dist/env/workflow/storage/index.js +3 -3
- package/dist/env/workflow/tools/index.js +16 -15
- package/dist/env/workflow/utils/index.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +118 -62
- package/dist/shared/@ai-setting/{roy-agent-core-dc9zq75z.js → roy-agent-core-0crmsc12.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-aa2j7bk9.js → roy-agent-core-0sbmdz8d.js} +171 -36
- package/dist/shared/@ai-setting/{roy-agent-core-87942bw4.js → roy-agent-core-1mhyh4c5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-v6vr6za7.js → roy-agent-core-1vv4fx15.js} +4 -4
- package/dist/shared/@ai-setting/roy-agent-core-2stt4rp5.js +134 -0
- package/dist/shared/@ai-setting/{roy-agent-core-nwbfepba.js → roy-agent-core-3e040tc5.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-418zc9ha.js +288 -0
- package/dist/shared/@ai-setting/{roy-agent-core-r5wt1h3c.js → roy-agent-core-4fkxy2gv.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-na18zwj0.js → roy-agent-core-4t3yskp8.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-5pr4zp88.js → roy-agent-core-5kzhaap1.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qq96p0tj.js → roy-agent-core-5s2t8z00.js} +22 -1
- package/dist/shared/@ai-setting/{roy-agent-core-6rh8k6ba.js → roy-agent-core-6gj1hc5z.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-ezvpreqz.js → roy-agent-core-6k8mb7zx.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-g8htfwxj.js → roy-agent-core-7f10p7m2.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-7kvpc0w5.js +177 -0
- package/dist/shared/@ai-setting/{roy-agent-core-h21gngxf.js → roy-agent-core-7yh5wps0.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-efkjyh69.js → roy-agent-core-9710zwwz.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-6cy43nss.js → roy-agent-core-9c565frx.js} +49 -9
- package/dist/shared/@ai-setting/{roy-agent-core-fghc2m8z.js → roy-agent-core-aa8kv18f.js} +34 -2
- package/dist/shared/@ai-setting/{roy-agent-core-ew6qb5yx.js → roy-agent-core-an35dzbf.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-mww0mnd9.js → roy-agent-core-azyz78ky.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-264qexac.js → roy-agent-core-b7h39vrc.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-dqxec05w.js → roy-agent-core-bjtc9d35.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-c4ec7k0p.js +426 -0
- package/dist/shared/@ai-setting/{roy-agent-core-ddyk1rc0.js → roy-agent-core-cre2y2ct.js} +160 -4
- package/dist/shared/@ai-setting/{roy-agent-core-tr3ep81v.js → roy-agent-core-d6zdbgtc.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-0qyrk5k0.js → roy-agent-core-ds6qzmf8.js} +14 -5
- package/dist/shared/@ai-setting/{roy-agent-core-cgtq6427.js → roy-agent-core-e08bvpaq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-12n08pg5.js → roy-agent-core-e69qxdyy.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rhtdspx6.js → roy-agent-core-fan8g0z1.js} +10 -10
- package/dist/shared/@ai-setting/{roy-agent-core-xcp8vwax.js → roy-agent-core-fepm835e.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-6j02sbee.js → roy-agent-core-fhg03v43.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-99nwgj84.js → roy-agent-core-fzw9xzm1.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-dvtg4sn0.js → roy-agent-core-g8yr733d.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-3gpygqcx.js → roy-agent-core-gr5h1dyr.js} +2753 -358
- package/dist/shared/@ai-setting/roy-agent-core-h1e1fm9b.js +380 -0
- package/dist/shared/@ai-setting/{roy-agent-core-c2gbt68e.js → roy-agent-core-h83zdsrq.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-8ez6mccb.js → roy-agent-core-k3gcvybs.js} +5 -1
- package/dist/shared/@ai-setting/{roy-agent-core-pgvcf91v.js → roy-agent-core-m39v7qpx.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-tm1mxttk.js → roy-agent-core-mf5p38yf.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-83bewqx8.js → roy-agent-core-mvh0td7p.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-v85n42ve.js → roy-agent-core-mx855td4.js} +17 -38
- package/dist/shared/@ai-setting/{roy-agent-core-v87njmq7.js → roy-agent-core-n197medr.js} +13 -13
- package/dist/shared/@ai-setting/{roy-agent-core-cmprygrp.js → roy-agent-core-nqkfkpf4.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-7cbpmk4q.js → roy-agent-core-p31ftgq9.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-vffccgf6.js → roy-agent-core-qwd2dq5q.js} +10 -3
- package/dist/shared/@ai-setting/{roy-agent-core-rsn44n9y.js → roy-agent-core-ra66sf50.js} +2526 -942
- package/dist/shared/@ai-setting/{roy-agent-core-1v4g0d4x.js → roy-agent-core-rm7seqwb.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-w0qjeq2v.js → roy-agent-core-shb1qsyg.js} +1041 -18
- package/dist/shared/@ai-setting/{roy-agent-core-ax9e9szb.js → roy-agent-core-smf94h73.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-acj8ag08.js → roy-agent-core-tjnabyvq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qqaak24r.js → roy-agent-core-tkpp1ba0.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9vhq7fvv.js → roy-agent-core-tpm1dd1g.js} +34 -88
- package/dist/shared/@ai-setting/{roy-agent-core-ed233k5z.js → roy-agent-core-v1n0106v.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-zxz5fkwj.js → roy-agent-core-v6yshv0z.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-mcy5apay.js → roy-agent-core-vf9sp6s3.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-q813vafd.js → roy-agent-core-vpcxv1ty.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-bxkjk7zx.js → roy-agent-core-vx8zc847.js} +4 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xvt7kf7p.js → roy-agent-core-w9ryeg2p.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-es203w7p.js → roy-agent-core-wqs6yypq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-hd3n57zs.js → roy-agent-core-wr1qexzq.js} +5 -5
- package/dist/shared/@ai-setting/roy-agent-core-wxrkcb17.js +56 -0
- package/dist/shared/@ai-setting/{roy-agent-core-0snm5hc5.js → roy-agent-core-y6shd91r.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9vxh6f8h.js → roy-agent-core-y7fqtzk2.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-cpcd24n2.js → roy-agent-core-yet36q5k.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-3fh1f7s7.js → roy-agent-core-yfpnkc4z.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-0v27y99n.js → roy-agent-core-yh68z1bg.js} +65 -4
- package/package.json +18 -1
- /package/dist/shared/@ai-setting/{roy-agent-core-b4x6x4k2.js → roy-agent-core-m1fgtnrc.js} +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isToolUnavailableError,
|
|
3
3
|
truncateOutputInline
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-mx855td4.js";
|
|
5
5
|
import {
|
|
6
6
|
AgentRegistry
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-v1n0106v.js";
|
|
8
8
|
import {
|
|
9
9
|
createTaskOpWatermarkPlugin,
|
|
10
10
|
enqueueToAddFakeUserMessage
|
|
11
|
-
} from "./roy-agent-core-
|
|
11
|
+
} from "./roy-agent-core-7yh5wps0.js";
|
|
12
12
|
import {
|
|
13
13
|
SessionMessageConverter
|
|
14
|
-
} from "./roy-agent-core-
|
|
14
|
+
} from "./roy-agent-core-y6shd91r.js";
|
|
15
15
|
import {
|
|
16
16
|
parseToolArgsStrict,
|
|
17
17
|
safeParseToolArgs,
|
|
18
18
|
withTimeout
|
|
19
|
-
} from "./roy-agent-core-
|
|
19
|
+
} from "./roy-agent-core-aa8kv18f.js";
|
|
20
20
|
import {
|
|
21
21
|
getCurrentBgTaskId
|
|
22
22
|
} from "./roy-agent-core-c1v263jn.js";
|
|
@@ -32,20 +32,20 @@ import {
|
|
|
32
32
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
33
33
|
import {
|
|
34
34
|
BaseComponent
|
|
35
|
-
} from "./roy-agent-core-
|
|
35
|
+
} from "./roy-agent-core-m39v7qpx.js";
|
|
36
36
|
import {
|
|
37
37
|
globalHookManager,
|
|
38
38
|
init_global_hook_manager
|
|
39
|
-
} from "./roy-agent-core-
|
|
39
|
+
} from "./roy-agent-core-yet36q5k.js";
|
|
40
40
|
import {
|
|
41
41
|
init_context
|
|
42
|
-
} from "./roy-agent-core-
|
|
42
|
+
} from "./roy-agent-core-tkpp1ba0.js";
|
|
43
43
|
import {
|
|
44
44
|
getCurrentTaskId,
|
|
45
45
|
getEnvContext,
|
|
46
46
|
resolveEnvParentTaskId,
|
|
47
47
|
runWithEnvContextAsync
|
|
48
|
-
} from "./roy-agent-core-
|
|
48
|
+
} from "./roy-agent-core-p31ftgq9.js";
|
|
49
49
|
import {
|
|
50
50
|
TracedAs,
|
|
51
51
|
agentRunParamFilter,
|
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
recordSessionMessagesParamFilter,
|
|
58
58
|
toolExecParamFilter,
|
|
59
59
|
toolExecResultFilter
|
|
60
|
-
} from "./roy-agent-core-
|
|
60
|
+
} from "./roy-agent-core-5s2t8z00.js";
|
|
61
61
|
import {
|
|
62
62
|
createLogger,
|
|
63
63
|
init_logger
|
|
@@ -69,8 +69,6 @@ import {
|
|
|
69
69
|
|
|
70
70
|
// src/env/agent/agent-component.ts
|
|
71
71
|
init_logger();
|
|
72
|
-
import fs from "fs/promises";
|
|
73
|
-
import path from "path";
|
|
74
72
|
import { z } from "zod";
|
|
75
73
|
|
|
76
74
|
// src/env/task/plugins/max-iteration-reminder-plugin.ts
|
|
@@ -556,10 +554,16 @@ var AgentInstanceSchema = z.object({
|
|
|
556
554
|
var AgentComponentConfigSchema = z.object({
|
|
557
555
|
defaultAgent: AgentInstanceSchema
|
|
558
556
|
});
|
|
559
|
-
function filterToolsByAgent(tools, agent) {
|
|
557
|
+
function filterToolsByAgent(tools, agent, extendTools) {
|
|
560
558
|
if (!tools?.length)
|
|
561
559
|
return tools ?? [];
|
|
562
560
|
return tools.filter((t) => {
|
|
561
|
+
if (t.metadata?.channelOnly === true) {
|
|
562
|
+
if (!extendTools || extendTools.length === 0)
|
|
563
|
+
return false;
|
|
564
|
+
if (!extendTools.includes(t.name))
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
563
567
|
const allowedList = t.metadata?.allowedAgentTypes;
|
|
564
568
|
if (!allowedList || allowedList.length === 0)
|
|
565
569
|
return true;
|
|
@@ -601,6 +605,7 @@ class AgentComponent extends BaseComponent {
|
|
|
601
605
|
abortControllers = new Map;
|
|
602
606
|
defaultTools = [];
|
|
603
607
|
doomLoopCaches = new Map;
|
|
608
|
+
_cacheSnapshots = new Map;
|
|
604
609
|
fallbackState = new Map;
|
|
605
610
|
configComponent;
|
|
606
611
|
skipAbortRunningTasksOnStop = false;
|
|
@@ -958,7 +963,8 @@ class AgentComponent extends BaseComponent {
|
|
|
958
963
|
this.defaultTools = tools;
|
|
959
964
|
}
|
|
960
965
|
getAvailableTools(agent, context) {
|
|
961
|
-
|
|
966
|
+
const extendTools = context?.extendTools;
|
|
967
|
+
let tools = filterToolsByAgent([...this.defaultTools], agent, extendTools);
|
|
962
968
|
logger2.debug(`[getAvailableTools] After defaultTools (filtered): ${tools.length} tools`, {
|
|
963
969
|
toolNames: tools.map((t) => t.name)
|
|
964
970
|
});
|
|
@@ -966,7 +972,7 @@ class AgentComponent extends BaseComponent {
|
|
|
966
972
|
const componentTools = this.toolComponent.listTools({
|
|
967
973
|
allowedAgent: agent.name
|
|
968
974
|
});
|
|
969
|
-
const filteredComponentTools = filterToolsByAgent(componentTools, agent);
|
|
975
|
+
const filteredComponentTools = filterToolsByAgent(componentTools, agent, extendTools);
|
|
970
976
|
tools = [...tools, ...filteredComponentTools];
|
|
971
977
|
logger2.debug(`[getAvailableTools] After adding componentTools: ${tools.length} tools`, {
|
|
972
978
|
componentToolNames: filteredComponentTools.map((t) => t.name)
|
|
@@ -988,7 +994,7 @@ class AgentComponent extends BaseComponent {
|
|
|
988
994
|
});
|
|
989
995
|
}
|
|
990
996
|
if (context?.extraTools?.length) {
|
|
991
|
-
const filteredExtraTools = filterToolsByAgent(context.extraTools, agent);
|
|
997
|
+
const filteredExtraTools = filterToolsByAgent(context.extraTools, agent, extendTools);
|
|
992
998
|
tools = [...tools, ...filteredExtraTools];
|
|
993
999
|
logger2.debug(`[getAvailableTools] After extraTools (filtered): ${tools.length} tools`, {
|
|
994
1000
|
extraToolNames: filteredExtraTools.map((t) => t.name)
|
|
@@ -1613,25 +1619,14 @@ class AgentComponent extends BaseComponent {
|
|
|
1613
1619
|
return { snapshot: null, systemPromptOverride: undefined };
|
|
1614
1620
|
}
|
|
1615
1621
|
try {
|
|
1616
|
-
const
|
|
1617
|
-
if (
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
const stale = await this._isMemorySnapshotStale(existingSnapshot);
|
|
1624
|
-
if (stale) {
|
|
1625
|
-
logger2.info(`[AgentComponent._run] cacheSnapshot for session ${sessionId} is stale (${stale}); recreating`);
|
|
1626
|
-
} else {
|
|
1627
|
-
logger2.debug(`[AgentComponent._run] Reusing cacheSnapshot for session ${sessionId} (snapshotAt=${existingSnapshot.snapshotAt})`);
|
|
1628
|
-
return {
|
|
1629
|
-
snapshot: existingSnapshot,
|
|
1630
|
-
systemPromptOverride: existingSnapshot.systemPrompt
|
|
1631
|
-
};
|
|
1632
|
-
}
|
|
1622
|
+
const existingSnapshot = this._cacheSnapshots.get(sessionId);
|
|
1623
|
+
if (existingSnapshot) {
|
|
1624
|
+
logger2.debug(`[AgentComponent._run] Reusing cacheSnapshot for session ${sessionId} (snapshotAt=${existingSnapshot.snapshotAt})`);
|
|
1625
|
+
return {
|
|
1626
|
+
snapshot: existingSnapshot,
|
|
1627
|
+
systemPromptOverride: existingSnapshot.systemPrompt
|
|
1628
|
+
};
|
|
1633
1629
|
}
|
|
1634
|
-
const memoryStat = await this._collectMemoryStat();
|
|
1635
1630
|
let resolvedSystemPrompt = initialSystemPrompt;
|
|
1636
1631
|
if (resolvedSystemPrompt && resolvedSystemPrompt.includes("{{memory}}")) {
|
|
1637
1632
|
try {
|
|
@@ -1650,66 +1645,16 @@ class AgentComponent extends BaseComponent {
|
|
|
1650
1645
|
const snapshot = {
|
|
1651
1646
|
systemPrompt: resolvedSystemPrompt ?? agentConfigSystemPrompt ?? "",
|
|
1652
1647
|
additionInfo: effectiveContext.additionInfo || "",
|
|
1653
|
-
snapshotAt: Date.now()
|
|
1654
|
-
memoryStat
|
|
1648
|
+
snapshotAt: Date.now()
|
|
1655
1649
|
};
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
metadata: {
|
|
1659
|
-
...session?.metadata ?? {},
|
|
1660
|
-
cacheSnapshot: snapshot
|
|
1661
|
-
}
|
|
1662
|
-
});
|
|
1663
|
-
logger2.debug(`[AgentComponent._run] Created cacheSnapshot for session ${sessionId} (snapshotAt=${snapshot.snapshotAt})`);
|
|
1664
|
-
} catch (updateErr) {
|
|
1665
|
-
logger2.warn(`[AgentComponent._run] Failed to persist cacheSnapshot for session ${sessionId}: ${updateErr}`);
|
|
1666
|
-
}
|
|
1650
|
+
this._cacheSnapshots.set(sessionId, snapshot);
|
|
1651
|
+
logger2.debug(`[AgentComponent._run] Created cacheSnapshot for session ${sessionId} (snapshotAt=${snapshot.snapshotAt})`);
|
|
1667
1652
|
return { snapshot, systemPromptOverride: resolvedSystemPrompt };
|
|
1668
1653
|
} catch (err) {
|
|
1669
1654
|
logger2.warn(`[AgentComponent._run] Failed to load cacheSnapshot: ${err}`);
|
|
1670
1655
|
return { snapshot: null, systemPromptOverride: undefined };
|
|
1671
1656
|
}
|
|
1672
1657
|
}
|
|
1673
|
-
async _isMemorySnapshotStale(snapshot) {
|
|
1674
|
-
const stat = snapshot.memoryStat;
|
|
1675
|
-
if (!stat || typeof stat !== "object") {
|
|
1676
|
-
return "no-memoryStat (legacy snapshot)";
|
|
1677
|
-
}
|
|
1678
|
-
const current = await this._collectMemoryStat();
|
|
1679
|
-
if (current.globalMtime !== stat.globalMtime) {
|
|
1680
|
-
return `global memory.md mtime changed (${stat.globalMtime} -> ${current.globalMtime})`;
|
|
1681
|
-
}
|
|
1682
|
-
if (current.projectMtime !== stat.projectMtime) {
|
|
1683
|
-
return `project memory.md mtime changed (${stat.projectMtime} -> ${current.projectMtime})`;
|
|
1684
|
-
}
|
|
1685
|
-
return null;
|
|
1686
|
-
}
|
|
1687
|
-
async _collectMemoryStat() {
|
|
1688
|
-
const empty = { globalMtime: 0, projectMtime: 0 };
|
|
1689
|
-
try {
|
|
1690
|
-
const memoryComponent = this.env?.getComponent?.("memory");
|
|
1691
|
-
if (!memoryComponent?.getMemoryPaths || !memoryComponent.getMemoryFile) {
|
|
1692
|
-
return empty;
|
|
1693
|
-
}
|
|
1694
|
-
const memoryFile = memoryComponent.getMemoryFile();
|
|
1695
|
-
const paths = memoryComponent.getMemoryPaths();
|
|
1696
|
-
const result = { globalMtime: 0, projectMtime: 0 };
|
|
1697
|
-
for (const p of paths) {
|
|
1698
|
-
const filePath = path.join(p.path, memoryFile);
|
|
1699
|
-
try {
|
|
1700
|
-
const st = await fs.stat(filePath);
|
|
1701
|
-
if (p.type === "global") {
|
|
1702
|
-
result.globalMtime = st.mtimeMs;
|
|
1703
|
-
} else if (p.type === "project") {
|
|
1704
|
-
result.projectMtime = st.mtimeMs;
|
|
1705
|
-
}
|
|
1706
|
-
} catch {}
|
|
1707
|
-
}
|
|
1708
|
-
return result;
|
|
1709
|
-
} catch {
|
|
1710
|
-
return empty;
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
1658
|
async _fallbackReplaceMemory(systemPrompt) {
|
|
1714
1659
|
if (!systemPrompt.includes("{{memory}}"))
|
|
1715
1660
|
return systemPrompt;
|
|
@@ -1991,7 +1936,8 @@ class AgentComponent extends BaseComponent {
|
|
|
1991
1936
|
...ctx._runId ? { runId: ctx._runId } : {},
|
|
1992
1937
|
...ctx.context.sessionId ? { sessionId: ctx.context.sessionId } : {},
|
|
1993
1938
|
...ctx.context.agentType ? { agentType: ctx.context.agentType } : {},
|
|
1994
|
-
...ctx.agent?.name ? { agentName: ctx.agent.name } : {}
|
|
1939
|
+
...ctx.agent?.name ? { agentName: ctx.agent.name } : {},
|
|
1940
|
+
...ctx.context.extendTools?.length ? { extendTools: ctx.context.extendTools } : {}
|
|
1995
1941
|
}
|
|
1996
1942
|
};
|
|
1997
1943
|
const request = {
|
|
@@ -7,7 +7,8 @@ var BUILT_IN_EVENT_SOURCE_TYPES = {
|
|
|
7
7
|
LARK_CLI: "lark-cli",
|
|
8
8
|
TIMER: "timer",
|
|
9
9
|
BOUNTY_IM: "bounty-im",
|
|
10
|
-
CLI_COMMAND: "cli-command"
|
|
10
|
+
CLI_COMMAND: "cli-command",
|
|
11
|
+
WECOM_CLI: "wecom-cli"
|
|
11
12
|
};
|
|
12
13
|
var BUILT_IN_EVENT_SOURCE_TYPE_LIST = Object.values(BUILT_IN_EVENT_SOURCE_TYPES);
|
|
13
14
|
var defaultLarkCliRunner = {
|
|
@@ -60,6 +61,8 @@ function getDefaultConfigForType(type) {
|
|
|
60
61
|
switch (type) {
|
|
61
62
|
case BUILT_IN_EVENT_SOURCE_TYPES.LARK_CLI:
|
|
62
63
|
return { command: "lark-cli event consume im.message.receive_v1 --as bot" };
|
|
64
|
+
case BUILT_IN_EVENT_SOURCE_TYPES.WECOM_CLI:
|
|
65
|
+
return { command: "wecom-cli event consume" };
|
|
63
66
|
default:
|
|
64
67
|
return {};
|
|
65
68
|
}
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
WorkflowRepository,
|
|
3
3
|
migrateEmptyTagsToDefault,
|
|
4
4
|
rowToWorkflow
|
|
5
|
-
} from "./roy-agent-core-
|
|
6
|
-
import"./roy-agent-core-
|
|
5
|
+
} from "./roy-agent-core-4fkxy2gv.js";
|
|
6
|
+
import"./roy-agent-core-vf9sp6s3.js";
|
|
7
7
|
import"./roy-agent-core-rvxg1wps.js";
|
|
8
|
-
import"./roy-agent-core-
|
|
8
|
+
import"./roy-agent-core-5s2t8z00.js";
|
|
9
9
|
import"./roy-agent-core-7f7t9wwp.js";
|
|
10
10
|
import"./roy-agent-core-85xyctnb.js";
|
|
11
11
|
import"./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LarkCardPatchNotifier,
|
|
3
3
|
formatDurationMs
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-shb1qsyg.js";
|
|
5
5
|
import {
|
|
6
6
|
WorkflowHookPoints,
|
|
7
7
|
init_workflow_hook_points
|
|
8
|
-
} from "./roy-agent-core-
|
|
8
|
+
} from "./roy-agent-core-h83zdsrq.js";
|
|
9
9
|
import {
|
|
10
10
|
init_context
|
|
11
|
-
} from "./roy-agent-core-
|
|
11
|
+
} from "./roy-agent-core-tkpp1ba0.js";
|
|
12
12
|
import {
|
|
13
13
|
getEnvContextOrEmpty
|
|
14
|
-
} from "./roy-agent-core-
|
|
14
|
+
} from "./roy-agent-core-p31ftgq9.js";
|
|
15
15
|
import {
|
|
16
16
|
TracedAs,
|
|
17
17
|
init_decorator
|
|
18
|
-
} from "./roy-agent-core-
|
|
18
|
+
} from "./roy-agent-core-5s2t8z00.js";
|
|
19
19
|
import {
|
|
20
20
|
createLogger,
|
|
21
21
|
init_logger
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/env/tool/validator.ts
|
|
2
|
+
import { ZodError } from "zod";
|
|
3
|
+
var REASON_REQUIRED_CONFIG_KEY = "tool.reason.required";
|
|
4
|
+
var moduleLevelReasonRequired = true;
|
|
5
|
+
var configComponentRef = null;
|
|
6
|
+
function setToolReasonConfigComponent(component) {
|
|
7
|
+
configComponentRef = component;
|
|
8
|
+
}
|
|
9
|
+
function isToolReasonRequired() {
|
|
10
|
+
if (configComponentRef) {
|
|
11
|
+
const v = configComponentRef.get(REASON_REQUIRED_CONFIG_KEY);
|
|
12
|
+
if (typeof v === "boolean")
|
|
13
|
+
return v;
|
|
14
|
+
if (typeof v === "string")
|
|
15
|
+
return v !== "false";
|
|
16
|
+
}
|
|
17
|
+
return moduleLevelReasonRequired;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class ToolValidator {
|
|
21
|
+
async validate(tool, args) {
|
|
22
|
+
if (isToolReasonRequired()) {
|
|
23
|
+
const reason = args?.["reason"];
|
|
24
|
+
if (typeof reason !== "string" || reason.trim() === "") {
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
error: `Missing or empty required parameter 'reason' for tool '${tool.name}': ` + `provide a one-sentence explanation of why you are calling this tool.`
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const parsed = await tool.parameters.parseAsync(args);
|
|
33
|
+
return {
|
|
34
|
+
success: true,
|
|
35
|
+
data: parsed
|
|
36
|
+
};
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof ZodError) {
|
|
39
|
+
const errorMessage = tool.formatValidationError ? tool.formatValidationError(error) : this.formatError(error);
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
error: `Invalid arguments for tool '${tool.name}': ${errorMessage}`
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
success: false,
|
|
47
|
+
error: `Validation error: ${error}`
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
formatError(error) {
|
|
52
|
+
return error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join("; ");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { setToolReasonConfigComponent, isToolReasonRequired, ToolValidator };
|
|
@@ -439,7 +439,7 @@ subSessionId: sub-session-xyz
|
|
|
439
439
|
| session 规模 | 建议处置 |
|
|
440
440
|
|---|---|
|
|
441
441
|
| **小**(超限比例 < 30%,消息数不多) | 直接 \`compact_session\` → 压缩成功后用 \`sub_session_id\` 续跑 |
|
|
442
|
-
| **大**(超限比例很高 / 消息数很多) | \`compact_session\` **可能要跑很久甚至撞 120s 工具超时** → **不要在同一个 session
|
|
442
|
+
| **大**(超限比例很高 / 消息数很多) | \`compact_session\` **可能要跑很久甚至撞 120s 工具超时** → **不要在同一个 session 上死磕**,走下面的**兜底路径**(压缩复查 → 仍无效才开新 session)+ 明确列出「已完成项 / 断点 / 小目标」 |
|
|
443
443
|
|
|
444
444
|
**为什么必须先评估**(实测数据):
|
|
445
445
|
|
|
@@ -474,7 +474,7 @@ const r = await compact_session({ session_id: "sub-session-xyz" });
|
|
|
474
474
|
2. **再检查一次**该 session 的**消息数 / checkpoint** —— \`compact_session\` 成功会返回 \`checkpointId\`,也可以用 session 相关工具确认消息是否已被 archived
|
|
475
475
|
3. 再决定走哪条路:
|
|
476
476
|
- **压缩其实成功了** → 用 \`sub_session_id\` 续跑(上下文已经变小,安全)
|
|
477
|
-
- **压缩确实没生效** →
|
|
477
|
+
- **压缩确实没生效** → 才走下面的兜底路径(换新 session)
|
|
478
478
|
|
|
479
479
|
**第 3 步:带同一个 \`sub_session_id\` 续跑**
|
|
480
480
|
|
|
@@ -502,9 +502,9 @@ delegate_task({
|
|
|
502
502
|
|
|
503
503
|
\`\`\`typescript
|
|
504
504
|
delegate_task({
|
|
505
|
-
description: "
|
|
505
|
+
description: "接续工作(上下文已超限,压缩复查后仍不可救,换新 session)",
|
|
506
506
|
prompt: "【已完成】... \\n【断点】... \\n【小目标】... \\n【相关文件路径】... \\n【已知结论】...",
|
|
507
|
-
//
|
|
507
|
+
sub_session_id: "sub-session-xyz", // ⚠️ 兜底路径:仅在 compact_session 也无效时才省略
|
|
508
508
|
});
|
|
509
509
|
\`\`\`
|
|
510
510
|
|
|
@@ -512,9 +512,9 @@ delegate_task({
|
|
|
512
512
|
|
|
513
513
|
#### ❌ 反模式警示
|
|
514
514
|
|
|
515
|
-
- ❌
|
|
516
|
-
- ❌ **不要在压缩失败时反复用同一个 session 续跑** —— 同样的超限会再发生一次,徒增 token 消耗。压缩失败就走"
|
|
517
|
-
- ❌ **不要在 session 规模很大时死磕 \`compact_session\`** —— 先按第 0 步评估,message
|
|
515
|
+
- ❌ **不要从头重新委托** —— 不传 \`sub_session_id\` 直接 \`delegate_task\` 是**最后手段**,只在旧 session 上下文已确认不可救(compact_session 后仍超限 / 迭代上限且无可复用断点)时才允许。其余情况一律带 \`sub_session_id\` 续跑(不传才会丢掉全部上下文,前面的调研和代码全白做,还可能重复踩已解决过的坑)。
|
|
516
|
+
- ❌ **不要在压缩失败时反复用同一个 session 续跑** —— 同样的超限会再发生一次,徒增 token 消耗。压缩失败就走"换新 session(不传 \`sub_session_id\`)+ 明确列出已完成项/断点/小目标"的兜底路径。
|
|
517
|
+
- ❌ **不要在 session 规模很大时死磕 \`compact_session\`** —— 先按第 0 步评估,message 数很多就走兜底路径(压缩复查 → 仍无效才换新 session)。
|
|
518
518
|
- ❌ **不要用 \`compact_session\` 压缩当前会话自己** —— 工具会直接拒绝(自毁)。
|
|
519
519
|
- ❌ **不要压缩还在 running/pending 的后台任务** —— 先 \`stop_task\`。
|
|
520
520
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
init_context
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-tkpp1ba0.js";
|
|
4
4
|
import {
|
|
5
5
|
getEnvContext
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-p31ftgq9.js";
|
|
7
7
|
import {
|
|
8
8
|
__esm
|
|
9
9
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-bjtc9d35.js";
|
|
5
5
|
import"./roy-agent-core-1db4vpc6.js";
|
|
6
6
|
import"./roy-agent-core-mkc3zshb.js";
|
|
7
|
-
import"./roy-agent-core-
|
|
8
|
-
import"./roy-agent-core-
|
|
9
|
-
import"./roy-agent-core-
|
|
10
|
-
import"./roy-agent-core-
|
|
7
|
+
import"./roy-agent-core-yet36q5k.js";
|
|
8
|
+
import"./roy-agent-core-tkpp1ba0.js";
|
|
9
|
+
import"./roy-agent-core-p31ftgq9.js";
|
|
10
|
+
import"./roy-agent-core-5s2t8z00.js";
|
|
11
11
|
import"./roy-agent-core-7f7t9wwp.js";
|
|
12
12
|
import"./roy-agent-core-85xyctnb.js";
|
|
13
13
|
import"./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
builtInHandlers
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-gr5h1dyr.js";
|
|
4
|
+
import {
|
|
5
|
+
appendAuditLog,
|
|
6
|
+
checkSourceCountDrop,
|
|
7
|
+
readSourceCountFromDisk,
|
|
8
|
+
snapshotConfigDir
|
|
9
|
+
} from "./roy-agent-core-2stt4rp5.js";
|
|
4
10
|
import {
|
|
5
11
|
envKeyToConfigKey
|
|
6
12
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
7
13
|
import {
|
|
8
14
|
BaseComponent
|
|
9
|
-
} from "./roy-agent-core-
|
|
15
|
+
} from "./roy-agent-core-m39v7qpx.js";
|
|
10
16
|
import {
|
|
11
17
|
TracedAs,
|
|
12
18
|
init_decorator
|
|
13
|
-
} from "./roy-agent-core-
|
|
19
|
+
} from "./roy-agent-core-5s2t8z00.js";
|
|
14
20
|
import {
|
|
15
21
|
createLogger,
|
|
16
22
|
init_logger
|
|
@@ -57,6 +63,23 @@ class EventSourceComponent extends BaseComponent {
|
|
|
57
63
|
buffers = new Map;
|
|
58
64
|
configPath = "";
|
|
59
65
|
persistenceEnabled = true;
|
|
66
|
+
constructor() {
|
|
67
|
+
super();
|
|
68
|
+
this.applyTestEnvironmentGuard();
|
|
69
|
+
}
|
|
70
|
+
static isTestEnvironment() {
|
|
71
|
+
return "BUN_TEST_WORKER_ID" in process.env;
|
|
72
|
+
}
|
|
73
|
+
applyTestEnvironmentGuard() {
|
|
74
|
+
if (this.persistenceEnabled && EventSourceComponent.isTestEnvironment()) {
|
|
75
|
+
if (process.env.ROY_AGENT_ES_PERSISTENCE === "1") {
|
|
76
|
+
logger.debug("EventSource persistence opt-out active in test env (ROY_AGENT_ES_PERSISTENCE=1)");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this.persistenceEnabled = false;
|
|
80
|
+
logger.debug("EventSource persistence disabled by test-environment guard (Task #5181)");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
60
83
|
configComponent;
|
|
61
84
|
configWatcher;
|
|
62
85
|
async onInit() {
|
|
@@ -86,6 +109,7 @@ class EventSourceComponent extends BaseComponent {
|
|
|
86
109
|
}
|
|
87
110
|
await this.onInit();
|
|
88
111
|
this.setStatus("running");
|
|
112
|
+
this.applyTestEnvironmentGuard();
|
|
89
113
|
}
|
|
90
114
|
async onStart() {}
|
|
91
115
|
async onStop() {
|
|
@@ -116,7 +140,7 @@ class EventSourceComponent extends BaseComponent {
|
|
|
116
140
|
}
|
|
117
141
|
}
|
|
118
142
|
async executeInitHooks() {
|
|
119
|
-
const { EventSourceInitHooks } = await import("./roy-agent-core-
|
|
143
|
+
const { EventSourceInitHooks } = await import("./roy-agent-core-fzw9xzm1.js");
|
|
120
144
|
await EventSourceInitHooks.execute(this);
|
|
121
145
|
}
|
|
122
146
|
registerHandler(handler) {
|
|
@@ -365,6 +389,17 @@ class EventSourceComponent extends BaseComponent {
|
|
|
365
389
|
const eventHandler = this.eventHandlers.get(id) ?? this.createDefaultEventHandler(id, config.type);
|
|
366
390
|
instance.onEvent(eventHandler);
|
|
367
391
|
await instance.start();
|
|
392
|
+
const instanceStatus = instance.getStatus();
|
|
393
|
+
if (instanceStatus === "error") {
|
|
394
|
+
this.statuses.set(id, "error");
|
|
395
|
+
const reason = instance.getLastError?.() ?? `event source '${config.type}' failed to start`;
|
|
396
|
+
logger.error(`EventSource degraded to error state: ${id} (${config.type}) — ${reason}`);
|
|
397
|
+
this.getEnv()?.pushEnvEvent({
|
|
398
|
+
type: "event-source.error",
|
|
399
|
+
payload: { sourceId: id, sourceType: config.type, reason }
|
|
400
|
+
});
|
|
401
|
+
throw new Error(reason);
|
|
402
|
+
}
|
|
368
403
|
this.statuses.set(id, "running");
|
|
369
404
|
this.getEnv()?.pushEnvEvent({
|
|
370
405
|
type: "event-source.started",
|
|
@@ -420,11 +455,37 @@ class EventSourceComponent extends BaseComponent {
|
|
|
420
455
|
return;
|
|
421
456
|
try {
|
|
422
457
|
const configPath = this.getConfigFilePath();
|
|
458
|
+
const configDir = join(configPath, "..");
|
|
459
|
+
const diskCount = readSourceCountFromDisk(configPath);
|
|
460
|
+
const newCount = this.sources.size;
|
|
461
|
+
const dropCheck = checkSourceCountDrop(diskCount, newCount);
|
|
462
|
+
if (!dropCheck.allowed && process.env.ROY_AGENT_ES_FORCE_SAVE !== "1") {
|
|
463
|
+
appendAuditLog(configDir, {
|
|
464
|
+
file: "event-sources.json",
|
|
465
|
+
action: "drop-blocked",
|
|
466
|
+
detail: dropCheck.reason
|
|
467
|
+
});
|
|
468
|
+
logger.error(`Refusing to save event sources: ${dropCheck.reason}`);
|
|
469
|
+
throw new Error(`EventSource saveConfig blocked: ${dropCheck.reason}`);
|
|
470
|
+
}
|
|
471
|
+
const snapDir = snapshotConfigDir(configDir);
|
|
472
|
+
if (snapDir) {
|
|
473
|
+
appendAuditLog(configDir, {
|
|
474
|
+
file: "event-sources.json",
|
|
475
|
+
action: "pre-save-snapshot",
|
|
476
|
+
detail: `snapshot=${snapDir}`
|
|
477
|
+
});
|
|
478
|
+
}
|
|
423
479
|
const config = {
|
|
424
480
|
version: "1.0.0",
|
|
425
481
|
sources: Array.from(this.sources.values())
|
|
426
482
|
};
|
|
427
483
|
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
484
|
+
appendAuditLog(configDir, {
|
|
485
|
+
file: "event-sources.json",
|
|
486
|
+
action: "save",
|
|
487
|
+
detail: `${newCount} sources (disk had ${diskCount})`
|
|
488
|
+
});
|
|
428
489
|
logger.debug(`Saved ${this.sources.size} event source configurations`);
|
|
429
490
|
} catch (error) {
|
|
430
491
|
logger.error("Failed to save event source configurations:", error);
|