import type { RuntimeClientConfig, GenerateWsConnectionParams, GeneratePresignedUrlParams, GenerateWsConnectionOAuthParams, WebSocketConnection, OpenShellParams, ConnectShellSigV4Params, ConnectShellPresignedParams, ConnectShellOAuthParams, ShellConnectionSigV4, ShellConnectionPresigned, ShellConnectionOAuth } from './types.js'; import { ShellSession } from './shell/session.js'; /** * Client for generating WebSocket authentication for AgentCore Runtime. * * This client provides authentication credentials for WebSocket connections * to AgentCore Runtime endpoints, allowing applications to establish * bidirectional streaming connections with agent runtimes. * * The client is stateless and does not manage session lifecycle. Each method * call is independent and takes the runtime ARN as a parameter. * * @example * ```typescript * const client = new RuntimeClient({ region: 'us-west-2' }) * * // Generate WebSocket connection with SigV4 headers * const { url, headers } = await client.generateWsConnection({ * runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-runtime', * endpointName: 'DEFAULT' * }) * * // Generate presigned WebSocket URL * const presignedUrl = await client.generatePresignedUrl({ * runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/my-runtime', * expires: 300 * }) * ``` */ export declare class RuntimeClient { readonly region: string; private readonly credentialsProvider; /** * Creates a new RuntimeClient instance. * * @param config - Configuration options for the client * @throws Error if region is not provided via config or AWS_REGION environment variable */ constructor(config?: RuntimeClientConfig); /** * Parses runtime ARN and extracts components. * * @param runtimeArn - Full runtime ARN * @returns Parsed ARN components * @throws Error if ARN format is invalid * * @internal */ private _parseAndValidateRegion; private _parseRuntimeArn; /** @internal */ private _buildWsUrl; /** @internal */ private _buildWebSocketUrl; /** * Generates WebSocket URL and SigV4 signed headers for runtime connection. * * This method creates authentication credentials for establishing a WebSocket * connection to an AgentCore Runtime. The returned headers include AWS SigV4 * signature for authentication. * * @param params - Parameters for generating the connection * @returns WebSocket URL and authentication headers * * @throws Error if runtime ARN format is invalid * @throws Error if AWS credentials are not available * * @example * ```typescript * const client = new RuntimeClient({ region: 'us-west-2' }) * * // With auto-generated session ID * const { url, headers } = await client.generateWsConnection({ * runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime' * }) * * // With custom session ID and endpoint * const connection = await client.generateWsConnection({ * runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime', * sessionId: 'my-session-123', * endpointName: 'DEFAULT' * }) * ``` */ generateWsConnection(params: GenerateWsConnectionParams): Promise; /** * Generates a presigned WebSocket URL for runtime connection. * * Presigned URLs include authentication in query parameters, allowing * frontend clients to connect without managing AWS credentials. * * @param params - Parameters for generating the presigned URL * @returns Presigned WebSocket URL with authentication in query parameters * * @throws Error if expires exceeds maximum (300 seconds) * @throws Error if runtime ARN format is invalid * @throws Error if AWS credentials are not available * * @example * ```typescript * const client = new RuntimeClient({ region: 'us-west-2' }) * * // Basic presigned URL * const url = await client.generatePresignedUrl({ * runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime' * }) * * // With custom parameters * const url = await client.generatePresignedUrl({ * runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime', * sessionId: 'my-session-123', * endpointName: 'DEFAULT', * customHeaders: { 'custom-param': 'value' }, * expires: 300 * }) * ``` */ generatePresignedUrl(params: GeneratePresignedUrlParams): Promise; /** @internal */ private _buildShellUrl; /** Sign a wss:// URL with SigV4 headers, including the session ID. @internal */ private _sigV4SignWsUrl; /** Presign a wss:// URL, embedding auth in query params. @internal */ private _presignWsUrl; /** * Generate a SigV4-signed WebSocket URL and headers for a shell connection. * Low-level helper — use `openShell` for a fully managed session. * * @example * ```typescript * const { url, headers } = await client.connectShellSigV4({ runtimeArn, shellId, sessionId }) * const ws = new WebSocket(url, { headers }) * ``` */ connectShellSigV4(params: ConnectShellSigV4Params): Promise; /** * Generate a presigned WebSocket URL for a shell connection. Auth is embedded * in the query string — suitable for browser clients or short-lived tokens. * Low-level helper — use `openShell` for a fully managed session. * * @example * ```typescript * const { url } = await client.connectShellPresigned({ runtimeArn, shellId, sessionId, expires: 120 }) * const ws = new WebSocket(url) * ``` */ connectShellPresigned(params: ConnectShellPresignedParams): Promise; /** * Generate a WebSocket URL and OAuth subprotocols for a shell connection. * Low-level helper — use `openShell` for a fully managed session. * * @example * ```typescript * const { url, subprotocols } = await client.connectShellOAuth({ runtimeArn, shellId, sessionId, bearerToken }) * const ws = new WebSocket(url, subprotocols) * ``` */ connectShellOAuth(params: ConnectShellOAuthParams): Promise; /** * Open a fully managed interactive PTY shell session on an agent VM. * * Returns a connected `ShellSession` — an async iterable that yields `ShellFrame` * objects. Call `close()` when done, or use `try/finally`. * * For lower-level control (custom WebSocket handling, browser relay), use the * `connectShellSigV4`, `connectShellPresigned`, or `connectShellOAuth` helpers * directly with `ShellFramer`. * * @example * ```typescript * const shell = await client.openShell({ runtimeArn }) * try { * await shell.send('echo hello\n') * for await (const frame of shell) { * if (frame.channel === ShellChannel.STDOUT) process.stdout.write(frame.text) * } * } finally { * await shell.close() * } * ``` * * @example Auto-reconnect: * ```typescript * const shell = await client.openShell({ * runtimeArn, * shellId: 'debug', * reconnectConfig: { maxRetries: 5, onReconnect: (r) => console.log('reconnected:', r) } * }) * ``` */ openShell(params: OpenShellParams): Promise; /** * Generates WebSocket URL and OAuth headers for runtime connection. * * This method uses OAuth bearer token authentication instead of AWS SigV4. * Suitable for scenarios where OAuth tokens are used for authentication. * Does NOT require AWS credentials. * * @param params - Parameters for generating the connection * @returns WebSocket URL and OAuth authentication headers * * @throws Error if bearer token is empty * @throws Error if runtime ARN format is invalid * * @example * ```typescript * const client = new RuntimeClient({ region: 'us-west-2' }) * * // With OAuth bearer token * const { url, headers } = await client.generateWsConnectionOAuth({ * runtimeArn: 'arn:aws:bedrock-agentcore:us-west-2:123:runtime/my-runtime', * bearerToken: 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...', * endpointName: 'DEFAULT' * }) * * // Use with WebSocket client * const ws = new WebSocket(url, { headers }) * ``` */ generateWsConnectionOAuth(params: GenerateWsConnectionOAuthParams): Promise; } //# sourceMappingURL=client.d.ts.map