@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
67 lines (66 loc) • 3.56 kB
TypeScript
/**
* Claude-Compatible Proxy Routes
*
* Exposes Anthropic-compatible /v1/messages, /v1/models, and /v1/messages/count_tokens
* endpoints. ALL requests are routed through ctx.neurolink.generate() / ctx.neurolink.stream()
* -- no direct HTTP calls to Anthropic.
*
* An optional ModelRouter can remap incoming model names to different
* provider/model pairs (e.g. "claude-sonnet-4-20250514" -> vertex/gemini-2.5-pro).
* Without a router, models are passed through to the Anthropic provider.
*/
import type { ModelRouter } from "../../proxy/modelRouter.js";
import type { ParsedClaudeError, ParsedClaudeRequest, ProxyPassthroughAccount, RouteGroup, RuntimeAccountState } from "../../types/index.js";
/** Resolve the configured primary's stable key to its current index in the
* request's enabledAccounts list. Returns 0 (insertion-order fallback) when
* no key is configured or the key cannot be matched (account disabled/
* removed). The resolution is per-request because enabledAccounts membership
* can shift between requests. */
declare function resolveHomeIndex(enabledAccounts: ProxyPassthroughAccount[]): number;
/** If the configured home primary is no longer cooling, reset
* primaryAccountIndex back to its index so traffic returns to the preferred
* account once its rate limit window expires. Called at the start of each
* request. Home is resolved fresh per call via resolveHomeIndex. */
declare function maybeResetPrimaryToHome(enabledAccounts: ProxyPassthroughAccount[]): void;
/**
* Create Claude-compatible proxy routes.
*
* Every request flows through ctx.neurolink.generate() or ctx.neurolink.stream().
* No direct fetch() calls to api.anthropic.com.
*
* @param modelRouter - Optional model router for remapping model names.
* @param basePath - Base path prefix (default: "" since Claude API uses /v1/...).
* @returns RouteGroup with Claude-compatible endpoints.
*/
export declare function createClaudeProxyRoutes(modelRouter?: ModelRouter, basePath?: string, accountStrategy?: "round-robin" | "fill-first", passthroughMode?: boolean, primaryAccountKey?: string): RouteGroup;
export declare function getTransientSameAccountRetryDelayMs(retryNumber: number): number;
/**
* Parse a Claude error payload when available.
*/
export declare function parseClaudeErrorBody(errBody: string): ParsedClaudeError;
/**
* Detect malformed request errors that should not trigger account/provider failover.
*/
export declare function isInvalidRequestError(status: number, errBody: string): boolean;
export declare function buildProxyFallbackOptions(parsed: ParsedClaudeRequest, overrides?: {
provider?: string;
model?: string;
}): Record<string, unknown>;
/**
* Detect transient upstream failures that should trigger account/provider failover.
*
* Includes Cloudflare 52x statuses and Anthropic 400/api_error wrappers that
* carry transient HTML responses (e.g. 520 pages) inside `error.message`.
*/
export declare function isTransientHttpFailure(status: number, errBody: string): boolean;
export declare const __testHooks: {
resolveHomeIndex: typeof resolveHomeIndex;
maybeResetPrimaryToHome: typeof maybeResetPrimaryToHome;
setConfiguredPrimaryAccountKey: (key: string | undefined) => void;
getConfiguredPrimaryAccountKey: () => string | undefined;
setPrimaryAccountIndex: (index: number) => void;
getPrimaryAccountIndex: () => number;
setAccountRuntimeState: (key: string, state: Partial<RuntimeAccountState>) => void;
resetAllRuntimeState: () => void;
};
export {};