Skip to content

feat: enhance API responses with pagination support and model updates#152

Open
Joffref wants to merge 7 commits into
mainfrom
majoffre/update-sdk-version
Open

feat: enhance API responses with pagination support and model updates#152
Joffref wants to merge 7 commits into
mainfrom
majoffre/update-sdk-version

Conversation

@Joffref

@Joffref Joffref commented May 28, 2026

Copy link
Copy Markdown
Contributor
  • Cursor-based pagination support across list endpoints, non-breaking: generated clients and wrappers accept both today's bare-array responses and the new paginated *List objects, preserving the legacy return shape until the platform migration completes
  • Hardens generated response parsing: documented statuses with non-JSON bodies raise ResponseParseError (status, content type, body preview) instead of JSONDecodeError (ENG-2802)
  • Regenerated against current definitions; shared list-unwrap helper; parsing + unwrap test coverage

Version pinning + auto-paging iterators (#145's design) remain follow-up; this is the bridge.

- Updated the API methods for listing agents, sandboxes, drives, functions, jobs, and job executions to support cursor-based pagination.
- Refactored response parsing to return structured lists (e.g., AgentList, SandboxList, DriveList, FunctionList, JobList, JobExecutionList) instead of raw arrays.
- Added new parameters for cursor, limit, sort, and anchor to improve query flexibility and response handling.
- Updated documentation to reflect changes in response structure and pagination capabilities.

This change improves the API's usability and aligns with the latest versioning standards.
mendral-app[bot]

This comment was marked as outdated.

@mendral-app

mendral-app Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🧪 Testing Guide

What this PR addresses

This PR adds cursor-based pagination support to all major list endpoints in the Python SDK (agents, sandboxes, drives, functions, jobs, models, policies, volumes). Response parsing is refactored from returning raw arrays to returning structured list objects (AgentList, SandboxList, etc.) that include pagination metadata (has_more, next_cursor, total). A backward-compatibility layer detects legacy bare-array responses and handles them transparently.

Steps to reproduce / exercise the new behavior

  1. Verify backward compatibility with legacy (bare array) responses:

    • Mock or use an older API version that returns a bare JSON array (e.g., [{"metadata": {...}, "spec": {...}}]) from a list endpoint.
    • Call the SDK method (e.g., list_agents.sync(client=client)).
    • Confirm the result is still a usable list of items (the SDK should detect the legacy format and unwrap .data automatically).
  2. Verify paginated responses work end-to-end:

    • Call a list endpoint with limit=2 to force pagination (e.g., list_agents.sync(client=client, limit=2)).
    • Confirm the response is an AgentList (or equivalent) with .data containing ≤2 items and .meta containing has_more, next_cursor, and total.
    • Use the returned next_cursor value in a follow-up call: list_agents.sync(client=client, cursor=next_cursor, limit=2).
    • Confirm the next page of results is returned correctly.
  3. Verify sort and anchor parameters:

    • Call a list endpoint with a sort parameter (e.g., sort=ListAgentsSort.CREATEDAT_DESC).
    • Confirm results are ordered by creation date descending.
    • Call with anchor=ListAgentsAnchor.END and confirm results are anchored to the end of the result set.
  4. Verify error handling for malformed responses:

    • Mock a response that returns non-JSON content (e.g., HTML error page) with a 200 status code.
    • Confirm a ResponseParseError is raised (when raise_on_unexpected_status=True) or None is returned gracefully.
  5. Run the new test suites:

    pytest tests/test_generated_client_response_parsing.py -v
    pytest tests/test_list_response_unwrap.py -v

What to verify (expected behavior)

  • All existing tests pass without regression (pytest green).
  • New list endpoints return structured *List objects (with .data and .meta) when the API returns paginated responses.
  • Legacy bare-array responses are still handled correctly — SDK consumers using the old pattern (for item in response) continue to work.
  • list_response_items() helper correctly unwraps both formats to a plain list.
  • Pagination parameters (cursor, limit, sort, anchor) are correctly serialized as query params in HTTP requests (not sent when UNSET).
  • PaginationMeta fields (has_more, next_cursor, total) are correctly deserialized from camelCase JSON keys.
  • ResponseParseError is raised on non-JSON responses when raise_on_unexpected_status is enabled.
  • No breaking changes to the public API surface — existing code that calls list methods without pagination params still works.

Note

Posted by PR Testing Guide · Tag @mendral-app with feedback.

@mendral-app mendral-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The previously flagged from_dict guard issue has been fully resolved — all *List models now handle bare arrays via isinstance(src_dict, list) wrapping, None via early return, and empty dicts safely. No new issues found.

Tag @mendral-app with feedback or questions. View session

# Conflicts:
#	src/blaxel/core/sandbox/default/sandbox.py
#	src/blaxel/core/sandbox/sync/sandbox.py
list_response_items now lives in common.internal (was duplicated in four
wrappers); adds unwrap unit tests, a jobs list regression test, and
success-status non-JSON parse coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants