taskmaster-api 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.
- taskmaster_api/__init__.py +6 -0
- taskmaster_api/client.py +230 -0
- taskmaster_api/py.typed +1 -0
- taskmaster_api-0.1.0.dist-info/METADATA +44 -0
- taskmaster_api-0.1.0.dist-info/RECORD +8 -0
- taskmaster_api-0.1.0.dist-info/WHEEL +5 -0
- taskmaster_api-0.1.0.dist-info/licenses/LICENSE +21 -0
- taskmaster_api-0.1.0.dist-info/top_level.txt +1 -0
taskmaster_api/client.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""HTTP client for one Taskmaster daemon.
|
|
2
|
+
|
|
3
|
+
``tm serve .`` listens on ``http://127.0.0.1:8737``. Health and pair need no
|
|
4
|
+
token. Every other ``/api`` route needs ``Authorization: Bearer <token>``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import urllib.error
|
|
11
|
+
import urllib.request
|
|
12
|
+
from typing import Any, Mapping, Optional
|
|
13
|
+
|
|
14
|
+
DEFAULT_BASE_URL = "http://127.0.0.1:8737"
|
|
15
|
+
VERSION = "0.1.0"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TaskmasterError(Exception):
|
|
19
|
+
"""The daemon refused the request, or the response was not usable JSON.
|
|
20
|
+
|
|
21
|
+
``status`` is ``0`` when no HTTP response arrived.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, status: int, message: str) -> None:
|
|
25
|
+
super().__init__(message)
|
|
26
|
+
self.status = status
|
|
27
|
+
self.message = message
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Taskmaster:
|
|
31
|
+
"""Synchronous client. A token set here is sent on every request."""
|
|
32
|
+
|
|
33
|
+
def __init__(self, base_url: str = DEFAULT_BASE_URL, token: Optional[str] = None, timeout: float = 30) -> None:
|
|
34
|
+
self.base_url = base_url.rstrip("/")
|
|
35
|
+
self.token = token
|
|
36
|
+
self.timeout = timeout
|
|
37
|
+
|
|
38
|
+
def with_token(self, token: str) -> "Taskmaster":
|
|
39
|
+
"""A new client with the same origin and a different token."""
|
|
40
|
+
return Taskmaster(self.base_url, token, self.timeout)
|
|
41
|
+
|
|
42
|
+
def set_token(self, token: str) -> None:
|
|
43
|
+
self.token = token
|
|
44
|
+
|
|
45
|
+
def clear_token(self) -> None:
|
|
46
|
+
self.token = None
|
|
47
|
+
|
|
48
|
+
def health(self) -> dict[str, Any]:
|
|
49
|
+
"""``GET /api/health``."""
|
|
50
|
+
return self._object(self.call("GET", "/api/health"))
|
|
51
|
+
|
|
52
|
+
def pair(self, code: str, label: Optional[str] = None, kind: Optional[str] = None) -> str:
|
|
53
|
+
"""``POST /api/pair``. Returns the device token and does not store it.
|
|
54
|
+
|
|
55
|
+
``kind`` is ``browser``, ``phone``, ``desktop``, ``machine``, or ``agent``.
|
|
56
|
+
"""
|
|
57
|
+
body: dict[str, str] = {"code": code}
|
|
58
|
+
if label:
|
|
59
|
+
body["label"] = label
|
|
60
|
+
if kind:
|
|
61
|
+
body["kind"] = kind
|
|
62
|
+
parsed = self._object(self.call("POST", "/api/pair", body))
|
|
63
|
+
token = parsed.get("token")
|
|
64
|
+
if not isinstance(token, str) or not token:
|
|
65
|
+
raise TaskmasterError(0, "pair response had no token")
|
|
66
|
+
return token
|
|
67
|
+
|
|
68
|
+
def runs(self) -> dict[str, Any]:
|
|
69
|
+
"""``GET /api/runs``. The body is ``{"runs": [...], "seq": n}``."""
|
|
70
|
+
return self._object(self.call("GET", "/api/runs"))
|
|
71
|
+
|
|
72
|
+
def runs_since(self, since: int) -> dict[str, Any]:
|
|
73
|
+
"""``GET /api/runs?since=``. ``since`` is a previous ``seq``."""
|
|
74
|
+
return self._object(self.call("GET", f"/api/runs?since={since}"))
|
|
75
|
+
|
|
76
|
+
def run(self, run_id: str) -> dict[str, Any]:
|
|
77
|
+
"""``GET /api/runs/{id}``."""
|
|
78
|
+
return self._object(self.call("GET", f"/api/runs/{_segment(run_id)}"))
|
|
79
|
+
|
|
80
|
+
def start(
|
|
81
|
+
self,
|
|
82
|
+
prompt: Optional[str] = None,
|
|
83
|
+
plan: Optional[Any] = None,
|
|
84
|
+
*,
|
|
85
|
+
yes: bool = False,
|
|
86
|
+
run_id: Optional[str] = None,
|
|
87
|
+
roles: Optional[Mapping[str, str]] = None,
|
|
88
|
+
models: Optional[Mapping[str, Optional[str]]] = None,
|
|
89
|
+
parallel: Optional[int] = None,
|
|
90
|
+
timeout_secs: Optional[int] = None,
|
|
91
|
+
template: Optional[str] = None,
|
|
92
|
+
max_cost_usd: Optional[float] = None,
|
|
93
|
+
mode: Optional[str] = None,
|
|
94
|
+
permission_mode: Optional[str] = None,
|
|
95
|
+
goal: Optional[str] = None,
|
|
96
|
+
goal_max_turns: Optional[int] = None,
|
|
97
|
+
computer_use: Optional[bool] = None,
|
|
98
|
+
) -> dict[str, Any]:
|
|
99
|
+
"""``POST /api/runs``. Send a prompt or a plan, and not both.
|
|
100
|
+
|
|
101
|
+
The daemon answers ``202`` once the run is started. ``yes`` builds
|
|
102
|
+
without waiting for approval.
|
|
103
|
+
"""
|
|
104
|
+
body: dict[str, Any] = {}
|
|
105
|
+
if run_id is not None:
|
|
106
|
+
body["id"] = run_id
|
|
107
|
+
if prompt is not None:
|
|
108
|
+
body["prompt"] = prompt
|
|
109
|
+
if plan is not None:
|
|
110
|
+
body["plan"] = plan
|
|
111
|
+
if yes:
|
|
112
|
+
body["yes"] = True
|
|
113
|
+
if roles:
|
|
114
|
+
body["roles"] = dict(roles)
|
|
115
|
+
if models:
|
|
116
|
+
body["models"] = dict(models)
|
|
117
|
+
if parallel is not None:
|
|
118
|
+
body["parallel"] = parallel
|
|
119
|
+
if timeout_secs is not None:
|
|
120
|
+
body["timeout_secs"] = timeout_secs
|
|
121
|
+
if template is not None:
|
|
122
|
+
body["template"] = template
|
|
123
|
+
if max_cost_usd is not None:
|
|
124
|
+
body["max_cost_usd"] = max_cost_usd
|
|
125
|
+
if mode is not None:
|
|
126
|
+
body["mode"] = mode
|
|
127
|
+
if permission_mode is not None:
|
|
128
|
+
body["permission_mode"] = permission_mode
|
|
129
|
+
if goal is not None:
|
|
130
|
+
body["goal"] = goal
|
|
131
|
+
if goal_max_turns is not None:
|
|
132
|
+
body["goal_max_turns"] = goal_max_turns
|
|
133
|
+
if computer_use is not None:
|
|
134
|
+
body["computer_use"] = computer_use
|
|
135
|
+
return self._object(self.call("POST", "/api/runs", body))
|
|
136
|
+
|
|
137
|
+
def approve(self, run_id: str, note: Optional[str] = None) -> dict[str, Any]:
|
|
138
|
+
"""``POST /api/runs/{id}/approve``. ``note`` is read by the master first."""
|
|
139
|
+
body: dict[str, Any] = {"note": note} if note else {}
|
|
140
|
+
return self._object(self.call("POST", f"/api/runs/{_segment(run_id)}/approve", body))
|
|
141
|
+
|
|
142
|
+
def reject(self, run_id: str, prompt: Optional[str] = None) -> dict[str, Any]:
|
|
143
|
+
"""``POST /api/runs/{id}/reject``. A prompt makes the run plan again."""
|
|
144
|
+
body: dict[str, Any] = {"prompt": prompt} if prompt else {}
|
|
145
|
+
return self._object(self.call("POST", f"/api/runs/{_segment(run_id)}/reject", body))
|
|
146
|
+
|
|
147
|
+
def resume(self, run_id: str) -> dict[str, Any]:
|
|
148
|
+
"""``POST /api/runs/{id}/resume``."""
|
|
149
|
+
return self._object(self.call("POST", f"/api/runs/{_segment(run_id)}/resume", {}))
|
|
150
|
+
|
|
151
|
+
def cancel(self, run_id: str) -> dict[str, Any]:
|
|
152
|
+
"""``POST /api/runs/{id}/cancel``."""
|
|
153
|
+
return self._object(self.call("POST", f"/api/runs/{_segment(run_id)}/cancel", {}))
|
|
154
|
+
|
|
155
|
+
def undo(self, run_id: str) -> Any:
|
|
156
|
+
"""``POST /api/runs/{id}/undo``."""
|
|
157
|
+
return self.call("POST", f"/api/runs/{_segment(run_id)}/undo", {})
|
|
158
|
+
|
|
159
|
+
def events(self, run_id: str, after: Optional[int] = None) -> dict[str, Any]:
|
|
160
|
+
"""``GET /api/runs/{id}/events``. ``after`` is the previous ``next``."""
|
|
161
|
+
query = "" if after is None else f"?after={after}"
|
|
162
|
+
return self._object(self.call("GET", f"/api/runs/{_segment(run_id)}/events{query}"))
|
|
163
|
+
|
|
164
|
+
def projects(self) -> Any:
|
|
165
|
+
"""``GET /api/projects``."""
|
|
166
|
+
return self.call("GET", "/api/projects")
|
|
167
|
+
|
|
168
|
+
def providers(self) -> Any:
|
|
169
|
+
"""``GET /api/providers``."""
|
|
170
|
+
return self.call("GET", "/api/providers")
|
|
171
|
+
|
|
172
|
+
def doctor(self) -> Any:
|
|
173
|
+
"""``GET /api/doctor``."""
|
|
174
|
+
return self.call("GET", "/api/doctor")
|
|
175
|
+
|
|
176
|
+
def call(self, method: str, path: str, body: Optional[Any] = None) -> Any:
|
|
177
|
+
"""Send any daemon route.
|
|
178
|
+
|
|
179
|
+
``path`` starts with ``/``. ``body`` is JSON for requests that have one.
|
|
180
|
+
An empty success body becomes ``None``.
|
|
181
|
+
"""
|
|
182
|
+
if not path.startswith("/") or "://" in path or "\0" in path:
|
|
183
|
+
raise TaskmasterError(0, f"path must start with /: {path}")
|
|
184
|
+
data = None if body is None else json.dumps(body).encode("utf-8")
|
|
185
|
+
request = urllib.request.Request(self.base_url + path, data=data, method=method)
|
|
186
|
+
if body is not None:
|
|
187
|
+
request.add_header("Content-Type", "application/json")
|
|
188
|
+
if self.token:
|
|
189
|
+
request.add_header("Authorization", f"Bearer {self.token}")
|
|
190
|
+
try:
|
|
191
|
+
with urllib.request.urlopen(request, timeout=self.timeout) as response:
|
|
192
|
+
raw = response.read()
|
|
193
|
+
except urllib.error.HTTPError as exc:
|
|
194
|
+
raw = exc.read()
|
|
195
|
+
raise TaskmasterError(exc.code, _error_message(raw, exc.code)) from None
|
|
196
|
+
except urllib.error.URLError as exc:
|
|
197
|
+
raise TaskmasterError(0, str(exc.reason)) from None
|
|
198
|
+
if not raw or not raw.strip():
|
|
199
|
+
return None
|
|
200
|
+
try:
|
|
201
|
+
return json.loads(raw.decode("utf-8"))
|
|
202
|
+
except json.JSONDecodeError as exc:
|
|
203
|
+
raise TaskmasterError(0, "response was not JSON") from exc
|
|
204
|
+
|
|
205
|
+
@staticmethod
|
|
206
|
+
def _object(value: Any) -> dict[str, Any]:
|
|
207
|
+
if not isinstance(value, dict):
|
|
208
|
+
raise TaskmasterError(0, "response was not a JSON object")
|
|
209
|
+
return value
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _segment(run_id: str) -> str:
|
|
213
|
+
from urllib.parse import quote
|
|
214
|
+
|
|
215
|
+
return quote(run_id, safe="")
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _error_message(raw: bytes, status: int) -> str:
|
|
219
|
+
text = raw.decode("utf-8", errors="replace").strip()
|
|
220
|
+
if not text:
|
|
221
|
+
return f"HTTP {status}"
|
|
222
|
+
try:
|
|
223
|
+
parsed = json.loads(text)
|
|
224
|
+
except json.JSONDecodeError:
|
|
225
|
+
return text
|
|
226
|
+
if isinstance(parsed, dict):
|
|
227
|
+
message = parsed.get("error")
|
|
228
|
+
if isinstance(message, str) and message:
|
|
229
|
+
return message
|
|
230
|
+
return text
|
taskmaster_api/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: taskmaster-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Client for the Taskmaster local daemon HTTP API
|
|
5
|
+
Author: Naren Sengodan
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/narensen/taskmaster-api
|
|
8
|
+
Project-URL: Repository, https://github.com/narensen/taskmaster-api
|
|
9
|
+
Keywords: taskmaster,api,client,daemon
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# taskmaster-api
|
|
19
|
+
|
|
20
|
+
Client for a [Taskmaster](https://github.com/narensen/Taskmaster) daemon running on your machine.
|
|
21
|
+
|
|
22
|
+
`tm serve .` listens on `http://127.0.0.1:8737`. `GET /api/health` and `POST /api/pair` need no token. Every other `/api` route needs `Authorization: Bearer <token>`.
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from taskmaster_api import Taskmaster
|
|
26
|
+
|
|
27
|
+
tm = Taskmaster()
|
|
28
|
+
tm.set_token(tm.pair("ABCD", label="laptop", kind="agent"))
|
|
29
|
+
|
|
30
|
+
accepted = tm.start("Add a command palette", yes=True)
|
|
31
|
+
page = tm.events(accepted["id"])
|
|
32
|
+
print(page["next"])
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`0.1.0` covers health, pairing, projects, providers, doctor, and the run lifecycle: list, get, start, approve, reject, resume, cancel, undo, and events. `call(method, path, body)` sends any other route and returns the JSON value.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
doctor = tm.doctor()
|
|
39
|
+
dictionary = tm.call("GET", "/api/dictionary?q=button")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The standard library is the only dependency. The same client is published for Rust (`cargo add taskmaster-api`) and JavaScript (`npm install taskmaster-api`).
|
|
43
|
+
|
|
44
|
+
MIT © 2026 Naren Sengodan
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
taskmaster_api/__init__.py,sha256=hBTAlTQhG9qByXoDJILAlfmJeNdMoWrwG2fsXuvEM1M,236
|
|
2
|
+
taskmaster_api/client.py,sha256=42WuW9Izgl1RJXTp2-l6KmFPJP_rSt0rnpmhNmrpyqo,8745
|
|
3
|
+
taskmaster_api/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
taskmaster_api-0.1.0.dist-info/licenses/LICENSE,sha256=dMTuPSKtnP69xjRoU09WxOfzuCXMfZ_e8GPCjZEY830,1071
|
|
5
|
+
taskmaster_api-0.1.0.dist-info/METADATA,sha256=l2Aq4XN3opc8uCjCJNZVZsXH_JL77Tf4Ia_x7aasJxA,1602
|
|
6
|
+
taskmaster_api-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
taskmaster_api-0.1.0.dist-info/top_level.txt,sha256=bN4d_q-hbPNkU7dCogKdyXzJg8JZyhtdlAnmcsH_RE4,15
|
|
8
|
+
taskmaster_api-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Naren Sengodan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
taskmaster_api
|