{"version":3,"file":"rehydrate-6SGyc4dD.cjs","names":["jsonSchemaToZod","createWorkflow","parseMapConfig","cloneWorkflow","getSingleStepEntryId","derivePredicateLabel","predicateToCondition","_exhaustive","createStepFromAgent","createStepFromTool","mapVariable"],"sources":["../src/workflows/dynamic/rehydrate.ts"],"sourcesContent":["/**\n * Storable → Runnable half of the workflow round-trip: rebuild a runnable\n * `Workflow` from the stored JSON form. References to agents/tools/workflows\n * are resolved against the live Mastra instance; throws if a reference is\n * missing — better to surface the failure at load time than at run time.\n */\nimport type { Mastra } from '../../mastra';\nimport { cloneWorkflow, createWorkflow } from '../create';\nimport { derivePredicateLabel } from '../predicate';\nimport type { Step } from '../step';\nimport { createStepFromAgent, createStepFromTool } from '../step-factories';\nimport type { SerializedSingleStepEntry, SerializedStepOptions, SingleStepEntry, StepFlowEntry } from '../types';\nimport { getSingleStepEntryId } from '../utils';\nimport { mapVariable, predicateToCondition } from '../workflow';\nimport { jsonSchemaToZod } from './json-schema-to-zod';\nimport type { JsonSchema, JsonSchemaToZodOptions } from './json-schema-to-zod';\nimport { parseMapConfig } from './mapping-config';\nimport type { ValidatableStepFlowEntry } from './validate/types';\n\n/**\n * JSON shape persisted to WorkflowDefinitionsStorage, and the same shape\n * `addDynamicWorkflows` hydrates from before it writes the row.\n */\nexport interface DynamicWorkflowGraph {\n  id: string;\n  description?: string;\n  metadata?: Record<string, unknown>;\n  inputSchema: JsonSchema;\n  outputSchema: JsonSchema;\n  stateSchema?: JsonSchema;\n  requestContextSchema?: JsonSchema;\n  graph: ValidatableStepFlowEntry[];\n}\n\n/**\n * Wrapper so the return value isn't recognized as a thenable by `await`.\n * `Workflow` carries a `.then(step)` builder method — returning one directly\n * from an `async` function (or any `await`-ed call) makes the runtime call\n * that builder method as a Promise resolver and the call hangs forever.\n * Always destructure: `const { workflow } = await rehydrateWorkflow(...)`.\n */\nexport interface RehydratedWorkflow {\n  workflow: any;\n}\n\n/**\n * Options controlling how `rehydrateWorkflow` handles unsupported JSON Schema\n * keywords. Forwarded to `jsonSchemaToZod` for every schema on the definition\n * (top-level + per-step `agent.outputSchema`). See `JsonSchemaToZodOptions`.\n */\nexport type RehydrateWorkflowOptions = JsonSchemaToZodOptions;\n\nexport async function rehydrateWorkflow(\n  def: DynamicWorkflowGraph,\n  mastra: Mastra,\n  opts?: RehydrateWorkflowOptions,\n): Promise<RehydratedWorkflow> {\n  const inputSchema = jsonSchemaToZod(def.inputSchema, opts);\n  const outputSchema = jsonSchemaToZod(def.outputSchema, opts);\n  const stateSchema = def.stateSchema ? jsonSchemaToZod(def.stateSchema, opts) : undefined;\n  const requestContextSchema = def.requestContextSchema ? jsonSchemaToZod(def.requestContextSchema, opts) : undefined;\n\n  const wf = createWorkflow({\n    id: def.id,\n    description: def.description,\n    metadata: def.metadata,\n    inputSchema: inputSchema as any,\n    outputSchema: outputSchema as any,\n    stateSchema: stateSchema as any,\n    requestContextSchema: requestContextSchema as any,\n  });\n\n  for (const entry of def.graph) {\n    applyGraphEntry(wf, entry, mastra, opts);\n  }\n  const built: any = wf.commit();\n  built.origin = 'dynamic';\n  return { workflow: built };\n}\n\nfunction applyGraphEntry(\n  wf: any,\n  entry: ValidatableStepFlowEntry,\n  mastra: Mastra,\n  schemaOpts?: JsonSchemaToZodOptions,\n): void {\n  switch (entry.type) {\n    case 'agent':\n    case 'tool':\n      wf.__pushStepFlowEntry(rehydrateSingleEntry(entry, mastra, schemaOpts), entry);\n      return;\n    case 'mapping': {\n      const cfg = parseMapConfig(entry.mapConfig, entry.id);\n      const live = rehydrateMapConfig(cfg, mastra);\n      wf.map(live, { id: entry.id });\n      return;\n    }\n    case 'sleep': {\n      if (typeof entry.duration !== 'number') {\n        throw new Error(`Stored sleep \"${entry.id}\" missing literal duration.`);\n      }\n      // Push directly (not wf.sleep()) so the stored step id survives the\n      // round-trip — the builder generates a fresh random id per call.\n      const live: StepFlowEntry = { type: 'sleep', id: entry.id, duration: entry.duration };\n      wf.__pushStepFlowEntry(live, live);\n      return;\n    }\n    case 'sleepUntil': {\n      if (!(entry.date instanceof Date) && typeof entry.date !== 'string') {\n        throw new Error(`Stored sleepUntil \"${entry.id}\" missing literal date.`);\n      }\n      const date = entry.date instanceof Date ? entry.date : new Date(entry.date);\n      if (Number.isNaN(date.getTime())) {\n        throw new Error(`Stored sleepUntil \"${entry.id}\" has an unparseable date: ${String(entry.date)}`);\n      }\n      const live: StepFlowEntry = { type: 'sleepUntil', id: entry.id, date };\n      wf.__pushStepFlowEntry(live, { type: 'sleepUntil', id: entry.id, date });\n      return;\n    }\n    case 'parallel': {\n      const live: StepFlowEntry = {\n        type: 'parallel',\n        steps: entry.steps.map(s => rehydrateSingleEntry(s, mastra, schemaOpts)),\n      };\n      wf.__pushStepFlowEntry(live, entry);\n      return;\n    }\n    case 'foreach': {\n      if (entry.step.type === 'mapping') {\n        throw new Error(\n          `Foreach step cannot iterate a mapping: mappings project data, they don't execute per item. Use an agent, tool, or plain step as the foreach body.`,\n        );\n      }\n      const live: StepFlowEntry = {\n        type: 'foreach',\n        step: rehydrateSingleEntry(entry.step, mastra, schemaOpts),\n        opts: { concurrency: entry.opts?.concurrency ?? 1 },\n      };\n      wf.__pushStepFlowEntry(live, entry);\n      return;\n    }\n    case 'step': {\n      const live = rehydrateSingleEntry(entry, mastra, schemaOpts);\n      wf.__pushStepFlowEntry(live, entry);\n      return;\n    }\n    case 'workflow': {\n      const nested = assertWorkflowExists(mastra, entry.workflowId);\n      // A nested workflow executes as its own `Workflow`, so the engine keys its\n      // result by the workflow's intrinsic id. The portable definition addresses\n      // it by the declared call-site id, which is what mappings, predicates and\n      // `${stepResults...}` templates reference. Clone it under the declared id so\n      // every reference resolves instead of silently falling back to `initData`.\n      wf.then(entry.id && entry.id !== nested.id ? cloneWorkflow(nested as any, { id: entry.id }) : nested);\n      return;\n    }\n    case 'conditional': {\n      const predicates = entry.predicates;\n      if (!predicates || predicates.length !== entry.steps.length || predicates.some(p => !p)) {\n        throw new Error(\n          `Cannot rehydrate conditional step: missing or mismatched predicates. Only declarative predicate branches round-trip.`,\n        );\n      }\n      const steps = entry.steps.map(s => rehydrateSingleEntry(s, mastra, schemaOpts));\n      // Wire graphs may omit the Studio-facing condition labels; derive them\n      // from the predicates (same convention as the fluent builder).\n      const serializedConditions =\n        entry.serializedConditions ??\n        steps.map((s, i) => ({ id: `${getSingleStepEntryId(s)}-condition`, fn: derivePredicateLabel(predicates[i]!) }));\n      const live: StepFlowEntry = {\n        type: 'conditional',\n        steps,\n        conditions: predicates.map(p => predicateToCondition(p!)),\n        serializedConditions,\n        predicates,\n      };\n      wf.__pushStepFlowEntry(live, { ...entry, serializedConditions });\n      return;\n    }\n    case 'loop': {\n      const { predicate, loopType } = entry;\n      if (!predicate || (loopType !== 'dowhile' && loopType !== 'dountil')) {\n        throw new Error(\n          `Cannot rehydrate loop step: missing declarative predicate or loopType. Only declarative predicate loops round-trip.`,\n        );\n      }\n      const step = rehydrateSingleEntry(entry.step, mastra, schemaOpts);\n      const serializedCondition = entry.serializedCondition ?? {\n        id: `${getSingleStepEntryId(step)}-condition`,\n        fn: derivePredicateLabel(predicate),\n      };\n      const live: StepFlowEntry = {\n        type: 'loop',\n        step,\n        condition: predicateToCondition(predicate),\n        loopType,\n        serializedCondition,\n        predicate,\n      };\n      wf.__pushStepFlowEntry(live, { ...entry, serializedCondition });\n      return;\n    }\n    default: {\n      const _exhaustive: never = entry;\n      throw new Error(`Unknown stored step type: ${JSON.stringify(_exhaustive)}`);\n    }\n  }\n}\n\n/**\n * Reconstruct the options bag `.agent()` accepts from a serialized entry.\n * Restores `structuredOutput.schema` from `outputSchema` (JSON Schema → Zod)\n * and merges in `retries` / `metadata`. Returns `undefined` when nothing to\n * restore so `.agent(agentId)` stays a clean call.\n */\nfunction rebuildAgentOptions(\n  entry: {\n    outputSchema?: Record<string, any>;\n    options?: SerializedStepOptions;\n  },\n  schemaOpts?: JsonSchemaToZodOptions,\n): Record<string, any> | undefined {\n  const opts: Record<string, any> = {};\n  if (entry.outputSchema) {\n    opts.structuredOutput = { schema: jsonSchemaToZod(entry.outputSchema, schemaOpts) };\n  }\n  if (entry.options?.retries !== undefined) opts.retries = entry.options.retries;\n  if (entry.options?.metadata !== undefined) opts.metadata = entry.options.metadata;\n  return Object.keys(opts).length > 0 ? opts : undefined;\n}\n\nfunction rebuildToolOptions(entry: { options?: SerializedStepOptions }): Record<string, any> | undefined {\n  const opts: Record<string, any> = {};\n  if (entry.options?.retries !== undefined) opts.retries = entry.options.retries;\n  if (entry.options?.metadata !== undefined) opts.metadata = entry.options.metadata;\n  return Object.keys(opts).length > 0 ? opts : undefined;\n}\n\n/**\n * Build the live `SingleStepEntry` for a stored entry. Declarative agent/tool\n * entries stay declarative — both engines interpret them per-kind at\n * execution time (`runAgentEntry` / `runToolEntry`) — so no fake `Step`\n * wrapper is needed and the stored `id` / `outputSchema` / `retries` /\n * `metadata` round-trip losslessly in every position (top-level, parallel,\n * branch, foreach and loop bodies).\n *\n * `step` descriptors resolve agent-then-tool by id against the live Mastra\n * instance; `workflow` entries resolve the registered instance. Both become\n * plain `{ type: 'step' }` entries, same as the fluent builder emits.\n */\nfunction rehydrateSingleEntry(\n  entry: SerializedSingleStepEntry,\n  mastra: Mastra,\n  schemaOpts?: JsonSchemaToZodOptions,\n): SingleStepEntry {\n  switch (entry.type) {\n    case 'agent': {\n      const agent = tryGetAgentById(mastra, entry.agentId);\n      if (!agent) {\n        throw new Error(\n          `Dynamic workflow references agent \"${entry.agentId}\" which is not registered on this Mastra instance.`,\n        );\n      }\n      return {\n        type: 'agent',\n        id: entry.id,\n        agentId: entry.agentId,\n        agent,\n        options: rebuildAgentOptions(entry, schemaOpts),\n      };\n    }\n    case 'tool': {\n      const tool = mastra.getTool?.(entry.toolId);\n      if (!tool) {\n        throw new Error(\n          `Dynamic workflow references tool \"${entry.toolId}\" which is not registered on this Mastra instance.`,\n        );\n      }\n      return { type: 'tool', id: entry.id, toolId: entry.toolId, tool, options: rebuildToolOptions(entry) };\n    }\n    case 'step': {\n      const { id } = entry.step;\n      // Wrap the resolved agent/tool in a real Step (same adapters `createStep`\n      // uses) so the entry honors the executeStep contract instead of casting a\n      // raw Agent/Tool instance — those don't carry a step-shaped `execute`.\n      const agent = tryGetAgentById(mastra, id);\n      if (agent) {\n        return { type: 'step', step: createStepFromAgent(agent) as unknown as Step };\n      }\n      const tool = tryGetToolById(mastra, id);\n      if (tool) {\n        return { type: 'step', step: createStepFromTool(tool as any) as unknown as Step };\n      }\n      throw new Error(\n        `Dynamic workflow references step \"${id}\" which is not registered as an agent or tool on this Mastra instance.`,\n      );\n    }\n    case 'workflow': {\n      const nested = assertWorkflowExists(mastra, entry.workflowId);\n      // Same call-site identity rule as top-level nested workflows: run the\n      // clone under the declared id so results are keyed the way the portable\n      // definition addresses them.\n      const step = entry.id && entry.id !== nested.id ? cloneWorkflow(nested as any, { id: entry.id }) : nested;\n      return { type: 'step', step: step as unknown as Step };\n    }\n    case 'mapping':\n      throw new Error(\n        `mapping entries cannot appear inside .parallel(), .branch(), or .foreach(); they must be top-level.`,\n      );\n  }\n}\n\n/**\n * Rebuild the object shape that `.map()` accepts. Step sources remain workflow-local\n * step IDs because mapping execution resolves them from the run's step results.\n */\nfunction rehydrateMapConfig(cfg: Record<string, any>, mastra: Mastra): Record<string, any> {\n  const out: Record<string, any> = {};\n  for (const [key, source] of Object.entries(cfg)) {\n    if (!source || typeof source !== 'object') {\n      out[key] = source;\n      continue;\n    }\n    if ('template' in source) {\n      out[key] = { template: source.template };\n    } else if ('value' in source) {\n      out[key] = { value: source.value };\n    } else if ('requestContextPath' in source) {\n      out[key] = { requestContextPath: source.requestContextPath };\n    } else if ('initData' in source && typeof source.initData === 'string') {\n      const wf = mastra.getWorkflow?.(source.initData);\n      if (!wf) {\n        throw new Error(`Mapping references unknown workflow init-data \"${source.initData}\".`);\n      }\n      out[key] = mapVariable({ initData: wf as any, path: source.path });\n    } else if ('step' in source) {\n      out[key] = mapVariable({ step: source.step as any, path: source.path });\n    } else {\n      out[key] = source;\n    }\n  }\n  return out;\n}\n\n/**\n * Mastra.getAgentById throws when the id isn't registered; every by-id\n * resolution path in this file wants a nullable \"does it exist?\" answer so it\n * can fall through to a tool lookup or a targeted error. Swallow the not-found\n * throw and return undefined.\n */\nfunction tryGetAgentById(mastra: Mastra, id: string): any | undefined {\n  if (!id || typeof mastra.getAgentById !== 'function') return undefined;\n  try {\n    return mastra.getAgentById(id);\n  } catch {\n    return undefined;\n  }\n}\n\n/** Same nullable-lookup contract as `tryGetAgentById`, for tools — `Mastra.getTool` throws on a missing id. */\nfunction tryGetToolById(mastra: Mastra, id: string): any | undefined {\n  if (!id || typeof mastra.getTool !== 'function') return undefined;\n  try {\n    return mastra.getTool(id);\n  } catch {\n    return undefined;\n  }\n}\n\n/**\n * Workflow references resolve like agent references: intrinsic workflow id\n * first (`getWorkflowById` scans registered workflows by their own `id`),\n * falling back to the registration key. Stored definitions reference the\n * intrinsic id — the identity discovery advertises — which may differ from\n * the key the workflow was registered under (`workflows: { greetingWorkflow }`\n * vs `id: 'greeting-workflow'`).\n */\nfunction tryGetWorkflowById(mastra: Mastra, id: string): any | undefined {\n  if (!id) return undefined;\n  if (typeof (mastra as any).getWorkflowById === 'function') {\n    try {\n      return (mastra as any).getWorkflowById(id);\n    } catch {\n      // fall through to registration-key lookup\n    }\n  }\n  if (typeof (mastra as any).getWorkflow !== 'function') return undefined;\n  try {\n    return (mastra as any).getWorkflow(id);\n  } catch {\n    return undefined;\n  }\n}\n\nfunction assertWorkflowExists(mastra: Mastra, workflowId: string): any {\n  const wf = tryGetWorkflowById(mastra, workflowId);\n  if (!wf) {\n    throw new Error(\n      `Dynamic workflow references nested workflow \"${workflowId}\" which is not registered on this Mastra instance.`,\n    );\n  }\n  return wf;\n}\n"],"mappings":";;;;AAoDA,eAAsB,kBACpB,KACA,QACA,MAC6B;CAC7B,MAAM,cAAcA,iBAAAA,gBAAgB,IAAI,aAAa,IAAI;CACzD,MAAM,eAAeA,iBAAAA,gBAAgB,IAA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