feat(sdk): node navigation helpers get_node, get_node_parent, get_node_path, get_node_map - #542
Merged
Merged
Conversation
…e_path, get_node_map They take the tree, not a doc_id: fetch it once (get_document_structure) and navigate locally, instead of one request per step. get_node / get_node_parent / get_node_path share one depth-first walk, O(n) per call; trees run tens to a few hundred nodes. They return the tree's own nodes rather than copies (unlike get_nodes / get_leaf_nodes), so node["nodes"] keeps working. get_node_map is create_node_mapping under a name in the same family. It leaves out include_page_ranges, which reads page_index and raises KeyError on local trees. create_node_mapping stays as the 0.2.8 surface.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ranges
get_node, get_node_parent, get_node_path and get_node_map returned
None / [] / {} when handed the whole get_tree() response or a None tree,
and get_node matched nothing for an int id. Callers (AI-written ones
especially) read that as "node absent". They now raise TypeError naming
get_document_structure(doc_id) / get_tree(doc_id)['result'].
create_node_mapping(include_page_ranges=True) read node["page_index"],
so a raw tree from page_index_main (start_index/end_index) raised
KeyError although it already carries its ranges. A node's own
start_index/end_index now win; page_index trees map as before.
#541 makes the same change (a node's own start_index/end_index win) with its own test, and the two versions conflict on merge. The node helpers here don't depend on it.
create_node_mapping walked children with tree.get('nodes', []), so a
node carrying nodes: None raised TypeError while get_node and
get_node_path, which use `or []`, handled the same tree. Use `or []`
in the shared walker so every create_node_mapping caller is covered.
#541 does not touch this line; a trial merge with its head 79d88e8 is
clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds four functions for navigating a document tree, in
pageindex.utils(also reachable aspageindex.get_nodeetc.):doc_id: fetch it once and navigate locally, instead of one request per step.get_nodes/get_leaf_nodes), sonode["nodes"]keeps working.TypeErrornaming the right one, so it never reads as "not found": the wholeget_tree()response (pass its['result']), aNonetree, or a non-string id.get_node_mapiscreate_node_mapping, plus that input check, under a name in the same family.create_node_mappingstays as the 0.2.8 surface.create_node_mapping(soget_node_maptoo) walks past a node whosenodesisNoneinstead of raisingTypeError, asget_nodealready did.Tests:
test_node_navigationandtest_node_navigation_rejects_wrong_inputintests/test_package_surface.py.