UNPKG

@pompeii-labs/magma

Version:

The Typescript framework to build AI agents quickly and easily

104 lines (101 loc) 4.28 kB
import { Request, Response } from 'express'; import { g as MagmaAgent, h as MagmaToolReturnType, i as MagmaToolCall, j as MagmaToolParam, k as MagmaMiddlewareTriggerType, l as MagmaMiddlewareReturnType, m as MagmaMiddlewareParamType, b as MagmaHook } from './trace-BClTKMpT.mjs'; import '@anthropic-ai/sdk'; import 'openai/resources/chat/completions/completions'; import '@google/generative-ai'; import 'groq-sdk'; import 'groq-sdk/resources/chat/completions'; import 'openai'; /** * Decorator to define a tool (optional) * @param args name and description for tool */ declare function tool(args: { name?: string; description?: string; cache?: boolean; enabled?: (agent: MagmaAgent) => boolean; }): <R extends MagmaToolReturnType | Promise<MagmaToolReturnType>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<((call: MagmaToolCall, agent: MagmaAgent) => R) & { _toolInfo?: { name?: string; description?: string; cache?: boolean; enabled?: (agent: MagmaAgent) => boolean; }; }>) => void; /** * Decorator for functions that are exposed to OpenAI tool calls * @param key name of the parameter * @param type type of the parameter (string, number, boolean, object, array) * @param description optional description of the parameter * @param required whether the parameter is required or not */ declare function toolparam(args: MagmaToolParam & { key: string; required?: boolean; }): <R extends MagmaToolReturnType | Promise<MagmaToolReturnType>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<((call: MagmaToolCall, agent: MagmaAgent) => R) & { _methodName?: string; _parameterInfo?: (MagmaToolParam & { key: string; required?: boolean; })[]; }>) => void; /** * Decorator for middleware functions to run during completion chains * @param trigger which middleware event should trigger the decorated function */ declare function middleware<T extends MagmaMiddlewareTriggerType>(trigger: T, options?: T extends 'preCompletion' | 'onToolExecution' ? { order?: number; } : { critical?: boolean; order?: number; }): <R extends MagmaMiddlewareReturnType<T> | Promise<MagmaMiddlewareReturnType<T>>>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<((content?: MagmaMiddlewareParamType<T>, agent?: MagmaAgent) => R) & { _middlewareTrigger?: T; _critical?: boolean; _order?: number; _name?: string; _id?: string; }>) => TypedPropertyDescriptor<((content?: MagmaMiddlewareParamType<T>, agent?: MagmaAgent) => R) & { _middlewareTrigger?: T; _critical?: boolean; _order?: number; _name?: string; _id?: string; }>; /** * Decorator for webhook functions * @param hookName name of the hook * @param options configuration options for the hook * @param options.session session configuration for the hook * @param options.setup arguments to pass to the agent's setup function before the hook handler is called * Examples: * @hook('notification') -> POST /hooks/notification * @hook('notification', { session: 'default' }) * @hook('notification', { session: (req) => req.body.userId }) * @hook('notification', { session: fetchFromExternal(req) }) */ declare function hook(hookName: string, options?: { session?: MagmaHook['session']; description?: string; setup?: MagmaHook['setup']; }): <R extends void>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<((req: Request, res: Response, agent?: MagmaAgent) => R) & { _hookName?: string; _session?: MagmaHook["session"]; _description?: string; _setup?: MagmaHook["setup"]; }>) => void; /** * Decorator for scheduled jobs * @param cron cron expression (https://www.npmjs.com/package/node-cron#cron-syntax) * @param options configuration options for the job * @param options.timezone set the timezone for the job schedule */ declare function job(cron: string, options?: { timezone?: string; }): <R extends void>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<((agent?: MagmaAgent) => R) & { _schedule?: string; _options?: { timezone?: string; }; }>) => void; export { hook, job, middleware, tool, toolparam };