@agentv/core 3.12.0 → 3.13.0
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/index.cjs +19 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -34
- package/dist/index.d.ts +3 -34
- package/dist/index.js +17 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-3G2KXH7N.js +0 -120
- package/dist/chunk-3G2KXH7N.js.map +0 -1
- package/dist/simple-trace-file-exporter-CRIO5HDZ.js +0 -7
- package/dist/simple-trace-file-exporter-CRIO5HDZ.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1380,132 +1380,6 @@ var init_otlp_json_file_exporter = __esm({
|
|
|
1380
1380
|
}
|
|
1381
1381
|
});
|
|
1382
1382
|
|
|
1383
|
-
// src/observability/simple-trace-file-exporter.ts
|
|
1384
|
-
var simple_trace_file_exporter_exports = {};
|
|
1385
|
-
__export(simple_trace_file_exporter_exports, {
|
|
1386
|
-
SimpleTraceFileExporter: () => SimpleTraceFileExporter
|
|
1387
|
-
});
|
|
1388
|
-
function hrTimeDiffMs(start, end) {
|
|
1389
|
-
const diffSec = end[0] - start[0];
|
|
1390
|
-
const diffNano = end[1] - start[1];
|
|
1391
|
-
return Math.round(diffSec * 1e3 + diffNano / 1e6);
|
|
1392
|
-
}
|
|
1393
|
-
var import_node_fs16, import_promises34, import_node_path50, SimpleTraceFileExporter;
|
|
1394
|
-
var init_simple_trace_file_exporter = __esm({
|
|
1395
|
-
"src/observability/simple-trace-file-exporter.ts"() {
|
|
1396
|
-
"use strict";
|
|
1397
|
-
import_node_fs16 = require("fs");
|
|
1398
|
-
import_promises34 = require("fs/promises");
|
|
1399
|
-
import_node_path50 = require("path");
|
|
1400
|
-
SimpleTraceFileExporter = class {
|
|
1401
|
-
stream = null;
|
|
1402
|
-
filePath;
|
|
1403
|
-
streamReady = null;
|
|
1404
|
-
pendingWrites = [];
|
|
1405
|
-
_shuttingDown = false;
|
|
1406
|
-
spansByTraceId = /* @__PURE__ */ new Map();
|
|
1407
|
-
constructor(filePath) {
|
|
1408
|
-
this.filePath = filePath;
|
|
1409
|
-
}
|
|
1410
|
-
async ensureStream() {
|
|
1411
|
-
if (!this.streamReady) {
|
|
1412
|
-
this.streamReady = (async () => {
|
|
1413
|
-
await (0, import_promises34.mkdir)((0, import_node_path50.dirname)(this.filePath), { recursive: true });
|
|
1414
|
-
this.stream = (0, import_node_fs16.createWriteStream)(this.filePath, { flags: "w" });
|
|
1415
|
-
return this.stream;
|
|
1416
|
-
})();
|
|
1417
|
-
}
|
|
1418
|
-
return this.streamReady;
|
|
1419
|
-
}
|
|
1420
|
-
export(spans, resultCallback) {
|
|
1421
|
-
if (this._shuttingDown) {
|
|
1422
|
-
resultCallback({ code: 0 });
|
|
1423
|
-
return;
|
|
1424
|
-
}
|
|
1425
|
-
const rootSpans = [];
|
|
1426
|
-
for (const span of spans) {
|
|
1427
|
-
const traceId = span.spanContext().traceId;
|
|
1428
|
-
const existing = this.spansByTraceId.get(traceId) ?? [];
|
|
1429
|
-
existing.push(span);
|
|
1430
|
-
this.spansByTraceId.set(traceId, existing);
|
|
1431
|
-
if (span.name === "agentv.eval") {
|
|
1432
|
-
rootSpans.push(span);
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
const writePromise = this.ensureStream().then((stream) => {
|
|
1436
|
-
for (const root of rootSpans) {
|
|
1437
|
-
const traceId = root.spanContext().traceId;
|
|
1438
|
-
const traceSpans = this.spansByTraceId.get(traceId) ?? [root];
|
|
1439
|
-
const children = traceSpans.filter(
|
|
1440
|
-
(span) => span.spanContext().spanId !== root.spanContext().spanId
|
|
1441
|
-
);
|
|
1442
|
-
const record = this.buildSimpleRecord(root, children);
|
|
1443
|
-
stream.write(`${JSON.stringify(record)}
|
|
1444
|
-
`);
|
|
1445
|
-
this.spansByTraceId.delete(traceId);
|
|
1446
|
-
}
|
|
1447
|
-
});
|
|
1448
|
-
this.pendingWrites.push(writePromise);
|
|
1449
|
-
resultCallback({ code: 0 });
|
|
1450
|
-
}
|
|
1451
|
-
async shutdown() {
|
|
1452
|
-
this._shuttingDown = true;
|
|
1453
|
-
await Promise.all(this.pendingWrites);
|
|
1454
|
-
this.pendingWrites = [];
|
|
1455
|
-
this.spansByTraceId.clear();
|
|
1456
|
-
return new Promise((resolve) => {
|
|
1457
|
-
if (this.stream) {
|
|
1458
|
-
this.stream.end(() => resolve());
|
|
1459
|
-
} else {
|
|
1460
|
-
resolve();
|
|
1461
|
-
}
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
|
-
async forceFlush() {
|
|
1465
|
-
await Promise.all(this.pendingWrites);
|
|
1466
|
-
this.pendingWrites = [];
|
|
1467
|
-
}
|
|
1468
|
-
buildSimpleRecord(root, children) {
|
|
1469
|
-
const attrs = root.attributes || {};
|
|
1470
|
-
const durationMs = typeof attrs["agentv.trace.duration_ms"] === "number" ? attrs["agentv.trace.duration_ms"] : hrTimeDiffMs(root.startTime, root.endTime);
|
|
1471
|
-
let inputTokens = 0;
|
|
1472
|
-
let outputTokens = 0;
|
|
1473
|
-
for (const child of children) {
|
|
1474
|
-
const ca = child.attributes || {};
|
|
1475
|
-
if (ca["gen_ai.usage.input_tokens"]) inputTokens += ca["gen_ai.usage.input_tokens"];
|
|
1476
|
-
if (ca["gen_ai.usage.output_tokens"]) outputTokens += ca["gen_ai.usage.output_tokens"];
|
|
1477
|
-
}
|
|
1478
|
-
const rootInputTokens = typeof attrs["agentv.trace.token_input"] === "number" ? attrs["agentv.trace.token_input"] : 0;
|
|
1479
|
-
const rootOutputTokens = typeof attrs["agentv.trace.token_output"] === "number" ? attrs["agentv.trace.token_output"] : 0;
|
|
1480
|
-
const rootCachedTokens = typeof attrs["agentv.trace.token_cached"] === "number" ? attrs["agentv.trace.token_cached"] : void 0;
|
|
1481
|
-
const llmSpans = children.filter((s) => s.attributes?.["gen_ai.operation.name"] === "chat").map((s) => ({
|
|
1482
|
-
type: "llm",
|
|
1483
|
-
name: s.name,
|
|
1484
|
-
duration_ms: hrTimeDiffMs(s.startTime, s.endTime)
|
|
1485
|
-
}));
|
|
1486
|
-
const toolSpans = children.filter((s) => s.attributes?.["gen_ai.tool.name"]).map((s) => ({
|
|
1487
|
-
type: "tool",
|
|
1488
|
-
name: s.attributes["gen_ai.tool.name"],
|
|
1489
|
-
duration_ms: hrTimeDiffMs(s.startTime, s.endTime)
|
|
1490
|
-
}));
|
|
1491
|
-
return {
|
|
1492
|
-
test_id: attrs["agentv.test_id"],
|
|
1493
|
-
target: attrs["agentv.target"],
|
|
1494
|
-
score: attrs["agentv.score"],
|
|
1495
|
-
duration_ms: durationMs,
|
|
1496
|
-
cost_usd: attrs["agentv.trace.cost_usd"],
|
|
1497
|
-
token_usage: inputTokens || outputTokens || rootInputTokens || rootOutputTokens || rootCachedTokens ? {
|
|
1498
|
-
input: inputTokens || rootInputTokens,
|
|
1499
|
-
output: outputTokens || rootOutputTokens,
|
|
1500
|
-
...rootCachedTokens ? { cached: rootCachedTokens } : {}
|
|
1501
|
-
} : void 0,
|
|
1502
|
-
spans: [...llmSpans, ...toolSpans].length > 0 ? [...llmSpans, ...toolSpans] : void 0
|
|
1503
|
-
};
|
|
1504
|
-
}
|
|
1505
|
-
};
|
|
1506
|
-
}
|
|
1507
|
-
});
|
|
1508
|
-
|
|
1509
1383
|
// src/index.ts
|
|
1510
1384
|
var index_exports = {};
|
|
1511
1385
|
__export(index_exports, {
|
|
@@ -1529,7 +1403,6 @@ __export(index_exports, {
|
|
|
1529
1403
|
ProviderRegistry: () => ProviderRegistry,
|
|
1530
1404
|
RepoManager: () => RepoManager,
|
|
1531
1405
|
ResponseCache: () => ResponseCache,
|
|
1532
|
-
SimpleTraceFileExporter: () => SimpleTraceFileExporter,
|
|
1533
1406
|
SkillTriggerEvaluator: () => SkillTriggerEvaluator,
|
|
1534
1407
|
TEST_MESSAGE_ROLES: () => TEST_MESSAGE_ROLES,
|
|
1535
1408
|
TemplateNotDirectoryError: () => TemplateNotDirectoryError,
|
|
@@ -2460,12 +2333,6 @@ function parseExecutionDefaults(raw, configPath) {
|
|
|
2460
2333
|
} else if (obj.verbose !== void 0) {
|
|
2461
2334
|
logWarning(`Invalid execution.verbose in ${configPath}, expected boolean`);
|
|
2462
2335
|
}
|
|
2463
|
-
const traceFile = obj.trace_file;
|
|
2464
|
-
if (typeof traceFile === "string" && traceFile.trim().length > 0) {
|
|
2465
|
-
result.trace_file = traceFile.trim();
|
|
2466
|
-
} else if (traceFile !== void 0) {
|
|
2467
|
-
logWarning(`Invalid execution.trace_file in ${configPath}, expected non-empty string`);
|
|
2468
|
-
}
|
|
2469
2336
|
if (typeof obj.keep_workspaces === "boolean") {
|
|
2470
2337
|
result.keep_workspaces = obj.keep_workspaces;
|
|
2471
2338
|
} else if (obj.keep_workspaces !== void 0) {
|
|
@@ -12810,10 +12677,26 @@ function extractJsonBlob(text) {
|
|
|
12810
12677
|
const match = text.match(/\{[\s\S]*\}/);
|
|
12811
12678
|
return match?.[0];
|
|
12812
12679
|
}
|
|
12680
|
+
function repairSchemaNearBooleanFields(text) {
|
|
12681
|
+
return text.replace(
|
|
12682
|
+
/("passed"\s*:\s*)(?:"([^"]+)"|([A-Za-z_][A-Za-z0-9_-]*))/gi,
|
|
12683
|
+
(_match, prefix, quotedValue, bareValue) => {
|
|
12684
|
+
const value = (quotedValue ?? bareValue ?? "").trim().toLowerCase();
|
|
12685
|
+
if (value === "true") {
|
|
12686
|
+
return `${prefix}true`;
|
|
12687
|
+
}
|
|
12688
|
+
if (value === "false") {
|
|
12689
|
+
return `${prefix}false`;
|
|
12690
|
+
}
|
|
12691
|
+
return `${prefix}false`;
|
|
12692
|
+
}
|
|
12693
|
+
);
|
|
12694
|
+
}
|
|
12813
12695
|
function parseJsonFromText(text) {
|
|
12814
12696
|
const cleaned = typeof text === "string" ? text.replace(/```json\n?|```/g, "").trim() : "";
|
|
12815
12697
|
const blob = extractJsonBlob(cleaned) ?? cleaned;
|
|
12816
|
-
|
|
12698
|
+
const repaired = repairSchemaNearBooleanFields(blob);
|
|
12699
|
+
return JSON.parse(repaired);
|
|
12817
12700
|
}
|
|
12818
12701
|
function isNonEmptyString(value) {
|
|
12819
12702
|
return typeof value === "string" && value.trim().length > 0;
|
|
@@ -12960,12 +12843,12 @@ async function execFileWithStdinNode(argv, stdinPayload, options) {
|
|
|
12960
12843
|
});
|
|
12961
12844
|
}
|
|
12962
12845
|
async function execShellWithStdin(command, stdinPayload, options = {}) {
|
|
12963
|
-
const { mkdir:
|
|
12846
|
+
const { mkdir: mkdir17, readFile: readFile14, rm: rm6, writeFile: writeFile9 } = await import("fs/promises");
|
|
12964
12847
|
const { tmpdir: tmpdir3 } = await import("os");
|
|
12965
12848
|
const path48 = await import("path");
|
|
12966
12849
|
const { randomUUID: randomUUID10 } = await import("crypto");
|
|
12967
12850
|
const dir = path48.join(tmpdir3(), `agentv-exec-${randomUUID10()}`);
|
|
12968
|
-
await
|
|
12851
|
+
await mkdir17(dir, { recursive: true });
|
|
12969
12852
|
const stdinPath = path48.join(dir, "stdin.txt");
|
|
12970
12853
|
const stdoutPath = path48.join(dir, "stdout.txt");
|
|
12971
12854
|
const stderrPath = path48.join(dir, "stderr.txt");
|
|
@@ -20061,8 +19944,6 @@ var AgentVConfigSchema = import_zod5.z.object({
|
|
|
20061
19944
|
agentTimeoutMs: import_zod5.z.number().int().min(0).optional(),
|
|
20062
19945
|
/** Enable verbose logging */
|
|
20063
19946
|
verbose: import_zod5.z.boolean().optional(),
|
|
20064
|
-
/** Write human-readable trace JSONL to this path (supports {timestamp} placeholder) */
|
|
20065
|
-
traceFile: import_zod5.z.string().optional(),
|
|
20066
19947
|
/** Always keep temp workspaces after eval */
|
|
20067
19948
|
keepWorkspaces: import_zod5.z.boolean().optional(),
|
|
20068
19949
|
/** Write OTLP JSON trace to this path (supports {timestamp} placeholder) */
|
|
@@ -20362,12 +20243,6 @@ var OtelTraceExporter = class {
|
|
|
20362
20243
|
new SimpleSpanProcessor(new OtlpJsonFileExporter2(this.options.otlpFilePath))
|
|
20363
20244
|
);
|
|
20364
20245
|
}
|
|
20365
|
-
if (this.options.traceFilePath) {
|
|
20366
|
-
const { SimpleTraceFileExporter: SimpleTraceFileExporter2 } = await Promise.resolve().then(() => (init_simple_trace_file_exporter(), simple_trace_file_exporter_exports));
|
|
20367
|
-
processors.push(
|
|
20368
|
-
new SimpleSpanProcessor(new SimpleTraceFileExporter2(this.options.traceFilePath))
|
|
20369
|
-
);
|
|
20370
|
-
}
|
|
20371
20246
|
if (processors.length === 0) {
|
|
20372
20247
|
return false;
|
|
20373
20248
|
}
|
|
@@ -20795,7 +20670,6 @@ function toHrTime(iso) {
|
|
|
20795
20670
|
|
|
20796
20671
|
// src/observability/index.ts
|
|
20797
20672
|
init_otlp_json_file_exporter();
|
|
20798
|
-
init_simple_trace_file_exporter();
|
|
20799
20673
|
|
|
20800
20674
|
// src/index.ts
|
|
20801
20675
|
function createAgentKernel() {
|
|
@@ -20823,7 +20697,6 @@ function createAgentKernel() {
|
|
|
20823
20697
|
ProviderRegistry,
|
|
20824
20698
|
RepoManager,
|
|
20825
20699
|
ResponseCache,
|
|
20826
|
-
SimpleTraceFileExporter,
|
|
20827
20700
|
SkillTriggerEvaluator,
|
|
20828
20701
|
TEST_MESSAGE_ROLES,
|
|
20829
20702
|
TemplateNotDirectoryError,
|