riffsdk 0.25.0__tar.gz → 0.26.0__tar.gz
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.
- {riffsdk-0.25.0 → riffsdk-0.26.0}/AGENTS.md +1 -1
- {riffsdk-0.25.0 → riffsdk-0.26.0}/CHANGELOG.md +34 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/PKG-INFO +41 -4
- {riffsdk-0.25.0 → riffsdk-0.26.0}/README.md +40 -3
- {riffsdk-0.25.0 → riffsdk-0.26.0}/mise.toml +4 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/pyproject.toml +1 -1
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/tasks/__init__.py +2 -1
- riffsdk-0.26.0/src/riffsdk/tasks/v0.py +332 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_imports.py +2 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_tasks_v0.py +263 -1
- riffsdk-0.26.0/uv.lock +965 -0
- riffsdk-0.25.0/src/riffsdk/tasks/v0.py +0 -143
- riffsdk-0.25.0/uv.lock +0 -821
- {riffsdk-0.25.0 → riffsdk-0.26.0}/.github/workflows/ci.yml +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/.github/workflows/pr-comment.yml +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/.github/workflows/release.yml +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/.gitignore +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/.python-version +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/CLAUDE.md +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/LICENCE +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/LOCAL-TESTING.md +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/USAGE_PROMPT.md +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/examples/async_client.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/examples/basic_crud.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/examples/email_notice.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/examples/file_upload_download.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/examples/get_task.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/examples/interpret_document.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/examples/optimistic_concurrency.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/new-sdk-url-schema.md +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/__init__.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/__main__.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/_cli.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/_internal/__init__.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/_internal/auth.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/_internal/config.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/_internal/transport.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/ai/__init__.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/ai/v0.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/client.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/context.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/email/__init__.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/email/v0.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/__init__.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_async_client.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_client.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_common.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_http.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_mime.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_models.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_session.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_streaming.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/_upload.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/exceptions.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/src/riffsdk/storage/py.typed +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/__init__.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/conftest.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_ai_v0.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_async_client.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_auth.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_cli.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_client.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_config.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_context.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_email_v0.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_exceptions.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_http.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_importance.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_integration.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_mime.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_models.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_session.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_single_put_upload.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_streaming.py +0 -0
- {riffsdk-0.25.0 → riffsdk-0.26.0}/tests/test_upload.py +0 -0
|
@@ -60,7 +60,7 @@ src/riffsdk/
|
|
|
60
60
|
v0.py # notice_html/notice_text - the AI notice for emails
|
|
61
61
|
tasks/
|
|
62
62
|
__init__.py # Docstring only - importing it loads no version
|
|
63
|
-
v0.py # get_task - one task off the app's task board
|
|
63
|
+
v0.py # get_task, update_task_metadata - one task off the app's task board, and its metadata/assignee
|
|
64
64
|
ai/
|
|
65
65
|
__init__.py # Docstring only - importing it loads no version
|
|
66
66
|
v0.py # interpret_document - extract text from a stored document (LLM call)
|
|
@@ -2,6 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- version list -->
|
|
4
4
|
|
|
5
|
+
## v0.26.0 (2026-11-17)
|
|
6
|
+
|
|
7
|
+
### Chores
|
|
8
|
+
|
|
9
|
+
- Add mise upgrade task for in-range dependency upgrades
|
|
10
|
+
([#54](https://github.com/databutton/riff-sdk-python/pull/54),
|
|
11
|
+
[`c6a311e`](https://github.com/databutton/riff-sdk-python/commit/c6a311e639819c6efa89b17fa950ffc64712053f))
|
|
12
|
+
|
|
13
|
+
- Refresh dependencies within existing ranges
|
|
14
|
+
([#54](https://github.com/databutton/riff-sdk-python/pull/54),
|
|
15
|
+
[`c6a311e`](https://github.com/databutton/riff-sdk-python/commit/c6a311e639819c6efa89b17fa950ffc64712053f))
|
|
16
|
+
|
|
17
|
+
- Upgrade dependencies within existing ranges
|
|
18
|
+
([#55](https://github.com/databutton/riff-sdk-python/pull/55),
|
|
19
|
+
[`20f2bc6`](https://github.com/databutton/riff-sdk-python/commit/20f2bc6921ab3750749fe71116d9492f1bf7ae5f))
|
|
20
|
+
|
|
21
|
+
- Upgrade dependencies within existing ranges
|
|
22
|
+
([#53](https://github.com/databutton/riff-sdk-python/pull/53),
|
|
23
|
+
[`e08f84f`](https://github.com/databutton/riff-sdk-python/commit/e08f84fc6aaff188d7b62446cea8f4987b10a8e4))
|
|
24
|
+
|
|
25
|
+
### Documentation
|
|
26
|
+
|
|
27
|
+
- **tasks**: Only a metadata change wakes the task, not an assignee-only change
|
|
28
|
+
([`4e03702`](https://github.com/databutton/riff-sdk-python/commit/4e03702bdedb3e723d92e78059af5a69f0f6bef9))
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
- **tasks**: Update_task_metadata merges metadata and sets the assignee
|
|
33
|
+
([`c99a4dc`](https://github.com/databutton/riff-sdk-python/commit/c99a4dc8258021442a75ae8242ffa52ad5db7c72))
|
|
34
|
+
|
|
35
|
+
- **tasks**: Update_task_metadata wakes the task on change; wake=False opts out
|
|
36
|
+
([`ef12c09`](https://github.com/databutton/riff-sdk-python/commit/ef12c09e51f9c2714cb1a25f38bd4a9c955e1f9a))
|
|
37
|
+
|
|
38
|
+
|
|
5
39
|
## v0.25.0 (2026-10-26)
|
|
6
40
|
|
|
7
41
|
### Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: riffsdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.26.0
|
|
4
4
|
Summary: Python SDK for the Riff Storage API
|
|
5
5
|
Project-URL: Homepage, https://riff.ai
|
|
6
6
|
Author-email: Martin Sandve Alnæs <msa@databutton.io>
|
|
@@ -88,6 +88,35 @@ work left on them and nothing about the ones already finished, so it cannot
|
|
|
88
88
|
tell an item it has never seen from one whose task is done — and proposes the
|
|
89
89
|
same finished work every time it fires. `get_task` closes that gap.
|
|
90
90
|
|
|
91
|
+
To record what a trigger learned about a task, merge metadata into it and/or
|
|
92
|
+
set its assignee. A metadata change wakes the task's agent so it sees it
|
|
93
|
+
(`task.woken`); changing only the assignee does not. Pass `wake=False` for a
|
|
94
|
+
write it need not react to:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
task = tasks.update_task_metadata(
|
|
98
|
+
"TASK-42",
|
|
99
|
+
{"chase_count": 2, "stale_since": None}, # merged; None clears a key
|
|
100
|
+
approver="buyer@example.com", # user id or email; None unassigns; omit to leave alone
|
|
101
|
+
)
|
|
102
|
+
print(task["metadata"], task["approver"])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Keys that are not configured fields are always accepted and saved as they are.
|
|
106
|
+
A value for a *configured* field is checked against its type (a number field
|
|
107
|
+
takes a number, a select one of its options, a date an ISO 8601 string); one that
|
|
108
|
+
fails is not written, but the call does not fail -- the rest lands, and the
|
|
109
|
+
held-back keys come back on `task.rejected_metadata` (key -> why) and are logged
|
|
110
|
+
as a warning. Only configured fields are **shown** on the board, as list/board
|
|
111
|
+
columns and in the task's key information. A builder adds one in *Configure
|
|
112
|
+
fields* (Show in list / Show in summary), and the keys you wrote that are not
|
|
113
|
+
configured come back on `task.unconfigured_metadata_keys`.
|
|
114
|
+
|
|
115
|
+
Only metadata and the assignee (`approver`) can be written -- status and summary
|
|
116
|
+
belong to the agent working the task. A trigger tool can also set both from its
|
|
117
|
+
result: see the `metadata` and `approver` fields of a task item in the trigger
|
|
118
|
+
contract.
|
|
119
|
+
|
|
91
120
|
Import the version you are writing against, bound to a short name as above.
|
|
92
121
|
A version does not change under you: when the API changes it appears as a new
|
|
93
122
|
version, and the one you imported keeps behaving as it did. Importing
|
|
@@ -101,6 +130,14 @@ version, and the one you imported keeps behaving as it did. Importing
|
|
|
101
130
|
name (`task["status"]`, `task["metadata"]`, `task.get("summary")`, or
|
|
102
131
|
`task.data` for the whole dict), so a task gaining a field needs no SDK
|
|
103
132
|
release.
|
|
133
|
+
- `update_task_metadata(ref, metadata=None, *, approver=UNSET, wake=True, client=None)` --
|
|
134
|
+
merges `metadata` into the task and/or sets its assignee, and returns the
|
|
135
|
+
updated `Task`. Safe to repeat (setting what the task already holds is a
|
|
136
|
+
no-op, and wakes nothing). A metadata change wakes the task's agent unless
|
|
137
|
+
`wake=False`; an assignee-only change wakes nothing; a finished task is never reopened (`task.woken` and
|
|
138
|
+
`task.not_woken_reason` report what happened). Raises `TaskError` if there is no such task (`status_code` 404 --
|
|
139
|
+
unlike `get_task`, a write to nothing has not happened), and `ValueError` if
|
|
140
|
+
there is nothing to update. `update_task_metadata_async` is the async form.
|
|
104
141
|
- Raises `TaskError` if the lookup failed -- including on a persistent 429/5xx
|
|
105
142
|
after retrying with backoff. A task that does not exist is not a failure;
|
|
106
143
|
it comes back as `None`.
|
|
@@ -109,9 +146,9 @@ version, and the one you imported keeps behaving as it did. Importing
|
|
|
109
146
|
ambient environment the first time it's needed -- pass your own to point it
|
|
110
147
|
elsewhere or to share it explicitly with other `riffsdk.tasks`/`riffsdk.ai`
|
|
111
148
|
calls.
|
|
112
|
-
- The board
|
|
113
|
-
the same app in the workspace sees the workspace's. There is
|
|
114
|
-
configure for that, and no way to
|
|
149
|
+
- The board is the app's own, for reads and writes: a deployed app sees its
|
|
150
|
+
production tasks, the same app in the workspace sees the workspace's. There is
|
|
151
|
+
nothing to configure for that, and no way to reach the other one.
|
|
115
152
|
- Runs from an app's backend, where the environment it needs is already set.
|
|
116
153
|
|
|
117
154
|
## AI
|
|
@@ -74,6 +74,35 @@ work left on them and nothing about the ones already finished, so it cannot
|
|
|
74
74
|
tell an item it has never seen from one whose task is done — and proposes the
|
|
75
75
|
same finished work every time it fires. `get_task` closes that gap.
|
|
76
76
|
|
|
77
|
+
To record what a trigger learned about a task, merge metadata into it and/or
|
|
78
|
+
set its assignee. A metadata change wakes the task's agent so it sees it
|
|
79
|
+
(`task.woken`); changing only the assignee does not. Pass `wake=False` for a
|
|
80
|
+
write it need not react to:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
task = tasks.update_task_metadata(
|
|
84
|
+
"TASK-42",
|
|
85
|
+
{"chase_count": 2, "stale_since": None}, # merged; None clears a key
|
|
86
|
+
approver="buyer@example.com", # user id or email; None unassigns; omit to leave alone
|
|
87
|
+
)
|
|
88
|
+
print(task["metadata"], task["approver"])
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Keys that are not configured fields are always accepted and saved as they are.
|
|
92
|
+
A value for a *configured* field is checked against its type (a number field
|
|
93
|
+
takes a number, a select one of its options, a date an ISO 8601 string); one that
|
|
94
|
+
fails is not written, but the call does not fail -- the rest lands, and the
|
|
95
|
+
held-back keys come back on `task.rejected_metadata` (key -> why) and are logged
|
|
96
|
+
as a warning. Only configured fields are **shown** on the board, as list/board
|
|
97
|
+
columns and in the task's key information. A builder adds one in *Configure
|
|
98
|
+
fields* (Show in list / Show in summary), and the keys you wrote that are not
|
|
99
|
+
configured come back on `task.unconfigured_metadata_keys`.
|
|
100
|
+
|
|
101
|
+
Only metadata and the assignee (`approver`) can be written -- status and summary
|
|
102
|
+
belong to the agent working the task. A trigger tool can also set both from its
|
|
103
|
+
result: see the `metadata` and `approver` fields of a task item in the trigger
|
|
104
|
+
contract.
|
|
105
|
+
|
|
77
106
|
Import the version you are writing against, bound to a short name as above.
|
|
78
107
|
A version does not change under you: when the API changes it appears as a new
|
|
79
108
|
version, and the one you imported keeps behaving as it did. Importing
|
|
@@ -87,6 +116,14 @@ version, and the one you imported keeps behaving as it did. Importing
|
|
|
87
116
|
name (`task["status"]`, `task["metadata"]`, `task.get("summary")`, or
|
|
88
117
|
`task.data` for the whole dict), so a task gaining a field needs no SDK
|
|
89
118
|
release.
|
|
119
|
+
- `update_task_metadata(ref, metadata=None, *, approver=UNSET, wake=True, client=None)` --
|
|
120
|
+
merges `metadata` into the task and/or sets its assignee, and returns the
|
|
121
|
+
updated `Task`. Safe to repeat (setting what the task already holds is a
|
|
122
|
+
no-op, and wakes nothing). A metadata change wakes the task's agent unless
|
|
123
|
+
`wake=False`; an assignee-only change wakes nothing; a finished task is never reopened (`task.woken` and
|
|
124
|
+
`task.not_woken_reason` report what happened). Raises `TaskError` if there is no such task (`status_code` 404 --
|
|
125
|
+
unlike `get_task`, a write to nothing has not happened), and `ValueError` if
|
|
126
|
+
there is nothing to update. `update_task_metadata_async` is the async form.
|
|
90
127
|
- Raises `TaskError` if the lookup failed -- including on a persistent 429/5xx
|
|
91
128
|
after retrying with backoff. A task that does not exist is not a failure;
|
|
92
129
|
it comes back as `None`.
|
|
@@ -95,9 +132,9 @@ version, and the one you imported keeps behaving as it did. Importing
|
|
|
95
132
|
ambient environment the first time it's needed -- pass your own to point it
|
|
96
133
|
elsewhere or to share it explicitly with other `riffsdk.tasks`/`riffsdk.ai`
|
|
97
134
|
calls.
|
|
98
|
-
- The board
|
|
99
|
-
the same app in the workspace sees the workspace's. There is
|
|
100
|
-
configure for that, and no way to
|
|
135
|
+
- The board is the app's own, for reads and writes: a deployed app sees its
|
|
136
|
+
production tasks, the same app in the workspace sees the workspace's. There is
|
|
137
|
+
nothing to configure for that, and no way to reach the other one.
|
|
101
138
|
- Runs from an app's backend, where the environment it needs is already set.
|
|
102
139
|
|
|
103
140
|
## AI
|
|
@@ -26,3 +26,7 @@ run = "uv run ruff check --fix src tests"
|
|
|
26
26
|
description = "Run integration tests against a local riff stack's front proxy"
|
|
27
27
|
env = { API_RIFF_NEW_URL = "http://localhost:8080", RIFF_INTEGRATION_TEST = "true" }
|
|
28
28
|
run = "uv run pytest tests/test_integration.py -v"
|
|
29
|
+
|
|
30
|
+
[tasks.upgrade]
|
|
31
|
+
description = "Refresh uv.lock to the newest versions within the declared ranges"
|
|
32
|
+
run = ["uv lock --upgrade", "uv sync"]
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
"""Read the app's task board.
|
|
1
|
+
"""Read the app's task board, and record metadata and the assignee on its tasks.
|
|
2
2
|
|
|
3
3
|
Import the version you are writing against, bound to a short name::
|
|
4
4
|
|
|
5
5
|
import riffsdk.tasks.v0 as tasks
|
|
6
6
|
|
|
7
7
|
task = tasks.get_task("TASK-42")
|
|
8
|
+
tasks.update_task_metadata("TASK-42", {"checked": True})
|
|
8
9
|
|
|
9
10
|
A version does not change under you. When the API changes it appears as a new
|
|
10
11
|
version, and the one you imported keeps behaving as it did.
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"""Read one task off the app's task board.
|
|
2
|
+
|
|
3
|
+
A trigger tool is handed the tasks that still have work left on them, and
|
|
4
|
+
nothing about the ones already finished — so it cannot tell an item it has
|
|
5
|
+
never seen from one whose task is done, and ends up proposing the same
|
|
6
|
+
finished work every time it fires. Looking the task up directly closes that:
|
|
7
|
+
it finds the task whatever state it is in, completed ones included.
|
|
8
|
+
|
|
9
|
+
import riffsdk.tasks.v0 as tasks
|
|
10
|
+
|
|
11
|
+
task = tasks.get_task("TASK-42")
|
|
12
|
+
if task is None:
|
|
13
|
+
... # nothing on the board for this item
|
|
14
|
+
elif task["status"] == "completed":
|
|
15
|
+
... # already handled — leave it alone
|
|
16
|
+
|
|
17
|
+
The task arrives as JSON, with a ``version`` alongside it. Read fields by name
|
|
18
|
+
(``task["status"]``, ``task["metadata"]``) rather than expecting a fixed set,
|
|
19
|
+
so that a task gaining a field does not need a new SDK release.
|
|
20
|
+
|
|
21
|
+
A trigger tool can also record what it learned about a task: merge metadata
|
|
22
|
+
into it and/or assign it to someone. A metadata change wakes the task's agent so
|
|
23
|
+
it sees it (reassigning alone does not); pass ``wake=False`` for a write it need
|
|
24
|
+
not react to:
|
|
25
|
+
|
|
26
|
+
task = tasks.update_task_metadata(
|
|
27
|
+
"TASK-42",
|
|
28
|
+
{"chase_count": 2, "last_chased_at": "2026-09-12"},
|
|
29
|
+
approver="buyer@example.com",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
Only metadata and the assignee (``approver``) can be written this way — a
|
|
33
|
+
task's status and summary belong to the agent working it.
|
|
34
|
+
|
|
35
|
+
The board is the app's own, for reads and writes alike: a deployed app sees its
|
|
36
|
+
production tasks, and the same app in the workspace sees the workspace's. There
|
|
37
|
+
is nothing to configure for that, and no way to reach the other one.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
from __future__ import annotations
|
|
41
|
+
|
|
42
|
+
import logging
|
|
43
|
+
from dataclasses import dataclass, field
|
|
44
|
+
from typing import Any
|
|
45
|
+
from urllib.parse import quote
|
|
46
|
+
|
|
47
|
+
import httpx
|
|
48
|
+
|
|
49
|
+
from riffsdk._internal.config import sdk_domain_path
|
|
50
|
+
from riffsdk._internal.transport import RetryableTransportError
|
|
51
|
+
from riffsdk.client import AsyncRiffClient, RiffClient
|
|
52
|
+
|
|
53
|
+
__all__ = [
|
|
54
|
+
"Task",
|
|
55
|
+
"TaskError",
|
|
56
|
+
"get_task",
|
|
57
|
+
"get_task_async",
|
|
58
|
+
"update_task_metadata",
|
|
59
|
+
"update_task_metadata_async",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
_DEFAULT_TIMEOUT = 10.0
|
|
63
|
+
_log = logging.getLogger(__name__)
|
|
64
|
+
_DOMAIN = "tasks"
|
|
65
|
+
_URL_VERSION = "v0"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class TaskError(Exception):
|
|
69
|
+
"""A task lookup or update that did not come back as an answer.
|
|
70
|
+
|
|
71
|
+
A task that simply does not exist is not an error for :func:`get_task`,
|
|
72
|
+
which returns ``None`` for it. It is one for :func:`update_task_metadata`:
|
|
73
|
+
a write to nothing has not happened. ``status_code`` is 404 then.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
def __init__(self, message: str, *, status_code: int | None = None) -> None:
|
|
77
|
+
super().__init__(message)
|
|
78
|
+
self.message = message
|
|
79
|
+
self.status_code = status_code
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True)
|
|
83
|
+
class Task:
|
|
84
|
+
"""One task: the task itself as JSON, and the ``version`` of that shape.
|
|
85
|
+
|
|
86
|
+
Read fields by name — ``task["status"]``, ``task["metadata"]``,
|
|
87
|
+
``task.get("summary")``, or ``task.data`` for the whole dict. ``version``
|
|
88
|
+
changes only if the shape changes in a way that breaks code written
|
|
89
|
+
against the old one, so code reading the fields it knows can ignore it.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
version: int
|
|
93
|
+
data: dict[str, Any]
|
|
94
|
+
# Only set on the task :func:`update_task_metadata` returns: the metadata
|
|
95
|
+
# keys that call wrote which are not configured fields. They are saved, but
|
|
96
|
+
# the board shows only configured fields as list columns and in the task's
|
|
97
|
+
# key information.
|
|
98
|
+
unconfigured_metadata_keys: list[str] = field(default_factory=list)
|
|
99
|
+
# Only set on the task :func:`update_task_metadata` returns: metadata keys
|
|
100
|
+
# that were NOT written because the value broke its configured field's type,
|
|
101
|
+
# mapped to why. Everything else in the call was written.
|
|
102
|
+
rejected_metadata: dict[str, str] = field(default_factory=dict)
|
|
103
|
+
# Only set on the task :func:`update_task_metadata` returns: whether the
|
|
104
|
+
# call woke the task's agent, and when a change could not wake it, why.
|
|
105
|
+
woken: bool = False
|
|
106
|
+
not_woken_reason: str | None = None
|
|
107
|
+
|
|
108
|
+
def __getitem__(self, key: str) -> Any:
|
|
109
|
+
return self.data[key]
|
|
110
|
+
|
|
111
|
+
def get(self, key: str, default: Any = None) -> Any:
|
|
112
|
+
return self.data.get(key, default)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _to_task(response: httpx.Response) -> Task | None:
|
|
116
|
+
if response.status_code == 404:
|
|
117
|
+
return None
|
|
118
|
+
if not response.is_success:
|
|
119
|
+
raise TaskError(
|
|
120
|
+
f"HTTP {response.status_code}: {response.text[:200]}",
|
|
121
|
+
status_code=response.status_code,
|
|
122
|
+
)
|
|
123
|
+
try:
|
|
124
|
+
body = response.json()
|
|
125
|
+
return Task(version=int(body["version"]), data=body["task"])
|
|
126
|
+
except Exception as e:
|
|
127
|
+
raise TaskError(f"Unexpected task response: {response.text[:200]}") from e
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def get_task(
|
|
131
|
+
ref: str,
|
|
132
|
+
*,
|
|
133
|
+
client: RiffClient | None = None,
|
|
134
|
+
) -> Task | None:
|
|
135
|
+
"""Return the task with display ID or UUID ``ref``, or ``None`` if there is none.
|
|
136
|
+
|
|
137
|
+
Finds the task whatever state it is in, completed ones included.
|
|
138
|
+
|
|
139
|
+
``ref`` is the task's display ID as it appears on the board — an exact
|
|
140
|
+
match, e.g. ``"TASK-42"`` — or its id.
|
|
141
|
+
|
|
142
|
+
Raises :class:`TaskError` if the lookup failed. A task that does not exist
|
|
143
|
+
is not a failure; it comes back as ``None``.
|
|
144
|
+
|
|
145
|
+
``client`` lets repeated calls share one connection; it defaults to
|
|
146
|
+
:meth:`riffsdk.client.RiffClient.default`, a shared instance built from
|
|
147
|
+
the ambient environment.
|
|
148
|
+
"""
|
|
149
|
+
if not ref:
|
|
150
|
+
raise ValueError("ref must be a non-empty display ID or task UUID")
|
|
151
|
+
client = client or RiffClient.default()
|
|
152
|
+
try:
|
|
153
|
+
resp = client.request(
|
|
154
|
+
"GET",
|
|
155
|
+
sdk_domain_path(_DOMAIN, _URL_VERSION, quote(ref, safe="")),
|
|
156
|
+
timeout=_DEFAULT_TIMEOUT,
|
|
157
|
+
)
|
|
158
|
+
except RetryableTransportError as e:
|
|
159
|
+
raise TaskError(str(e), status_code=e.status_code) from e
|
|
160
|
+
return _to_task(resp)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
async def get_task_async(
|
|
164
|
+
ref: str,
|
|
165
|
+
*,
|
|
166
|
+
client: AsyncRiffClient | None = None,
|
|
167
|
+
) -> Task | None:
|
|
168
|
+
"""Async form of :func:`get_task`."""
|
|
169
|
+
if not ref:
|
|
170
|
+
raise ValueError("ref must be a non-empty display ID or task UUID")
|
|
171
|
+
client = client or AsyncRiffClient.default()
|
|
172
|
+
try:
|
|
173
|
+
resp = await client.request(
|
|
174
|
+
"GET",
|
|
175
|
+
sdk_domain_path(_DOMAIN, _URL_VERSION, quote(ref, safe="")),
|
|
176
|
+
timeout=_DEFAULT_TIMEOUT,
|
|
177
|
+
)
|
|
178
|
+
except RetryableTransportError as e:
|
|
179
|
+
raise TaskError(str(e), status_code=e.status_code) from e
|
|
180
|
+
return _to_task(resp)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
class _Unset:
|
|
184
|
+
"""Marks an argument as not given, so ``None`` can mean something."""
|
|
185
|
+
|
|
186
|
+
def __repr__(self) -> str:
|
|
187
|
+
return "UNSET"
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
UNSET: Any = _Unset()
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _update_request(
|
|
194
|
+
ref: str,
|
|
195
|
+
metadata: dict[str, Any] | None,
|
|
196
|
+
approver: str | None | _Unset,
|
|
197
|
+
wake: bool,
|
|
198
|
+
) -> tuple[str, dict[str, Any]]:
|
|
199
|
+
"""The path and body of an update, or ``ValueError`` if it asks for nothing."""
|
|
200
|
+
if not ref:
|
|
201
|
+
raise ValueError("ref must be a non-empty display ID or task UUID")
|
|
202
|
+
body: dict[str, Any] = {}
|
|
203
|
+
if metadata:
|
|
204
|
+
for key in metadata:
|
|
205
|
+
if not isinstance(key, str) or not key.strip():
|
|
206
|
+
raise ValueError("metadata keys must be non-empty strings")
|
|
207
|
+
body["metadata"] = metadata
|
|
208
|
+
if not isinstance(approver, _Unset):
|
|
209
|
+
body["approver"] = approver
|
|
210
|
+
if not body:
|
|
211
|
+
raise ValueError("nothing to update: pass metadata and/or approver")
|
|
212
|
+
if not wake:
|
|
213
|
+
body["wake"] = False
|
|
214
|
+
path = sdk_domain_path(_DOMAIN, _URL_VERSION, f"{quote(ref, safe='')}/metadata")
|
|
215
|
+
return path, body
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _to_updated_task(response: httpx.Response) -> Task:
|
|
219
|
+
if not response.is_success:
|
|
220
|
+
try:
|
|
221
|
+
detail = response.json()["error"]
|
|
222
|
+
except Exception:
|
|
223
|
+
detail = response.text[:200]
|
|
224
|
+
raise TaskError(
|
|
225
|
+
f"HTTP {response.status_code}: {detail}",
|
|
226
|
+
status_code=response.status_code,
|
|
227
|
+
)
|
|
228
|
+
task = _to_task(response)
|
|
229
|
+
if task is None:
|
|
230
|
+
raise TaskError(f"Unexpected task response: {response.text[:200]}")
|
|
231
|
+
try:
|
|
232
|
+
extras = response.json()
|
|
233
|
+
unconfigured = list(extras.get("unconfigured_metadata_keys") or [])
|
|
234
|
+
rejected = dict(extras.get("rejected_metadata") or {})
|
|
235
|
+
woken = bool(extras.get("woken", False))
|
|
236
|
+
not_woken_reason = extras.get("not_woken_reason")
|
|
237
|
+
except Exception:
|
|
238
|
+
unconfigured, rejected, woken, not_woken_reason = [], {}, False, None
|
|
239
|
+
if rejected:
|
|
240
|
+
# The call succeeded, so nothing raises; but a caller that never looks at
|
|
241
|
+
# the result would lose these silently.
|
|
242
|
+
_log.warning(
|
|
243
|
+
"update_task_metadata: not written for %s: %s",
|
|
244
|
+
task.data.get("display_id", "task"),
|
|
245
|
+
"; ".join(rejected.values()),
|
|
246
|
+
)
|
|
247
|
+
return Task(
|
|
248
|
+
version=task.version,
|
|
249
|
+
data=task.data,
|
|
250
|
+
unconfigured_metadata_keys=unconfigured,
|
|
251
|
+
rejected_metadata=rejected,
|
|
252
|
+
woken=woken,
|
|
253
|
+
not_woken_reason=not_woken_reason,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def update_task_metadata(
|
|
258
|
+
ref: str,
|
|
259
|
+
metadata: dict[str, Any] | None = None,
|
|
260
|
+
*,
|
|
261
|
+
approver: str | None | _Unset = UNSET,
|
|
262
|
+
wake: bool = True,
|
|
263
|
+
client: RiffClient | None = None,
|
|
264
|
+
) -> Task:
|
|
265
|
+
"""Merge ``metadata`` into a task and/or set its assignee; return the task.
|
|
266
|
+
|
|
267
|
+
``ref`` is the task's display ID as it appears on the board, e.g.
|
|
268
|
+
``"TASK-42"``, or its id.
|
|
269
|
+
|
|
270
|
+
``metadata`` is merged into what the task already holds: keys you leave out
|
|
271
|
+
keep their values, and a ``None`` value clears that key. Leaving it out
|
|
272
|
+
leaves the metadata alone.
|
|
273
|
+
|
|
274
|
+
``approver`` is the task's assignee — a user id or an email. Leave it out to
|
|
275
|
+
leave the assignee alone; pass ``None`` to unassign.
|
|
276
|
+
|
|
277
|
+
``metadata`` values for a *configured* field are checked against its type (a
|
|
278
|
+
number field takes a number, a select one of its options, a date an ISO 8601
|
|
279
|
+
string). A value that fails is not written, and the call does not fail: the
|
|
280
|
+
rest still lands, and the held-back keys come back on the returned task's
|
|
281
|
+
``rejected_metadata`` (key -> why) and are logged as a warning. Keys that are
|
|
282
|
+
not configured fields are always accepted and saved as they are, but the
|
|
283
|
+
board does not show them: only configured fields appear as list/board columns
|
|
284
|
+
and in the task's key information. A builder adds a field in *Configure
|
|
285
|
+
fields* (Show in list / Show in summary). The keys you wrote that are not
|
|
286
|
+
configured are on ``unconfigured_metadata_keys``.
|
|
287
|
+
|
|
288
|
+
Only metadata and the assignee can be written here; nothing else about the
|
|
289
|
+
task changes. Setting a value a task already holds is a no-op, so the call
|
|
290
|
+
is safe to repeat.
|
|
291
|
+
|
|
292
|
+
If the call changes the task's metadata, its agent is woken so it sees the
|
|
293
|
+
change (``task.woken``). Changing only the assignee wakes nothing: it changes
|
|
294
|
+
who is asked about the task, not what the agent knows. Pass ``wake=False``
|
|
295
|
+
for a write the agent need not react to, such as bookkeeping. A change never
|
|
296
|
+
reopens a finished task: with no live session nothing is woken, and
|
|
297
|
+
``task.not_woken_reason`` says why. A call that changes nothing wakes
|
|
298
|
+
nothing.
|
|
299
|
+
|
|
300
|
+
Raises :class:`TaskError` if the update did not happen — including when no
|
|
301
|
+
such task exists (``status_code`` 404), unlike :func:`get_task`, which
|
|
302
|
+
returns ``None`` for that. Raises ``ValueError`` if there is nothing to
|
|
303
|
+
update.
|
|
304
|
+
|
|
305
|
+
``client`` lets repeated calls share one connection; it defaults to
|
|
306
|
+
:meth:`riffsdk.client.RiffClient.default`.
|
|
307
|
+
"""
|
|
308
|
+
path, body = _update_request(ref, metadata, approver, wake)
|
|
309
|
+
client = client or RiffClient.default()
|
|
310
|
+
try:
|
|
311
|
+
resp = client.request("POST", path, json=body, timeout=_DEFAULT_TIMEOUT)
|
|
312
|
+
except RetryableTransportError as e:
|
|
313
|
+
raise TaskError(str(e), status_code=e.status_code) from e
|
|
314
|
+
return _to_updated_task(resp)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
async def update_task_metadata_async(
|
|
318
|
+
ref: str,
|
|
319
|
+
metadata: dict[str, Any] | None = None,
|
|
320
|
+
*,
|
|
321
|
+
approver: str | None | _Unset = UNSET,
|
|
322
|
+
wake: bool = True,
|
|
323
|
+
client: AsyncRiffClient | None = None,
|
|
324
|
+
) -> Task:
|
|
325
|
+
"""Async form of :func:`update_task_metadata`."""
|
|
326
|
+
path, body = _update_request(ref, metadata, approver, wake)
|
|
327
|
+
client = client or AsyncRiffClient.default()
|
|
328
|
+
try:
|
|
329
|
+
resp = await client.request("POST", path, json=body, timeout=_DEFAULT_TIMEOUT)
|
|
330
|
+
except RetryableTransportError as e:
|
|
331
|
+
raise TaskError(str(e), status_code=e.status_code) from e
|
|
332
|
+
return _to_updated_task(resp)
|