@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
88 lines (87 loc) • 3.91 kB
JavaScript
/**
* Route Builders
* Pre-built route definitions for common NeuroLink endpoints
*/
import { createAgentRoutes } from "./agentRoutes.js";
import { createClaudeProxyRoutes } from "./claudeProxyRoutes.js";
// ClaudeProxyDeps removed
import { createGeminiProxyRoutes } from "./geminiProxyRoutes.js";
import { createHealthRoutes } from "./healthRoutes.js";
import { createOpenAIProxyRoutes } from "./openaiProxyRoutes.js";
import { createCodexProxyRoutes } from "./codexProxyRoutes.js";
import { createMCPRoutes } from "./mcpRoutes.js";
import { createMemoryRoutes } from "./memoryRoutes.js";
import { createOpenApiRoutes } from "./openApiRoutes.js";
import { createToolRoutes } from "./toolRoutes.js";
// Re-export route builders from individual files
export { createAgentRoutes } from "./agentRoutes.js";
export { createClaudeProxyRoutes } from "./claudeProxyRoutes.js";
// ClaudeProxyDeps removed
export { createHealthRoutes } from "./healthRoutes.js";
export { createOpenAIProxyRoutes } from "./openaiProxyRoutes.js";
export { createCodexProxyRoutes } from "./codexProxyRoutes.js";
export { createGeminiProxyRoutes } from "./geminiProxyRoutes.js";
export { createMCPRoutes } from "./mcpRoutes.js";
export { createMemoryRoutes } from "./memoryRoutes.js";
export { createOpenApiRoutes } from "./openApiRoutes.js";
export { createToolRoutes } from "./toolRoutes.js";
/**
* Create all standard routes
* Convenience method that combines all route groups
*
* NOTE on the Codex outbound fallback's `anthropic` target: this function
* does not thread `loopbackPort`/`internalDispatch` into
* `createCodexProxyRoutes`, so that target cannot dispatch when the feature
* is enabled through `options.runtimeConfigProvider` here — only the CLI
* proxy command wires the in-process loopback directly. Route creation logs
* one warning when this gap applies; see `CreateRoutesOptions.runtimeConfigProvider`
* and docs/features/codex-proxy-support.md.
*/
export function createAllRoutes(basePath = "/api", options) {
const routes = [
createAgentRoutes(basePath),
createToolRoutes(basePath),
createMCPRoutes(basePath),
createMemoryRoutes(basePath),
createHealthRoutes(basePath),
];
// Conditionally add OpenAPI/Swagger routes
if (options?.enableSwagger) {
routes.push(createOpenApiRoutes(basePath, options.getRoutes));
}
// Unified proxy flag enables every door. Codex was omitted here for long
// enough that it became reachable only from `neurolink proxy start`; a
// consumer opting into proxying means all of it, not a subset.
// Legacy per-format flags are still supported for backward compatibility.
const enableClaudeProxy = options?.proxy || options?.claudeProxy;
const enableOpenAIProxy = options?.proxy || options?.openaiProxy;
const enableCodexProxy = options?.proxy || options?.codexProxy;
const enableGeminiProxy = options?.proxy || options?.geminiProxy;
if (enableClaudeProxy) {
routes.push(createClaudeProxyRoutes(undefined, basePath));
}
if (enableOpenAIProxy) {
routes.push(createOpenAIProxyRoutes(undefined, basePath));
}
if (enableCodexProxy) {
routes.push(createCodexProxyRoutes(basePath, options?.runtimeConfigProvider));
}
if (enableGeminiProxy) {
routes.push(createGeminiProxyRoutes(undefined, basePath));
}
return routes;
}
/**
* Register all routes with a server adapter
*/
export function registerAllRoutes(adapter, basePath = "/api", options) {
// If adapter has listRoutes and getRoutes not provided, use adapter's listRoutes
const routeOptions = {
...options,
getRoutes: options?.getRoutes ?? adapter.listRoutes?.bind(adapter),
};
const routeGroups = createAllRoutes(basePath, routeOptions);
for (const group of routeGroups) {
adapter.registerRouteGroup(group);
}
}