/** * Higher-order functions for wrapping tools with automatic credential injection */ import type { OAuth2WrapperConfig, ApiKeyWrapperConfig } from './types.js'; /** * Helper type to extract all parameters except the last one (the token/apiKey) */ type InitParams = T extends [...infer Init, unknown] ? Init : never; /** * Wraps an async function to automatically inject OAuth2 access token. * The token is injected as the last parameter of the wrapped function. * * @param config - OAuth2 configuration * @returns Function wrapper that injects token as last parameter * * @example * ```typescript * const myTool = withAccessToken({ * workloadIdentityToken: token, * providerName: 'github', * scopes: ['repo'], * authFlow: 'M2M' * })(async (input: string, token: string) => { * // Use token to call GitHub API * return { result: input }; * }); * * await myTool('hello'); // token injected automatically * ``` */ export declare function withAccessToken(config: OAuth2WrapperConfig): (fn: (...args: TParams) => Promise) => ((...args: InitParams) => Promise); /** * Wraps an async function to automatically inject API key. * The API key is injected as the last parameter of the wrapped function. * * @param config - API key configuration * @returns Function wrapper that injects API key as last parameter * * @example * ```typescript * const myTool = withApiKey({ * workloadIdentityToken: token, * providerName: 'openai' * })(async (input: string, apiKey: string) => { * // Use API key to call OpenAI API * return { result: input }; * }); * * await myTool('hello'); // apiKey injected automatically * ``` */ export declare function withApiKey(config: ApiKeyWrapperConfig): (fn: (...args: TParams) => Promise) => ((...args: InitParams) => Promise); /** * Wraps an async function to automatically inject the Workload Access Token (WAT). * The WAT is read from the current request context and injected as the last parameter. * * * @param fn - Async function whose last parameter receives the WAT * @returns Wrapped function that injects the WAT automatically * * @example * ```typescript * const callGateway = withWAT(async (query: string, wat: string) => { * return fetch('https://gateway.example.com/mcp', { * headers: { 'X-Amz-Bedrock-AgentCore-Identity-WAT': wat } * }) * }) * * // Inside a request handler — wat injected from context * await callGateway('what is the weather?') * ``` */ export declare function withWAT(fn: (...args: [...TParams, string]) => Promise): (...args: TParams) => Promise; export {}; //# sourceMappingURL=wrappers.d.ts.map