code: def to_function_spec(hvobj):
      """
      Convert Dynamic HoloViews object into a pure function that accepts kdim values
      and stream contents as positional arguments.
  
      This borrows the low-level holoviews decollate logic, but instead of returning
      DynamicMap with cloned streams, returns a HoloViewsFunctionSpec.
  
      Args:
          hvobj: A potentially dynamic Holoviews object
  
      Returns:
          HoloViewsFunctionSpec
      """
      kdims_list = []
      original_streams = []
      streams = []
      stream_mapping = {}
      initialize_dynamic(hvobj)
      expr = to_expr_extract_streams(
          hvobj, kdims_list, streams, original_streams, stream_mapping
      )
      expr_fn = expr_to_fn_of_stream_contents(
          expr, nkdims=len(kdims_list)
      )
  
      # Check for unbounded dimensions
      if isinstance(hvobj, DynamicMap) and hvobj.unbounded:
          dims = ", ".join(f"{dim!r}" for dim in hvobj.unbounded)
          msg = (
              "DynamicMap cannot be displayed without explicit indexing "
              "as {dims} dimension(s) are unbounded. "
              "\nSet dimensions bounds with the DynamicMap redim.range "
              "or redim.values methods."
          )
          raise ValueError(msg.format(dims=dims))
  
      # Build mapping from kdims to values/range
      dimensions_dict = {d.name: d for d in hvobj.dimensions()}
      kdims = {}
      for k in kdims_list:
          dim = dimensions_dict[k.name]
          label = dim.label or dim.name
          kdims[k.name] = label, dim.values or dim.range
  
      return HoloViewsFunctionSpec(
          fn=expr_fn, kdims=kdims, streams=original_streams
      )
  
imports: import base64
  import copy
  import pickle
  import uuid
  from collections import namedtuple
  from dash.exceptions import PreventUpdate
  import holoviews
  from holoviews.core.decollate import expr_to_fn_of_stream_contents, initialize_dynamic, to_expr_extract_streams
  from holoviews.plotting.plotly import DynamicMap, PlotlyRenderer
  from holoviews.plotting.plotly.callbacks import BoundsXCallback, BoundsXYCallback, BoundsYCallback, RangeXCallback, RangeXYCallback, RangeYCallback, Selection1DCallback
  from holoviews.plotting.plotly.util import clean_internal_figure_properties
  from holoviews.streams import Derived, History
  import plotly.graph_objects
  from dash import callback_context
  from dash.dependencies import Input, Output, State
label_desc: Use image node_id 3 for calling a global function with example usage: to_function_spec(hvobj) and returns: HoloViewsFunctionSpec