import 'reflect-metadata'; import { type ConcurrencyConfigInput, type RateLimitConfigInput, type TimeoutConfigInput } from '@frontmcp/guard'; import type z from '@frontmcp/lazy-zod'; import { type AgentContext } from '../interfaces'; import { type AgentMetadata, type ToolInputType, type ToolOutputType } from '../metadata'; type AgentContextBase = { execute: (...args: any[]) => any; }; /** * Handler type for function-based agents. */ export type FrontMcpAgentExecuteHandler, Out = AgentOutputOf<{ outputSchema: OutSchema; }>> = (input: In, ctx: AgentContextBase) => Out | Promise; /** * Return type for function-based agents created with agent(). * Contains the handler function and agent metadata symbols. */ export type FrontMcpAgentFunction = (() => FrontMcpAgentExecuteHandler) & {}; /** * Function decorator that creates an agent from a handler function. * * @example * ```typescript * const researchAgent = agent({ * name: 'research-agent', * inputSchema: { topic: z.string() }, * llm: { adapter: 'openai', model: 'gpt-4-turbo', apiKey: { env: 'OPENAI_API_KEY' } }, * })((input, ctx) => { * // Agent implementation * return { result: 'done' }; * }); * ``` */ declare function frontMcpAgent, InSchema extends ToolInputType = T['inputSchema'] extends ToolInputType ? T['inputSchema'] : ToolInputType, OutSchema extends ToolOutputType = T['outputSchema']>(providedMetadata: T): (handler: FrontMcpAgentExecuteHandler) => FrontMcpAgentFunction; export { FrontMcpAgent, FrontMcpAgent as Agent, frontMcpAgent, frontMcpAgent as agent }; /** * This is a modified version following the tool decorator pattern. * Provides type inference for agent input/output schemas. */ type __Shape = z.ZodRawShape; type __AsZodObj = T extends z.ZodRawShape ? z.ZodObject : never; /** * Infers the input type from an agent's inputSchema. */ export type AgentInputOf = Opt extends { inputSchema: infer I; } ? z.infer<__AsZodObj> : never; /** * Helper to infer the return type from any Zod schema. */ type __InferZod = S extends z.ZodType ? z.infer : S extends z.ZodRawShape ? z.infer> : never; /** * Infers the output type from a single schema definition. */ type __InferFromSingleSchema = S extends 'string' ? string : S extends 'number' ? number : S extends 'boolean' ? boolean : S extends 'date' ? Date : S extends z.ZodType | z.ZodRawShape ? __InferZod : any; /** * Infers a tuple/array of output types from an array of schemas. */ type __InferFromArraySchema = A extends readonly any[] ? { [K in keyof A]: __InferFromSingleSchema; } : never; /** * Main output type inference for agents. * Handles single schemas, arrays of schemas, or no schema. */ export type AgentOutputOf = Opt extends { outputSchema: infer O; } ? O extends readonly any[] ? __InferFromArraySchema : __InferFromSingleSchema : any; type __Ctor = (new (...a: any[]) => any) | (abstract new (...a: any[]) => any); type __A = C extends new (...a: infer A) => any ? A : C extends abstract new (...a: infer A) => any ? A : never; type __R = C extends new (...a: any[]) => infer R ? R : C extends abstract new (...a: any[]) => infer R ? R : never; type __Param = __R extends { execute: (arg: infer P, ...r: any) => any; } ? P : never; type __Return = __R extends { execute: (...a: any) => infer R; } ? R : never; type __Unwrap = T extends Promise ? U : T; type __IsAny = 0 extends 1 & T ? true : false; type __IsBaseClassDefault

= P extends Record ? Record extends P ? true : false : false; type __MustParam = __IsAny extends true ? unknown : __IsAny<__Param> extends true ? { 'execute() parameter error': "Parameter type must not be 'any'."; expected_input_type: In; } : __IsBaseClassDefault<__Param> extends true ? unknown : __Param extends In ? In extends __Param ? unknown : { 'execute() parameter error': 'Parameter type is too wide. It must exactly match the input schema.'; expected_input_type: In; actual_parameter_type: __Param; } : { 'execute() parameter error': 'Parameter type does not match the input schema.'; expected_input_type: In; actual_parameter_type: __Param; }; type __MustReturn = __IsAny extends true ? unknown : __Unwrap<__Return> extends Out ? unknown : { 'execute() return type error': "The method's return type is not assignable to the expected output schema type."; expected_output_type: Out; 'actual_return_type (unwrapped)': __Unwrap<__Return>; }; type __MustExtendCtx = __R extends AgentContext ? unknown : { 'Agent class error': 'Class must extend AgentContext'; }; type __Rewrap = C extends abstract new (...a: __A) => __R ? C & (abstract new (...a: __A) => AgentContextBase & __R) : C extends new (...a: __A) => __R ? C & (new (...a: __A) => AgentContextBase & __R) : never; type __PrimitiveOutputType = 'string' | 'number' | 'date' | 'boolean' | z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodDate; type __StructuredOutputType = z.ZodRawShape | z.ZodObject | z.ZodArray | z.ZodUnion<[z.ZodObject, ...z.ZodObject[]]> | z.ZodDiscriminatedUnion<[z.ZodObject, ...z.ZodObject[]]>; type __AgentSingleOutputType = __PrimitiveOutputType | __StructuredOutputType; type __OutputSchema = __AgentSingleOutputType | __AgentSingleOutputType[]; /** * Agent metadata options with permissive guard config types for IDE IntelliSense. * * Guard fields (concurrency, rateLimit, timeout) use auto-generated Input types * where all fields are optional. Required fields are validated at runtime by Zod. * @see schemas.generated.ts in @frontmcp/guard * * These fields are `Omit`-ed from {@link AgentMetadata} and re-declared with the * permissive `*Input` types. The re-declarations carry their own JSDoc so editor * hover docs work on them (the base field docs do not survive `Omit`) — #452. */ export type AgentMetadataOptions = Omit, 'concurrency' | 'rateLimit' | 'timeout'> & { /** * Concurrency control for this agent — caps the number of simultaneous executions. * * @example * ```typescript * @Agent({ name: 'researcher', inputSchema: { topic: z.string() }, concurrency: { maxConcurrent: 2 } }) * ``` */ concurrency?: ConcurrencyConfigInput; /** * Rate limiting for this agent — how many invocations are allowed within a time window. * * @example * ```typescript * @Agent({ * name: 'researcher', * inputSchema: { topic: z.string() }, * rateLimit: { maxRequests: 20, windowMs: 60_000 }, * }) * ``` */ rateLimit?: RateLimitConfigInput; /** * Timeout for this agent's execution — wraps the execute stage with a deadline. * * @example * ```typescript * @Agent({ name: 'researcher', inputSchema: { topic: z.string() }, timeout: { executeMs: 120_000 } }) * ``` */ timeout?: TimeoutConfigInput; }; declare module '@frontmcp/sdk' { function Agent(opts: AgentMetadataOptions & { outputSchema: O; }): (cls: C & __MustExtendCtx & __MustParam> & __MustReturn>) => __Rewrap, AgentOutputOf<{ outputSchema: O; }>>; function Agent(opts: AgentMetadataOptions & { outputSchema?: never; }): (cls: C & __MustExtendCtx & __MustParam> & __MustReturn>) => __Rewrap, AgentOutputOf<{}>>; } //# sourceMappingURL=agent.decorator.d.ts.map