evalrouter 0.3.1__tar.gz → 0.3.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.
Files changed (32) hide show
  1. {evalrouter-0.3.1 → evalrouter-0.3.3}/PKG-INFO +6 -5
  2. {evalrouter-0.3.1 → evalrouter-0.3.3}/README.md +5 -4
  3. {evalrouter-0.3.1 → evalrouter-0.3.3}/pyproject.toml +1 -1
  4. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/evalrouter_contracts/__init__.py +1 -1
  5. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/__init__.py +1 -1
  6. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/_account.py +140 -14
  7. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/cli.py +1 -2
  8. {evalrouter-0.3.1 → evalrouter-0.3.3}/LICENSE +0 -0
  9. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/evalrouter_contracts/bundle.py +0 -0
  10. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/evalrouter_contracts/components.py +0 -0
  11. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/evalrouter_contracts/models.py +0 -0
  12. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/evalrouter_contracts/protocol.py +0 -0
  13. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/evalrouter_contracts/py.typed +0 -0
  14. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/evalrouter_contracts/templates.py +0 -0
  15. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/evalrouter_contracts/validation.py +0 -0
  16. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/__main__.py +0 -0
  17. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/_boundary.py +0 -0
  18. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/_guided.py +0 -0
  19. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/_helpers.py +0 -0
  20. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/_listing.py +0 -0
  21. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/_resources.py +0 -0
  22. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/_transport.py +0 -0
  23. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/py.typed +0 -0
  24. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/render/__init__.py +0 -0
  25. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/render/_console.py +0 -0
  26. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/render/_theme.py +0 -0
  27. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/render/_widgets.py +0 -0
  28. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/render/live.py +0 -0
  29. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/render/picker.py +0 -0
  30. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/render/screens.py +0 -0
  31. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/render/tables.py +0 -0
  32. {evalrouter-0.3.1 → evalrouter-0.3.3}/src/kimpton_evalrouter/types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evalrouter
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Typed Kimpton evaluation client and command-line interface
5
5
  License-Expression: LicenseRef-Kimpton-EvalRouter-SDK
6
6
  License-File: LICENSE
@@ -38,8 +38,7 @@ the `kimpton_evalrouter` import and every API are unchanged. To switch, run
38
38
  `pip uninstall -y kimpton-evalrouter-sdk evalrouter`) and install `evalrouter`.
39
39
 
40
40
  The package supplies the `evalrouter` command; no repository checkout is needed.
