evalrouter 0.3.4__tar.gz → 0.3.6__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.
- evalrouter-0.3.4/README.md → evalrouter-0.3.6/PKG-INFO +58 -0
- evalrouter-0.3.4/PKG-INFO → evalrouter-0.3.6/README.md +38 -15
- {evalrouter-0.3.4 → evalrouter-0.3.6}/pyproject.toml +4 -1
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/evalrouter_contracts/__init__.py +1 -1
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/__init__.py +10 -1
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/_account.py +201 -21
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/_guided.py +55 -7
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/_resources.py +496 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/cli.py +151 -36
- evalrouter-0.3.6/src/kimpton_evalrouter/langsmith.py +936 -0
- evalrouter-0.3.6/src/kimpton_evalrouter/render/picker.py +426 -0
- evalrouter-0.3.6/src/kimpton_evalrouter/tracing.py +360 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/types.py +743 -1
- evalrouter-0.3.4/src/kimpton_evalrouter/render/picker.py +0 -230
- {evalrouter-0.3.4 → evalrouter-0.3.6}/LICENSE +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/evalrouter_contracts/bundle.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/evalrouter_contracts/components.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/evalrouter_contracts/models.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/evalrouter_contracts/protocol.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/evalrouter_contracts/py.typed +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/evalrouter_contracts/templates.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/evalrouter_contracts/validation.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/__main__.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/_boundary.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/_helpers.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/_listing.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/_transport.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/py.typed +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/render/__init__.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/render/_console.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/render/_theme.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/render/_widgets.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/render/live.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/render/screens.py +0 -0
- {evalrouter-0.3.4 → evalrouter-0.3.6}/src/kimpton_evalrouter/render/tables.py +0 -0
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evalrouter
|
|
3
|
+
Version: 0.3.6
|
|
4
|
+
Summary: Typed Kimpton evaluation client and command-line interface
|
|
5
|
+
License-Expression: LicenseRef-Kimpton-EvalRouter-SDK
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: <3.14,>=3.12
|
|
8
|
+
Requires-Dist: httpx==0.28.1
|
|
9
|
+
Requires-Dist: rich==15.0.0
|
|
10
|
+
Provides-Extra: benchmark
|
|
11
|
+
Requires-Dist: pydantic==2.13.5; extra == 'benchmark'
|
|
12
|
+
Provides-Extra: keyring
|
|
13
|
+
Requires-Dist: keyring==25.7.0; extra == 'keyring'
|
|
14
|
+
Provides-Extra: langsmith
|
|
15
|
+
Requires-Dist: langsmith==0.12.6; extra == 'langsmith'
|
|
16
|
+
Provides-Extra: tracing
|
|
17
|
+
Requires-Dist: opentelemetry-api==1.45.0; extra == 'tracing'
|
|
18
|
+
Requires-Dist: opentelemetry-sdk==1.45.0; extra == 'tracing'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
1
21
|
# EvalRouter CLI
|
|
2
22
|
|
|
3
23
|
Evaluate models or qualified repository agents from your terminal: discover
|
|
@@ -44,6 +64,26 @@ CI and services can use `EVALROUTER_API_KEY` and `EVALROUTER_WORKSPACE_ID` suppl
|
|
|
44
64
|
privately by a secret manager. Never put credentials in arguments, URLs, request
|
|
45
65
|
files or logs.
|
|
46
66
|
|
|
67
|
+
## Import LangSmith traces
|
|
68
|
+
|
|
69
|
+
The optional `langsmith` extra provides a local connector for completed agent
|
|
70
|
+
runs. Create a LangSmith connection in **Traces → Connect agent**, then supply
|
|
71
|
+
`LANGSMITH_API_KEY` and the connection's EvalRouter environment variables through
|
|
72
|
+
your secret manager. The source key is never sent to EvalRouter.
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
pip install 'evalrouter[langsmith]'
|
|
76
|
+
python -m kimpton_evalrouter.langsmith projects
|
|
77
|
+
python -m kimpton_evalrouter.langsmith sync --project 'YOUR_PROJECT_ID' \
|
|
78
|
+
--state './evalrouter-langsmith-state.json' --watch
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The process must stay running for automatic imports. Its private checkpoint
|
|
82
|
+
resumes progress across restarts. Set `--since` to an ISO timestamp to choose
|
|
83
|
+
the initial import window. Inputs and outputs are bounded and field-name
|
|
84
|
+
redacted; only activity recorded by LangSmith can be imported. This connector
|
|
85
|
+
requires a package build that includes the `langsmith` extra.
|
|
86
|
+
|
|
47
87
|
## Run an evaluation in one command
|
|
48
88
|
|
|
49
89
|
```sh
|
|
@@ -262,3 +302,21 @@ Replace the coverage placeholder with the entire returned object; do not guess
|
|
|
262
302
|
tasks, counts or seeds. Use the existing `quote`, `run`, `wait`, `results` and
|
|
263
303
|
`export` commands above. Qualification and evaluation have separate caps and
|
|
264
304
|
charges. A qualification pass does not submit an evaluation automatically.
|
|
305
|
+
|
|
306
|
+
## Live agent capture
|
|
307
|
+
|
|
308
|
+
Install `evalrouter[tracing]` and use `from kimpton_evalrouter.tracing import TraceCapture`.
|
|
309
|
+
Create a connection in Traces and configure its restricted ingest key with
|
|
310
|
+
`EVALROUTER_TRACE_KEY` and `EVALROUTER_TRACE_CONNECTION_ID`, alongside the API
|
|
311
|
+
origin and workspace ID. Wrap each run with `capture.agent(...)`, and calls with
|
|
312
|
+
`capture.model(...)` or `capture.tool(...)`. Use `span.input(value)` and
|
|
313
|
+
`span.output(value)` to capture content. Call `capture.flush()` before a
|
|
314
|
+
serverless invocation exits and `capture.close()` on shutdown. The optional
|
|
315
|
+
OpenTelemetry dependency is isolated from the base HTTP client.
|
|
316
|
+
|
|
317
|
+
See [the capture guide](https://evalrouter.ai/developers/docs/live-traces) for complete
|
|
318
|
+
examples, redaction settings, coverage, retention, and delivery limits.
|
|
319
|
+
|
|
320
|
+
Use `client.traces` for connection, trace, evaluator and finding resources, and
|
|
321
|
+
`client.datasets` for curation, review, immutable versions and exports.
|
|
322
|
+
These operations require the corresponding service release and workspace permissions.
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: evalrouter
|
|
3
|
-
Version: 0.3.4
|
|
4
|
-
Summary: Typed Kimpton evaluation client and command-line interface
|
|
5
|
-
License-Expression: LicenseRef-Kimpton-EvalRouter-SDK
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Requires-Python: <3.14,>=3.12
|
|
8
|
-
Requires-Dist: httpx==0.28.1
|
|
9
|
-
Requires-Dist: rich==15.0.0
|
|
10
|
-
Provides-Extra: benchmark
|
|
11
|
-
Requires-Dist: pydantic==2.13.5; extra == 'benchmark'
|
|
12
|
-
Provides-Extra: keyring
|
|
13
|
-
Requires-Dist: keyring==25.7.0; extra == 'keyring'
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
|
|
16
1
|
# EvalRouter CLI
|
|
17
2
|
|
|
18
3
|
Evaluate models or qualified repository agents from your terminal: discover
|
|
@@ -59,6 +44,26 @@ CI and services can use `EVALROUTER_API_KEY` and `EVALROUTER_WORKSPACE_ID` suppl
|
|
|
59
44
|
privately by a secret manager. Never put credentials in arguments, URLs, request
|
|
60
45
|
files or logs.
|
|
61
46
|
|
|
47
|
+
## Import LangSmith traces
|
|
48
|
+
|
|
49
|
+
The optional `langsmith` extra provides a local connector for completed agent
|
|
50
|
+
runs. Create a LangSmith connection in **Traces → Connect agent**, then supply
|
|
51
|
+
`LANGSMITH_API_KEY` and the connection's EvalRouter environment variables through
|
|
52
|
+
your secret manager. The source key is never sent to EvalRouter.
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
pip install 'evalrouter[langsmith]'
|
|
56
|
+
python -m kimpton_evalrouter.langsmith projects
|
|
57
|
+
python -m kimpton_evalrouter.langsmith sync --project 'YOUR_PROJECT_ID' \
|
|
58
|
+
--state './evalrouter-langsmith-state.json' --watch
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The process must stay running for automatic imports. Its private checkpoint
|
|
62
|
+
resumes progress across restarts. Set `--since` to an ISO timestamp to choose
|
|
63
|
+
the initial import window. Inputs and outputs are bounded and field-name
|
|
64
|
+
redacted; only activity recorded by LangSmith can be imported. This connector
|
|
65
|
+
requires a package build that includes the `langsmith` extra.
|
|
66
|
+
|
|
62
67
|
## Run an evaluation in one command
|
|
63
68
|
|
|
64
69
|
```sh
|
|
@@ -277,3 +282,21 @@ Replace the coverage placeholder with the entire returned object; do not guess
|
|
|
277
282
|
tasks, counts or seeds. Use the existing `quote`, `run`, `wait`, `results` and
|
|
278
283
|
`export` commands above. Qualification and evaluation have separate caps and
|
|
279
284
|
charges. A qualification pass does not submit an evaluation automatically.
|
|
285
|
+
|
|
286
|
+
## Live agent capture
|
|
287
|
+
|
|
288
|
+
Install `evalrouter[tracing]` and use `from kimpton_evalrouter.tracing import TraceCapture`.
|
|
289
|
+
Create a connection in Traces and configure its restricted ingest key with
|
|
290
|
+
`EVALROUTER_TRACE_KEY` and `EVALROUTER_TRACE_CONNECTION_ID`, alongside the API
|
|
291
|
+
origin and workspace ID. Wrap each run with `capture.agent(...)`, and calls with
|
|
292
|
+
`capture.model(...)` or `capture.tool(...)`. Use `span.input(value)` and
|
|
293
|
+
`span.output(value)` to capture content. Call `capture.flush()` before a
|
|
294
|
+
serverless invocation exits and `capture.close()` on shutdown. The optional
|
|
295
|
+
OpenTelemetry dependency is isolated from the base HTTP client.
|
|
296
|
+
|
|
297
|
+
See [the capture guide](https://evalrouter.ai/developers/docs/live-traces) for complete
|
|
298
|
+
examples, redaction settings, coverage, retention, and delivery limits.
|
|
299
|
+
|
|
300
|
+
Use `client.traces` for connection, trace, evaluator and finding resources, and
|
|
301
|
+
`client.datasets` for curation, review, immutable versions and exports.
|
|
302
|
+
These operations require the corresponding service release and workspace permissions.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "evalrouter"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.6"
|
|
8
8
|
description = "Typed Kimpton evaluation client and command-line interface"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "LicenseRef-Kimpton-EvalRouter-SDK"
|
|
@@ -19,6 +19,7 @@ requires-python = ">=3.12,<3.14"
|
|
|
19
19
|
dependencies = ["httpx==0.28.1", "rich==15.0.0"]
|
|
20
20
|
|
|
21
21
|
[project.optional-dependencies]
|
|
22
|
+
tracing = ["opentelemetry-api==1.45.0", "opentelemetry-sdk==1.45.0"]
|
|
22
23
|
# Exactly the internal contracts package's own dependency list
|
|
23
24
|
# (packages/contracts/pyproject.toml); build_packages.py refuses any drift.
|
|
24
25
|
benchmark = ["pydantic==2.13.5"]
|
|
@@ -26,6 +27,8 @@ benchmark = ["pydantic==2.13.5"]
|
|
|
26
27
|
# installed; otherwise it uses a private 0600 file. Kept optional so the base
|
|
27
28
|
# installation and every service/runner lock stay unchanged.
|
|
28
29
|
keyring = ["keyring==25.7.0"]
|
|
30
|
+
# Pull LangSmith projects into a local EvalRouter live trace connection.
|
|
31
|
+
langsmith = ["langsmith==0.12.6"]
|
|
29
32
|
|
|
30
33
|
[project.scripts]
|
|
31
34
|
evalrouter = "kimpton_evalrouter.cli:main"
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from functools import cached_property as _cached_property
|
|
4
4
|
|
|
5
5
|
from . import types
|
|
6
|
+
from ._resources import Traces as _Traces, Datasets as _Datasets
|
|
6
7
|
from ._resources import AgentBuilds as _AgentBuilds
|
|
7
8
|
from ._resources import Agents as _Agents
|
|
8
9
|
from ._resources import Catalog as _Catalog
|
|
@@ -26,10 +27,18 @@ __all__ = [
|
|
|
26
27
|
"WaitCancelled",
|
|
27
28
|
"types",
|
|
28
29
|
]
|
|
29
|
-
__version__ = "0.3.
|
|
30
|
+
__version__ = "0.3.6"
|
|
30
31
|
|
|
31
32
|
|
|
32
33
|
class Client(_Transport):
|
|
34
|
+
@_cached_property
|
|
35
|
+
def traces(self) -> _Traces:
|
|
36
|
+
return _Traces(self)
|
|
37
|
+
|
|
38
|
+
@_cached_property
|
|
39
|
+
def datasets(self) -> _Datasets:
|
|
40
|
+
return _Datasets(self)
|
|
41
|
+
|
|
33
42
|
@_cached_property
|
|
34
43
|
def agent_builds(self) -> _AgentBuilds:
|
|
35
44
|
return _AgentBuilds(self)
|
|
@@ -28,6 +28,7 @@ import json
|
|
|
28
28
|
import os
|
|
29
29
|
import re
|
|
30
30
|
import select
|
|
31
|
+
import shutil
|
|
31
32
|
import socket
|
|
32
33
|
import stat
|
|
33
34
|
import sys
|
|
@@ -55,8 +56,7 @@ DEFAULT_API_ORIGIN = "https://api.evalrouter.ai"
|
|
|
55
56
|
CONNECT_WEBSITES = {
|
|
56
57
|
"api.evalrouter.ai": "https://evalrouter.ai",
|
|
57
58
|
"api.dev.evalrouter.ai": "https://dev.evalrouter.ai",
|
|
58
|
-
"kimpton-evalrouter-dev--evalrouter-service-api.us-east.modal.direct":
|
|
59
|
-
"https://dev.evalrouter.ai",
|
|
59
|
+
"kimpton-evalrouter-dev--evalrouter-service-api.us-east.modal.direct": "https://dev.evalrouter.ai",
|
|
60
60
|
}
|
|
61
61
|
LOGIN_HINT = "Run `evalrouter login` or set EVALROUTER_API_KEY."
|
|
62
62
|
#: Largest secret accepted on stdin or at a prompt (bytes of UTF-8).
|
|
@@ -555,9 +555,16 @@ def start_device_authorization(http: httpx.Client, config: dict) -> dict:
|
|
|
555
555
|
try:
|
|
556
556
|
parsed = urlsplit(address)
|
|
557
557
|
except ValueError:
|
|
558
|
-
raise ClientError(
|
|
559
|
-
|
|
560
|
-
|
|
558
|
+
raise ClientError(
|
|
559
|
+
"login_unavailable", "Sign-in returned an unsafe verification URL."
|
|
560
|
+
) from None
|
|
561
|
+
if (
|
|
562
|
+
parsed.scheme != "https"
|
|
563
|
+
or parsed.netloc != urlsplit(config["issuer"]).netloc
|
|
564
|
+
or parsed.username
|
|
565
|
+
or parsed.password
|
|
566
|
+
or parsed.fragment
|
|
567
|
+
):
|
|
561
568
|
raise ClientError("login_unavailable", "Sign-in returned an unsafe verification URL.")
|
|
562
569
|
return value
|
|
563
570
|
|
|
@@ -811,6 +818,24 @@ def advertised(base: str | None = None, store: CredentialStore | None = None) ->
|
|
|
811
818
|
)
|
|
812
819
|
|
|
813
820
|
|
|
821
|
+
def login_possible(base: str | None = None) -> bool:
|
|
822
|
+
"""Local-only: False only for a server already seen without browser sign-in.
|
|
823
|
+
|
|
824
|
+
Unlike `advertised`, an unknown server (a --base-url never used before)
|
|
825
|
+
counts as possible: `login` asks the server and explains if sign-in is off.
|
|
826
|
+
"""
|
|
827
|
+
if advertised(base):
|
|
828
|
+
return True
|
|
829
|
+
try:
|
|
830
|
+
base = base or normalize_base_url(
|
|
831
|
+
os.environ.get("EVALROUTER_BASE_URL") or DEFAULT_API_ORIGIN, True
|
|
832
|
+
)
|
|
833
|
+
entry = CredentialStore(use_keyring=False).server(base)
|
|
834
|
+
except (ClientError, OSError):
|
|
835
|
+
return True
|
|
836
|
+
return entry.get("login_advertised") is not False
|
|
837
|
+
|
|
838
|
+
|
|
814
839
|
def has_stored_login(args) -> bool:
|
|
815
840
|
"""Local-only: suppress first-use guidance for a device that is signed in."""
|
|
816
841
|
base = base_url(args)
|
|
@@ -987,7 +1012,7 @@ def forget_session(store: CredentialStore, base: str) -> None:
|
|
|
987
1012
|
store.delete(_token_key(base, "refresh_token"))
|
|
988
1013
|
for workspace_id in store.server(base).get("devices") or {}:
|
|
989
1014
|
store.delete(_device_key(base, workspace_id))
|
|
990
|
-
store.update_server(base, session=None, devices=None, active=None)
|
|
1015
|
+
store.update_server(base, session=None, devices=None, active=None, account=None)
|
|
991
1016
|
|
|
992
1017
|
|
|
993
1018
|
def _forget_device(store: CredentialStore, base: str, workspace_id: str) -> None:
|
|
@@ -1055,6 +1080,10 @@ def _select_workspace(workspaces: list, wanted: str | None, *, prompt=input) ->
|
|
|
1055
1080
|
"invalid_input",
|
|
1056
1081
|
"You belong to several workspaces. Choose one with --workspace ID_OR_NAME.",
|
|
1057
1082
|
)
|
|
1083
|
+
if prompt is input:
|
|
1084
|
+
chosen = _pick_workspace(workspaces, None)
|
|
1085
|
+
if chosen is not False:
|
|
1086
|
+
return chosen
|
|
1058
1087
|
for number, workspace in enumerate(workspaces, 1):
|
|
1059
1088
|
print(f" {number}. {workspace.get('name')} ({workspace.get('id')})", file=sys.stderr)
|
|
1060
1089
|
choice = prompt("Choose a workspace number: ").strip()
|
|
@@ -1063,6 +1092,36 @@ def _select_workspace(workspaces: list, wanted: str | None, *, prompt=input) ->
|
|
|
1063
1092
|
return workspaces[int(choice) - 1]
|
|
1064
1093
|
|
|
1065
1094
|
|
|
1095
|
+
def _pick_workspace(workspaces: list, current: str | None):
|
|
1096
|
+
"""Arrow-key choice; False where raw terminal input is unavailable."""
|
|
1097
|
+
from . import render
|
|
1098
|
+
from .render import picker
|
|
1099
|
+
|
|
1100
|
+
labels = [
|
|
1101
|
+
f"{w.get('name')}" + (" (current)" if str(w.get("id")) == current else "")
|
|
1102
|
+
for w in workspaces
|
|
1103
|
+
]
|
|
1104
|
+
encoding = str(getattr(sys.stderr, "encoding", "") or "").lower().replace("-", "")
|
|
1105
|
+
default = next((i for i, w in enumerate(workspaces) if str(w.get("id")) == current), 0)
|
|
1106
|
+
try:
|
|
1107
|
+
index = picker.select(
|
|
1108
|
+
"Which workspace?",
|
|
1109
|
+
labels,
|
|
1110
|
+
hints=[str(w.get("id")) for w in workspaces],
|
|
1111
|
+
default=default,
|
|
1112
|
+
filterable=len(workspaces) > 8,
|
|
1113
|
+
color=not render.is_plain(sys.stderr),
|
|
1114
|
+
unicode=encoding.startswith("utf"),
|
|
1115
|
+
)
|
|
1116
|
+
except (ImportError, OSError):
|
|
1117
|
+
return False
|
|
1118
|
+
except KeyboardInterrupt:
|
|
1119
|
+
index = None
|
|
1120
|
+
if not isinstance(index, int):
|
|
1121
|
+
raise ClientError("invalid_input", "No workspace was selected.")
|
|
1122
|
+
return workspaces[index]
|
|
1123
|
+
|
|
1124
|
+
|
|
1066
1125
|
def _list_workspaces(client_factory, access) -> list:
|
|
1067
1126
|
with client_factory(api_key=access, workspace_id=None) as client:
|
|
1068
1127
|
try:
|
|
@@ -1078,8 +1137,16 @@ def _list_workspaces(client_factory, access) -> list:
|
|
|
1078
1137
|
|
|
1079
1138
|
|
|
1080
1139
|
def _onboarding_workspaces(
|
|
1081
|
-
client_factory,
|
|
1082
|
-
|
|
1140
|
+
client_factory,
|
|
1141
|
+
access,
|
|
1142
|
+
base,
|
|
1143
|
+
*,
|
|
1144
|
+
no_browser,
|
|
1145
|
+
notice,
|
|
1146
|
+
open_browser,
|
|
1147
|
+
sleep,
|
|
1148
|
+
clock=time.monotonic,
|
|
1149
|
+
timeout=600,
|
|
1083
1150
|
) -> list:
|
|
1084
1151
|
"""Finish browser-owned account setup without provisioning from CLI claims.
|
|
1085
1152
|
|
|
@@ -1095,8 +1162,7 @@ def _onboarding_workspaces(
|
|
|
1095
1162
|
website = {
|
|
1096
1163
|
"api.evalrouter.ai": "https://evalrouter.ai",
|
|
1097
1164
|
"api.dev.evalrouter.ai": "https://dev.evalrouter.ai",
|
|
1098
|
-
"kimpton-evalrouter-dev--evalrouter-service-api.us-east.modal.direct":
|
|
1099
|
-
"https://dev.evalrouter.ai",
|
|
1165
|
+
"kimpton-evalrouter-dev--evalrouter-service-api.us-east.modal.direct": "https://dev.evalrouter.ai",
|
|
1100
1166
|
}.get(urlsplit(base).netloc)
|
|
1101
1167
|
if website is None:
|
|
1102
1168
|
raise
|
|
@@ -1118,7 +1184,8 @@ def _onboarding_workspaces(
|
|
|
1118
1184
|
raise
|
|
1119
1185
|
raise ClientError(
|
|
1120
1186
|
"account_setup_pending",
|
|
1121
|
-
"Account setup is not complete. Finish signing in at "
|
|
1187
|
+
"Account setup is not complete. Finish signing in at "
|
|
1188
|
+
+ target
|
|
1122
1189
|
+ ", then run `evalrouter login` again.",
|
|
1123
1190
|
)
|
|
1124
1191
|
|
|
@@ -1174,6 +1241,80 @@ def _whoami(client_factory, credentials: Credentials) -> dict:
|
|
|
1174
1241
|
return value
|
|
1175
1242
|
|
|
1176
1243
|
|
|
1244
|
+
def _erase_lines(lines: list[str]) -> None:
|
|
1245
|
+
"""Remove lines just printed on an interactive stderr (they wrap at its width)."""
|
|
1246
|
+
if not (sys.stderr.isatty() and os.environ.get("TERM", "") != "dumb") or not lines:
|
|
1247
|
+
return
|
|
1248
|
+
columns = shutil.get_terminal_size().columns or 80
|
|
1249
|
+
rows = sum(max(1, -(-len(line) // columns)) for line in lines)
|
|
1250
|
+
sys.stderr.write(f"\x1b[{rows}F\x1b[J")
|
|
1251
|
+
sys.stderr.flush()
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
def _compact_device_login(http, config, device, target, *, open_browser, notice, sleep, lead=None):
|
|
1255
|
+
"""The terminal sign-in: open the browser, show the code, wait with a spinner.
|
|
1256
|
+
|
|
1257
|
+
Returns tokens, or None when the person asked for a new code. The steps
|
|
1258
|
+
are the same device authorization as the full text; only the words shrink.
|
|
1259
|
+
The instructions are temporary: after approval they are erased, like the
|
|
1260
|
+
spinner, so the session keeps only the outcome. A failure leaves them.
|
|
1261
|
+
"""
|
|
1262
|
+
from . import render
|
|
1263
|
+
|
|
1264
|
+
shown: list[str] = []
|
|
1265
|
+
real_notice = notice
|
|
1266
|
+
|
|
1267
|
+
def notice(line):
|
|
1268
|
+
shown.append(line)
|
|
1269
|
+
real_notice(line)
|
|
1270
|
+
|
|
1271
|
+
if lead:
|
|
1272
|
+
notice(lead)
|
|
1273
|
+
host = urlsplit(config["issuer"]).netloc
|
|
1274
|
+
opened = False
|
|
1275
|
+
with contextlib.suppress(Exception):
|
|
1276
|
+
opened = bool(open_browser(target))
|
|
1277
|
+
notice(
|
|
1278
|
+
"Opened your browser to sign in or create an account."
|
|
1279
|
+
if opened
|
|
1280
|
+
else "Open this link to sign in or create an account:"
|
|
1281
|
+
)
|
|
1282
|
+
notice(
|
|
1283
|
+
f" Code {device['user_code']}: confirm it, sign in at {host} if asked,"
|
|
1284
|
+
' then wait for "Device connected".'
|
|
1285
|
+
)
|
|
1286
|
+
if opened:
|
|
1287
|
+
notice(f" Browser did not open? {target}")
|
|
1288
|
+
else:
|
|
1289
|
+
notice(f" {target}")
|
|
1290
|
+
waiting = "Waiting for the browser (Enter: new code, Ctrl+C: cancel)"
|
|
1291
|
+
plain = render.is_plain(sys.stderr)
|
|
1292
|
+
status = (
|
|
1293
|
+
contextlib.nullcontext()
|
|
1294
|
+
if plain
|
|
1295
|
+
else render.console_for(sys.stderr).status(waiting, spinner="dots")
|
|
1296
|
+
)
|
|
1297
|
+
if plain:
|
|
1298
|
+
notice(waiting + "...")
|
|
1299
|
+
try:
|
|
1300
|
+
with status:
|
|
1301
|
+
tokens = poll_for_tokens(
|
|
1302
|
+
http, config, device, sleep=sleep, wait_for_restart=_wait_for_login_restart
|
|
1303
|
+
)
|
|
1304
|
+
_erase_lines(shown)
|
|
1305
|
+
return tokens
|
|
1306
|
+
except _RestartDeviceLogin:
|
|
1307
|
+
notice("Starting a new code. Close the earlier tab and use the new link.")
|
|
1308
|
+
return None
|
|
1309
|
+
except ClientError as error:
|
|
1310
|
+
if error.code != "login_expired":
|
|
1311
|
+
raise
|
|
1312
|
+
notice("This code expired. Press Enter for a new code, or Ctrl+C to cancel.")
|
|
1313
|
+
if not _wait_for_login_restart(None):
|
|
1314
|
+
raise
|
|
1315
|
+
return None
|
|
1316
|
+
|
|
1317
|
+
|
|
1177
1318
|
def login(
|
|
1178
1319
|
args,
|
|
1179
1320
|
*,
|
|
@@ -1203,9 +1344,24 @@ def login(
|
|
|
1203
1344
|
store.update_server(base, login_advertised=True)
|
|
1204
1345
|
config = auth0_config(base, advertisement)
|
|
1205
1346
|
interactive = _interactive() and not getattr(args, "json", False)
|
|
1347
|
+
compact = interactive and not getattr(args, "no_browser", False)
|
|
1206
1348
|
while True:
|
|
1207
1349
|
device = start_device_authorization(http, config)
|
|
1208
1350
|
target = connect_target(base, device)
|
|
1351
|
+
if compact:
|
|
1352
|
+
tokens = _compact_device_login(
|
|
1353
|
+
http,
|
|
1354
|
+
config,
|
|
1355
|
+
device,
|
|
1356
|
+
target,
|
|
1357
|
+
open_browser=open_browser,
|
|
1358
|
+
notice=notice,
|
|
1359
|
+
sleep=sleep,
|
|
1360
|
+
lead=getattr(args, "sign_in_reason", None),
|
|
1361
|
+
)
|
|
1362
|
+
if tokens is None:
|
|
1363
|
+
continue
|
|
1364
|
+
break
|
|
1209
1365
|
notice("Open this link to sign in or create an account:")
|
|
1210
1366
|
notice(target)
|
|
1211
1367
|
notice(f"Your terminal code: {device['user_code']}")
|
|
@@ -1226,7 +1382,10 @@ def login(
|
|
|
1226
1382
|
notice("Invalid or expired code? Restart `evalrouter login` for a new link.")
|
|
1227
1383
|
try:
|
|
1228
1384
|
tokens = poll_for_tokens(
|
|
1229
|
-
http,
|
|
1385
|
+
http,
|
|
1386
|
+
config,
|
|
1387
|
+
device,
|
|
1388
|
+
sleep=sleep,
|
|
1230
1389
|
wait_for_restart=_wait_for_login_restart if interactive else None,
|
|
1231
1390
|
)
|
|
1232
1391
|
break
|
|
@@ -1264,14 +1423,21 @@ def login(
|
|
|
1264
1423
|
wanted = getattr(args, "workspace", None) or getattr(args, "workspace_id", None)
|
|
1265
1424
|
workspace = _select_workspace(
|
|
1266
1425
|
_onboarding_workspaces(
|
|
1267
|
-
client_factory,
|
|
1268
|
-
|
|
1269
|
-
|
|
1426
|
+
client_factory,
|
|
1427
|
+
tokens["access_token"],
|
|
1428
|
+
base,
|
|
1429
|
+
no_browser=getattr(args, "no_browser", False),
|
|
1430
|
+
notice=notice,
|
|
1431
|
+
open_browser=open_browser,
|
|
1432
|
+
sleep=sleep,
|
|
1270
1433
|
),
|
|
1271
1434
|
wanted,
|
|
1272
1435
|
)
|
|
1273
1436
|
device_view = _register(client_factory, store, base, tokens["access_token"], workspace)
|
|
1274
1437
|
value = _whoami(client_factory, stored_credentials(store, base, device_view["id"]))
|
|
1438
|
+
email = (value.get("user") or {}).get("email")
|
|
1439
|
+
# Display metadata for the offline home ("Signed in as ..."); never a credential.
|
|
1440
|
+
store.update_server(base, account={"email": email} if isinstance(email, str) else None)
|
|
1275
1441
|
value["credential_store"] = storage
|
|
1276
1442
|
value["api_key_overrides"] = bool(os.environ.get("EVALROUTER_API_KEY"))
|
|
1277
1443
|
return value
|
|
@@ -1454,8 +1620,23 @@ def switch(args, *, client_factory, store: CredentialStore | None = None):
|
|
|
1454
1620
|
"""Activate a registered workspace, or register this device for it (no browser)."""
|
|
1455
1621
|
store = store or CredentialStore()
|
|
1456
1622
|
base = _require_base(args)
|
|
1457
|
-
|
|
1458
|
-
|
|
1623
|
+
entry = store.server(base)
|
|
1624
|
+
devices = entry.get("devices") or {}
|
|
1625
|
+
wanted = (getattr(args, "workspace", None) or "").strip()
|
|
1626
|
+
if not wanted:
|
|
1627
|
+
if not _interactive():
|
|
1628
|
+
raise ClientError(
|
|
1629
|
+
"invalid_input", "Name a workspace: evalrouter workspace switch ID_OR_NAME"
|
|
1630
|
+
)
|
|
1631
|
+
access = session_token(store, base)
|
|
1632
|
+
if not access:
|
|
1633
|
+
raise ClientError("login_required", "You are not signed in. Run `evalrouter login`.")
|
|
1634
|
+
chosen = _pick_workspace(_list_workspaces(client_factory, access), entry.get("active"))
|
|
1635
|
+
if chosen is False:
|
|
1636
|
+
raise ClientError(
|
|
1637
|
+
"invalid_input", "Name a workspace: evalrouter workspace switch ID_OR_NAME"
|
|
1638
|
+
)
|
|
1639
|
+
wanted = str(chosen.get("id"))
|
|
1459
1640
|
matches = [
|
|
1460
1641
|
wid
|
|
1461
1642
|
for wid, device in devices.items()
|
|
@@ -1506,16 +1687,15 @@ def human(command: str, action: str | None, value: dict) -> list[str]:
|
|
|
1506
1687
|
]
|
|
1507
1688
|
else:
|
|
1508
1689
|
user = value.get("user") or {}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
if workspace:
|
|
1690
|
+
lines = [f"Signed in as {text(user.get('email'))}."]
|
|
1691
|
+
if workspace and command == "whoami":
|
|
1512
1692
|
role = f", {text(workspace['role'])}" if workspace.get("role") else ""
|
|
1513
1693
|
detail = f" ({text(workspace.get('id'))}{role})" if command == "whoami" else ""
|
|
1514
1694
|
lines.append(f"Workspace: {text(workspace.get('name'))}{detail}")
|
|
1515
1695
|
if value.get("scopes") and command == "whoami":
|
|
1516
1696
|
lines.append("Scopes: " + ", ".join(text(s) for s in value["scopes"]))
|
|
1517
1697
|
if command == "login":
|
|
1518
|
-
lines.append("
|
|
1698
|
+
lines.append("Run evalrouter to get started.")
|
|
1519
1699
|
if value.get("replaced_sign_in"):
|
|
1520
1700
|
lines.append("This replaced the device sign-in for this server.")
|
|
1521
1701
|
if value.get("api_key_overrides"):
|
|
@@ -36,6 +36,7 @@ from urllib.parse import urlsplit
|
|
|
36
36
|
|
|
37
37
|
from . import render
|
|
38
38
|
from ._transport import APIError, ClientError, RequestTimeout
|
|
39
|
+
from .render import picker
|
|
39
40
|
|
|
40
41
|
#: Error codes that mean "the command line needs changing" (exit status 2).
|
|
41
42
|
USAGE_CODES = frozenset(
|
|
@@ -111,6 +112,7 @@ LAST_RUN_EXAMPLES = """examples:
|
|
|
111
112
|
EXPORT_EXAMPLES = """examples:
|
|
112
113
|
evalrouter export last run as evalrouter-<id>.json
|
|
113
114
|
evalrouter export --format html,json both reports in one call
|
|
115
|
+
evalrouter export --format bundle evidence ZIP: report, CSV, JSONL, checksums
|
|
114
116
|
evalrouter export 1a2b3c4d --format csv --output scores.csv
|
|
115
117
|
"""
|
|
116
118
|
|
|
@@ -602,6 +604,16 @@ def say(text: str = "") -> None:
|
|
|
602
604
|
print(text, file=sys.stderr, flush=True)
|
|
603
605
|
|
|
604
606
|
|
|
607
|
+
@contextlib.contextmanager
|
|
608
|
+
def loading(text: str):
|
|
609
|
+
"""A spinner on an interactive stderr while a request runs; silent elsewhere."""
|
|
610
|
+
if not (sys.stderr.isatty() and not render.is_plain(sys.stderr)):
|
|
611
|
+
yield
|
|
612
|
+
return
|
|
613
|
+
with render.console_for(sys.stderr).status(text, spinner="dots"):
|
|
614
|
+
yield
|
|
615
|
+
|
|
616
|
+
|
|
605
617
|
def ask(message: str, default: str | None = None) -> str:
|
|
606
618
|
suffix = f" [{default}]" if default is not None else ""
|
|
607
619
|
print(f"{message}{suffix}: ", end="", file=sys.stderr, flush=True)
|
|
@@ -627,8 +639,42 @@ def confirm(message: str, *, default: bool = True) -> bool:
|
|
|
627
639
|
return False
|
|
628
640
|
|
|
629
641
|
|
|
642
|
+
#: Choices a numbered prompt lists; `search` reaches the rest.
|
|
643
|
+
NUMBERED_CHOICES = 20
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
def _terminal_style() -> dict:
|
|
647
|
+
encoding = str(getattr(sys.stderr, "encoding", "") or "").lower().replace("-", "")
|
|
648
|
+
return {"color": not render.is_plain(sys.stderr), "unicode": encoding.startswith("utf")}
|
|
649
|
+
|
|
650
|
+
|
|
630
651
|
def choose(title: str, options: list[tuple[str, Any]], *, default: int = 1, search=None):
|
|
631
|
-
"""
|
|
652
|
+
"""One choice; free text is passed to `search` (returns a value or None).
|
|
653
|
+
|
|
654
|
+
At a terminal this is an inline arrow-key menu where typing filters the
|
|
655
|
+
options; a query matching none of them goes to `search`. Without raw
|
|
656
|
+
terminal input it is a numbered prompt over the first choices.
|
|
657
|
+
"""
|
|
658
|
+
title = title.rstrip(":")
|
|
659
|
+
labels = [label for label, _value in options]
|
|
660
|
+
try:
|
|
661
|
+
while True:
|
|
662
|
+
chosen = picker.select(
|
|
663
|
+
title, labels, default=default - 1, filterable=True, **_terminal_style()
|
|
664
|
+
)
|
|
665
|
+
if isinstance(chosen, int):
|
|
666
|
+
return options[chosen][1]
|
|
667
|
+
if chosen is None:
|
|
668
|
+
raise ClientError("input_closed", "No choice was made; nothing ran.")
|
|
669
|
+
found = search(chosen) if search is not None else None
|
|
670
|
+
if found is not None:
|
|
671
|
+
return found
|
|
672
|
+
say(f"Nothing matches {chosen!r}; try again.")
|
|
673
|
+
except (ImportError, OSError):
|
|
674
|
+
pass
|
|
675
|
+
except KeyboardInterrupt:
|
|
676
|
+
raise ClientError("input_closed", "No choice was made; nothing ran.") from None
|
|
677
|
+
options = options[:NUMBERED_CHOICES]
|
|
632
678
|
say(title)
|
|
633
679
|
for index, (label, _value) in enumerate(options, start=1):
|
|
634
680
|
say(f" {index:>2}. {label}")
|
|
@@ -768,7 +814,8 @@ def resolve_benchmark(client, term: str | None, *, prompt: bool) -> dict:
|
|
|
768
814
|
if term and "@" in term:
|
|
769
815
|
slug, _, version = term.partition("@")
|
|
770
816
|
return _version_record(client, slug, version)
|
|
771
|
-
|
|
817
|
+
with loading("Loading benchmarks..."):
|
|
818
|
+
rows = list(_pages(client.catalog.benchmarks, {"status": "active"}))
|
|
772
819
|
if term:
|
|
773
820
|
exact = [row for row in rows if row.get("id") == term]
|
|
774
821
|
if exact:
|
|
@@ -789,7 +836,7 @@ def resolve_benchmark(client, term: str | None, *, prompt: bool) -> dict:
|
|
|
789
836
|
if len(found) > 1 and prompt:
|
|
790
837
|
return choose(
|
|
791
838
|
f"{len(found)} benchmarks match {text!r}:",
|
|
792
|
-
[(benchmark_label(slugs[slug]), slug) for slug in found
|
|
839
|
+
[(benchmark_label(slugs[slug]), slug) for slug in found],
|
|
793
840
|
)
|
|
794
841
|
return None
|
|
795
842
|
|
|
@@ -797,7 +844,7 @@ def resolve_benchmark(client, term: str | None, *, prompt: bool) -> dict:
|
|
|
797
844
|
ready = [slug for slug, row in slugs.items() if _ready(row)] or list(slugs)
|
|
798
845
|
slug = choose(
|
|
799
846
|
"Which benchmark?",
|
|
800
|
-
[(benchmark_label(slugs[item]), item) for item in ready
|
|
847
|
+
[(benchmark_label(slugs[item]), item) for item in ready],
|
|
801
848
|
search=search,
|
|
802
849
|
)
|
|
803
850
|
return _version_record(client, slug, None)
|
|
@@ -841,7 +888,8 @@ def resolve_model(client, term: str | None, *, prompt: bool) -> tuple[dict, str]
|
|
|
841
888
|
"model_not_found",
|
|
842
889
|
"Choose a model with --model. List models: evalrouter catalog --models",
|
|
843
890
|
)
|
|
844
|
-
|
|
891
|
+
with loading("Loading models..."):
|
|
892
|
+
routes = list(_pages(client.catalog.models, {}))
|
|
845
893
|
entries = [
|
|
846
894
|
(
|
|
847
895
|
[
|
|
@@ -863,13 +911,13 @@ def resolve_model(client, term: str | None, *, prompt: bool) -> tuple[dict, str]
|
|
|
863
911
|
if len(found) > 1 and prompt:
|
|
864
912
|
return choose(
|
|
865
913
|
f"{len(found)} models match {text!r}:",
|
|
866
|
-
[(model_label(route), route) for route in found
|
|
914
|
+
[(model_label(route), route) for route in found],
|
|
867
915
|
)
|
|
868
916
|
return None
|
|
869
917
|
|
|
870
918
|
if not term:
|
|
871
919
|
route = choose(
|
|
872
|
-
"Which model?", [(model_label(route), route) for route in routes
|
|
920
|
+
"Which model?", [(model_label(route), route) for route in routes], search=search
|
|
873
921
|
)
|
|
874
922
|
else:
|
|
875
923
|
found = _rank(term, entries)
|