1919
2020from glom import GlomError , glom
2121
22- from .explorer import RichExplorer
23- from . object_store import Explorable , ObjectRef , ObjectStore
22+ from deepset_mcp . tools . tokonomics .explorer import RichExplorer
23+ from deepset_mcp . tools . tokonomics . object_store import Explorable , ObjectStore
2424
2525F = TypeVar ("F" , bound = Callable [..., Any ])
2626
2727
2828def _is_reference (value : Any ) -> bool :
2929 """Check if a value is a reference string."""
30- return isinstance (value , str ) and ObjectRef . parse ( value ) is not None
30+ return isinstance (value , str ) and value . startswith ( "@" ) and len ( value ) > 1
3131
3232
3333def _type_allows_str (annotation : Any ) -> bool :
@@ -87,10 +87,10 @@ def _enhance_docstring_for_references(original: str, param_info: dict[str, dict[
8787 f" { func_name } (data={{'key': 'value'}}, threshold=10)" ,
8888 "" ,
8989 " # Call with references" ,
90- f" { func_name } (data='@obj_001 ', threshold='@obj_002 .config.threshold')" ,
90+ f" { func_name } (data='@obj_123 ', threshold='@obj_456 .config.threshold')" ,
9191 "" ,
9292 " # Mixed call" ,
93- f" { func_name } (data='@obj_001 .items', threshold=10)" ,
93+ f" { func_name } (data='@obj_123 .items', threshold=10)" ,
9494 ]
9595 )
9696
@@ -141,7 +141,7 @@ def explorable(
141141 ... return {"processed": data}
142142 ...
143143 >>> result = process_data({"input": "value"})
144- >>> # result contains a preview and object ID like "@obj_001 "
144+ >>> # result contains a preview and object ID like "@obj_123 "
145145 """
146146
147147 def decorator (func : F ) -> F :
@@ -180,7 +180,7 @@ def referenceable(
180180) -> Callable [[F ], F ]:
181181 """Decorator factory that enables parameters to accept object references.
182182
183- Parameters can accept reference strings like '@obj_001 ' or '@obj_001 .path.to.value'
183+ Parameters can accept reference strings like '@obj_id ' or '@obj_id .path.to.value'
184184 which are automatically resolved before calling the function.
185185
186186 :param object_store: The object store instance to use for lookups.
@@ -200,27 +200,25 @@ def referenceable(
200200 >>> process_data({"a": 1, "b": 2}, 10)
201201 >>>
202202 >>> # Call with references
203- >>> process_data("@obj_001 ", "@obj_002 .config.threshold")
203+ >>> process_data("@obj_123 ", "@obj_456 .config.threshold")
204204 """
205205
206206 def resolve_reference (ref_str : str ) -> Any :
207207 """Resolve a reference string to its actual value."""
208- ref = ObjectRef .parse (ref_str )
209- if ref is None :
210- raise ValueError (f"Invalid reference format: { ref_str } " )
208+ obj_id , path = explorer .parse_reference (ref_str )
211209
212- obj = object_store .get (ref . obj_id )
210+ obj = object_store .get (obj_id )
213211 if obj is None :
214- raise ValueError (f"Object @{ ref . obj_id } not found or expired" )
212+ raise ValueError (f"Object @{ obj_id } not found or expired" )
215213
216- if ref . path :
214+ if path :
217215 try :
218- explorer ._validate_path (ref . path )
219- return glom (obj , explorer ._parse_path (ref . path ))
216+ explorer ._validate_path (path )
217+ return glom (obj , explorer ._parse_path (path ))
220218 except GlomError as exc :
221- raise ValueError (f"Navigation error at { ref . path } : { exc } " ) from exc
219+ raise ValueError (f"Navigation error at { path } : { exc } " ) from exc
222220 except ValueError as exc :
223- raise ValueError (f"Invalid path { ref . path } : { exc } " ) from exc
221+ raise ValueError (f"Invalid path { path } : { exc } " ) from exc
224222
225223 return obj
226224
@@ -362,7 +360,7 @@ def explorable_and_referenceable(
362360 ... return {**data1, **data2}
363361 ...
364362 >>> # Accepts references and returns preview with object ID
365- >>> result = merge_data("@obj_001 ", {"new": "data"})
363+ >>> result = merge_data("@obj_123 ", {"new": "data"})
366364 >>> # result contains a preview and can be referenced as "@obj_002"
367365 """
368366
0 commit comments