export type ChainInputType = "string" | "number" | "boolean" | "enum" | "file" | "image" | "json" | "url" | "text"; export interface ChainInput { name: string; description?: string; optional?: boolean; type?: ChainInputType; default?: string; placeholder?: string; enum?: string[]; enum_labels?: Record; pattern?: string; min_length?: number; max_length?: number; min?: number; max?: number; accepts?: string[]; max_file_size?: number; examples?: string[]; } export type PreToolType = "current_datetime" | "http_fetch" | "web_search" | "read_file" | "write_file" | "bash" | "env_var" | "mcp_call" | "db_query" | "email" | "pdf_generate" | "ocr" | "state_load" | "state_save" | "vector_query" | "vector_index" | "json_parse" | "diff_inject" | "notify" | "semantic_cache" | "screenshot" | "sandbox_exec" | "cost_gate" | "ast_parse" | "embed_compare" | "graph_query" | "parallel_fetch" | "template_render" | "approval_request" | "image_generate"; export interface PreTool { type: PreToolType; inject_as: string; label?: string; url?: string; query?: string; path?: string; content?: string; command?: string; var_name?: string; server?: string; tool?: string; args?: Record; method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; headers?: Record; body?: string; json_path?: string; timezone?: string; format?: string; encoding?: string; append?: boolean; stderr?: boolean; default_value?: string; connection?: string; sql?: string; to?: string; subject?: string; from?: string; provider?: string; smtp_host?: string; smtp_port?: number; html?: string; output_path?: string; image_path?: string; language?: string; key?: string; value?: string; scope?: string; default?: string; collection?: string; top_k?: number; source?: string; chunk_size?: number; input?: string; repo?: string; base?: string; head?: string; max_tokens?: number; channel?: string; webhook_url?: string; message?: string; similarity_threshold?: number; viewport?: { width: number; height: number; }; wait_ms?: number; image?: string; mount?: string; budget_usd?: number; action?: string; extract?: string[]; text_a?: string; text_b?: string; triples?: Array<{ subject: string; predicate: string; object: string; }>; graph_query_subject?: string; graph_query_predicate?: string; urls?: string[]; rate_limit_ms?: number; template?: string; data?: Record; title?: string; description?: string; expires_hours?: number; image_provider?: "openai" | "huggingface" | "stability"; image_model?: string; image_size?: string; image_quality?: string; image_style?: string; negative_prompt?: string; image_format?: "png" | "jpeg" | "webp"; on_error?: "inject" | "skip" | "fail"; timeout_ms?: number; retry?: number; cache_ttl_minutes?: number; parallel?: boolean; } export type StepType = "agent" | "router" | "gate" | "evaluator" | "transform" | "loop" | "merge" | "browser" | "subchain" | "debate" | "webhook" | "image_gen"; export interface RetryConfig { max: number; delay_ms?: number; backoff?: number; } export type ContextStrategy = Record; export interface ChainStep { id: string; type?: StepType; label?: string; model?: string; prompt: string; tools?: string[]; depends_on?: string[]; output_var: string; cwd?: string; pre_tools?: PreTool[]; retry?: RetryConfig; fallback_models?: string[]; condition?: string; routes?: Record; default_route?: string; timeout_hours?: number; on_timeout?: "skip" | "error" | "approve"; input_var?: string; criteria?: string; on_fail?: "retry" | "skip" | "error"; max_retries?: number; retry_target?: string; operation?: "json_extract" | "regex_match" | "template" | "split" | "merge" | "truncate" | "replace" | "filter" | "map" | "join" | "to_json" | "from_json"; json_path?: string; regex?: string; template_str?: string; items_var?: string; max_parallel?: number; step_template?: Omit; inputs?: string[]; strategy?: "concatenate" | "json_array" | "llm_summarize" | "pick_best"; browser_url?: string; browser_task?: string; browser_max_steps?: number; browser_headless?: boolean; browser_port?: number; browser_viewport?: { width: number; height: number; }; browser_wait_ms?: number; browser_output_format?: "text" | "markdown" | "json" | "screenshot"; browser_page_name?: string; browser_scroll_strategy?: "auto" | "full" | "none"; browser_cookies_domain?: string; context_strategy?: ContextStrategy; cache?: { enabled: boolean; ttl_minutes?: number; }; output_schema?: "json" | "markdown" | "text"; output_must_contain?: string[]; output_must_not_contain?: string[]; output_max_length?: number; timeout_ms?: number; subchain?: string; subchain_input_map?: Record; debate_agents?: Array<{ prompt: string; model?: string; }>; debate_rounds?: number; debate_decision?: "voting" | "consensus" | "last_round"; chain?: string; url?: string; webhook_url?: string; webhook_method?: "POST" | "PUT" | "PATCH" | "GET" | "DELETE"; webhook_headers?: Record; webhook_body?: string; webhook_timeout_ms?: number; webhook_retry?: number; webhook_success_status?: number[]; early_exit_if?: string; truncate_limit?: number; loop_until?: string; loop_on_error?: "continue" | "abort"; gate_actions?: string[]; gate_rejection_reason?: boolean; gate_auto_approve_if?: string; eval_scoring?: boolean; eval_threshold?: number; guardrails?: Array<{ type: "max_length" | "min_length" | "must_contain" | "must_not_contain" | "regex_match" | "json_valid"; value?: string | number; }>; } export interface ChainDefinition { name: string; description?: string; version?: string; inputs?: ChainInput[]; steps: ChainStep[]; output: string; max_context_chars?: number; } export type StepStatus = "pending" | "running" | "done" | "error" | "skipped"; export interface StepResult { stepId: string; status: StepStatus; output?: string; error?: string; startedAt?: string; finishedAt?: string; durationMs?: number; inputTokens?: number; outputTokens?: number; } export type ExecutionStatus = "pending" | "running" | "done" | "error" | "skipped"; export interface ChainExecution { id: string; chainName: string; status: ExecutionStatus; input: Record; steps: Record; result?: string; error?: string; startedAt: string; finishedAt?: string; durationMs?: number; } export interface PipelineChainRef { id: string; chain: string; label?: string; depends_on?: string[]; condition?: string; inputs: Record; summarize_output?: boolean | number; } export interface PipelineDefinition { name: string; description?: string; version?: string; inputs?: ChainInput[]; chains: PipelineChainRef[]; output: string; } export interface PipelineExecution { id: string; pipelineName: string; status: ExecutionStatus; input: Record; chains: Record; result?: string; error?: string; startedAt: string; finishedAt?: string; durationMs?: number; } export type ExecutionEvent = { type: "execution_started"; executionId: string; chainName: string; timestamp?: string; } | { type: "step_started"; executionId: string; stepId: string; label?: string; timestamp?: string; } | { type: "step_output"; executionId: string; stepId: string; chunk: string; timestamp?: string; } | { type: "step_done"; executionId: string; stepId: string; durationMs: number; inputTokens?: number; outputTokens?: number; timestamp?: string; } | { type: "step_error"; executionId: string; stepId: string; error: string; timestamp?: string; } | { type: "step_log"; executionId: string; stepId: string; message: string; level: "info" | "warn" | "error"; timestamp?: string; } | { type: "execution_done"; executionId: string; result: string; durationMs: number; timestamp?: string; } | { type: "step_waiting_approval"; executionId: string; stepId: string; prompt: string; timestamp?: string; } | { type: "execution_error"; executionId: string; error: string; timestamp?: string; } | { type: "step_cache_hit"; executionId: string; stepId: string; timestamp?: string; } | { type: "gate_action"; executionId: string; stepId: string; action: string; reason?: string; timestamp?: string; }; export interface CacheEntry { key: string; stepId: string; chainName: string; result: string; createdAt: string; ttlMinutes: number; inputTokens?: number; outputTokens?: number; }