import { z } from "zod"; import type { Inferable } from "../Inferable"; import { createApiClient } from "../create-client"; import { JobContext, JsonSchemaInput, WorkflowToolRegistrationInput } from "../types"; import { notificationSchema, ToolConfigSchema } from "../contract"; import L1M from "l1m"; type WorkflowInput = { executionId: string; }; type Logger = { info: (message: string, meta?: Record) => void; error: (message: string, meta?: Record) => void; }; type WorkflowConfig = { inferable: Inferable; name: name; description?: string; inputSchema: z.ZodType; logger?: Logger; client: ReturnType; config?: z.infer; getClusterId: () => Promise; endpoint: string; machineId: string; apiSecret: string; }; type AgentConfig = { name: string; systemPrompt?: string; tools?: string[]; resultSchema?: z.ZodType; runId?: string; }; type ReactAgentConfig = { /** * The name of the agent. */ name: string; /** * The system prompt for the agent. */ instructions: string; /** * The input for the agent. */ input: string; /** * The result schema for the agent. */ schema: z.ZodType; /** * The tools for the agent. */ tools: string[]; /** /** * Anthropic API key and model to use for the agent run. * */ provider?: { key: string; model: "claude-3-7-sonnet-20250219" | "claude-3-7-sonnet-latest" | "claude-3-5-sonnet-20241022" | "claude-3-5-sonnet-latest" | "claude-3-5-sonnet-20240620" | "claude-3-5-haiku-20241022" | "claude-3-5-haiku-latest"; }; /** * A function that is called before the agent returns its result. */ onBeforeReturn?: ( /** * The result of the agent. */ result: TResult, /** * The agent object. */ agent: { /** * Send a message to the agent. */ sendMessage: (message: string) => Promise; }) => Promise; }; type WorkflowContext = { /** * Core LLM functionality for the workflow. * * @example * ```typescript * const result = await ctx.llm.structured({ * input: "Good morning Vietnam!", * schema: z.object({ * country: z.string(), * }), * }); * ``` */ llm: L1M; /** * Result caching for the workflow. * @deprecated Use `memo` instead */ result: (name: string, fn: () => Promise) => Promise; /** * Result caching for the workflow. * * @example * ```typescript * const result = await ctx.memo("my-result", async () => { * return "my-result"; * }); * ``` */ memo: (name: string, fn: () => Promise) => Promise; /** * @deprecated Use `agents.react` instead * Agent functionality for the workflow. */ agent: (config: AgentConfig) => { trigger: (params: { data: { [key: string]: unknown; }; }) => Promise<{ result: TAgentResult; }>; }; /** * Input for the workflow. */ input: TInput; /** * Logging for the workflow. */ log: (status: "info" | "warn" | "error", meta: { [key: string]: unknown; }) => Promise; /** * Send a notification from the workflow. * * @example * ```typescript * await ctx.notify({ * message: "Something important happened", * destination: { * type: "email", * email: "test@example.com", * } * }); * ``` * * @example * ```typescript * await ctx.notify({ * message: "Something important happened", * destination: { * type: "slack", * // The email address of the Slack user to notify * email: "test@example.com", * // Or Slack user ID * userId: "U0123456789", * // Or Slack channel ID * channelId: "C0123456789", * }); * ``` */ notify: (notification: z.infer) => Promise; /** * Agent functionality for the workflow. */ agents: { /** * Default inferable agent functionality for the workflow. Muti-step. * * @example * ```typescript * const result = await ctx.agents.react({ * name: "userSearchAgent", * instructions: "Call the userSearch iteratively until the user is found", * input: "Hello, my name is John Smith and my address is 123 Main St, Anytown, USA. I want to find my user record.", * schema: z.object({ * user: z.object({ * id: z.string(), * name: z.string(), * }), * }), * tools: ["userSearch"], * }); * ``` */ react: (config: ReactAgentConfig) => Promise; }; } & Pick; export declare const helpers: { structuredPrompt: (params: { facts: string[]; goals: string[]; }) => string; }; export declare class Workflow { private name; private description?; private inputSchema; private versionHandlers; private pollingAgent; private getClusterId; private client; private logger?; private config?; private agentTools; private endpoint; private machineId; private apiSecret; constructor(config: WorkflowConfig); version(version: number): { define: (handler: (ctx: WorkflowContext, input: TInput) => Promise) => void; }; tools: { register: (tool: WorkflowToolRegistrationInput) => void; }; private createWorkflowContext; listen(): Promise; unlisten(): Promise; } export {};