telem-sdk 0.2.3__tar.gz → 0.3.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.
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/PKG-INFO +12 -1
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/README.md +11 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/__init__.py +16 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/_base.py +32 -3
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/_normalize.py +1 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/_version.py +1 -1
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/async_client.py +11 -4
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/client.py +11 -4
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/errors.py +17 -1
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/models.py +126 -4
- telem_sdk-0.3.0/telem/resources/monitors.py +475 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/resources/sessions.py +11 -4
- telem_sdk-0.2.3/telem/resources/monitors.py +0 -270
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/LICENSE +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/pyproject.toml +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/_config_files.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/_skills/telem-search/SKILL.md +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/_skills/telem-search/scripts/search.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/_version_advisory.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/config.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/install_skill.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/__init__.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/_hermes_render.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/_hermes_state.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/_langchain_trajectory.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/_openai_trajectory.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/_tools.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/_trajectory_v5.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/_update_advisory.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/hermes.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/langchain.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/integrations/openai.py +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/py.typed +0 -0
- {telem_sdk-0.2.3 → telem_sdk-0.3.0}/telem/resources/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: telem-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python SDK for the Telem search orchestration API.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
@@ -187,10 +187,21 @@ your last poll. `poll` returns a `SearchResponse`:
|
|
|
187
187
|
```python
|
|
188
188
|
monitor = client.monitors.create("Nvidia files a new 8-K with the SEC", frequency="1h", ttl="7d")
|
|
189
189
|
response = client.monitors.poll(monitor.id)
|
|
190
|
+
for change in client.monitors.iter_changes(monitor.id):
|
|
191
|
+
print(change.seq, change.kind, change.subject.name)
|
|
190
192
|
client.monitors.update(monitor.id, status="paused")
|
|
191
193
|
client.monitors.delete(monitor.id)
|
|
192
194
|
```
|
|
193
195
|
|
|
196
|
+
A monitor has an agent unless you create it with `agent=False`. The agent checks every
|
|
197
|
+
result against the query and keeps the ones that match. `iter_changes` reads what it
|
|
198
|
+
kept, oldest first, until you are caught up, and then stops. Keep the `seq` of the last
|
|
199
|
+
change you handled and pass it as `cursor` next time: no change comes twice, and none
|
|
200
|
+
is skipped. `changes` returns one page (`next_cursor`, `watermark`) and takes
|
|
201
|
+
`cursor`, `since`, `kinds` and `limit`. `agent` returns the agent itself, and
|
|
202
|
+
`monitor.agent_state` shows it on the monitor. With `AsyncTelem`, read `iter_changes`
|
|
203
|
+
with `async for`.
|
|
204
|
+
|
|
194
205
|
`client.monitors` also has `get` and `list`. See [Monitors](https://docs.telem.ai/resources/monitors/)
|
|
195
206
|
for the fields and the errors.
|
|
196
207
|
|
|
@@ -167,10 +167,21 @@ your last poll. `poll` returns a `SearchResponse`:
|
|
|
167
167
|
```python
|
|
168
168
|
monitor = client.monitors.create("Nvidia files a new 8-K with the SEC", frequency="1h", ttl="7d")
|
|
169
169
|
response = client.monitors.poll(monitor.id)
|
|
170
|
+
for change in client.monitors.iter_changes(monitor.id):
|
|
171
|
+
print(change.seq, change.kind, change.subject.name)
|
|
170
172
|
client.monitors.update(monitor.id, status="paused")
|
|
171
173
|
client.monitors.delete(monitor.id)
|
|
172
174
|
```
|
|
173
175
|
|
|
176
|
+
A monitor has an agent unless you create it with `agent=False`. The agent checks every
|
|
177
|
+
result against the query and keeps the ones that match. `iter_changes` reads what it
|
|
178
|
+
kept, oldest first, until you are caught up, and then stops. Keep the `seq` of the last
|
|
179
|
+
change you handled and pass it as `cursor` next time: no change comes twice, and none
|
|
180
|
+
is skipped. `changes` returns one page (`next_cursor`, `watermark`) and takes
|
|
181
|
+
`cursor`, `since`, `kinds` and `limit`. `agent` returns the agent itself, and
|
|
182
|
+
`monitor.agent_state` shows it on the monitor. With `AsyncTelem`, read `iter_changes`
|
|
183
|
+
with `async for`.
|
|
184
|
+
|
|
174
185
|
`client.monitors` also has `get` and `list`. See [Monitors](https://docs.telem.ai/resources/monitors/)
|
|
175
186
|
for the fields and the errors.
|
|
176
187
|
|
|
@@ -16,11 +16,19 @@ from telem.errors import (
|
|
|
16
16
|
TelemConnectionError,
|
|
17
17
|
TelemError,
|
|
18
18
|
TelemServerVersionError,
|
|
19
|
+
TelemTimeoutError,
|
|
19
20
|
)
|
|
20
21
|
from telem.models import (
|
|
22
|
+
AgentCompileState,
|
|
23
|
+
AgentDocument,
|
|
24
|
+
AgentState,
|
|
25
|
+
ChangeRecord,
|
|
26
|
+
ChangesPage,
|
|
27
|
+
ChangeSubject,
|
|
21
28
|
FetchResponse,
|
|
22
29
|
FetchResult,
|
|
23
30
|
Monitor,
|
|
31
|
+
MonitorPage,
|
|
24
32
|
ProviderInfo,
|
|
25
33
|
ProviderRun,
|
|
26
34
|
SearchResponse,
|
|
@@ -46,6 +54,13 @@ __all__ = [
|
|
|
46
54
|
"SessionHistory",
|
|
47
55
|
"SessionResults",
|
|
48
56
|
"Monitor",
|
|
57
|
+
"MonitorPage",
|
|
58
|
+
"AgentState",
|
|
59
|
+
"AgentCompileState",
|
|
60
|
+
"AgentDocument",
|
|
61
|
+
"ChangesPage",
|
|
62
|
+
"ChangeRecord",
|
|
63
|
+
"ChangeSubject",
|
|
49
64
|
"verify_webhook",
|
|
50
65
|
"TelemError",
|
|
51
66
|
"AuthError",
|
|
@@ -54,6 +69,7 @@ __all__ = [
|
|
|
54
69
|
"APIStatusError",
|
|
55
70
|
"TelemServerVersionError",
|
|
56
71
|
"TelemConnectionError",
|
|
72
|
+
"TelemTimeoutError",
|
|
57
73
|
# The unified config — read explicitly, never by the client itself.
|
|
58
74
|
"resolve_search_options",
|
|
59
75
|
"SearchOptionsResolution",
|
|
@@ -11,12 +11,18 @@ import os
|
|
|
11
11
|
from collections.abc import Sequence
|
|
12
12
|
from datetime import date, datetime
|
|
13
13
|
from typing import Any
|
|
14
|
+
from urllib.parse import quote
|
|
14
15
|
|
|
15
16
|
import httpx
|
|
16
17
|
|
|
17
18
|
from telem._config_files import TELEM_OPTIONS, option_from_env, read_credentials
|
|
18
19
|
from telem._version import __version__
|
|
19
|
-
from telem.errors import
|
|
20
|
+
from telem.errors import (
|
|
21
|
+
TelemConnectionError,
|
|
22
|
+
TelemServerVersionError,
|
|
23
|
+
TelemTimeoutError,
|
|
24
|
+
raise_for_status,
|
|
25
|
+
)
|
|
20
26
|
|
|
21
27
|
#: The hosted deployment. A default rather than a requirement: an ordinary user
|
|
22
28
|
#: should not have to know where Telem runs, and `TELEM_BASE_URL` or the
|
|
@@ -47,6 +53,14 @@ def _csv_env(name: str) -> list[str] | None:
|
|
|
47
53
|
return [item for item in items if item] or None
|
|
48
54
|
|
|
49
55
|
|
|
56
|
+
def path_segment(value: str) -> str:
|
|
57
|
+
"""Encode a caller-supplied id as ONE path segment, so ``../`` cannot change the route."""
|
|
58
|
+
# quote() leaves dots alone, and httpx collapses a bare ``..`` segment.
|
|
59
|
+
if value in (".", ".."):
|
|
60
|
+
raise ValueError(f"invalid id: {value!r}")
|
|
61
|
+
return quote(value, safe="")
|
|
62
|
+
|
|
63
|
+
|
|
50
64
|
def _providers_refusal(include: list[str], include_from_call: bool, exclude_from_call: bool) -> str:
|
|
51
65
|
"""The message for an ``include`` that ``exclude`` empties: where each list was set."""
|
|
52
66
|
|
|
@@ -110,13 +124,17 @@ class BaseClient:
|
|
|
110
124
|
# This is the SDK's ONE config file. Repo-local `.telem/telem.json` options stay
|
|
111
125
|
# unread here on purpose: a library must not let a checked-out
|
|
112
126
|
# repository steer an arbitrary program's spend.
|
|
127
|
+
if api_key is not None and not api_key.strip():
|
|
128
|
+
raise ValueError("api_key is empty")
|
|
113
129
|
resolved_key = api_key or os.environ.get("TELEM_API_KEY") or None
|
|
114
130
|
resolved_base = base_url or os.environ.get("TELEM_BASE_URL") or None
|
|
115
131
|
if resolved_key is None or resolved_base is None:
|
|
116
132
|
credentials = read_credentials(os.environ)
|
|
117
133
|
resolved_key = resolved_key or credentials.get("apiKey")
|
|
118
134
|
resolved_base = resolved_base or credentials.get("baseUrl")
|
|
119
|
-
|
|
135
|
+
# Stripped: ``$(cat keyfile)`` leaves a trailing newline, which httpx rejects
|
|
136
|
+
# as an illegal header value.
|
|
137
|
+
self.api_key = resolved_key.strip() if resolved_key else resolved_key
|
|
120
138
|
self.base_url = (resolved_base or _DEFAULT_BASE_URL).rstrip("/")
|
|
121
139
|
self.timeout = timeout
|
|
122
140
|
self.user_agent = user_agent or _DEFAULT_USER_AGENT
|
|
@@ -448,8 +466,11 @@ class BaseClient:
|
|
|
448
466
|
|
|
449
467
|
def _connection_error(self, path: str, exc: Exception) -> TelemConnectionError:
|
|
450
468
|
"""Wrap a transport-level failure (no HTTP response was produced) for ``path``."""
|
|
469
|
+
# A LocalProtocolError is a fault in the request we built, and its text can quote
|
|
470
|
+
# a header value (the Authorization key), so its text is never echoed.
|
|
471
|
+
detail = "" if isinstance(exc, httpx.LocalProtocolError) else f": {exc}"
|
|
451
472
|
return TelemConnectionError(
|
|
452
|
-
f"could not reach {self._url(path)}: {type(exc).__name__}
|
|
473
|
+
f"could not reach {self._url(path)}: {type(exc).__name__}{detail}"
|
|
453
474
|
)
|
|
454
475
|
|
|
455
476
|
@staticmethod
|
|
@@ -493,6 +514,14 @@ class BaseClient:
|
|
|
493
514
|
raise_for_status(status_code, body)
|
|
494
515
|
return body
|
|
495
516
|
|
|
517
|
+
def _timeout_error(self, path: str, exc: Exception) -> TelemTimeoutError:
|
|
518
|
+
"""Wrap a timeout for ``path``: the server may have got the request, so it is not
|
|
519
|
+
"could not reach"."""
|
|
520
|
+
return TelemTimeoutError(
|
|
521
|
+
f"request to {self._url(path)} timed out after {self.timeout} s: "
|
|
522
|
+
f"{type(exc).__name__}: {exc}"
|
|
523
|
+
)
|
|
524
|
+
|
|
496
525
|
@classmethod
|
|
497
526
|
def _result(cls, response: httpx.Response) -> Any:
|
|
498
527
|
"""Parse an httpx response into JSON (falling back to text) and apply error mapping.
|
|
@@ -45,7 +45,8 @@ class AsyncTelem(BaseClient):
|
|
|
45
45
|
Args:
|
|
46
46
|
api_key: Bearer token. Falls back to the ``TELEM_API_KEY`` env var, then to
|
|
47
47
|
``~/.telem/credentials.json`` (the file the guided installer writes;
|
|
48
|
-
``TELEM_CONFIG_DIR`` relocates the directory), then anonymous.
|
|
48
|
+
``TELEM_CONFIG_DIR`` relocates the directory), then anonymous. An empty
|
|
49
|
+
``api_key`` raises ``ValueError``.
|
|
49
50
|
base_url: API base URL. Falls back to ``TELEM_BASE_URL``, then to the same
|
|
50
51
|
credentials file, then the hosted deployment at router.telem.ai.
|
|
51
52
|
timeout: Request timeout in seconds.
|
|
@@ -85,7 +86,9 @@ class AsyncTelem(BaseClient):
|
|
|
85
86
|
"""Issue a GET request and return the parsed body (raising typed errors on failure)."""
|
|
86
87
|
try:
|
|
87
88
|
response = await self._client.get(self._url(path), params=params)
|
|
88
|
-
except
|
|
89
|
+
except httpx.TimeoutException as exc:
|
|
90
|
+
raise self._timeout_error(path, exc) from exc
|
|
91
|
+
except httpx.TransportError as exc:
|
|
89
92
|
raise self._connection_error(path, exc) from exc
|
|
90
93
|
return self._result(response)
|
|
91
94
|
|
|
@@ -93,7 +96,9 @@ class AsyncTelem(BaseClient):
|
|
|
93
96
|
"""Issue a POST request and return the parsed body (raising typed errors on failure)."""
|
|
94
97
|
try:
|
|
95
98
|
response = await self._client.post(self._url(path), json=json)
|
|
96
|
-
except
|
|
99
|
+
except httpx.TimeoutException as exc:
|
|
100
|
+
raise self._timeout_error(path, exc) from exc
|
|
101
|
+
except httpx.TransportError as exc:
|
|
97
102
|
raise self._connection_error(path, exc) from exc
|
|
98
103
|
return self._result(response)
|
|
99
104
|
|
|
@@ -101,7 +106,9 @@ class AsyncTelem(BaseClient):
|
|
|
101
106
|
"""Issue a PATCH/DELETE request and return the parsed body (typed errors on failure)."""
|
|
102
107
|
try:
|
|
103
108
|
response = await self._client.request(method, self._url(path), json=json)
|
|
104
|
-
except
|
|
109
|
+
except httpx.TimeoutException as exc:
|
|
110
|
+
raise self._timeout_error(path, exc) from exc
|
|
111
|
+
except httpx.TransportError as exc:
|
|
105
112
|
raise self._connection_error(path, exc) from exc
|
|
106
113
|
return self._result(response)
|
|
107
114
|
|
|
@@ -45,7 +45,8 @@ class Telem(BaseClient):
|
|
|
45
45
|
Args:
|
|
46
46
|
api_key: Bearer token. Falls back to the ``TELEM_API_KEY`` env var, then to
|
|
47
47
|
``~/.telem/credentials.json`` (the file the guided installer writes;
|
|
48
|
-
``TELEM_CONFIG_DIR`` relocates the directory), then anonymous.
|
|
48
|
+
``TELEM_CONFIG_DIR`` relocates the directory), then anonymous. An empty
|
|
49
|
+
``api_key`` raises ``ValueError``.
|
|
49
50
|
base_url: API base URL. Falls back to ``TELEM_BASE_URL``, then to the same
|
|
50
51
|
credentials file, then the hosted deployment at router.telem.ai.
|
|
51
52
|
timeout: Request timeout in seconds.
|
|
@@ -85,7 +86,9 @@ class Telem(BaseClient):
|
|
|
85
86
|
"""Issue a GET request and return the parsed body (raising typed errors on failure)."""
|
|
86
87
|
try:
|
|
87
88
|
response = self._client.get(self._url(path), params=params)
|
|
88
|
-
except
|
|
89
|
+
except httpx.TimeoutException as exc:
|
|
90
|
+
raise self._timeout_error(path, exc) from exc
|
|
91
|
+
except httpx.TransportError as exc:
|
|
89
92
|
raise self._connection_error(path, exc) from exc
|
|
90
93
|
return self._result(response)
|
|
91
94
|
|
|
@@ -93,7 +96,9 @@ class Telem(BaseClient):
|
|
|
93
96
|
"""Issue a POST request and return the parsed body (raising typed errors on failure)."""
|
|
94
97
|
try:
|
|
95
98
|
response = self._client.post(self._url(path), json=json)
|
|
96
|
-
except
|
|
99
|
+
except httpx.TimeoutException as exc:
|
|
100
|
+
raise self._timeout_error(path, exc) from exc
|
|
101
|
+
except httpx.TransportError as exc:
|
|
97
102
|
raise self._connection_error(path, exc) from exc
|
|
98
103
|
return self._result(response)
|
|
99
104
|
|
|
@@ -101,7 +106,9 @@ class Telem(BaseClient):
|
|
|
101
106
|
"""Issue a PATCH/DELETE request and return the parsed body (typed errors on failure)."""
|
|
102
107
|
try:
|
|
103
108
|
response = self._client.request(method, self._url(path), json=json)
|
|
104
|
-
except
|
|
109
|
+
except httpx.TimeoutException as exc:
|
|
110
|
+
raise self._timeout_error(path, exc) from exc
|
|
111
|
+
except httpx.TransportError as exc:
|
|
105
112
|
raise self._connection_error(path, exc) from exc
|
|
106
113
|
return self._result(response)
|
|
107
114
|
|
|
@@ -49,6 +49,17 @@ class TelemConnectionError(TelemError):
|
|
|
49
49
|
"""Raised when the request never produced an HTTP response (timeout or transport failure)."""
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
class TelemTimeoutError(TelemConnectionError):
|
|
53
|
+
"""Raised when the request timed out. The server may have got it and acted on it."""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
#: The message for a request that the firewall in front of Telem blocked.
|
|
57
|
+
BLOCKED_MESSAGE = (
|
|
58
|
+
"The request was blocked by a firewall before it reached Telem; "
|
|
59
|
+
"the text may have characters that are not allowed."
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
52
63
|
def _detail_from_body(body: object) -> str | None:
|
|
53
64
|
"""Extract a human-readable message from a parsed JSON error body, if present.
|
|
54
65
|
|
|
@@ -83,7 +94,8 @@ def raise_for_status(status_code: int, body: object) -> None:
|
|
|
83
94
|
"""Raise the appropriate :class:`TelemError` subclass for a non-2xx response.
|
|
84
95
|
|
|
85
96
|
Maps status codes to exception types:
|
|
86
|
-
400 -> :class:`BadRequestError`, 401/403 -> :class:`AuthError
|
|
97
|
+
400 -> :class:`BadRequestError`, 401/403 -> :class:`AuthError` (a 403 whose body is
|
|
98
|
+
not JSON -> :class:`APIStatusError`: a firewall blocked it before it reached Telem),
|
|
87
99
|
404 -> :class:`NotFoundError`, any other non-2xx -> :class:`APIStatusError`.
|
|
88
100
|
2xx status codes are treated as success and do not raise.
|
|
89
101
|
|
|
@@ -97,6 +109,10 @@ def raise_for_status(status_code: int, body: object) -> None:
|
|
|
97
109
|
return
|
|
98
110
|
|
|
99
111
|
detail = _detail_from_body(body)
|
|
112
|
+
if status_code == 403 and not isinstance(body, dict):
|
|
113
|
+
# Telem's own 403 is JSON. A non-JSON one comes from the firewall in front of
|
|
114
|
+
# Telem: the key is not the problem.
|
|
115
|
+
raise APIStatusError(BLOCKED_MESSAGE, status_code=status_code, body=body)
|
|
100
116
|
if status_code == 400:
|
|
101
117
|
message = detail or "Bad request"
|
|
102
118
|
raise BadRequestError(message, status_code=status_code, body=body)
|
|
@@ -58,6 +58,8 @@ class ProviderRun(BaseModel):
|
|
|
58
58
|
verticals: dict[str, Any] | None = None
|
|
59
59
|
usage: dict[str, Any] | list[Any] | None = None
|
|
60
60
|
warnings: list[dict[str, Any]] = Field(default_factory=list)
|
|
61
|
+
# Monitor polls: results folded as the same story, {lead url: [{url, title}]}
|
|
62
|
+
same_story: dict[str, list[dict[str, Any]]] | None = None
|
|
61
63
|
raw: dict[str, Any] | None = None
|
|
62
64
|
|
|
63
65
|
|
|
@@ -137,8 +139,7 @@ class ProviderInfo(BaseModel):
|
|
|
137
139
|
url: str | None = None
|
|
138
140
|
normalized: bool = False
|
|
139
141
|
tiers: list[str] = Field(default_factory=list)
|
|
140
|
-
#: Whether auto-routing can pick it
|
|
141
|
-
#: that does not say.
|
|
142
|
+
#: Whether auto-routing can pick it. ``None`` from a router that does not say.
|
|
142
143
|
auto_routed: bool | None = None
|
|
143
144
|
|
|
144
145
|
|
|
@@ -176,6 +177,38 @@ class SessionResults(BaseModel):
|
|
|
176
177
|
previous_preprocessor_results: list[dict[str, Any]] = Field(default_factory=list)
|
|
177
178
|
|
|
178
179
|
|
|
180
|
+
class AgentCompileState(BaseModel):
|
|
181
|
+
"""The job that makes the agent's plan: ``AgentState.compile``."""
|
|
182
|
+
|
|
183
|
+
model_config = ConfigDict(extra="ignore")
|
|
184
|
+
|
|
185
|
+
job_id: str
|
|
186
|
+
status: str
|
|
187
|
+
#: Why the plan could not be made; ``None`` when it did not fail.
|
|
188
|
+
error: str | None = None
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class AgentState(BaseModel):
|
|
192
|
+
"""What the monitor agent is doing: ``Monitor.agent_state``."""
|
|
193
|
+
|
|
194
|
+
model_config = ConfigDict(extra="ignore")
|
|
195
|
+
|
|
196
|
+
#: The agent engine: ``"v4"`` today.
|
|
197
|
+
engine: str
|
|
198
|
+
#: Such as ``compiling``, ``ready``, ``paused`` or ``failed``.
|
|
199
|
+
status: str
|
|
200
|
+
#: ``True`` when the agent needs you to look at it, for example after it failed.
|
|
201
|
+
needs_attention: bool = False
|
|
202
|
+
#: The version of the agent's plan; ``None`` until the first plan is made.
|
|
203
|
+
plan_version: int | None = None
|
|
204
|
+
#: When the agent runs next, as an ISO 8601 time; ``None`` when it is not scheduled.
|
|
205
|
+
next_run_at: str | None = None
|
|
206
|
+
#: The ``seq`` of the newest change you can read. ``0``: there is none yet.
|
|
207
|
+
watermark: int = 0
|
|
208
|
+
#: The latest job that made the agent's plan; ``None`` when there is none.
|
|
209
|
+
compile: AgentCompileState | None = None
|
|
210
|
+
|
|
211
|
+
|
|
179
212
|
class Monitor(BaseModel):
|
|
180
213
|
"""A monitor: a query that Telem runs on a schedule."""
|
|
181
214
|
|
|
@@ -184,13 +217,102 @@ class Monitor(BaseModel):
|
|
|
184
217
|
id: str
|
|
185
218
|
query: str
|
|
186
219
|
frequency: str
|
|
187
|
-
#: ``active
|
|
220
|
+
#: ``active``, ``paused`` (you paused it) or ``ended`` (past ``expires_at``).
|
|
188
221
|
status: str
|
|
189
222
|
session_id: str
|
|
190
223
|
created_at: str
|
|
191
224
|
last_polled_at: str | None = None
|
|
192
|
-
#: When
|
|
225
|
+
#: When the monitor ends; ``None``: never.
|
|
193
226
|
expires_at: str | None = None
|
|
194
227
|
webhook_url: str | None = None
|
|
195
228
|
#: Signs the webhook deliveries. Only in the response that set ``webhook_url``.
|
|
196
229
|
webhook_secret: str | None = None
|
|
230
|
+
#: The monitor agent; ``None`` for a monitor without one (``agent=False``), and from
|
|
231
|
+
#: a router that does not say.
|
|
232
|
+
agent_state: AgentState | None = None
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class MonitorPage(BaseModel):
|
|
236
|
+
"""One page of :meth:`~telem.resources.monitors.MonitorsResource.list_page`."""
|
|
237
|
+
|
|
238
|
+
model_config = ConfigDict(extra="ignore")
|
|
239
|
+
|
|
240
|
+
monitors: list[Monitor] = []
|
|
241
|
+
#: Pass as ``cursor`` to get the next page; ``None`` on the last page.
|
|
242
|
+
next_cursor: str | None = None
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
class AgentDocument(BaseModel):
|
|
246
|
+
"""The agent of a monitor: :meth:`~telem.resources.monitors.MonitorsResource.agent`.
|
|
247
|
+
|
|
248
|
+
The router sends more than these fields, such as the plan and the counts. All of it
|
|
249
|
+
is in ``raw``. The document has no ``watermark``: a :class:`ChangesPage` has it, and
|
|
250
|
+
so does ``Monitor.agent_state``.
|
|
251
|
+
"""
|
|
252
|
+
|
|
253
|
+
model_config = ConfigDict(extra="ignore")
|
|
254
|
+
|
|
255
|
+
#: Such as ``compiling``, ``ready``, ``paused`` or ``failed``.
|
|
256
|
+
status: str | None = None
|
|
257
|
+
query: str | None = None
|
|
258
|
+
frequency: str | None = None
|
|
259
|
+
#: The version of the agent's plan; ``0`` until the first plan is made.
|
|
260
|
+
spec_version: int | None = None
|
|
261
|
+
#: The agent's spending limits; ``None`` when none are set.
|
|
262
|
+
budget: dict[str, Any] | None = None
|
|
263
|
+
#: What the agent has spent so far, in US dollars.
|
|
264
|
+
spend_usd: float | None = None
|
|
265
|
+
#: The whole document, as the router sent it.
|
|
266
|
+
raw: dict[str, Any] = Field(default_factory=dict)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class ChangeSubject(BaseModel):
|
|
270
|
+
"""The item a change is about.
|
|
271
|
+
|
|
272
|
+
``entity_id`` is ``None`` for a change to the whole monitor, such as a run or a plan
|
|
273
|
+
change.
|
|
274
|
+
"""
|
|
275
|
+
|
|
276
|
+
model_config = ConfigDict(extra="ignore")
|
|
277
|
+
|
|
278
|
+
entity_id: str | None = None
|
|
279
|
+
name: str | None = None
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class ChangeRecord(BaseModel):
|
|
283
|
+
"""One change of the monitor agent: the records of :class:`ChangesPage`."""
|
|
284
|
+
|
|
285
|
+
model_config = ConfigDict(extra="ignore")
|
|
286
|
+
|
|
287
|
+
#: Where the change is in the stream. It only grows. Pass the last one you handled
|
|
288
|
+
#: as ``cursor`` to read on from there.
|
|
289
|
+
seq: int
|
|
290
|
+
#: The agent's own name for the change, such as ``new_object`` or ``tick``.
|
|
291
|
+
type: str
|
|
292
|
+
#: ``entity_added``, ``value_changed``, ``fact_status_changed``, ``alert``, ``run``
|
|
293
|
+
#: or ``plan_changed``.
|
|
294
|
+
kind: str
|
|
295
|
+
monitor_id: str
|
|
296
|
+
subject: ChangeSubject = Field(default_factory=ChangeSubject)
|
|
297
|
+
#: The value before and after the change. Any JSON, and ``None`` when there is none.
|
|
298
|
+
before: Any = None
|
|
299
|
+
after: Any = None
|
|
300
|
+
fact_ids: list[str] = Field(default_factory=list)
|
|
301
|
+
#: When the change happened, as an ISO 8601 time.
|
|
302
|
+
at: str
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
class ChangesPage(BaseModel):
|
|
306
|
+
"""One page of :meth:`~telem.resources.monitors.MonitorsResource.changes`."""
|
|
307
|
+
|
|
308
|
+
model_config = ConfigDict(extra="ignore")
|
|
309
|
+
|
|
310
|
+
#: Oldest first.
|
|
311
|
+
changes: list[ChangeRecord] = Field(default_factory=list)
|
|
312
|
+
#: Keep it, and pass it as ``cursor`` to read on. On a full page (``limit`` changes) it
|
|
313
|
+
#: is the ``seq`` of the last change. On a shorter page it is ``watermark``: the read
|
|
314
|
+
#: got that far, past the changes that ``kinds`` left out too.
|
|
315
|
+
next_cursor: int
|
|
316
|
+
#: The ``seq`` of the newest change you can read now. You are caught up when
|
|
317
|
+
#: ``next_cursor`` reaches it.
|
|
318
|
+
watermark: int
|