feat(templates): template list pagination via GET /v2/templates#1479
feat(templates): template list pagination via GET /v2/templates#1479huv1k wants to merge 22 commits into
Conversation
Add a paginated `GET /v2/templates` endpoint to the spec and expose it across all packages: - JS SDK: `Template.list()` -> `TemplatePaginator` returning `TemplateInfo`, matching `Sandbox.list()`. - Python SDK: `Template.list()` / `AsyncTemplate.list()` -> `TemplatePaginator` / `AsyncTemplatePaginator` (sync + async). - CLI: `e2b template list` pages through templates via the SDK paginator and adds a `-l, --limit` option (default 1000, 0 for no limit). Pagination uses `limit`/`nextToken` query params and the `X-Next-Token` response header, consistent with `sandbox list`.
🦋 Changeset detectedLatest commit: d6c9939 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Package ArtifactsBuilt from 1cb1172. Download artifacts from this workflow run. JS SDK ( npm install ./e2b-2.31.1-templates-list-pagination-for-cli-en-603.0.tgzCLI ( npm install ./e2b-cli-2.13.1-templates-list-pagination-for-cli-en-603.0.tgzPython SDK ( pip install ./e2b-2.30.0+templates.list.pagination.for.cli.en.603-py3-none-any.whl |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 760d988327
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Template.list builds its own ConnectionConfig, so passing only teamId/limit left config-file logins (e2b auth login) unauthenticated. Resolve the API key via ensureAPIKey() and pass it to the paginator, mirroring sandbox list. This also fixes the delete/publish --select flows.
mishushakov
left a comment
There was a problem hiding this comment.
move template method to template and shared classes to utils
|
also, no tests for the Python SDKs? |
…tion-for-cli-en-603 # Conflicts: # packages/js-sdk/src/sandbox/sandboxApi.ts # packages/python-sdk/e2b/sandbox/sandbox_api.py
The API key is team-scoped, so listing templates never needs a team identifier. Remove teamId/team_id from Template.list (JS + Python sync/async), the TemplatePaginator(Base), and the /v2/templates query, and drop the now-dead --team option from `template list/delete/publish`.
…ator is exhausted Per review: template paginator nextItems/next_items now returns [] when there are no more items, rather than raising. Sandbox/snapshot paginators still throw; noted in comments that they'll be aligned to this behaviour.
Per review: remove the "Showing first N templates" hint. listSandboxTemplates
now returns the template array directly instead of { templates, hasMore }; the
delete/publish select flows and tests are updated accordingly.
…tests Per review (no mocks): the JS SDK test now builds a real template and asserts it appears via Template.list() against the live /v2/templates endpoint (and cleans it up); the CLI test runs the built CLI's `template list -f json` against the real API and validates the returned templates.
templateApi no longer imports SandboxApiOpts from the sandbox module. It uses the shared ConnectionOpts (already used by Template.build/exists/getTags), so the template SDK only depends on shared infra (Paginator, ConnectionOpts), not sandbox internals.
…mplateInfo Per review: destructure only the fields that need renaming (templateID/buildID) or date conversion (createdAt/updatedAt/lastSpawnedAt) and spread the rest, instead of copying every field by hand.
Align Python with the TypeScript layout: template code no longer lives in the sandbox modules. - TemplateInfo -> e2b/template/template_api.py (mirrors templateApi.ts) - TemplatePaginator -> e2b/template_sync/paginator.py - AsyncTemplatePaginator -> e2b/template_async/paginator.py - both extend the shared PaginatorBase directly (drop the redundant TemplatePaginatorBase), return [] when exhausted, and raise TemplateException - template_sync/async main + e2b/__init__ import from the template modules; no sandbox imports remain in the template SDK
Per review: the CLI now fetches the whole list (auto-paginating every page), since output is commonly piped into other tools and there's no good way to paginate from the CLI yet. Removes the --limit option and the page/limit bookkeeping.
Per review: build a real template and assert it appears via Template.list() / AsyncTemplate.list() against the live /v2/templates endpoint, verify the TemplateInfo shape and that an exhausted paginator returns [], then clean up.
Mirror `sandbox list` for now: re-add the -l, --limit option (default 1000, 100 per page, 0 = no limit), cap the auto-pagination at the limit, and print the "Showing first N templates. Use --limit to change." hint when more exist. The SDK paginator still returns [] when exhausted.
GET /v2/templates returns buildID as a zero UUID right after building (it's the last *successful* build id, distinct from the just-triggered build), so the integration tests now just assert buildId is a string. Fixes the failing JS and Python SDK integration tests.
The paginators fell back to the default Sandbox error on HTTP failure. Pass TemplateError (JS) / TemplateException (Python) to handleApiError / handle_api_exception, matching the other template ops and the paginator's own parsed-body error branch. Also mark TemplateInfo.aliases deprecated in the Python SDK (use names), mirroring the JS SDK and the OpenAPI spec.
…tion-for-cli-en-603 # Conflicts: # packages/js-sdk/src/template/index.ts
…dules Address latest review: - JS: move TemplateInfo/TemplateListOpts into template/types.ts and TemplatePaginator into template/paginator.ts; delete templateApi.ts. - Python: move TemplateInfo into template/types.py; delete template_api.py. - CLI: simplify toTemplateSchema (spread, convert only date fields) and drop the 'Showing first N' hint (keep --limit).
Change the -l, --limit default from 1000 to 0 (no limit) so `e2b template list` returns the whole list by default; pass --limit N to cap.
Summary
Adds support for listing templates with pagination via the new
GET /v2/templatesendpoint (added tospec/openapi.yml; clients regenerated). The JS and Python SDKs gain aTemplate.list()paginator that yieldsTemplateInfoand is built on the shared paginator base from #1491 (Paginatorin JS,PaginatorBasein Python), mirroringSandbox.list(). The CLI'se2b template listpages through results behind a-l, --limitoption (default 1000, 100 per page,0for no limit) with a "Showing first N…" hint — aligned withe2b sandbox list. Pagination uses thelimit/nextTokenquery params and theX-Next-Tokenresponse header. The API key is team-scoped, so listing takes no team identifier.What's included
GET /v2/templates(limit+nextToken,Template[]), regenerated JS + Python clients.e2b):Template.list()→TemplatePaginator(hasNext/nextItems()) returningTemplateInfo. Lives insrc/template/templateApi.tsand depends only on shared infra (Paginator,ConnectionOpts).@e2b/python-sdk):Template.list()/AsyncTemplate.list()→TemplatePaginator/AsyncTemplatePaginatorreturningTemplateInfo, living in the template package (e2b/template/template_api.py,e2b/template_{sync,async}/paginator.py) and built on the sharedPaginatorBase.@e2b/cli):e2b template listpagination matchingsandbox list; thedelete/publish--selectflows consume the same helper.Template.list()against the live API.e2b,@e2b/python-sdk,@e2b/cli.Usage
CLI:
JS SDK:
Python SDK:
Notes
TemplatePaginator.nextItems()returns[]when exhausted (the sandbox/snapshot paginators still throw — to be unified separately).