github-router 0.3.313 → 0.3.315
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/aic-ledger-BS47yb_C.js +298 -0
- package/dist/aic-ledger-BS47yb_C.js.map +1 -0
- package/dist/{attribution-settings-Dnt04Iyn.js → attribution-settings-DXmmyuEE.js} +8 -8
- package/dist/{attribution-settings-Dnt04Iyn.js.map → attribution-settings-DXmmyuEE.js.map} +1 -1
- package/dist/{auth-O_UG1ABO.js → auth-D8t41c5D.js} +3 -3
- package/dist/{auth-O_UG1ABO.js.map → auth-D8t41c5D.js.map} +1 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{check-usage-dicJOWML.js → check-usage-BpBKOjGZ.js} +4 -4
- package/dist/{check-usage-dicJOWML.js.map → check-usage-BpBKOjGZ.js.map} +1 -1
- package/dist/{claude-D_Me80Yi.js → claude-Cmmu3-cL.js} +140 -20
- package/dist/claude-Cmmu3-cL.js.map +1 -0
- package/dist/{codex-CE7zZm-M.js → codex-DqTKKoEx.js} +5 -5
- package/dist/{codex-CE7zZm-M.js.map → codex-DqTKKoEx.js.map} +1 -1
- package/dist/copilot-discount-IbXR5A28.js +220 -0
- package/dist/copilot-discount-IbXR5A28.js.map +1 -0
- package/dist/{debug-2PgImRnr.js → debug-CA7pg8V9.js} +2 -2
- package/dist/{debug-2PgImRnr.js.map → debug-CA7pg8V9.js.map} +1 -1
- package/dist/engine-b9XaKLp0.js +2 -0
- package/dist/{exec-y8C_MU8A.js → exec-COUT4QsS.js} +2 -2
- package/dist/{exec-y8C_MU8A.js.map → exec-COUT4QsS.js.map} +1 -1
- package/dist/{gate-discovery-_flEdhYo.js → gate-discovery-CPk6Z8yc.js} +6 -6
- package/dist/{gate-discovery-_flEdhYo.js.map → gate-discovery-CPk6Z8yc.js.map} +1 -1
- package/dist/{get-copilot-usage-Cjy8TiFf.js → get-copilot-usage-FSQE8szQ.js} +2 -2
- package/dist/{get-copilot-usage-Cjy8TiFf.js.map → get-copilot-usage-FSQE8szQ.js.map} +1 -1
- package/dist/hooks.mjs +615 -15
- package/dist/hooks.sha256 +1 -1
- package/dist/internal-aic-status-BN0xRLSF.js +432 -0
- package/dist/internal-aic-status-BN0xRLSF.js.map +1 -0
- package/dist/{internal-artifact-open-CxeIfsW_.js → internal-artifact-open-B3stUu74.js} +2 -2
- package/dist/{internal-artifact-open-CxeIfsW_.js.map → internal-artifact-open-B3stUu74.js.map} +1 -1
- package/dist/{internal-fast-dispatch-guard-D8YNlnuQ.js → internal-fast-dispatch-guard-2QjUlhqO.js} +1 -1
- package/dist/{internal-fast-dispatch-guard-19xQEouu.js → internal-fast-dispatch-guard-CAwYj_Yz.js} +2 -2
- package/dist/{internal-fast-dispatch-guard-19xQEouu.js.map → internal-fast-dispatch-guard-CAwYj_Yz.js.map} +1 -1
- package/dist/{internal-first-mate-guard-BuweUgjb.js → internal-first-mate-guard-B0rbLb0L.js} +3 -3
- package/dist/{internal-first-mate-guard-BuweUgjb.js.map → internal-first-mate-guard-B0rbLb0L.js.map} +1 -1
- package/dist/{internal-first-mate-guard-Nf1H0mCK.js → internal-first-mate-guard-VgnHBp0s.js} +1 -1
- package/dist/{internal-max-dispatch-guard-_Pp4LltM.js → internal-max-dispatch-guard-BzKsY9ze.js} +1 -1
- package/dist/{internal-max-dispatch-guard-DZ7KLWxP.js → internal-max-dispatch-guard-l1NGYHtF.js} +2 -2
- package/dist/{internal-max-dispatch-guard-DZ7KLWxP.js.map → internal-max-dispatch-guard-l1NGYHtF.js.map} +1 -1
- package/dist/{internal-plan-review-DLduDz41.js → internal-plan-review-QUvNZmMR.js} +3 -3
- package/dist/{internal-plan-review-DLduDz41.js.map → internal-plan-review-QUvNZmMR.js.map} +1 -1
- package/dist/{internal-prompt-submit-DG94f8E-.js → internal-prompt-submit-fj5ccft_.js} +5 -5
- package/dist/{internal-prompt-submit-DG94f8E-.js.map → internal-prompt-submit-fj5ccft_.js.map} +1 -1
- package/dist/{internal-session-bind-D6Hpl-84.js → internal-session-bind-0Hmak8PR.js} +2 -2
- package/dist/{internal-session-bind-D6Hpl-84.js.map → internal-session-bind-0Hmak8PR.js.map} +1 -1
- package/dist/{internal-stop-hook-BJ3o61-L.js → internal-stop-hook-BKiKYeda.js} +6 -6
- package/dist/{internal-stop-hook-BJ3o61-L.js.map → internal-stop-hook-BKiKYeda.js.map} +1 -1
- package/dist/{internal-stop-review-DlKzZgFm.js → internal-stop-review-8v2llYDB.js} +2 -2
- package/dist/{internal-stop-review-DlKzZgFm.js.map → internal-stop-review-8v2llYDB.js.map} +1 -1
- package/dist/{internal-worker-guard-D7sfByyo.js → internal-worker-guard-BI4Pl0Ew.js} +2 -2
- package/dist/{internal-worker-guard-D7sfByyo.js.map → internal-worker-guard-BI4Pl0Ew.js.map} +1 -1
- package/dist/{internal-workspace-header-CU5OjLCB.js → internal-workspace-header-kg9FoNXK.js} +2 -2
- package/dist/{internal-workspace-header-CU5OjLCB.js.map → internal-workspace-header-kg9FoNXK.js.map} +1 -1
- package/dist/lifecycle-BpqAyaAj.js +2 -0
- package/dist/lifecycle-CL2WiyeQ.js +2 -0
- package/dist/{lifecycle-CtRA3Y7p.js → lifecycle-Cx1wVrLb.js} +3 -3
- package/dist/{lifecycle-CtRA3Y7p.js.map → lifecycle-Cx1wVrLb.js.map} +1 -1
- package/dist/{lifecycle-BCnarXJV.js → lifecycle-IwotwedG.js} +2 -2
- package/dist/{lifecycle-BCnarXJV.js.map → lifecycle-IwotwedG.js.map} +1 -1
- package/dist/main.js +21 -20
- package/dist/main.js.map +1 -1
- package/dist/{mcp-workspace-header-B60WSR1Y.js → mcp-workspace-header-BYgWioLH.js} +2 -2
- package/dist/{mcp-workspace-header-B60WSR1Y.js.map → mcp-workspace-header-BYgWioLH.js.map} +1 -1
- package/dist/{models-COuMOfM6.js → models-DgLeb-Dv.js} +3 -3
- package/dist/{models-COuMOfM6.js.map → models-DgLeb-Dv.js.map} +1 -1
- package/dist/{orchestration-DjLA-lxB.js → orchestration-Dc3mO0G3.js} +3 -3
- package/dist/{orchestration-DjLA-lxB.js.map → orchestration-Dc3mO0G3.js.map} +1 -1
- package/dist/paths-BXXCVFvA.js +2 -0
- package/dist/{paths-De1Qh9Q9.js → paths-CMxlQEfQ.js} +3 -3
- package/dist/{paths-De1Qh9Q9.js.map → paths-CMxlQEfQ.js.map} +1 -1
- package/dist/{peer-mcp-personas-DklYru_1.js → peer-mcp-personas-CYWJSxPK.js} +40 -13
- package/dist/{peer-mcp-personas-DklYru_1.js.map → peer-mcp-personas-CYWJSxPK.js.map} +1 -1
- package/dist/{plan-review-hook-vL6BYmA8.js → plan-review-hook-BIMwWkh6.js} +4 -4
- package/dist/{plan-review-hook-vL6BYmA8.js.map → plan-review-hook-BIMwWkh6.js.map} +1 -1
- package/dist/{prompt-submit-hook-DfqufWC1.js → prompt-submit-hook-BcFpjHXg.js} +3 -3
- package/dist/{prompt-submit-hook-DfqufWC1.js.map → prompt-submit-hook-BcFpjHXg.js.map} +1 -1
- package/dist/{provision-BYdIsKcp.js → provision-AwSjt-vR.js} +9 -5
- package/dist/provision-AwSjt-vR.js.map +1 -0
- package/dist/{self-invocation-B84JCHps.js → self-invocation-cRl4RqfW.js} +2 -2
- package/dist/{self-invocation-B84JCHps.js.map → self-invocation-cRl4RqfW.js.map} +1 -1
- package/dist/{serve-DI4QgSSB.js → serve-BG2O6Slz.js} +13 -13
- package/dist/{serve-DI4QgSSB.js.map → serve-BG2O6Slz.js.map} +1 -1
- package/dist/{server-setup-s2Os8RfG.js → server-setup-D7ABbEs1.js} +109 -10
- package/dist/server-setup-D7ABbEs1.js.map +1 -0
- package/dist/{start-DV5iDhbP.js → start-Dpwpnq99.js} +3 -3
- package/dist/{start-DV5iDhbP.js.map → start-Dpwpnq99.js.map} +1 -1
- package/dist/{stop-gate-hook-BEU8qQrC.js → stop-gate-hook-BUCxa5Kc.js} +4 -4
- package/dist/{stop-gate-hook-BEU8qQrC.js.map → stop-gate-hook-BUCxa5Kc.js.map} +1 -1
- package/dist/{stop-gate-policy-qzqXfRxE.js → stop-gate-policy--bpyxxXU.js} +3 -3
- package/dist/{stop-gate-policy-qzqXfRxE.js.map → stop-gate-policy--bpyxxXU.js.map} +1 -1
- package/dist/{token-CCg-Ov5q.js → token-ClzS23Y2.js} +2 -2
- package/dist/{token-CCg-Ov5q.js.map → token-ClzS23Y2.js.map} +1 -1
- package/dist/{worker-dispatch-CH-NN5FW.js → worker-dispatch-DMIdrlsF.js} +2 -2
- package/dist/{worker-dispatch-CH-NN5FW.js.map → worker-dispatch-DMIdrlsF.js.map} +1 -1
- package/package.json +1 -1
- package/dist/claude-D_Me80Yi.js.map +0 -1
- package/dist/engine-DyzGsCUb.js +0 -2
- package/dist/lifecycle-B0USSJvd.js +0 -2
- package/dist/lifecycle-CQFjaQc0.js +0 -2
- package/dist/paths-DyX6SEnd.js +0 -2
- package/dist/provision-BYdIsKcp.js.map +0 -1
- package/dist/server-setup-s2Os8RfG.js.map +0 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { $ as UNKNOWN_EFFORT_ANCHOR, An as CHEAP_PROFILE_MODELS, B as resolveAdvisorEffort, Cn as upstreamMaxConnections, D as toolbeltEnabled, Dn as withOneMSuffix, En as oneMContextDisabled, F as ADVISOR_TOOL_INSTRUCTIONS, Fn as withInstallLock, Ft as createMessages, G as repairRejectedThinkingHistory, Gt as createResponses, H as formatThinkingRepairDecline, Ht as assembleResponsesPayload, I as FAST_ADVISOR_TOOL_INSTRUCTIONS, It as getTextTokenCount, J as isControllerClosedError, Jt as readResponseBodyCapped, K as buildAnthropicErrorEvent, Kt as createChatCompletions, L as buildAdvisorStream, Lt as getTokenCount, N as searchWeb, Nt as shimDefaultsToXhigh, On as withOneMSuffixForLead, P as ADVISOR_INTERNAL_TOOL_NAME, Pn as CHEAP_PROFILE_SUBAGENT_CONTEXT_TOKENS, Pt as countTokens, Q as EFFORT_ORDER, R as injectAdvisorTool, Rt as getTokenizerFromModel, Sn as upstreamAllowH2, Tn as catalogAdvertises1M, U as rememberThinkingHistoryRepair, Ut as warnOnTokenPriceDrift, V as resolveAdvisorModel, W as repairKnownThinkingHistory, Wt as resolveMcpToolTimeoutMs, X as readIteratorWithTimeout, Xt as normalizeOpenAIUsage, Y as logStreamError, Yt as parseJsonOrDiagnose, Z as relayAnthropicStream, _n as UPSTREAM_INACTIVITY_TIMEOUT_MS, dn as BUDGET_SMALL_FAST_SLUG, et as bucketEffort, gn as UPSTREAM_FETCH_TIMEOUT_MS, i as assertMcpToolSurfaceConsistent, in as provisionTreeSitterAssets, it as agentToolsEnabled, jn as CHEAP_PROFILE_NATIVE_AGENT_NAMES, kn as CHEAP_PROFILE_ADVISOR_CLIENT_MODEL, ln as toolbeltPathOverride, nt as handleMcpDelete, q as buildOpenAIErrorEvent, qt as MAX_RESPONSE_BODY_BYTES, rt as handleMcpPost, tt as clampEffort, vn as generateRandomPort, wn as classifyMessagesRoute, yn as isBudgetClaudeLead, z as isAdvisorRequested, zt as findLaunchBySecret } from "./peer-mcp-personas-
|
|
1
|
+
import { $ as UNKNOWN_EFFORT_ANCHOR, An as CHEAP_PROFILE_MODELS, B as resolveAdvisorEffort, Cn as upstreamMaxConnections, D as toolbeltEnabled, Dn as withOneMSuffix, En as oneMContextDisabled, F as ADVISOR_TOOL_INSTRUCTIONS, Fn as withInstallLock, Ft as createMessages, G as repairRejectedThinkingHistory, Gt as createResponses, H as formatThinkingRepairDecline, Ht as assembleResponsesPayload, I as FAST_ADVISOR_TOOL_INSTRUCTIONS, It as getTextTokenCount, J as isControllerClosedError, Jt as readResponseBodyCapped, K as buildAnthropicErrorEvent, Kt as createChatCompletions, L as buildAdvisorStream, Lt as getTokenCount, N as searchWeb, Nt as shimDefaultsToXhigh, On as withOneMSuffixForLead, P as ADVISOR_INTERNAL_TOOL_NAME, Pn as CHEAP_PROFILE_SUBAGENT_CONTEXT_TOKENS, Pt as countTokens, Q as EFFORT_ORDER, R as injectAdvisorTool, Rt as getTokenizerFromModel, Sn as upstreamAllowH2, Tn as catalogAdvertises1M, U as rememberThinkingHistoryRepair, Ut as warnOnTokenPriceDrift, V as resolveAdvisorModel, W as repairKnownThinkingHistory, Wt as resolveMcpToolTimeoutMs, X as readIteratorWithTimeout, Xt as normalizeOpenAIUsage, Y as logStreamError, Yt as parseJsonOrDiagnose, Z as relayAnthropicStream, _n as UPSTREAM_INACTIVITY_TIMEOUT_MS, dn as BUDGET_SMALL_FAST_SLUG, et as bucketEffort, gn as UPSTREAM_FETCH_TIMEOUT_MS, i as assertMcpToolSurfaceConsistent, in as provisionTreeSitterAssets, it as agentToolsEnabled, jn as CHEAP_PROFILE_NATIVE_AGENT_NAMES, kn as CHEAP_PROFILE_ADVISOR_CLIENT_MODEL, ln as toolbeltPathOverride, nt as handleMcpDelete, q as buildOpenAIErrorEvent, qt as MAX_RESPONSE_BODY_BYTES, rt as handleMcpPost, tt as clampEffort, vn as generateRandomPort, wn as classifyMessagesRoute, yn as isBudgetClaudeLead, z as isAdvisorRequested, zt as findLaunchBySecret } from "./peer-mcp-personas-CYWJSxPK.js";
|
|
2
2
|
import { t as getPackageVersion } from "./version-C8x2hQrZ.js";
|
|
3
|
-
import { i as ensurePaths, t as PATHS } from "./paths-
|
|
3
|
+
import { i as ensurePaths, t as PATHS } from "./paths-CMxlQEfQ.js";
|
|
4
4
|
import { t as state } from "./state-B8adscCv.js";
|
|
5
|
-
import { T as copilotHeaders, _ as forwardError, a as cacheCopilotVersion, c as filterBetaHeader, d as resolveModel, f as sleep, g as HTTPError, i as tryRefreshAndRetry, l as isNullish, n as setupGitHubAgentToken, o as cacheModels, r as setupGitHubToken, s as cacheVSCodeVersion, t as setupCopilotToken, w as copilotBaseUrl, y as fetchWithTransientRetry } from "./token-
|
|
6
|
-
import { t as getCopilotUsage } from "./get-copilot-usage-
|
|
7
|
-
import {
|
|
5
|
+
import { T as copilotHeaders, _ as forwardError, a as cacheCopilotVersion, c as filterBetaHeader, d as resolveModel, f as sleep, g as HTTPError, i as tryRefreshAndRetry, l as isNullish, n as setupGitHubAgentToken, o as cacheModels, r as setupGitHubToken, s as cacheVSCodeVersion, t as setupCopilotToken, w as copilotBaseUrl, y as fetchWithTransientRetry } from "./token-ClzS23Y2.js";
|
|
6
|
+
import { t as getCopilotUsage } from "./get-copilot-usage-FSQE8szQ.js";
|
|
7
|
+
import { c as runCommandVoid, i as parseBoolEnv, o as resolveExecutable, r as killManagedTree, s as runCommandCapture } from "./exec-COUT4QsS.js";
|
|
8
8
|
import { c as FAST_PROFILE_MODELS, l as FAST_PROFILE_NATIVE_AGENT_NAMES, r as FAST_PROFILE_ADVISOR_MODEL } from "./fast-profile-contract-_DhIWank.js";
|
|
9
9
|
import { A as normalizeTrailingOneMSuffix, a as MAX_PROFILE_NATIVE_AGENT_NAMES, d as maxAdvisorPinIsValid, h as maxOpusModel, i as MAX_PROFILE_MODELS, j as stripTrailingOneMSuffix, k as fastEndpointForModel, l as maxAdvisorEffortForModel, n as MAX_PROFILE_ALLOWED_LEAD_MODEL_IDS, t as MAX_PROFILE_ADVISOR_INSTRUCTIONS, u as maxAdvisorModelFromPin, y as validateMaxProfilePrerequisites } from "./max-profile-contract-BcrMlrmo.js";
|
|
10
|
+
import { c as recordAic, d as extractCopilotUsage, f as formatAic, i as extractAndRecordAic, p as nanoAiuToCredits } from "./aic-ledger-BS47yb_C.js";
|
|
10
11
|
import consola from "consola";
|
|
11
12
|
import fs, { existsSync } from "node:fs";
|
|
12
13
|
import path from "node:path";
|
|
@@ -1986,7 +1987,7 @@ function formatTokens(n) {
|
|
|
1986
1987
|
/**
|
|
1987
1988
|
* Build a context window summary: "in:1.2K out:50 ctx:1.2K/1M (0.1%)"
|
|
1988
1989
|
*/
|
|
1989
|
-
function formatTokenInfo(inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, model) {
|
|
1990
|
+
function formatTokenInfo(inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, model, aicNano) {
|
|
1990
1991
|
if (inputTokens === void 0) return void 0;
|
|
1991
1992
|
const parts = [];
|
|
1992
1993
|
const maxPrompt = model?.capabilities?.limits?.max_prompt_tokens;
|
|
@@ -1996,6 +1997,7 @@ function formatTokenInfo(inputTokens, outputTokens, cacheReadTokens, cacheWriteT
|
|
|
1996
1997
|
} else parts.push(`in:${formatTokens(inputTokens)}`);
|
|
1997
1998
|
if (outputTokens !== void 0) parts.push(`out:${formatTokens(outputTokens)}`);
|
|
1998
1999
|
if ((cacheReadTokens ?? 0) > 0 || (cacheWriteTokens ?? 0) > 0) parts.push(`cache:r${formatTokens(cacheReadTokens ?? 0)}/w${formatTokens(cacheWriteTokens ?? 0)}`);
|
|
2000
|
+
if ((aicNano ?? 0) > 0) parts.push(`aic:${formatAic(nanoAiuToCredits(aicNano))}`);
|
|
1999
2001
|
return parts.join(" ");
|
|
2000
2002
|
}
|
|
2001
2003
|
/**
|
|
@@ -2031,7 +2033,7 @@ function logRequest(info, model, startTime) {
|
|
|
2031
2033
|
parts.push(`${info.method} ${info.path}`);
|
|
2032
2034
|
if (info.resolvedModel && info.resolvedModel !== info.model) parts.push(`${info.model}→${info.resolvedModel}`);
|
|
2033
2035
|
else if (info.resolvedModel ?? info.model) parts.push(info.resolvedModel ?? info.model);
|
|
2034
|
-
const tokenInfo = formatTokenInfo(info.inputTokens, info.outputTokens, info.cacheReadTokens, info.cacheWriteTokens, model);
|
|
2036
|
+
const tokenInfo = formatTokenInfo(info.inputTokens, info.outputTokens, info.cacheReadTokens, info.cacheWriteTokens, model, info.aicNano);
|
|
2035
2037
|
if (tokenInfo) parts.push(tokenInfo);
|
|
2036
2038
|
if (info.bodyBytes !== void 0) parts.push(`body:${formatBytes(info.bodyBytes)}`);
|
|
2037
2039
|
if (info.status !== void 0) parts.push(String(info.status));
|
|
@@ -2106,7 +2108,7 @@ function collectToolFieldKeys(body) {
|
|
|
2106
2108
|
//#endregion
|
|
2107
2109
|
//#region package.json
|
|
2108
2110
|
var name = "github-router";
|
|
2109
|
-
var version = "0.3.
|
|
2111
|
+
var version = "0.3.315";
|
|
2110
2112
|
//#endregion
|
|
2111
2113
|
//#region src/lib/approval.ts
|
|
2112
2114
|
const awaitApproval = async () => {
|
|
@@ -2801,6 +2803,7 @@ async function handleCompletion$1(c) {
|
|
|
2801
2803
|
const outputTokens = !isStreaming ? response.usage?.completion_tokens : void 0;
|
|
2802
2804
|
const rawUsage = !isStreaming ? response.usage : void 0;
|
|
2803
2805
|
const responseUsage = rawUsage ? normalizeOpenAIUsage(rawUsage) : void 0;
|
|
2806
|
+
const aicNano = !isStreaming ? extractAndRecordAic(resolvedModel, response) : void 0;
|
|
2804
2807
|
logRequest({
|
|
2805
2808
|
method: "POST",
|
|
2806
2809
|
path: c.req.path,
|
|
@@ -2810,6 +2813,7 @@ async function handleCompletion$1(c) {
|
|
|
2810
2813
|
outputTokens,
|
|
2811
2814
|
cacheReadTokens: responseUsage?.cacheRead,
|
|
2812
2815
|
cacheWriteTokens: responseUsage?.cacheWrite,
|
|
2816
|
+
aicNano,
|
|
2813
2817
|
status: 200,
|
|
2814
2818
|
streaming: isStreaming
|
|
2815
2819
|
}, selectedModel, startTime);
|
|
@@ -2823,6 +2827,14 @@ async function handleCompletion$1(c) {
|
|
|
2823
2827
|
let pendingFirstChunk = firstResult.done ? void 0 : firstResult.value;
|
|
2824
2828
|
let upstreamFinished = firstResult.done;
|
|
2825
2829
|
let consumerCancelled = false;
|
|
2830
|
+
let aicRecorded = false;
|
|
2831
|
+
const tapAic = (chunk) => {
|
|
2832
|
+
if (aicRecorded || !chunk.data || chunk.data === "[DONE]") return;
|
|
2833
|
+
try {
|
|
2834
|
+
const parsed = JSON.parse(chunk.data);
|
|
2835
|
+
if (extractAndRecordAic(resolvedModel, parsed) !== void 0) aicRecorded = true;
|
|
2836
|
+
} catch {}
|
|
2837
|
+
};
|
|
2826
2838
|
const safeClose = (controller) => {
|
|
2827
2839
|
try {
|
|
2828
2840
|
controller.close();
|
|
@@ -2854,6 +2866,7 @@ async function handleCompletion$1(c) {
|
|
|
2854
2866
|
const chunk = pendingFirstChunk;
|
|
2855
2867
|
pendingFirstChunk = void 0;
|
|
2856
2868
|
if (debugEnabled) consola.debug("Streaming chunk:", JSON.stringify(chunk));
|
|
2869
|
+
tapAic(chunk);
|
|
2857
2870
|
safeEnqueue(controller, ENCODER$1.encode(formatSSE$1(chunk)));
|
|
2858
2871
|
return;
|
|
2859
2872
|
}
|
|
@@ -2870,6 +2883,7 @@ async function handleCompletion$1(c) {
|
|
|
2870
2883
|
}
|
|
2871
2884
|
if (result.value === void 0 || result.value === null) return;
|
|
2872
2885
|
if (debugEnabled) consola.debug("Streaming chunk:", JSON.stringify(result.value));
|
|
2886
|
+
tapAic(result.value);
|
|
2873
2887
|
safeEnqueue(controller, ENCODER$1.encode(formatSSE$1(result.value)));
|
|
2874
2888
|
} catch (error) {
|
|
2875
2889
|
upstreamFinished = true;
|
|
@@ -3285,6 +3299,63 @@ function sanitizeAnthropicBody(rawBody) {
|
|
|
3285
3299
|
return JSON.stringify(parsed);
|
|
3286
3300
|
}
|
|
3287
3301
|
//#endregion
|
|
3302
|
+
//#region src/lib/aic-sse-tap.ts
|
|
3303
|
+
/**
|
|
3304
|
+
* Incremental SSE tap that extracts upstream `copilot_usage` (AIC) from a
|
|
3305
|
+
* `/v1/messages` byte stream without modifying it.
|
|
3306
|
+
*
|
|
3307
|
+
* Verified live: `copilot_usage` rides inside the terminal `message_delta`
|
|
3308
|
+
* event beside `usage`. Chunks are arbitrary byte splits, so the tap buffers
|
|
3309
|
+
* text, splits on blank-line event boundaries, and keeps the tail. Recording
|
|
3310
|
+
* fires at most once per tap instance (one terminal event per stream).
|
|
3311
|
+
*
|
|
3312
|
+
* Total and never throws — a malformed frame is skipped silently. The relay
|
|
3313
|
+
* path additionally wraps the call in try/catch, so a tap bug can never break
|
|
3314
|
+
* byte delivery.
|
|
3315
|
+
*/
|
|
3316
|
+
function createAnthropicAicTap(record) {
|
|
3317
|
+
const decoder = new TextDecoder();
|
|
3318
|
+
let buffer = "";
|
|
3319
|
+
let recorded = false;
|
|
3320
|
+
const handleEvent = (rawEvent) => {
|
|
3321
|
+
if (recorded) return;
|
|
3322
|
+
const lines = rawEvent.split("\n");
|
|
3323
|
+
let eventName = "";
|
|
3324
|
+
const dataLines = [];
|
|
3325
|
+
for (const line of lines) if (line.startsWith("event:")) eventName = line.slice(6).trim();
|
|
3326
|
+
else if (line.startsWith("data:")) dataLines.push(line.slice(5).trimStart());
|
|
3327
|
+
if (eventName !== "" && eventName !== "message_delta") return;
|
|
3328
|
+
if (dataLines.length === 0) return;
|
|
3329
|
+
if (!(dataLines[0] ?? "").startsWith("{")) return;
|
|
3330
|
+
try {
|
|
3331
|
+
const parsed = JSON.parse(dataLines.join("\n"));
|
|
3332
|
+
const usage = extractCopilotUsage(parsed.copilot_usage);
|
|
3333
|
+
if (usage) {
|
|
3334
|
+
recorded = true;
|
|
3335
|
+
try {
|
|
3336
|
+
record(usage);
|
|
3337
|
+
} catch {}
|
|
3338
|
+
}
|
|
3339
|
+
} catch {}
|
|
3340
|
+
};
|
|
3341
|
+
return { onBytes(bytes) {
|
|
3342
|
+
if (recorded || bytes.length === 0) return;
|
|
3343
|
+
buffer += decoder.decode(bytes, { stream: true });
|
|
3344
|
+
let boundary = buffer.indexOf("\n\n");
|
|
3345
|
+
while (boundary >= 0) {
|
|
3346
|
+
const rawEvent = buffer.slice(0, boundary);
|
|
3347
|
+
buffer = buffer.slice(boundary + 2);
|
|
3348
|
+
handleEvent(rawEvent);
|
|
3349
|
+
if (recorded) {
|
|
3350
|
+
buffer = "";
|
|
3351
|
+
return;
|
|
3352
|
+
}
|
|
3353
|
+
boundary = buffer.indexOf("\n\n");
|
|
3354
|
+
}
|
|
3355
|
+
if (buffer.length > 1048576) buffer = "";
|
|
3356
|
+
} };
|
|
3357
|
+
}
|
|
3358
|
+
//#endregion
|
|
3288
3359
|
//#region src/lib/anthropic-translate/anthropic-sse.ts
|
|
3289
3360
|
/**
|
|
3290
3361
|
* Anthropic Messages SSE egress: frame builders + a Bun-safe ReadableStream
|
|
@@ -4215,6 +4286,7 @@ function chatStopReason(finishReason, sawTool) {
|
|
|
4215
4286
|
* and each `message.tool_calls[]` becomes a tool_use block.
|
|
4216
4287
|
*/
|
|
4217
4288
|
function chatResponseToAnthropicMessage(resp, modelId) {
|
|
4289
|
+
extractAndRecordAic(modelId, resp);
|
|
4218
4290
|
const choice = resp.choices?.[0];
|
|
4219
4291
|
const content = [];
|
|
4220
4292
|
let sawTool = false;
|
|
@@ -4277,6 +4349,7 @@ async function* synthAnthropicFromChat(upstream, opts) {
|
|
|
4277
4349
|
let usageOut = 0;
|
|
4278
4350
|
let usageCacheRead = 0;
|
|
4279
4351
|
let usageCacheWrite = 0;
|
|
4352
|
+
let aicRecorded = false;
|
|
4280
4353
|
let finishReason = null;
|
|
4281
4354
|
let sawDone = false;
|
|
4282
4355
|
yield makeMessageStart(messageId, opts.modelId);
|
|
@@ -4293,6 +4366,9 @@ async function* synthAnthropicFromChat(upstream, opts) {
|
|
|
4293
4366
|
} catch {
|
|
4294
4367
|
continue;
|
|
4295
4368
|
}
|
|
4369
|
+
if (!aicRecorded) {
|
|
4370
|
+
if (extractAndRecordAic(opts.modelId, chunk) !== void 0) aicRecorded = true;
|
|
4371
|
+
}
|
|
4296
4372
|
if (chunk.usage) {
|
|
4297
4373
|
usageIn = Math.max(usageIn, chunk.usage.prompt_tokens ?? 0);
|
|
4298
4374
|
usageOut = Math.max(usageOut, chunk.usage.completion_tokens ?? 0);
|
|
@@ -4455,6 +4531,7 @@ function parseToolArgs(raw) {
|
|
|
4455
4531
|
* else `end_turn`.
|
|
4456
4532
|
*/
|
|
4457
4533
|
function responsesResponseToAnthropicMessage(resp, modelId) {
|
|
4534
|
+
extractAndRecordAic(modelId, resp);
|
|
4458
4535
|
const output = Array.isArray(resp.output) ? resp.output : [];
|
|
4459
4536
|
const content = [];
|
|
4460
4537
|
let sawToolUse = false;
|
|
@@ -4532,6 +4609,7 @@ async function* synthAnthropicFromResponses(upstream, opts) {
|
|
|
4532
4609
|
let sawTool = false;
|
|
4533
4610
|
let hitMaxTokens = false;
|
|
4534
4611
|
let sawTerminal = false;
|
|
4612
|
+
let aicRecorded = false;
|
|
4535
4613
|
const closeCurrent = () => {
|
|
4536
4614
|
if (!current) return;
|
|
4537
4615
|
q.push(makeContentBlockStop(current.index));
|
|
@@ -4701,6 +4779,9 @@ async function* synthAnthropicFromResponses(upstream, opts) {
|
|
|
4701
4779
|
case "response.completed":
|
|
4702
4780
|
case "response.incomplete": {
|
|
4703
4781
|
sawTerminal = true;
|
|
4782
|
+
if (!aicRecorded) {
|
|
4783
|
+
if (extractAndRecordAic(opts.modelId, ev) !== void 0) aicRecorded = true;
|
|
4784
|
+
}
|
|
4704
4785
|
const u = ev.response?.usage;
|
|
4705
4786
|
if (u) {
|
|
4706
4787
|
usageIn = Math.max(usageIn, u.input_tokens ?? 0);
|
|
@@ -5891,7 +5972,10 @@ async function handleCompletion(c) {
|
|
|
5891
5972
|
headers: streamHeaders
|
|
5892
5973
|
});
|
|
5893
5974
|
}
|
|
5894
|
-
return new Response(response.body ? relayAnthropicStream(response.body, {
|
|
5975
|
+
return new Response(response.body ? relayAnthropicStream(response.body, {
|
|
5976
|
+
routePath: c.req.path,
|
|
5977
|
+
onBytes: createAnthropicAicTap((usage) => recordAic(resolvedModel, usage)).onBytes
|
|
5978
|
+
}) : null, {
|
|
5895
5979
|
status: response.status,
|
|
5896
5980
|
headers: streamHeaders
|
|
5897
5981
|
});
|
|
@@ -5900,6 +5984,7 @@ async function handleCompletion(c) {
|
|
|
5900
5984
|
if (!cappedResult.ok) return c.json(cappedResult.errorResponse, cappedResult.status);
|
|
5901
5985
|
const responseBody = cappedResult.value;
|
|
5902
5986
|
const usage = responseBody.usage;
|
|
5987
|
+
const aicNano = extractAndRecordAic(resolvedModel, responseBody);
|
|
5903
5988
|
logRequest({
|
|
5904
5989
|
method: "POST",
|
|
5905
5990
|
path: c.req.path,
|
|
@@ -5909,6 +5994,7 @@ async function handleCompletion(c) {
|
|
|
5909
5994
|
outputTokens: usage?.output_tokens,
|
|
5910
5995
|
cacheReadTokens: usage?.cache_read_input_tokens,
|
|
5911
5996
|
cacheWriteTokens: usage?.cache_creation_input_tokens,
|
|
5997
|
+
aicNano,
|
|
5912
5998
|
status: response.status
|
|
5913
5999
|
}, selectedModel, startTime);
|
|
5914
6000
|
if (debugEnabled) consola.debug("Non-streaming response from Copilot /v1/messages:", JSON.stringify(responseBody).slice(0, 2e3));
|
|
@@ -6470,6 +6556,7 @@ async function handleResponses(c) {
|
|
|
6470
6556
|
const isStreaming = !isNonStreaming(response);
|
|
6471
6557
|
const rawUsage = !isStreaming ? response.usage : void 0;
|
|
6472
6558
|
const responseUsage = rawUsage && typeof rawUsage === "object" && !Array.isArray(rawUsage) ? normalizeOpenAIUsage(rawUsage) : void 0;
|
|
6559
|
+
const aicNano = !isStreaming ? extractAndRecordAic(resolvedModel, response) : void 0;
|
|
6473
6560
|
logRequest({
|
|
6474
6561
|
method: "POST",
|
|
6475
6562
|
path: c.req.path,
|
|
@@ -6479,6 +6566,7 @@ async function handleResponses(c) {
|
|
|
6479
6566
|
outputTokens: responseUsage?.output,
|
|
6480
6567
|
cacheReadTokens: responseUsage?.cacheRead,
|
|
6481
6568
|
cacheWriteTokens: responseUsage?.cacheWrite,
|
|
6569
|
+
aicNano,
|
|
6482
6570
|
status: 200,
|
|
6483
6571
|
streaming: isStreaming
|
|
6484
6572
|
}, selectedModel, startTime);
|
|
@@ -6514,6 +6602,15 @@ async function handleResponses(c) {
|
|
|
6514
6602
|
if (firstChunk === void 0) consola.warn(`Upstream /responses returned no payload events at ${c.req.path}`);
|
|
6515
6603
|
let pendingFirstChunk = firstChunk;
|
|
6516
6604
|
let consumerCancelled = false;
|
|
6605
|
+
let aicRecorded = false;
|
|
6606
|
+
const tapAic = (chunk) => {
|
|
6607
|
+
if (aicRecorded || !chunk.data || chunk.data === "[DONE]") return;
|
|
6608
|
+
try {
|
|
6609
|
+
const parsed = JSON.parse(chunk.data);
|
|
6610
|
+
if (extractAndRecordAic(resolvedModel, parsed) !== void 0) aicRecorded = true;
|
|
6611
|
+
} catch {}
|
|
6612
|
+
};
|
|
6613
|
+
if (pendingFirstChunk !== void 0) tapAic(pendingFirstChunk);
|
|
6517
6614
|
const safeClose = (controller) => {
|
|
6518
6615
|
try {
|
|
6519
6616
|
controller.close();
|
|
@@ -6545,6 +6642,7 @@ async function handleResponses(c) {
|
|
|
6545
6642
|
const chunk = pendingFirstChunk;
|
|
6546
6643
|
pendingFirstChunk = void 0;
|
|
6547
6644
|
if (debugEnabled) consola.debug("Streaming chunk:", JSON.stringify(chunk));
|
|
6645
|
+
tapAic(chunk);
|
|
6548
6646
|
safeEnqueue(controller, ENCODER.encode(formatSSE(chunk)));
|
|
6549
6647
|
return;
|
|
6550
6648
|
}
|
|
@@ -6567,6 +6665,7 @@ async function handleResponses(c) {
|
|
|
6567
6665
|
}
|
|
6568
6666
|
if (!result.value.data) return;
|
|
6569
6667
|
if (debugEnabled) consola.debug("Streaming chunk:", JSON.stringify(result.value));
|
|
6668
|
+
tapAic(result.value);
|
|
6570
6669
|
safeEnqueue(controller, ENCODER.encode(formatSSE(result.value)));
|
|
6571
6670
|
} catch (error) {
|
|
6572
6671
|
upstreamFinished = true;
|
|
@@ -7425,4 +7524,4 @@ function getCodexEnvVars(serverUrl) {
|
|
|
7425
7524
|
//#endregion
|
|
7426
7525
|
export { checkClaudeVersion as C, runSelfUpdate as S, resolveLaunchProfile as _, sharedServerArgs as a, validateFastProfilePrerequisites as b, stopKeepAwake as c, enableFileLogging as d, LUNA_SCOUT_ALIAS_ID as f, profileDescriptor as g, formatFastPrerequisiteFailure as h, setupAndServe as i, injectModelPickerSettingsFile as l, formatCheapPrerequisiteFailure as m, getCodexEnvVars as n, LAUNCH_SECRET_HEADER as o, formatCheap1mPrerequisiteFailure as p, parseSharedArgs as r, startKeepAwake as s, getClaudeCodeEnvVars as t, listModelsForEndpoint as u, validateCheap1mProfilePrerequisites as v, updateClaude as w, validateMaxProfileLaunch as x, validateCheapProfilePrerequisites as y };
|
|
7427
7526
|
|
|
7428
|
-
//# sourceMappingURL=server-setup-
|
|
7527
|
+
//# sourceMappingURL=server-setup-D7ABbEs1.js.map
|