import { k as AgentHandlers, A as Agent, q as AgentNotification } from './agent.types-crcJBtCy.cjs'; import { W as Workflow, L as Logger, C as ClientOptions, H as HealthCheck, e as DiscoverOutput, i as Event, n as ExecuteOutput, d as CodeResult, j as EventTriggerParams, m as Execute, t as WorkflowOptions } from './health-check.types-C2XZ-Tpt.cjs'; import { A as Awaitable } from './util.types-DaFfsxgy.cjs'; import 'chat'; import { S as Schema, a as FromSchema, F as FromSchemaUnvalidated } from './base.schema.types-BApIn9jr.cjs'; import './step-resolver.cjs'; import './subscriber.types-BanvmGul.cjs'; /** * Define a new conversational agent. * * @param agentId - Unique identifier matching the agent entity created in Novu (e.g. 'wine-bot') * @param handlers - Handler functions for agent events */ declare function agent(agentId: string, handlers: AgentHandlers): Agent; /** * Narrows `notification.payload` to the workflow's schema when `workflowId` matches `workflow.id`. */ declare function isFromWorkflow>(notification: AgentNotification | null, workflow: Workflow): notification is AgentNotification; declare class Client { private discoveredWorkflows; private discoverWorkflowPromises; private registeredAgents; private templateEngine; secretKey: string; apiUrl: string; version: string; strictAuthentication: boolean; verbose: boolean; logger: Logger; constructor(options?: ClientOptions); private buildOptions; private log; /** * Adds workflows to the client. * * A locking mechanism is used to ensure that duplicate workflows are not added. * * @param workflows - The workflows to add. */ addWorkflows(workflows: Array): Promise; addAgents(agents: Array): void; getAgent(agentId: string): Agent | undefined; private addWorkflow; healthCheck(): HealthCheck; private getWorkflow; private getStep; private getRegisteredWorkflows; discover(): DiscoverOutput; /** * Mocks data based on the given schema. * The `default` value in the schema is used as the base data. * If no `default` value is provided, the data is generated using JSONSchemaFaker. * * @param schema * @returns mocked data */ private mock; private validate; private throwInvalidProvider; private throwInvalidStep; private throwInvalidEvent; private executeStepFactory; private shouldSanitize; private shouldSkip; executeWorkflow(event: Event): Promise; private createExecutionPayload; private prettyPrintExecute; private executeProviders; private runProvider; private resolveProviderOutput; private executeStep; /** * Code-first chat steps may return `card` as a `chat` JSX element (e.g. `Card(...)`) or a plain * `CardElement`. Normalize it to plain `CardElement` JSON before validation so it matches the * chat output schema and can cross the bridge unchanged. Non-chat steps and card-less outputs * pass through untouched. */ private normalizeChatCardOutput; private compileControls; /** * Preprocesses standalone translation patterns. * Transforms {{t.key}} to [T:key] placeholder (not Liquid syntax, passes through unchanged). */ private preprocessTranslationPatterns; /** * Preprocesses translation keys used as filter arguments. * Transforms 't.key' to '[T:key]' placeholder (not Liquid syntax, passes through unchanged). * Example: pluralize: 't.apple', 't.apples' → pluralize: '[T:apple]', '[T:apples]' */ private preprocessFilterTranslationArgs; /** * Post-processes placeholders back to translation markers after Liquid render. * Transforms [T:key] back to {{t.key}} for the translation service. */ private postprocessTranslationMarkers; /** * Create the controls for a step, taking both the event controls and the default controls into account * * @param step The step to create the controls for * @param event The event that triggered the step * @returns The controls for the step */ private createStepControls; private previewStep; private constructStepForPreview; private extractMockDataForPreviousSteps; private previewRequiredStep; private getStepState; private getStepCode; private getWorkflowCode; getCode(workflowId: string, stepId?: string): CodeResult; } interface ServeHandlerOptions { client?: Client; workflows?: Array; agents?: Array; /** * Extends the lifetime of the request handler until the given promise settles. * * Agent events are acknowledged immediately while the turn (LLM calls, replies, * tool use) continues in the background. On serverless platforms the runtime is * frozen as soon as the response is sent, so the background work is silently * dropped unless a platform `waitUntil` primitive is provided. * * The Next.js adapter (on Next.js >= 15.1) and the Hono adapter (on Cloudflare * Workers) wire this automatically. Provide it explicitly for other serverless * platforms, or to override the automatic detection. * * @example Cloudflare Workers (without Hono) * ```ts * export default { * async fetch(request, env, ctx) { * const handler = serve({ agents: [myAgent], waitUntil: (promise) => ctx.waitUntil(promise) }); * * return handler(request); * }, * }; * ``` */ waitUntil?: (promise: Promise) => void; } type INovuRequestHandlerOptions = ServeHandlerOptions & { frameworkName: string; client?: Client; workflows?: Array; agents?: Array; handler: Handler; }; type Handler = (...args: Input) => HandlerResponse; type HandlerResponse = { body: () => Awaitable; headers: (key: string) => Awaitable; method: () => Awaitable; queryString?: (key: string, url: URL) => Awaitable; url: () => Awaitable; transformResponse: (res: IActionResponse) => Output; waitUntil?: (promise: Promise) => void; }; type IActionResponse = { status: number; headers: Record; body: TBody; }; declare class NovuRequestHandler { readonly frameworkName: string; readonly handler: Handler; readonly client: Client; private readonly hmacEnabled; private readonly http; private readonly workflows; private readonly agents; private readonly waitUntil?; constructor(options: INovuRequestHandlerOptions); createHandler(): (...args: Input) => Promise; private getStaticHeaders; private createResponse; private createError; private handleAction; private getPostActionMap; /** * Agent events are acknowledged immediately and the turn continues in the * background. On serverless platforms the runtime freezes once the response * is sent, so without a `waitUntil` primitive the turn is silently dropped * mid-flight. Detecting the known freeze-prone platforms lets us surface an * actionable warning instead of logs that just stop with no error. */ private warnOnUnprotectedServerlessRuntime; triggerAction(triggerEvent: EventTriggerParams): () => Promise>; private getGetActionMap; private handlePostAction; private handleGetAction; private handleError; private validateHmac; } /** * Define a new notification workflow. */ declare function workflow = FromSchema, T_PayloadUnvalidated extends Record = FromSchemaUnvalidated, T_Controls extends Record = FromSchema, T_Env extends Record = FromSchema>(workflowId: string, execute: Execute, workflowOptions?: WorkflowOptions): Workflow; export { Client as C, type INovuRequestHandlerOptions as I, NovuRequestHandler as N, type ServeHandlerOptions as S, agent as a, isFromWorkflow as i, workflow as w };