riffsdk 0.26.0__tar.gz → 0.28.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.
Files changed (77) hide show
  1. {riffsdk-0.26.0 → riffsdk-0.28.0}/AGENTS.md +3 -0
  2. {riffsdk-0.26.0 → riffsdk-0.28.0}/CHANGELOG.md +33 -0
  3. {riffsdk-0.26.0 → riffsdk-0.28.0}/LOCAL-TESTING.md +9 -2
  4. {riffsdk-0.26.0 → riffsdk-0.28.0}/PKG-INFO +152 -1
  5. {riffsdk-0.26.0 → riffsdk-0.28.0}/README.md +151 -0
  6. riffsdk-0.28.0/examples/query_metrics.py +72 -0
  7. {riffsdk-0.26.0 → riffsdk-0.28.0}/new-sdk-url-schema.md +1 -0
  8. {riffsdk-0.26.0 → riffsdk-0.28.0}/pyproject.toml +1 -1
  9. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/_internal/transport.py +2 -2
  10. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/client.py +2 -2
  11. riffsdk-0.28.0/src/riffsdk/metrics/__init__.py +16 -0
  12. riffsdk-0.28.0/src/riffsdk/metrics/v0.py +681 -0
  13. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_imports.py +63 -1
  14. riffsdk-0.28.0/tests/test_metrics_v0.py +923 -0
  15. {riffsdk-0.26.0 → riffsdk-0.28.0}/.github/workflows/ci.yml +0 -0
  16. {riffsdk-0.26.0 → riffsdk-0.28.0}/.github/workflows/pr-comment.yml +0 -0
  17. {riffsdk-0.26.0 → riffsdk-0.28.0}/.github/workflows/release.yml +0 -0
  18. {riffsdk-0.26.0 → riffsdk-0.28.0}/.gitignore +0 -0
  19. {riffsdk-0.26.0 → riffsdk-0.28.0}/.python-version +0 -0
  20. {riffsdk-0.26.0 → riffsdk-0.28.0}/CLAUDE.md +0 -0
  21. {riffsdk-0.26.0 → riffsdk-0.28.0}/LICENCE +0 -0
  22. {riffsdk-0.26.0 → riffsdk-0.28.0}/USAGE_PROMPT.md +0 -0
  23. {riffsdk-0.26.0 → riffsdk-0.28.0}/examples/async_client.py +0 -0
  24. {riffsdk-0.26.0 → riffsdk-0.28.0}/examples/basic_crud.py +0 -0
  25. {riffsdk-0.26.0 → riffsdk-0.28.0}/examples/email_notice.py +0 -0
  26. {riffsdk-0.26.0 → riffsdk-0.28.0}/examples/file_upload_download.py +0 -0
  27. {riffsdk-0.26.0 → riffsdk-0.28.0}/examples/get_task.py +0 -0
  28. {riffsdk-0.26.0 → riffsdk-0.28.0}/examples/interpret_document.py +0 -0
  29. {riffsdk-0.26.0 → riffsdk-0.28.0}/examples/optimistic_concurrency.py +0 -0
  30. {riffsdk-0.26.0 → riffsdk-0.28.0}/mise.toml +0 -0
  31. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/__init__.py +0 -0
  32. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/__main__.py +0 -0
  33. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/_cli.py +0 -0
  34. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/_internal/__init__.py +0 -0
  35. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/_internal/auth.py +0 -0
  36. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/_internal/config.py +0 -0
  37. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/ai/__init__.py +0 -0
  38. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/ai/v0.py +0 -0
  39. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/context.py +0 -0
  40. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/email/__init__.py +0 -0
  41. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/email/v0.py +0 -0
  42. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/__init__.py +0 -0
  43. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_async_client.py +0 -0
  44. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_client.py +0 -0
  45. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_common.py +0 -0
  46. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_http.py +0 -0
  47. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_mime.py +0 -0
  48. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_models.py +0 -0
  49. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_session.py +0 -0
  50. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_streaming.py +0 -0
  51. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/_upload.py +0 -0
  52. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/exceptions.py +0 -0
  53. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/storage/py.typed +0 -0
  54. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/tasks/__init__.py +0 -0
  55. {riffsdk-0.26.0 → riffsdk-0.28.0}/src/riffsdk/tasks/v0.py +0 -0
  56. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/__init__.py +0 -0
  57. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/conftest.py +0 -0
  58. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_ai_v0.py +0 -0
  59. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_async_client.py +0 -0
  60. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_auth.py +0 -0
  61. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_cli.py +0 -0
  62. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_client.py +0 -0
  63. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_config.py +0 -0
  64. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_context.py +0 -0
  65. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_email_v0.py +0 -0
  66. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_exceptions.py +0 -0
  67. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_http.py +0 -0
  68. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_importance.py +0 -0
  69. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_integration.py +0 -0
  70. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_mime.py +0 -0
  71. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_models.py +0 -0
  72. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_session.py +0 -0
  73. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_single_put_upload.py +0 -0
  74. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_streaming.py +0 -0
  75. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_tasks_v0.py +0 -0
  76. {riffsdk-0.26.0 → riffsdk-0.28.0}/tests/test_upload.py +0 -0
  77. {riffsdk-0.26.0 → riffsdk-0.28.0}/uv.lock +0 -0
