sinatra-dev 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. sinatra_dev/__init__.py +71 -0
  2. sinatra_dev/_client.py +391 -0
  3. sinatra_dev/_errors.py +53 -0
  4. sinatra_dev/_generated/__init__.py +8 -0
  5. sinatra_dev/_generated/api/__init__.py +1 -0
  6. sinatra_dev/_generated/api/me/__init__.py +1 -0
  7. sinatra_dev/_generated/api/me/me_get.py +156 -0
  8. sinatra_dev/_generated/api/me/me_revoke_token.py +173 -0
  9. sinatra_dev/_generated/api/messages/__init__.py +1 -0
  10. sinatra_dev/_generated/api/messages/messages_create.py +323 -0
  11. sinatra_dev/_generated/api/messages/messages_list.py +332 -0
  12. sinatra_dev/_generated/api/tasks/__init__.py +1 -0
  13. sinatra_dev/_generated/api/tasks/tasks_create.py +337 -0
  14. sinatra_dev/_generated/api/tasks/tasks_get.py +202 -0
  15. sinatra_dev/_generated/api/tasks/tasks_list.py +252 -0
  16. sinatra_dev/_generated/api/tasks/tasks_stop.py +231 -0
  17. sinatra_dev/_generated/api/tickets/__init__.py +1 -0
  18. sinatra_dev/_generated/api/tickets/tickets_delegate.py +273 -0
  19. sinatra_dev/_generated/api/tickets/tickets_search.py +265 -0
  20. sinatra_dev/_generated/client.py +280 -0
  21. sinatra_dev/_generated/errors.py +16 -0
  22. sinatra_dev/_generated/models/__init__.py +47 -0
  23. sinatra_dev/_generated/models/create_message_request.py +62 -0
  24. sinatra_dev/_generated/models/create_message_response.py +62 -0
  25. sinatra_dev/_generated/models/create_task_request.py +106 -0
  26. sinatra_dev/_generated/models/create_task_response.py +76 -0
  27. sinatra_dev/_generated/models/delegate_github_ticket.py +86 -0
  28. sinatra_dev/_generated/models/delegate_linear_ticket.py +78 -0
  29. sinatra_dev/_generated/models/delegate_ticket_response.py +62 -0
  30. sinatra_dev/_generated/models/error.py +168 -0
  31. sinatra_dev/_generated/models/me.py +86 -0
  32. sinatra_dev/_generated/models/me_user.py +98 -0
  33. sinatra_dev/_generated/models/message.py +113 -0
  34. sinatra_dev/_generated/models/message_list.py +91 -0
  35. sinatra_dev/_generated/models/pull_request.py +70 -0
  36. sinatra_dev/_generated/models/stop_task_response.py +62 -0
  37. sinatra_dev/_generated/models/task.py +201 -0
  38. sinatra_dev/_generated/models/task_list.py +91 -0
  39. sinatra_dev/_generated/models/ticket.py +147 -0
  40. sinatra_dev/_generated/models/ticket_search_result.py +97 -0
  41. sinatra_dev/_generated/models/ticket_search_result_github.py +77 -0
  42. sinatra_dev/_generated/models/ticket_search_result_linear.py +79 -0
  43. sinatra_dev/_generated/models/workspace.py +78 -0
  44. sinatra_dev/_generated/types.py +54 -0
  45. sinatra_dev/_retry.py +72 -0
  46. sinatra_dev/py.typed +0 -0
  47. sinatra_dev-0.1.0.dist-info/METADATA +184 -0
  48. sinatra_dev-0.1.0.dist-info/RECORD +50 -0
  49. sinatra_dev-0.1.0.dist-info/WHEEL +4 -0
  50. sinatra_dev-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,97 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from typing import TYPE_CHECKING, Any, Self, TypeVar
