fix: normalize opus 4.7 context window

Normalize Anthropic-owned Opus 4.7 context reporting to 1M while keeping inferred and bare discovery paths conservative.

- normalize Anthropic and claude-cli Opus 4.7 runtime/status context metadata to 1M
- keep inferred-provider and bare discovery ids on discovered conservative limits
- add regression coverage for provider, lookup, status, and discovery-cache paths
- keep the Telegram abort-signal wrapper typing narrow so changed-scope validation stays green
This commit is contained in:
Val Alexander
2026-04-22 14:58:16 -05:00
committed by GitHub
parent c542d42f6f
commit 9ea5484fa1
8 changed files with 293 additions and 9 deletions

View File

@@ -75,6 +75,12 @@ type TelegramCompatFetch = (
input: TelegramFetchInput,
init?: TelegramFetchInit,
) => ReturnType<TelegramClientFetch>;
type TelegramAbortSignalLike = {
aborted: boolean;
reason?: unknown;
addEventListener: (type: "abort", listener: () => void, options?: { once?: boolean }) => void;
removeEventListener: (type: "abort", listener: () => void) => void;
};
function asTelegramClientFetch(
fetchImpl: TelegramCompatFetch | typeof globalThis.fetch,
@@ -86,6 +92,17 @@ function asTelegramCompatFetch(fetchImpl: TelegramClientFetch): TelegramCompatFe
return fetchImpl as unknown as TelegramCompatFetch;
}
function isTelegramAbortSignalLike(value: unknown): value is TelegramAbortSignalLike {
return (
typeof value === "object" &&
value !== null &&
"aborted" in value &&
typeof (value as { aborted?: unknown }).aborted === "boolean" &&
typeof (value as { addEventListener?: unknown }).addEventListener === "function" &&
typeof (value as { removeEventListener?: unknown }).removeEventListener === "function"
);
}
function readRequestUrl(input: TelegramFetchInput): string | null {
if (typeof input === "string") {
return input;
@@ -172,8 +189,11 @@ export function createTelegramBot(opts: TelegramBotOptions): TelegramBotInstance
// causing "signals[0] must be an instance of AbortSignal" errors).
finalFetch = (input: TelegramFetchInput, init?: TelegramFetchInit) => {
const controller = new AbortController();
const abortWith = (signal: AbortSignal) => controller.abort(signal.reason);
const shutdownSignal = opts.fetchAbortSignal;
const abortWith = (signal: Pick<TelegramAbortSignalLike, "reason">) =>
controller.abort(signal.reason);
const shutdownSignal = isTelegramAbortSignalLike(opts.fetchAbortSignal)
? opts.fetchAbortSignal
: undefined;
const onShutdown = () => {
if (shutdownSignal) {
abortWith(shutdownSignal);
@@ -183,7 +203,7 @@ export function createTelegramBot(opts: TelegramBotOptions): TelegramBotInstance
const requestTimeoutMs = resolveTelegramRequestTimeoutMs(method);
let requestTimeout: ReturnType<typeof setTimeout> | undefined;
let onRequestAbort: (() => void) | undefined;
const requestSignal = init?.signal;
const requestSignal = isTelegramAbortSignalLike(init?.signal) ? init.signal : undefined;
if (shutdownSignal?.aborted) {
abortWith(shutdownSignal);
} else if (shutdownSignal) {