{"version":3,"file":"workflow-state.cjs","sources":["@gensx/core/../../../../src/workflow-state.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */\nimport { getCurrentContext } from \"./context.js\";\nimport * as fastJsonPatch from \"./utils/fast-json-patch/index.js\";\n\n// Define JSON Patch operation types based on RFC 6902\ninterface BaseOperation {\n  path: string;\n}\n\ninterface AddOperation<T> extends BaseOperation {\n  op: \"add\";\n  value: T;\n}\n\ninterface RemoveOperation extends BaseOperation {\n  op: \"remove\";\n}\n\ninterface ReplaceOperation<T> extends BaseOperation {\n  op: \"replace\";\n  value: T;\n}\n\ninterface MoveOperation extends BaseOperation {\n  op: \"move\";\n  from: string;\n}\n\ninterface CopyOperation extends BaseOperation {\n  op: \"copy\";\n  from: string;\n}\n\ninterface TestOperation<T> extends BaseOperation {\n  op: \"test\";\n  value: T;\n}\n\ninterface GetOperation<T> extends BaseOperation {\n  op: \"_get\";\n  value: T;\n}\n\ntype JsonPatchOperation =\n  | AddOperation<JsonValue>\n  | RemoveOperation\n  | ReplaceOperation<JsonValue>\n  | MoveOperation\n  | CopyOperation\n  | TestOperation<JsonValue>\n  | GetOperation<JsonValue>;\n\n// JSON-serializable value type for progress data\nexport type JsonValue =\n  | string\n  | number\n  | boolean\n  | null\n  | JsonValue[]\n  | { [key: string]: JsonValue };\n\n// Extended operation types for optimized string handling\nexport interface StringAppendOperation {\n  op: \"string-append\";\n  path: string;\n  value: string;\n}\n\n// Combined operation type including standard JSON Patch and our extensions\nexport type Operation = JsonPatchOperation | StringAppendOperation;\n\n// Individual message types\nexport interface StartMessage {\n  type: \"start\";\n  workflowExecutionId?: string;\n  workflowName: string;\n}\n\nexport interface ComponentStartMessage {\n  type: \"component-start\";\n  componentName: string;\n  label?: string;\n  componentId: string;\n}\n\nexport interface ComponentEndMessage {\n  type: \"component-end\";\n  componentName: string;\n  label?: string;\n  componentId: string;\n}\n\nexport interface DataMessage {\n  type: \"data\";\n  data: JsonValue;\n}\n\nexport interface EventMessage {\n  type: \"event\";\n  data: JsonValue;\n  label: string;\n}\n\nexport interface ObjectMessage {\n  type: \"object\";\n  label: string;\n  patches: Operation[];\n  isInitial?: boolean;\n}\n\nexport interface ErrorMessage {\n  type: \"error\";\n  error: string;\n}\n\nexport interface EndMessage {\n  type: \"end\";\n}\n\nexport interface ExternalToolMessage {\n  type: \"external-tool\";\n  toolName: string;\n  params: JsonValue;\n  paramsSchema: unknown;\n  resultSchema: unknown;\n  nodeId: string;\n}\n\n// Union of all message types\nexport type WorkflowMessage =\n  | StartMessage\n  | ComponentStartMessage\n  | ComponentEndMessage\n  | DataMessage\n  | EventMessage\n  | ObjectMessage\n  | ErrorMessage\n  | EndMessage\n  | ExternalToolMessage;\n\nexport type WorkflowMessageListener = (message: WorkflowMessage) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type PublishableData = any;\n\n/**\n * Publish data to the workflow message stream. This is a low-level utility for putting arbitrary data on the stream.\n *\n * @param data - The data to publish.\n */\nexport function publishData(data: JsonValue) {\n  const context = getCurrentContext();\n  context.getWorkflowContext().sendWorkflowMessage({\n    type: \"data\",\n    data,\n  });\n}\n\n/**\n * Publish an event to the workflow message stream. Labels group events together, and generally all events within the same label should be related with the same type.\n *\n * @param label - The label of the event.\n * @param data - The data to publish.\n */\nexport function publishEvent<T = PublishableData>(label: string, data: T) {\n  const context = getCurrentContext();\n  context.getWorkflowContext().sendWorkflowMessage({\n    type: \"event\",\n    label,\n    data: data as PublishableData,\n  });\n}\n\n/**\n * Publish a state to the workflow message stream. A State represents a snapshot of an object that is updated over time.\n * This now uses JSON patches to efficiently send only the differences between states.\n *\n * @param label - The label of the state.\n * @param data - The data to publish. Can be any value that can be serialized to JSON .\n */\nexport function publishObject<T = JsonValue>(label: string, data: T) {\n  const context = getCurrentContext();\n  const workflowContext = context.getWorkflowContext();\n\n  // Deep clone the data to avoid mutations affecting the ability to diff\n  const newData = JSON.parse(JSON.stringify(data)) as JsonValue;\n  const previousData = workflowContext.objectStateMap.get(label);\n\n  if (previousData === undefined) {\n    // First time publishing this object\n    let patches: Operation[];\n    if (isPlainObject(newData)) {\n      // Use RFC 6902 add patches for each property\n      patches = fastJsonPatch.compare({}, newData);\n    } else {\n      // For primitives/arrays, use a root-level replace\n      patches = [{ op: \"replace\", path: \"\", value: newData }];\n    }\n    workflowContext.sendWorkflowMessage({\n      type: \"object\",\n      label,\n      patches,\n      isInitial: true,\n    });\n  } else {\n    // Generate optimized patches from previous state to new state\n    const patches = generateOptimizedPatches(previousData, newData);\n\n    // Only send message if there are changes\n    if (patches.length > 0) {\n      workflowContext.sendWorkflowMessage({\n        type: \"object\",\n        label,\n        patches,\n      });\n    }\n  }\n\n  // Store the new state\n  workflowContext.objectStateMap.set(label, newData);\n}\n\n/**\n * Generate optimized patches that use string-specific operations when beneficial.\n * Handles any JsonValue at the root, including string-append optimization for root strings.\n */\nexport function generateOptimizedPatches(\n  oldData: PublishableData,\n  newData: PublishableData,\n): Operation[] {\n  // Handle root-level string-append optimization\n  if (typeof oldData === \"string\" && typeof newData === \"string\") {\n    if (newData.startsWith(oldData)) {\n      const appendedText = newData.slice(oldData.length);\n      if (appendedText.length > 0) {\n        return [{ op: \"string-append\", path: \"\", value: appendedText }];\n      }\n    }\n    // If not an append, just replace\n    if (oldData !== newData) {\n      return [{ op: \"replace\", path: \"\", value: newData }];\n    }\n    return [];\n  }\n\n  // If either is not a plain object, use a single replace patch at the root\n  if (!isPlainObject(oldData) || !isPlainObject(newData)) {\n    if (oldData !== newData) {\n      return [{ op: \"replace\", path: \"\", value: newData }];\n    }\n    return [];\n  }\n\n  // Both are plain objects: use standard patching and string-append optimization for properties\n  const standardPatches = fastJsonPatch.compare(oldData, newData);\n  const optimizedPatches: Operation[] = [];\n\n  // Collect all parent paths that are being added/replaced\n  const parentPaths = new Set(\n    standardPatches\n      .filter((patch) => patch.op === \"add\" || patch.op === \"replace\")\n      .map((patch) => patch.path),\n  );\n\n  for (const patch of standardPatches) {\n    // If this patch's path is a child of any parent path, skip it\n    if (\n      Array.from(parentPaths).some(\n        (parent) => parent !== \"\" && patch.path.startsWith(parent + \"/\"),\n      )\n    ) {\n      continue;\n    }\n    if (patch.op === \"replace\" && typeof patch.value === \"string\") {\n      // Check if this is a string replacement that could be optimized\n      const oldValue = getValueByJsonPath(oldData, patch.path);\n      if (typeof oldValue === \"string\") {\n        const newValue = patch.value;\n        // Check if it's a simple append (common in streaming scenarios)\n        if (newValue.startsWith(oldValue)) {\n          const appendedText = newValue.slice(oldValue.length);\n          if (appendedText.length > 0) {\n            optimizedPatches.push({\n              op: \"string-append\",\n              path: patch.path,\n              value: appendedText,\n            });\n            continue;\n          }\n        }\n      }\n    }\n    // Use standard patch if no optimization applies\n    optimizedPatches.push(patch);\n  }\n\n  return optimizedPatches;\n}\n\n/**\n * Utility to check if a value is a non-null, non-array object\n */\nfunction isPlainObject(val: unknown): val is Record<string, JsonValue> {\n  return typeof val === \"object\" && val !== null && !Array.isArray(val);\n}\n\n/**\n * Get a value from an object using a JSON pointer path (RFC 6901 compliant, supports arrays)\n */\nexport function getValueByJsonPath(\n  obj: JsonValue,\n  path: string,\n): JsonValue | undefined {\n  if (path === \"\") {\n    return obj;\n  }\n  const pathParts = path.split(\"/\").slice(1); // Remove empty first element\n  let current: JsonValue = obj;\n\n  for (const part of pathParts) {\n    if (Array.isArray(current)) {\n      // Try to parse as array index\n      const idx = Number(part);\n      if (!Number.isNaN(idx) && idx >= 0 && idx < current.length) {\n        current = current[idx];\n      } else {\n        return undefined;\n      }\n    } else if (isPlainObject(current)) {\n      if (part in current) {\n        current = current[part];\n      } else {\n        return undefined;\n      }\n    } else {\n      return undefined;\n    }\n  }\n\n  return current;\n}\n\n/**\n * Create a function that publishes an event to the workflow message stream with the given label.\n *\n * @param label - The label of the event.\n * @returns A function that publishes an event to the workflow message stream.\n */\nexport function createEventStream<T = PublishableData>(label: string) {\n  return (data: T) => {\n    publishEvent(label, data);\n  };\n}\n\n/**\n * Create a function that publishes a state to the workflow message stream with the given label.\n *\n * @param label - The label of the state.\n * @returns A function that publishes a state to the workflow message stream.\n */\nexport function createObjectStream<T extends JsonValue = JsonValue>(\n  label: string,\n) {\n  return (data: T) => {\n    publishObject(label, data);\n  };\n}\n\n/**\n * Clear stored state for a given label. This is useful when starting a new workflow execution.\n *\n * @param label - The label of the state to clear.\n */\nexport function clearObjectState(label: string) {\n  const context = getCurrentContext();\n  context.getWorkflowContext().objectStateMap.delete(label);\n}\n\n/**\n * Clear all stored object states. This is useful when starting a new workflow execution.\n */\nexport function clearAllObjectStates() {\n  const context = getCurrentContext();\n  context.getWorkflowContext().objectStateMap.clear();\n}\n\n/**\n * Apply a JSON patch to reconstruct object state. This is useful for consumers who want to reconstruct the full object state from patches.\n *\n * @param patches - The JSON patch operations to apply.\n * @param currentState - The current state of the object (defaults to empty object).\n * @returns The new state after applying the patches.\n */\nexport function applyObjectPatches(\n  patches: Operation[],\n  currentState: PublishableData = {},\n): PublishableData {\n  let document = fastJsonPatch.deepClone(currentState);\n\n  let standardPatches: fastJsonPatch.Operation[] = [];\n  for (const operation of patches) {\n    if (operation.op === \"string-append\") {\n      // Handle string append operation\n      if (operation.path === \"\") {\n        // Root-level string append\n        if (typeof document === \"string\") {\n          document = document + operation.value;\n        } else {\n          // Warn and skip instead of throwing or replacing\n          console.warn(\n            `Cannot apply string-append: root value is not a string. Skipping operation.`,\n          );\n          // Do nothing\n        }\n        continue;\n      }\n      const pathParts = operation.path.split(\"/\").slice(1); // Remove empty first element\n      const target = getValueByPath(document, pathParts.slice(0, -1));\n      const property = pathParts[pathParts.length - 1];\n\n      if (typeof target === \"object\" && target !== null) {\n        const currentValue = (target as Record<string, JsonValue>)[property];\n        if (typeof currentValue === \"string\") {\n          (target as Record<string, JsonValue>)[property] =\n            currentValue + operation.value;\n        } else {\n          // Warn and skip instead of replacing\n          console.warn(\n            `Cannot apply string-append: target path '${operation.path}' is not a string. Skipping operation.`,\n          );\n          // Do nothing\n        }\n      } else {\n        // Warn and skip instead of throwing\n        console.warn(\n          `Cannot apply string-append: target path '${operation.path}' does not exist or is not an object. Skipping operation.`,\n        );\n        // Do nothing\n      }\n    } else {\n      // Handle standard JSON Patch operations\n      standardPatches.push(operation);\n    }\n  }\n\n  if (standardPatches.length > 0) {\n    const result = fastJsonPatch.applyPatch(\n      document,\n      fastJsonPatch.deepClone(standardPatches) as fastJsonPatch.Operation[],\n    );\n    return result.newDocument;\n  }\n\n  return document;\n}\n\n/**\n * Helper function to get a value by path in an object or array (RFC 6901 compliant)\n */\nfunction getValueByPath(obj: PublishableData, path: string[]): PublishableData {\n  let current: PublishableData = obj;\n  for (const segment of path) {\n    if (Array.isArray(current)) {\n      const idx = Number(segment);\n      if (!Number.isNaN(idx) && idx >= 0 && idx < current.length) {\n        current = current[idx];\n      } else {\n        return undefined;\n      }\n    } else if (isPlainObject(current)) {\n      if (segment in current) {\n        current = current[segment];\n      } else {\n        return undefined;\n      }\n    } else {\n      return undefined;\n    }\n  }\n  return current;\n}\n"],"names":["context","getCurrentContext","fastJsonPatch.compare","fastJsonPatch.deepClone","fastJsonPatch.applyPatch"],"mappings":";;;;;;;;;;;;;AAAA;AAiJA;;;;AAIG;AACG,SAAU,WAAW,CAAC,IAAe,EAAA;AACzC,IAAA,MAAMA,SAAO,GAAGC,yBAAiB,EAAE;AACnC,IAAAD,SAAO,CAAC,kBAAkB,EAAE,CAAC,mBAAmB,CAAC;AAC/C,QAAA,IAAI,EAAE,MAAM;QACZ,IAAI;AACL,KAAA,CAAC;AACJ;AAEA;;;;;AAKG;AACa,SAAA,YAAY,CAAsB,KAAa,EAAE,IAAO,EAAA;AACtE,IAAA,MAAMA,SAAO,GAAGC,yBAAiB,EAAE;AACnC,IAAAD,SAAO,CAAC,kBAAkB,EAAE,CAAC,mBAAmB,CAAC;AAC/C,QAAA,IAAI,EAAE,OAAO;QACb,KAAK;AACL,QAAA,IAAI,EAAE,IAAuB;AAC9B,KAAA,CAAC;AACJ;AAEA;;;;;;AAMG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