@ai-setting/roy-agent-core 1.7.0 → 1.7.1
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/env/agent/index.js +3 -4
- package/dist/env/index.js +7 -8
- package/dist/env/llm/index.js +3 -4
- package/dist/env/session/index.js +4 -4
- package/dist/env/session/storage/index.js +3 -3
- package/dist/env/workflow/index.js +6 -6
- package/dist/env/workflow/tools/index.js +5 -5
- package/dist/index.js +13 -14
- package/dist/shared/@ai-setting/{roy-agent-core-167qsqrz.js → roy-agent-core-2xb3f3ye.js} +143 -23
- package/dist/shared/@ai-setting/{roy-agent-core-q34tv05y.js → roy-agent-core-3dwcwgn5.js} +136 -29
- package/dist/shared/@ai-setting/{roy-agent-core-mreh3s0v.js → roy-agent-core-qatz3q31.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-w66q6zst.js → roy-agent-core-w93wrd77.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-xcs0vjqg.js → roy-agent-core-wgp3q62x.js} +7 -4
- package/dist/shared/@ai-setting/{roy-agent-core-mhayyp5c.js → roy-agent-core-xmacq00w.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-bs3c1x02.js → roy-agent-core-xvag5pd0.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-879dbkpx.js → roy-agent-core-zcx8nf4a.js} +1 -1
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-ddrc00er.js +0 -50
package/dist/env/agent/index.js
CHANGED
|
@@ -2,8 +2,7 @@ import {
|
|
|
2
2
|
AgentComponent,
|
|
3
3
|
AgentComponentConfigSchema,
|
|
4
4
|
SummaryAgent
|
|
5
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
6
|
-
import"../../shared/@ai-setting/roy-agent-core-167qsqrz.js";
|
|
5
|
+
} from "../../shared/@ai-setting/roy-agent-core-3dwcwgn5.js";
|
|
7
6
|
import"../../shared/@ai-setting/roy-agent-core-h28gcd77.js";
|
|
8
7
|
import"../../shared/@ai-setting/roy-agent-core-br7dmedr.js";
|
|
9
8
|
import"../../shared/@ai-setting/roy-agent-core-t3yqzgse.js";
|
|
@@ -12,8 +11,8 @@ import"../../shared/@ai-setting/roy-agent-core-x0yztmm6.js";
|
|
|
12
11
|
import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
|
|
13
12
|
import"../../shared/@ai-setting/roy-agent-core-c1v263jn.js";
|
|
14
13
|
import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
|
|
15
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
16
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
14
|
+
import"../../shared/@ai-setting/roy-agent-core-zcx8nf4a.js";
|
|
15
|
+
import"../../shared/@ai-setting/roy-agent-core-2xb3f3ye.js";
|
|
17
16
|
import"../../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
18
17
|
import"../../shared/@ai-setting/roy-agent-core-pde8hkq4.js";
|
|
19
18
|
import"../../shared/@ai-setting/roy-agent-core-5ts23mx0.js";
|
package/dist/env/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import"../shared/@ai-setting/roy-agent-core-gns3wa97.js";
|
|
|
21
21
|
import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
22
22
|
import {
|
|
23
23
|
WorkflowComponent
|
|
24
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
24
|
+
} from "../shared/@ai-setting/roy-agent-core-xmacq00w.js";
|
|
25
25
|
import"../shared/@ai-setting/roy-agent-core-3e0w0ekw.js";
|
|
26
26
|
import"../shared/@ai-setting/roy-agent-core-s4r8f6se.js";
|
|
27
27
|
import"../shared/@ai-setting/roy-agent-core-6atd905e.js";
|
|
@@ -30,7 +30,7 @@ import"../shared/@ai-setting/roy-agent-core-h1cb2jzh.js";
|
|
|
30
30
|
import"../shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
|
|
31
31
|
import"../shared/@ai-setting/roy-agent-core-hhrg314p.js";
|
|
32
32
|
import"../shared/@ai-setting/roy-agent-core-0qjw25e8.js";
|
|
33
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
33
|
+
import"../shared/@ai-setting/roy-agent-core-qatz3q31.js";
|
|
34
34
|
import"../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
|
|
35
35
|
import"../shared/@ai-setting/roy-agent-core-j9ybhwnq.js";
|
|
36
36
|
import"../shared/@ai-setting/roy-agent-core-w8rv08d3.js";
|
|
@@ -41,8 +41,7 @@ import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
|
|
|
41
41
|
import {
|
|
42
42
|
AgentComponent,
|
|
43
43
|
AgentComponentConfigSchema
|
|
44
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
45
|
-
import"../shared/@ai-setting/roy-agent-core-167qsqrz.js";
|
|
44
|
+
} from "../shared/@ai-setting/roy-agent-core-3dwcwgn5.js";
|
|
46
45
|
import"../shared/@ai-setting/roy-agent-core-h28gcd77.js";
|
|
47
46
|
import"../shared/@ai-setting/roy-agent-core-br7dmedr.js";
|
|
48
47
|
import"../shared/@ai-setting/roy-agent-core-t3yqzgse.js";
|
|
@@ -72,11 +71,11 @@ import {
|
|
|
72
71
|
import"../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
|
|
73
72
|
import"../shared/@ai-setting/roy-agent-core-fnv3ev18.js";
|
|
74
73
|
import"../shared/@ai-setting/roy-agent-core-dxfd6p1c.js";
|
|
75
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
74
|
+
import"../shared/@ai-setting/roy-agent-core-xvag5pd0.js";
|
|
76
75
|
import"../shared/@ai-setting/roy-agent-core-rvxg1wps.js";
|
|
77
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
78
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
79
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
76
|
+
import"../shared/@ai-setting/roy-agent-core-wgp3q62x.js";
|
|
77
|
+
import"../shared/@ai-setting/roy-agent-core-zcx8nf4a.js";
|
|
78
|
+
import"../shared/@ai-setting/roy-agent-core-2xb3f3ye.js";
|
|
80
79
|
import"../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
81
80
|
import {
|
|
82
81
|
BaseComponent
|
package/dist/env/llm/index.js
CHANGED
|
@@ -14,17 +14,16 @@ import {
|
|
|
14
14
|
createLLMAdapter,
|
|
15
15
|
getLLMProviderOverride,
|
|
16
16
|
setLLMProvider
|
|
17
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
17
|
+
} from "../../shared/@ai-setting/roy-agent-core-w93wrd77.js";
|
|
18
18
|
import"../../shared/@ai-setting/roy-agent-core-y3g3ar7a.js";
|
|
19
|
+
import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
|
|
19
20
|
import {
|
|
20
21
|
convertToSDKMessages,
|
|
21
22
|
createInvokeConfig,
|
|
22
23
|
invoke,
|
|
23
24
|
invokeNonStream,
|
|
24
25
|
parseModelString
|
|
25
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
26
|
-
import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
|
|
27
|
-
import"../../shared/@ai-setting/roy-agent-core-ddrc00er.js";
|
|
26
|
+
} from "../../shared/@ai-setting/roy-agent-core-2xb3f3ye.js";
|
|
28
27
|
import"../../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
29
28
|
import"../../shared/@ai-setting/roy-agent-core-pde8hkq4.js";
|
|
30
29
|
import"../../shared/@ai-setting/roy-agent-core-5ts23mx0.js";
|
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
MIN_SESSION_ID_LENGTH,
|
|
4
4
|
SessionComponent,
|
|
5
5
|
isValidSessionId
|
|
6
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
6
|
+
} from "../../shared/@ai-setting/roy-agent-core-xvag5pd0.js";
|
|
7
7
|
import"../../shared/@ai-setting/roy-agent-core-rvxg1wps.js";
|
|
8
8
|
import {
|
|
9
9
|
MemorySessionStore
|
|
10
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
10
|
+
} from "../../shared/@ai-setting/roy-agent-core-wgp3q62x.js";
|
|
11
11
|
import {
|
|
12
12
|
SessionMessageConverter
|
|
13
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
14
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
13
|
+
} from "../../shared/@ai-setting/roy-agent-core-zcx8nf4a.js";
|
|
14
|
+
import"../../shared/@ai-setting/roy-agent-core-2xb3f3ye.js";
|
|
15
15
|
import"../../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
16
16
|
import"../../shared/@ai-setting/roy-agent-core-pde8hkq4.js";
|
|
17
17
|
import"../../shared/@ai-setting/roy-agent-core-5ts23mx0.js";
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
SQLiteSessionStore,
|
|
4
4
|
getDefaultDataDir,
|
|
5
5
|
getDefaultSessionDbPath
|
|
6
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
7
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
8
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
6
|
+
} from "../../../shared/@ai-setting/roy-agent-core-wgp3q62x.js";
|
|
7
|
+
import"../../../shared/@ai-setting/roy-agent-core-zcx8nf4a.js";
|
|
8
|
+
import"../../../shared/@ai-setting/roy-agent-core-2xb3f3ye.js";
|
|
9
9
|
import"../../../shared/@ai-setting/roy-agent-core-kaq037np.js";
|
|
10
10
|
import"../../../shared/@ai-setting/roy-agent-core-1khp1m0r.js";
|
|
11
11
|
import"../../../shared/@ai-setting/roy-agent-core-4an1p9a1.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WorkflowComponent
|
|
3
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
3
|
+
} from "../../shared/@ai-setting/roy-agent-core-xmacq00w.js";
|
|
4
4
|
import"../../shared/@ai-setting/roy-agent-core-3e0w0ekw.js";
|
|
5
5
|
import"../../shared/@ai-setting/roy-agent-core-s4r8f6se.js";
|
|
6
6
|
import"../../shared/@ai-setting/roy-agent-core-6atd905e.js";
|
|
@@ -9,7 +9,7 @@ import"../../shared/@ai-setting/roy-agent-core-h1cb2jzh.js";
|
|
|
9
9
|
import"../../shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
|
|
10
10
|
import"../../shared/@ai-setting/roy-agent-core-hhrg314p.js";
|
|
11
11
|
import"../../shared/@ai-setting/roy-agent-core-0qjw25e8.js";
|
|
12
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
12
|
+
import"../../shared/@ai-setting/roy-agent-core-qatz3q31.js";
|
|
13
13
|
import"../../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
|
|
14
14
|
import"../../shared/@ai-setting/roy-agent-core-j9ybhwnq.js";
|
|
15
15
|
import"../../shared/@ai-setting/roy-agent-core-w8rv08d3.js";
|
|
@@ -84,11 +84,11 @@ import {
|
|
|
84
84
|
createWorkflowAskUserEvent
|
|
85
85
|
} from "../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
86
86
|
import"../../shared/@ai-setting/roy-agent-core-c1v263jn.js";
|
|
87
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
87
|
+
import"../../shared/@ai-setting/roy-agent-core-xvag5pd0.js";
|
|
88
88
|
import"../../shared/@ai-setting/roy-agent-core-rvxg1wps.js";
|
|
89
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
90
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
91
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
89
|
+
import"../../shared/@ai-setting/roy-agent-core-wgp3q62x.js";
|
|
90
|
+
import"../../shared/@ai-setting/roy-agent-core-zcx8nf4a.js";
|
|
91
|
+
import"../../shared/@ai-setting/roy-agent-core-2xb3f3ye.js";
|
|
92
92
|
import"../../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
93
93
|
import"../../shared/@ai-setting/roy-agent-core-pde8hkq4.js";
|
|
94
94
|
import"../../shared/@ai-setting/roy-agent-core-5ts23mx0.js";
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
getRunWorkflowTool,
|
|
25
25
|
initRunWorkflowTool,
|
|
26
26
|
resetRunWorkflowTool
|
|
27
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
27
|
+
} from "../../../shared/@ai-setting/roy-agent-core-qatz3q31.js";
|
|
28
28
|
import {
|
|
29
29
|
WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME,
|
|
30
30
|
WorkflowJsonOutputMarker,
|
|
@@ -38,11 +38,11 @@ import"../../../shared/@ai-setting/roy-agent-core-0v74marc.js";
|
|
|
38
38
|
import"../../../shared/@ai-setting/roy-agent-core-jrj30vq3.js";
|
|
39
39
|
import"../../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
40
40
|
import"../../../shared/@ai-setting/roy-agent-core-c1v263jn.js";
|
|
41
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
41
|
+
import"../../../shared/@ai-setting/roy-agent-core-xvag5pd0.js";
|
|
42
42
|
import"../../../shared/@ai-setting/roy-agent-core-rvxg1wps.js";
|
|
43
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
44
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
45
|
-
import"../../../shared/@ai-setting/roy-agent-core-
|
|
43
|
+
import"../../../shared/@ai-setting/roy-agent-core-wgp3q62x.js";
|
|
44
|
+
import"../../../shared/@ai-setting/roy-agent-core-zcx8nf4a.js";
|
|
45
|
+
import"../../../shared/@ai-setting/roy-agent-core-2xb3f3ye.js";
|
|
46
46
|
import"../../../shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
47
47
|
import"../../../shared/@ai-setting/roy-agent-core-pde8hkq4.js";
|
|
48
48
|
import"../../../shared/@ai-setting/roy-agent-core-5ts23mx0.js";
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ModelLimitsSchema,
|
|
10
10
|
ProviderCapabilitiesSchema,
|
|
11
11
|
ProviderConfigSchema
|
|
12
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
12
|
+
} from "./shared/@ai-setting/roy-agent-core-w93wrd77.js";
|
|
13
13
|
import {
|
|
14
14
|
ConfigComponent
|
|
15
15
|
} from "./shared/@ai-setting/roy-agent-core-g7nmwg63.js";
|
|
@@ -102,7 +102,7 @@ import {
|
|
|
102
102
|
} from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
103
103
|
import {
|
|
104
104
|
WorkflowComponent
|
|
105
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
105
|
+
} from "./shared/@ai-setting/roy-agent-core-xmacq00w.js";
|
|
106
106
|
import {
|
|
107
107
|
init_node_registry_helper,
|
|
108
108
|
registerDecoratorNodeType
|
|
@@ -114,7 +114,7 @@ import"./shared/@ai-setting/roy-agent-core-h1cb2jzh.js";
|
|
|
114
114
|
import"./shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
|
|
115
115
|
import"./shared/@ai-setting/roy-agent-core-hhrg314p.js";
|
|
116
116
|
import"./shared/@ai-setting/roy-agent-core-0qjw25e8.js";
|
|
117
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
117
|
+
import"./shared/@ai-setting/roy-agent-core-qatz3q31.js";
|
|
118
118
|
import"./shared/@ai-setting/roy-agent-core-1db4vpc6.js";
|
|
119
119
|
import"./shared/@ai-setting/roy-agent-core-j9ybhwnq.js";
|
|
120
120
|
import"./shared/@ai-setting/roy-agent-core-w8rv08d3.js";
|
|
@@ -131,13 +131,7 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
|
|
|
131
131
|
import {
|
|
132
132
|
AgentComponent,
|
|
133
133
|
AgentComponentConfigSchema
|
|
134
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
135
|
-
import {
|
|
136
|
-
createInvokeConfig,
|
|
137
|
-
invoke,
|
|
138
|
-
invokeNonStream,
|
|
139
|
-
parseModelString
|
|
140
|
-
} from "./shared/@ai-setting/roy-agent-core-167qsqrz.js";
|
|
134
|
+
} from "./shared/@ai-setting/roy-agent-core-3dwcwgn5.js";
|
|
141
135
|
import {
|
|
142
136
|
ToolComponent,
|
|
143
137
|
ToolRegistry,
|
|
@@ -200,13 +194,18 @@ import"./shared/@ai-setting/roy-agent-core-fnv3ev18.js";
|
|
|
200
194
|
import"./shared/@ai-setting/roy-agent-core-dxfd6p1c.js";
|
|
201
195
|
import {
|
|
202
196
|
SessionComponent
|
|
203
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
197
|
+
} from "./shared/@ai-setting/roy-agent-core-xvag5pd0.js";
|
|
204
198
|
import"./shared/@ai-setting/roy-agent-core-rvxg1wps.js";
|
|
205
199
|
import {
|
|
206
200
|
MemorySessionStore
|
|
207
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
208
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
209
|
-
import
|
|
201
|
+
} from "./shared/@ai-setting/roy-agent-core-wgp3q62x.js";
|
|
202
|
+
import"./shared/@ai-setting/roy-agent-core-zcx8nf4a.js";
|
|
203
|
+
import {
|
|
204
|
+
createInvokeConfig,
|
|
205
|
+
invoke,
|
|
206
|
+
invokeNonStream,
|
|
207
|
+
parseModelString
|
|
208
|
+
} from "./shared/@ai-setting/roy-agent-core-2xb3f3ye.js";
|
|
210
209
|
import"./shared/@ai-setting/roy-agent-core-7hh0brvs.js";
|
|
211
210
|
import {
|
|
212
211
|
BaseComponent
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
safeParseToolArgs
|
|
3
|
-
} from "./roy-agent-core-ddrc00er.js";
|
|
4
1
|
import {
|
|
5
2
|
createLogger,
|
|
6
3
|
init_logger
|
|
@@ -18,7 +15,113 @@ import { createAnthropic } from "@ai-sdk/anthropic";
|
|
|
18
15
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
19
16
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
20
17
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
21
|
-
|
|
18
|
+
|
|
19
|
+
// src/env/llm/tool-args-parser.ts
|
|
20
|
+
init_logger();
|
|
21
|
+
var logger = createLogger("llm:tool-args-parser");
|
|
22
|
+
var MAX_SAFE_DEPTH = 5;
|
|
23
|
+
function safeParseToolArgs(args, depth = 0) {
|
|
24
|
+
if (depth >= MAX_SAFE_DEPTH) {
|
|
25
|
+
logger.warn(`[safeParseToolArgs] Max recursion depth (${MAX_SAFE_DEPTH}) exceeded at depth ${depth}. ` + "Input may be malicious or abnormally deeply nested. Returning empty object.", { depth, argsType: typeof args });
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
if (typeof args === "object" && args !== null && !Array.isArray(args)) {
|
|
29
|
+
return args;
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(args)) {
|
|
32
|
+
logger.debug(`[safeParseToolArgs] Input is an array. Tool arguments should be objects. Returning empty object.`, { depth, arrayLength: args.length });
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
if (typeof args === "string") {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(args);
|
|
38
|
+
if (typeof parsed === "string") {
|
|
39
|
+
logger.debug(`[safeParseToolArgs] Detected double/multi-stringified JSON at depth ${depth}. ` + "LLM may be double-stringifying tool arguments. Parsing recursively.", { depth, parsedLength: parsed.length });
|
|
40
|
+
return safeParseToolArgs(parsed, depth + 1);
|
|
41
|
+
}
|
|
42
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
43
|
+
return parsed;
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(parsed)) {
|
|
46
|
+
logger.debug(`[safeParseToolArgs] Parsed result is an array at depth ${depth}. ` + "Tool arguments should be objects, not arrays. Returning empty object.", { depth, parsedLength: parsed.length });
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
return { value: parsed };
|
|
50
|
+
} catch (e) {
|
|
51
|
+
logger.warn(`[safeParseToolArgs] JSON.parse failed at depth ${depth}`, {
|
|
52
|
+
parse_failed: true,
|
|
53
|
+
input_length: args.length,
|
|
54
|
+
depth,
|
|
55
|
+
error: e.message
|
|
56
|
+
});
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/env/llm/llm-cache.ts
|
|
64
|
+
function isOpenAICompatibleProvider(providerName) {
|
|
65
|
+
return providerName === "openai-compatible" || providerName === "openai" || providerName.startsWith("minimax") || providerName === "deepseek" || providerName.startsWith("deepseek") || providerName === "glm" || providerName.startsWith("glm");
|
|
66
|
+
}
|
|
67
|
+
function clampOpenAIPromptCacheKey(sessionId, maxLen = 64) {
|
|
68
|
+
if (sessionId.length <= maxLen)
|
|
69
|
+
return sessionId;
|
|
70
|
+
return sessionId.slice(0, maxLen - 8) + "-" + sessionId.slice(-7);
|
|
71
|
+
}
|
|
72
|
+
function buildOpenAICompatProviderOptions(sessionId, cacheRetention = "long") {
|
|
73
|
+
if (!sessionId)
|
|
74
|
+
return {};
|
|
75
|
+
return {
|
|
76
|
+
openai: {
|
|
77
|
+
promptCacheKey: clampOpenAIPromptCacheKey(sessionId),
|
|
78
|
+
promptCacheRetention: cacheRetention === "long" ? "24h" : undefined
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function applyToolCacheControl(tools, providerName) {
|
|
83
|
+
if (!tools || tools.length === 0)
|
|
84
|
+
return tools;
|
|
85
|
+
if (providerName !== "anthropic" && !providerName.startsWith("anthropic")) {
|
|
86
|
+
return tools;
|
|
87
|
+
}
|
|
88
|
+
const result = tools.map((t) => ({ ...t }));
|
|
89
|
+
const lastTool = result[result.length - 1];
|
|
90
|
+
lastTool.providerOptions = {
|
|
91
|
+
anthropic: { cacheControl: { type: "ephemeral" } }
|
|
92
|
+
};
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
function canonicalizeParts(parts) {
|
|
96
|
+
if (!parts)
|
|
97
|
+
return JSON.stringify(parts);
|
|
98
|
+
const sorted = sortObjectKeysDeep(parts);
|
|
99
|
+
canonicalizeToolCallArgsInPlace(sorted);
|
|
100
|
+
return JSON.stringify(sorted);
|
|
101
|
+
}
|
|
102
|
+
function canonicalizeToolCallArgsInPlace(value) {
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
for (const item of value)
|
|
105
|
+
canonicalizeToolCallArgsInPlace(item);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (value && typeof value === "object") {
|
|
109
|
+
const obj = value;
|
|
110
|
+
if (obj.type === "tool-call" && typeof obj.arguments === "string") {
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(obj.arguments);
|
|
113
|
+
const sorted = sortObjectKeysDeep(parsed);
|
|
114
|
+
obj.arguments = JSON.stringify(sorted);
|
|
115
|
+
} catch {}
|
|
116
|
+
}
|
|
117
|
+
for (const key of Object.keys(obj)) {
|
|
118
|
+
canonicalizeToolCallArgsInPlace(obj[key]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/env/llm/invoke.ts
|
|
124
|
+
var logger2 = createLogger("llm:invoke");
|
|
22
125
|
var MAX_RETRIES = 3;
|
|
23
126
|
var DEFAULT_TIMEOUT = 60000;
|
|
24
127
|
|
|
@@ -153,7 +256,7 @@ function isPlainObject(obj) {
|
|
|
153
256
|
var ANTHROPIC_CACHE_CONTROL = {
|
|
154
257
|
anthropic: { cacheControl: { type: "ephemeral" } }
|
|
155
258
|
};
|
|
156
|
-
function convertToSDKMessages(messages) {
|
|
259
|
+
function convertToSDKMessages(messages, options) {
|
|
157
260
|
let lastUserIndex = -1;
|
|
158
261
|
for (let i = messages.length - 1;i >= 0; i--) {
|
|
159
262
|
if (messages[i].role === "user") {
|
|
@@ -161,12 +264,13 @@ function convertToSDKMessages(messages) {
|
|
|
161
264
|
break;
|
|
162
265
|
}
|
|
163
266
|
}
|
|
267
|
+
const openaiOptions = isOpenAICompatibleProvider(options?.provider ?? "") ? buildOpenAICompatProviderOptions(options?.sessionId, "long") : {};
|
|
164
268
|
return messages.map((msg, index) => {
|
|
165
269
|
if (msg.role === "system") {
|
|
166
270
|
return {
|
|
167
271
|
role: "system",
|
|
168
272
|
content: typeof msg.content === "string" ? msg.content : "",
|
|
169
|
-
providerOptions: ANTHROPIC_CACHE_CONTROL
|
|
273
|
+
providerOptions: Object.keys(openaiOptions).length > 0 ? { ...ANTHROPIC_CACHE_CONTROL, ...openaiOptions } : ANTHROPIC_CACHE_CONTROL
|
|
170
274
|
};
|
|
171
275
|
}
|
|
172
276
|
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
@@ -237,7 +341,7 @@ function convertToSDKMessages(messages) {
|
|
|
237
341
|
}
|
|
238
342
|
if (msg.role === "tool") {
|
|
239
343
|
if (!msg.toolCallId) {
|
|
240
|
-
|
|
344
|
+
logger2.warn("Tool message missing toolCallId", { msg });
|
|
241
345
|
}
|
|
242
346
|
let outputValue = "";
|
|
243
347
|
const content = msg.content;
|
|
@@ -270,7 +374,7 @@ function convertToSDKMessages(messages) {
|
|
|
270
374
|
return msg;
|
|
271
375
|
});
|
|
272
376
|
}
|
|
273
|
-
function convertToolsToSDK(tools) {
|
|
377
|
+
function convertToolsToSDK(tools, providerName) {
|
|
274
378
|
const result = {};
|
|
275
379
|
for (const tool of tools) {
|
|
276
380
|
const jsonSchemaObj = extractToolSchema(tool.parameters);
|
|
@@ -279,6 +383,16 @@ function convertToolsToSDK(tools) {
|
|
|
279
383
|
inputSchema: jsonSchema(jsonSchemaObj)
|
|
280
384
|
};
|
|
281
385
|
}
|
|
386
|
+
if (providerName) {
|
|
387
|
+
const cached = applyToolCacheControl(Object.entries(result).map(([name, def]) => ({ name, ...def || {} })), providerName);
|
|
388
|
+
if (cached && cached.length > 0) {
|
|
389
|
+
const lastCached = cached[cached.length - 1];
|
|
390
|
+
const lastName = lastCached.name || Object.keys(result)[Object.keys(result).length - 1];
|
|
391
|
+
if (result[lastName]) {
|
|
392
|
+
result[lastName].providerOptions = lastCached.providerOptions;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
282
396
|
return result;
|
|
283
397
|
}
|
|
284
398
|
function extractToolSchema(parameters) {
|
|
@@ -331,7 +445,7 @@ function convertToolChoice(toolChoice) {
|
|
|
331
445
|
}
|
|
332
446
|
function createEnvEventEmitter(env, context) {
|
|
333
447
|
if (!env || typeof env.pushEnvEvent !== "function") {
|
|
334
|
-
|
|
448
|
+
logger2.warn("[invoke] createEnvEventEmitter: env is null/undefined or pushEnvEvent is unavailable, streaming events will be disabled");
|
|
335
449
|
return null;
|
|
336
450
|
}
|
|
337
451
|
return (event) => {
|
|
@@ -349,7 +463,7 @@ function createEnvEventEmitter(env, context) {
|
|
|
349
463
|
payload: event
|
|
350
464
|
});
|
|
351
465
|
} catch (err) {
|
|
352
|
-
|
|
466
|
+
logger2.warn("Failed to push env event", { error: String(err), eventType: event.type });
|
|
353
467
|
}
|
|
354
468
|
};
|
|
355
469
|
}
|
|
@@ -432,7 +546,7 @@ function processThinkingStream(textDelta, config, state) {
|
|
|
432
546
|
async function invoke(config, options, ctx) {
|
|
433
547
|
try {
|
|
434
548
|
const emitToEnv = createEnvEventEmitter(options.env, options.context);
|
|
435
|
-
|
|
549
|
+
logger2.info("[invoke] Created event emitter", {
|
|
436
550
|
envAvailable: !!options.env,
|
|
437
551
|
hasContext: options.context !== undefined
|
|
438
552
|
});
|
|
@@ -441,7 +555,10 @@ async function invoke(config, options, ctx) {
|
|
|
441
555
|
if (!provider) {
|
|
442
556
|
throw new Error(`Failed to create provider for ${providerId}`);
|
|
443
557
|
}
|
|
444
|
-
const messages = convertToSDKMessages(options.messages
|
|
558
|
+
const messages = convertToSDKMessages(options.messages, {
|
|
559
|
+
sessionId: options.context?.sessionId,
|
|
560
|
+
provider: providerId
|
|
561
|
+
});
|
|
445
562
|
const toolCallIds = new Set;
|
|
446
563
|
const assistantToolCalls = [];
|
|
447
564
|
const toolResultIds = [];
|
|
@@ -468,24 +585,24 @@ async function invoke(config, options, ctx) {
|
|
|
468
585
|
const missingToolResults = assistantToolCalls.filter((tc) => !toolResultIds.includes(tc.id));
|
|
469
586
|
const orphanedToolResults = toolResultIds.filter((id) => !toolCallIds.has(id));
|
|
470
587
|
if (assistantToolCalls.length > 0 || toolResultIds.length > 0) {
|
|
471
|
-
|
|
588
|
+
logger2.debug("[invoke] ToolCallId matching analysis:", {
|
|
472
589
|
assistantToolCalls,
|
|
473
590
|
toolResultIds,
|
|
474
591
|
missingToolResults: missingToolResults.length > 0 ? missingToolResults : "none",
|
|
475
592
|
orphanedToolResults: orphanedToolResults.length > 0 ? orphanedToolResults : "none"
|
|
476
593
|
});
|
|
477
594
|
}
|
|
478
|
-
const tools = options.tools && options.tools.length > 0 ? convertToolsToSDK(options.tools) : undefined;
|
|
595
|
+
const tools = options.tools && options.tools.length > 0 ? convertToolsToSDK(options.tools, providerId) : undefined;
|
|
479
596
|
const providerOptions = generateProviderOptions(providerId, {
|
|
480
597
|
temperature: options.temperature,
|
|
481
598
|
maxTokens: options.maxTokens
|
|
482
599
|
});
|
|
483
600
|
const model = `${providerId}/${modelId}`;
|
|
484
601
|
if (emitToEnv) {
|
|
485
|
-
|
|
602
|
+
logger2.info("[invoke] Emitting llm.start event");
|
|
486
603
|
emitToEnv({ type: "start", metadata: { model } });
|
|
487
604
|
} else {
|
|
488
|
-
|
|
605
|
+
logger2.warn("[invoke] emitToEnv is null, skipping llm.start event");
|
|
489
606
|
}
|
|
490
607
|
const streamTextOptions = {
|
|
491
608
|
model: provider.languageModel(modelId),
|
|
@@ -607,7 +724,7 @@ async function invoke(config, options, ctx) {
|
|
|
607
724
|
`).filter(Boolean);
|
|
608
725
|
const uniqueLines = new Set(outputLines);
|
|
609
726
|
if (outputLines.length !== uniqueLines.size) {
|
|
610
|
-
|
|
727
|
+
logger2.warn("[DEBUG_DUPLICATE] outputContent has duplicate lines", {
|
|
611
728
|
fullContent,
|
|
612
729
|
rawFullContent,
|
|
613
730
|
outputContent,
|
|
@@ -615,7 +732,7 @@ async function invoke(config, options, ctx) {
|
|
|
615
732
|
textDeltas: textDeltaLog
|
|
616
733
|
});
|
|
617
734
|
} else {
|
|
618
|
-
|
|
735
|
+
logger2.info("[DEBUG_DUPLICATE] outputContent OK", {
|
|
619
736
|
charCount: outputContent.length,
|
|
620
737
|
lineCount: outputLines.length,
|
|
621
738
|
uniqueLineCount: uniqueLines.size,
|
|
@@ -650,7 +767,7 @@ async function invoke(config, options, ctx) {
|
|
|
650
767
|
})
|
|
651
768
|
};
|
|
652
769
|
} catch (error) {
|
|
653
|
-
|
|
770
|
+
logger2.error("Error during invocation", {
|
|
654
771
|
error: error instanceof Error ? error.message : String(error),
|
|
655
772
|
stack: error instanceof Error ? error.stack : undefined
|
|
656
773
|
});
|
|
@@ -690,7 +807,7 @@ function createProviderInstance(providerId, apiKey, baseURL) {
|
|
|
690
807
|
});
|
|
691
808
|
return defaultProvider;
|
|
692
809
|
} catch (error) {
|
|
693
|
-
|
|
810
|
+
logger2.error(`Failed to create provider ${providerId}`, { error: String(error) });
|
|
694
811
|
return null;
|
|
695
812
|
}
|
|
696
813
|
}
|
|
@@ -700,8 +817,11 @@ async function invokeNonStream(config, options, ctx) {
|
|
|
700
817
|
if (!provider) {
|
|
701
818
|
throw new Error(`Failed to create provider for ${providerId}`);
|
|
702
819
|
}
|
|
703
|
-
const messages = convertToSDKMessages(options.messages
|
|
704
|
-
|
|
820
|
+
const messages = convertToSDKMessages(options.messages, {
|
|
821
|
+
sessionId: options.context?.sessionId,
|
|
822
|
+
provider: providerId
|
|
823
|
+
});
|
|
824
|
+
const tools = options.tools && options.tools.length > 0 ? convertToolsToSDK(options.tools, providerId) : undefined;
|
|
705
825
|
const providerOptions = generateProviderOptions(providerId, {
|
|
706
826
|
temperature: options.temperature,
|
|
707
827
|
maxTokens: options.maxTokens
|
|
@@ -759,4 +879,4 @@ function createInvokeConfig(model, apiKey, baseURL) {
|
|
|
759
879
|
};
|
|
760
880
|
}
|
|
761
881
|
|
|
762
|
-
export { withTimeout, parseModelString, convertToSDKMessages, invoke, invokeNonStream, createInvokeConfig };
|
|
882
|
+
export { safeParseToolArgs, canonicalizeParts, withTimeout, parseModelString, convertToSDKMessages, invoke, invokeNonStream, createInvokeConfig };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
withTimeout
|
|
3
|
-
} from "./roy-agent-core-167qsqrz.js";
|
|
4
1
|
import {
|
|
5
2
|
truncateOutputInline
|
|
6
3
|
} from "./roy-agent-core-h28gcd77.js";
|
|
@@ -22,10 +19,11 @@ import {
|
|
|
22
19
|
} from "./roy-agent-core-ctdhjv68.js";
|
|
23
20
|
import {
|
|
24
21
|
SessionMessageConverter
|
|
25
|
-
} from "./roy-agent-core-
|
|
22
|
+
} from "./roy-agent-core-zcx8nf4a.js";
|
|
26
23
|
import {
|
|
27
|
-
safeParseToolArgs
|
|
28
|
-
|
|
24
|
+
safeParseToolArgs,
|
|
25
|
+
withTimeout
|
|
26
|
+
} from "./roy-agent-core-2xb3f3ye.js";
|
|
29
27
|
import {
|
|
30
28
|
envKeyToConfigKey
|
|
31
29
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
@@ -810,20 +808,6 @@ class AgentComponent extends BaseComponent {
|
|
|
810
808
|
const workspaceDir = this.env?.getComponent?.("config")?.get?.("workspace_dir") || process.cwd();
|
|
811
809
|
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{workspace_dir}}", String(workspaceDir));
|
|
812
810
|
}
|
|
813
|
-
if (resolvedSystemPrompt.includes("{{memory}}")) {
|
|
814
|
-
try {
|
|
815
|
-
const memoryComponent = this.env?.getComponent?.("memory");
|
|
816
|
-
if (memoryComponent && typeof memoryComponent.recallMemory === "function") {
|
|
817
|
-
const memoryContent = await memoryComponent.recallMemory();
|
|
818
|
-
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", memoryContent || "(No memory)");
|
|
819
|
-
} else {
|
|
820
|
-
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", "(Memory component not available)");
|
|
821
|
-
}
|
|
822
|
-
} catch (err) {
|
|
823
|
-
logger2.warn(`[AgentComponent._run] Failed to replace {{memory}}: ${err}`);
|
|
824
|
-
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", "(Failed to load memory)");
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
811
|
}
|
|
828
812
|
const effectiveContext = {
|
|
829
813
|
...context,
|
|
@@ -846,6 +830,12 @@ class AgentComponent extends BaseComponent {
|
|
|
846
830
|
resolvedSystemPrompt = eventSourceSystemPrompt;
|
|
847
831
|
}
|
|
848
832
|
}
|
|
833
|
+
const { snapshot: cacheSnapshot, systemPromptOverride } = await this._loadOrCreateCacheSnapshot(effectiveContext.sessionId, effectiveContext, resolvedSystemPrompt, agent.config.systemPrompt);
|
|
834
|
+
if (systemPromptOverride !== undefined) {
|
|
835
|
+
resolvedSystemPrompt = systemPromptOverride;
|
|
836
|
+
} else if (resolvedSystemPrompt) {
|
|
837
|
+
resolvedSystemPrompt = await this._fallbackReplaceMemory(resolvedSystemPrompt);
|
|
838
|
+
}
|
|
849
839
|
const hookCtx = {
|
|
850
840
|
agent,
|
|
851
841
|
iteration: 0,
|
|
@@ -853,7 +843,8 @@ class AgentComponent extends BaseComponent {
|
|
|
853
843
|
messages: [],
|
|
854
844
|
tools: this.getAvailableTools(agent, effectiveContext),
|
|
855
845
|
systemPrompt: resolvedSystemPrompt ?? agent.config.systemPrompt ?? "You are a helpful assistant.",
|
|
856
|
-
context: effectiveContext
|
|
846
|
+
context: effectiveContext,
|
|
847
|
+
...cacheSnapshot ? { _cacheSnapshot: cacheSnapshot } : {}
|
|
857
848
|
};
|
|
858
849
|
let historyMessageCount = 0;
|
|
859
850
|
if (effectiveContext.messages && effectiveContext.messages.length > 0) {
|
|
@@ -1328,7 +1319,80 @@ class AgentComponent extends BaseComponent {
|
|
|
1328
1319
|
}
|
|
1329
1320
|
logger2.info(`All agents aborted (${this.abortControllers.size} runs)`);
|
|
1330
1321
|
}
|
|
1322
|
+
async _loadOrCreateCacheSnapshot(sessionId, effectiveContext, initialSystemPrompt, agentConfigSystemPrompt) {
|
|
1323
|
+
if (!sessionId) {
|
|
1324
|
+
return { snapshot: null, systemPromptOverride: undefined };
|
|
1325
|
+
}
|
|
1326
|
+
try {
|
|
1327
|
+
const sessionComponent = this.env?.getComponent?.("session");
|
|
1328
|
+
if (!sessionComponent) {
|
|
1329
|
+
return { snapshot: null, systemPromptOverride: undefined };
|
|
1330
|
+
}
|
|
1331
|
+
const session = await sessionComponent.get(sessionId);
|
|
1332
|
+
const existingSnapshot = session?.metadata?.cacheSnapshot;
|
|
1333
|
+
if (existingSnapshot && typeof existingSnapshot === "object" && existingSnapshot.systemPrompt) {
|
|
1334
|
+
logger2.debug(`[AgentComponent._run] Reusing cacheSnapshot for session ${sessionId} (snapshotAt=${existingSnapshot.snapshotAt})`);
|
|
1335
|
+
return {
|
|
1336
|
+
snapshot: existingSnapshot,
|
|
1337
|
+
systemPromptOverride: existingSnapshot.systemPrompt
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
let resolvedSystemPrompt = initialSystemPrompt;
|
|
1341
|
+
if (resolvedSystemPrompt && resolvedSystemPrompt.includes("{{memory}}")) {
|
|
1342
|
+
try {
|
|
1343
|
+
const memoryComponent = this.env?.getComponent?.("memory");
|
|
1344
|
+
if (memoryComponent && typeof memoryComponent.recallMemory === "function") {
|
|
1345
|
+
const memoryContent = await memoryComponent.recallMemory();
|
|
1346
|
+
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", memoryContent || "(No memory)");
|
|
1347
|
+
} else {
|
|
1348
|
+
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", "(Memory component not available)");
|
|
1349
|
+
}
|
|
1350
|
+
} catch (err) {
|
|
1351
|
+
logger2.warn(`[AgentComponent._run] Failed to replace {{memory}}: ${err}`);
|
|
1352
|
+
resolvedSystemPrompt = resolvedSystemPrompt.replaceAll("{{memory}}", "(Failed to load memory)");
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
const snapshot = {
|
|
1356
|
+
systemPrompt: resolvedSystemPrompt ?? agentConfigSystemPrompt ?? "",
|
|
1357
|
+
additionInfo: effectiveContext.additionInfo || "",
|
|
1358
|
+
snapshotAt: Date.now()
|
|
1359
|
+
};
|
|
1360
|
+
try {
|
|
1361
|
+
await sessionComponent.update(sessionId, {
|
|
1362
|
+
metadata: {
|
|
1363
|
+
...session?.metadata ?? {},
|
|
1364
|
+
cacheSnapshot: snapshot
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
logger2.debug(`[AgentComponent._run] Created cacheSnapshot for session ${sessionId} (snapshotAt=${snapshot.snapshotAt})`);
|
|
1368
|
+
} catch (updateErr) {
|
|
1369
|
+
logger2.warn(`[AgentComponent._run] Failed to persist cacheSnapshot for session ${sessionId}: ${updateErr}`);
|
|
1370
|
+
}
|
|
1371
|
+
return { snapshot, systemPromptOverride: resolvedSystemPrompt };
|
|
1372
|
+
} catch (err) {
|
|
1373
|
+
logger2.warn(`[AgentComponent._run] Failed to load cacheSnapshot: ${err}`);
|
|
1374
|
+
return { snapshot: null, systemPromptOverride: undefined };
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
async _fallbackReplaceMemory(systemPrompt) {
|
|
1378
|
+
if (!systemPrompt.includes("{{memory}}"))
|
|
1379
|
+
return systemPrompt;
|
|
1380
|
+
try {
|
|
1381
|
+
const memoryComponent = this.env?.getComponent?.("memory");
|
|
1382
|
+
if (memoryComponent && typeof memoryComponent.recallMemory === "function") {
|
|
1383
|
+
const memoryContent = await memoryComponent.recallMemory();
|
|
1384
|
+
return systemPrompt.replaceAll("{{memory}}", memoryContent || "(No memory)");
|
|
1385
|
+
}
|
|
1386
|
+
return systemPrompt.replaceAll("{{memory}}", "(Memory component not available)");
|
|
1387
|
+
} catch (err) {
|
|
1388
|
+
logger2.warn(`[AgentComponent._run] Failed to replace {{memory}}: ${err}`);
|
|
1389
|
+
return systemPrompt.replaceAll("{{memory}}", "(Failed to load memory)");
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1331
1392
|
async _buildAdditionInfo(ctx) {
|
|
1393
|
+
if (ctx._cacheSnapshot) {
|
|
1394
|
+
return ctx._cacheSnapshot.additionInfo;
|
|
1395
|
+
}
|
|
1332
1396
|
let additionInfo = ctx.context?.additionInfo || "";
|
|
1333
1397
|
return additionInfo;
|
|
1334
1398
|
}
|
|
@@ -1336,21 +1400,28 @@ class AgentComponent extends BaseComponent {
|
|
|
1336
1400
|
const messages = [];
|
|
1337
1401
|
const additionInfo = await this._buildAdditionInfo(ctx);
|
|
1338
1402
|
if (ctx.systemPrompt) {
|
|
1403
|
+
messages.push(...buildMultiBlockSystem({
|
|
1404
|
+
characterSheet: ctx.systemPrompt,
|
|
1405
|
+
toolDefinitions: undefined,
|
|
1406
|
+
memoryBlock: undefined,
|
|
1407
|
+
dynamicContext: additionInfo
|
|
1408
|
+
}));
|
|
1409
|
+
} else if (additionInfo) {
|
|
1339
1410
|
messages.push({
|
|
1340
1411
|
role: "system",
|
|
1341
|
-
content:
|
|
1342
|
-
|
|
1343
|
-
${additionInfo}`
|
|
1344
|
-
});
|
|
1345
|
-
} else {
|
|
1346
|
-
messages.push({
|
|
1347
|
-
role: "system",
|
|
1348
|
-
content: `${additionInfo}`
|
|
1412
|
+
content: additionInfo
|
|
1349
1413
|
});
|
|
1350
1414
|
}
|
|
1351
1415
|
messages.push(...ctx.messages);
|
|
1352
1416
|
return messages;
|
|
1353
1417
|
}
|
|
1418
|
+
_formatToolDefinitions(tools) {
|
|
1419
|
+
if (!tools || tools.length === 0)
|
|
1420
|
+
return "";
|
|
1421
|
+
const sorted = [...tools].sort((a, b) => a.name.localeCompare(b.name));
|
|
1422
|
+
return sorted.map((t) => `${t.name}: ${t.description || ""}`).join(`
|
|
1423
|
+
`);
|
|
1424
|
+
}
|
|
1354
1425
|
async invokeLLM(ctx) {
|
|
1355
1426
|
logger2.debug("[invokeLLM] Starting LLM invocation");
|
|
1356
1427
|
if (this.llmComponent?.invoke) {
|
|
@@ -1693,6 +1764,9 @@ __legacyDecorateClassTS([
|
|
|
1693
1764
|
__legacyDecorateClassTS([
|
|
1694
1765
|
TracedAs("agent.component.run", { recordParams: true, recordResult: true, log: true })
|
|
1695
1766
|
], AgentComponent.prototype, "_run", null);
|
|
1767
|
+
__legacyDecorateClassTS([
|
|
1768
|
+
TracedAs("agent.component.loadOrCreateCacheSnapshot", { recordParams: true, recordResult: true, log: true })
|
|
1769
|
+
], AgentComponent.prototype, "_loadOrCreateCacheSnapshot", null);
|
|
1696
1770
|
__legacyDecorateClassTS([
|
|
1697
1771
|
TracedAs("agent.component.buildAdditionInfo", { recordParams: true, recordResult: true, log: true })
|
|
1698
1772
|
], AgentComponent.prototype, "_buildAdditionInfo", null);
|
|
@@ -1730,6 +1804,39 @@ __legacyDecorateClassTS([
|
|
|
1730
1804
|
__legacyDecorateClassTS([
|
|
1731
1805
|
TracedAs("agent.component.getConversationHistory", { recordParams: true, recordResult: true, log: true })
|
|
1732
1806
|
], AgentComponent.prototype, "getConversationHistory", null);
|
|
1807
|
+
function buildMultiBlockSystem(ctx) {
|
|
1808
|
+
const ANTHROPIC_CACHE_CONTROL = {
|
|
1809
|
+
anthropic: { cacheControl: { type: "ephemeral" } }
|
|
1810
|
+
};
|
|
1811
|
+
const messages = [];
|
|
1812
|
+
if (ctx.characterSheet) {
|
|
1813
|
+
messages.push({
|
|
1814
|
+
role: "system",
|
|
1815
|
+
content: ctx.characterSheet,
|
|
1816
|
+
providerOptions: ANTHROPIC_CACHE_CONTROL
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
if (ctx.toolDefinitions) {
|
|
1820
|
+
messages.push({
|
|
1821
|
+
role: "system",
|
|
1822
|
+
content: ctx.toolDefinitions,
|
|
1823
|
+
providerOptions: ANTHROPIC_CACHE_CONTROL
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
if (ctx.memoryBlock) {
|
|
1827
|
+
messages.push({
|
|
1828
|
+
role: "system",
|
|
1829
|
+
content: ctx.memoryBlock
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
if (ctx.dynamicContext) {
|
|
1833
|
+
messages.push({
|
|
1834
|
+
role: "system",
|
|
1835
|
+
content: ctx.dynamicContext
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
return messages;
|
|
1839
|
+
}
|
|
1733
1840
|
// src/env/agent/summary-agent.ts
|
|
1734
1841
|
class SummaryAgent {
|
|
1735
1842
|
llmComponent;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EnvSource
|
|
3
3
|
} from "./roy-agent-core-y3g3ar7a.js";
|
|
4
|
-
import {
|
|
5
|
-
invoke,
|
|
6
|
-
invokeNonStream
|
|
7
|
-
} from "./roy-agent-core-167qsqrz.js";
|
|
8
4
|
import {
|
|
9
5
|
ContextError,
|
|
10
6
|
ErrorCodes
|
|
11
7
|
} from "./roy-agent-core-ctdhjv68.js";
|
|
8
|
+
import {
|
|
9
|
+
invoke,
|
|
10
|
+
invokeNonStream
|
|
11
|
+
} from "./roy-agent-core-2xb3f3ye.js";
|
|
12
12
|
import {
|
|
13
13
|
envKeyToConfigKey,
|
|
14
14
|
toEnvKey
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SessionMessageConverter
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-zcx8nf4a.js";
|
|
4
|
+
import {
|
|
5
|
+
canonicalizeParts
|
|
6
|
+
} from "./roy-agent-core-2xb3f3ye.js";
|
|
4
7
|
import {
|
|
5
8
|
createLogger,
|
|
6
9
|
init_logger
|
|
@@ -796,7 +799,7 @@ class SQLiteSessionStore extends BaseSessionStore {
|
|
|
796
799
|
INSERT INTO message (id, session_id, role, content, timestamp, parts, metadata)
|
|
797
800
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
798
801
|
`);
|
|
799
|
-
stmt.run(msg.id, msg.sessionID, msg.role, msg.content, msg.timestamp, msg.parts ?
|
|
802
|
+
stmt.run(msg.id, msg.sessionID, msg.role, msg.content, msg.timestamp, msg.parts ? canonicalizeParts(msg.parts) : null, msg.metadata ? JSON.stringify(msg.metadata) : null);
|
|
800
803
|
const countResult = this.db.prepare("SELECT COUNT(*) as count FROM message WHERE session_id = ? AND is_archived = 0").get(sessionId);
|
|
801
804
|
session.messageCount = countResult?.count || 0;
|
|
802
805
|
session.updatedAt = now;
|
|
@@ -856,7 +859,7 @@ class SQLiteSessionStore extends BaseSessionStore {
|
|
|
856
859
|
for (const message of messages) {
|
|
857
860
|
const id = generateMessageId2();
|
|
858
861
|
ids.push(id);
|
|
859
|
-
insertStmt.run(id, sessionId, message.role, message.content, now, message.parts ?
|
|
862
|
+
insertStmt.run(id, sessionId, message.role, message.content, now, message.parts ? canonicalizeParts(message.parts) : null, message.metadata ? JSON.stringify(message.metadata) : null);
|
|
860
863
|
}
|
|
861
864
|
const countResult = this.db.prepare("SELECT COUNT(*) as count FROM message WHERE session_id = ? AND is_archived = 0").get(sessionId);
|
|
862
865
|
const newCount = countResult?.count ?? 0;
|
|
@@ -911,7 +914,7 @@ class SQLiteSessionStore extends BaseSessionStore {
|
|
|
911
914
|
}
|
|
912
915
|
if (updates.parts !== undefined) {
|
|
913
916
|
sets.push("parts = ?");
|
|
914
|
-
values.push(
|
|
917
|
+
values.push(canonicalizeParts(updates.parts));
|
|
915
918
|
}
|
|
916
919
|
if (updates.metadata !== undefined) {
|
|
917
920
|
sets.push("metadata = ?");
|
package/package.json
CHANGED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createLogger,
|
|
3
|
-
init_logger
|
|
4
|
-
} from "./roy-agent-core-kaq037np.js";
|
|
5
|
-
|
|
6
|
-
// src/env/llm/tool-args-parser.ts
|
|
7
|
-
init_logger();
|
|
8
|
-
var logger = createLogger("llm:tool-args-parser");
|
|
9
|
-
var MAX_SAFE_DEPTH = 5;
|
|
10
|
-
function safeParseToolArgs(args, depth = 0) {
|
|
11
|
-
if (depth >= MAX_SAFE_DEPTH) {
|
|
12
|
-
logger.warn(`[safeParseToolArgs] Max recursion depth (${MAX_SAFE_DEPTH}) exceeded at depth ${depth}. ` + "Input may be malicious or abnormally deeply nested. Returning empty object.", { depth, argsType: typeof args });
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
if (typeof args === "object" && args !== null && !Array.isArray(args)) {
|
|
16
|
-
return args;
|
|
17
|
-
}
|
|
18
|
-
if (Array.isArray(args)) {
|
|
19
|
-
logger.debug(`[safeParseToolArgs] Input is an array. Tool arguments should be objects. Returning empty object.`, { depth, arrayLength: args.length });
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
if (typeof args === "string") {
|
|
23
|
-
try {
|
|
24
|
-
const parsed = JSON.parse(args);
|
|
25
|
-
if (typeof parsed === "string") {
|
|
26
|
-
logger.debug(`[safeParseToolArgs] Detected double/multi-stringified JSON at depth ${depth}. ` + "LLM may be double-stringifying tool arguments. Parsing recursively.", { depth, parsedLength: parsed.length });
|
|
27
|
-
return safeParseToolArgs(parsed, depth + 1);
|
|
28
|
-
}
|
|
29
|
-
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
30
|
-
return parsed;
|
|
31
|
-
}
|
|
32
|
-
if (Array.isArray(parsed)) {
|
|
33
|
-
logger.debug(`[safeParseToolArgs] Parsed result is an array at depth ${depth}. ` + "Tool arguments should be objects, not arrays. Returning empty object.", { depth, parsedLength: parsed.length });
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
return { value: parsed };
|
|
37
|
-
} catch (e) {
|
|
38
|
-
logger.warn(`[safeParseToolArgs] JSON.parse failed at depth ${depth}`, {
|
|
39
|
-
parse_failed: true,
|
|
40
|
-
input_length: args.length,
|
|
41
|
-
depth,
|
|
42
|
-
error: e.message
|
|
43
|
-
});
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export { safeParseToolArgs };
|