blun-king-cli 9.1.243 → 9.1.244
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/bin/loop-event-record-policy.cjs +12 -2
- package/blun.mjs +4 -4
- package/package.json +1 -1
|
@@ -11,6 +11,10 @@ const STEP_END_LIVE_ONLY_FIELDS = [
|
|
|
11
11
|
];
|
|
12
12
|
const STEP_END_ROUTINE_FINISH_REASONS = new Set(['tool_use', 'end_turn']);
|
|
13
13
|
|
|
14
|
+
function usageTotal(usage) {
|
|
15
|
+
return usage.inputCacheRead + usage.inputCacheCreation + usage.inputOther + usage.output;
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
function hasOwn(object, key) {
|
|
15
19
|
return Object.prototype.hasOwnProperty.call(object, key);
|
|
16
20
|
}
|
|
@@ -56,11 +60,13 @@ function projectLoopEventForRecord(event) {
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
const hasRoutineFinishReason = STEP_END_ROUTINE_FINISH_REASONS.has(event?.finishReason);
|
|
63
|
+
const hasUsage = event?.type === 'step.end' && hasOwn(event, 'usage');
|
|
59
64
|
if (
|
|
60
65
|
event?.type !== 'step.end' ||
|
|
61
66
|
(
|
|
62
67
|
!hasOwn(event, 'turnId') &&
|
|
63
68
|
!hasOwn(event, 'step') &&
|
|
69
|
+
!hasUsage &&
|
|
64
70
|
!hasRoutineFinishReason &&
|
|
65
71
|
!STEP_END_LIVE_ONLY_FIELDS.some((field) => hasOwn(event, field))
|
|
66
72
|
)
|
|
@@ -78,10 +84,14 @@ function projectLoopEventForRecord(event) {
|
|
|
78
84
|
llmServerDecodeMs: _llmServerDecodeMs,
|
|
79
85
|
llmClientConsumeMs: _llmClientConsumeMs,
|
|
80
86
|
messageId: _messageId,
|
|
87
|
+
usage: _usage,
|
|
81
88
|
...recordedEvent
|
|
82
89
|
} = event;
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
const compactUsageEvent = hasUsage
|
|
91
|
+
? { ...recordedEvent, contextTokens: usageTotal(event.usage) }
|
|
92
|
+
: recordedEvent;
|
|
93
|
+
if (!hasRoutineFinishReason) return compactUsageEvent;
|
|
94
|
+
const { finishReason: _finishReason, ...withoutRoutineFinishReason } = compactUsageEvent;
|
|
85
95
|
return withoutRoutineFinishReason;
|
|
86
96
|
}
|
|
87
97
|
|
package/blun.mjs
CHANGED
|
@@ -79132,10 +79132,10 @@ var init_context$2 = __esmMin((() => {
|
|
|
79132
79132
|
case "step.end": {
|
|
79133
79133
|
const openStep = this.openSteps.get(event.uuid);
|
|
79134
79134
|
this.openSteps.delete(event.uuid);
|
|
79135
|
-
if (event.usage !== void 0) {
|
|
79135
|
+
if (event.usage !== void 0 || event.contextTokens !== void 0) {
|
|
79136
79136
|
const openStepIndex = openStep === void 0 ? -1 : this._history.indexOf(openStep);
|
|
79137
79137
|
const coveredCount = openStepIndex === -1 ? this._history.length : openStepIndex + 1;
|
|
79138
|
-
const totalUsage = event.usage.inputCacheRead + event.usage.inputCacheCreation + event.usage.inputOther + event.usage.output;
|
|
79138
|
+
const totalUsage = event.contextTokens ?? event.usage.inputCacheRead + event.usage.inputCacheCreation + event.usage.inputOther + event.usage.output;
|
|
79139
79139
|
if (totalUsage > 0) this._tokenCount = totalUsage;
|
|
79140
79140
|
else {
|
|
79141
79141
|
const previousCoveredCount = this.tokenCountCoveredMessageCount;
|
|
@@ -398968,8 +398968,8 @@ function projectContext(entries, mode = "model") {
|
|
|
398968
398968
|
});
|
|
398969
398969
|
}
|
|
398970
398970
|
} else if (ev.type === "step.end") {
|
|
398971
|
-
if ("usage" in ev && ev.usage !== void 0) {
|
|
398972
|
-
const fill = ev.usage.inputCacheRead + ev.usage.inputCacheCreation + ev.usage.inputOther + ev.usage.output;
|
|
398971
|
+
if ("usage" in ev && ev.usage !== void 0 || ev.contextTokens !== void 0) {
|
|
398972
|
+
const fill = ev.contextTokens ?? ev.usage.inputCacheRead + ev.usage.inputCacheCreation + ev.usage.inputOther + ev.usage.output;
|
|
398973
398973
|
if (fill > 0) contextTokens = fill;
|
|
398974
398974
|
}
|
|
398975
398975
|
openSteps.delete(ev.uuid);
|