@ai-setting/roy-agent-core 1.5.89 → 1.5.91
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/index.js +8 -8
- package/dist/env/agent/index.js +14 -14
- package/dist/env/commands/index.js +8 -8
- package/dist/env/context/index.js +4 -4
- package/dist/env/debug/index.js +8 -8
- package/dist/env/event-source/index.js +18 -14
- package/dist/env/hook/index.js +6 -6
- package/dist/env/index.js +35 -35
- package/dist/env/llm/index.js +12 -10
- package/dist/env/log-trace/index.js +8 -8
- package/dist/env/mcp/index.js +9 -9
- package/dist/env/mcp/tool/index.js +2 -2
- package/dist/env/memory/index.js +9 -9
- package/dist/env/memory/plugin/index.js +2 -2
- package/dist/env/plugin/index.js +8 -8
- package/dist/env/prompt/index.js +9 -9
- package/dist/env/session/index.js +11 -11
- package/dist/env/session/storage/index.js +4 -4
- package/dist/env/skill/index.js +8 -8
- package/dist/env/task/delegate/index.js +7 -7
- package/dist/env/task/index.js +12 -12
- package/dist/env/task/plugins/index.js +7 -7
- package/dist/env/task/storage/index.js +2 -2
- package/dist/env/task/tools/index.js +4 -4
- package/dist/env/tool/built-in/index.js +3 -3
- package/dist/env/tool/index.js +10 -10
- package/dist/env/workflow/engine/index.js +9 -9
- package/dist/env/workflow/index.js +15 -15
- package/dist/env/workflow/nodes/index.js +3 -3
- package/dist/env/workflow/service/index.js +3 -3
- package/dist/env/workflow/storage/index.js +4 -4
- package/dist/env/workflow/tools/index.js +4 -4
- package/dist/env/workflow/utils/index.js +3 -3
- package/dist/index.js +155 -50
- package/dist/shared/@ai-setting/{roy-agent-core-fvfc7f6v.js → roy-agent-core-0ger6zdn.js} +65 -11
- package/dist/shared/@ai-setting/{roy-agent-core-bwjpte58.js → roy-agent-core-0vsnecwa.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-h5867smx.js → roy-agent-core-0ye4q2jj.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-prdngx28.js → roy-agent-core-33rhv946.js} +43 -7
- package/dist/shared/@ai-setting/{roy-agent-core-djtkntar.js → roy-agent-core-4w6rgxs4.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fgpnv7dt.js → roy-agent-core-55br4t6v.js} +80 -37
- package/dist/shared/@ai-setting/{roy-agent-core-3952rkj0.js → roy-agent-core-578qk38y.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-2q7cshpm.js → roy-agent-core-5j649pb1.js} +289 -21
- package/dist/shared/@ai-setting/{roy-agent-core-2h38rvyj.js → roy-agent-core-634ee5jb.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-w6bmrgap.js → roy-agent-core-7svhckhz.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-ce10b0ez.js → roy-agent-core-8x4ngxcy.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-83d035pp.js → roy-agent-core-97tjdb2r.js} +70 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qbq3jgrn.js → roy-agent-core-9amq4epa.js} +14 -14
- package/dist/shared/@ai-setting/{roy-agent-core-pcdzfwdv.js → roy-agent-core-9xby523m.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-mw4ty0ba.js → roy-agent-core-at05dk0z.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-ewr1nw7t.js → roy-agent-core-b1vkkcbr.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-n19rm7tw.js → roy-agent-core-b2thb9xj.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-3sv590cv.js → roy-agent-core-b77yz0wt.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-yanpq5gb.js → roy-agent-core-bdajt9cs.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-3czy06aq.js → roy-agent-core-bqwj1dq0.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-k05v31rc.js → roy-agent-core-cg146hmg.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-07290s9n.js → roy-agent-core-cx67bv9d.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-taxvytzz.js → roy-agent-core-cx9p8b2t.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-d6597yp0.js → roy-agent-core-ddghwfmk.js} +3 -3
- 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-tq9528d3.js → roy-agent-core-e7t3rj0e.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-h2d1s8yd.js → roy-agent-core-fg5eaht3.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-q7sqeax6.js → roy-agent-core-fx1fdzbz.js} +163 -3
- package/dist/shared/@ai-setting/{roy-agent-core-hc20420t.js → roy-agent-core-g2mth323.js} +28 -4
- package/dist/shared/@ai-setting/{roy-agent-core-7tp56w6n.js → roy-agent-core-gp872e7m.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-c67wr8sp.js → roy-agent-core-hf8pqrvy.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-32m0nb9j.js → roy-agent-core-j3qb695p.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-r0m0at3x.js → roy-agent-core-j7jeqxhd.js} +121 -9
- package/dist/shared/@ai-setting/{roy-agent-core-h4h55x4h.js → roy-agent-core-jexyz11d.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-hxsbegfc.js → roy-agent-core-jf865m5b.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-b8r4tfqq.js → roy-agent-core-ksx9a556.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rgckng3p.js → roy-agent-core-pf1c360e.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-xckhrs2p.js → roy-agent-core-q7ffkt1e.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-gb9gbkc3.js → roy-agent-core-q88vxmx5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-y5d04fm3.js → roy-agent-core-scp0afxg.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-3f6k060j.js → roy-agent-core-snvsn60t.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-xnxyzaw4.js → roy-agent-core-spzb03na.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-86d4exyf.js → roy-agent-core-sssn8kt9.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-m3dkyprg.js → roy-agent-core-svcr4gjw.js} +14 -9
- package/dist/shared/@ai-setting/{roy-agent-core-nqzt9ne4.js → roy-agent-core-vady4w02.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-shme7set.js → roy-agent-core-vyygk314.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-5kdw0p98.js → roy-agent-core-w1s8yrm5.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-v8xa6vs8.js → roy-agent-core-wmkx79b1.js} +14 -12
- package/dist/shared/@ai-setting/{roy-agent-core-t1ef8hf2.js → roy-agent-core-ws76avbn.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-xhcgg11h.js → roy-agent-core-wtbyj0q1.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-fjexv5nm.js → roy-agent-core-xgnpr28w.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-c1j7ev4e.js → roy-agent-core-yfhgxh5a.js} +71 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qg4rma4c.js → roy-agent-core-zttjq1h3.js} +1 -1
- package/package.json +1 -1
- /package/dist/shared/@ai-setting/{roy-agent-core-4f3976cd.js → roy-agent-core-k5hxvaf0.js} +0 -0
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SessionMessageConverter
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-yfhgxh5a.js";
|
|
4
|
+
import {
|
|
5
|
+
createLogger,
|
|
6
|
+
init_logger
|
|
7
|
+
} from "./roy-agent-core-vyygk314.js";
|
|
4
8
|
import {
|
|
5
9
|
__require
|
|
6
10
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
7
11
|
|
|
12
|
+
// src/env/session/session-store.ts
|
|
13
|
+
class BaseSessionStore {
|
|
14
|
+
async addMessages(sessionId, messages) {
|
|
15
|
+
if (messages.length === 0)
|
|
16
|
+
return [];
|
|
17
|
+
const ids = [];
|
|
18
|
+
for (const msg of messages) {
|
|
19
|
+
ids.push(await this.addMessage(sessionId, msg));
|
|
20
|
+
}
|
|
21
|
+
return ids;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
8
25
|
// src/env/session/storage/memory.ts
|
|
9
26
|
import { randomUUID } from "crypto";
|
|
10
27
|
function generateSessionId() {
|
|
@@ -14,7 +31,7 @@ function generateMessageId() {
|
|
|
14
31
|
return `msg_${randomUUID()}`;
|
|
15
32
|
}
|
|
16
33
|
|
|
17
|
-
class MemorySessionStore {
|
|
34
|
+
class MemorySessionStore extends BaseSessionStore {
|
|
18
35
|
sessions = new Map;
|
|
19
36
|
messages = new Map;
|
|
20
37
|
checkpoints = new Map;
|
|
@@ -138,6 +155,40 @@ class MemorySessionStore {
|
|
|
138
155
|
session.updatedAt = Date.now();
|
|
139
156
|
return msg.id;
|
|
140
157
|
}
|
|
158
|
+
async addMessages(sessionId, messages) {
|
|
159
|
+
if (messages.length === 0) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
const session = this.sessions.get(sessionId);
|
|
163
|
+
if (!session) {
|
|
164
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
165
|
+
}
|
|
166
|
+
const sessionMessages = this.messages.get(sessionId) ?? [];
|
|
167
|
+
const ids = [];
|
|
168
|
+
const now = Date.now();
|
|
169
|
+
for (const message of messages) {
|
|
170
|
+
const rawMessage = {
|
|
171
|
+
sessionID: sessionId,
|
|
172
|
+
role: message.role,
|
|
173
|
+
content: message.content,
|
|
174
|
+
parts: message.parts,
|
|
175
|
+
metadata: message.metadata
|
|
176
|
+
};
|
|
177
|
+
const msg = this.messageConverter.migrateMessage(rawMessage);
|
|
178
|
+
msg.id = generateMessageId();
|
|
179
|
+
msg.timestamp = now;
|
|
180
|
+
sessionMessages.push(msg);
|
|
181
|
+
ids.push(msg.id);
|
|
182
|
+
}
|
|
183
|
+
this.messages.set(sessionId, sessionMessages);
|
|
184
|
+
session.messageCount = sessionMessages.filter((m) => !m.isArchived).length;
|
|
185
|
+
session.metadata = {
|
|
186
|
+
...session.metadata,
|
|
187
|
+
messageCount: session.messageCount
|
|
188
|
+
};
|
|
189
|
+
session.updatedAt = now;
|
|
190
|
+
return ids;
|
|
191
|
+
}
|
|
141
192
|
async updateMessage(sessionId, messageId, updates) {
|
|
142
193
|
const sessionMessages = this.messages.get(sessionId);
|
|
143
194
|
if (!sessionMessages) {
|
|
@@ -371,6 +422,8 @@ class MemorySessionStore {
|
|
|
371
422
|
// src/env/session/storage/sqlite.ts
|
|
372
423
|
import { join } from "path";
|
|
373
424
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
425
|
+
init_logger();
|
|
426
|
+
var logger = createLogger("session:storage:sqlite");
|
|
374
427
|
function getDatabaseClass() {
|
|
375
428
|
if (typeof Bun !== "undefined") {
|
|
376
429
|
const { Database } = __require("bun:sqlite");
|
|
@@ -379,6 +432,17 @@ function getDatabaseClass() {
|
|
|
379
432
|
return __require("better-sqlite3");
|
|
380
433
|
}
|
|
381
434
|
}
|
|
435
|
+
function isSqliteBusyError(err) {
|
|
436
|
+
if (err == null)
|
|
437
|
+
return false;
|
|
438
|
+
const e = err;
|
|
439
|
+
if (typeof e.code === "string" && /^SQLITE_(BUSY|LOCKED)$/i.test(e.code))
|
|
440
|
+
return true;
|
|
441
|
+
if (typeof e.errno === "number" && (e.errno === 5 || e.errno === 6))
|
|
442
|
+
return true;
|
|
443
|
+
const msg = e.message ?? "";
|
|
444
|
+
return /SQLiteError:\s+(database is locked|database table is locked)/i.test(msg);
|
|
445
|
+
}
|
|
382
446
|
function createCompatibleDatabase(path) {
|
|
383
447
|
const Database = getDatabaseClass();
|
|
384
448
|
const db = new Database(path);
|
|
@@ -407,7 +471,7 @@ function getDefaultSessionDbPath() {
|
|
|
407
471
|
return join(getDefaultDataDir(), "roy-agent", "sessions.db");
|
|
408
472
|
}
|
|
409
473
|
|
|
410
|
-
class SQLiteSessionStore {
|
|
474
|
+
class SQLiteSessionStore extends BaseSessionStore {
|
|
411
475
|
db = null;
|
|
412
476
|
dbPath;
|
|
413
477
|
initialized = false;
|
|
@@ -416,6 +480,7 @@ class SQLiteSessionStore {
|
|
|
416
480
|
checkpointsCache = new Map;
|
|
417
481
|
messageConverter = new SessionMessageConverter;
|
|
418
482
|
constructor(dbPath) {
|
|
483
|
+
super();
|
|
419
484
|
this.dbPath = dbPath || getDefaultSessionDbPath();
|
|
420
485
|
}
|
|
421
486
|
async initialize() {
|
|
@@ -430,6 +495,10 @@ class SQLiteSessionStore {
|
|
|
430
495
|
}
|
|
431
496
|
}
|
|
432
497
|
this.db = createCompatibleDatabase(this.dbPath);
|
|
498
|
+
this.applyPragma("PRAGMA journal_mode = WAL");
|
|
499
|
+
this.applyPragma("PRAGMA busy_timeout = 5000");
|
|
500
|
+
this.applyPragma("PRAGMA synchronous = NORMAL");
|
|
501
|
+
this.applyPragma("PRAGMA wal_autocheckpoint = 1000");
|
|
433
502
|
this.db.run(`
|
|
434
503
|
CREATE TABLE IF NOT EXISTS session (
|
|
435
504
|
id TEXT PRIMARY KEY,
|
|
@@ -611,6 +680,90 @@ class SQLiteSessionStore {
|
|
|
611
680
|
this.sessionsCache.set(sessionId, session);
|
|
612
681
|
return msg.id;
|
|
613
682
|
}
|
|
683
|
+
async addMessages(sessionId, messages) {
|
|
684
|
+
if (messages.length === 0) {
|
|
685
|
+
return [];
|
|
686
|
+
}
|
|
687
|
+
const BATCH_BACKOFFS_MS = [50, 100, 200];
|
|
688
|
+
let lastError = undefined;
|
|
689
|
+
for (let attempt = 0;attempt <= BATCH_BACKOFFS_MS.length; attempt++) {
|
|
690
|
+
try {
|
|
691
|
+
return await this.addMessagesOnce(sessionId, messages);
|
|
692
|
+
} catch (err) {
|
|
693
|
+
if (!isSqliteBusyError(err) || attempt === BATCH_BACKOFFS_MS.length) {
|
|
694
|
+
this.messagesCache.delete(sessionId);
|
|
695
|
+
this.sessionsCache.delete(sessionId);
|
|
696
|
+
lastError = err;
|
|
697
|
+
if (!isSqliteBusyError(err))
|
|
698
|
+
throw err;
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
await new Promise((resolve) => setTimeout(resolve, BATCH_BACKOFFS_MS[attempt]));
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
throw lastError;
|
|
705
|
+
}
|
|
706
|
+
async addMessagesOnce(sessionId, messages) {
|
|
707
|
+
await this.initialize();
|
|
708
|
+
const session = await this.get(sessionId);
|
|
709
|
+
if (!session) {
|
|
710
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
711
|
+
}
|
|
712
|
+
const now = Date.now();
|
|
713
|
+
const ids = [];
|
|
714
|
+
const insertStmt = this.db.prepare(`
|
|
715
|
+
INSERT INTO message (id, session_id, role, content, timestamp, parts, metadata)
|
|
716
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
717
|
+
`);
|
|
718
|
+
const sessionUpdateStmt = this.db.prepare(`
|
|
719
|
+
UPDATE session SET message_count = ?, metadata = ?, updated_at = ? WHERE id = ?
|
|
720
|
+
`);
|
|
721
|
+
this.db.run("BEGIN");
|
|
722
|
+
try {
|
|
723
|
+
for (const message of messages) {
|
|
724
|
+
const id = generateMessageId2();
|
|
725
|
+
ids.push(id);
|
|
726
|
+
insertStmt.run(id, sessionId, message.role, message.content, now, message.parts ? JSON.stringify(message.parts) : null, message.metadata ? JSON.stringify(message.metadata) : null);
|
|
727
|
+
}
|
|
728
|
+
const countResult = this.db.prepare("SELECT COUNT(*) as count FROM message WHERE session_id = ? AND is_archived = 0").get(sessionId);
|
|
729
|
+
const newCount = countResult?.count ?? 0;
|
|
730
|
+
session.messageCount = newCount;
|
|
731
|
+
session.updatedAt = now;
|
|
732
|
+
session.metadata = {
|
|
733
|
+
...session.metadata ?? {},
|
|
734
|
+
messageCount: newCount
|
|
735
|
+
};
|
|
736
|
+
sessionUpdateStmt.run(newCount, JSON.stringify(session.metadata), now, sessionId);
|
|
737
|
+
this.db.run("COMMIT");
|
|
738
|
+
} catch (err) {
|
|
739
|
+
try {
|
|
740
|
+
this.db.run("ROLLBACK");
|
|
741
|
+
} catch {}
|
|
742
|
+
throw err;
|
|
743
|
+
}
|
|
744
|
+
try {
|
|
745
|
+
const cached = this.messagesCache.get(sessionId) ?? [];
|
|
746
|
+
for (let i = 0;i < messages.length; i++) {
|
|
747
|
+
const message = messages[i];
|
|
748
|
+
cached.push({
|
|
749
|
+
id: ids[i],
|
|
750
|
+
sessionID: sessionId,
|
|
751
|
+
role: message.role,
|
|
752
|
+
content: message.content,
|
|
753
|
+
timestamp: now,
|
|
754
|
+
parts: message.parts,
|
|
755
|
+
metadata: message.metadata
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
this.messagesCache.set(sessionId, cached);
|
|
759
|
+
this.sessionsCache.set(sessionId, session);
|
|
760
|
+
} catch (cacheErr) {
|
|
761
|
+
logger.warn(`[SQLiteSessionStore] cache update failed after commit; invalidating: ${cacheErr}`);
|
|
762
|
+
this.messagesCache.delete(sessionId);
|
|
763
|
+
this.sessionsCache.delete(sessionId);
|
|
764
|
+
}
|
|
765
|
+
return ids;
|
|
766
|
+
}
|
|
614
767
|
async updateMessage(sessionId, messageId, updates) {
|
|
615
768
|
await this.initialize();
|
|
616
769
|
const row = this.db.prepare("SELECT id FROM message WHERE id = ? AND session_id = ?").get(messageId, sessionId);
|
|
@@ -679,6 +832,13 @@ class SQLiteSessionStore {
|
|
|
679
832
|
const rows = this.db.prepare(sql).all(...params);
|
|
680
833
|
return rows.map((row) => this.rowToMessage(row));
|
|
681
834
|
}
|
|
835
|
+
applyPragma(pragmaSql) {
|
|
836
|
+
this.db.run(pragmaSql);
|
|
837
|
+
const readback = this.db.prepare(pragmaSql.split("=")[0].trim()).get();
|
|
838
|
+
const key = Object.keys(readback ?? {})[0];
|
|
839
|
+
const actual = key ? readback[key] : undefined;
|
|
840
|
+
logger.info(`[SQLiteSessionStore] Applied ${pragmaSql} → ${actual}`);
|
|
841
|
+
}
|
|
682
842
|
async getMessageCount(sessionId, includeArchived = false) {
|
|
683
843
|
await this.initialize();
|
|
684
844
|
let sql = "SELECT COUNT(*) as count FROM message WHERE session_id = ?";
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TracedAs,
|
|
3
3
|
init_decorator
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-cg146hmg.js";
|
|
5
5
|
import {
|
|
6
6
|
__esm,
|
|
7
7
|
__legacyDecorateClassTS
|
|
8
8
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
9
9
|
|
|
10
10
|
// src/env/workflow/nodes/tool-node.ts
|
|
11
|
-
|
|
11
|
+
function isPositiveNumber(v) {
|
|
12
|
+
return typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
13
|
+
}
|
|
14
|
+
function getToolTimeoutMs(input, config) {
|
|
15
|
+
if (input && typeof input === "object") {
|
|
16
|
+
const inputTimeout = input.timeout;
|
|
17
|
+
if (isPositiveNumber(inputTimeout)) {
|
|
18
|
+
return inputTimeout;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (config && isPositiveNumber(config.timeout)) {
|
|
22
|
+
return config.timeout;
|
|
23
|
+
}
|
|
24
|
+
return DEFAULT_TOOL_TIMEOUT_MS;
|
|
25
|
+
}
|
|
26
|
+
var DEFAULT_TOOL_TIMEOUT_MS = 60000, ToolNode;
|
|
12
27
|
var init_tool_node = __esm(() => {
|
|
13
28
|
init_decorator();
|
|
14
29
|
ToolNode = class ToolNode {
|
|
@@ -88,11 +103,20 @@ var init_tool_node = __esm(() => {
|
|
|
88
103
|
nodeId: context.nodeId
|
|
89
104
|
}
|
|
90
105
|
};
|
|
106
|
+
const toolTimeoutMs = getToolTimeoutMs(input, this.definition.config);
|
|
91
107
|
const executePromise = tool.execute(input, toolContext);
|
|
108
|
+
let timeoutHandle;
|
|
92
109
|
const timeoutPromise = new Promise((_, reject) => {
|
|
93
|
-
setTimeout(() => reject(new Error(`Tool '${toolName}' execution timeout after
|
|
110
|
+
timeoutHandle = setTimeout(() => reject(new Error(`Tool '${toolName}' execution timeout after ${Math.round(toolTimeoutMs / 1000)} seconds`)), toolTimeoutMs);
|
|
94
111
|
});
|
|
95
|
-
|
|
112
|
+
try {
|
|
113
|
+
output = await Promise.race([executePromise, timeoutPromise]);
|
|
114
|
+
} finally {
|
|
115
|
+
if (timeoutHandle !== undefined) {
|
|
116
|
+
clearTimeout(timeoutHandle);
|
|
117
|
+
timeoutHandle = undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
96
120
|
} catch (toolError) {
|
|
97
121
|
if (toolError instanceof TypeError && toolError.message.includes("context") && toolError.message.includes("not a function")) {
|
|
98
122
|
output = await tool.execute(input);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
init_context
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-zttjq1h3.js";
|
|
4
4
|
import {
|
|
5
5
|
getEnvContext
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-scp0afxg.js";
|
|
7
7
|
import {
|
|
8
8
|
__esm
|
|
9
9
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TagRepository
|
|
3
|
-
} from "./roy-agent-core-
|
|
4
|
-
import"./roy-agent-core-
|
|
5
|
-
import"./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-b77yz0wt.js";
|
|
4
|
+
import"./roy-agent-core-cg146hmg.js";
|
|
5
|
+
import"./roy-agent-core-vyygk314.js";
|
|
6
6
|
import"./roy-agent-core-7z9b1fm8.js";
|
|
7
7
|
import"./roy-agent-core-c6592r3c.js";
|
|
8
8
|
import"./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TAG_MAX_COUNT,
|
|
3
3
|
TAG_MIN_COUNT
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-e7t3rj0e.js";
|
|
5
5
|
import {
|
|
6
6
|
validateWorkflowDefinition
|
|
7
7
|
} from "./roy-agent-core-8wd3qwx5.js";
|
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
TracedAs,
|
|
14
14
|
init_decorator
|
|
15
|
-
} from "./roy-agent-core-
|
|
15
|
+
} from "./roy-agent-core-cg146hmg.js";
|
|
16
16
|
import {
|
|
17
17
|
createLogger,
|
|
18
18
|
init_logger
|
|
19
|
-
} from "./roy-agent-core-
|
|
19
|
+
} from "./roy-agent-core-vyygk314.js";
|
|
20
20
|
import {
|
|
21
21
|
__legacyDecorateClassTS
|
|
22
22
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
safeParseToolArgs
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-8x4ngxcy.js";
|
|
4
4
|
import {
|
|
5
5
|
createLogger,
|
|
6
6
|
init_logger
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-vyygk314.js";
|
|
8
8
|
import {
|
|
9
9
|
__require
|
|
10
10
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TagRepository
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-b77yz0wt.js";
|
|
4
4
|
import {
|
|
5
5
|
exports_search_query_parser,
|
|
6
6
|
init_search_query_parser
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
createLogger,
|
|
10
10
|
init_logger
|
|
11
|
-
} from "./roy-agent-core-
|
|
11
|
+
} from "./roy-agent-core-vyygk314.js";
|
|
12
12
|
import {
|
|
13
13
|
__require,
|
|
14
14
|
__toCommonJS
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AUTO_TASK_METADATA_BEGIN,
|
|
3
3
|
AUTO_TASK_METADATA_END
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-bdajt9cs.js";
|
|
5
5
|
import {
|
|
6
6
|
AskUserError,
|
|
7
7
|
init_workflow_hil
|
|
@@ -12,20 +12,20 @@ import {
|
|
|
12
12
|
} from "./roy-agent-core-qxhq8ven.js";
|
|
13
13
|
import {
|
|
14
14
|
BaseComponent
|
|
15
|
-
} from "./roy-agent-core-
|
|
15
|
+
} from "./roy-agent-core-pf1c360e.js";
|
|
16
16
|
import {
|
|
17
17
|
ToolHookPoints,
|
|
18
18
|
globalHookManager,
|
|
19
19
|
init_global_hook_manager
|
|
20
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-gp872e7m.js";
|
|
21
21
|
import {
|
|
22
22
|
getCurrentTaskId,
|
|
23
23
|
init_env_context
|
|
24
|
-
} from "./roy-agent-core-
|
|
24
|
+
} from "./roy-agent-core-scp0afxg.js";
|
|
25
25
|
import {
|
|
26
26
|
createLogger,
|
|
27
27
|
init_logger
|
|
28
|
-
} from "./roy-agent-core-
|
|
28
|
+
} from "./roy-agent-core-vyygk314.js";
|
|
29
29
|
import {
|
|
30
30
|
__require
|
|
31
31
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createHook
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-ksx9a556.js";
|
|
4
4
|
import {
|
|
5
5
|
HookManager
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-gp872e7m.js";
|
|
7
7
|
|
|
8
8
|
// src/env/component.ts
|
|
9
9
|
class BaseComponent {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-w1s8yrm5.js";
|
|
5
5
|
import"./roy-agent-core-1db4vpc6.js";
|
|
6
6
|
import"./roy-agent-core-e25xkv53.js";
|
|
7
|
-
import"./roy-agent-core-
|
|
8
|
-
import"./roy-agent-core-
|
|
9
|
-
import"./roy-agent-core-
|
|
10
|
-
import"./roy-agent-core-
|
|
11
|
-
import"./roy-agent-core-
|
|
7
|
+
import"./roy-agent-core-gp872e7m.js";
|
|
8
|
+
import"./roy-agent-core-zttjq1h3.js";
|
|
9
|
+
import"./roy-agent-core-scp0afxg.js";
|
|
10
|
+
import"./roy-agent-core-cg146hmg.js";
|
|
11
|
+
import"./roy-agent-core-vyygk314.js";
|
|
12
12
|
import"./roy-agent-core-7z9b1fm8.js";
|
|
13
13
|
import"./roy-agent-core-c6592r3c.js";
|
|
14
14
|
import"./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
init_decorator,
|
|
3
3
|
wrapFunction
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-cg146hmg.js";
|
|
5
5
|
import {
|
|
6
6
|
createLogger,
|
|
7
7
|
init_logger
|
|
8
|
-
} from "./roy-agent-core-
|
|
8
|
+
} from "./roy-agent-core-vyygk314.js";
|
|
9
9
|
import {
|
|
10
10
|
__esm
|
|
11
11
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-w1s8yrm5.js";
|
|
5
5
|
import {
|
|
6
6
|
buildWorkflowNodeMetadata,
|
|
7
7
|
getWorkflowNodeIdFromMetadata,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import {
|
|
12
12
|
TemplateResolver,
|
|
13
13
|
init_template_resolver
|
|
14
|
-
} from "./roy-agent-core-
|
|
14
|
+
} from "./roy-agent-core-q88vxmx5.js";
|
|
15
15
|
import {
|
|
16
16
|
SkillNode,
|
|
17
17
|
ToolNode,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
init_skill_node,
|
|
20
20
|
init_tool_node,
|
|
21
21
|
init_workflow_node
|
|
22
|
-
} from "./roy-agent-core-
|
|
22
|
+
} from "./roy-agent-core-g2mth323.js";
|
|
23
23
|
import {
|
|
24
24
|
WorkflowError,
|
|
25
25
|
createWorkflowEvent,
|
|
@@ -47,11 +47,11 @@ import {
|
|
|
47
47
|
import {
|
|
48
48
|
TracedAs,
|
|
49
49
|
init_decorator
|
|
50
|
-
} from "./roy-agent-core-
|
|
50
|
+
} from "./roy-agent-core-cg146hmg.js";
|
|
51
51
|
import {
|
|
52
52
|
createLogger,
|
|
53
53
|
init_logger
|
|
54
|
-
} from "./roy-agent-core-
|
|
54
|
+
} from "./roy-agent-core-vyygk314.js";
|
|
55
55
|
import {
|
|
56
56
|
__esm,
|
|
57
57
|
__export,
|