telem-sdk 0.2.1__tar.gz → 0.2.3__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.1 → telem_sdk-0.2.3}/PKG-INFO +10 -1
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/README.md +9 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/__init__.py +8 -1
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/_base.py +58 -3
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/_skills/telem-search/SKILL.md +8 -7
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/_skills/telem-search/scripts/search.py +2 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/_version.py +1 -1
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/async_client.py +17 -1
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/client.py +17 -1
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/config.py +171 -37
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/hermes.py +20 -4
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/models.py +3 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/resources/monitors.py +39 -7
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/LICENSE +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/pyproject.toml +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/_config_files.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/_normalize.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/_version_advisory.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/errors.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/install_skill.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/__init__.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/_hermes_render.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/_hermes_state.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/_langchain_trajectory.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/_openai_trajectory.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/_tools.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/_trajectory_v5.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/_update_advisory.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/langchain.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/integrations/openai.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/py.typed +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/resources/__init__.py +0 -0
- {telem_sdk-0.2.1 → telem_sdk-0.2.3}/telem/resources/sessions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: telem-sdk
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Python SDK for the Telem search orchestration API.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
@@ -62,6 +62,9 @@ environment, then — for credentials only — `~/.telem/credentials.json`, then
|
|
|
62
62
|
| Provider allow-list | `default_providers_include` | `TELEM_PROVIDERS_INCLUDE` (csv) | the deployment's set |
|
|
63
63
|
| Provider deny-list | `default_providers_exclude` | `TELEM_PROVIDERS_EXCLUDE` (csv) | unset |
|
|
64
64
|
| Full page content | `default_include_full_content` | `TELEM_FULL_CONTENT` (`1` only) | off |
|
|
65
|
+
| Fetch providers | none (`fetch(providers=…)`) | `TELEM_FETCH_PROVIDERS` (csv) | the server's chain |
|
|
66
|
+
| Fetch tier | none (`fetch(tier=…)`) | `TELEM_FETCH_TIER` | the server's |
|
|
67
|
+
| Skip the fetch cache | none (`fetch(no_cache=…)`) | `TELEM_FETCH_NO_CACHE` (`1` only) | off |
|
|
65
68
|
|
|
66
69
|
When an API key is set, requests carry an `Authorization: Bearer <key>` header. Anonymous
|
|
67
70
|
access works for most endpoints locally; `sessions.list` requires a token.
|
|
@@ -87,6 +90,12 @@ the Telem plugins, where it survives as a
|
|
|
87
90
|
**deprecated alias of the provider allow-list**, ranked below `TELEM_PROVIDERS_INCLUDE`
|
|
88
91
|
and below both config files. Export `TELEM_PROVIDERS_INCLUDE` everywhere.
|
|
89
92
|
|
|
93
|
+
The three fetch defaults have no constructor argument: each resolves as **`fetch`
|
|
94
|
+
argument → env var → unset**, with the same csv and `1`-only rules, and `TELEM_FETCH_TIER`
|
|
95
|
+
is trimmed and lowercased. `no_cache=False` in a call overrides `TELEM_FETCH_NO_CACHE=1`.
|
|
96
|
+
To use the fetch keys in the Telem config files as well, pass
|
|
97
|
+
`**telem.resolve_fetch_options(project_root=...).fetch_kwargs` to `fetch`.
|
|
98
|
+
|
|
90
99
|
`num_results`, `include_raw` and `provider_overrides` are deliberately call-level only:
|
|
91
100
|
per-call intent, an audit knob and a surgical escape hatch respectively.
|
|
92
101
|
|
|
@@ -42,6 +42,9 @@ environment, then — for credentials only — `~/.telem/credentials.json`, then
|
|
|
42
42
|
| Provider allow-list | `default_providers_include` | `TELEM_PROVIDERS_INCLUDE` (csv) | the deployment's set |
|
|
43
43
|
| Provider deny-list | `default_providers_exclude` | `TELEM_PROVIDERS_EXCLUDE` (csv) | unset |
|
|
44
44
|
| Full page content | `default_include_full_content` | `TELEM_FULL_CONTENT` (`1` only) | off |
|
|
45
|
+
| Fetch providers | none (`fetch(providers=…)`) | `TELEM_FETCH_PROVIDERS` (csv) | the server's chain |
|
|
46
|
+
| Fetch tier | none (`fetch(tier=…)`) | `TELEM_FETCH_TIER` | the server's |
|
|
47
|
+
| Skip the fetch cache | none (`fetch(no_cache=…)`) | `TELEM_FETCH_NO_CACHE` (`1` only) | off |
|
|
45
48
|
|
|
46
49
|
When an API key is set, requests carry an `Authorization: Bearer <key>` header. Anonymous
|
|
47
50
|
access works for most endpoints locally; `sessions.list` requires a token.
|
|
@@ -67,6 +70,12 @@ the Telem plugins, where it survives as a
|
|
|
67
70
|
**deprecated alias of the provider allow-list**, ranked below `TELEM_PROVIDERS_INCLUDE`
|
|
68
71
|
and below both config files. Export `TELEM_PROVIDERS_INCLUDE` everywhere.
|
|
69
72
|
|
|
73
|
+
The three fetch defaults have no constructor argument: each resolves as **`fetch`
|
|
74
|
+
argument → env var → unset**, with the same csv and `1`-only rules, and `TELEM_FETCH_TIER`
|
|
75
|
+
is trimmed and lowercased. `no_cache=False` in a call overrides `TELEM_FETCH_NO_CACHE=1`.
|
|
76
|
+
To use the fetch keys in the Telem config files as well, pass
|
|
77
|
+
`**telem.resolve_fetch_options(project_root=...).fetch_kwargs` to `fetch`.
|
|
78
|
+
|
|
70
79
|
`num_results`, `include_raw` and `provider_overrides` are deliberately call-level only:
|
|
71
80
|
per-call intent, an audit knob and a surgical escape hatch respectively.
|
|
72
81
|
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
from telem.async_client import AsyncTelem
|
|
4
4
|
from telem.client import Telem
|
|
5
|
-
from telem.config import
|
|
5
|
+
from telem.config import (
|
|
6
|
+
FetchOptionsResolution,
|
|
7
|
+
SearchOptionsResolution,
|
|
8
|
+
resolve_fetch_options,
|
|
9
|
+
resolve_search_options,
|
|
10
|
+
)
|
|
6
11
|
from telem.errors import (
|
|
7
12
|
APIStatusError,
|
|
8
13
|
AuthError,
|
|
@@ -52,4 +57,6 @@ __all__ = [
|
|
|
52
57
|
# The unified config — read explicitly, never by the client itself.
|
|
53
58
|
"resolve_search_options",
|
|
54
59
|
"SearchOptionsResolution",
|
|
60
|
+
"resolve_fetch_options",
|
|
61
|
+
"FetchOptionsResolution",
|
|
55
62
|
]
|
|
@@ -14,7 +14,7 @@ from typing import Any
|
|
|
14
14
|
|
|
15
15
|
import httpx
|
|
16
16
|
|
|
17
|
-
from telem._config_files import read_credentials
|
|
17
|
+
from telem._config_files import TELEM_OPTIONS, option_from_env, read_credentials
|
|
18
18
|
from telem._version import __version__
|
|
19
19
|
from telem.errors import TelemConnectionError, TelemServerVersionError, raise_for_status
|
|
20
20
|
|
|
@@ -47,11 +47,33 @@ def _csv_env(name: str) -> list[str] | None:
|
|
|
47
47
|
return [item for item in items if item] or None
|
|
48
48
|
|
|
49
49
|
|
|
50
|
+
def _providers_refusal(include: list[str], include_from_call: bool, exclude_from_call: bool) -> str:
|
|
51
|
+
"""The message for an ``include`` that ``exclude`` empties: where each list was set."""
|
|
52
|
+
|
|
53
|
+
def where(half: str, from_call: bool) -> str:
|
|
54
|
+
return f"the {half} argument" if from_call else f"default_{half} or TELEM_{half.upper()}"
|
|
55
|
+
|
|
56
|
+
names = ", ".join(include)
|
|
57
|
+
return (
|
|
58
|
+
f"providers_exclude removes every provider in providers_include ({names}), so no "
|
|
59
|
+
f"provider is left and no search was sent. Remove {names} from providers_include "
|
|
60
|
+
f"(set by {where('providers_include', include_from_call)}) or from providers_exclude "
|
|
61
|
+
f"(set by {where('providers_exclude', exclude_from_call)})."
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
50
65
|
def _flag_env(name: str) -> bool | None:
|
|
51
66
|
"""Parse a boolean env var: exactly ``"1"`` means True, anything else is unset."""
|
|
52
67
|
return True if os.environ.get(name) == "1" else None
|
|
53
68
|
|
|
54
69
|
|
|
70
|
+
def _fetch_env(key: str) -> Any | None:
|
|
71
|
+
"""Read one fetch key from its ``TELEM_FETCH_*`` var with the shared option table's
|
|
72
|
+
parsing (``nameList`` as CSV, ``name`` trimmed, ``flag`` on with exactly ``"1"``)."""
|
|
73
|
+
spec = next(spec for spec in TELEM_OPTIONS if spec.key == key)
|
|
74
|
+
return option_from_env(spec, os.environ)
|
|
75
|
+
|
|
76
|
+
|
|
55
77
|
def _int_env(name: str) -> int | None:
|
|
56
78
|
"""Parse an integer env var, or ``None`` when it is unset or not an integer."""
|
|
57
79
|
try:
|
|
@@ -136,6 +158,13 @@ class BaseClient:
|
|
|
136
158
|
if default_topic is not None
|
|
137
159
|
else ((os.environ.get("TELEM_TOPIC") or "").strip() or None)
|
|
138
160
|
)
|
|
161
|
+
# Fetch defaults: env var only, else unset; a ``fetch()`` argument wins per key.
|
|
162
|
+
# The tier is lowercased, as the agent plugins send it. The config files stay
|
|
163
|
+
# unread here too: ``resolve_fetch_options()`` is the opt-in for them.
|
|
164
|
+
fetch_tier = _fetch_env("fetchTier")
|
|
165
|
+
self.default_fetch_providers = _fetch_env("fetchProviders")
|
|
166
|
+
self.default_fetch_tier = fetch_tier.lower() if fetch_tier is not None else None
|
|
167
|
+
self.default_fetch_no_cache = _fetch_env("fetchNoCache")
|
|
139
168
|
|
|
140
169
|
def _headers(self) -> dict[str, str]:
|
|
141
170
|
"""Build the default request headers, adding Bearer auth only when an api_key is set."""
|
|
@@ -167,6 +196,7 @@ class BaseClient:
|
|
|
167
196
|
topic: str | None = None,
|
|
168
197
|
published_after: str | date | None = None,
|
|
169
198
|
published_before: str | date | None = None,
|
|
199
|
+
include_domains: list[str] | None = None,
|
|
170
200
|
) -> dict[str, Any]:
|
|
171
201
|
"""Resolve call arguments against the client defaults into the wire ``search`` block.
|
|
172
202
|
|
|
@@ -180,7 +210,8 @@ class BaseClient:
|
|
|
180
210
|
never carries both.
|
|
181
211
|
2. When both provider halves resolve, ``include`` fully determines the set: the
|
|
182
212
|
excluded names are subtracted client-side and ``exclude`` is not sent. An include
|
|
183
|
-
emptied by that subtraction is
|
|
213
|
+
emptied by that subtraction raises ``ValueError`` before anything is sent: no
|
|
214
|
+
provider is left, and the deployment's default set could hold an excluded one.
|
|
184
215
|
|
|
185
216
|
Returns:
|
|
186
217
|
The ``search`` block, containing exactly the options that are set (``{}`` when
|
|
@@ -204,7 +235,14 @@ class BaseClient:
|
|
|
204
235
|
)
|
|
205
236
|
if include is not None and exclude is not None:
|
|
206
237
|
excluded = set(exclude)
|
|
207
|
-
|
|
238
|
+
kept = [name for name in include if name not in excluded]
|
|
239
|
+
if include and not kept:
|
|
240
|
+
raise ValueError(
|
|
241
|
+
_providers_refusal(
|
|
242
|
+
include, providers_include is not None, providers_exclude is not None
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
include = kept
|
|
208
246
|
exclude = None
|
|
209
247
|
|
|
210
248
|
if include_full_content is None:
|
|
@@ -250,6 +288,8 @@ class BaseClient:
|
|
|
250
288
|
block["published_after"] = _iso(published_after)
|
|
251
289
|
if published_before is not None:
|
|
252
290
|
block["published_before"] = _iso(published_before)
|
|
291
|
+
if include_domains is not None:
|
|
292
|
+
block["include_domains"] = include_domains
|
|
253
293
|
return block
|
|
254
294
|
|
|
255
295
|
def _search_body(
|
|
@@ -269,6 +309,7 @@ class BaseClient:
|
|
|
269
309
|
topic: str | None = None,
|
|
270
310
|
published_after: str | date | None = None,
|
|
271
311
|
published_before: str | date | None = None,
|
|
312
|
+
include_domains: list[str] | None = None,
|
|
272
313
|
goal: str | None = None,
|
|
273
314
|
context: str | None = None,
|
|
274
315
|
session: str | None = None,
|
|
@@ -332,6 +373,7 @@ class BaseClient:
|
|
|
332
373
|
topic=topic,
|
|
333
374
|
published_after=published_after,
|
|
334
375
|
published_before=published_before,
|
|
376
|
+
include_domains=include_domains,
|
|
335
377
|
)
|
|
336
378
|
if search:
|
|
337
379
|
body["search"] = search
|
|
@@ -347,6 +389,8 @@ class BaseClient:
|
|
|
347
389
|
inline_content: bool | None = None,
|
|
348
390
|
inline_max_chars: int | None = None,
|
|
349
391
|
content_format: str | None = None,
|
|
392
|
+
tier: str | None = None,
|
|
393
|
+
no_cache: bool | None = None,
|
|
350
394
|
session: str | None = None,
|
|
351
395
|
metadata: dict[str, Any] | None = None,
|
|
352
396
|
) -> dict[str, Any]:
|
|
@@ -376,6 +420,13 @@ class BaseClient:
|
|
|
376
420
|
"urls": url_list,
|
|
377
421
|
"metadata": dict(metadata) if metadata else {},
|
|
378
422
|
}
|
|
423
|
+
# A call argument wins; ``None`` falls back to the ``TELEM_FETCH_*`` default.
|
|
424
|
+
if providers is None and self.default_fetch_providers is not None:
|
|
425
|
+
providers = list(self.default_fetch_providers)
|
|
426
|
+
if tier is None:
|
|
427
|
+
tier = self.default_fetch_tier
|
|
428
|
+
if no_cache is None:
|
|
429
|
+
no_cache = self.default_fetch_no_cache
|
|
379
430
|
options: dict[str, Any] = {}
|
|
380
431
|
if providers is not None:
|
|
381
432
|
options["providers"] = providers
|
|
@@ -385,6 +436,10 @@ class BaseClient:
|
|
|
385
436
|
options["inline_max_chars"] = inline_max_chars
|
|
386
437
|
if content_format is not None:
|
|
387
438
|
options["content_format"] = content_format
|
|
439
|
+
if tier is not None:
|
|
440
|
+
options["tier"] = tier
|
|
441
|
+
if no_cache is not None:
|
|
442
|
+
options["no_cache"] = no_cache
|
|
388
443
|
if options:
|
|
389
444
|
body["options"] = options
|
|
390
445
|
if session is not None:
|
|
@@ -77,17 +77,18 @@ opencode and pi plugins apply, in this order:
|
|
|
77
77
|
1. A request may carry `tier` **or** `fields`, never both — the more specific level
|
|
78
78
|
wins; on a tie, `fields`.
|
|
79
79
|
2. When **both** `providersInclude` and `providersExclude` resolve, the exclusion is
|
|
80
|
-
subtracted from the include and only `providersInclude` is sent:
|
|
81
|
-
|
|
82
|
-
the
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
own is forwarded verbatim.
|
|
80
|
+
subtracted from the include and only `providersInclude` is sent: exclude wins, and
|
|
81
|
+
an include already replaces the deployment's default set. If the subtraction
|
|
82
|
+
empties the include, no provider is left: the search is refused before anything is
|
|
83
|
+
sent (`options.refusal`, raised by `search_kwargs`), and the message says where
|
|
84
|
+
each list was set. The default providers never run instead, because they could
|
|
85
|
+
include the one you excluded. `providersExclude` on its own is forwarded verbatim.
|
|
86
86
|
3. `providerOverrides` applies only alongside the resolved `providersInclude` and only
|
|
87
87
|
to providers named there — anything else is dropped rather than sent, because the
|
|
88
88
|
server rejects an override naming a provider the request did not select.
|
|
89
89
|
|
|
90
|
-
Each rule that drops something says so in `options.warnings
|
|
90
|
+
Each rule that drops something says so in `options.warnings`; a refused search says so
|
|
91
|
+
in `options.refusal`.
|
|
91
92
|
|
|
92
93
|
The **client itself never reads these files** — a library must not let a checked-out
|
|
93
94
|
repository steer an arbitrary program's spend. It does read
|
|
@@ -151,6 +151,8 @@ def main() -> None:
|
|
|
151
151
|
)
|
|
152
152
|
except TelemError as exc:
|
|
153
153
|
sys.exit(f"telem search failed: {exc.message}")
|
|
154
|
+
except ValueError as exc: # refused before sending, e.g. the config leaves no provider
|
|
155
|
+
sys.exit(f"telem search failed: {exc}")
|
|
154
156
|
except httpx.HTTPError as exc:
|
|
155
157
|
sys.exit(f"telem search failed: could not reach the Telem backend ({exc})")
|
|
156
158
|
|
|
@@ -122,6 +122,7 @@ class AsyncTelem(BaseClient):
|
|
|
122
122
|
topic: str | None = None,
|
|
123
123
|
published_after: str | date | None = None,
|
|
124
124
|
published_before: str | date | None = None,
|
|
125
|
+
include_domains: list[str] | None = None,
|
|
125
126
|
goal: str | None = None,
|
|
126
127
|
context: str | None = None,
|
|
127
128
|
session: str | None = None,
|
|
@@ -157,6 +158,9 @@ class AsyncTelem(BaseClient):
|
|
|
157
158
|
with no known publication date are kept.
|
|
158
159
|
published_before: Only return results published before this date or
|
|
159
160
|
date-time. A date with no time includes that whole day.
|
|
161
|
+
include_domains: Only return results from these domains, at most 20
|
|
162
|
+
hostnames such as ``"linkedin.com"``. A subdomain such as
|
|
163
|
+
``"uk.linkedin.com"`` matches its domain.
|
|
160
164
|
goal: Optional agent goal, merged into request metadata.
|
|
161
165
|
context: Optional context string, merged into request metadata.
|
|
162
166
|
session: Optional session id to continue an existing session.
|
|
@@ -180,6 +184,7 @@ class AsyncTelem(BaseClient):
|
|
|
180
184
|
topic=topic,
|
|
181
185
|
published_after=published_after,
|
|
182
186
|
published_before=published_before,
|
|
187
|
+
include_domains=include_domains,
|
|
183
188
|
goal=goal,
|
|
184
189
|
context=context,
|
|
185
190
|
session=session,
|
|
@@ -197,6 +202,8 @@ class AsyncTelem(BaseClient):
|
|
|
197
202
|
inline_content: bool | None = None,
|
|
198
203
|
inline_max_chars: int | None = None,
|
|
199
204
|
content_format: str | None = None,
|
|
205
|
+
tier: str | None = None,
|
|
206
|
+
no_cache: bool | None = None,
|
|
200
207
|
session: str | None = None,
|
|
201
208
|
metadata: dict[str, Any] | None = None,
|
|
202
209
|
) -> FetchResponse:
|
|
@@ -209,10 +216,17 @@ class AsyncTelem(BaseClient):
|
|
|
209
216
|
|
|
210
217
|
Args:
|
|
211
218
|
urls: The http(s) URLs to read (the server caps the batch size).
|
|
212
|
-
providers: Fetch provider chain override (e.g. ``["tavily"]``).
|
|
219
|
+
providers: Fetch provider chain override (e.g. ``["tavily"]``). Defaults to
|
|
220
|
+
``TELEM_FETCH_PROVIDERS``.
|
|
213
221
|
inline_content: Whether to inline page content in the response.
|
|
214
222
|
inline_max_chars: Max inlined characters per page.
|
|
215
223
|
content_format: Requested content format (e.g. ``"markdown"``).
|
|
224
|
+
tier: Fetch tier: ``"minimalist"``, ``"default"``, ``"extended"`` or ``"max"``
|
|
225
|
+
(sent as given; the server rejects an unknown one). Defaults to
|
|
226
|
+
``TELEM_FETCH_TIER``, lowercased.
|
|
227
|
+
no_cache: ``True`` reads every page live and skips the shared fetch cache.
|
|
228
|
+
Defaults to ``TELEM_FETCH_NO_CACHE`` (on with exactly ``"1"``); ``False``
|
|
229
|
+
overrides it.
|
|
216
230
|
session: Optional session id to continue an existing session.
|
|
217
231
|
metadata: Additional request metadata.
|
|
218
232
|
|
|
@@ -226,6 +240,8 @@ class AsyncTelem(BaseClient):
|
|
|
226
240
|
inline_content=inline_content,
|
|
227
241
|
inline_max_chars=inline_max_chars,
|
|
228
242
|
content_format=content_format,
|
|
243
|
+
tier=tier,
|
|
244
|
+
no_cache=no_cache,
|
|
229
245
|
session=session,
|
|
230
246
|
metadata=metadata,
|
|
231
247
|
)
|
|
@@ -122,6 +122,7 @@ class Telem(BaseClient):
|
|
|
122
122
|
topic: str | None = None,
|
|
123
123
|
published_after: str | date | None = None,
|
|
124
124
|
published_before: str | date | None = None,
|
|
125
|
+
include_domains: list[str] | None = None,
|
|
125
126
|
goal: str | None = None,
|
|
126
127
|
context: str | None = None,
|
|
127
128
|
session: str | None = None,
|
|
@@ -157,6 +158,9 @@ class Telem(BaseClient):
|
|
|
157
158
|
with no known publication date are kept.
|
|
158
159
|
published_before: Only return results published before this date or
|
|
159
160
|
date-time. A date with no time includes that whole day.
|
|
161
|
+
include_domains: Only return results from these domains, at most 20
|
|
162
|
+
hostnames such as ``"linkedin.com"``. A subdomain such as
|
|
163
|
+
``"uk.linkedin.com"`` matches its domain.
|
|
160
164
|
goal: Optional agent goal, merged into request metadata.
|
|
161
165
|
context: Optional context string, merged into request metadata.
|
|
162
166
|
session: Optional session id to continue an existing session.
|
|
@@ -180,6 +184,7 @@ class Telem(BaseClient):
|
|
|
180
184
|
topic=topic,
|
|
181
185
|
published_after=published_after,
|
|
182
186
|
published_before=published_before,
|
|
187
|
+
include_domains=include_domains,
|
|
183
188
|
goal=goal,
|
|
184
189
|
context=context,
|
|
185
190
|
session=session,
|
|
@@ -197,6 +202,8 @@ class Telem(BaseClient):
|
|
|
197
202
|
inline_content: bool | None = None,
|
|
198
203
|
inline_max_chars: int | None = None,
|
|
199
204
|
content_format: str | None = None,
|
|
205
|
+
tier: str | None = None,
|
|
206
|
+
no_cache: bool | None = None,
|
|
200
207
|
session: str | None = None,
|
|
201
208
|
metadata: dict[str, Any] | None = None,
|
|
202
209
|
) -> FetchResponse:
|
|
@@ -209,10 +216,17 @@ class Telem(BaseClient):
|
|
|
209
216
|
|
|
210
217
|
Args:
|
|
211
218
|
urls: The http(s) URLs to read (the server caps the batch size).
|
|
212
|
-
providers: Fetch provider chain override (e.g. ``["tavily"]``).
|
|
219
|
+
providers: Fetch provider chain override (e.g. ``["tavily"]``). Defaults to
|
|
220
|
+
``TELEM_FETCH_PROVIDERS``.
|
|
213
221
|
inline_content: Whether to inline page content in the response.
|
|
214
222
|
inline_max_chars: Max inlined characters per page.
|
|
215
223
|
content_format: Requested content format (e.g. ``"markdown"``).
|
|
224
|
+
tier: Fetch tier: ``"minimalist"``, ``"default"``, ``"extended"`` or ``"max"``
|
|
225
|
+
(sent as given; the server rejects an unknown one). Defaults to
|
|
226
|
+
``TELEM_FETCH_TIER``, lowercased.
|
|
227
|
+
no_cache: ``True`` reads every page live and skips the shared fetch cache.
|
|
228
|
+
Defaults to ``TELEM_FETCH_NO_CACHE`` (on with exactly ``"1"``); ``False``
|
|
229
|
+
overrides it.
|
|
216
230
|
session: Optional session id to continue an existing session.
|
|
217
231
|
metadata: Additional request metadata.
|
|
218
232
|
|
|
@@ -226,6 +240,8 @@ class Telem(BaseClient):
|
|
|
226
240
|
inline_content=inline_content,
|
|
227
241
|
inline_max_chars=inline_max_chars,
|
|
228
242
|
content_format=content_format,
|
|
243
|
+
tier=tier,
|
|
244
|
+
no_cache=no_cache,
|
|
229
245
|
session=session,
|
|
230
246
|
metadata=metadata,
|
|
231
247
|
)
|
|
@@ -26,7 +26,10 @@ the user's project (the MCP server, a skill script run by the agent) passes
|
|
|
26
26
|
**It never raises.** A missing, unreadable, malformed, hostile or wrong-typed file is
|
|
27
27
|
ABSENT, and the next level supplies the key instead; everything ignored comes back in
|
|
28
28
|
:attr:`SearchOptionsResolution.warnings` for the caller to print (this module never
|
|
29
|
-
prints).
|
|
29
|
+
prints). A config that can run no search (``providersExclude`` removes every provider in
|
|
30
|
+
``providersInclude``) is not an error here either: it comes back as
|
|
31
|
+
:attr:`SearchOptionsResolution.refusal`, and :meth:`SearchOptionsResolution.search_kwargs`
|
|
32
|
+
raises it as ``ValueError``, so no request goes out.
|
|
30
33
|
|
|
31
34
|
The reading itself lives in :mod:`telem._config_files`, the corpus-pinned Python mirror
|
|
32
35
|
of ``config-core``. What this module adds is the three composition rules that a *caller*
|
|
@@ -39,14 +42,19 @@ because each one decides what the next one sees.
|
|
|
39
42
|
from __future__ import annotations
|
|
40
43
|
|
|
41
44
|
import os
|
|
42
|
-
from collections.abc import Mapping, Sequence
|
|
45
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
43
46
|
from dataclasses import dataclass, field
|
|
44
47
|
from types import MappingProxyType
|
|
45
48
|
from typing import Any
|
|
46
49
|
|
|
47
|
-
from telem._config_files import resolve_options
|
|
50
|
+
from telem._config_files import CONFIG_FILE_NAME, TELEM_OPTIONS, option_from_env, resolve_options
|
|
48
51
|
|
|
49
|
-
__all__ = [
|
|
52
|
+
__all__ = [
|
|
53
|
+
"FetchOptionsResolution",
|
|
54
|
+
"SearchOptionsResolution",
|
|
55
|
+
"resolve_fetch_options",
|
|
56
|
+
"resolve_search_options",
|
|
57
|
+
]
|
|
50
58
|
|
|
51
59
|
#: Config key -> ``client.search()`` keyword argument. The ONE place the two
|
|
52
60
|
#: vocabularies meet: the config file speaks the cross-harness names of the contract, the
|
|
@@ -73,6 +81,12 @@ _SEARCH_KWARGS: Mapping[str, str] = MappingProxyType(
|
|
|
73
81
|
}
|
|
74
82
|
)
|
|
75
83
|
|
|
84
|
+
#: Fetch config key -> ``client.fetch()`` keyword argument, in the block's key order. Its
|
|
85
|
+
#: keys are the FETCH keys of the option table, the ones a search never sends.
|
|
86
|
+
_FETCH_KWARGS: Mapping[str, str] = MappingProxyType(
|
|
87
|
+
{"fetchProviders": "providers", "fetchTier": "tier", "fetchNoCache": "no_cache"}
|
|
88
|
+
)
|
|
89
|
+
|
|
76
90
|
#: Precedence rank of each level, lower wins. Mirrors ``layerRank`` in
|
|
77
91
|
#: the shared config contract over the three levels a Python reader has, plus
|
|
78
92
|
#: ``"call"`` — the caller's own override, above every level, which is the harness
|
|
@@ -104,6 +118,10 @@ class SearchOptionsResolution:
|
|
|
104
118
|
#: values the composition rules dropped. Print them to **stderr** — never into
|
|
105
119
|
#: text a model reads.
|
|
106
120
|
warnings: tuple[str, ...] = ()
|
|
121
|
+
#: Set when this config can run no search: ``providersExclude`` removes every
|
|
122
|
+
#: provider in ``providersInclude``. The provider keys are then absent from
|
|
123
|
+
#: ``values``, and :meth:`search_kwargs` raises this message, so no request goes out.
|
|
124
|
+
refusal: str | None = None
|
|
107
125
|
|
|
108
126
|
def search_kwargs(self) -> dict[str, Any]:
|
|
109
127
|
"""The resolved options as ``client.search()`` keyword arguments.
|
|
@@ -114,7 +132,14 @@ class SearchOptionsResolution:
|
|
|
114
132
|
rather than ``None``, so they leave the client's defaults alone.
|
|
115
133
|
|
|
116
134
|
A fresh, ordinary ``dict`` each call: it is made to be splatted and edited.
|
|
135
|
+
|
|
136
|
+
Raises:
|
|
137
|
+
ValueError: :attr:`refusal` is set. Searching without the provider keys
|
|
138
|
+
would run the deployment's default set, which can hold the provider
|
|
139
|
+
the user excluded.
|
|
117
140
|
"""
|
|
141
|
+
if self.refusal is not None:
|
|
142
|
+
raise ValueError(self.refusal)
|
|
118
143
|
return {_SEARCH_KWARGS[key]: value for key, value in self.values.items()}
|
|
119
144
|
|
|
120
145
|
|
|
@@ -175,12 +200,19 @@ def resolve_search_options(
|
|
|
175
200
|
_compose_tier_fields(values, sources, warnings)
|
|
176
201
|
# BEFORE the overrides guard: the guard checks membership against the include the
|
|
177
202
|
# request will actually carry, which is the SUBTRACTED one.
|
|
178
|
-
_compose_providers(
|
|
179
|
-
|
|
203
|
+
refusal = _compose_providers(
|
|
204
|
+
values,
|
|
205
|
+
warnings,
|
|
206
|
+
lambda key: _source_phrase(key, sources.get(key, ""), resolution.telem_dir, environ),
|
|
207
|
+
)
|
|
208
|
+
# A refused search sends no overrides, so the guard has nothing to say.
|
|
209
|
+
if refusal is None:
|
|
210
|
+
_guard_provider_overrides(values, warnings)
|
|
180
211
|
return SearchOptionsResolution(
|
|
181
212
|
values=MappingProxyType(values),
|
|
182
213
|
sources=MappingProxyType(sources),
|
|
183
214
|
warnings=tuple(warnings),
|
|
215
|
+
refusal=refusal,
|
|
184
216
|
)
|
|
185
217
|
|
|
186
218
|
|
|
@@ -214,17 +246,53 @@ def _compose_tier_fields(
|
|
|
214
246
|
)
|
|
215
247
|
|
|
216
248
|
|
|
217
|
-
def
|
|
249
|
+
def _source_phrase(key: str, level: str, telem_dir: str, env: Mapping[str, str]) -> str:
|
|
250
|
+
"""Where a provider list was set, as the end of "set …" in a refusal. Mirrors
|
|
251
|
+
``sourcePhrase`` in the shared config contract, so every surface says the same
|
|
252
|
+
words for the same tree."""
|
|
253
|
+
if level == "call":
|
|
254
|
+
return "by the providers_include argument"
|
|
255
|
+
if level == "project":
|
|
256
|
+
return "in the project's .telem/telem.json"
|
|
257
|
+
if level == "env":
|
|
258
|
+
spec = next(option for option in TELEM_OPTIONS if option.key == key)
|
|
259
|
+
names = [spec.env or key, *spec.env_aliases]
|
|
260
|
+
found = [n for n in names if option_from_env(spec._replace(env=n, env_aliases=()), env)]
|
|
261
|
+
return f"by {(found or names)[0]}"
|
|
262
|
+
return f"in {os.path.join(telem_dir, CONFIG_FILE_NAME)}"
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def providers_refusal(include: Sequence[str], in_include: str, in_exclude: str) -> str:
|
|
266
|
+
"""The refusal for a config whose ``providersExclude`` removes every provider in its
|
|
267
|
+
``providersInclude``. Mirrors ``providersRefusal`` in the shared config contract."""
|
|
268
|
+
names = ", ".join(include)
|
|
269
|
+
if in_include == in_exclude:
|
|
270
|
+
fix = f"Remove {names} from one of the two lists {in_include}."
|
|
271
|
+
else:
|
|
272
|
+
fix = (
|
|
273
|
+
f"Remove {names} from providersInclude (set {in_include}) "
|
|
274
|
+
f"or from providersExclude (set {in_exclude})."
|
|
275
|
+
)
|
|
276
|
+
return (
|
|
277
|
+
f"[telem] providersExclude removes every provider in providersInclude ({names}), "
|
|
278
|
+
f"so no provider is left and no search was sent. {fix}"
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _compose_providers(
|
|
283
|
+
values: dict[str, Any], warnings: list[str], source_of: Callable[[str], str]
|
|
284
|
+
) -> str | None:
|
|
218
285
|
"""When both provider halves resolve, ``exclude`` is subtracted from ``include``
|
|
219
286
|
here and only the subtracted ``include`` is sent.
|
|
220
287
|
|
|
221
|
-
The
|
|
222
|
-
same provider with a 400
|
|
223
|
-
|
|
224
|
-
ladder, so a user file's ``providersExclude`` meets a project file's
|
|
288
|
+
The router used to answer ``search.providers.include`` and ``exclude`` naming the
|
|
289
|
+
same provider with a 400 (since 2026-10-26 it subtracts too, and answers 400 only
|
|
290
|
+
when nothing is left). Both halves resolving is not exotic: they resolve PER KEY
|
|
291
|
+
over the ladder, so a user file's ``providersExclude`` meets a project file's
|
|
225
292
|
``providersInclude`` the moment two people configure the thing they each cared
|
|
226
293
|
about. Forwarding that pair verbatim made a checked-in config break EVERY search in
|
|
227
|
-
the repository, with a message about the request rather than about the file.
|
|
294
|
+
the repository, with a message about the request rather than about the file. The
|
|
295
|
+
client subtracts first so its message can name the file.
|
|
228
296
|
|
|
229
297
|
Subtracting is not a reinterpretation: ``include`` REPLACES the deployment's default
|
|
230
298
|
set, so once it resolves it already names the whole candidate set, and "run
|
|
@@ -233,21 +301,21 @@ def _compose_providers(values: dict[str, Any], warnings: list[str]) -> None:
|
|
|
233
301
|
wire body is now the same bytes from every surface rather than two dialects of one
|
|
234
302
|
config file.
|
|
235
303
|
|
|
236
|
-
An emptied ``include``
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
304
|
+
An emptied ``include`` REFUSES the search (owner design, 2026-10-26): both
|
|
305
|
+
halves and ``providerOverrides`` leave ``values``, and the refusal is returned, for
|
|
306
|
+
:meth:`SearchOptionsResolution.search_kwargs` to raise. Running the deployment's
|
|
307
|
+
default set instead could search the very provider the user excluded. A disjoint
|
|
308
|
+
pair is silent — dropping a no-op is not news. ``exclude`` ALONE keeps riding
|
|
309
|
+
verbatim: with no ``include`` the set it subtracts from is the deployment default,
|
|
310
|
+
which this process cannot enumerate.
|
|
243
311
|
|
|
244
|
-
Mirrors ``composeProviders`` in the shared config contract and in the
|
|
245
|
-
vendored
|
|
312
|
+
Mirrors ``composeProviders`` in the shared config contract and in the three
|
|
313
|
+
vendored readers; the shared corpus pins that they agree on the byte.
|
|
246
314
|
"""
|
|
247
315
|
include = values.get("providersInclude")
|
|
248
316
|
exclude = values.get("providersExclude")
|
|
249
317
|
if not isinstance(include, list) or not isinstance(exclude, list):
|
|
250
|
-
return
|
|
318
|
+
return None
|
|
251
319
|
|
|
252
320
|
excluded = set(exclude)
|
|
253
321
|
kept = [name for name in include if name not in excluded]
|
|
@@ -256,23 +324,16 @@ def _compose_providers(values: dict[str, Any], warnings: list[str]) -> None:
|
|
|
256
324
|
|
|
257
325
|
if kept:
|
|
258
326
|
values["providersInclude"] = kept
|
|
259
|
-
if
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
"is sent."
|
|
266
|
-
)
|
|
267
|
-
return
|
|
327
|
+
if dropped:
|
|
328
|
+
warnings.append(
|
|
329
|
+
f"[telem] providersExclude removes {', '.join(dropped)} from providersInclude: "
|
|
330
|
+
f"this search runs {', '.join(kept)}."
|
|
331
|
+
)
|
|
332
|
+
return None
|
|
268
333
|
|
|
269
334
|
del values["providersInclude"]
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
f"providersInclude ({', '.join(include)}): this config resolves to an EMPTY provider "
|
|
273
|
-
"set, which no search can run, so BOTH halves are dropped and the deployment's default "
|
|
274
|
-
"provider set is running instead."
|
|
275
|
-
)
|
|
335
|
+
values.pop("providerOverrides", None)
|
|
336
|
+
return providers_refusal(include, source_of("providersInclude"), source_of("providersExclude"))
|
|
276
337
|
|
|
277
338
|
|
|
278
339
|
def _guard_provider_overrides(values: dict[str, Any], warnings: list[str]) -> None:
|
|
@@ -321,3 +382,76 @@ def _guard_provider_overrides(values: dict[str, Any], warnings: list[str]) -> No
|
|
|
321
382
|
"providersInclude REPLACES the deployment's default provider set with exactly the "
|
|
322
383
|
"providers you list, rather than adding to it."
|
|
323
384
|
)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
@dataclass(frozen=True)
|
|
388
|
+
class FetchOptionsResolution:
|
|
389
|
+
"""The fetch options resolved from the unified config, and everything ignored on the way.
|
|
390
|
+
|
|
391
|
+
The fetch half of the same files and environment that :func:`resolve_search_options`
|
|
392
|
+
reads: ``fetchProviders``, ``fetchTier`` and ``fetchNoCache`` only.
|
|
393
|
+
"""
|
|
394
|
+
|
|
395
|
+
#: Only the FETCH keys that resolved, under their config names. An absent key is not
|
|
396
|
+
#: present — never ``None``.
|
|
397
|
+
values: Mapping[str, Any] = field(default_factory=lambda: MappingProxyType({}))
|
|
398
|
+
#: ``"project"`` | ``"user"`` | ``"env"`` per resolved key, keyed like ``values``.
|
|
399
|
+
sources: Mapping[str, str] = field(default_factory=lambda: MappingProxyType({}))
|
|
400
|
+
#: The reader's warnings (an ignored file, a refused relocation). Print them to
|
|
401
|
+
#: **stderr** — never into text a model reads.
|
|
402
|
+
warnings: tuple[str, ...] = ()
|
|
403
|
+
|
|
404
|
+
def fetch_kwargs(self) -> dict[str, Any]:
|
|
405
|
+
"""The resolved options as ``client.fetch()`` keyword arguments, in the block's key
|
|
406
|
+
order (``providers``, ``tier``, ``no_cache``).
|
|
407
|
+
|
|
408
|
+
``tier`` is lowercased, because fetch tiers are case-insensitive; that is
|
|
409
|
+
normalization, not validation, so an unknown tier is still sent for the server to
|
|
410
|
+
reject. Provider names go as written, and ``no_cache`` as resolved, so a file's
|
|
411
|
+
``false`` is sent as ``false``. A fresh ``dict`` each call.
|
|
412
|
+
"""
|
|
413
|
+
kwargs: dict[str, Any] = {}
|
|
414
|
+
for key, kwarg in _FETCH_KWARGS.items():
|
|
415
|
+
if key not in self.values:
|
|
416
|
+
continue
|
|
417
|
+
value = self.values[key]
|
|
418
|
+
if key == "fetchTier":
|
|
419
|
+
value = value.lower()
|
|
420
|
+
elif key == "fetchProviders":
|
|
421
|
+
value = list(value)
|
|
422
|
+
kwargs[kwarg] = value
|
|
423
|
+
return kwargs
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def resolve_fetch_options(
|
|
427
|
+
*,
|
|
428
|
+
project_root: str | None = None,
|
|
429
|
+
env: Mapping[str, str] | None = None,
|
|
430
|
+
) -> FetchOptionsResolution:
|
|
431
|
+
"""Resolve the fetch keys of the unified Telem config: project file > user file >
|
|
432
|
+
``TELEM_FETCH_*`` env, per key.
|
|
433
|
+
|
|
434
|
+
The fetch twin of :func:`resolve_search_options`, with the same opt-in project level
|
|
435
|
+
and the same never-raises rule. No composition rule applies to the fetch keys.
|
|
436
|
+
|
|
437
|
+
Args:
|
|
438
|
+
project_root: The user's project directory, enabling the project level. ``None``
|
|
439
|
+
— the default — reads no repo-local file at all.
|
|
440
|
+
env: Environment to read, defaulting to :data:`os.environ`.
|
|
441
|
+
|
|
442
|
+
Returns:
|
|
443
|
+
A :class:`FetchOptionsResolution`. Never raises: everything that went wrong is a
|
|
444
|
+
warning.
|
|
445
|
+
"""
|
|
446
|
+
environ = os.environ if env is None else env
|
|
447
|
+
try:
|
|
448
|
+
resolution = resolve_options(environ, project_root)
|
|
449
|
+
except Exception as error: # pragma: no cover - defense in depth, as for search
|
|
450
|
+
return FetchOptionsResolution(warnings=(f"[telem] ignoring the Telem config: {error}",))
|
|
451
|
+
values = {key: value for key, value in resolution.values.items() if key in _FETCH_KWARGS}
|
|
452
|
+
sources = {key: level for key, level in resolution.sources.items() if key in _FETCH_KWARGS}
|
|
453
|
+
return FetchOptionsResolution(
|
|
454
|
+
values=MappingProxyType(values),
|
|
455
|
+
sources=MappingProxyType(sources),
|
|
456
|
+
warnings=tuple(resolution.warnings),
|
|
457
|
+
)
|
|
@@ -44,7 +44,7 @@ from collections.abc import Awaitable, Callable
|
|
|
44
44
|
from typing import Any
|
|
45
45
|
from urllib.parse import unquote, urlsplit
|
|
46
46
|
|
|
47
|
-
from telem import AsyncTelem, resolve_search_options
|
|
47
|
+
from telem import AsyncTelem, resolve_fetch_options, resolve_search_options
|
|
48
48
|
from telem.errors import APIStatusError
|
|
49
49
|
from telem.integrations import _hermes_state, _trajectory_v5, _update_advisory
|
|
50
50
|
from telem.integrations._tools import (
|
|
@@ -331,8 +331,10 @@ def project_root() -> str:
|
|
|
331
331
|
def _search_options() -> dict[str, Any]:
|
|
332
332
|
"""Resolve project file > user file > ``TELEM_*`` for this call.
|
|
333
333
|
|
|
334
|
-
|
|
335
|
-
|
|
334
|
+
Anything ignored comes back as a warning, which goes to the host log and never
|
|
335
|
+
into the text the model reads. Raises ``ValueError`` before any network call
|
|
336
|
+
when the config can run no search (``providersExclude`` removes every provider
|
|
337
|
+
in ``providersInclude``); the message says which lists to fix.
|
|
336
338
|
"""
|
|
337
339
|
resolution = resolve_search_options(project_root=project_root())
|
|
338
340
|
for warning in resolution.warnings:
|
|
@@ -340,6 +342,19 @@ def _search_options() -> dict[str, Any]:
|
|
|
340
342
|
return resolution.search_kwargs()
|
|
341
343
|
|
|
342
344
|
|
|
345
|
+
def _fetch_options() -> dict[str, Any]:
|
|
346
|
+
"""Resolve the fetch keys (``fetchProviders``, ``fetchTier``, ``fetchNoCache``) over
|
|
347
|
+
project file > user file > ``TELEM_FETCH_*`` for this call, as ``client.fetch()``
|
|
348
|
+
keyword arguments.
|
|
349
|
+
|
|
350
|
+
Never raises; anything ignored is logged, never put into the text the model reads.
|
|
351
|
+
"""
|
|
352
|
+
resolution = resolve_fetch_options(project_root=project_root())
|
|
353
|
+
for warning in resolution.warnings:
|
|
354
|
+
logger.warning("%s", warning)
|
|
355
|
+
return resolution.fetch_kwargs()
|
|
356
|
+
|
|
357
|
+
|
|
343
358
|
def build_trajectory(
|
|
344
359
|
kind: str,
|
|
345
360
|
session_id: Any = None,
|
|
@@ -653,11 +668,12 @@ async def telem_search(args: dict, **kwargs: Any) -> str:
|
|
|
653
668
|
async def telem_fetch(args: dict, **kwargs: Any) -> str:
|
|
654
669
|
urls = normalize_urls((args or {}).get("urls"))
|
|
655
670
|
await assert_urls_safe(urls)
|
|
671
|
+
options = _fetch_options()
|
|
656
672
|
|
|
657
673
|
async with AsyncTelem() as client:
|
|
658
674
|
plan = _delivery_plan(client)
|
|
659
675
|
metadata = build_trajectory("fetch", kwargs.get("session_id"), kwargs.get("task_id"), plan)
|
|
660
|
-
response = await _send(plan, lambda: client.fetch(urls, metadata=metadata))
|
|
676
|
+
response = await _send(plan, lambda: client.fetch(urls, metadata=metadata, **options))
|
|
661
677
|
return wrap_untrusted("telem_fetch", render_fetch(response))
|
|
662
678
|
|
|
663
679
|
|
|
@@ -137,6 +137,9 @@ class ProviderInfo(BaseModel):
|
|
|
137
137
|
url: str | None = None
|
|
138
138
|
normalized: bool = False
|
|
139
139
|
tiers: list[str] = Field(default_factory=list)
|
|
140
|
+
#: Whether auto-routing can pick it for a ranked topic. ``None`` from a router
|
|
141
|
+
#: that does not say.
|
|
142
|
+
auto_routed: bool | None = None
|
|
140
143
|
|
|
141
144
|
|
|
142
145
|
class SessionSummary(BaseModel):
|
|
@@ -17,12 +17,21 @@ if TYPE_CHECKING:
|
|
|
17
17
|
|
|
18
18
|
def _create_body(
|
|
19
19
|
query: str,
|
|
20
|
-
frequency: str,
|
|
20
|
+
frequency: str | None,
|
|
21
21
|
metadata: dict[str, Any] | None,
|
|
22
22
|
webhook_url: str | None,
|
|
23
23
|
ttl: str | None,
|
|
24
|
+
search: dict[str, Any] | None,
|
|
25
|
+
include_domains: list[str] | None,
|
|
24
26
|
) -> dict[str, Any]:
|
|
25
|
-
|
|
27
|
+
options: dict[str, Any] = {}
|
|
28
|
+
if frequency is not None:
|
|
29
|
+
options["frequency"] = frequency
|
|
30
|
+
if include_domains is not None:
|
|
31
|
+
options["include_domains"] = include_domains
|
|
32
|
+
if search is not None:
|
|
33
|
+
options["search"] = _search_block(search)
|
|
34
|
+
body: dict[str, Any] = {"query": query, "options": options}
|
|
26
35
|
if metadata is not None:
|
|
27
36
|
body["metadata"] = metadata
|
|
28
37
|
if webhook_url is not None:
|
|
@@ -32,6 +41,19 @@ def _create_body(
|
|
|
32
41
|
return body
|
|
33
42
|
|
|
34
43
|
|
|
44
|
+
def _search_block(search: dict[str, Any]) -> dict[str, Any]:
|
|
45
|
+
"""The monitor's search options for the wire: the keys of ``search()``, with
|
|
46
|
+
``providers_include``/``providers_exclude`` as ``providers``. No client
|
|
47
|
+
default applies: a monitor's search is set on the monitor alone."""
|
|
48
|
+
block = {k: v for k, v in search.items() if not k.startswith("providers_")}
|
|
49
|
+
providers = {
|
|
50
|
+
k.removeprefix("providers_"): v for k, v in search.items() if k.startswith("providers_")
|
|
51
|
+
}
|
|
52
|
+
if providers:
|
|
53
|
+
block["providers"] = providers
|
|
54
|
+
return block
|
|
55
|
+
|
|
56
|
+
|
|
35
57
|
def _update_body(
|
|
36
58
|
status: str | None,
|
|
37
59
|
frequency: str | None,
|
|
@@ -99,26 +121,34 @@ class MonitorsResource:
|
|
|
99
121
|
self,
|
|
100
122
|
query: str,
|
|
101
123
|
*,
|
|
102
|
-
frequency: str,
|
|
124
|
+
frequency: str | None = None,
|
|
103
125
|
metadata: dict[str, Any] | None = None,
|
|
104
126
|
webhook_url: str | None = None,
|
|
105
127
|
ttl: str | None = None,
|
|
128
|
+
search: dict[str, Any] | None = None,
|
|
129
|
+
include_domains: list[str] | None = None,
|
|
106
130
|
) -> Monitor:
|
|
107
131
|
"""Create a monitor. Telem runs ``query`` on the schedule.
|
|
108
132
|
|
|
109
133
|
Args:
|
|
110
134
|
query: What to watch for, as a plain sentence.
|
|
111
|
-
frequency: ``"1h"``, ``"6h"``, ``"1d"`` or ``"7d"``.
|
|
135
|
+
frequency: ``"1h"``, ``"6h"``, ``"12h"``, ``"1d"`` or ``"7d"``. If you leave it
|
|
136
|
+
out, the monitor runs once a day.
|
|
112
137
|
metadata: Request metadata (query lineage keys), as in a search.
|
|
113
138
|
webhook_url: An ``https`` URL that receives the new results.
|
|
114
139
|
ttl: Delete the monitor after this long, such as ``"12h"`` or ``"7d"``
|
|
115
140
|
(at most ``"30d"``). Without it, the monitor never expires.
|
|
141
|
+
search: Also run a web search for ``query`` on the schedule, with these
|
|
142
|
+
search options, named as in :meth:`Telem.search`: ``num_results`` and ``tier``.
|
|
143
|
+
``{}`` uses the defaults.
|
|
144
|
+
include_domains: Only results from these sites and their subdomains, such as
|
|
145
|
+
``["sec.gov"]``, from every source of the monitor.
|
|
116
146
|
|
|
117
147
|
Returns:
|
|
118
148
|
The new :class:`Monitor`. With ``webhook_url``, its ``webhook_secret``
|
|
119
149
|
signs the deliveries; Telem shows it only in this response.
|
|
120
150
|
"""
|
|
121
|
-
body = _create_body(query, frequency, metadata, webhook_url, ttl)
|
|
151
|
+
body = _create_body(query, frequency, metadata, webhook_url, ttl, search, include_domains)
|
|
122
152
|
return Monitor.model_validate(self._client._post("/v1/monitors", body))
|
|
123
153
|
|
|
124
154
|
def list(self, *, limit: int | None = None) -> list[Monitor]:
|
|
@@ -191,13 +221,15 @@ class AsyncMonitorsResource:
|
|
|
191
221
|
self,
|
|
192
222
|
query: str,
|
|
193
223
|
*,
|
|
194
|
-
frequency: str,
|
|
224
|
+
frequency: str | None = None,
|
|
195
225
|
metadata: dict[str, Any] | None = None,
|
|
196
226
|
webhook_url: str | None = None,
|
|
197
227
|
ttl: str | None = None,
|
|
228
|
+
search: dict[str, Any] | None = None,
|
|
229
|
+
include_domains: list[str] | None = None,
|
|
198
230
|
) -> Monitor:
|
|
199
231
|
"""Create a monitor. See :meth:`MonitorsResource.create`."""
|
|
200
|
-
body = _create_body(query, frequency, metadata, webhook_url, ttl)
|
|
232
|
+
body = _create_body(query, frequency, metadata, webhook_url, ttl, search, include_domains)
|
|
201
233
|
return Monitor.model_validate(await self._client._post("/v1/monitors", body))
|
|
202
234
|
|
|
203
235
|
async def list(self, *, limit: int | None = None) -> list[Monitor]:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|