@@ -64,6 +64,9 @@ src/riffsdk/
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)
67
+ metrics/
68
+ __init__.py # Docstring only - importing it loads no version
69
+ v0.py # query, get_schema, measure/filter helpers - Insights-style metrics about the app's own agent
67
70
  _internal/
68
71
  auth.py # RiffAuth - authentication
69
72
  config.py # Configuration handling
@@ -2,6 +2,39 @@
2
2
 
3
3
  <!-- version list -->
4
4
 
5
+ ## v0.28.0 (2026-12-02)
6
+
7
+ ### Features
8
+
9
+ - **metrics**: Accept an optional project selector on query and get_schema
10
+ ([`53219e3`](https://github.com/databutton/riff-sdk-python/commit/53219e3d3eae11727913b7a0269f53455126e821))
11
+
12
+
13
+ ## v0.27.0 (2026-12-01)
14
+
15
+ ### Bug Fixes
16
+
17
+ - **metrics**: Retry a 429 several times, apart from the failure attempts
18
+ ([#57](https://github.com/databutton/riff-sdk-python/pull/57),
19
+ [`47cd41e`](https://github.com/databutton/riff-sdk-python/commit/47cd41e9932864e47dd084a0b443277c74f47424))
20
+
21
+ - **metrics**: Two attempts per query, document 422/429 and the shared schema lists
22
+ ([#57](https://github.com/databutton/riff-sdk-python/pull/57),
23
+ [`47cd41e`](https://github.com/databutton/riff-sdk-python/commit/47cd41e9932864e47dd084a0b443277c74f47424))
24
+
25
+ ### Documentation
26
+
27
+ - **metrics**: Examples break down by task metadata, not tool input
28
+ ([#57](https://github.com/databutton/riff-sdk-python/pull/57),
29
+ [`47cd41e`](https://github.com/databutton/riff-sdk-python/commit/47cd41e9932864e47dd084a0b443277c74f47424))
30
+
31
+ ### Features
32
+
33
+ - **metrics**: Add riffsdk.metrics.v0, Insights-style queries over the app's own agent
34
+ ([#57](https://github.com/databutton/riff-sdk-python/pull/57),
35
+ [`47cd41e`](https://github.com/databutton/riff-sdk-python/commit/47cd41e9932864e47dd084a0b443277c74f47424))
36
+
37
+
5
38
  ## v0.26.0 (2026-11-17)
6
39
 
7
40
  ### Chores
@@ -60,5 +60,12 @@ Not applicable — riffsdk doesn't join the orchestrated stack as a service.
60
60
 
61
61
  ## Known limitations / degraded modes
62
62
 
63
- Integration tests only exercise the `storage` domain today. `tasks`/`ai` have no
64
- integration coverage yet — their tests all mock the transport.
63
+ Integration tests only exercise the `storage` domain today. `tasks`/`ai`/`metrics`
64
+ have no integration coverage yet — their tests all mock the transport.
65
+
66
+ To try `riffsdk.metrics.v0` by hand against a local stack, point
67
+ `API_RIFF_NEW_URL` at the front proxy and run `examples/query_metrics.py` from a
68
+ project whose id is in `RIFF_PROJECT_ID`. The orchestrator answers only the
69
+ devx and prodx appbutler roles (it takes the project and the environment from
70
+ them), so a person's or an API key's token gets a 400 from `/query` and
71
+ `/schema`, by design.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: riffsdk
3
- Version: 0.26.0
3
+ Version: 0.28.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>
@@ -197,6 +197,157 @@ version, and the one you imported keeps behaving as it did. Importing
197
197
  the client's own default: this proxies to an LLM call through
198
198
  riff-orchestrator, whose own timeout defaults to 120s.
199
199
 
200
+ ## Metrics
201
+
202
+ Ask for numbers about the app's own agent -- its tasks, the decisions it asked
203
+ people for, the tool calls it made and the hooks that fired -- with a query,
204
+ instead of a new endpoint per number. The query has the shape of an analytics
205
+ "insights" query: an event, how to measure it, filters, a breakdown, and a time
206
+ range bucketed by a unit.
207
+
208
+ ```python
209
+ import riffsdk.metrics.v0 as metrics
210
+
211
+ result = metrics.query(
212
+ event="decision_resolved",
213
+ measure=metrics.median("wait_seconds"), # default: metrics.count()
214
+ filters=[metrics.where("type", "eq", "approval")],
215
+ breakdown="task.metadata.supplier", # up to two properties
216
+ last_days=30, # or from_=/to= (datetime or ISO 8601)
217
+ unit="week", # hour | day | week | month | total
218
+ )
219
+ for row in result.rows("a"): # a single series is called "a"
220
+ print(row["bucket"], row["breakdown"], row["value"])
221
+ ```
222
+
223
+ Call `metrics.get_schema()` first to see the events, their properties and
224
+ types, the measures, filter operators and units (one list shared by all events),
225
+ the limits, and the project's task metadata keys, rather than guessing names.
226
+
227
+ Several series (one to four) can be read side by side or combined with a
228
+ `formula` of numbers, series ids and `+ - * / ( )`, evaluated per bucket and
229
+ breakdown row. The result then has one more series, `"formula"`, whose `value`
230
+ is `None` where it divided by zero:
231
+
232
+ ```python
233
+ result = metrics.query(
234
+ series=[
235
+ {"id": "a", "event": "decision_requested", "measure": "count",
236
+ "filters": [metrics.where("type", "eq", "escalation")]},
237
+ {"id": "b", "event": "task_created", "measure": "count"},
238
+ ],
239
+ formula="a / b",
240
+ last_days=30,
241
+ unit="total",
242
+ )
243
+ escalation_rate = result.rows("formula")[0]["value"]
244
+ ```
245
+
246
+ A view's backend is the usual caller. In `backend/app/views/<name>.py`, combine
247
+ the agent's numbers with the app's own data:
248
+
249
+ ```python
250
+ import riffsdk.metrics.v0 as metrics
251
+
252
+ def handler(params):
253
+ sent = metrics.query(
254
+ event="tool_called",
255
+ filters=[
256
+ metrics.where("tool_name", "eq", "send_chase"),
257
+ metrics.where("output.status", "eq", "sent"),
258
+ ],
259
+ last_days=90,
260
+ unit="week",
261
+ )
262
+ weekly = [{"week": r["bucket"], "sent": r["value"]} for r in sent.rows("a")]
263
+ return {"weekly_chases": weekly, "open_lines": load_open_lines()} # your own ERP data
264
+ ```
265
+
266
+ `input.<key>` and `output.<key>` of a tool call can be used in filters and
267
+ measures but not in `breakdown`; split by a task metadata key
268
+ (`task.metadata.<key>`) instead.
269
+
270
+ This is for what the orchestrator knows. ERP and other app data stay in the
271
+ app, and raw rows (a list of tasks or tool calls) are not metrics.
272
+
273
+ By default a project reads only its own metrics. The account and the
274
+ environment are decided by the credentials the request is made with: a
275
+ deployed app sees its production data, the same app in the workspace sees the
276
+ workspace's. Nothing in a query names them.
277
+
278
+ ### Reading other projects (dashboards)
279
+
280
+ A *dashboard* project can read the metrics of other projects with the optional
281
+ `project=` argument on `query`, `query_async`, `get_schema` and
282
+ `get_schema_async`: one project id, or a list of up to ten.
283
+
284
+ ```python
285
+ result = metrics.query(
286
+ event="task_created",
287
+ last_days=30,
288
+ unit="week",
289
+ breakdown="project_id", # tell the projects apart
290
+ project=["proj-a", "proj-b"], # or project="proj-a"
291
+ )
292
+ schema = metrics.get_schema(project="proj-a") # sent as ?project=proj-a
293
+ ```
294
+
295
+ - Only dashboard projects may pass it. From any other kind of project it is
296
+ refused.
297
+ - Only projects of the caller's own account (or the caller itself) can be named.
298
+ - The environment is always the caller's: a workspace dashboard reads workspace
299
+ data and a deployed one production data. There is no `mode` to pass.
300
+ - A refusal (not a dashboard, another account, an unknown project, too many
301
+ targets) raises the usual `MetricsError` with a 4xx `status_code`; the
302
+ message does not say which rule applied.
303
+ - A list is sent as a list and a string as a string; `get_schema` sends a list
304
+ as repeated `?project=` parameters. More than ten ids, an empty list or an
305
+ empty id raises `ValueError` before anything is sent.
306
+ - Leaving `project` out gives exactly the behaviour above: the caller's own
307
+ metrics, and nothing extra on the wire.
308
+
309
+ Import the version you are writing against, bound to a short name as above. A
310
+ version does not change under you: when the API changes it appears as a new
311
+ version, and the one you imported keeps behaving as it did. Importing `riffsdk`
312
+ or `riffsdk.metrics` loads no version.
313
+
314
+ ### API
315
+
316
+ - `query(*, series=None, event=None, measure=None, filters=None, from_=None,
317
+ to=None, last_days=None, unit=None, breakdown=None, formula=None, limit=None,
318
+ project=None, client=None)` -- returns a `MetricsResult`. Either `event=` (with `measure=`,
319
+ default `count()`, and `filters=`) for one series, or `series=[{"id", "event",
320
+ "measure", "filters"?}, ...]`. Give the time as `from_` (and optionally `to`,
321
+ exclusive) -- a `datetime` (naive ones are taken as UTC) or an ISO 8601
322
+ string -- or as `last_days=N`. `limit` keeps the top N breakdown combinations.
323
+ `query_async` is the async form.
324
+ - `get_schema(*, project=None, client=None)` -- what can be queried.
325
+ `get_schema_async` is the async form.
326
+ - `MetricsResult` is the answer as JSON plus the `version` of that shape. Read
327
+ it by key (`result["meta"]`, `result.get("series")`, or `result.data`), so
328
+ the server gaining a field needs no SDK release. `result.series` is the list
329
+ of series and `result.rows(series_id)` the rows of one, each
330
+ `{"bucket", "breakdown", "value"}`.
331
+ - Measures: `count()`, `unique(p)`, `sum_(p)`, `avg(p)`, `median(p)`, `p90(p)`,
332
+ `min_(p)`, `max_(p)`. They are only strings (`"avg(wait_seconds)"`), as a
333
+ filter is only a dict (`where(p, op, value)` builds
334
+ `{"property", "op", "value"}`), so plain ones work as well.
335
+ - Raises `ValueError`, without sending anything, for a query that cannot be
336
+ valid (no series or more than four, more than two breakdowns, `last_days`
337
+ together with `from_`). Raises `MetricsError` (`status_code`, `message`) if
338
+ the server rejected the query -- a 400 whose message says what to change,
339
+ e.g. an unknown event or property, or a range that is too long; or a 422 if it
340
+ is too expensive to run (shorten the range, add filters, use a coarser unit)
341
+ -- or did not answer, including on a persistent 429/5xx. A timeout or 5xx gets two
342
+ attempts in all, so a slow query cannot be re-run several times on the server.
343
+ A 429 (the project already has queries running, as when a view loads several
344
+ tiles at once) is retried up to eight times, about a second apart, before it
345
+ reaches you.
346
+ - `client` lets many calls share one connection; see `riffsdk.tasks`' API
347
+ notes above -- the modules default to and can share the same
348
+ `RiffClient`/`AsyncRiffClient`. A query runs under a server-side statement
349
+ timeout of about 10s; the call's own timeout is 30s.
350
+
200
351
  ## Email
201
352
 
202
353
  The AI notice that goes at the end of an email an agent sends. Recipients have to
@@ -183,6 +183,157 @@ version, and the one you imported keeps behaving as it did. Importing
183
183
  the client's own default: this proxies to an LLM call through
184
184
  riff-orchestrator, whose own timeout defaults to 120s.
185
185
 
186
+ ## Metrics
187
+
188
+ Ask for numbers about the app's own agent -- its tasks, the decisions it asked
189
+ people for, the tool calls it made and the hooks that fired -- with a query,
190
+ instead of a new endpoint per number. The query has the shape of an analytics
191
+ "insights" query: an event, how to measure it, filters, a breakdown, and a time
192
+ range bucketed by a unit.
193
+
194
+ ```python
195
+ import riffsdk.metrics.v0 as metrics
196
+
197
+ result = metrics.query(
198
+ event="decision_resolved",
199
+ measure=metrics.median("wait_seconds"), # default: metrics.count()
200
+ filters=[metrics.where("type", "eq", "approval")],
201
+ breakdown="task.metadata.supplier", # up to two properties
202
+ last_days=30, # or from_=/to= (datetime or ISO 8601)
203
+ unit="week", # hour | day | week | month | total
204
+ )
205
+ for row in result.rows("a"): # a single series is called "a"
206
+ print(row["bucket"], row["breakdown"], row["value"])
207
+ ```
208
+
209
+ Call `metrics.get_schema()` first to see the events, their properties and
210
+ types, the measures, filter operators and units (one list shared by all events),
211
+ the limits, and the project's task metadata keys, rather than guessing names.
212
+
213
+ Several series (one to four) can be read side by side or combined with a
214
+ `formula` of numbers, series ids and `+ - * / ( )`, evaluated per bucket and
215
+ breakdown row. The result then has one more series, `"formula"`, whose `value`
216
+ is `None` where it divided by zero:
217
+
218
+ ```python
219
+ result = metrics.query(
220
+ series=[
221
+ {"id": "a", "event": "decision_requested", "measure": "count",
222
+ "filters": [metrics.where("type", "eq", "escalation")]},
223
+ {"id": "b", "event": "task_created", "measure": "count"},
224
+ ],
225
+ formula="a / b",
226
+ last_days=30,
227
+ unit="total",
228
+ )
229
+ escalation_rate = result.rows("formula")[0]["value"]
230
+ ```
231
+
232
+ A view's backend is the usual caller. In `backend/app/views/<name>.py`, combine
233
+ the agent's numbers with the app's own data:
234
+
235
+ ```python
236
+ import riffsdk.metrics.v0 as metrics
237
+
238
+ def handler(params):
239
+ sent = metrics.query(
240
+ event="tool_called",
241
+ filters=[
242
+ metrics.where("tool_name", "eq", "send_chase"),
243
+ metrics.where("output.status", "eq", "sent"),
244
+ ],
245
+ last_days=90,
246
+ unit="week",
247
+ )
248
+ weekly = [{"week": r["bucket"], "sent": r["value"]} for r in sent.rows("a")]
249
+ return {"weekly_chases": weekly, "open_lines": load_open_lines()} # your own ERP data
250
+ ```
251
+
252
+ `input.<key>` and `output.<key>` of a tool call can be used in filters and
253
+ measures but not in `breakdown`; split by a task metadata key
254
+ (`task.metadata.<key>`) instead.
255
+
256
+ This is for what the orchestrator knows. ERP and other app data stay in the
257
+ app, and raw rows (a list of tasks or tool calls) are not metrics.
258
+
259
+ By default a project reads only its own metrics. The account and the
260
+ environment are decided by the credentials the request is made with: a
261
+ deployed app sees its production data, the same app in the workspace sees the
262
+ workspace's. Nothing in a query names them.
263
+
264
+ ### Reading other projects (dashboards)
265
+
266
+ A *dashboard* project can read the metrics of other projects with the optional
267
+ `project=` argument on `query`, `query_async`, `get_schema` and
268
+ `get_schema_async`: one project id, or a list of up to ten.
269
+
270
+ ```python
271
+ result = metrics.query(
272
+ event="task_created",
273
+ last_days=30,
274
+ unit="week",
275
+ breakdown="project_id", # tell the projects apart
276
+ project=["proj-a", "proj-b"], # or project="proj-a"
277
+ )
278
+ schema = metrics.get_schema(project="proj-a") # sent as ?project=proj-a
279
+ ```
280
+
281
+ - Only dashboard projects may pass it. From any other kind of project it is
282
+ refused.
283
+ - Only projects of the caller's own account (or the caller itself) can be named.
284
+ - The environment is always the caller's: a workspace dashboard reads workspace
285
+ data and a deployed one production data. There is no `mode` to pass.
286
+ - A refusal (not a dashboard, another account, an unknown project, too many
287
+ targets) raises the usual `MetricsError` with a 4xx `status_code`; the
288
+ message does not say which rule applied.
289
+ - A list is sent as a list and a string as a string; `get_schema` sends a list
290
+ as repeated `?project=` parameters. More than ten ids, an empty list or an
291
+ empty id raises `ValueError` before anything is sent.
292
+ - Leaving `project` out gives exactly the behaviour above: the caller's own
293
+ metrics, and nothing extra on the wire.
294
+
295
+ Import the version you are writing against, bound to a short name as above. A
296
+ version does not change under you: when the API changes it appears as a new
297
+ version, and the one you imported keeps behaving as it did. Importing `riffsdk`
298
+ or `riffsdk.metrics` loads no version.
299
+
300
+ ### API
301
+
302
+ - `query(*, series=None, event=None, measure=None, filters=None, from_=None,
303
+ to=None, last_days=None, unit=None, breakdown=None, formula=None, limit=None,
304
+ project=None, client=None)` -- returns a `MetricsResult`. Either `event=` (with `measure=`,
305
+ default `count()`, and `filters=`) for one series, or `series=[{"id", "event",
306
+ "measure", "filters"?}, ...]`. Give the time as `from_` (and optionally `to`,
307
+ exclusive) -- a `datetime` (naive ones are taken as UTC) or an ISO 8601
308
+ string -- or as `last_days=N`. `limit` keeps the top N breakdown combinations.
309
+ `query_async` is the async form.
310
+ - `get_schema(*, project=None, client=None)` -- what can be queried.
311
+ `get_schema_async` is the async form.
312
+ - `MetricsResult` is the answer as JSON plus the `version` of that shape. Read
313
+ it by key (`result["meta"]`, `result.get("series")`, or `result.data`), so
314
+ the server gaining a field needs no SDK release. `result.series` is the list
315
+ of series and `result.rows(series_id)` the rows of one, each
316
+ `{"bucket", "breakdown", "value"}`.
317
+ - Measures: `count()`, `unique(p)`, `sum_(p)`, `avg(p)`, `median(p)`, `p90(p)`,
318
+ `min_(p)`, `max_(p)`. They are only strings (`"avg(wait_seconds)"`), as a
319
+ filter is only a dict (`where(p, op, value)` builds
320
+ `{"property", "op", "value"}`), so plain ones work as well.
321
+ - Raises `ValueError`, without sending anything, for a query that cannot be
322
+ valid (no series or more than four, more than two breakdowns, `last_days`
323
+ together with `from_`). Raises `MetricsError` (`status_code`, `message`) if
324
+ the server rejected the query -- a 400 whose message says what to change,
325
+ e.g. an unknown event or property, or a range that is too long; or a 422 if it
326
+ is too expensive to run (shorten the range, add filters, use a coarser unit)
327
+ -- or did not answer, including on a persistent 429/5xx. A timeout or 5xx gets two
328
+ attempts in all, so a slow query cannot be re-run several times on the server.
329
+ A 429 (the project already has queries running, as when a view loads several
330
+ tiles at once) is retried up to eight times, about a second apart, before it
331
+ reaches you.
332
+ - `client` lets many calls share one connection; see `riffsdk.tasks`' API
333
+ notes above -- the modules default to and can share the same
334
+ `RiffClient`/`AsyncRiffClient`. A query runs under a server-side statement
335
+ timeout of about 10s; the call's own timeout is 30s.
336
+
186
337
  ## Email
187
338
 
188
339
  The AI notice that goes at the end of an email an agent sends. Recipients have to
@@ -0,0 +1,72 @@
1
+ """Ask the orchestrator for numbers about the app's own agent.
2
+
3
+ The case this exists for: a KPI view ("how many chase e-mails went out each
4
+ week", "how long do people take to answer the agent", "what share of tasks
5
+ needed an escalation") used to need its own endpoint per number. One query
6
+ now says which events to count, how to measure them, and how to split them.
7
+
8
+ Run this from an app's backend, where the environment it needs is already set.
9
+ A project reads only its own metrics: nothing in a query names the project, the
10
+ account or the environment, and there is no way to reach another one.
11
+ """
12
+
13
+ import riffsdk.metrics.v0 as metrics
14
+
15
+ # Look at what can be queried before guessing at names.
16
+ schema = metrics.get_schema()
17
+ print(f"payload version {schema.version}")
18
+ print("events:", [e["name"] for e in schema["events"]])
19
+
20
+ # 1. One series: chase e-mails actually sent, per week, per supplier (a key in
21
+ # the task's metadata; tool input/output can filter but never break down).
22
+ sent = metrics.query(
23
+ event="tool_called",
24
+ measure=metrics.count(),
25
+ filters=[
26
+ metrics.where("tool_name", "eq", "send_chase"),
27
+ metrics.where("output.status", "eq", "sent"),
28
+ metrics.where("is_error", "eq", False),
29
+ ],
30
+ breakdown=["task.metadata.supplier"],
31
+ last_days=90,
32
+ unit="week",
33
+ )
34
+ for row in sent.rows("a"):
35
+ print(row["bucket"], row["breakdown"], row["value"])
36
+
37
+ # 2. How long people take to answer the agent: the median, per week.
38
+ answer_time = metrics.query(
39
+ event="decision_resolved",
40
+ measure=metrics.median("wait_seconds"),
41
+ last_days=30,
42
+ unit="week",
43
+ )
44
+ for row in answer_time.rows("a"):
45
+ print(row["bucket"], row["value"])
46
+
47
+ # 3. Two series and a formula: the escalation rate, per supplier.
48
+ rate = metrics.query(
49
+ series=[
50
+ {
51
+ "id": "a",
52
+ "event": "decision_requested",
53
+ "measure": metrics.count(),
54
+ "filters": [metrics.where("type", "eq", "escalation")],
55
+ },
56
+ {"id": "b", "event": "task_created", "measure": metrics.count()},
57
+ ],
58
+ formula="a / b",
59
+ breakdown="task.metadata.supplier",
60
+ last_days=30,
61
+ unit="total",
62
+ )
63
+ for row in rate.rows("formula"):
64
+ # value is None where the formula divided by zero
65
+ print(row["breakdown"], row["value"])
66
+
67
+ # A query the server rejects (an unknown event or property) raises
68
+ # MetricsError with its reason; metrics.query_async is the async form.
69
+ try:
70
+ metrics.query(event="no_such_event", last_days=1)
71
+ except metrics.MetricsError as e:
72
+ print(f"rejected ({e.status_code}): {e.message}")
@@ -46,6 +46,7 @@ is introduced later, that would move to `/sdk/v1/tasks`).
46
46
  | storage | `/_projects/{id}/sdk/v0/storage/<tail>` | `$DBAPI_SERVICE_URL` (riff-api, same backend as today) | `/riff-api/storage/v1/<tail>` |
47
47
  | tasks | `/_projects/{id}/sdk/v0/tasks/<tail>` | `$ORCHESTRATOR_SERVICE_URL` (riff-orchestrator, **directly** — bypasses riff-api) | `/api/v0/riffsdk/tasks/<tail>` |
48
48
  | ai | `/_projects/{id}/sdk/v0/ai/<tail>` | `$ORCHESTRATOR_SERVICE_URL` (riff-orchestrator, **directly** — bypasses riff-api) | `/api/v0/riffsdk/ai/<tail>` |
49
+ | metrics | `/_projects/{id}/sdk/v0/metrics/<tail>` | `$ORCHESTRATOR_SERVICE_URL` (riff-orchestrator, **directly** — bypasses riff-api) | `/api/v0/riffsdk/metrics/<tail>` |
49
50
 
50
51
  The proxy does a literal prefix substitution (`/_projects/{id}/sdk/v0/tasks`
51
52
  → `/api/v0/riffsdk/tasks`, etc.) and leaves everything after that prefix
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "riffsdk"
7
- version = "0.26.0"
7
+ version = "0.28.0"
8
8
  description = "Python SDK for the Riff Storage API"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -217,7 +217,7 @@ class Transport:
217
217
  *,
218
218
  json: Any = None,
219
219
  content: bytes | None = None,
220
- params: dict[str, str] | None = None,
220
+ params: dict[str, str | list[str]] | None = None,
221
221
  headers: dict[str, str] | None = None,
222
222
  context: dict[str, str] | None = None,
223
223
  timeout: float | None = None,
@@ -331,7 +331,7 @@ class AsyncTransport:
331
331
  *,
332
332
  json: Any = None,
333
333
  content: bytes | None = None,
334
- params: dict[str, str] | None = None,
334
+ params: dict[str, str | list[str]] | None = None,
335
335
  headers: dict[str, str] | None = None,
336
336
  context: dict[str, str] | None = None,
337
337
  timeout: float | None = None,
@@ -136,7 +136,7 @@ class RiffClient:
136
136
  path: str,
137
137
  *,
138
138
  json: Any = None,
139
- params: dict[str, str] | None = None,
139
+ params: dict[str, str | list[str]] | None = None,
140
140
  headers: dict[str, str] | None = None,
141
141
  timeout: float | None = None,
142
142
  max_retries: int | None = None,
@@ -206,7 +206,7 @@ class AsyncRiffClient:
206
206
  path: str,
207
207
  *,
208
208
  json: Any = None,
209
- params: dict[str, str] | None = None,
209
+ params: dict[str, str | list[str]] | None = None,
210
210
  headers: dict[str, str] | None = None,
211
211
  timeout: float | None = None,
212
212
  max_retries: int | None = None,
@@ -0,0 +1,16 @@
1
+ """Query the metrics of the app's agent: tasks, decisions, tool calls and hooks.
2
+
3
+ Import the version you are writing against, bound to a short name::
4
+
5
+ import riffsdk.metrics.v0 as metrics
6
+
7
+ result = metrics.query(
8
+ event="decision_resolved",
9
+ measure=metrics.median("wait_seconds"),
10
+ last_days=30,
11
+ unit="week",
12
+ )
13
+
14
+ A version does not change under you. When the API changes it appears as a new
15
+ version, and the one you imported keeps behaving as it did.
16
+ """