@yishiguji/tokenarena 0.18.3 → 0.18.4
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.js +30 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6472,6 +6472,24 @@ function projectFromDirName(name) {
|
|
|
6472
6472
|
const last = parts[parts.length - 1];
|
|
6473
6473
|
return last ? decodeSegment(last) || "unknown" : "unknown";
|
|
6474
6474
|
}
|
|
6475
|
+
function firstOwnRowIndex(rows) {
|
|
6476
|
+
const bodyStart = rows[0]?.type === "session" ? 1 : 0;
|
|
6477
|
+
const seedLength = bodyStart === 1 ? rows[0].seedLength : void 0;
|
|
6478
|
+
if (typeof seedLength === "number" && seedLength > 0) {
|
|
6479
|
+
const index = rows.findIndex(
|
|
6480
|
+
(row, position) => position >= bodyStart && typeof row.seq === "number" && row.seq >= seedLength
|
|
6481
|
+
);
|
|
6482
|
+
return index === -1 ? rows.length : index;
|
|
6483
|
+
}
|
|
6484
|
+
let firstOwn = bodyStart;
|
|
6485
|
+
for (let index = bodyStart; index < rows.length; index++) {
|
|
6486
|
+
const row = rows[index];
|
|
6487
|
+
if (row.type === "session/end-seed" && row.data?.inherited === true) {
|
|
6488
|
+
firstOwn = index + 1;
|
|
6489
|
+
}
|
|
6490
|
+
}
|
|
6491
|
+
return firstOwn;
|
|
6492
|
+
}
|
|
6475
6493
|
var DshParser = class {
|
|
6476
6494
|
tool;
|
|
6477
6495
|
sessionsDirs;
|
|
@@ -6508,8 +6526,10 @@ var DshParser = class {
|
|
|
6508
6526
|
const header = rows[0]?.type === "session" ? rows[0] : void 0;
|
|
6509
6527
|
const sessionId = (header?.id ?? decodeSegment(relativeParts[1] ?? "")) || "unknown";
|
|
6510
6528
|
const project = typeof header?.cwd === "string" && header.cwd ? basename14(header.cwd) || "unknown" : projectFromDirName(relativeParts[0] ?? "");
|
|
6529
|
+
const firstOwn = firstOwnRowIndex(rows);
|
|
6530
|
+
let delegatedTaskPending = (header?.delegationDepth ?? 0) > 0;
|
|
6511
6531
|
let currentModel = "unknown";
|
|
6512
|
-
for (const row of rows) {
|
|
6532
|
+
for (const [index, row] of rows.entries()) {
|
|
6513
6533
|
if (row.type === "request/context") {
|
|
6514
6534
|
const model2 = row.data?.model;
|
|
6515
6535
|
if (typeof model2 === "string" && model2) currentModel = model2;
|
|
@@ -6520,10 +6540,17 @@ var DshParser = class {
|
|
|
6520
6540
|
if (typeof model2 === "string" && model2) currentModel = model2;
|
|
6521
6541
|
continue;
|
|
6522
6542
|
}
|
|
6543
|
+
const inherited = index < firstOwn;
|
|
6523
6544
|
const timestamp = typeof row.time === "number" && Number.isFinite(row.time) ? new Date(row.time) : null;
|
|
6524
6545
|
if (row.type === "user/message") {
|
|
6546
|
+
if (inherited) continue;
|
|
6525
6547
|
const sourceKind = row.data?.source?.kind ?? row.data?.message?.source?.kind;
|
|
6526
6548
|
if (sourceKind !== "user") continue;
|
|
6549
|
+
if (delegatedTaskPending) {
|
|
6550
|
+
delegatedTaskPending = false;
|
|
6551
|
+
const rpcId = row.data?.source?.rpcId ?? row.data?.message?.source?.rpcId;
|
|
6552
|
+
if (rpcId === void 0) continue;
|
|
6553
|
+
}
|
|
6527
6554
|
if (timestamp) {
|
|
6528
6555
|
sessionEvents.push({
|
|
6529
6556
|
sessionId,
|
|
@@ -6537,7 +6564,7 @@ var DshParser = class {
|
|
|
6537
6564
|
}
|
|
6538
6565
|
const isCompaction = row.type === "compaction/summary";
|
|
6539
6566
|
if (row.type !== "assistant/message" && !isCompaction) continue;
|
|
6540
|
-
if (timestamp && !isCompaction) {
|
|
6567
|
+
if (timestamp && !isCompaction && !inherited) {
|
|
6541
6568
|
sessionEvents.push({
|
|
6542
6569
|
sessionId,
|
|
6543
6570
|
source: TOOL_ID20,
|
|
@@ -6550,6 +6577,7 @@ var DshParser = class {
|
|
|
6550
6577
|
if (!usage || timestamp === null) continue;
|
|
6551
6578
|
const declaredModel = toModelName(row.data?.model) ?? toModelName(row.data?.message?.source?.model);
|
|
6552
6579
|
if (declaredModel) currentModel = declaredModel;
|
|
6580
|
+
if (inherited) continue;
|
|
6553
6581
|
const model = declaredModel ?? currentModel;
|
|
6554
6582
|
const inputTokens = toNonNegativeNumber4(usage.inputTokens);
|
|
6555
6583
|
const cachedTokens = toNonNegativeNumber4(usage.cacheReadTokens);
|