blun-king-cli 9.1.612 → 9.1.613
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/CHANGELOG.md +8 -1
- package/LIESMICH.txt +1 -1
- package/README.md +1 -1
- package/agent-spine-plugin/src/hook.js +4 -0
- package/agent-spine-plugin/src/lib/preflight.js +27 -9
- package/blun.mjs +1547 -330
- package/bundled-agent-sources.json +2 -2
- package/package.json +1 -1
- package/worker-host.mjs +194 -25
|
@@ -506,7 +506,7 @@
|
|
|
506
506
|
"agent-spine-plugin/src/cli-sharing.js": "4a4700510bfcb75fec34033cd270f3ac8e067a14dbcc7c7220613c365a66eb33",
|
|
507
507
|
"agent-spine-plugin/src/cli.js": "9f0e2c486db488234e84f573804268c4e4e9921a71f59c0d69c2003228ce87a3",
|
|
508
508
|
"agent-spine-plugin/src/codex-reader-launcher.js": "be1b50914e7ea10325b8136dd1926a559541cc9c5f5e2fad16a8c047cc2e8180",
|
|
509
|
-
"agent-spine-plugin/src/hook.js": "
|
|
509
|
+
"agent-spine-plugin/src/hook.js": "cfe335e04fc191180a129e5e416e11181dd2475f208c904059eafc9dc4b5a484",
|
|
510
510
|
"agent-spine-plugin/src/index.js": "ef3a85e94c1e70e054b5afa2ea0ccda28ed4c917ade8aba0388ad859bc9a30b5",
|
|
511
511
|
"agent-spine-plugin/src/lib/acceptance.js": "acace8d372e7580831d9f6352d4dc9a132f222ab288632c4c3d765b23b7a0947",
|
|
512
512
|
"agent-spine-plugin/src/lib/action-lesson-recall.js": "9a36d0602ed98bf0f7a374dc4f7702bffa4d5745fe6d1a05db2e4b327b0c3948",
|
|
@@ -637,7 +637,7 @@
|
|
|
637
637
|
"agent-spine-plugin/src/lib/persona-runtime.js": "1f4c2f44edacc80bf92fc6906c78410ead0e379f2aaf34fed4bda55d4effe393",
|
|
638
638
|
"agent-spine-plugin/src/lib/pre-answer-timeline-recall.js": "50780f8f6ec1578fc06b82cf8f2902a203232964b6745d8155049f5284ff9221",
|
|
639
639
|
"agent-spine-plugin/src/lib/preflight-delivery-id.js": "d1467ac8278de877a44253428c7503991a08cc64f61ec6409f0f153535c7a2a6",
|
|
640
|
-
"agent-spine-plugin/src/lib/preflight.js": "
|
|
640
|
+
"agent-spine-plugin/src/lib/preflight.js": "54b1f576e255df4a2824c9030cfa142c035cfd01b5855dd5668c5859ba624354",
|
|
641
641
|
"agent-spine-plugin/src/lib/project-portfolio.js": "9125715201d97b694827b400c8829cecfbbc142d01b19bd16f92915be08a904f",
|
|
642
642
|
"agent-spine-plugin/src/lib/runtime.js": "e9cb158700de18038651bbb21ac8211fcad8d50b016c7276dd078146a21f5555",
|
|
643
643
|
"agent-spine-plugin/src/lib/selfstarter-core.js": "428ab53db57163b53d6125df914fee14bfbdd555c761cf89993d273f4d92f5a9",
|
package/package.json
CHANGED
package/worker-host.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// BLUN_BUILD_INPUT_SHA256:
|
|
2
|
+
// BLUN_BUILD_INPUT_SHA256:5c7277a864ffcc0a6909494ad5ada6956f900fe23735200c5aca26b1e7d78834
|
|
3
3
|
import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
|
|
4
4
|
import { dirname as __cjsShimDirname } from 'node:path';
|
|
5
5
|
const __filename = __cjsShimFileURLToPath(import.meta.url);
|
|
@@ -1959,16 +1959,6 @@ function measureSerializedRequest(body, requestBytes) {
|
|
|
1959
1959
|
const payload = parsed;
|
|
1960
1960
|
const messages = Array.isArray(payload["messages"]) ? payload["messages"] : [];
|
|
1961
1961
|
const tools = Array.isArray(payload["tools"]) ? payload["tools"] : void 0;
|
|
1962
|
-
let systemMessageBytes = 0;
|
|
1963
|
-
let conversationMessageBytes = 0;
|
|
1964
|
-
let toolResultMessageBytes = 0;
|
|
1965
|
-
for (const message of messages) {
|
|
1966
|
-
const size = Buffer.byteLength(JSON.stringify(message), "utf8");
|
|
1967
|
-
const role = message !== null && typeof message === "object" ? message["role"] : void 0;
|
|
1968
|
-
if (role === "system" || role === "developer") systemMessageBytes += size;
|
|
1969
|
-
else if (role === "tool") toolResultMessageBytes += size;
|
|
1970
|
-
else conversationMessageBytes += size;
|
|
1971
|
-
}
|
|
1972
1962
|
const toolDefinitions = Object.freeze((tools ?? []).map((tool, index) => {
|
|
1973
1963
|
const entry = tool !== null && typeof tool === "object" ? tool : void 0;
|
|
1974
1964
|
const fn = entry?.["function"];
|
|
@@ -1979,6 +1969,44 @@ function measureSerializedRequest(body, requestBytes) {
|
|
|
1979
1969
|
...typeof name === "string" && name.length > 0 && name.length <= 128 ? { name } : {}
|
|
1980
1970
|
});
|
|
1981
1971
|
}));
|
|
1972
|
+
const declaredNames = new Set(toolDefinitions.flatMap((tool) => tool.name === void 0 ? [] : [tool.name]));
|
|
1973
|
+
const callNames = /* @__PURE__ */ new Map();
|
|
1974
|
+
for (const message of messages) {
|
|
1975
|
+
if (message === null || typeof message !== "object" || message["role"] !== "assistant") continue;
|
|
1976
|
+
const calls = message["tool_calls"];
|
|
1977
|
+
if (!Array.isArray(calls)) continue;
|
|
1978
|
+
for (const call of calls) {
|
|
1979
|
+
if (call === null || typeof call !== "object") continue;
|
|
1980
|
+
const entry = call;
|
|
1981
|
+
const fn = entry["function"];
|
|
1982
|
+
const name = fn !== null && typeof fn === "object" ? fn["name"] : void 0;
|
|
1983
|
+
const id = entry["id"];
|
|
1984
|
+
if (typeof id !== "string" || id.length === 0) continue;
|
|
1985
|
+
callNames.set(id, callNames.has(id) ? void 0 : typeof name === "string" && declaredNames.has(name) ? name : void 0);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
let systemMessageBytes = 0;
|
|
1989
|
+
let conversationMessageBytes = 0;
|
|
1990
|
+
let toolResultMessageBytes = 0;
|
|
1991
|
+
const results = /* @__PURE__ */ new Map();
|
|
1992
|
+
for (const message of messages) {
|
|
1993
|
+
const size = Buffer.byteLength(JSON.stringify(message), "utf8");
|
|
1994
|
+
const role = message !== null && typeof message === "object" ? message["role"] : void 0;
|
|
1995
|
+
if (role === "system" || role === "developer") systemMessageBytes += size;
|
|
1996
|
+
else if (role === "tool") {
|
|
1997
|
+
toolResultMessageBytes += size;
|
|
1998
|
+
const id = message["tool_call_id"];
|
|
1999
|
+
const name = typeof id === "string" ? callNames.get(id) : void 0;
|
|
2000
|
+
const key = name ?? "";
|
|
2001
|
+
const previous = results.get(key);
|
|
2002
|
+
results.set(key, {
|
|
2003
|
+
...name === void 0 ? {} : { name },
|
|
2004
|
+
count: (previous?.count ?? 0) + 1,
|
|
2005
|
+
bytes: (previous?.bytes ?? 0) + size
|
|
2006
|
+
});
|
|
2007
|
+
} else conversationMessageBytes += size;
|
|
2008
|
+
}
|
|
2009
|
+
const toolResultByTool = Object.freeze(Array.from(results.values(), (entry) => Object.freeze(entry)));
|
|
1982
2010
|
const toolArrayOverheadBytes = tools === void 0 ? 0 : 2 + Math.max(0, tools.length - 1);
|
|
1983
2011
|
const toolSchemaBytes = toolDefinitions.reduce((sum, tool) => sum + tool.bytes, toolArrayOverheadBytes);
|
|
1984
2012
|
return Object.freeze({
|
|
@@ -1988,6 +2016,7 @@ function measureSerializedRequest(body, requestBytes) {
|
|
|
1988
2016
|
systemMessageBytes,
|
|
1989
2017
|
conversationMessageBytes,
|
|
1990
2018
|
toolResultMessageBytes,
|
|
2019
|
+
...toolResultByTool.length === 0 ? {} : { toolResultByTool },
|
|
1991
2020
|
toolSchemaBytes,
|
|
1992
2021
|
toolDefinitions,
|
|
1993
2022
|
toolArrayOverheadBytes,
|
|
@@ -2372,6 +2401,9 @@ function extractChatCompletionUsage(usage) {
|
|
|
2372
2401
|
const value = usage;
|
|
2373
2402
|
const promptTokens = typeof value["prompt_tokens"] === "number" ? value["prompt_tokens"] : 0;
|
|
2374
2403
|
const completionTokens = typeof value["completion_tokens"] === "number" ? value["completion_tokens"] : 0;
|
|
2404
|
+
const completionDetails = value["completion_tokens_details"];
|
|
2405
|
+
const reportedReasoning = completionDetails !== null && typeof completionDetails === "object" ? completionDetails["reasoning_tokens"] : void 0;
|
|
2406
|
+
const outputReasoning = typeof reportedReasoning === "number" && Number.isSafeInteger(reportedReasoning) && reportedReasoning >= 0 && reportedReasoning <= completionTokens ? reportedReasoning : void 0;
|
|
2375
2407
|
let cachedTokens = 0;
|
|
2376
2408
|
if (typeof value["cached_tokens"] === "number") cachedTokens = value["cached_tokens"];
|
|
2377
2409
|
else if (value["prompt_tokens_details"] !== null && typeof value["prompt_tokens_details"] === "object") {
|
|
@@ -2381,6 +2413,7 @@ function extractChatCompletionUsage(usage) {
|
|
|
2381
2413
|
return {
|
|
2382
2414
|
inputOther: promptTokens - cachedTokens,
|
|
2383
2415
|
output: completionTokens,
|
|
2416
|
+
...outputReasoning === void 0 ? {} : { outputReasoning },
|
|
2384
2417
|
inputCacheRead: cachedTokens,
|
|
2385
2418
|
inputCacheCreation: 0
|
|
2386
2419
|
};
|
|
@@ -3371,9 +3404,11 @@ function emptyUsage() {
|
|
|
3371
3404
|
* Sum two TokenUsage values.
|
|
3372
3405
|
*/
|
|
3373
3406
|
function addUsage(a, b) {
|
|
3407
|
+
const outputReasoning = a.outputReasoning !== void 0 && b.outputReasoning !== void 0 ? a.outputReasoning + b.outputReasoning : a.output === 0 ? b.outputReasoning : b.output === 0 ? a.outputReasoning : void 0;
|
|
3374
3408
|
return {
|
|
3375
3409
|
inputOther: a.inputOther + b.inputOther,
|
|
3376
3410
|
output: a.output + b.output,
|
|
3411
|
+
...outputReasoning === void 0 ? {} : { outputReasoning },
|
|
3377
3412
|
inputCacheRead: a.inputCacheRead + b.inputCacheRead,
|
|
3378
3413
|
inputCacheCreation: a.inputCacheCreation + b.inputCacheCreation
|
|
3379
3414
|
};
|
|
@@ -9783,6 +9818,8 @@ const StringRecordSchema = record$2(string(), string());
|
|
|
9783
9818
|
const ProviderConfigSchema = object({
|
|
9784
9819
|
type: ProviderTypeSchema,
|
|
9785
9820
|
apiKey: string().optional(),
|
|
9821
|
+
memoryWorkspaceId: string().regex(/^blun-[0-9a-f]{64}$/u).optional(),
|
|
9822
|
+
memoryApiKeyHash: string().regex(/^[0-9a-f]{64}$/u).optional(),
|
|
9786
9823
|
baseUrl: string().optional(),
|
|
9787
9824
|
defaultModel: string().optional(),
|
|
9788
9825
|
oauth: OAuthRefSchema.optional(),
|
|
@@ -10331,7 +10368,8 @@ function tokenToWire(token) {
|
|
|
10331
10368
|
expires_at: token.expiresAt,
|
|
10332
10369
|
scope: token.scope,
|
|
10333
10370
|
token_type: token.tokenType,
|
|
10334
|
-
expires_in: token.expiresIn
|
|
10371
|
+
expires_in: token.expiresIn,
|
|
10372
|
+
...token.memoryWorkspaceId === void 0 ? {} : { memory_workspace_id: token.memoryWorkspaceId }
|
|
10335
10373
|
};
|
|
10336
10374
|
}
|
|
10337
10375
|
function tokenFromWire(wire) {
|
|
@@ -10341,7 +10379,8 @@ function tokenFromWire(wire) {
|
|
|
10341
10379
|
expiresAt: typeof wire.expires_at === "number" ? wire.expires_at : 0,
|
|
10342
10380
|
scope: wire.scope ?? "",
|
|
10343
10381
|
tokenType: wire.token_type ?? "",
|
|
10344
|
-
expiresIn: typeof wire.expires_in === "number" ? wire.expires_in : 0
|
|
10382
|
+
expiresIn: typeof wire.expires_in === "number" ? wire.expires_in : 0,
|
|
10383
|
+
...typeof wire.memory_workspace_id === "string" && wire.memory_workspace_id.length > 0 ? { memoryWorkspaceId: wire.memory_workspace_id } : {}
|
|
10345
10384
|
};
|
|
10346
10385
|
}
|
|
10347
10386
|
//#endregion
|
|
@@ -12732,6 +12771,27 @@ var OAuthManager = class {
|
|
|
12732
12771
|
const state = await this.loadState();
|
|
12733
12772
|
return state.kind === "valid" ? state.token.accessToken : void 0;
|
|
12734
12773
|
}
|
|
12774
|
+
async getCachedMemoryWorkspaceId() {
|
|
12775
|
+
const state = await this.loadState();
|
|
12776
|
+
return state.kind === "valid" && state.token.expiresAt > this.now() ? state.token.memoryWorkspaceId : void 0;
|
|
12777
|
+
}
|
|
12778
|
+
async cacheMemoryWorkspaceId(workspaceId) {
|
|
12779
|
+
if (workspaceId.length === 0) return false;
|
|
12780
|
+
const release = await this.acquireRefreshLock();
|
|
12781
|
+
try {
|
|
12782
|
+
const state = await this.loadState();
|
|
12783
|
+
if (state.kind !== "valid" || state.token.expiresAt <= this.now()) return false;
|
|
12784
|
+
if (state.token.memoryWorkspaceId === workspaceId) return true;
|
|
12785
|
+
if (state.token.memoryWorkspaceId !== void 0) return false;
|
|
12786
|
+
await this.storage.save(this.config.name, {
|
|
12787
|
+
...state.token,
|
|
12788
|
+
memoryWorkspaceId: workspaceId
|
|
12789
|
+
});
|
|
12790
|
+
return true;
|
|
12791
|
+
} finally {
|
|
12792
|
+
await release();
|
|
12793
|
+
}
|
|
12794
|
+
}
|
|
12735
12795
|
async logout() {
|
|
12736
12796
|
await this.inFlightRefresh?.promise.catch(() => void 0);
|
|
12737
12797
|
const release = await this.acquireRefreshLock();
|
|
@@ -12799,7 +12859,10 @@ var OAuthManager = class {
|
|
|
12799
12859
|
if (activeToken.refreshToken.length === 0) throw new OAuthUnauthorizedError(`Token for "${this.config.name}" has no refresh_token; re-login required.`);
|
|
12800
12860
|
try {
|
|
12801
12861
|
const refreshed = await this.refreshImpl(this.config, activeToken.refreshToken);
|
|
12802
|
-
await this.storage.save(this.config.name,
|
|
12862
|
+
await this.storage.save(this.config.name, {
|
|
12863
|
+
...refreshed,
|
|
12864
|
+
memoryWorkspaceId: activeToken.memoryWorkspaceId
|
|
12865
|
+
});
|
|
12803
12866
|
this.notifyRefresh({ success: true });
|
|
12804
12867
|
return refreshed.accessToken;
|
|
12805
12868
|
} catch (error) {
|
|
@@ -14176,6 +14239,16 @@ var BlunOAuthToolkit = class {
|
|
|
14176
14239
|
hasToken: await this.managerFor(name, oauthKey, oauthHost).hasToken()
|
|
14177
14240
|
}] };
|
|
14178
14241
|
}
|
|
14242
|
+
async getCachedMemoryWorkspaceId(oauthRef) {
|
|
14243
|
+
const oauthHost = this.oauthHostFor(oauthRef);
|
|
14244
|
+
const oauthKey = oauthRef?.key ?? this.defaultOAuthKey(void 0, oauthHost);
|
|
14245
|
+
return this.managerFor(BLUN_PROVIDER_NAME$1, oauthKey, oauthHost).getCachedMemoryWorkspaceId();
|
|
14246
|
+
}
|
|
14247
|
+
async cacheMemoryWorkspaceId(workspaceId, oauthRef) {
|
|
14248
|
+
const oauthHost = this.oauthHostFor(oauthRef);
|
|
14249
|
+
const oauthKey = oauthRef?.key ?? this.defaultOAuthKey(void 0, oauthHost);
|
|
14250
|
+
return this.managerFor(BLUN_PROVIDER_NAME$1, oauthKey, oauthHost).cacheMemoryWorkspaceId(workspaceId);
|
|
14251
|
+
}
|
|
14179
14252
|
async login(providerName, options = {}) {
|
|
14180
14253
|
const name = providerName ?? "managed:blun";
|
|
14181
14254
|
const oauthHost = this.oauthHostFor(options.oauthRef, options.oauthHost);
|
|
@@ -16243,6 +16316,8 @@ function providerToToml(provider, rawProvider) {
|
|
|
16243
16316
|
for (const key of [
|
|
16244
16317
|
"type",
|
|
16245
16318
|
"apiKey",
|
|
16319
|
+
"memoryWorkspaceId",
|
|
16320
|
+
"memoryApiKeyHash",
|
|
16246
16321
|
"baseUrl",
|
|
16247
16322
|
"defaultModel",
|
|
16248
16323
|
"oauth",
|
|
@@ -230295,7 +230370,7 @@ var FullCompaction = class {
|
|
|
230295
230370
|
}
|
|
230296
230371
|
requestBodyByteBudget(messages, context) {
|
|
230297
230372
|
const limit = this.agent.blunConfig?.loopControl?.maxRequestHistoryBytes;
|
|
230298
|
-
if (!this.agent.config.hasProvider || this.strategy.compactionBudgetTokens === void 0 || limit
|
|
230373
|
+
if (!this.agent.config.hasProvider || this.strategy.compactionBudgetTokens === void 0 || limit !== void 0 && (!Number.isSafeInteger(limit) || limit <= 0)) return void 0;
|
|
230299
230374
|
const model = this.agent.activeResponderModel ?? this.agent.config.modelAlias;
|
|
230300
230375
|
if (model === void 0 || this.agent.config.runtimeModel(model).provider.name !== "blun") return void 0;
|
|
230301
230376
|
const systemPrompt = context.systemPrompt ?? this.agent.effectiveSystemPrompt;
|
|
@@ -230313,7 +230388,7 @@ var FullCompaction = class {
|
|
|
230313
230388
|
if (Buffer.byteLength(JSON.stringify({
|
|
230314
230389
|
systemPrompt,
|
|
230315
230390
|
messages: []
|
|
230316
|
-
}), "utf8")
|
|
230391
|
+
}), "utf8") >= BLUN_COMPACTION_REQUEST_BUDGET_BYTES) return void 0;
|
|
230317
230392
|
return {
|
|
230318
230393
|
usedRequestBytesEstimate: Buffer.byteLength(JSON.stringify({
|
|
230319
230394
|
systemPrompt,
|
|
@@ -230673,7 +230748,10 @@ var FullCompaction = class {
|
|
|
230673
230748
|
dropOrphanResults: true
|
|
230674
230749
|
}), createUserMessage(requestInstruction)], capability));
|
|
230675
230750
|
};
|
|
230676
|
-
const estimateRequestBytes = (messages) => Buffer.byteLength(JSON.stringify(
|
|
230751
|
+
const estimateRequestBytes = (messages) => Buffer.byteLength(JSON.stringify({
|
|
230752
|
+
systemPrompt: this.agent.effectiveSystemPrompt,
|
|
230753
|
+
messages
|
|
230754
|
+
}), "utf8");
|
|
230677
230755
|
while (true) {
|
|
230678
230756
|
signal.throwIfAborted();
|
|
230679
230757
|
if (hierarchicalPassCount >= MAX_HIERARCHICAL_COMPACTION_PASSES) throw new BlunError(ErrorCodes.COMPACTION_FAILED, `Compaction stopped after ${String(MAX_HIERARCHICAL_COMPACTION_PASSES)} staged requests without reaching a final summary. The conversation history was not changed.`, { details: {
|
|
@@ -239259,10 +239337,27 @@ var import_turn_tool_performance_policy = (/* @__PURE__ */ __commonJSMin(((expor
|
|
|
239259
239337
|
function relatedSearchTerms(token) {
|
|
239260
239338
|
return TOOL_SEARCH_RELATED_TERM_GROUPS.find((terms) => terms.includes(token)) || [token];
|
|
239261
239339
|
}
|
|
239340
|
+
function withoutFencedCode(value) {
|
|
239341
|
+
const visibleLines = [];
|
|
239342
|
+
let fence = null;
|
|
239343
|
+
for (const line of String(value || "").split(/\r?\n/)) {
|
|
239344
|
+
const marker = line.match(/^ {0,3}(`{3,}|~{3,})/u)?.[1];
|
|
239345
|
+
if (fence) {
|
|
239346
|
+
if (marker?.[0] === fence[0] && marker.length >= fence.length && /^ {0,3}(?:`{3,}|~{3,})[ \t]*$/u.test(line)) fence = null;
|
|
239347
|
+
continue;
|
|
239348
|
+
}
|
|
239349
|
+
if (marker) {
|
|
239350
|
+
fence = marker;
|
|
239351
|
+
continue;
|
|
239352
|
+
}
|
|
239353
|
+
visibleLines.push(line);
|
|
239354
|
+
}
|
|
239355
|
+
return visibleLines.join("\n");
|
|
239356
|
+
}
|
|
239262
239357
|
function rankingIntentTexts(value) {
|
|
239263
239358
|
const text = String(value || "");
|
|
239264
239359
|
const channelBodies = [...text.matchAll(/(?:^|\r?\n)<channel\b[^>]*>\r?\n([\s\S]*?)\r?\n<\/channel>(?=\r?\n|$)/giu)].map((match) => match[1]);
|
|
239265
|
-
return (channelBodies.length > 0 ? channelBodies : [text]).map((intentText) => normalizeDeferredToolQuery(intentText.replace(TOOL_RANK_EMBEDDED_CONTENT_RE, " ")));
|
|
239360
|
+
return (channelBodies.length > 0 ? channelBodies : [text]).map((intentText) => normalizeDeferredToolQuery(withoutFencedCode(intentText.replace(TOOL_RANK_EMBEDDED_CONTENT_RE, " "))));
|
|
239266
239361
|
}
|
|
239267
239362
|
function rankingTokens(value) {
|
|
239268
239363
|
return [...new Set(String(value || "").normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}]{3,}/gu) || [])].filter((token) => !TOOL_RANK_STOP_WORDS.has(token));
|
|
@@ -250149,7 +250244,8 @@ function logStepTiming(log, turnId, step, response) {
|
|
|
250149
250244
|
inputOtherTokens: response.usage.inputOther,
|
|
250150
250245
|
cacheReadTokens: response.usage.inputCacheRead,
|
|
250151
250246
|
cacheCreationTokens: response.usage.inputCacheCreation,
|
|
250152
|
-
outputTokens: response.usage.output
|
|
250247
|
+
outputTokens: response.usage.output,
|
|
250248
|
+
...response.usage.outputReasoning === void 0 ? {} : { outputReasoningTokens: response.usage.outputReasoning }
|
|
250153
250249
|
});
|
|
250154
250250
|
}
|
|
250155
250251
|
function deriveStepStopReason(response) {
|
|
@@ -251137,6 +251233,7 @@ const MCP_OAUTH_AUTHORIZATION_URL_TOOL_UPDATE = "mcp.oauth.authorization_url";
|
|
|
251137
251233
|
const tokenUsageSchema = object({
|
|
251138
251234
|
inputOther: number$1(),
|
|
251139
251235
|
output: number$1(),
|
|
251236
|
+
outputReasoning: number$1().optional(),
|
|
251140
251237
|
inputCacheRead: number$1(),
|
|
251141
251238
|
inputCacheCreation: number$1()
|
|
251142
251239
|
});
|
|
@@ -267820,6 +267917,10 @@ var TurnFlow = class {
|
|
|
267820
267917
|
signal.throwIfAborted();
|
|
267821
267918
|
const blockResult = renderUserPromptHookBlockResult(promptHookResults);
|
|
267822
267919
|
if (blockResult !== void 0) {
|
|
267920
|
+
this.agent.log.warn("turn blocked by UserPromptSubmit hook", {
|
|
267921
|
+
turnId,
|
|
267922
|
+
reason: blockResult.message
|
|
267923
|
+
});
|
|
267823
267924
|
this.agent.context.appendMessage({
|
|
267824
267925
|
role: "assistant",
|
|
267825
267926
|
content: [{
|
|
@@ -268037,6 +268138,17 @@ var TurnFlow = class {
|
|
|
268037
268138
|
signal.throwIfAborted();
|
|
268038
268139
|
if (stopBlock !== void 0) {
|
|
268039
268140
|
stopHookContinuationUsed = true;
|
|
268141
|
+
this.agent.log.warn("turn continuation blocked by Stop hook", {
|
|
268142
|
+
turnId,
|
|
268143
|
+
reason: stopBlock.reason
|
|
268144
|
+
});
|
|
268145
|
+
this.agent.emitEvent({
|
|
268146
|
+
type: "hook.result",
|
|
268147
|
+
turnId,
|
|
268148
|
+
hookEvent: "Stop",
|
|
268149
|
+
content: stopBlock.reason,
|
|
268150
|
+
blocked: true
|
|
268151
|
+
});
|
|
268040
268152
|
this.agent.context.appendUserMessage([{
|
|
268041
268153
|
type: "text",
|
|
268042
268154
|
text: stopBlock.reason
|
|
@@ -271539,6 +271651,7 @@ var FallbackLLM = class {
|
|
|
271539
271651
|
throw new Error("Fallback request preparation requires a fresh request boundary.");
|
|
271540
271652
|
}
|
|
271541
271653
|
let requestParams = params;
|
|
271654
|
+
let messagesReady = false;
|
|
271542
271655
|
const rebuildRequestMessages = async () => {
|
|
271543
271656
|
const messages = await rebuildMessages();
|
|
271544
271657
|
const suffix = requestParams.boundaryMessageSuffix;
|
|
@@ -271547,7 +271660,14 @@ var FallbackLLM = class {
|
|
|
271547
271660
|
while (true) {
|
|
271548
271661
|
const candidate = this.current;
|
|
271549
271662
|
try {
|
|
271550
|
-
|
|
271663
|
+
const prepared = await this.prepareRequest?.(candidate, requestParams, rebuildRequestMessages);
|
|
271664
|
+
if (prepared !== void 0) if ("messagesReady" in prepared) {
|
|
271665
|
+
requestParams = prepared.params;
|
|
271666
|
+
messagesReady = true;
|
|
271667
|
+
} else {
|
|
271668
|
+
requestParams = prepared;
|
|
271669
|
+
messagesReady = false;
|
|
271670
|
+
}
|
|
271551
271671
|
} catch (error) {
|
|
271552
271672
|
if (!isFallbackCandidateError(error) && !isUnavailableFallbackCandidate(error)) throw error;
|
|
271553
271673
|
const nextIndex = this.findNextCandidateIndex();
|
|
@@ -271557,13 +271677,14 @@ var FallbackLLM = class {
|
|
|
271557
271677
|
...requestParams,
|
|
271558
271678
|
messages: await rebuildRequestMessages()
|
|
271559
271679
|
};
|
|
271680
|
+
messagesReady = false;
|
|
271560
271681
|
requestParams.signal.throwIfAborted();
|
|
271561
271682
|
this.currentIndex = nextIndex;
|
|
271562
271683
|
this.onModelChanged(this.current.alias);
|
|
271563
271684
|
continue;
|
|
271564
271685
|
}
|
|
271565
271686
|
requestParams.signal.throwIfAborted();
|
|
271566
|
-
const messages = await rebuildRequestMessages();
|
|
271687
|
+
const messages = messagesReady ? requestParams.messages : await rebuildRequestMessages();
|
|
271567
271688
|
requestParams.signal.throwIfAborted();
|
|
271568
271689
|
return {
|
|
271569
271690
|
...requestParams,
|
|
@@ -271826,6 +271947,11 @@ var LlmRequestLogger = class {
|
|
|
271826
271947
|
systemMessageBytes: breakdown.systemMessageBytes,
|
|
271827
271948
|
conversationMessageBytes: breakdown.conversationMessageBytes,
|
|
271828
271949
|
toolResultMessageBytes: breakdown.toolResultMessageBytes,
|
|
271950
|
+
...breakdown.toolResultByTool === void 0 ? {} : { toolResultByTool: breakdown.toolResultByTool.map((tool) => ({
|
|
271951
|
+
count: tool.count,
|
|
271952
|
+
bytes: tool.bytes,
|
|
271953
|
+
...tool.name === void 0 ? {} : { name: tool.name }
|
|
271954
|
+
})) },
|
|
271829
271955
|
toolSchemaBytes: breakdown.toolSchemaBytes,
|
|
271830
271956
|
otherBytes: breakdown.otherBytes,
|
|
271831
271957
|
...breakdown.toolArrayOverheadBytes === void 0 ? {} : { toolArrayOverheadBytes: breakdown.toolArrayOverheadBytes },
|
|
@@ -272163,11 +272289,18 @@ var Agent$1 = class {
|
|
|
272163
272289
|
systemPrompt,
|
|
272164
272290
|
tools: params.tools
|
|
272165
272291
|
}).eligible ? params.tools.filter((tool) => tool.name !== "CompactConversation") : params.tools;
|
|
272166
|
-
this.turn.commitPendingSteers(steers);
|
|
272167
|
-
|
|
272292
|
+
const steersCommitted = this.turn.commitPendingSteers(steers);
|
|
272293
|
+
if (compacted || steersCommitted) params = {
|
|
272168
272294
|
...params,
|
|
272169
|
-
|
|
272170
|
-
|
|
272295
|
+
messages: await rebuildMessages()
|
|
272296
|
+
};
|
|
272297
|
+
return {
|
|
272298
|
+
params: {
|
|
272299
|
+
...params,
|
|
272300
|
+
systemPrompt,
|
|
272301
|
+
tools
|
|
272302
|
+
},
|
|
272303
|
+
messagesReady: true
|
|
272171
272304
|
};
|
|
272172
272305
|
}, (candidate, _params, error) => {
|
|
272173
272306
|
this.fullCompaction.observeContextOverflow(error, candidate.alias);
|
|
@@ -347961,6 +348094,39 @@ var BlunAuthFacade = class {
|
|
|
347961
348094
|
}
|
|
347962
348095
|
return this.toolkit.status(providerName, this.resolveRuntimeManagedAuth(providerName).oauthRef);
|
|
347963
348096
|
}
|
|
348097
|
+
async getCachedMemoryWorkspaceId() {
|
|
348098
|
+
const apiKey = nonEmpty(this.resolveManagedAuth(BLUN_PROVIDER_NAME$1).apiKey);
|
|
348099
|
+
if (apiKey !== void 0) {
|
|
348100
|
+
const provider = readConfigFileForUpdate(this.options.configPath).providers[BLUN_PROVIDER_NAME$1];
|
|
348101
|
+
if (provider?.apiKey !== apiKey || provider.memoryApiKeyHash !== memoryApiKeyHash(apiKey)) return;
|
|
348102
|
+
return provider.memoryWorkspaceId;
|
|
348103
|
+
}
|
|
348104
|
+
return this.toolkit.getCachedMemoryWorkspaceId(this.resolveRuntimeManagedAuth(BLUN_PROVIDER_NAME$1).oauthRef);
|
|
348105
|
+
}
|
|
348106
|
+
async cacheMemoryWorkspaceId(workspaceId) {
|
|
348107
|
+
const apiKey = nonEmpty(this.resolveManagedAuth(BLUN_PROVIDER_NAME$1).apiKey);
|
|
348108
|
+
if (apiKey !== void 0) {
|
|
348109
|
+
const hash = memoryApiKeyHash(apiKey);
|
|
348110
|
+
return mutateConfigFile(this.options.configPath, (config) => {
|
|
348111
|
+
const provider = config.providers[BLUN_PROVIDER_NAME$1];
|
|
348112
|
+
if (provider?.apiKey !== apiKey) return {
|
|
348113
|
+
config,
|
|
348114
|
+
result: false
|
|
348115
|
+
};
|
|
348116
|
+
if (provider.memoryApiKeyHash === hash && provider.memoryWorkspaceId !== void 0 && provider.memoryWorkspaceId !== workspaceId) return {
|
|
348117
|
+
config,
|
|
348118
|
+
result: false
|
|
348119
|
+
};
|
|
348120
|
+
provider.memoryApiKeyHash = hash;
|
|
348121
|
+
provider.memoryWorkspaceId = workspaceId;
|
|
348122
|
+
return {
|
|
348123
|
+
config,
|
|
348124
|
+
result: true
|
|
348125
|
+
};
|
|
348126
|
+
});
|
|
348127
|
+
}
|
|
348128
|
+
return this.toolkit.cacheMemoryWorkspaceId(workspaceId, this.resolveRuntimeManagedAuth(BLUN_PROVIDER_NAME$1).oauthRef);
|
|
348129
|
+
}
|
|
347964
348130
|
async login(providerName = BLUN_PROVIDER_NAME$1, options = {}) {
|
|
347965
348131
|
const auth = this.resolveManagedAuth(providerName);
|
|
347966
348132
|
const loginAuth = resolveBlunCodeLoginAuth({
|
|
@@ -348266,6 +348432,9 @@ function nonEmpty(value) {
|
|
|
348266
348432
|
const normalized = value?.trim();
|
|
348267
348433
|
return normalized === void 0 || normalized.length === 0 ? void 0 : normalized;
|
|
348268
348434
|
}
|
|
348435
|
+
function memoryApiKeyHash(apiKey) {
|
|
348436
|
+
return createHash("sha256").update(apiKey).digest("hex");
|
|
348437
|
+
}
|
|
348269
348438
|
function transitionAggregateError(message, primary, secondary) {
|
|
348270
348439
|
return new AggregateError([primary, secondary], message, { cause: primary });
|
|
348271
348440
|
}
|