@ai-setting/roy-agent-core 1.5.88 → 1.5.90
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 +8 -8
- package/dist/env/event-source/index.js +12 -4
- package/dist/env/index.js +20 -15
- package/dist/env/llm/index.js +4 -2
- package/dist/env/prompt/index.js +2 -1
- package/dist/env/session/index.js +3 -4
- package/dist/env/session/storage/index.js +2 -2
- package/dist/env/task/delegate/index.js +3 -2
- package/dist/env/task/index.js +4 -3
- package/dist/env/task/plugins/index.js +7 -4
- package/dist/env/tool/built-in/index.js +2 -1
- package/dist/env/tool/index.js +11 -8
- package/dist/env/workflow/engine/index.js +5 -3
- package/dist/env/workflow/index.js +6 -4
- package/dist/env/workflow/nodes/index.js +1 -1
- package/dist/env/workflow/tools/index.js +7 -1
- package/dist/env/workflow/utils/index.js +5 -0
- package/dist/index.js +144 -32
- package/dist/shared/@ai-setting/{roy-agent-core-r0m0at3x.js → roy-agent-core-0r4ndyn9.js} +119 -7
- package/dist/shared/@ai-setting/{roy-agent-core-jymz9fzp.js → roy-agent-core-2c8eraxq.js} +126 -41
- package/dist/shared/@ai-setting/{roy-agent-core-0y64qaac.js → roy-agent-core-32m0nb9j.js} +119 -30
- package/dist/shared/@ai-setting/roy-agent-core-4yq23m5g.js +421 -0
- package/dist/shared/@ai-setting/{roy-agent-core-h2d1s8yd.js → roy-agent-core-5ykms33a.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-mmkyydw7.js → roy-agent-core-83d035pp.js} +91 -579
- package/dist/shared/@ai-setting/roy-agent-core-8wd3qwx5.js +35 -0
- package/dist/shared/@ai-setting/{roy-agent-core-yx0vw1aw.js → roy-agent-core-8zjntsbb.js} +102 -32
- package/dist/shared/@ai-setting/{roy-agent-core-29fh9mxg.js → roy-agent-core-bwjpte58.js} +1 -2
- package/dist/shared/@ai-setting/{roy-agent-core-vneyghpg.js → roy-agent-core-ddq5hcp5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qhhxx2x2.js → roy-agent-core-ds5f75pg.js} +2 -1
- package/dist/shared/@ai-setting/{roy-agent-core-4cdtdxqx.js → roy-agent-core-ewr1nw7t.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-hvdfgvfz.js +114 -0
- package/dist/shared/@ai-setting/{roy-agent-core-3arrpf7n.js → roy-agent-core-hxsbegfc.js} +229 -9
- package/dist/shared/@ai-setting/{roy-agent-core-9y09xfav.js → roy-agent-core-j0107ww1.js} +6 -418
- package/dist/shared/@ai-setting/{roy-agent-core-6mk0m4t3.js → roy-agent-core-m683wd1n.js} +283 -15
- package/dist/shared/@ai-setting/{roy-agent-core-bgw4dq11.js → roy-agent-core-mw4ty0ba.js} +44 -5
- package/dist/shared/@ai-setting/{roy-agent-core-7z4xtrmw.js → roy-agent-core-nqzt9ne4.js} +53 -0
- package/dist/shared/@ai-setting/roy-agent-core-pt7as39r.js +0 -0
- package/dist/shared/@ai-setting/{roy-agent-core-6n7xwv4v.js → roy-agent-core-rkz8r2sx.js} +5 -3
- package/dist/shared/@ai-setting/{roy-agent-core-c1j7ev4e.js → roy-agent-core-txwf64pd.js} +70 -0
- package/dist/shared/@ai-setting/{roy-agent-core-7fdzfsm6.js → roy-agent-core-w0kb72ve.js} +42 -213
- package/dist/shared/@ai-setting/roy-agent-core-w6bmrgap.js +581 -0
- package/dist/shared/@ai-setting/{roy-agent-core-qhjb153z.js → roy-agent-core-xnxyzaw4.js} +27 -4
- package/dist/shared/@ai-setting/roy-agent-core-yanpq5gb.js +116 -0
- package/dist/shared/@ai-setting/{roy-agent-core-hc20420t.js → roy-agent-core-z240ts1r.js} +27 -3
- package/dist/shared/@ai-setting/{roy-agent-core-q7sqeax6.js → roy-agent-core-zky9jse4.js} +163 -3
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-x3gtyqax.js +0 -378
- /package/dist/shared/@ai-setting/{roy-agent-core-4f3976cd.js → roy-agent-core-k5hxvaf0.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PromptComponent,
|
|
3
|
-
PromptStore
|
|
4
|
-
|
|
5
|
-
getBuiltInPromptNames
|
|
6
|
-
} from "./shared/@ai-setting/roy-agent-core-mmkyydw7.js";
|
|
3
|
+
PromptStore
|
|
4
|
+
} from "./shared/@ai-setting/roy-agent-core-w6bmrgap.js";
|
|
7
5
|
import {
|
|
8
6
|
LLMComponent,
|
|
9
7
|
LLMConfigSchema,
|
|
@@ -11,18 +9,14 @@ import {
|
|
|
11
9
|
ModelLimitsSchema,
|
|
12
10
|
ProviderCapabilitiesSchema,
|
|
13
11
|
ProviderConfigSchema
|
|
14
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
12
|
+
} from "./shared/@ai-setting/roy-agent-core-5ykms33a.js";
|
|
15
13
|
import {
|
|
16
14
|
ConfigComponent
|
|
17
15
|
} from "./shared/@ai-setting/roy-agent-core-prdngx28.js";
|
|
18
16
|
import {
|
|
19
17
|
CommandsComponent
|
|
20
18
|
} from "./shared/@ai-setting/roy-agent-core-3952rkj0.js";
|
|
21
|
-
import
|
|
22
|
-
ToolComponent,
|
|
23
|
-
ToolRegistry,
|
|
24
|
-
ToolValidator
|
|
25
|
-
} from "./shared/@ai-setting/roy-agent-core-3arrpf7n.js";
|
|
19
|
+
import"./shared/@ai-setting/roy-agent-core-pt7as39r.js";
|
|
26
20
|
import {
|
|
27
21
|
bashTool,
|
|
28
22
|
editFileTool,
|
|
@@ -32,12 +26,12 @@ import {
|
|
|
32
26
|
grepTool,
|
|
33
27
|
readFileTool,
|
|
34
28
|
writeFileTool
|
|
35
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
29
|
+
} from "./shared/@ai-setting/roy-agent-core-xnxyzaw4.js";
|
|
36
30
|
import {
|
|
37
31
|
closeDatabase
|
|
38
32
|
} from "./shared/@ai-setting/roy-agent-core-h4h55x4h.js";
|
|
39
33
|
import"./shared/@ai-setting/roy-agent-core-3sv590cv.js";
|
|
40
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
34
|
+
import"./shared/@ai-setting/roy-agent-core-k5hxvaf0.js";
|
|
41
35
|
import {
|
|
42
36
|
MemoryComponent
|
|
43
37
|
} from "./shared/@ai-setting/roy-agent-core-2h38rvyj.js";
|
|
@@ -58,15 +52,17 @@ import {
|
|
|
58
52
|
BaseEnvironment,
|
|
59
53
|
generateDescendingId,
|
|
60
54
|
generateId
|
|
61
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
55
|
+
} from "./shared/@ai-setting/roy-agent-core-bwjpte58.js";
|
|
62
56
|
import {
|
|
57
|
+
BountyIMInstance,
|
|
63
58
|
EventSourceComponent,
|
|
64
59
|
TimerInstance,
|
|
60
|
+
bountyIMHandler,
|
|
65
61
|
builtInHandlers,
|
|
66
62
|
getBuiltInHandler,
|
|
67
63
|
larkCliHandler,
|
|
68
64
|
timerHandler
|
|
69
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
65
|
+
} from "./shared/@ai-setting/roy-agent-core-m683wd1n.js";
|
|
70
66
|
import {
|
|
71
67
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
72
68
|
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
@@ -75,7 +71,7 @@ import {
|
|
|
75
71
|
isBuiltInEventSourceType,
|
|
76
72
|
isValidEventSourceType,
|
|
77
73
|
validateEventSourceConfig
|
|
78
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
74
|
+
} from "./shared/@ai-setting/roy-agent-core-ds5f75pg.js";
|
|
79
75
|
import {
|
|
80
76
|
LogTraceComponent,
|
|
81
77
|
LogTraceConfigSchema
|
|
@@ -84,30 +80,35 @@ import {
|
|
|
84
80
|
PluginComponent
|
|
85
81
|
} from "./shared/@ai-setting/roy-agent-core-t1ef8hf2.js";
|
|
86
82
|
import {
|
|
87
|
-
TaskTagPlugin
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
TaskTagPlugin
|
|
84
|
+
} from "./shared/@ai-setting/roy-agent-core-w0kb72ve.js";
|
|
85
|
+
import {
|
|
86
|
+
getBuiltInPrompt,
|
|
87
|
+
getBuiltInPromptNames
|
|
88
|
+
} from "./shared/@ai-setting/roy-agent-core-83d035pp.js";
|
|
90
89
|
import {
|
|
91
90
|
BasePlugin
|
|
92
91
|
} from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
|
|
93
92
|
import {
|
|
94
93
|
WorkflowComponent
|
|
95
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
94
|
+
} from "./shared/@ai-setting/roy-agent-core-rkz8r2sx.js";
|
|
96
95
|
import {
|
|
97
96
|
init_node_registry_helper,
|
|
98
97
|
registerDecoratorNodeType
|
|
99
98
|
} from "./shared/@ai-setting/roy-agent-core-fjexv5nm.js";
|
|
100
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
99
|
+
import"./shared/@ai-setting/roy-agent-core-j0107ww1.js";
|
|
101
100
|
import"./shared/@ai-setting/roy-agent-core-5kdw0p98.js";
|
|
102
101
|
import"./shared/@ai-setting/roy-agent-core-6atd905e.js";
|
|
103
102
|
import"./shared/@ai-setting/roy-agent-core-gb9gbkc3.js";
|
|
104
103
|
import"./shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
|
|
105
104
|
import"./shared/@ai-setting/roy-agent-core-hhrg314p.js";
|
|
106
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
105
|
+
import"./shared/@ai-setting/roy-agent-core-z240ts1r.js";
|
|
107
106
|
import"./shared/@ai-setting/roy-agent-core-qnrf2aw6.js";
|
|
108
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
107
|
+
import"./shared/@ai-setting/roy-agent-core-32m0nb9j.js";
|
|
109
108
|
import"./shared/@ai-setting/roy-agent-core-1db4vpc6.js";
|
|
110
109
|
import"./shared/@ai-setting/roy-agent-core-tq9528d3.js";
|
|
110
|
+
import"./shared/@ai-setting/roy-agent-core-8wd3qwx5.js";
|
|
111
|
+
import"./shared/@ai-setting/roy-agent-core-4yq23m5g.js";
|
|
111
112
|
import {
|
|
112
113
|
Edge,
|
|
113
114
|
NodeAs,
|
|
@@ -119,29 +120,38 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
|
|
|
119
120
|
import {
|
|
120
121
|
AgentComponent,
|
|
121
122
|
AgentComponentConfigSchema
|
|
122
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
123
|
+
} from "./shared/@ai-setting/roy-agent-core-8zjntsbb.js";
|
|
123
124
|
import {
|
|
124
125
|
createInvokeConfig,
|
|
125
126
|
invoke,
|
|
126
127
|
invokeNonStream,
|
|
127
128
|
parseModelString
|
|
128
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
129
|
+
} from "./shared/@ai-setting/roy-agent-core-0r4ndyn9.js";
|
|
130
|
+
import {
|
|
131
|
+
ToolComponent,
|
|
132
|
+
ToolRegistry,
|
|
133
|
+
ToolValidator
|
|
134
|
+
} from "./shared/@ai-setting/roy-agent-core-hxsbegfc.js";
|
|
135
|
+
import {
|
|
136
|
+
createAutoTaskPlugin
|
|
137
|
+
} from "./shared/@ai-setting/roy-agent-core-yanpq5gb.js";
|
|
129
138
|
import {
|
|
130
139
|
AskUserError,
|
|
131
140
|
init_workflow_hil
|
|
132
141
|
} from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
|
|
133
142
|
import {
|
|
134
143
|
TaskComponent
|
|
135
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
144
|
+
} from "./shared/@ai-setting/roy-agent-core-ewr1nw7t.js";
|
|
136
145
|
import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
|
|
137
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
146
|
+
import"./shared/@ai-setting/roy-agent-core-mw4ty0ba.js";
|
|
147
|
+
import"./shared/@ai-setting/roy-agent-core-hvdfgvfz.js";
|
|
138
148
|
import {
|
|
139
149
|
SQLiteTaskStore,
|
|
140
150
|
getDefaultTaskDbPath
|
|
141
151
|
} from "./shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
|
|
142
152
|
import {
|
|
143
153
|
AgentRegistry
|
|
144
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
154
|
+
} from "./shared/@ai-setting/roy-agent-core-nqzt9ne4.js";
|
|
145
155
|
import {
|
|
146
156
|
XDG_PATHS,
|
|
147
157
|
getXDGPath,
|
|
@@ -174,13 +184,12 @@ import"./shared/@ai-setting/roy-agent-core-fnv3ev18.js";
|
|
|
174
184
|
import"./shared/@ai-setting/roy-agent-core-djtkntar.js";
|
|
175
185
|
import {
|
|
176
186
|
SessionComponent
|
|
177
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
187
|
+
} from "./shared/@ai-setting/roy-agent-core-2c8eraxq.js";
|
|
178
188
|
import"./shared/@ai-setting/roy-agent-core-rvxg1wps.js";
|
|
179
189
|
import {
|
|
180
190
|
MemorySessionStore
|
|
181
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
182
|
-
import"./shared/@ai-setting/roy-agent-core-
|
|
183
|
-
import"./shared/@ai-setting/roy-agent-core-c1j7ev4e.js";
|
|
191
|
+
} from "./shared/@ai-setting/roy-agent-core-zky9jse4.js";
|
|
192
|
+
import"./shared/@ai-setting/roy-agent-core-txwf64pd.js";
|
|
184
193
|
import"./shared/@ai-setting/roy-agent-core-ce10b0ez.js";
|
|
185
194
|
import"./shared/@ai-setting/roy-agent-core-qxhq8ven.js";
|
|
186
195
|
import {
|
|
@@ -224,6 +233,103 @@ import {
|
|
|
224
233
|
SQLiteSpanStorage
|
|
225
234
|
} from "./shared/@ai-setting/roy-agent-core-c6592r3c.js";
|
|
226
235
|
import"./shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
|
|
236
|
+
// src/utils/media.ts
|
|
237
|
+
import * as fs from "node:fs/promises";
|
|
238
|
+
import * as path from "node:path";
|
|
239
|
+
var ATTACH_FILE_MAX_BYTES = 10 * 1024 * 1024;
|
|
240
|
+
function startsWith(buf, sig) {
|
|
241
|
+
if (buf.length < sig.length)
|
|
242
|
+
return false;
|
|
243
|
+
for (let i = 0;i < sig.length; i++) {
|
|
244
|
+
if (buf[i] !== sig[i])
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
function sniffMimeType(buffer, fallbackName) {
|
|
250
|
+
if (startsWith(buffer, [137, 80, 78, 71, 13, 10, 26, 10])) {
|
|
251
|
+
return "image/png";
|
|
252
|
+
}
|
|
253
|
+
if (startsWith(buffer, [255, 216, 255])) {
|
|
254
|
+
return "image/jpeg";
|
|
255
|
+
}
|
|
256
|
+
if (startsWith(buffer, [71, 73, 70, 56])) {
|
|
257
|
+
return "image/gif";
|
|
258
|
+
}
|
|
259
|
+
if (startsWith(buffer, [66, 77])) {
|
|
260
|
+
return "image/bmp";
|
|
261
|
+
}
|
|
262
|
+
if (startsWith(buffer, [37, 80, 68, 70, 45])) {
|
|
263
|
+
return "application/pdf";
|
|
264
|
+
}
|
|
265
|
+
if (startsWith(buffer, [82, 73, 70, 70]) && startsWith(buffer.subarray(8), [87, 69, 66, 80])) {
|
|
266
|
+
return "image/webp";
|
|
267
|
+
}
|
|
268
|
+
if (fallbackName) {
|
|
269
|
+
const ext = path.extname(fallbackName).toLowerCase();
|
|
270
|
+
const extMap = {
|
|
271
|
+
".png": "image/png",
|
|
272
|
+
".jpg": "image/jpeg",
|
|
273
|
+
".jpeg": "image/jpeg",
|
|
274
|
+
".gif": "image/gif",
|
|
275
|
+
".webp": "image/webp",
|
|
276
|
+
".bmp": "image/bmp",
|
|
277
|
+
".pdf": "application/pdf",
|
|
278
|
+
".mp3": "audio/mpeg",
|
|
279
|
+
".wav": "audio/wav",
|
|
280
|
+
".ogg": "audio/ogg",
|
|
281
|
+
".m4a": "audio/mp4",
|
|
282
|
+
".mp4": "video/mp4",
|
|
283
|
+
".mov": "video/quicktime",
|
|
284
|
+
".webm": "video/webm"
|
|
285
|
+
};
|
|
286
|
+
const mapped = extMap[ext];
|
|
287
|
+
if (mapped)
|
|
288
|
+
return mapped;
|
|
289
|
+
}
|
|
290
|
+
return "application/octet-stream";
|
|
291
|
+
}
|
|
292
|
+
function isMediaType(mime) {
|
|
293
|
+
if (typeof mime !== "string")
|
|
294
|
+
return false;
|
|
295
|
+
const m = mime.toLowerCase();
|
|
296
|
+
return m.startsWith("image/") || m.startsWith("audio/") || m.startsWith("video/") || m === "application/pdf";
|
|
297
|
+
}
|
|
298
|
+
var HTTP_URL_RE = /^https?:\/\//i;
|
|
299
|
+
var DATA_URL_RE = /^data:([^;,]+)(;base64)?,(.*)$/s;
|
|
300
|
+
async function parseImageInput(input) {
|
|
301
|
+
if (!input || typeof input !== "string" || input.trim().length === 0) {
|
|
302
|
+
throw new Error("parseImageInput: input is empty");
|
|
303
|
+
}
|
|
304
|
+
const trimmed = input.trim();
|
|
305
|
+
if (HTTP_URL_RE.test(trimmed)) {
|
|
306
|
+
return { type: "image", image: trimmed };
|
|
307
|
+
}
|
|
308
|
+
if (DATA_URL_RE.test(trimmed)) {
|
|
309
|
+
return { type: "image", image: trimmed };
|
|
310
|
+
}
|
|
311
|
+
return await parseLocalImagePath(trimmed);
|
|
312
|
+
}
|
|
313
|
+
async function parseLocalImagePath(filePath) {
|
|
314
|
+
let stat2;
|
|
315
|
+
try {
|
|
316
|
+
stat2 = await fs.stat(filePath);
|
|
317
|
+
} catch (err) {
|
|
318
|
+
throw new Error(`parseImageInput: cannot stat file '${filePath}': ${err.message}`);
|
|
319
|
+
}
|
|
320
|
+
if (!stat2.isFile()) {
|
|
321
|
+
throw new Error(`parseImageInput: not a regular file: ${filePath}`);
|
|
322
|
+
}
|
|
323
|
+
if (stat2.size > ATTACH_FILE_MAX_BYTES) {
|
|
324
|
+
throw new Error(`parseImageInput: file '${filePath}' exceeds 10 MiB limit ` + `(${stat2.size} bytes > ${ATTACH_FILE_MAX_BYTES} bytes)`);
|
|
325
|
+
}
|
|
326
|
+
const buffer = await fs.readFile(filePath);
|
|
327
|
+
const mime = sniffMimeType(buffer, filePath);
|
|
328
|
+
if (!mime.startsWith("image/")) {
|
|
329
|
+
throw new Error(`parseImageInput: file '${filePath}' is not an image (detected ${mime}). ` + `Use ContentPart type 'file' for non-image attachments.`);
|
|
330
|
+
}
|
|
331
|
+
return { type: "image", image: buffer };
|
|
332
|
+
}
|
|
227
333
|
// src/env/memory/tools/memory-agent-tools.ts
|
|
228
334
|
import { z } from "zod";
|
|
229
335
|
var SearchSessionsSchema = z.object({
|
|
@@ -349,6 +455,7 @@ export {
|
|
|
349
455
|
wrapFunction,
|
|
350
456
|
validateEventSourceConfig,
|
|
351
457
|
timerHandler,
|
|
458
|
+
sniffMimeType,
|
|
352
459
|
setQuietMode,
|
|
353
460
|
setConfigComponent as setLoggerConfigComponent,
|
|
354
461
|
setLogDirOverride,
|
|
@@ -357,10 +464,12 @@ export {
|
|
|
357
464
|
readFileTool,
|
|
358
465
|
propagation,
|
|
359
466
|
parseModelString,
|
|
467
|
+
parseImageInput,
|
|
360
468
|
larkCliHandler,
|
|
361
469
|
isValidEventSourceType,
|
|
362
470
|
isRoyError,
|
|
363
471
|
isQuietMode,
|
|
472
|
+
isMediaType,
|
|
364
473
|
isBuiltInEventSourceType,
|
|
365
474
|
invokeNonStream,
|
|
366
475
|
invoke,
|
|
@@ -394,6 +503,7 @@ export {
|
|
|
394
503
|
createAutoTaskPlugin,
|
|
395
504
|
closeDatabase,
|
|
396
505
|
builtInHandlers,
|
|
506
|
+
bountyIMHandler,
|
|
397
507
|
bashTool,
|
|
398
508
|
XDG_PATHS,
|
|
399
509
|
WorkflowEdges,
|
|
@@ -448,6 +558,7 @@ export {
|
|
|
448
558
|
ConfigComponent,
|
|
449
559
|
ComponentError,
|
|
450
560
|
CommandsComponent,
|
|
561
|
+
BountyIMInstance,
|
|
451
562
|
BasePlugin,
|
|
452
563
|
BaseEnvironment,
|
|
453
564
|
BaseComponent,
|
|
@@ -457,5 +568,6 @@ export {
|
|
|
457
568
|
AgentRegistry,
|
|
458
569
|
AgentError,
|
|
459
570
|
AgentComponentConfigSchema,
|
|
460
|
-
AgentComponent
|
|
571
|
+
AgentComponent,
|
|
572
|
+
ATTACH_FILE_MAX_BYTES
|
|
461
573
|
};
|
|
@@ -59,10 +59,15 @@ function extractUsageInfo(usage) {
|
|
|
59
59
|
if (!usage)
|
|
60
60
|
return;
|
|
61
61
|
if (usage.inputTokens && typeof usage.inputTokens === "object") {
|
|
62
|
+
const inputTokens = usage.inputTokens;
|
|
63
|
+
const cacheRead = typeof inputTokens.cacheRead === "number" ? inputTokens.cacheRead : typeof usage.inputTokenDetails?.cacheReadTokens === "number" ? usage.inputTokenDetails.cacheReadTokens : undefined;
|
|
64
|
+
const cacheWrite = typeof inputTokens.cacheWrite === "number" ? inputTokens.cacheWrite : typeof usage.inputTokenDetails?.cacheWriteTokens === "number" ? usage.inputTokenDetails.cacheWriteTokens : undefined;
|
|
62
65
|
return {
|
|
63
|
-
promptTokens:
|
|
66
|
+
promptTokens: inputTokens.total ?? 0,
|
|
64
67
|
completionTokens: usage.outputTokens?.total ?? 0,
|
|
65
|
-
totalTokens: usage.totalTokens ?? 0
|
|
68
|
+
totalTokens: usage.totalTokens ?? 0,
|
|
69
|
+
cacheRead,
|
|
70
|
+
cacheWrite
|
|
66
71
|
};
|
|
67
72
|
}
|
|
68
73
|
if (typeof usage.promptTokens === "number") {
|
|
@@ -73,10 +78,13 @@ function extractUsageInfo(usage) {
|
|
|
73
78
|
};
|
|
74
79
|
}
|
|
75
80
|
if (usage.inputTokenDetails || usage.outputTokenDetails) {
|
|
81
|
+
const details = usage.inputTokenDetails;
|
|
76
82
|
return {
|
|
77
|
-
promptTokens:
|
|
83
|
+
promptTokens: details?.tokens ?? 0,
|
|
78
84
|
completionTokens: usage.outputTokenDetails?.tokens ?? 0,
|
|
79
|
-
totalTokens: usage.totalTokens ?? 0
|
|
85
|
+
totalTokens: usage.totalTokens ?? 0,
|
|
86
|
+
cacheRead: details?.cacheReadTokens,
|
|
87
|
+
cacheWrite: details?.cacheWriteTokens
|
|
80
88
|
};
|
|
81
89
|
}
|
|
82
90
|
if (usage.raw && typeof usage.raw.total_tokens === "number") {
|
|
@@ -88,8 +96,111 @@ function extractUsageInfo(usage) {
|
|
|
88
96
|
}
|
|
89
97
|
return;
|
|
90
98
|
}
|
|
99
|
+
function flattenAssistantContentToText(content) {
|
|
100
|
+
if (typeof content === "string") {
|
|
101
|
+
return content;
|
|
102
|
+
}
|
|
103
|
+
return content.filter((p) => p.type === "text").map((p) => p.text).join("");
|
|
104
|
+
}
|
|
105
|
+
function sortObjectKeysDeep(obj, seen = new WeakSet) {
|
|
106
|
+
if (obj === null || obj === undefined)
|
|
107
|
+
return obj;
|
|
108
|
+
if (typeof obj !== "object")
|
|
109
|
+
return obj;
|
|
110
|
+
if (seen.has(obj))
|
|
111
|
+
return obj;
|
|
112
|
+
seen.add(obj);
|
|
113
|
+
if (Array.isArray(obj)) {
|
|
114
|
+
return obj.map((item) => sortObjectKeysDeep(item, seen));
|
|
115
|
+
}
|
|
116
|
+
if (obj instanceof Uint8Array)
|
|
117
|
+
return obj;
|
|
118
|
+
if (obj instanceof URL)
|
|
119
|
+
return obj;
|
|
120
|
+
if (obj instanceof Date)
|
|
121
|
+
return obj;
|
|
122
|
+
if (obj instanceof RegExp)
|
|
123
|
+
return obj;
|
|
124
|
+
if (obj instanceof WeakSet)
|
|
125
|
+
return obj;
|
|
126
|
+
if (obj instanceof WeakMap)
|
|
127
|
+
return obj;
|
|
128
|
+
if (obj instanceof Map) {
|
|
129
|
+
const sortedEntries = [...obj.entries()].sort(([a], [b]) => String(a).localeCompare(String(b)));
|
|
130
|
+
const sorted2 = {};
|
|
131
|
+
for (const [k, v] of sortedEntries) {
|
|
132
|
+
sorted2[String(k)] = sortObjectKeysDeep(v, seen);
|
|
133
|
+
}
|
|
134
|
+
return sorted2;
|
|
135
|
+
}
|
|
136
|
+
if (obj instanceof Set) {
|
|
137
|
+
return [...obj].sort().map((v) => sortObjectKeysDeep(v, seen));
|
|
138
|
+
}
|
|
139
|
+
if (!isPlainObject(obj))
|
|
140
|
+
return obj;
|
|
141
|
+
const sorted = {};
|
|
142
|
+
for (const key of Object.keys(obj).sort()) {
|
|
143
|
+
sorted[key] = sortObjectKeysDeep(obj[key], seen);
|
|
144
|
+
}
|
|
145
|
+
return sorted;
|
|
146
|
+
}
|
|
147
|
+
function isPlainObject(obj) {
|
|
148
|
+
if (obj === null || typeof obj !== "object")
|
|
149
|
+
return false;
|
|
150
|
+
const proto = Object.getPrototypeOf(obj);
|
|
151
|
+
return proto === Object.prototype || proto === null;
|
|
152
|
+
}
|
|
153
|
+
var ANTHROPIC_CACHE_CONTROL = {
|
|
154
|
+
anthropic: { cacheControl: { type: "ephemeral" } }
|
|
155
|
+
};
|
|
91
156
|
function convertToSDKMessages(messages) {
|
|
92
|
-
|
|
157
|
+
let lastUserIndex = -1;
|
|
158
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
159
|
+
if (messages[i].role === "user") {
|
|
160
|
+
lastUserIndex = i;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return messages.map((msg, index) => {
|
|
165
|
+
if (msg.role === "system") {
|
|
166
|
+
return {
|
|
167
|
+
role: "system",
|
|
168
|
+
content: typeof msg.content === "string" ? msg.content : "",
|
|
169
|
+
providerOptions: ANTHROPIC_CACHE_CONTROL
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
173
|
+
const contentParts = msg.content.map((part) => {
|
|
174
|
+
if (part.type === "image") {
|
|
175
|
+
return { type: "image", image: part.image };
|
|
176
|
+
}
|
|
177
|
+
if (part.type === "file") {
|
|
178
|
+
return { type: "file", data: part.file, mediaType: part.mediaType };
|
|
179
|
+
}
|
|
180
|
+
return { type: "text", text: part.text };
|
|
181
|
+
});
|
|
182
|
+
if (index === lastUserIndex && contentParts.length > 0) {
|
|
183
|
+
const lastPart = contentParts[contentParts.length - 1];
|
|
184
|
+
lastPart.providerOptions = ANTHROPIC_CACHE_CONTROL;
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
role: "user",
|
|
188
|
+
content: contentParts
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (msg.role === "user" && typeof msg.content === "string") {
|
|
192
|
+
if (index === lastUserIndex) {
|
|
193
|
+
return {
|
|
194
|
+
role: "user",
|
|
195
|
+
content: msg.content,
|
|
196
|
+
providerOptions: ANTHROPIC_CACHE_CONTROL
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
role: "user",
|
|
201
|
+
content: msg.content
|
|
202
|
+
};
|
|
203
|
+
}
|
|
93
204
|
if (msg.role === "assistant" && msg.toolCalls && msg.toolCalls.length > 0) {
|
|
94
205
|
const toolCallParts = msg.toolCalls.map((tc) => {
|
|
95
206
|
let input = {};
|
|
@@ -106,6 +217,7 @@ function convertToSDKMessages(messages) {
|
|
|
106
217
|
input = tc.arguments;
|
|
107
218
|
}
|
|
108
219
|
}
|
|
220
|
+
input = sortObjectKeysDeep(input);
|
|
109
221
|
return {
|
|
110
222
|
type: "tool-call",
|
|
111
223
|
toolCallId: tc.id,
|
|
@@ -115,7 +227,7 @@ function convertToSDKMessages(messages) {
|
|
|
115
227
|
});
|
|
116
228
|
const contentParts = [];
|
|
117
229
|
if (msg.content) {
|
|
118
|
-
contentParts.push({ type: "text", text: msg.content });
|
|
230
|
+
contentParts.push({ type: "text", text: flattenAssistantContentToText(msg.content) });
|
|
119
231
|
}
|
|
120
232
|
contentParts.push(...toolCallParts);
|
|
121
233
|
return {
|
|
@@ -644,4 +756,4 @@ function createInvokeConfig(model, apiKey, baseURL) {
|
|
|
644
756
|
};
|
|
645
757
|
}
|
|
646
758
|
|
|
647
|
-
export { withTimeout, parseModelString, invoke, invokeNonStream, createInvokeConfig };
|
|
759
|
+
export { withTimeout, parseModelString, convertToSDKMessages, invoke, invokeNonStream, createInvokeConfig };
|