5
+
6
+ from attrs import define as _attrs_define
7
+ from attrs import field as _attrs_field
8
+
9
+ if TYPE_CHECKING:
10
+ from ..models.ticket import Ticket
11
+ from ..models.ticket_search_result_github import TicketSearchResultGithub
12
+ from ..models.ticket_search_result_linear import TicketSearchResultLinear
13
+
14
+
15
+ T = TypeVar("T", bound="TicketSearchResult")
16
+
17
+
18
+ @_attrs_define
19
+ class TicketSearchResult:
20
+ """The issues you could delegate, and how the workspace is connected to each tracker.
21
+
22
+ Attributes:
23
+ tickets (list[Ticket]): The issues you could delegate. Linear issues come first, then GitHub's, each with yours
24
+ before your team's unassigned ones.
25
+ linear (TicketSearchResultLinear): The workspace's Linear connection, as it applies to you.
26
+ github (TicketSearchResultGithub): The workspace's GitHub connection.
27
+ """
28
+
29
+ tickets: list[Ticket]
30
+ linear: TicketSearchResultLinear
31
+ github: TicketSearchResultGithub
32
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
33
+
34
+ def to_dict(self) -> dict[str, Any]:
35
+ tickets = []
36
+ for tickets_item_data in self.tickets:
37
+ tickets_item = tickets_item_data.to_dict()
38
+ tickets.append(tickets_item)
39
+
40
+ linear = self.linear.to_dict()
41
+
42
+ github = self.github.to_dict()
43
+
44
+ field_dict: dict[str, Any] = {}
45
+ field_dict.update(self.additional_properties)
46
+ field_dict.update(
47
+ {
48
+ "tickets": tickets,
49
+ "linear": linear,
50
+ "github": github,
51
+ }
52
+ )
53
+
54
+ return field_dict
55
+
56
+ @classmethod
57
+ def from_dict(cls, src_dict: Mapping[str, Any]) -> Self:
58
+ from ..models.ticket import Ticket
59
+ from ..models.ticket_search_result_github import TicketSearchResultGithub
60
+ from ..models.ticket_search_result_linear import TicketSearchResultLinear
61
+
62
+ d = dict(src_dict)
63
+ tickets = []
64
+ _tickets = d.pop("tickets")
65
+ for tickets_item_data in _tickets:
66
+ tickets_item = Ticket.from_dict(tickets_item_data)
67
+
68
+ tickets.append(tickets_item)
69
+
70
+ linear = TicketSearchResultLinear.from_dict(d.pop("linear"))
71
+
72
+ github = TicketSearchResultGithub.from_dict(d.pop("github"))
73
+
74
+ ticket_search_result = cls(
75
+ tickets=tickets,
76
+ linear=linear,
77
+ github=github,
78
+ )
79
+
80
+ ticket_search_result.additional_properties = d
81
+ return ticket_search_result
82
+
83
+ @property
84
+ def additional_keys(self) -> list[str]:
85
+ return list(self.additional_properties.keys())
86
+
87
+ def __getitem__(self, key: str) -> Any:
88
+ return self.additional_properties[key]
89
+
90
+ def __setitem__(self, key: str, value: Any) -> None:
91
+ self.additional_properties[key] = value
92
+
93
+ def __delitem__(self, key: str) -> None:
94
+ del self.additional_properties[key]
95
+
96
+ def __contains__(self, key: str) -> bool:
97
+ return key in self.additional_properties
@@ -0,0 +1,77 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from typing import Any, Self, TypeVar, cast
5
+
6
+ from attrs import define as _attrs_define
7
+ from attrs import field as _attrs_field
8
+
9
+ T = TypeVar("T", bound="TicketSearchResultGithub")
10
+
11
+
12
+ @_attrs_define
13
+ class TicketSearchResultGithub:
14
+ """The workspace's GitHub connection.
15
+
16
+ Attributes:
17
+ connected (bool): Whether the workspace is connected to GitHub.
18
+ repo (None | str): The repository the GitHub search covered, when the `repo` query matched an enabled one and
19
+ had open issues. Otherwise `null`.
20
+ """
21
+
22
+ connected: bool
23
+ repo: None | str
24
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
25
+
26
+ def to_dict(self) -> dict[str, Any]:
27
+ connected = self.connected
28
+
29
+ repo: None | str
30
+ repo = self.repo
31
+
32
+ field_dict: dict[str, Any] = {}
33
+ field_dict.update(self.additional_properties)
34
+ field_dict.update(
35
+ {
36
+ "connected": connected,
37
+ "repo": repo,
38
+ }
39
+ )
40
+
41
+ return field_dict
42
+
43
+ @classmethod
44
+ def from_dict(cls, src_dict: Mapping[str, Any]) -> Self:
45
+ d = dict(src_dict)
46
+ connected = d.pop("connected")
47
+
48
+ def _parse_repo(data: object) -> None | str:
49
+ if data is None:
50
+ return data
51
+ return cast(None | str, data)
52
+
53
+ repo = _parse_repo(d.pop("repo"))
54
+
55
+ ticket_search_result_github = cls(
56
+ connected=connected,
57
+ repo=repo,
58
+ )
59
+
60
+ ticket_search_result_github.additional_properties = d
61
+ return ticket_search_result_github
62
+
63
+ @property
64
+ def additional_keys(self) -> list[str]:
65
+ return list(self.additional_properties.keys())
66
+
67
+ def __getitem__(self, key: str) -> Any:
68
+ return self.additional_properties[key]
69
+
70
+ def __setitem__(self, key: str, value: Any) -> None:
71
+ self.additional_properties[key] = value
72
+
73
+ def __delitem__(self, key: str) -> None:
74
+ del self.additional_properties[key]
75
+
76
+ def __contains__(self, key: str) -> bool:
77
+ return key in self.additional_properties
@@ -0,0 +1,79 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from typing import Any, Self, TypeVar
5
+
6
+ from attrs import define as _attrs_define
7
+ from attrs import field as _attrs_field
8
+
9
+ T = TypeVar("T", bound="TicketSearchResultLinear")
10
+
11
+
12
+ @_attrs_define
13
+ class TicketSearchResultLinear:
14
+ """The workspace's Linear connection, as it applies to you.
15
+
16
+ Attributes:
17
+ connected (bool): Whether the workspace is connected to Linear.
18
+ identity_linked (bool): Whether your Linear account is linked in this workspace. Linear issues are listed only
19
+ when it is.
20
+ identity_bound (bool): Whether your Linear identity is tied to your Sinatra user.
21
+ """
22
+
23
+ connected: bool
24
+ identity_linked: bool
25
+ identity_bound: bool
26
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
27
+
28
+ def to_dict(self) -> dict[str, Any]:
29
+ connected = self.connected
30
+
31
+ identity_linked = self.identity_linked
32
+
33
+ identity_bound = self.identity_bound
34
+
35
+ field_dict: dict[str, Any] = {}
36
+ field_dict.update(self.additional_properties)
37
+ field_dict.update(
38
+ {
39
+ "connected": connected,
40
+ "identityLinked": identity_linked,
41
+ "identityBound": identity_bound,
42
+ }
43
+ )
44
+
45
+ return field_dict
46
+
47
+ @classmethod
48
+ def from_dict(cls, src_dict: Mapping[str, Any]) -> Self:
49
+ d = dict(src_dict)
50
+ connected = d.pop("connected")
51
+
52
+ identity_linked = d.pop("identityLinked")
53
+
54
+ identity_bound = d.pop("identityBound")
55
+
56
+ ticket_search_result_linear = cls(
57
+ connected=connected,
58
+ identity_linked=identity_linked,
59
+ identity_bound=identity_bound,
60
+ )
61
+
62
+ ticket_search_result_linear.additional_properties = d
63
+ return ticket_search_result_linear
64
+
65
+ @property
66
+ def additional_keys(self) -> list[str]:
67
+ return list(self.additional_properties.keys())
68
+
69
+ def __getitem__(self, key: str) -> Any:
70
+ return self.additional_properties[key]
71
+
72
+ def __setitem__(self, key: str, value: Any) -> None:
73
+ self.additional_properties[key] = value
74
+
75
+ def __delitem__(self, key: str) -> None:
76
+ del self.additional_properties[key]
77
+
78
+ def __contains__(self, key: str) -> bool:
79
+ return key in self.additional_properties
@@ -0,0 +1,78 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from typing import Any, Self, TypeVar
5
+
6
+ from attrs import define as _attrs_define
7
+ from attrs import field as _attrs_field
8
+
9
+ T = TypeVar("T", bound="Workspace")
10
+
11
+
12
+ @_attrs_define
13
+ class Workspace:
14
+ """A workspace you belong to.
15
+
16
+ Attributes:
17
+ id (str): The workspace's id. Use it as `workspaceId` in the workspace endpoints.
18
+ name (str): The workspace's name.
19
+ role (str): Your role in it: `owner`, `admin` or `member`. New roles can appear.
20
+ """
21
+
22
+ id: str
23
+ name: str
24
+ role: str
25
+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
26
+
27
+ def to_dict(self) -> dict[str, Any]:
28
+ id = self.id
29
+
30
+ name = self.name
31
+
32
+ role = self.role
33
+
34
+ field_dict: dict[str, Any] = {}
35
+ field_dict.update(self.additional_properties)
36
+ field_dict.update(
37
+ {
38
+ "id": id,
39
+ "name": name,
40
+ "role": role,
41
+ }
42
+ )
43
+
44
+ return field_dict
45
+
46
+ @classmethod
47
+ def from_dict(cls, src_dict: Mapping[str, Any]) -> Self:
48
+ d = dict(src_dict)
49
+ id = d.pop("id")
50
+
51
+ name = d.pop("name")
52
+
53
+ role = d.pop("role")
54
+
55
+ workspace = cls(
56
+ id=id,
57
+ name=name,
58
+ role=role,
59
+ )
60
+
61
+ workspace.additional_properties = d
62
+ return workspace
63
+
64
+ @property
65
+ def additional_keys(self) -> list[str]:
66
+ return list(self.additional_properties.keys())
67
+
68
+ def __getitem__(self, key: str) -> Any:
69
+ return self.additional_properties[key]
70
+
71
+ def __setitem__(self, key: str, value: Any) -> None:
72
+ self.additional_properties[key] = value
73
+
74
+ def __delitem__(self, key: str) -> None:
75
+ del self.additional_properties[key]
76
+
77
+ def __contains__(self, key: str) -> bool:
78
+ return key in self.additional_properties
@@ -0,0 +1,54 @@
1
+ """Contains some shared types for properties"""
2
+
3
+ from collections.abc import Mapping, MutableMapping
4
+ from http import HTTPStatus
5
+ from typing import IO, BinaryIO, Generic, Literal, TypeVar
6
+
7
+ from attrs import define
8
+
9
+
10
+ class Unset:
11
+ def __bool__(self) -> Literal[False]:
12
+ return False
13
+
14
+
15
+ UNSET: Unset = Unset()
16
+
17
+ # The types that `httpx.Client(files=)` can accept, copied from that library.
18
+ FileContent = IO[bytes] | bytes | str
19
+ FileTypes = (
20
+ # (filename, file (or bytes), content_type)
21
+ tuple[str | None, FileContent, str | None]
22
+ # (filename, file (or bytes), content_type, headers)
23
+ | tuple[str | None, FileContent, str | None, Mapping[str, str]]
24
+ )
25
+ RequestFiles = list[tuple[str, FileTypes]]
26
+
27
+
28
+ @define
29
+ class File:
30
+ """Contains information for file uploads"""
31
+
32
+ payload: BinaryIO
33
+ file_name: str | None = None
34
+ mime_type: str | None = None
35
+
36
+ def to_tuple(self) -> FileTypes:
37
+ """Return a tuple representation that httpx will accept for multipart/form-data"""
38
+ return self.file_name, self.payload, self.mime_type
39
+
40
+
41
+ T = TypeVar("T")
42
+
43
+
44
+ @define
45
+ class Response(Generic[T]):
46
+ """A response from an endpoint"""
47
+
48
+ status_code: HTTPStatus
49
+ content: bytes
50
+ headers: MutableMapping[str, str]
51
+ parsed: T | None
52
+
53
+
54
+ __all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"]
sinatra_dev/_retry.py ADDED
@@ -0,0 +1,72 @@
1
+ """When a request is retried, and how long the client waits first."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ import time
7
+ from collections.abc import Callable
8
+ from datetime import UTC
9
+ from email.utils import parsedate_to_datetime
10
+
11
+ import httpx
12
+
13
+ MAX_RETRIES = 3
14
+ """At most this many retries after the first attempt."""
15
+ BACKOFF_SECONDS = 0.5
16
+ """The first ``503`` backoff; it doubles on each retry (0.5s, 1s, 2s)."""
17
+ MAX_RETRY_AFTER_SECONDS = 60.0
18
+ """A ``Retry-After`` longer than this is cut to it."""
19
+
20
+ RETRY_IDEMPOTENT = frozenset({429, 503})
21
+ """GETs, DELETE, and POSTs that carry an ``Idempotency-Key``."""
22
+ RETRY_UNAVAILABLE = frozenset({503})
23
+ """``tasks.stop``: a stop is safe to repeat after a ``503``, but not after a ``429``."""
24
+ RETRY_NEVER: frozenset[int] = frozenset()
25
+ """POSTs without an ``Idempotency-Key``: never retried."""
26
+
27
+ # The tests replace this with a fake clock.
28
+ sleep: Callable[[float], None] = time.sleep
29
+
30
+
31
+ def with_retries(retry_on: frozenset[int], attempt: Callable[[], httpx.Response]) -> httpx.Response:
32
+ """Sends ``attempt()`` until it succeeds, fails with a status ``retry_on``
33
+ doesn't cover, or runs out of retries, and returns the last response.
34
+
35
+ Every attempt must send the same request: callers compute the
36
+ ``Idempotency-Key`` once, outside ``attempt``. Exceptions (network errors,
37
+ timeouts) are never retried.
38
+ """
39
+ retry = 0
40
+ while True:
41
+ response = attempt()
42
+ if response.is_success or retry >= MAX_RETRIES or response.status_code not in retry_on:
43
+ return response
44
+ sleep(retry_delay(response, retry))
45
+ retry += 1
46
+
47
+
48
+ def retry_delay(response: httpx.Response, retry: int) -> float:
49
+ if response.status_code == 429:
50
+ after = parse_retry_after(response.headers.get("retry-after"))
51
+ if after is not None:
52
+ return min(after, MAX_RETRY_AFTER_SECONDS)
53
+ return float(BACKOFF_SECONDS * 2**retry)
54
+
55
+
56
+ def parse_retry_after(value: str | None) -> float | None:
57
+ """``Retry-After`` is either seconds or an HTTP date. Returns seconds."""
58
+ if value is None or not value.strip():
59
+ return None
60
+ try:
61
+ seconds = float(value)
62
+ except ValueError:
63
+ pass
64
+ else:
65
+ return max(0.0, seconds) if math.isfinite(seconds) else None
66
+ try:
67
+ when = parsedate_to_datetime(value)
68
+ except (TypeError, ValueError):
69
+ return None
70
+ if when.tzinfo is None: # "-0000": HTTP dates are always GMT
71
+ when = when.replace(tzinfo=UTC)
72
+ return max(0.0, when.timestamp() - time.time())
sinatra_dev/py.typed ADDED
File without changes
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.5
2
+ Name: sinatra-dev
3
+ Version: 0.1.0
4
+ Summary: Python client for the Sinatra API: start, follow and stop Sinatra tasks, and delegate Linear and GitHub issues.
5
+ Project-URL: Homepage, https://sinatra.dev
6
+ Project-URL: Documentation, https://docs.sinatra.dev/docs/api-reference
7
+ Project-URL: Repository, https://github.com/sinatra-dev/sinatra-python
8
+ Project-URL: Issues, https://github.com/sinatra-dev/sinatra-python/issues
9
+ Author-email: Sinatra <contact@sinatra.dev>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api-client,coding-agent,sdk,sinatra,sinatra.dev
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: attrs>=22.2.0
24
+ Requires-Dist: httpx<0.29.0,>=0.23.1
25
+ Description-Content-Type: text/markdown
26
+
27
+ # sinatra-dev
28
+
29
+ A Python client for the [Sinatra API](https://docs.sinatra.dev/docs/api-reference): start, follow and stop Sinatra tasks, and delegate Linear and GitHub issues.
30
+
31
+ It runs on Python 3.11 and later, is typed (`py.typed`), and depends only on `httpx` and `attrs`. The client is generated from the API's [OpenAPI spec](https://api.sinatra.dev/openapi.json) and released automatically when the spec changes.
32
+
33
+ ## Install
34
+
35
+ ```sh
36
+ pip install sinatra-dev
37
+ ```
38
+
39
+ ## Quick start
40
+
41
+ ```python
42
+ import time
43
+
44
+ from sinatra_dev import Sinatra
45
+
46
+ # The turn is done when the task leaves these statuses (for example, it reaches replied or pr_open).
47
+ WORKING = {"pending", "investigating", "implementing", "rework"}
48
+
49
+ with Sinatra() as sinatra: # reads SINATRA_TOKEN
50
+ me = sinatra.me.get()
51
+ if not me.workspaces:
52
+ raise SystemExit("The token's user isn't in any workspace yet.")
53
+ workspace = me.workspaces[0]
54
+
55
+ task = sinatra.tasks.create(
56
+ workspace.id, "Fix the flaky login test", repo="acme/web", idempotency_key="fix-flaky-login-1"
57
+ ).task
58
+
59
+ after = None
60
+ while True:
61
+ status = sinatra.tasks.get(workspace.id, task.id).status
62
+ for m in sinatra.messages.list_all(workspace.id, task.id, after=after):
63
+ print(f"{m.role}: {m.body}")
64
+ after = m.id
65
+ if status not in WORKING:
66
+ break
67
+ time.sleep(3)
68
+ print(f"Task {task.id} is {status}.")
69
+ ```
70
+
71
+ The API has no streaming. To wait for a reply, read the conversation after the last entry you've seen, and check the task's `status`: the agent posts one reply per turn, and the turn is done when the task stops working. The loop reads the status before the conversation, so it never stops before printing the reply that ended the turn. An unknown status counts as done, so the loop can't wait forever on a status added after this was written. See [How replies work](https://docs.sinatra.dev/docs/cli-and-api#how-replies-work).
72
+
73
+ ## Authentication
74
+
75
+ Create a personal access token on the [Access tokens](https://app.sinatra.dev/tokens) page (**CLI & API** in the dashboard). It starts with `sntr_` and acts as you in every workspace you belong to. The client reads it from the `SINATRA_TOKEN` environment variable, or you can pass it:
76
+
77
+ ```python
78
+ sinatra = Sinatra(token=os.environ["MY_TOKEN"])
79
+ ```
80
+
81
+ The constructor raises `ValueError` if it finds no token. Other options:
82
+
83
+ - `base_url`: defaults to `https://api.sinatra.dev`.
84
+ - `timeout`: seconds each attempt may wait to connect, and for each chunk of the response, before httpx raises `httpx.TimeoutException`. Defaults to 60; `None` turns it off. An `httpx.Timeout` works too.
85
+ - `http_client`: an `httpx.Client` to send requests with, for example one with a proxy. The client doesn't close it.
86
+
87
+ Every method takes a `timeout` keyword that overrides the client's for that call:
88
+
89
+ ```python
90
+ sinatra.tasks.get(workspace_id, task_id, timeout=5)
91
+ ```
92
+
93
+ Use the client as a context manager, or call `sinatra.close()`, to release its connections.
94
+
95
+ ## Operations
96
+
97
+ The namespaces mirror the API's operation ids:
98
+
99
+ | Method | Request |
100
+ | --- | --- |
101
+ | `me.get()` | `GET /v1/me` |
102
+ | `me.revoke_token()` | `DELETE /v1/me/token` |
103
+ | `tasks.list(workspace_id, status=, limit=, cursor=)` | `GET /v1/workspaces/{workspaceId}/tasks` |
104
+ | `tasks.get(workspace_id, task_id)` | `GET /v1/workspaces/{workspaceId}/tasks/{taskId}` |
105
+ | `tasks.create(workspace_id, prompt, title=, repo=, idempotency_key=)` | `POST /v1/workspaces/{workspaceId}/tasks` |
106
+ | `tasks.stop(workspace_id, task_id)` | `POST /v1/workspaces/{workspaceId}/tasks/{taskId}/stop` |
107
+ | `messages.create(workspace_id, task_id, text, idempotency_key=)` | `POST /v1/workspaces/{workspaceId}/tasks/{taskId}/messages` |
108
+ | `messages.list(workspace_id, task_id, after=, limit=)` | `GET /v1/workspaces/{workspaceId}/tasks/{taskId}/messages` |
109
+ | `tickets.search(workspace_id, q=, repo=)` | `GET /v1/workspaces/{workspaceId}/tickets` |
110
+ | `tickets.delegate(workspace_id, source="linear", id=)` or `(workspace_id, source="github", repo=, number=)` | `POST /v1/workspaces/{workspaceId}/tickets/delegate` |
111
+
112
+ Responses are typed objects with snake_case attributes (`task.pull_request`, `page.next_cursor`). Fields the API added after this release are kept in each object's `additional_properties`.
113
+
114
+ `tasks.list_all` and `messages.list_all` page through everything for you:
115
+
116
+ ```python
117
+ for task in sinatra.tasks.list_all(workspace_id, status="pr_open"):
118
+ print(task.id, task.title)
119
+ ```
120
+
121
+ Fields such as `status`, `source`, `role`, `kind` and the error `code` are plain strings, and the API adds new values over time. Handle values you don't recognise.
122
+
123
+ ## Retries and idempotency
124
+
125
+ `tasks.create` and `messages.create` always send an `Idempotency-Key`. If you don't pass one, the client makes a random UUID. Every retry of a call sends the same key, so a retried start never starts a second task. Pass your own key to make a retry safe across process restarts too.
126
+
127
+ The client retries a request up to 3 times when it's safe to repeat:
128
+
129
+ - `429`: after the `Retry-After` the server sends, at most 60 seconds.
130
+ - `503`: after 0.5s, then 1s, then 2s.
131
+
132
+ GETs, `me.revoke_token`, `tasks.create` and `messages.create` retry on both. `tasks.stop` retries on `503` only. `tickets.delegate` takes no idempotency key and is never retried. Other errors, timeouts and network failures are never retried.
133
+
134
+ ## Errors
135
+
136
+ An error response raises a `SinatraError`:
137
+
138
+ ```python
139
+ from sinatra_dev import SinatraError
140
+
141
+ try:
142
+ sinatra.tasks.stop(workspace_id, task_id)
143
+ except SinatraError as err:
144
+ if err.code != "not_running": # not_running: the task had already stopped
145
+ raise
146
+ ```
147
+
148
+ | Attribute | |
149
+ | --- | --- |
150
+ | `status` | The HTTP status. |
151
+ | `code` | The API's `error` code, such as `capacity_full`. `http_error` when the response carried none, such as an HTML error page from a proxy. |
152
+ | `reason` | A sentence for a person. Don't branch on it. |
153
+ | `request_id` | The request's id. Include it when you contact support. |
154
+ | `body` | The response body: the parsed JSON, or the text. Refusals carry extra fields here, such as `billingUrl`. |
155
+ | `headers` | The response headers. |
156
+
157
+ Network failures and timeouts are not wrapped: they raise the `httpx.HTTPError` (for example `httpx.TimeoutException`) that httpx raised.
158
+
159
+ The [API reference](https://docs.sinatra.dev/docs/api-reference) lists every operation's error codes.
160
+
161
+ ## Versions
162
+
163
+ Releases follow semver. While the version is `0.x`, a breaking API change bumps the minor version and anything else bumps the patch. From `1.0`, breaking changes bump the major version and additions bump the minor.
164
+
165
+ ## Development
166
+
167
+ Needs [uv](https://docs.astral.sh/uv/), and Node 24 for the contract tests.
168
+
169
+ ```sh
170
+ uv sync
171
+ bash scripts/install-oasdiff.sh # installs the pinned oasdiff into .tools/bin
172
+ bash scripts/generate.sh # regenerates src/sinatra_dev/_generated from openapi.json
173
+ uv run ruff check . && uv run ruff format --check . && uv run mypy
174
+ uv run pytest # wrapper tests against a local stub server
175
+ bash scripts/contract.sh # every operation against a Prism mock of openapi.json
176
+ PATH="$PWD/.tools/bin:$PATH" bash scripts/next-version.test.sh
177
+ bash scripts/build.sh # sdist and wheel in dist/, build backend pinned by hash
178
+ ```
179
+
180
+ `src/sinatra_dev/_generated` is written by `openapi-python-client` and never edited by hand; CI fails if it differs from what `openapi.json` generates (`bash scripts/check-generated.sh`). `openapi.json` is updated by the release workflow. See [RELEASING.md](RELEASING.md).
181
+
182
+ ## License
183
+
184
+ MIT