import { z } from 'zod'; import type { BedrockAgentCoreAppParams, AsyncTaskStatus, HealthStatus } from './types.js'; /** * Fastify-based HTTP server for hosting agents on AWS Bedrock AgentCore Runtime. * * This class provides an HTTP server that implements the AgentCore Runtime protocol * with health check and invocation endpoints. The server runs on port 8080 and * handles both JSON responses and Server-Sent Events (SSE) streaming. * * @example * ```typescript * const app = new BedrockAgentCoreApp({ * invocationHandler: { * requestSchema: z.object({ message: z.string() }), * process: async (request, context) => { * console.log(`Processing request with session ${context.sessionId}`) * return `Hello ${request.message}!` * } * } * }) * * app.run() * ``` */ export declare class BedrockAgentCoreApp> { private readonly _app; private readonly _config; private readonly _handler; private _websocketHandler; private readonly _activeTasksMap; private _taskCounter; private _pingHandler; private _forcedPingStatus?; private _lastStatusUpdateTime; private _lastKnownStatus?; /** * Creates a new BedrockAgentCoreApp instance. * * @param params - Configuration including handler and optional settings */ constructor(params: BedrockAgentCoreAppParams); /** * Starts the Fastify server. * * @param options - Optional server options. Supports `port` (defaults to 8080) and `host` (defaults to '0.0.0.0'). */ run(options?: { port?: number; host?: string; }): void; /** * Register an async task for health tracking. * * @param name - Human-readable task name * @param metadata - Optional task metadata * @returns Task ID for completion tracking */ addAsyncTask(name: string, metadata?: Record): number; /** * Mark an async task as complete. * * @param taskId - Task ID from addAsyncTask * @returns True if task was found and removed */ completeAsyncTask(taskId: number): boolean; /** * Get current ping status based on priority system. * Priority: Forced \> Custom Handler \> Automatic * * @returns Current health status */ getCurrentPingStatus(): HealthStatus; /** * Decorator to automatically track async tasks. * Status becomes HealthyBusy during execution. * * @param fn - Async function to wrap * @returns Wrapped function with automatic task tracking * @throws Error if fn is not an async function */ asyncTask Promise>(fn: T): T; /** * Get information about currently running async tasks. * * @returns Task status with count and details */ getAsyncTaskInfo(): AsyncTaskStatus; /** * Sets up HTTP routes for the server. */ private _setupRoutes; /** * Register custom content type parsers using Fastify's native addContentTypeParser. */ private _setupContentTypeParsers; /** * Registers Fastify plugins. */ private _registerPlugins; /** * Gets the logger configuration based on BedrockAgentCoreAppConfig. * * @returns Fastify logger configuration */ private _getLoggerConfig; /** * Handles health check requests. * * @param request - Fastify request object * @param reply - Fastify reply object */ private _handlePing; /** * Handles agent invocation requests. * * @param request - Fastify request object * @param reply - Fastify reply object */ private _handleInvocation; /** * Checks if a value is an async generator. * * @param value - Value to check * @returns True if the value is an async generator */ private _isAsyncGenerator; /** * Handles streaming response using Server-Sent Events (SSE) via Fastify SSE plugin. * * @param reply - Fastify reply object * @param generator - Async generator that yields data chunks */ private _handleStreamingResponse; /** * Normalizes a chunk yielded by the user's async generator into a valid SSESource. * * \@fastify/sse's send() accepts: string, Buffer, SSEMessage (object with `data` field), * Readable, or AsyncIterable. Arbitrary objects without a `data` field are rejected. * This method wraps such objects as `{ data: chunk }` so they are sent as SSE data. * * @param chunk - Raw value yielded by the generator * @returns A valid SSESource */ private _normalizeSSEChunk; /** * Handles WebSocket connections at /ws endpoint. * * @param connection - Fastify WebSocket connection * @param request - Fastify request object */ private _handleWebSocket; /** * Extracts request context from the incoming request. * * @param request - Fastify request object * @returns Request context with sessionId, headers, and request-scoped logger */ private _extractContext; } //# sourceMappingURL=app.d.ts.map