github-router 0.3.370 → 0.3.371
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/ado-tools-512UGB6R.js +1 -0
- package/dist/{attribution-settings-Cppl9atx.js → attribution-settings-Beer9wsJ.js} +5 -5
- package/dist/{attribution-settings-Cppl9atx.js.map → attribution-settings-Beer9wsJ.js.map} +1 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{claude-B3qNFwtc.js → claude-CAYTTiyt.js} +9 -9
- package/dist/{claude-B3qNFwtc.js.map → claude-CAYTTiyt.js.map} +1 -1
- package/dist/{claude-md-injection-K3DKhsfI.js → claude-md-injection-D1aMjvb_.js} +2 -2
- package/dist/{claude-md-injection-K3DKhsfI.js.map → claude-md-injection-D1aMjvb_.js.map} +1 -1
- package/dist/{codex-3DEffjlm.js → codex-CALX-qG4.js} +5 -5
- package/dist/{codex-3DEffjlm.js.map → codex-CALX-qG4.js.map} +1 -1
- package/dist/engine-CSAEqj2p.js +1 -0
- package/dist/{gate-discovery-BV6UGGVd.js → gate-discovery-CITKjhsD.js} +2 -2
- package/dist/{gate-discovery-BV6UGGVd.js.map → gate-discovery-CITKjhsD.js.map} +1 -1
- package/dist/{internal-stop-hook-covotLvl.js → internal-stop-hook-DT27bzH7.js} +2 -2
- package/dist/{internal-stop-hook-covotLvl.js.map → internal-stop-hook-DT27bzH7.js.map} +1 -1
- package/dist/main.js +6 -6
- package/dist/{peer-mcp-personas-6zWkXHQW.js → peer-mcp-personas-D7vaM-V5.js} +352 -34
- package/dist/peer-mcp-personas-D7vaM-V5.js.map +1 -0
- package/dist/{pi-DJJlBHP9.js → pi-D4LrdubN.js} +6 -6
- package/dist/{pi-DJJlBHP9.js.map → pi-D4LrdubN.js.map} +1 -1
- package/dist/{provision-C_aTowyW.js → provision-DonGTIfK.js} +2 -2
- package/dist/{provision-C_aTowyW.js.map → provision-DonGTIfK.js.map} +1 -1
- package/dist/{serve-CfizTkRS.js → serve-jzmQ8KEE.js} +6 -6
- package/dist/{serve-CfizTkRS.js.map → serve-jzmQ8KEE.js.map} +1 -1
- package/dist/{server-setup-rm8ELtYa.js → server-setup-wWidNq5m.js} +20 -10
- package/dist/{server-setup-rm8ELtYa.js.map → server-setup-wWidNq5m.js.map} +1 -1
- package/dist/{start-D7RcHG8T.js → start-CTluQxu5.js} +3 -3
- package/dist/{start-D7RcHG8T.js.map → start-CTluQxu5.js.map} +1 -1
- package/dist/workiq-tools-CDLIrILp.js +1 -0
- package/package.json +1 -1
- package/dist/ado-tools-B5MNQMFs.js +0 -1
- package/dist/engine-C2YCclx0.js +0 -1
- package/dist/peer-mcp-personas-6zWkXHQW.js.map +0 -1
- package/dist/workiq-tools-BeTneKco.js +0 -1
|
@@ -18461,7 +18461,7 @@ const GPT56_EXPLICIT_CACHE_MODELS = /* @__PURE__ */ new Set([
|
|
|
18461
18461
|
"gpt-5.6-luna"
|
|
18462
18462
|
]);
|
|
18463
18463
|
const priorSignatures = /* @__PURE__ */ new Map();
|
|
18464
|
-
function nonNegativeInt(value) {
|
|
18464
|
+
function nonNegativeInt$1(value) {
|
|
18465
18465
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return 0;
|
|
18466
18466
|
return Math.floor(value);
|
|
18467
18467
|
}
|
|
@@ -18504,15 +18504,15 @@ function normalizeOpenAIUsage(usage) {
|
|
|
18504
18504
|
cacheWrite: 0,
|
|
18505
18505
|
totalTokens: 0
|
|
18506
18506
|
};
|
|
18507
|
-
const totalInput = nonNegativeInt(usage.input_tokens ?? usage.prompt_tokens);
|
|
18508
|
-
const output = nonNegativeInt(usage.output_tokens ?? usage.completion_tokens);
|
|
18507
|
+
const totalInput = nonNegativeInt$1(usage.input_tokens ?? usage.prompt_tokens);
|
|
18508
|
+
const output = nonNegativeInt$1(usage.output_tokens ?? usage.completion_tokens);
|
|
18509
18509
|
const details = usageDetails(usage);
|
|
18510
|
-
const cacheRead = Math.min(totalInput, nonNegativeInt(details.cached_tokens));
|
|
18510
|
+
const cacheRead = Math.min(totalInput, nonNegativeInt$1(details.cached_tokens));
|
|
18511
18511
|
const remaining = Math.max(0, totalInput - cacheRead);
|
|
18512
|
-
const cacheWrite = Math.min(remaining, nonNegativeInt(details.cache_write_tokens ?? details.cache_creation_tokens));
|
|
18512
|
+
const cacheWrite = Math.min(remaining, nonNegativeInt$1(details.cache_write_tokens ?? details.cache_creation_tokens));
|
|
18513
18513
|
const uncachedInput = Math.max(0, totalInput - cacheRead - cacheWrite);
|
|
18514
|
-
const reportedTotal = nonNegativeInt(usage.total_tokens);
|
|
18515
|
-
const cacheTtlSeconds = nonNegativeInt(details.cache_ttl_seconds);
|
|
18514
|
+
const reportedTotal = nonNegativeInt$1(usage.total_tokens);
|
|
18515
|
+
const cacheTtlSeconds = nonNegativeInt$1(details.cache_ttl_seconds);
|
|
18516
18516
|
return {
|
|
18517
18517
|
totalInput,
|
|
18518
18518
|
uncachedInput,
|
|
@@ -30069,6 +30069,257 @@ function handleMcpDelete(c) {
|
|
|
30069
30069
|
return c.body(null, 200);
|
|
30070
30070
|
}
|
|
30071
30071
|
//#endregion
|
|
30072
|
+
//#region src/lib/anthropic-usage.ts
|
|
30073
|
+
const ENCODER$2 = new TextEncoder();
|
|
30074
|
+
const DECODER = new TextDecoder();
|
|
30075
|
+
/** The usage fields this module reasons about, in log order. */
|
|
30076
|
+
const USAGE_KEYS = [
|
|
30077
|
+
"input_tokens",
|
|
30078
|
+
"cache_creation_input_tokens",
|
|
30079
|
+
"cache_read_input_tokens",
|
|
30080
|
+
"output_tokens"
|
|
30081
|
+
];
|
|
30082
|
+
/**
|
|
30083
|
+
* Cap on a single un-terminated SSE record held in the transform buffer.
|
|
30084
|
+
* A record that grows past this is emitted verbatim rather than buffered
|
|
30085
|
+
* forever, so a pathological upstream event is passed through instead of
|
|
30086
|
+
* being truncated or held in memory.
|
|
30087
|
+
*/
|
|
30088
|
+
const MAX_PENDING_RECORD_BYTES = 1 << 20;
|
|
30089
|
+
function nonNegativeInt(value) {
|
|
30090
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return 0;
|
|
30091
|
+
return Math.floor(value);
|
|
30092
|
+
}
|
|
30093
|
+
/**
|
|
30094
|
+
* True when the operator has opted out of the Anthropic usage rewrite.
|
|
30095
|
+
*
|
|
30096
|
+
* The rewrite targets an upstream that reports `input_tokens` as the TOTAL
|
|
30097
|
+
* prompt with the cached prefix as a DETAIL of that total (OpenAI semantics)
|
|
30098
|
+
* rather than as the uncached remainder (the Anthropic contract). BOTH shapes
|
|
30099
|
+
* have been measured in real traffic through this proxy: session `ec65e3f9`
|
|
30100
|
+
* was inclusive on the native Copilot path, the same path captured exclusive
|
|
30101
|
+
* on 2026-11-05, and the local endpoint of session `a1ab11a5` was inclusive.
|
|
30102
|
+
* An operator pointing `--localurl` at an upstream whose shape the
|
|
30103
|
+
* `input < cached` guard cannot discriminate can disable the rewrite here.
|
|
30104
|
+
*/
|
|
30105
|
+
function anthropicUsageNormalizeDisabled() {
|
|
30106
|
+
return parseBoolEnv(process.env.GH_ROUTER_DISABLE_ANTHROPIC_USAGE_NORMALIZE) === true;
|
|
30107
|
+
}
|
|
30108
|
+
/**
|
|
30109
|
+
* Rewrite an Anthropic-shaped `usage` object so its three input buckets are
|
|
30110
|
+
* mutually exclusive, which is what Anthropic clients (and Claude Code's
|
|
30111
|
+
* context meter) sum.
|
|
30112
|
+
*
|
|
30113
|
+
* The problem this fixes: some upstreams report `input_tokens` INCLUSIVE of
|
|
30114
|
+
* `cache_read_input_tokens` — OpenAI semantics inside an Anthropic-shaped
|
|
30115
|
+
* usage object. Claude Code computes context size as `input_tokens +
|
|
30116
|
+
* cache_creation_input_tokens + cache_read_input_tokens + output_tokens`, so
|
|
30117
|
+
* forwarding the inclusive figure counts the cached prefix twice. Measured on
|
|
30118
|
+
* a warm turn in session `ec65e3f9` (native Copilot path): turn 1 `55931/0`
|
|
30119
|
+
* followed by turn 2 `56423/55808` across an exchange whose entire new
|
|
30120
|
+
* payload was under 2 KB. Under the exclusive reading that turn would have
|
|
30121
|
+
* added ~56,300 tokens; inclusive predicts +492, which is what happened. The
|
|
30122
|
+
* local egress is inclusive too: a 2026-11-05 capture of `-m local` showed a
|
|
30123
|
+
* warm `message_delta` of `input_tokens=45620 cache_read_input_tokens=45440`,
|
|
30124
|
+
* and the client meter read 91,060 for a 45,620-token prompt. The doubled
|
|
30125
|
+
* meter halves the effective context window and makes autocompact thrash on
|
|
30126
|
+
* sessions with a large static prefix.
|
|
30127
|
+
*
|
|
30128
|
+
* NOT every upstream is inclusive, and the Copilot path is not guaranteed to
|
|
30129
|
+
* be: an advisor-off capture of it on 2026-11-05 reported `message_start
|
|
30130
|
+
* input_tokens=2 cache_creation_input_tokens=66941`, which only the exclusive
|
|
30131
|
+
* reading explains. Every capture so far delivered `input_tokens` and the
|
|
30132
|
+
* cache buckets on the SAME SSE record, so the guard below is what
|
|
30133
|
+
* discriminates the two shapes rather than across-frame reassembly.
|
|
30134
|
+
*
|
|
30135
|
+
* The math mirrors `normalizeOpenAIUsage` in `~/lib/prompt-cache`:
|
|
30136
|
+
* `uncached = total - cacheRead - cacheWrite`.
|
|
30137
|
+
*
|
|
30138
|
+
* The guard is what lets this run unconditionally. An exclusive (conformant)
|
|
30139
|
+
* upstream reports the uncached remainder as `input_tokens`, which on a warm
|
|
30140
|
+
* turn is SMALLER than the cached prefix — a shape that is impossible under
|
|
30141
|
+
* inclusive semantics. Such a response is left byte-for-byte alone. A cold
|
|
30142
|
+
* turn reports no cache at all, where both conventions agree, so it is a
|
|
30143
|
+
* no-op too.
|
|
30144
|
+
*
|
|
30145
|
+
* Residual ambiguity: an exclusive upstream whose uncached remainder exceeds
|
|
30146
|
+
* its cached prefix (`input >= cached`) is misread as inclusive and
|
|
30147
|
+
* under-reported by the cached total. That takes a single turn adding more
|
|
30148
|
+
* new tokens than the whole cached prefix, and it applies to EITHER egress,
|
|
30149
|
+
* since the native Copilot path has been measured exclusive. The error
|
|
30150
|
+
* direction is the safe one: the meter under-reads, so the client compacts
|
|
30151
|
+
* later rather than earlier.
|
|
30152
|
+
* `GH_ROUTER_DISABLE_ANTHROPIC_USAGE_NORMALIZE` exists for an upstream whose
|
|
30153
|
+
* shape the guard cannot discriminate.
|
|
30154
|
+
*
|
|
30155
|
+
* CALL ONCE PER USAGE OBJECT. The rewrite is not idempotent: a second pass
|
|
30156
|
+
* over an already-corrected object subtracts the cache buckets again whenever
|
|
30157
|
+
* the remainder is at least the cached total. Every caller applies it exactly
|
|
30158
|
+
* once — one call per SSE record, one call per non-streaming response, and a
|
|
30159
|
+
* freshly built map per advisor `message_delta`.
|
|
30160
|
+
*
|
|
30161
|
+
* Never throws. Returns true iff `usage.input_tokens` was rewritten.
|
|
30162
|
+
*/
|
|
30163
|
+
function normalizeAnthropicUsageInPlace(usage) {
|
|
30164
|
+
if (!usage || typeof usage !== "object" || Array.isArray(usage)) return false;
|
|
30165
|
+
const record = usage;
|
|
30166
|
+
const input = nonNegativeInt(record.input_tokens);
|
|
30167
|
+
const cached = nonNegativeInt(record.cache_read_input_tokens) + nonNegativeInt(record.cache_creation_input_tokens);
|
|
30168
|
+
if (cached <= 0) return false;
|
|
30169
|
+
if (input < cached) return false;
|
|
30170
|
+
const next = Math.max(0, input - cached);
|
|
30171
|
+
if (next === record.input_tokens) return false;
|
|
30172
|
+
record.input_tokens = next;
|
|
30173
|
+
return true;
|
|
30174
|
+
}
|
|
30175
|
+
/**
|
|
30176
|
+
* Length of the SSE record terminator beginning at `index` (a `\n`), or 0 if
|
|
30177
|
+
* no blank-line terminator starts there. Handles both `\n\n` and `\r\n\r\n`.
|
|
30178
|
+
*/
|
|
30179
|
+
function terminatorLengthAt(buffer, index) {
|
|
30180
|
+
if (buffer[index + 1] === 10) return 2;
|
|
30181
|
+
if (buffer[index + 1] === 13 && buffer[index + 2] === 10) return 3;
|
|
30182
|
+
return 0;
|
|
30183
|
+
}
|
|
30184
|
+
/** First complete SSE record terminator in `buffer`, if any. */
|
|
30185
|
+
function findRecordTerminator(buffer) {
|
|
30186
|
+
for (let index = 0; index < buffer.byteLength - 1; index++) {
|
|
30187
|
+
if (buffer[index] !== 10) continue;
|
|
30188
|
+
const length = terminatorLengthAt(buffer, index);
|
|
30189
|
+
if (length > 0 && index + length <= buffer.byteLength) return {
|
|
30190
|
+
index,
|
|
30191
|
+
length
|
|
30192
|
+
};
|
|
30193
|
+
}
|
|
30194
|
+
}
|
|
30195
|
+
/**
|
|
30196
|
+
* Opt-in wire diagnostic (`GH_ROUTER_LOG_ANTHROPIC_USAGE_FRAMES=1`), matching
|
|
30197
|
+
* the `GH_ROUTER_LOG_FIELDS` / `GH_ROUTER_LOG_CACHE` convention.
|
|
30198
|
+
*
|
|
30199
|
+
* The rewrite rests on an upstream wire detail Copilot does not version:
|
|
30200
|
+
* whether `input_tokens` and the cache buckets arrive on the SAME SSE record.
|
|
30201
|
+
* Only a record carrying both is rewritten, so a split shape would silently
|
|
30202
|
+
* turn the rewrite into a no-op — and no unit test can observe the real
|
|
30203
|
+
* upstream shape. Logs one line per `message_start` / `message_delta` with
|
|
30204
|
+
* numeric usage fields only: no prompt text, no payloads, no identifiers.
|
|
30205
|
+
*
|
|
30206
|
+
* Called BEFORE normalization, so the values are exactly what upstream sent.
|
|
30207
|
+
* Writes to stderr directly (the `GH_ROUTER_LOG_PEER_MCP` pattern) so it is
|
|
30208
|
+
* visible regardless of consola level and can never interleave with a
|
|
30209
|
+
* JSONL-speaking client's stdout.
|
|
30210
|
+
*
|
|
30211
|
+
* Both egresses captured on 2026-11-05 (native Copilot, and `-m local` against
|
|
30212
|
+
* an LM Studio-backed gateway) delivered `input_tokens` and the cache buckets
|
|
30213
|
+
* on the same `message_delta` record, which is why the transform needs no
|
|
30214
|
+
* across-frame state. That is an unversioned upstream detail: if it ever
|
|
30215
|
+
* splits, the rewrite becomes a silent no-op and these lines are the only
|
|
30216
|
+
* signal, so the flag stays in the product rather than in a one-off script.
|
|
30217
|
+
*
|
|
30218
|
+
* It runs inside the rewrite transform, so it is silent when
|
|
30219
|
+
* `GH_ROUTER_DISABLE_ANTHROPIC_USAGE_NORMALIZE` is set — that path installs no
|
|
30220
|
+
* transform at all.
|
|
30221
|
+
*/
|
|
30222
|
+
function logUsageFrame(eventType, usage) {
|
|
30223
|
+
if (process.env.GH_ROUTER_LOG_ANTHROPIC_USAGE_FRAMES !== "1") return;
|
|
30224
|
+
if (!usage || typeof usage !== "object" || Array.isArray(usage)) {
|
|
30225
|
+
process.stderr.write(`[anthropic-usage] ${eventType} usage=absent\n`);
|
|
30226
|
+
return;
|
|
30227
|
+
}
|
|
30228
|
+
const record = usage;
|
|
30229
|
+
const fields = USAGE_KEYS.map((key) => {
|
|
30230
|
+
const value = record[key];
|
|
30231
|
+
return `${key}=${typeof value === "number" ? value : "absent"}`;
|
|
30232
|
+
});
|
|
30233
|
+
process.stderr.write(`[anthropic-usage] ${eventType} ${fields.join(" ")}\n`);
|
|
30234
|
+
}
|
|
30235
|
+
/**
|
|
30236
|
+
* Rewrite one complete SSE record if it carries usage. Records that need no
|
|
30237
|
+
* correction — every event type other than `message_start` / `message_delta`,
|
|
30238
|
+
* unparseable payloads, and already-disjoint usage — are returned as the
|
|
30239
|
+
* exact bytes they arrived as.
|
|
30240
|
+
*/
|
|
30241
|
+
function rewriteRecord(record) {
|
|
30242
|
+
const text = DECODER.decode(record);
|
|
30243
|
+
const dataMatch = /(?:^|\n)data:/.exec(text);
|
|
30244
|
+
if (!dataMatch) return record;
|
|
30245
|
+
const dataStart = dataMatch.index + (dataMatch[0].length - 5);
|
|
30246
|
+
const dataLines = [];
|
|
30247
|
+
for (const line of text.slice(dataStart).split("\n")) {
|
|
30248
|
+
if (!line.startsWith("data:")) break;
|
|
30249
|
+
dataLines.push(line.slice(5).replace(/^ /, ""));
|
|
30250
|
+
}
|
|
30251
|
+
if (dataLines.length === 0) return record;
|
|
30252
|
+
let payload;
|
|
30253
|
+
try {
|
|
30254
|
+
payload = JSON.parse(dataLines.join("\n"));
|
|
30255
|
+
} catch {
|
|
30256
|
+
return record;
|
|
30257
|
+
}
|
|
30258
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) return record;
|
|
30259
|
+
const event = payload;
|
|
30260
|
+
let changed = false;
|
|
30261
|
+
if (event.type === "message_start") {
|
|
30262
|
+
const message = event.message;
|
|
30263
|
+
if (message && typeof message === "object" && !Array.isArray(message)) {
|
|
30264
|
+
const usage = message.usage;
|
|
30265
|
+
logUsageFrame("message_start", usage);
|
|
30266
|
+
changed = normalizeAnthropicUsageInPlace(usage) || changed;
|
|
30267
|
+
}
|
|
30268
|
+
} else if (event.type === "message_delta") {
|
|
30269
|
+
logUsageFrame("message_delta", event.usage);
|
|
30270
|
+
changed = normalizeAnthropicUsageInPlace(event.usage) || changed;
|
|
30271
|
+
}
|
|
30272
|
+
if (!changed) return record;
|
|
30273
|
+
const prefix = text.slice(0, dataStart);
|
|
30274
|
+
return ENCODER$2.encode(`${prefix}data: ${JSON.stringify(event)}\n\n`);
|
|
30275
|
+
}
|
|
30276
|
+
function concat(left, right) {
|
|
30277
|
+
if (left.byteLength === 0) return right;
|
|
30278
|
+
if (right.byteLength === 0) return left;
|
|
30279
|
+
const out = new Uint8Array(left.byteLength + right.byteLength);
|
|
30280
|
+
out.set(left, 0);
|
|
30281
|
+
out.set(right, left.byteLength);
|
|
30282
|
+
return out;
|
|
30283
|
+
}
|
|
30284
|
+
/**
|
|
30285
|
+
* Streaming counterpart of `normalizeAnthropicUsageInPlace`, shaped for
|
|
30286
|
+
* `relayAnthropicStream`'s `transform` hook.
|
|
30287
|
+
*
|
|
30288
|
+
* Buffers across arbitrary chunk boundaries and only ever emits COMPLETE SSE
|
|
30289
|
+
* records, so an event split mid-record is never corrupted. `flush()` releases
|
|
30290
|
+
* a trailing partial record at upstream EOF; a stream that ends without its
|
|
30291
|
+
* terminator must not lose bytes.
|
|
30292
|
+
*/
|
|
30293
|
+
function createAnthropicUsageRewriteTransform() {
|
|
30294
|
+
let pending = /* @__PURE__ */ new Uint8Array(0);
|
|
30295
|
+
return {
|
|
30296
|
+
push(bytes) {
|
|
30297
|
+
pending = concat(pending, bytes);
|
|
30298
|
+
let emitted;
|
|
30299
|
+
for (;;) {
|
|
30300
|
+
const terminator = findRecordTerminator(pending);
|
|
30301
|
+
if (!terminator) break;
|
|
30302
|
+
const end = terminator.index + terminator.length;
|
|
30303
|
+
const record = pending.subarray(0, end);
|
|
30304
|
+
pending = pending.subarray(end);
|
|
30305
|
+
const rewritten = rewriteRecord(record);
|
|
30306
|
+
emitted = emitted ? concat(emitted, rewritten) : rewritten;
|
|
30307
|
+
}
|
|
30308
|
+
if (pending.byteLength > MAX_PENDING_RECORD_BYTES) {
|
|
30309
|
+
emitted = emitted ? concat(emitted, pending) : pending;
|
|
30310
|
+
pending = /* @__PURE__ */ new Uint8Array(0);
|
|
30311
|
+
}
|
|
30312
|
+
return emitted;
|
|
30313
|
+
},
|
|
30314
|
+
flush() {
|
|
30315
|
+
if (pending.byteLength === 0) return void 0;
|
|
30316
|
+
const tail = pending;
|
|
30317
|
+
pending = /* @__PURE__ */ new Uint8Array(0);
|
|
30318
|
+
return tail;
|
|
30319
|
+
}
|
|
30320
|
+
};
|
|
30321
|
+
}
|
|
30322
|
+
//#endregion
|
|
30072
30323
|
//#region src/lib/reasoning-effort.ts
|
|
30073
30324
|
/**
|
|
30074
30325
|
* Reasoning-effort bucketing + clamping shared by the `/v1/messages` handler
|
|
@@ -30163,6 +30414,15 @@ function clampEffort(bucketed, supported) {
|
|
|
30163
30414
|
//#endregion
|
|
30164
30415
|
//#region src/lib/stream-relay.ts
|
|
30165
30416
|
const ENCODER$1 = new TextEncoder();
|
|
30417
|
+
/** Concatenate two byte runs, preserving order (left first). */
|
|
30418
|
+
function concatBytes(left, right) {
|
|
30419
|
+
if (left.byteLength === 0) return right;
|
|
30420
|
+
if (right.byteLength === 0) return left;
|
|
30421
|
+
const out = new Uint8Array(left.byteLength + right.byteLength);
|
|
30422
|
+
out.set(left, 0);
|
|
30423
|
+
out.set(right, left.byteLength);
|
|
30424
|
+
return out;
|
|
30425
|
+
}
|
|
30166
30426
|
/**
|
|
30167
30427
|
* Detect the family of "controller has already closed" errors that Bun and
|
|
30168
30428
|
* the WHATWG streams runtime throw when an enqueue/close call races with
|
|
@@ -30205,11 +30465,67 @@ function relayAnthropicStream(body, opts) {
|
|
|
30205
30465
|
let bytesRelayed = 0;
|
|
30206
30466
|
let upstreamFinished = false;
|
|
30207
30467
|
let consumerCancelled = false;
|
|
30468
|
+
let transform = opts.transform;
|
|
30208
30469
|
const safeClose = (controller) => {
|
|
30209
30470
|
try {
|
|
30210
30471
|
controller.close();
|
|
30211
30472
|
} catch {}
|
|
30212
30473
|
};
|
|
30474
|
+
/**
|
|
30475
|
+
* Enqueue transform output, tolerating the consumer-cancel race exactly like
|
|
30476
|
+
* the untransformed path. Returns false when the consumer has gone away, in
|
|
30477
|
+
* which case the caller must stop pulling.
|
|
30478
|
+
*/
|
|
30479
|
+
const enqueueBytes = (controller, bytes) => {
|
|
30480
|
+
if (!bytes || bytes.byteLength === 0) return true;
|
|
30481
|
+
try {
|
|
30482
|
+
controller.enqueue(bytes);
|
|
30483
|
+
return true;
|
|
30484
|
+
} catch (enqueueError) {
|
|
30485
|
+
if (isControllerClosedError(enqueueError)) {
|
|
30486
|
+
consumerCancelled = true;
|
|
30487
|
+
return false;
|
|
30488
|
+
}
|
|
30489
|
+
throw enqueueError;
|
|
30490
|
+
}
|
|
30491
|
+
};
|
|
30492
|
+
/**
|
|
30493
|
+
* Run the optional transform. A throw retires the transform and delivers this
|
|
30494
|
+
* chunk verbatim — a rewriter bug must never break delivery.
|
|
30495
|
+
*
|
|
30496
|
+
* Bytes the transform buffered from EARLIER chunks are not recoverable from
|
|
30497
|
+
* this chunk, so they are flushed out best-effort ahead of it. Without that,
|
|
30498
|
+
* a transform that held a partial record and then threw would silently
|
|
30499
|
+
* truncate everything it was holding.
|
|
30500
|
+
*/
|
|
30501
|
+
const applyTransform = (bytes) => {
|
|
30502
|
+
const active = transform;
|
|
30503
|
+
if (!active) return bytes;
|
|
30504
|
+
try {
|
|
30505
|
+
return active.push(bytes);
|
|
30506
|
+
} catch (error) {
|
|
30507
|
+
transform = void 0;
|
|
30508
|
+
consola.warn(`Stream byte transform disabled at ${opts.routePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
30509
|
+
let buffered;
|
|
30510
|
+
try {
|
|
30511
|
+
buffered = active.flush();
|
|
30512
|
+
} catch {}
|
|
30513
|
+
if (!buffered || buffered.byteLength === 0) return bytes;
|
|
30514
|
+
return concatBytes(buffered, bytes);
|
|
30515
|
+
}
|
|
30516
|
+
};
|
|
30517
|
+
/** Release any bytes the transform buffered, at a clean upstream EOF. */
|
|
30518
|
+
const flushTransform = () => {
|
|
30519
|
+
const active = transform;
|
|
30520
|
+
if (!active) return void 0;
|
|
30521
|
+
transform = void 0;
|
|
30522
|
+
try {
|
|
30523
|
+
return active.flush();
|
|
30524
|
+
} catch (error) {
|
|
30525
|
+
consola.warn(`Stream byte transform flush failed at ${opts.routePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
30526
|
+
return;
|
|
30527
|
+
}
|
|
30528
|
+
};
|
|
30213
30529
|
return new ReadableStream({
|
|
30214
30530
|
async pull(controller) {
|
|
30215
30531
|
if (consumerCancelled || upstreamFinished) {
|
|
@@ -30217,30 +30533,28 @@ function relayAnthropicStream(body, opts) {
|
|
|
30217
30533
|
return;
|
|
30218
30534
|
}
|
|
30219
30535
|
try {
|
|
30220
|
-
|
|
30221
|
-
|
|
30222
|
-
|
|
30223
|
-
|
|
30224
|
-
|
|
30225
|
-
|
|
30226
|
-
if (
|
|
30227
|
-
|
|
30228
|
-
|
|
30229
|
-
|
|
30230
|
-
|
|
30231
|
-
|
|
30232
|
-
|
|
30233
|
-
if (
|
|
30234
|
-
|
|
30235
|
-
|
|
30236
|
-
|
|
30237
|
-
|
|
30238
|
-
|
|
30239
|
-
if (
|
|
30240
|
-
|
|
30241
|
-
|
|
30242
|
-
}
|
|
30243
|
-
throw enqueueError;
|
|
30536
|
+
for (;;) {
|
|
30537
|
+
const result = await readWithInactivityTimeout(reader, inactivityMs);
|
|
30538
|
+
if (consumerCancelled) {
|
|
30539
|
+
safeClose(controller);
|
|
30540
|
+
return;
|
|
30541
|
+
}
|
|
30542
|
+
if (result.done) {
|
|
30543
|
+
if (bytesRelayed === 0) consola.warn(`Upstream returned empty SSE stream at ${opts.routePath}`);
|
|
30544
|
+
upstreamFinished = true;
|
|
30545
|
+
if (!enqueueBytes(controller, flushTransform())) return;
|
|
30546
|
+
safeClose(controller);
|
|
30547
|
+
return;
|
|
30548
|
+
}
|
|
30549
|
+
if (result.value) {
|
|
30550
|
+
bytesRelayed += result.value.byteLength;
|
|
30551
|
+
if (opts.onBytes) try {
|
|
30552
|
+
opts.onBytes(result.value);
|
|
30553
|
+
} catch {}
|
|
30554
|
+
const out = applyTransform(result.value);
|
|
30555
|
+
if (!out || out.byteLength === 0) continue;
|
|
30556
|
+
if (!enqueueBytes(controller, out)) return;
|
|
30557
|
+
return;
|
|
30244
30558
|
}
|
|
30245
30559
|
}
|
|
30246
30560
|
} catch (error) {
|
|
@@ -31791,6 +32105,7 @@ function buildAdvisorStream(opts) {
|
|
|
31791
32105
|
}
|
|
31792
32106
|
const nextUsage = {};
|
|
31793
32107
|
for (const [key, value] of Object.entries(usage)) if (typeof value === "number" && Number.isFinite(value)) nextUsage[key] = value;
|
|
32108
|
+
if (!anthropicUsageNormalizeDisabled()) normalizeAnthropicUsageInPlace(nextUsage);
|
|
31794
32109
|
pendingMessageDelta.usage = nextUsage;
|
|
31795
32110
|
const turnAic = extractCopilotUsage(payload.copilot_usage);
|
|
31796
32111
|
if (!turnAic || turnAic.totalNanoAiu <= 0) return;
|
|
@@ -31848,7 +32163,9 @@ function buildAdvisorStream(opts) {
|
|
|
31848
32163
|
continue;
|
|
31849
32164
|
}
|
|
31850
32165
|
switch (ev.event) {
|
|
31851
|
-
case "message_start":
|
|
32166
|
+
case "message_start": {
|
|
32167
|
+
const startMessage = payload.message;
|
|
32168
|
+
if (!anthropicUsageNormalizeDisabled() && startMessage && typeof startMessage === "object" && !Array.isArray(startMessage)) normalizeAnthropicUsageInPlace(startMessage.usage);
|
|
31852
32169
|
if (!messageStartForwarded) {
|
|
31853
32170
|
if (!safeEnqueueEvent(ev.event, payload)) return {
|
|
31854
32171
|
capturedBlocks,
|
|
@@ -31858,6 +32175,7 @@ function buildAdvisorStream(opts) {
|
|
|
31858
32175
|
messageStartForwarded = true;
|
|
31859
32176
|
}
|
|
31860
32177
|
continue;
|
|
32178
|
+
}
|
|
31861
32179
|
case "content_block_start": {
|
|
31862
32180
|
const block = payload.content_block;
|
|
31863
32181
|
const upstreamIndex = payload.index;
|
|
@@ -38715,6 +39033,6 @@ function enumerateInjectedMcpToolNames(groupKeys, opts = {}) {
|
|
|
38715
39033
|
return [...new Set(names)];
|
|
38716
39034
|
}
|
|
38717
39035
|
//#endregion
|
|
38718
|
-
export { buildAnthropicErrorEvent as $,
|
|
39036
|
+
export { buildAnthropicErrorEvent as $, UPSTREAM_FETCH_TIMEOUT_MS as $n, nativeSubagentModel as $t, TOOLBELT_TOOLS$1 as A, parseJsonOrDiagnose as An, brainstormModel as At, FAST_ADVISOR_TOOL_INSTRUCTIONS as B, colbertDegradedWarning as Bn, cloudAgentToolsEnabled as Bt, runWorkerAgent as C, assembleResponsesPayload as Cn, ADO_DEFAULT_TOOLSETS as Ct, toolbeltEnabled as D, createChatCompletions as Dn, artifactToolsEnabled as Dt, buildToolbeltAwareness as E, createResponses as En, agentToolsEnabled as Et, ADVISOR_TOOL_INSTRUCTIONS as F, hasSupportedBrowserInstalled as Fn, cheapOracleModel as Ft, isAdvisorRequested as G, collapsePathKeys as Gn, fastPlanModel as Gt, LOCAL_REVIEWER_ADVISOR_TOOL_INSTRUCTIONS as H, semanticSearchOptedIn as Hn, fastAstraModel as Ht, CHEAPEST_ADVISOR_TOOL_INSTRUCTIONS as I, normalizeCloudAgentEnvironment as In, cheapReviewerModel as It, resolveCuratedAdvisorModel as J, BUDGET_SMALL_FAST_SLUG as Jn, fleetToolsEnabled as Jt, resolveAdvisorEffort as K, toolbeltPathOverride as Kn, fastReviewerModel as Kt, CHEAPEST_REVIEWER_ADVISOR_TOOL_INSTRUCTIONS as L, normalizeKustoClusterUri as Ln, cheapestAdvisorModel as Lt, satisfiesMinVersion as M, effectiveLocalProfile as Mn, browserCompoundToolsEnabled as Mt, searchWeb as N, normalizeOpenAIUsage as Nn, browserToolsEnabled as Nt, toolbeltSkipSet as O, MAX_RESPONSE_BODY_BYTES as On, balancedOracleModel as Ot, ADVISOR_INTERNAL_TOOL_NAME as P, provisionBrowserAssets as Pn, cheapAdvisorModel as Pt, repairRejectedThinkingHistory as Q, DEFAULT_PORT as Qn, kustoToolsEnabled as Qt, CHEAPLOCAL_ADVISOR_TOOL_INSTRUCTIONS as R, CONDENSED_OPERATING_SEQUENCE as Rn, cheapestOracleModel as Rt, resolveWorkerRunOpts as S, unregisterLaunch as Sn, provisionAdoTools as St, availableToolCommands as T, resolveMcpToolTimeoutMs as Tn, adoToolsEnabled as Tt, buildAdvisorStream as U, shouldUseInsecureTls as Un, fastGeneralPurposeModel as Ut, LOCAL_ADVISOR_TOOL_INSTRUCTIONS as V, provisionAndIndexColbert as Vn, fastAdvisorModel as Vt, injectAdvisorTool as W, LOCAL_CONSULT_REDACTION_LINE as Wn, fastOracleModel as Wt, rememberThinkingHistoryRepair as X, DEFAULT_CODEX_MODEL as Xn, generalPurposeFastModel as Xt, formatThinkingRepairDecline as Y, DEFAULT_CLAUDE_MODEL_FALLBACKS as Yn, geminiAvailable as Yt, repairKnownThinkingHistory as Z, DEFAULT_CODEX_MODEL_FALLBACKS as Zn, implementerFastModel as Zt, REVIEW_DEFAULT_MODEL as _, LAUNCH_BOUND_TOKEN_PREFIX as _n, CHEAP_PROFILE_SUBAGENT_CONTEXT_TOKENS as _r, provisionWorkiqTools as _t, buildAgentPrompt as a, standInToolEnabled as an, upstreamAllowH2 as ar, EFFORT_ORDER as at, resolveDefaultModel as b, registerLaunch as bn, buildAdoToolEntries as bt, enumerateInjectedMcpToolNames as c, shimDefaultsToXhigh as cn, catalogAdvertises1M as cr, clampEffort as ct, BROWSE_DEFAULT_MODEL as d, getTokenizerFromModel as dn, withOneMSuffixForLead as dr, normalizeAnthropicUsageInPlace as dt, resolveGeminiReviewModel as en, UPSTREAM_INACTIVITY_TIMEOUT_MS as er, buildOpenAIErrorEvent as et, DEFAULT_MODEL_CHAIN as f, configureLocalEgress as fn, CHEAP_PROFILE_ADVISOR_CLIENT_MODEL as fr, handleMcpDelete as ft, PLAN_DEFAULT_MODEL as g, createMessages as gn, CHEAP_PROFILE_NATIVE_MODELS as gr, disposeWorkiqClients as gt, IMPLEMENT_DEFAULT_MODEL as h, countTokens as hn, CHEAP_PROFILE_NATIVE_EFFORTS as hr, buildWorkiqToolEntries as ht, assertMcpToolSurfaceConsistent as i, scribeModel as in, resolveLeadSlugArg as ir, relayAnthropicStream as it, assetFor as j, assertCopilotModelAllowed as jn, browseAgentEnabled as jt, vscodeRipgrepPath as k, readResponseBodyCapped as kn, balancedReviewerModel as kt, maxPersonasFor as l, getTextTokenCount as ln, oneMContextDisabled as lr, anthropicUsageNormalizeDisabled as lt, EXPLORE_DEFAULT_THINKING as m, localSessionId as mn, CHEAP_PROFILE_NATIVE_AGENT_NAMES as mr, WORKIQ_TOOL_ALIASES as mt, MCP_GROUPS as n, reviewerModel as nn, isBudgetClaudeLead as nr, logStreamError as nt, buildPeerAwarenessSnippet as o, workerToolsEnabled as on, upstreamMaxConnections as or, UNKNOWN_EFFORT_ANCHOR as ot, EXPLORE_DEFAULT_MODEL as p, localBaseUrl as pn, CHEAP_PROFILE_MODELS as pr, handleMcpPost as pt, resolveAdvisorModel as q, BUDGET_SMALL_FAST_CATALOG_ID as qn, fastScoutModel as qt, agentNamesForToolAllowlist as r, scoutModel as rn, pickClaudeDefault as rr, readIteratorWithTimeout as rt, buildPeerAwarenessSummary as s, workiqToolsEnabled as sn, classifyMessagesRoute as sr, bucketEffort as st, GROUP_META as t, reviewerFastModel as tn, generateRandomPort as tr, isControllerClosedError as tt, personasFor as u, getTokenCount as un, withOneMSuffix as ur, createAnthropicUsageRewriteTransform as ut, TEST_DEFAULT_MODEL as v, findLaunchBySecret as vn, workiqMcpToolEntries as vt, buildEnv as w, warnOnTokenPriceDrift as wn, normalizeAdoToolsets as wt, resolveModeDefaults as x, rememberLaunchSessionId as xn, disposeAdoClients as xt, appendPlanReminder as y, launchBoundAccessToken as yn, adoMcpToolEntries as yt, CHEAPLOCAL_REVIEWER_ADVISOR_TOOL_INSTRUCTIONS as z, DEFINITION_OF_GREATNESS as zn, cheapestReviewerModel as zt };
|
|
38719
39037
|
|
|
38720
|
-
//# sourceMappingURL=peer-mcp-personas-
|
|
39038
|
+
//# sourceMappingURL=peer-mcp-personas-D7vaM-V5.js.map
|