UNPKG

@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

106 lines (105 loc) • 3.54 kB
/** * Hono Server Adapter * Primary server adapter implementation using Hono framework * Hono is chosen for its performance, TypeScript-first design, and edge compatibility */ import type { NeuroLink } from "../../neurolink.js"; import { BaseServerAdapter } from "../abstract/baseServerAdapter.js"; import type { MiddlewareDefinition, RouteDefinition, ServerAdapterConfig } from "../../types/index.js"; /** * Hono-specific server adapter * Supports multiple runtimes: Bun, Deno, Node.js */ export declare class HonoServerAdapter extends BaseServerAdapter { private app; private server?; private rateLimitStore; private rateLimitCleanupInterval?; private requestContextStore; private requestIds; private streamSSEFn; private parseFormBody; private getConnInfoFn?; private warnedNoClientAddress; constructor(neurolink: NeuroLink, config?: ServerAdapterConfig); /** * Create rate limiter middleware for Hono */ private createRateLimiter; /** * Periodically clean up expired rate limit entries */ private cleanupRateLimitStore; /** * Initialize Hono framework * Dynamically imports Hono and its middleware so requiring only another * adapter (Express/Fastify/Koa) never pulls Hono's import graph in. */ protected initializeFramework(): Promise<void>; /** * Register route with Hono */ protected registerFrameworkRoute(route: RouteDefinition): void; /** * Handle streaming response using SSE */ private handleStreamingResponse; /** * Transform a raw provider chunk into a StreamEvent * Provider chunks are typically { content: string } objects; * the client SDK expects { type: "text", content: string, timestamp: number } */ private toStreamEvent; /** * Register middleware with Hono */ protected registerFrameworkMiddleware(middleware: MiddlewareDefinition): void; /** * The id of this request: the caller's `X-Request-ID` when sent, otherwise * one generated on first use, and the same one on every later use. */ private requestIdFor; /** * Start the Hono server */ start(): Promise<void>; /** * Stop the Hono server with graceful shutdown */ stop(): Promise<void>; /** * Stop accepting new connections */ protected stopAcceptingConnections(): Promise<void>; /** * Close the underlying server */ protected closeServer(): Promise<void>; /** * Force close all active connections */ protected forceCloseConnections(): Promise<void>; /** * Get the Hono app instance */ getFrameworkInstance(): unknown; getNativeServer(): unknown; private extractHeaders; /** * The runtime's connection-info helper: `@hono/node-server`'s on Node, the * Bun or Deno adapter's there. Absent on a runtime that offers none. */ private loadConnInfo; /** The TCP peer of this request, when the runtime reports one. */ private remoteAddressFor; private extractQuery; /** * A request's context, or the 413 that answers a JSON or form body over its * limit. That answer is built here, before the context exists, so no * middleware (an auth check included) and no route runs for the request. * An upload over the limit still reaches its route as the error itself, * which answers in its own wire format. */ private createRequestContext; private extractBody; }