import React from "react"; import type { CachePolicy } from "../CachePolicy"; import type { RetryPolicy } from "../RetryPolicy"; import type { SmithersWorkflow } from "../SmithersWorkflow"; /** Valid output targets: a Zod schema, a Drizzle table object, or a string key. */ type OutputTarget = import("zod").ZodObject | { $inferSelect: any } | string; export type SubflowProps = { id: string; /** The child workflow definition. */ workflow: SmithersWorkflow; /** Input to pass to the child workflow. */ input?: unknown; /** `"childRun"` gets its own DB row/run; `"inline"` embeds in parent. */ mode?: "childRun" | "inline"; /** Where to store the subflow's result. */ output: OutputTarget; skipIf?: boolean; timeoutMs?: number; heartbeatTimeoutMs?: number; heartbeatTimeout?: number; retries?: number; retryPolicy?: RetryPolicy; continueOnFail?: boolean; cache?: CachePolicy; /** Explicit dependency on other task node IDs. */ dependsOn?: string[]; /** Named dependencies on other tasks. Keys become context keys, values are task node IDs. */ needs?: Record; label?: string; meta?: Record; key?: string; children?: React.ReactNode; }; export function Subflow(props: SubflowProps) { if (props.skipIf) return null; return React.createElement("smithers:subflow", { id: props.id, key: props.key, workflow: props.workflow, input: props.input, mode: props.mode ?? "childRun", output: props.output, timeoutMs: props.timeoutMs, heartbeatTimeoutMs: props.heartbeatTimeoutMs, heartbeatTimeout: props.heartbeatTimeout, retries: props.retries, retryPolicy: props.retryPolicy, continueOnFail: props.continueOnFail, cache: props.cache, dependsOn: props.dependsOn, needs: props.needs, label: props.label ?? props.id, meta: props.meta, __smithersSubflowWorkflow: props.workflow, __smithersSubflowInput: props.input, __smithersSubflowMode: props.mode ?? "childRun", }); }