{"version":3,"file":"workflow-context.cjs","sources":["@gensx/core/../../../../src/workflow-context.ts"],"sourcesContent":["import { CheckpointManager, ExecutionNode } from \"./checkpoint.js\";\nimport { getCurrentContext } from \"./context.js\";\nimport {\n  JsonValue,\n  WorkflowMessage,\n  WorkflowMessageListener,\n} from \"./workflow-state.js\";\n\n// Static symbol for workflow context\nexport const WORKFLOW_CONTEXT_SYMBOL = Symbol.for(\"gensx.workflow\");\n\ntype JsonSchema = unknown;\n\nexport type InputRequest =\n  | {\n      type: \"input-request\";\n      nodeId: string;\n      resultSchema: JsonSchema;\n      timeoutAt: string | null;\n    }\n  | {\n      type: \"external-tool\";\n      toolName: string;\n      nodeId: string;\n      params: unknown;\n      // TODO: Types\n      paramsSchema: JsonSchema;\n      resultSchema: JsonSchema;\n    };\n\nexport interface WorkflowExecutionContext {\n  checkpointManager: CheckpointManager;\n  sendWorkflowMessage: WorkflowMessageListener;\n  onRequestInput: (request: InputRequest) => Promise<unknown>;\n  objectStateMap: Map<string, JsonValue>;\n  onRestoreCheckpoint: (\n    node: ExecutionNode,\n    feedback: unknown,\n  ) => Promise<void>;\n  checkpointLabelMap: Map<string, ExecutionNode>;\n  executionScope: Record<string, unknown>;\n  // Future: Add more workflow-level utilities here\n}\n\nexport function createWorkflowContext({\n  onMessage,\n  onRequestInput,\n  onRestoreCheckpoint,\n  checkpoint,\n  executionScope = {},\n}: {\n  onMessage?: WorkflowMessageListener;\n  onRequestInput?: (request: InputRequest) => Promise<unknown>;\n  onRestoreCheckpoint?: (\n    node: ExecutionNode,\n    feedback: unknown,\n  ) => Promise<void>;\n  checkpoint?: ExecutionNode;\n  executionScope?: Record<string, unknown>;\n} = {}): WorkflowExecutionContext {\n  return {\n    checkpointManager: new CheckpointManager({ checkpoint }),\n    sendWorkflowMessage: (message: WorkflowMessage) => {\n      onMessage?.(message);\n    },\n    onRequestInput:\n      onRequestInput ??\n      // eslint-disable-next-line @typescript-eslint/require-await\n      (async () => {\n        // TODO: Should we throw here? This will cause weird behavior if the external tool helper is used\n        // without the request input helper not properly wired up.\n        console.warn(\n          \"[GenSX] Requesting input not supported in this environment\",\n        );\n      }),\n    onRestoreCheckpoint:\n      onRestoreCheckpoint ??\n      // eslint-disable-next-line @typescript-eslint/require-await\n      (async () => {\n        // TODO: Should we throw here? This will cause weird behavior if the restore checkpoint functionality is used\n        // without the restore checkpoint stuff properly wired up.\n        // We can probably build an in-memory implementation of this.\n        console.warn(\n          \"[GenSX] Restore checkpoint not supported in this environment\",\n        );\n      }),\n    checkpointLabelMap: new Map(),\n    objectStateMap: new Map(),\n    executionScope,\n  };\n}\n\nexport function getWorkflowContext(): WorkflowExecutionContext | undefined {\n  const context = getCurrentContext();\n  return context.getWorkflowContext();\n}\n"],"names":["checkpoint","CheckpointManager","context","getCurrentContext"],"mappings":";;;;;;;;;;;AAQA;AACa,MAAA,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB;SAmClD,qBAAqB,CAAC,EACpC,SAAS,EACT,cAAc,EACd,mBAAmB,cACnBA,YAAU,EACV,cAAc,GAAG,EAAE,MAUjB,EAAE,EAAA;IACJ,OAAO;AACL,QAAA,iBAAiB,EAAE,IAAIC,4BAAiB,CAAC,cAAED,YAAU,EAAE,CAAC;AACxD,QAAA,mBAAmB,EAAE,CAAC,OAAwB,KAAI;AAChD,YAAA,SAAS,GAAG,OAAO,CAAC;SACrB;AACD,QAAA,cAAc,EACZ,cAAc;;aAEb,YAAW;;;AAGV,gBAAA,OAAO,CAAC,IAAI,CACV,4DAA4D,CAC7D;AACH,aAAC,CAAC;AACJ,QAAA,mBAAmB,EACjB,mBAAmB;;aAElB,YAAW;;;;AAIV,gBAAA,OAAO,CAAC,IAAI,CACV,8DAA8D,CAC/D;AACH,aAAC,CAAC;QACJ,kBAAkB,EAAE,IAAI,GAAG,EAAE;QAC7B,cAAc,EAAE,IAAI,GAAG,EAAE;QACzB,cAAc;KACf;AACH;SAEgB,kBAAkB,GAAA;AAChC,IAAA,MAAME,SAAO,GAAGC,yBAAiB,EAAE;AACnC,IAAA,OAAOD,SAAO,CAAC,kBAAkB,EAAE;AACrC;;;;;;"}