blun-king-cli 9.1.283 → 9.1.284
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/subagent-usage-rollup-policy.cjs +29 -0
- package/blun.mjs +19 -4
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const USAGE_FIELDS = [
|
|
4
|
+
'inputOther',
|
|
5
|
+
'output',
|
|
6
|
+
'inputCacheRead',
|
|
7
|
+
'inputCacheCreation',
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
function safeTokenCount(value) {
|
|
11
|
+
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function buildSubagentUsageDelta(after, before) {
|
|
15
|
+
if (after === undefined || after === null || typeof after !== 'object') return null;
|
|
16
|
+
const baseline = before !== null && typeof before === 'object' ? before : {};
|
|
17
|
+
if (USAGE_FIELDS.some((field) => safeTokenCount(after[field]) < safeTokenCount(baseline[field]))) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const delta = Object.fromEntries(USAGE_FIELDS.map((field) => [
|
|
21
|
+
field,
|
|
22
|
+
safeTokenCount(after[field]) - safeTokenCount(baseline[field]),
|
|
23
|
+
]));
|
|
24
|
+
return USAGE_FIELDS.some((field) => delta[field] > 0) ? delta : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
buildSubagentUsageDelta,
|
|
29
|
+
};
|
package/blun.mjs
CHANGED
|
@@ -252106,7 +252106,7 @@ function shouldSuppressQueuedAttemptFailureEvent(options, error) {
|
|
|
252106
252106
|
if (isProviderRateLimitError(error)) return true;
|
|
252107
252107
|
return isAbortError$4(error) || options.signal.aborted;
|
|
252108
252108
|
}
|
|
252109
|
-
var DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation, SUMMARY_MIN_LENGTH, SUMMARY_CONTINUATION_ATTEMPTS, HOOK_TEXT_PREVIEW_LENGTH, SUBAGENT_MAX_TOKENS_ERROR, TOOL_CALL_DISABLED_MESSAGE, SUBAGENT_PROMPT_ORIGIN, SIDE_QUESTION_SYSTEM_REMINDER, SessionSubagentHost;
|
|
252109
|
+
var DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation, buildSubagentUsageDelta, SUMMARY_MIN_LENGTH, SUMMARY_CONTINUATION_ATTEMPTS, HOOK_TEXT_PREVIEW_LENGTH, SUBAGENT_MAX_TOKENS_ERROR, TOOL_CALL_DISABLED_MESSAGE, SUBAGENT_PROMPT_ORIGIN, SIDE_QUESTION_SYSTEM_REMINDER, SessionSubagentHost;
|
|
252110
252110
|
var init_subagent_host = __esmMin((() => {
|
|
252111
252111
|
init_src$4();
|
|
252112
252112
|
init_errors$8();
|
|
@@ -252119,6 +252119,7 @@ var init_subagent_host = __esmMin((() => {
|
|
|
252119
252119
|
init_subagent_batch();
|
|
252120
252120
|
init_summary_continuation();
|
|
252121
252121
|
({ DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation } = createRequire(import.meta.url)("./bin/subagent-timeout-policy.cjs"));
|
|
252122
|
+
({ buildSubagentUsageDelta } = createRequire(import.meta.url)("./bin/subagent-usage-rollup-policy.cjs"));
|
|
252122
252123
|
SUMMARY_MIN_LENGTH = 200;
|
|
252123
252124
|
SUMMARY_CONTINUATION_ATTEMPTS = 1;
|
|
252124
252125
|
HOOK_TEXT_PREVIEW_LENGTH = 500;
|
|
@@ -252177,7 +252178,7 @@ IMPORTANT:
|
|
|
252177
252178
|
parentAgentId: this.ownerAgentId,
|
|
252178
252179
|
swarmItem: options.swarmItem
|
|
252179
252180
|
});
|
|
252180
|
-
const completion = this.
|
|
252181
|
+
const completion = this.runWithTrackedChildUsage(parent, agent, id, options, async (runOptions) => {
|
|
252181
252182
|
this.emitSubagentSpawned(parent, id, profile.name, runOptions);
|
|
252182
252183
|
try {
|
|
252183
252184
|
await this.configureChild(parent, agent, profile);
|
|
@@ -252201,7 +252202,7 @@ IMPORTANT:
|
|
|
252201
252202
|
agentId,
|
|
252202
252203
|
profileName,
|
|
252203
252204
|
resumed: true,
|
|
252204
|
-
completion: this.
|
|
252205
|
+
completion: this.runWithTrackedChildUsage(parent, child, agentId, options, async (runOptions) => {
|
|
252205
252206
|
this.emitSubagentSpawned(parent, agentId, profileName, runOptions);
|
|
252206
252207
|
try {
|
|
252207
252208
|
child.config.update({
|
|
@@ -252239,7 +252240,7 @@ IMPORTANT:
|
|
|
252239
252240
|
agentId,
|
|
252240
252241
|
profileName,
|
|
252241
252242
|
resumed: true,
|
|
252242
|
-
completion: this.
|
|
252243
|
+
completion: this.runWithTrackedChildUsage(parent, child, agentId, options, async (runOptions) => {
|
|
252243
252244
|
try {
|
|
252244
252245
|
runOptions.signal.throwIfAborted();
|
|
252245
252246
|
child.config.update({
|
|
@@ -252354,6 +252355,20 @@ IMPORTANT:
|
|
|
252354
252355
|
this.activeChildren.delete(childId);
|
|
252355
252356
|
});
|
|
252356
252357
|
}
|
|
252358
|
+
async runWithTrackedChildUsage(parent, child, childId, options, run) {
|
|
252359
|
+
const usageBefore = child.usage.data().total;
|
|
252360
|
+
try {
|
|
252361
|
+
return await this.runWithActiveChild(childId, options, run);
|
|
252362
|
+
} finally {
|
|
252363
|
+
this.recordSubagentUsageDelta(parent, child, usageBefore);
|
|
252364
|
+
}
|
|
252365
|
+
}
|
|
252366
|
+
recordSubagentUsageDelta(parent, child, usageBefore) {
|
|
252367
|
+
const usageDelta = buildSubagentUsageDelta(child.usage.data().total, usageBefore);
|
|
252368
|
+
if (usageDelta === null) return;
|
|
252369
|
+
const model = child.config.modelAlias ?? parent.config.modelAlias ?? "subagent";
|
|
252370
|
+
parent.usage.record(model, usageDelta, "session");
|
|
252371
|
+
}
|
|
252357
252372
|
async runPromptTurn(parent, childId, child, profileName, options) {
|
|
252358
252373
|
options.signal.throwIfAborted();
|
|
252359
252374
|
await this.triggerSubagentStart(parent, profileName, options.prompt, options.signal);
|