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

188 lines (187 loc) • 7.17 kB
/** * Request Validation Utilities * Provides Zod schemas and validation helpers for server routes */ import { z } from "zod"; import type { ErrorResponse, ServerValidationResult } from "../../types/index.js"; /** * Agent execute request schema */ export declare const AgentExecuteRequestSchema: z.ZodObject<{ input: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{ text: z.ZodString; images: z.ZodOptional<z.ZodArray<z.ZodString>>; files: z.ZodOptional<z.ZodArray<z.ZodString>>; }, z.core.$strip>]>; provider: z.ZodOptional<z.ZodString>; model: z.ZodOptional<z.ZodString>; systemPrompt: z.ZodOptional<z.ZodString>; temperature: z.ZodOptional<z.ZodNumber>; maxTokens: z.ZodOptional<z.ZodNumber>; tools: z.ZodOptional<z.ZodArray<z.ZodString>>; stream: z.ZodOptional<z.ZodBoolean>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; }, z.core.$strip>; /** * Options a WebSocket `generate`/`stream` message may pass through to * `neurolink.generate()`/`.stream()`. Deliberately an allowlist, not the full * `GenerateOptions`/`StreamOptions` shape: the raw client JSON is untrusted, * and `GenerateOptions.credentials` in particular carries a per-provider * `baseURL` (see `NeurolinkCredentials`) that would otherwise let any caller * redirect the server's own outbound request to an arbitrary host (SSRF) or * swap in their own API key. `z.object` strips unknown keys by default, so * `credentials` and anything else outside this list never reaches the SDK * call — the same posture `AgentExecuteRequestSchema` already takes for the * equivalent HTTP route. */ export declare const WebSocketAgentOptionsSchema: z.ZodObject<{ provider: z.ZodOptional<z.ZodString>; model: z.ZodOptional<z.ZodString>; systemPrompt: z.ZodOptional<z.ZodString>; temperature: z.ZodOptional<z.ZodNumber>; maxTokens: z.ZodOptional<z.ZodNumber>; maxSteps: z.ZodOptional<z.ZodNumber>; }, z.core.$strip>; /** * WebSocket `generate`/`stream` message payload schema. */ export declare const WebSocketAgentRequestSchema: z.ZodObject<{ prompt: z.ZodString; options: z.ZodOptional<z.ZodObject<{ provider: z.ZodOptional<z.ZodString>; model: z.ZodOptional<z.ZodString>; systemPrompt: z.ZodOptional<z.ZodString>; temperature: z.ZodOptional<z.ZodNumber>; maxTokens: z.ZodOptional<z.ZodNumber>; maxSteps: z.ZodOptional<z.ZodNumber>; }, z.core.$strip>>; }, z.core.$strip>; /** * Tool execute request schema */ export declare const ToolExecuteRequestSchema: z.ZodObject<{ name: z.ZodString; arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>; sessionId: z.ZodOptional<z.ZodString>; userId: z.ZodOptional<z.ZodString>; }, z.core.$strip>; /** * Tool arguments schema (for direct tool execution) */ export declare const ToolArgumentsSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>; /** * Memory session ID parameter schema */ export declare const SessionIdParamSchema: z.ZodObject<{ sessionId: z.ZodString; }, z.core.$strip>; /** * MCP server name parameter schema */ export declare const ServerNameParamSchema: z.ZodObject<{ name: z.ZodString; }, z.core.$strip>; /** * Tool name parameter schema */ export declare const ToolNameParamSchema: z.ZodObject<{ name: z.ZodString; }, z.core.$strip>; /** * Tool search query schema */ export declare const ToolSearchQuerySchema: z.ZodObject<{ q: z.ZodOptional<z.ZodString>; source: z.ZodOptional<z.ZodString>; limit: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>; }, z.core.$strip>; /** * Generic ID parameter schema (for session endpoints using :id) */ export declare const IdParamSchema: z.ZodObject<{ id: z.ZodString; }, z.core.$strip>; /** * Sessions list query schema (with optional pagination and filtering) */ export declare const SessionsListQuerySchema: z.ZodObject<{ userId: z.ZodOptional<z.ZodString>; limit: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>; offset: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>; }, z.core.$strip>; /** * Session messages query schema (for pagination) */ export declare const SessionMessagesQuerySchema: z.ZodObject<{ limit: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>; offset: z.ZodOptional<z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>, z.ZodNumber>>; }, z.core.$strip>; /** * Embed request schema (single text) */ export declare const EmbedRequestSchema: z.ZodObject<{ text: z.ZodString; provider: z.ZodOptional<z.ZodString>; model: z.ZodOptional<z.ZodString>; }, z.core.$strip>; /** * Embed many request schema (batch texts) */ export declare const EmbedManyRequestSchema: z.ZodObject<{ texts: z.ZodArray<z.ZodString>; provider: z.ZodOptional<z.ZodString>; model: z.ZodOptional<z.ZodString>; }, z.core.$strip>; /** * Skill create request schema */ export declare const SkillCreateRequestSchema: z.ZodObject<{ name: z.ZodString; displayName: z.ZodOptional<z.ZodString>; description: z.ZodString; instructions: z.ZodString; tags: z.ZodOptional<z.ZodArray<z.ZodString>>; scope: z.ZodOptional<z.ZodEnum<{ global: "global"; scoped: "scoped"; }>>; scopeIds: z.ZodOptional<z.ZodArray<z.ZodString>>; requestedBy: z.ZodOptional<z.ZodString>; }, z.core.$strip>; /** * Skill update request schema — all fields optional (patch semantics) */ export declare const SkillUpdateRequestSchema: z.ZodObject<{ name: z.ZodOptional<z.ZodString>; displayName: z.ZodOptional<z.ZodOptional<z.ZodString>>; description: z.ZodOptional<z.ZodString>; instructions: z.ZodOptional<z.ZodString>; tags: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodString>>>; scope: z.ZodOptional<z.ZodOptional<z.ZodEnum<{ global: "global"; scoped: "scoped"; }>>>; scopeIds: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodString>>>; requestedBy: z.ZodOptional<z.ZodOptional<z.ZodString>>; }, z.core.$strip>; /** * Type guard to check if a value is an ErrorResponse */ export declare function isErrorResponse(value: unknown): value is ErrorResponse; /** * Create a standardized error response */ export declare function createErrorResponse(code: string, message: string, details?: unknown, requestId?: string, httpStatus?: number): ErrorResponse; /** * Validate request body against a Zod schema */ export declare function validateRequest<T>(schema: z.ZodSchema<T>, data: unknown, requestId?: string): ServerValidationResult<T>; /** * Validate query parameters against a Zod schema */ export declare function validateQuery<T>(schema: z.ZodSchema<T>, query: Record<string, string>, requestId?: string): ServerValidationResult<T>; /** * Validate path parameters against a Zod schema */ export declare function validateParams<T>(schema: z.ZodSchema<T>, params: Record<string, string>, requestId?: string): ServerValidationResult<T>;