import * as Zod from 'zod'; import { PromptFile } from '../prompt-fs'; import { LlmAdapter } from './adapter'; import { Conversation } from './conversation'; import { WorkflowControls } from './workflow'; export interface BasicStep { /** Step name */ name: string; /** Determines if the step should be run or not */ runIf?: (messages: Conversation, ctx: CTX) => boolean | Promise; /** * When provided, throws an error if the step is invoked more times than `maxAttempts`. * Number of attempts taken is reset when the flow passed the step that was rewinding. */ maxAttempts?: number; /** Error handler called if an error occurred during in `execute` function */ onError?: (error: string, ctx: CTX) => Promise; } export interface ProgrammaticStep extends BasicStep { /** Content of the step */ execute: (messages: Conversation, ctx: CTX, workflow: WorkflowControls) => Promise; } export interface LLMStep extends BasicStep { /** LLM adapter to use */ model: LlmAdapter; /** * Prompt can be a simple string or a link to a file, loaded with `loadFile` function which * takes a path to the file relative to `src/use-cases` directory. Should be Nunjucks-compatible. */ prompt: string | PromptFile; /** * Do not put messages that were added via {@link Conversation.addMessage} into the prompt. */ ignoreAddedMessages?: boolean; } export interface JsonLLMStep extends LLMStep { /** * Defines the expected structure of the LLM's output. Accepts ZodSchema. When provided, the * LLM's response is validated and parsed according to this schema ensuring reliable structured * output. */ schema: Schema; /** * Function to execute with the LLM's response. Use {@link setProposedReply} to use the LLM's output as the proposed reply. * Or use combination of {@link getProposedReply} and {@link setProposedReply} to substitute parts of the string. * @example * ``` * // Use LLM output directly as reply * execute: (reply) => messages.setProposedReply(reply) * * // Substitute tokens in LLM output * execute: (reply) => { * const withLink = reply.replace('', 'https://payment.example.com/123') * messages.setProposedReply(withLink) * } * ``` */ execute: (reply: Zod.infer, conversation: Conversation, ctx: CTX, workflowControls: WorkflowControls) => Promise; } export interface StringLLMStep extends LLMStep { /** * Function to execute with the LLM's response. Use {@link setProposedReply} to use the LLM's output as the proposed reply. * Or use combination of {@link getProposedReply} and {@link setProposedReply} to substitute parts of the string. * @example * ``` * // Use LLM output directly as reply * execute: (reply) => messages.setProposedReply(reply) * * // Substitute tokens in LLM output * execute: (reply) => { * const withLink = reply.replace('', 'https://payment.example.com/123') * messages.setProposedReply(withLink) * } * ``` */ execute: (reply: string, conversation: Conversation, ctx: CTX, workflowControls?: WorkflowControls) => Promise; } export type WorkflowStep = StringLLMStep | JsonLLMStep | ProgrammaticStep; export interface StepBuilder { (step: JsonLLMStep): JsonLLMStep; (step: StringLLMStep): StringLLMStep; (step: ProgrammaticStep): ProgrammaticStep; } //# sourceMappingURL=steps.d.ts.map