41
- [Create an EvalRouter account](https://evalrouter.ai/register), verify your email,
42
- and follow the browser sign-in below.
41
+ Run the browser sign-in below to sign in or create your account.
43
42
  Package installation does not grant account access or evaluation credit.
44
43
 
45
44
  Sign in with your account:
@@ -49,8 +48,8 @@ evalrouter login
49
48
  evalrouter whoami
50
49
  ```
51
50
 
52
- Approve the browser code. New accounts finish setup on the website; the CLI
53
- continues when that is complete. It selects your only workspace automatically.
51
+ The browser guides you through sign-up or sign-in, email verification and
52
+ terminal approval. The CLI resumes automatically and selects your only workspace.
54
53
  Production is the default API, with `--base-url` available for other environments.
55
54
  No API key or credential-storage setup is needed for a normal sign-in.
56
55
 
@@ -276,3 +275,5 @@ Replace the coverage placeholder with the entire returned object; do not guess
276
275
  tasks, counts or seeds. Use the existing `quote`, `run`, `wait`, `results` and
277
276
  `export` commands above. Qualification and evaluation have separate caps and
278
277
  charges. A qualification pass does not submit an evaluation automatically.
278
+
279
+ After confirming the terminal code, sign in if asked and keep the browser open until your device is connected. If the browser says the code is invalid, press Enter in the waiting terminal for a fresh code (or restart evalrouter login). Your account and workspace are preserved.
@@ -23,8 +23,7 @@ the `kimpton_evalrouter` import and every API are unchanged. To switch, run
23
23
  `pip uninstall -y kimpton-evalrouter-sdk evalrouter`) and install `evalrouter`.
24
24
 
25
25
  The package supplies the `evalrouter` command; no repository checkout is needed.
26
- [Create an EvalRouter account](https://evalrouter.ai/register), verify your email,
27
- and follow the browser sign-in below.
26
+ Run the browser sign-in below to sign in or create your account.
28
27
  Package installation does not grant account access or evaluation credit.
29
28
 
30
29
  Sign in with your account:
@@ -34,8 +33,8 @@ evalrouter login
34
33
  evalrouter whoami
35
34
  ```
36
35
 
37
- Approve the browser code. New accounts finish setup on the website; the CLI
38
- continues when that is complete. It selects your only workspace automatically.
36
+ The browser guides you through sign-up or sign-in, email verification and
37
+ terminal approval. The CLI resumes automatically and selects your only workspace.
39
38
  Production is the default API, with `--base-url` available for other environments.
40
39
  No API key or credential-storage setup is needed for a normal sign-in.
41
40
 
@@ -261,3 +260,5 @@ Replace the coverage placeholder with the entire returned object; do not guess
261
260
  tasks, counts or seeds. Use the existing `quote`, `run`, `wait`, `results` and
262
261
  `export` commands above. Qualification and evaluation have separate caps and
263
262
  charges. A qualification pass does not submit an evaluation automatically.
263
+
264
+ After confirming the terminal code, sign in if asked and keep the browser open until your device is connected. If the browser says the code is invalid, press Enter in the waiting terminal for a fresh code (or restart evalrouter login). Your account and workspace are preserved.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "evalrouter"
7
- version = "0.3.1"
7
+ version = "0.3.3"
8
8
  description = "Typed Kimpton evaluation client and command-line interface"
9
9
  readme = "README.md"
10
10
  license = "LicenseRef-Kimpton-EvalRouter-SDK"
@@ -8,4 +8,4 @@ computes digests and refuses invalid packages; it never imports contributed
8
8
  code, opens a network connection, signs anything or carries operator state.
9
9
  """
10
10
 
11
- __version__ = "0.3.1"
11
+ __version__ = "0.3.3"
@@ -26,7 +26,7 @@ __all__ = [
26
26
  "WaitCancelled",
27
27
  "types",
28
28
  ]
29
- __version__ = "0.3.1"
29
+ __version__ = "0.3.3"
30
30
 
31
31
 
32
32
  class Client(_Transport):
@@ -27,6 +27,7 @@ import getpass
27
27
  import json
28
28
  import os
29
29
  import re
30
+ import select
30
31
  import socket
31
32
  import stat
32
33
  import sys
@@ -37,7 +38,7 @@ import webbrowser
37
38
  from dataclasses import dataclass
38
39
  from pathlib import Path
39
40
  from types import SimpleNamespace
40
- from urllib.parse import urlsplit, urlunsplit
41
+ from urllib.parse import urlencode, urlsplit, urlunsplit
41
42
 
42
43
  import httpx
43
44
 
@@ -51,6 +52,12 @@ FILE_STORE_NAME = "credentials.json"
51
52
  REFRESH_MARGIN_SECONDS = 60
52
53
  MAX_POLL_INTERVAL = 60
53
54
  DEFAULT_API_ORIGIN = "https://api.evalrouter.ai"
55
+ CONNECT_WEBSITES = {
56
+ "api.evalrouter.ai": "https://evalrouter.ai",
57
+ "api.dev.evalrouter.ai": "https://dev.evalrouter.ai",
58
+ "kimpton-evalrouter-dev--evalrouter-service-api.us-east.modal.direct":
59
+ "https://dev.evalrouter.ai",
60
+ }
54
61
  LOGIN_HINT = "Run `evalrouter login` or set EVALROUTER_API_KEY."
55
62
  #: Largest secret accepted on stdin or at a prompt (bytes of UTF-8).
56
63
  MAX_SECRET_BYTES = 16 * 1024
@@ -537,12 +544,37 @@ def start_device_authorization(http: httpx.Client, config: dict) -> dict:
537
544
  required = ("device_code", "user_code", "verification_uri")
538
545
  if not isinstance(value, dict) or not all(isinstance(value.get(k), str) for k in required):
539
546
  raise ClientError("login_unavailable", "Sign-in could not be started. Try again later.")
547
+ if not re.fullmatch(r"[A-Za-z0-9-]{4,32}", value["user_code"]):
548
+ raise ClientError("login_unavailable", "Sign-in returned an unusable terminal code.")
540
549
  for key in ("verification_uri", "verification_uri_complete"):
541
- if value.get(key) and urlsplit(value[key]).scheme != "https":
550
+ if not value.get(key):
551
+ continue
552
+ address = value[key]
553
+ if not isinstance(address, str) or any(ord(c) < 33 or ord(c) > 126 for c in address):
554
+ raise ClientError("login_unavailable", "Sign-in returned an unsafe verification URL.")
555
+ try:
556
+ parsed = urlsplit(address)
557
+ except ValueError:
558
+ raise ClientError("login_unavailable", "Sign-in returned an unsafe verification URL.") from None
559
+ if (parsed.scheme != "https" or parsed.netloc != urlsplit(config["issuer"]).netloc
560
+ or parsed.username or parsed.password or parsed.fragment):
542
561
  raise ClientError("login_unavailable", "Sign-in returned an unsafe verification URL.")
543
562
  return value
544
563
 
545
564
 
565
+ def connect_target(base: str, device: dict) -> str:
566
+ """Prepare the browser account before approving the existing OAuth request.
567
+
568
+ Only the user-facing code reaches the website, never the device secret,
569
+ access token or refresh token. Custom servers keep their provider's flow.
570
+ """
571
+ website = CONNECT_WEBSITES.get(urlsplit(base).netloc)
572
+ code = device["user_code"]
573
+ if website and re.fullmatch(r"[A-Za-z0-9]{4}-[A-Za-z0-9]{4}", code):
574
+ return website + "/activate?" + urlencode({"code": code.upper()})
575
+ return device.get("verification_uri_complete") or device["verification_uri"]
576
+
577
+
546
578
  def _jwt_expiry(token: str) -> float | None:
547
579
  """Scheduling hint only; the server verifies every token."""
548
580
  try:
@@ -573,6 +605,47 @@ def _tokens(value, now: float) -> dict:
573
605
  }
574
606
 
575
607
 
608
+ class _RestartDeviceLogin(Exception):
609
+ """The customer requested a new code; the pending request is abandoned."""
610
+
611
+
612
+ def _wait_for_login_restart(delay: float | None) -> bool:
613
+ """Wait for Enter without a reader thread that could outlive login.
614
+
615
+ Called only with interactive stdin/stderr, never for pipes or --json.
616
+ A timeout preserves OAuth polling cadence; EOF cannot trigger a retry loop.
617
+ """
618
+ if sys.platform == "win32":
619
+ import msvcrt
620
+
621
+ deadline = time.monotonic() + delay if delay is not None else None
622
+ while deadline is None or time.monotonic() < deadline:
623
+ if msvcrt.kbhit():
624
+ key = msvcrt.getwch()
625
+ if key in ("\r", "\n"):
626
+ return True
627
+ if key == "\x03":
628
+ raise KeyboardInterrupt
629
+ if key in ("\x00", "\xe0"):
630
+ msvcrt.getwch() # extended key, not an Enter request
631
+ remaining = max(0, deadline - time.monotonic()) if deadline is not None else 0.1
632
+ time.sleep(min(0.1, remaining))
633
+ return False
634
+ started = time.monotonic()
635
+ try:
636
+ ready, _, _ = select.select([sys.stdin], [], [], delay)
637
+ if not ready:
638
+ return False
639
+ if sys.stdin.readline():
640
+ return True
641
+ except (OSError, ValueError):
642
+ pass
643
+ # Closed/unsupported input must not shorten the provider's polling interval.
644
+ if delay is not None:
645
+ time.sleep(max(0, delay - (time.monotonic() - started)))
646
+ return False
647
+
648
+
576
649
  def poll_for_tokens(
577
650
  http: httpx.Client,
578
651
  config: dict,
@@ -581,6 +654,7 @@ def poll_for_tokens(
581
654
  sleep=time.sleep,
582
655
  clock=time.monotonic,
583
656
  wall=time.time,
657
+ wait_for_restart=None,
584
658
  ) -> dict:
585
659
  """Poll the token endpoint per RFC 8628, honoring slow_down and expiry."""
586
660
  interval = device.get("interval")
@@ -589,7 +663,10 @@ def poll_for_tokens(
589
663
  lifetime = float(lifetime) if isinstance(lifetime, (int, float)) and lifetime > 0 else 300
590
664
  deadline = clock() + lifetime
591
665
  while True:
592
- sleep(interval)
666
+ if wait_for_restart is None:
667
+ sleep(interval)
668
+ elif wait_for_restart(interval):
669
+ raise _RestartDeviceLogin
593
670
  if clock() >= deadline:
594
671
  raise ClientError(
595
672
  "login_expired", "The sign-in code expired. Run `evalrouter login` again."
@@ -672,10 +749,29 @@ class Credentials:
672
749
  device_secret: str | None = None
673
750
 
674
751
 
752
+ CLIENT_HEADER = "X-EvalRouter-Client"
753
+ # Coding agents that set a recognizable variable when they run a subprocess.
754
+ AGENT_ENVIRONMENT = ("CLAUDECODE", "CODEX_SANDBOX", "CURSOR_AGENT", "GEMINI_CLI")
755
+
756
+
757
+ def client_label() -> str:
758
+ """`cli/<version>`, or `agent/<version>` when a coding agent runs the CLI."""
759
+ try:
760
+ from importlib.metadata import version
761
+
762
+ release = version("evalrouter")
763
+ except Exception:
764
+ release = "unknown"
765
+ name = "agent" if any(os.environ.get(key) for key in AGENT_ENVIRONMENT) else "cli"
766
+ return f"{name}/{release}"
767
+
768
+
675
769
  def attach(client, credentials: Credentials):
676
- """Add the device-grant header to a constructed Client; returns the client."""
770
+ """Add the device-grant and client headers to a constructed Client; returns the client."""
677
771
  if credentials.device_secret:
678
772
  client._http.headers[DEVICE_HEADER] = credentials.device_secret
773
+ # Product analytics attribution only: a client name and package version.
774
+ client._http.headers[CLIENT_HEADER] = client_label()
679
775
  return client
680
776
 
681
777
 
@@ -1106,16 +1202,46 @@ def login(
1106
1202
  )
1107
1203
  store.update_server(base, login_advertised=True)
1108
1204
  config = auth0_config(base, advertisement)
1109
- device = start_device_authorization(http, config)
1110
- target = device.get("verification_uri_complete") or device["verification_uri"]
1111
- notice(f"First copy your one-time code: {device['user_code']}")
1112
- notice(f"Then open: {device['verification_uri']}")
1113
- if not getattr(args, "no_browser", False) and _interactive():
1114
- with contextlib.suppress(Exception):
1115
- if open_browser(target):
1116
- notice("Opened your browser. Approve the request to continue.")
1117
- notice("Waiting for sign-in to be approved...")
1118
- tokens = poll_for_tokens(http, config, device, sleep=sleep)
1205
+ interactive = _interactive() and not getattr(args, "json", False)
1206
+ while True:
1207
+ device = start_device_authorization(http, config)
1208
+ target = connect_target(base, device)
1209
+ notice("Open this link to sign in or create an account:")
1210
+ notice(target)
1211
+ notice(f"Your terminal code: {device['user_code']}")
1212
+ notice(f"Approval continues at {urlsplit(config['issuer']).netloc}:")
1213
+ notice(" 1. Confirm your terminal code.")
1214
+ notice(" 2. Sign in if asked, even if the website already recognizes you.")
1215
+ notice(" 3. Keep the tab open until it says Device connected.")
1216
+ notice("Confirming the code alone does not finish sign-in.")
1217
+ if not getattr(args, "no_browser", False) and _interactive():
1218
+ with contextlib.suppress(Exception):
1219
+ if open_browser(target):
1220
+ notice("Opened your browser. Finish connecting there.")
1221
+ notice("Waiting for browser approval...")
1222
+ if interactive:
1223
+ notice("Closed the tab or see an invalid code? Press Enter for a new code.")
1224
+ notice("Press Ctrl+C to cancel.")
1225
+ else:
1226
+ notice("Invalid or expired code? Restart `evalrouter login` for a new link.")
1227
+ try:
1228
+ tokens = poll_for_tokens(
1229
+ http, config, device, sleep=sleep,
1230
+ wait_for_restart=_wait_for_login_restart if interactive else None,
1231
+ )
1232
+ break
1233
+ except _RestartDeviceLogin:
1234
+ notice("Starting a new request. Close the earlier tab and use the new link.")
1235
+ except ClientError as error:
1236
+ if error.code != "login_expired" or not interactive:
1237
+ raise
1238
+ notice("This code expired. Press Enter for a new code, or Ctrl+C to cancel.")
1239
+ if not _wait_for_login_restart(None):
1240
+ raise
1241
+ except KeyboardInterrupt:
1242
+ raise ClientError(
1243
+ "login_cancelled", "Sign-in cancelled. You can close the browser tab."
1244
+ ) from None
1119
1245
  finally:
1120
1246
  if owned:
1121
1247
  http.close()
@@ -523,8 +523,7 @@ def benchmark_human_result(action, value):
523
523
 
524
524
 
525
525
  ONBOARDING = """Get started:
526
- 1. Run evalrouter login and sign in through your browser.
527
- New to EvalRouter? Create your account at https://evalrouter.ai/register.
526
+ 1. Run evalrouter login to sign in or create your account in the browser.
528
527
  2. Run evalrouter catalog to choose a benchmark, or catalog --models for models.
529
528
  3. Run evalrouter run to review a quote before starting an evaluation.
530
529
 
File without changes