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

82 lines (81 loc) • 2.53 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 HTTPExceptionCtor; private streamSSEFn; 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; /** * 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; private extractHeaders; private extractQuery; private extractBody; }