Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/configuration.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
| `compat` | { roles?, dropFields? } | {} | — | ルート単位のワイヤー互換性上書き;provider エントリはキーごとに global ブロックを優先します;dropFields は加算的に union されます。 |
| `direct` | boolean | false | — | クライアント側の除外:このアップストリームへのトラフィックは決して bili に指向されません。 |
| `passthrough` | boolean | false | — | セッション状態なしのルートスコープのバイト単位リレー — 不正防止アップストリーム向け。 |
| `renderNone` | boolean | unset (follows diagnostics.renderNone) | — | ルートスコープのレンダータグ:true でこのルートの履歴に ACP タグを描画せず、false で強制的に有効化(#2483)。 |
| `imageBilling` | "auto" \| "pixels" \| "bytes" | auto (→ pixels) | — | このルートのイメージトークンカウント基準;bytes はバイトリレーに対する明示的なオプトインです。 |
| `imageTokenCap` | number | unset (uncapped) | — | このルートのイメージごとのトークンコスト上限。 |
| `resign` | scheme → { enabled?, passthrough?, credentialRef? } | {} (global map applies) | — | グローバル resign マップのルート単位のオーバーライド(レベル 2、最も深いものが優先)。 |
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `compat` | { roles?, dropFields? } | {} | — | Per-route wire-compat overrides; provider entries beat the global block per key; dropFields union additively. |
| `direct` | boolean | false | — | Client-side exemption: traffic for this upstream is never pointed at bili at all. |
| `passthrough` | boolean | false | — | Route-scoped byte-for-byte relay with no session state — for anti-fraud upstreams. |
| `renderNone` | boolean | unset (follows diagnostics.renderNone) | — | Route-scoped render tags: true renders no ACP tags into this route's history, false forces them on (#2483). |
| `imageBilling` | "auto" \| "pixels" \| "bytes" | auto (→ pixels) | — | Image-token counting basis for this route; bytes is an explicit opt-in for byte relays. |
| `imageTokenCap` | number | unset (uncapped) | — | Per-image token cost cap for this route. |
| `resign` | scheme → { enabled?, passthrough?, credentialRef? } | {} (global map applies) | — | Per-route overrides of the global resign map (level 2, deepest wins). |
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
| `compat` | { roles?, dropFields? } | {} | — | 逐路由线上兼容覆盖;provider 条目按键级覆盖全局;dropFields 加法并集。 |
| `direct` | boolean | false | — | 客户端侧豁免:该上游流量完全不指向 bili。 |
| `passthrough` | boolean | false | — | 路由级逐字节透传、无会话状态——面向反作弊上游。 |
| `renderNone` | boolean | unset (follows diagnostics.renderNone) | — | 路由级渲染标记:true 时本路由历史不渲染 ACP 标签,false 强制开启(#2483)。 |
| `imageBilling` | "auto" \| "pixels" \| "bytes" | auto (→ pixels) | — | 本路由图片 token 计费口径;bytes 为字节中继的显式指定。 |
| `imageTokenCap` | number | unset (uncapped) | — | 本路由单张图片 token 成本上限。 |
| `resign` | scheme → { enabled?, passthrough?, credentialRef? } | {} (global map applies) | — | 按路由覆盖全局 resign 映射(第 2 级,最深层胜出)。 |
Expand Down
2 changes: 1 addition & 1 deletion src/cache-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ function formatSeam(r: BiliCacheReport): string {
if (r.seam.providerSide.count > 0) {
out.push("▲ PROVIDER-SIDE MISS (previous request's message list fully preserved)");
out.push(` ${r.seam.providerSide.count} sample(s) · ${fmtTok(r.seam.providerSide.missed)} tok — the previous request's message list is preserved in this one (byte-for-byte under the 512 KiB forensics cap; above it, proven by the stable recorded head plus exact message-count growth — any difference is only the appended tail), and the sample arrived within ${Math.round(PROVIDER_TTL_GAP_MS / 60_000)} min of the previous one, so this is an ABNORMAL provider miss (eviction / relay node rotation), not TTL ageing. Not a bili rebuild seam.`);
out.push(` stateful-upstream check (#2483): if your upstream keeps a live session per conversation and validates the echoed history against its own transcript (claude-code-based relays such as magpie), bili's render tags on assistant text trip that check even though bili's own list is unchanged — set diagnostics.renderNone=true until per-route render-tags control ships; expect exactly ONE replay when flipping the flag mid-session`);
out.push(` stateful-upstream check (#2483): if your upstream keeps a live session per conversation and validates the echoed history against its own transcript (claude-code-based relays such as magpie), bili's render tags on assistant text trip that check even though bili's own list is unchanged — set providers["<that upstream url>"].renderNone=true (or diagnostics.renderNone=true for every lane); expect exactly ONE replay when flipping the flag mid-session`);
}
if (r.seam.client.count > 0) {
out.push("✎ CLIENT MID-HISTORY REWRITE (host-side insert — NOT a bili seam)");
Expand Down
13 changes: 11 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export type ProviderRoute = {
* verbatim, no session state. For upstreams whose anti-cheat fingerprints
* the request body (e.g. ZCode 405/3012). */
passthrough?: boolean;
/** Route-scoped render-tags switch (#2483): `true` renders no ACP tags
* into history for requests matching this route, `false` forces them on,
* unset follows `diagnostics.renderNone`. For upstreams that keep a live
* session per conversation and validate the echoed history against their
* own transcript (claude-code-based relays such as magpie), where render
* tags on assistant text break session reuse every turn. ACP_RENDER_NONE
* still wins over both. */
renderNone?: boolean;
/** Client-side routing exemption (#1622): this upstream never gets pointed
* through bili at all. Store-rewriting native lanes (zcode today) skip
* matching entries instead of wrapping them, so traffic flows
Expand Down Expand Up @@ -1173,7 +1181,7 @@ interface DshFileSettings {
* {@link parseRouteEntry} consumes per route. When they sit on a non-URL key
* WITHOUT `bind` they are inert (longest-prefix matching never hits a name),
* so loadRoutes warns loudly instead of letting them sit dead (#1469). */
const NAMED_PROVIDER_ROUTING_FIELDS = ["compress", "models", "proxy", "passthrough", "compressProtocol", "protocol", "compat", "imageBilling", "imageTokenCap"] as const;
const NAMED_PROVIDER_ROUTING_FIELDS = ["compress", "models", "proxy", "passthrough", "compressProtocol", "protocol", "compat", "imageBilling", "imageTokenCap", "renderNone"] as const;

// Once-per-signature dedup so hot-reload / repeated launcher loads don't spam
// the same named-provider warning (same pattern as the absorb warnings below).
Expand Down Expand Up @@ -3067,7 +3075,7 @@ export function parseRouteEntry(v: unknown): ProviderRoute | undefined {
// is the KEY in the providers map (identical to the /bili/<url> string),
// so it is NOT repeated inside the value.
if (v && typeof v === "object" && !Array.isArray(v)) {
const obj = v as { models?: Record<string, ModelEntry>; proxy?: string; compressProtocol?: string; protocol?: unknown; compress?: CompressSettings; cacheKeepalive?: unknown; compat?: { roles?: unknown; dropFields?: unknown }; passthrough?: boolean; direct?: boolean; imageBilling?: unknown; imageTokenCap?: unknown; calibration?: unknown; baseUrl?: unknown; api?: unknown; apiKeyEnv?: unknown; credentialRef?: unknown };
const obj = v as { models?: Record<string, ModelEntry>; proxy?: string; compressProtocol?: string; protocol?: unknown; compress?: CompressSettings; cacheKeepalive?: unknown; compat?: { roles?: unknown; dropFields?: unknown }; passthrough?: boolean; renderNone?: unknown; direct?: boolean; imageBilling?: unknown; imageTokenCap?: unknown; calibration?: unknown; baseUrl?: unknown; api?: unknown; apiKeyEnv?: unknown; credentialRef?: unknown };
const route: ProviderRoute = { models: obj.models };
if (typeof obj.proxy === "string") route.proxy = obj.proxy;
if (obj.compressProtocol === "marker" || obj.compressProtocol === "tools") route.compressProtocol = obj.compressProtocol;
Expand All @@ -3090,6 +3098,7 @@ export function parseRouteEntry(v: unknown): ProviderRoute | undefined {
if (compatDrops) compat.dropFields = compatDrops;
if (Object.keys(compat).length > 0) route.compat = compat;
if (typeof obj.passthrough === "boolean") route.passthrough = obj.passthrough;
if (typeof obj.renderNone === "boolean") route.renderNone = obj.renderNone;
if (typeof obj.direct === "boolean") route.direct = obj.direct;
const imageBilling = parseImageBilling(obj.imageBilling);
if (imageBilling) route.imageBilling = imageBilling;
Expand Down
19 changes: 18 additions & 1 deletion src/knobs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AsyncLocalStorage } from "node:async_hooks";
// #2030: canonical home for runtime knobs. Every knob resolves
// env var > config file > default:
// - the ENV tier is byte-exact with the historical parsing (deployments and
Expand Down Expand Up @@ -863,10 +864,26 @@ export function dumpGcMaxAgeMs(): number | null {
return null;
}

/** ACP_RENDER_NONE > diagnostics.renderNone > false (any non-empty env value enables). */
/** #2483: request-scoped render override from the matched provider route
* (`providers[<url>].renderNone`). Set by the request handler around the
* prepare pipeline so every render-strategy reader (prepare-*, inject,
* count_tokens, the compress-loop rebuild) agrees for that request. */
const routeRender = new AsyncLocalStorage<{ renderNone: boolean }>();

/** Run `fn` with the route's renderNone in scope; undefined = no route override. */
export function withRouteRenderNone<T>(value: boolean | undefined, fn: () => T): T {
return value === undefined ? fn() : routeRender.run({ renderNone: value }, fn);
}

/** ACP_RENDER_NONE > providers[<url>].renderNone > diagnostics.renderNone > false
* (any non-empty env value enables). The route value wins over the global
* file flag in either direction, so one lane can opt in (a stateful
* claude-code relay such as magpie) or out while the rest keep the default. */
export function renderNone(): boolean {
const envRaw = process.env.ACP_RENDER_NONE;
if (envRaw !== undefined) return envRaw.length > 0;
const route = routeRender.getStore();
if (route !== undefined) return route.renderNone;
return fileDiag().renderNone === true;
}

Expand Down
7 changes: 5 additions & 2 deletions src/server/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { resolveCompatDropFields } from "../compat-drop.js";
import { unwrapCommandcodeBody, type CommandcodeEnvelopeMeta } from "../commandcode-wire.js";
import { DecompressedTooLargeError, decodeRequestBody, IngestBodyTooLargeError } from "../content-encoding.js";
import { matchModelEndpoint } from "../model-endpoints.js";
import { autoModeForgeEnabled, dshAuthoredCompactionEnabled, imageRescaleEnabled, limitsDecodedBytes as knobLimitsDecodedBytes, limitsIngestBytes as knobLimitsIngestBytes, noInjectTool as knobNoInjectTool, pluginBypassOverride, rawDumpDir as knobRawDumpDir } from "../knobs.js";
import { autoModeForgeEnabled, dshAuthoredCompactionEnabled, imageRescaleEnabled, limitsDecodedBytes as knobLimitsDecodedBytes, limitsIngestBytes as knobLimitsIngestBytes, noInjectTool as knobNoInjectTool, pluginBypassOverride, withRouteRenderNone, rawDumpDir as knobRawDumpDir } from "../knobs.js";
import { buildForgeResponse, classifierForgeVariant, estimateCjkTokens, isAutoModeClassifier, requestText, summarizeAction } from "../auto-mode-forge.js";
import { extractConversationId, isV1BackgroundSideRequest, isV1InternalRequest, unwrapV1Internal } from "../v1internal.js";
import { anthropicBetaContextWindow, BILI_HOP_HEADER, capRegistryWindowByStandard, expandedContextSuffixWindow, launcherContextWindow, launcherMaxOutput, noteUnresolvedModelSession, UNRESOLVED_MODEL_SESSION_THRESHOLD, windowSourceLogged } from "./context-window.js";
Expand Down Expand Up @@ -1065,6 +1065,9 @@ async function handleRequest(
// requests whose upstream URL matches a provider route with
// `passthrough: true` (upstreams that fingerprint the request body).
const routePassthrough = !opts.passthrough && findRoute(opts.routes, providerDestUrl)?.passthrough === true;
// #2483: route-scoped render tags (`providers[<url>].renderNone`), applied
// around every prepare of this request (incl. compress-loop rebuilds).
const routeRenderNone = findRoute(opts.routes, providerDestUrl)?.renderNone;
if (routePassthrough && hopMarker === undefined && protocol && parsed) {
log("info", `[route-passthrough] ${maskUrlsInText(providerDestUrl)} matches a passthrough route — forwarding verbatim, kernel bypassed`);
}
Expand Down Expand Up @@ -3054,7 +3057,7 @@ async function handleRequest(
// #1295: stamp the envelope meta onto every Prepared for this
// request (initial AND preflight re-prepares both flow through).
const runPrepare = async (): Promise<Prepared> => {
const p = await runPrepareInner();
const p = await withRouteRenderNone(routeRenderNone, runPrepareInner);
if (ccMeta !== undefined) p.commandcode = { meta: ccMeta };
return p;
};
Expand Down
Loading
Loading