evalrouter 0.3.0__tar.gz → 0.3.2__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.0 → evalrouter-0.3.2}/PKG-INFO +17 -7
  2. {evalrouter-0.3.0 → evalrouter-0.3.2}/README.md +16 -6
  3. {evalrouter-0.3.0 → evalrouter-0.3.2}/pyproject.toml +1 -1
  4. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/evalrouter_contracts/__init__.py +1 -1
  5. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/__init__.py +1 -1
  6. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/_account.py +127 -22
  7. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/cli.py +11 -5
  8. {evalrouter-0.3.0 → evalrouter-0.3.2}/LICENSE +0 -0
  9. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/evalrouter_contracts/bundle.py +0 -0
  10. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/evalrouter_contracts/components.py +0 -0
  11. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/evalrouter_contracts/models.py +0 -0
  12. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/evalrouter_contracts/protocol.py +0 -0
  13. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/evalrouter_contracts/py.typed +0 -0
  14. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/evalrouter_contracts/templates.py +0 -0
  15. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/evalrouter_contracts/validation.py +0 -0
  16. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/__main__.py +0 -0
  17. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/_boundary.py +0 -0
  18. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/_guided.py +0 -0
  19. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/_helpers.py +0 -0
  20. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/_listing.py +0 -0
  21. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/_resources.py +0 -0
  22. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/_transport.py +0 -0
  23. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/py.typed +0 -0
  24. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/render/__init__.py +0 -0
  25. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/render/_console.py +0 -0
  26. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/render/_theme.py +0 -0
  27. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/render/_widgets.py +0 -0
  28. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/render/live.py +0 -0
  29. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/render/picker.py +0 -0
  30. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/render/screens.py +0 -0
  31. {evalrouter-0.3.0 → evalrouter-0.3.2}/src/kimpton_evalrouter/render/tables.py +0 -0
  32. {evalrouter-0.3.0 → evalrouter-0.3.2}/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.0
3
+ Version: 0.3.2
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,14 +38,24 @@ 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 create a workspace key in [API key settings](https://evalrouter.ai/settings/api-keys).
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
- Set `EVALROUTER_API_KEY` and `EVALROUTER_WORKSPACE_ID` through your secret manager
46
- or private environment. Use `https://api.evalrouter.ai` for `EVALROUTER_BASE_URL`,
47
- without `/v1`. Never put credentials in arguments, URLs, request files or logs.
48
- The CLI uses an existing workspace key; browser sign-up is a separate step.
44
+ Sign in with your account:
45
+
46
+ ```sh
47
+ evalrouter login
48
+ evalrouter whoami
49
+ ```
50
+
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.
53
+ Production is the default API, with `--base-url` available for other environments.
54
+ No API key or credential-storage setup is needed for a normal sign-in.
55
+
56
+ CI and services can use `EVALROUTER_API_KEY` and `EVALROUTER_WORKSPACE_ID` supplied
57
+ privately by a secret manager. Never put credentials in arguments, URLs, request
58
+ files or logs.
49
59
 
50
60
  ## Run an evaluation in one command
51
61
 
@@ -23,14 +23,24 @@ 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 create a workspace key in [API key settings](https://evalrouter.ai/settings/api-keys).
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
- Set `EVALROUTER_API_KEY` and `EVALROUTER_WORKSPACE_ID` through your secret manager
31
- or private environment. Use `https://api.evalrouter.ai` for `EVALROUTER_BASE_URL`,
32
- without `/v1`. Never put credentials in arguments, URLs, request files or logs.
33
- The CLI uses an existing workspace key; browser sign-up is a separate step.
29
+ Sign in with your account:
30
+
31
+ ```sh
32
+ evalrouter login
33
+ evalrouter whoami
34
+ ```
35
+
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.
38
+ Production is the default API, with `--base-url` available for other environments.
39
+ No API key or credential-storage setup is needed for a normal sign-in.
40
+
41
+ CI and services can use `EVALROUTER_API_KEY` and `EVALROUTER_WORKSPACE_ID` supplied
42
+ privately by a secret manager. Never put credentials in arguments, URLs, request
43
+ files or logs.
34
44
 
35
45
  ## Run an evaluation in one command
36
46
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "evalrouter"
7
- version = "0.3.0"
7
+ version = "0.3.2"
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.0"
11
+ __version__ = "0.3.2"
@@ -26,7 +26,7 @@ __all__ = [
26
26
  "WaitCancelled",
27
27
  "types",
28
28
  ]
29
- __version__ = "0.3.0"
29
+ __version__ = "0.3.2"
30
30
 
31
31
 
32
32
  class Client(_Transport):
@@ -37,7 +37,7 @@ import webbrowser
37
37
  from dataclasses import dataclass
38
38
  from pathlib import Path
39
39
  from types import SimpleNamespace
40
- from urllib.parse import urlsplit, urlunsplit
40
+ from urllib.parse import urlencode, urlsplit, urlunsplit
41
41
 
42
42
  import httpx
43
43
 
@@ -50,6 +50,13 @@ INDEX_NAME = "accounts.json"
50
50
  FILE_STORE_NAME = "credentials.json"
51
51
  REFRESH_MARGIN_SECONDS = 60
52
52
  MAX_POLL_INTERVAL = 60
53
+ DEFAULT_API_ORIGIN = "https://api.evalrouter.ai"
54
+ CONNECT_WEBSITES = {
55
+ "api.evalrouter.ai": "https://evalrouter.ai",
56
+ "api.dev.evalrouter.ai": "https://dev.evalrouter.ai",
57
+ "kimpton-evalrouter-dev--evalrouter-service-api.us-east.modal.direct":
58
+ "https://dev.evalrouter.ai",
59
+ }
53
60
  LOGIN_HINT = "Run `evalrouter login` or set EVALROUTER_API_KEY."
54
61
  #: Largest secret accepted on stdin or at a prompt (bytes of UTF-8).
55
62
  MAX_SECRET_BYTES = 16 * 1024
@@ -536,12 +543,37 @@ def start_device_authorization(http: httpx.Client, config: dict) -> dict:
536
543
  required = ("device_code", "user_code", "verification_uri")
537
544
  if not isinstance(value, dict) or not all(isinstance(value.get(k), str) for k in required):
538
545
  raise ClientError("login_unavailable", "Sign-in could not be started. Try again later.")
546
+ if not re.fullmatch(r"[A-Za-z0-9-]{4,32}", value["user_code"]):
547
+ raise ClientError("login_unavailable", "Sign-in returned an unusable terminal code.")
539
548
  for key in ("verification_uri", "verification_uri_complete"):
540
- if value.get(key) and urlsplit(value[key]).scheme != "https":
549
+ if not value.get(key):
550
+ continue
551
+ address = value[key]
552
+ if not isinstance(address, str) or any(ord(c) < 33 or ord(c) > 126 for c in address):
553
+ raise ClientError("login_unavailable", "Sign-in returned an unsafe verification URL.")
554
+ try:
555
+ parsed = urlsplit(address)
556
+ except ValueError:
557
+ raise ClientError("login_unavailable", "Sign-in returned an unsafe verification URL.") from None
558
+ if (parsed.scheme != "https" or parsed.netloc != urlsplit(config["issuer"]).netloc
559
+ or parsed.username or parsed.password or parsed.fragment):
541
560
  raise ClientError("login_unavailable", "Sign-in returned an unsafe verification URL.")
542
561
  return value
543
562
 
544
563
 
564
+ def connect_target(base: str, device: dict) -> str:
565
+ """Prepare the browser account before approving the existing OAuth request.
566
+
567
+ Only the user-facing code reaches the website, never the device secret,
568
+ access token or refresh token. Custom servers keep their provider's flow.
569
+ """
570
+ website = CONNECT_WEBSITES.get(urlsplit(base).netloc)
571
+ code = device["user_code"]
572
+ if website and re.fullmatch(r"[A-Za-z0-9]{4}-[A-Za-z0-9]{4}", code):
573
+ return website + "/activate?" + urlencode({"code": code.upper()})
574
+ return device.get("verification_uri_complete") or device["verification_uri"]
575
+
576
+
545
577
  def _jwt_expiry(token: str) -> float | None:
546
578
  """Scheduling hint only; the server verifies every token."""
547
579
  try:
@@ -671,10 +703,29 @@ class Credentials:
671
703
  device_secret: str | None = None
672
704
 
673
705
 
706
+ CLIENT_HEADER = "X-EvalRouter-Client"
707
+ # Coding agents that set a recognizable variable when they run a subprocess.
708
+ AGENT_ENVIRONMENT = ("CLAUDECODE", "CODEX_SANDBOX", "CURSOR_AGENT", "GEMINI_CLI")
709
+
710
+
711
+ def client_label() -> str:
712
+ """`cli/<version>`, or `agent/<version>` when a coding agent runs the CLI."""
713
+ try:
714
+ from importlib.metadata import version
715
+
716
+ release = version("evalrouter")
717
+ except Exception:
718
+ release = "unknown"
719
+ name = "agent" if any(os.environ.get(key) for key in AGENT_ENVIRONMENT) else "cli"
720
+ return f"{name}/{release}"
721
+
722
+
674
723
  def attach(client, credentials: Credentials):
675
- """Add the device-grant header to a constructed Client; returns the client."""
724
+ """Add the device-grant and client headers to a constructed Client; returns the client."""
676
725
  if credentials.device_secret:
677
726
  client._http.headers[DEVICE_HEADER] = credentials.device_secret
727
+ # Product analytics attribution only: a client name and package version.
728
+ client._http.headers[CLIENT_HEADER] = client_label()
678
729
  return client
679
730
 
680
731
 
@@ -682,7 +733,9 @@ def base_url(args) -> str | None:
682
733
  """The normalized API base, or None when unset/invalid (Client reports that)."""
683
734
  try:
684
735
  return normalize_base_url(
685
- getattr(args, "base_url", None) or os.environ.get("EVALROUTER_BASE_URL", ""),
736
+ getattr(args, "base_url", None)
737
+ or os.environ.get("EVALROUTER_BASE_URL")
738
+ or DEFAULT_API_ORIGIN,
686
739
  getattr(args, "allow_http", False),
687
740
  )
688
741
  except ClientError:
@@ -694,9 +747,13 @@ def advertised(base: str | None = None, store: CredentialStore | None = None) ->
694
747
  if os.environ.get("EVALROUTER_CLI_LOGIN", "").lower() == "on":
695
748
  return True
696
749
  try:
697
- base = base or normalize_base_url(os.environ.get("EVALROUTER_BASE_URL", ""), True)
750
+ base = base or normalize_base_url(
751
+ os.environ.get("EVALROUTER_BASE_URL") or DEFAULT_API_ORIGIN, True
752
+ )
698
753
  except ClientError:
699
754
  return False
755
+ if base == DEFAULT_API_ORIGIN + "/v1":
756
+ return True
700
757
  try:
701
758
  entry = (store or CredentialStore(use_keyring=False)).server(base)
702
759
  except OSError:
@@ -974,6 +1031,52 @@ def _list_workspaces(client_factory, access) -> list:
974
1031
  return rows if isinstance(rows, list) else []
975
1032
 
976
1033
 
1034
+ def _onboarding_workspaces(
1035
+ client_factory, access, base, *, no_browser, notice, open_browser, sleep,
1036
+ clock=time.monotonic, timeout=600,
1037
+ ) -> list:
1038
+ """Finish browser-owned account setup without provisioning from CLI claims.
1039
+
1040
+ Only the two hosted environments have a known website. Never guess a
1041
+ registration URL or send a token to a website advertised by another server.
1042
+ The same issuer/subject must become available before a grant is registered.
1043
+ """
1044
+ try:
1045
+ return _list_workspaces(client_factory, access)
1046
+ except APIError as error:
1047
+ if error.code not in {"account_not_found", "email_unverified"}:
1048
+ raise
1049
+ website = {
1050
+ "api.evalrouter.ai": "https://evalrouter.ai",
1051
+ "api.dev.evalrouter.ai": "https://dev.evalrouter.ai",
1052
+ "kimpton-evalrouter-dev--evalrouter-service-api.us-east.modal.direct":
1053
+ "https://dev.evalrouter.ai",
1054
+ }.get(urlsplit(base).netloc)
1055
+ if website is None:
1056
+ raise
1057
+ target = website + "/login?next=%2Fsettings%2Faccount"
1058
+ notice("Finish setting up your EvalRouter account in the browser:")
1059
+ notice(target)
1060
+ notice("Use the same account you just signed in with and verify your email.")
1061
+ if not no_browser and _interactive():
1062
+ with contextlib.suppress(Exception):
1063
+ open_browser(target)
1064
+ notice("Waiting for account setup; this command will continue automatically...")
1065
+ deadline = clock() + timeout
1066
+ while clock() < deadline:
1067
+ sleep(min(5, max(0, deadline - clock())))
1068
+ try:
1069
+ return _list_workspaces(client_factory, access)
1070
+ except APIError as error:
1071
+ if error.code not in {"account_not_found", "email_unverified"}:
1072
+ raise
1073
+ raise ClientError(
1074
+ "account_setup_pending",
1075
+ "Account setup is not complete. Finish signing in at " + target
1076
+ + ", then run `evalrouter login` again.",
1077
+ )
1078
+
1079
+
977
1080
  def _register(client_factory, store, base, access, workspace) -> dict:
978
1081
  """Create a device grant for one workspace and store its secret."""
979
1082
  with client_factory(api_key=access, workspace_id=None) as client:
@@ -1054,14 +1157,15 @@ def login(
1054
1157
  store.update_server(base, login_advertised=True)
1055
1158
  config = auth0_config(base, advertisement)
1056
1159
  device = start_device_authorization(http, config)
1057
- target = device.get("verification_uri_complete") or device["verification_uri"]
1058
- notice(f"First copy your one-time code: {device['user_code']}")
1059
- notice(f"Then open: {device['verification_uri']}")
1160
+ target = connect_target(base, device)
1161
+ notice("Open this link to sign in or create an account:")
1162
+ notice(target)
1163
+ notice(f"Your terminal code: {device['user_code']}")
1060
1164
  if not getattr(args, "no_browser", False) and _interactive():
1061
1165
  with contextlib.suppress(Exception):
1062
1166
  if open_browser(target):
1063
- notice("Opened your browser. Approve the request to continue.")
1064
- notice("Waiting for sign-in to be approved...")
1167
+ notice("Opened your browser. Finish connecting there.")
1168
+ notice("Waiting for you to finish in the browser...")
1065
1169
  tokens = poll_for_tokens(http, config, device, sleep=sleep)
1066
1170
  finally:
1067
1171
  if owned:
@@ -1083,7 +1187,14 @@ def login(
1083
1187
  },
1084
1188
  )
1085
1189
  wanted = getattr(args, "workspace", None) or getattr(args, "workspace_id", None)
1086
- workspace = _select_workspace(_list_workspaces(client_factory, tokens["access_token"]), wanted)
1190
+ workspace = _select_workspace(
1191
+ _onboarding_workspaces(
1192
+ client_factory, tokens["access_token"], base,
1193
+ no_browser=getattr(args, "no_browser", False), notice=notice,
1194
+ open_browser=open_browser, sleep=sleep,
1195
+ ),
1196
+ wanted,
1197
+ )
1087
1198
  device_view = _register(client_factory, store, base, tokens["access_token"], workspace)
1088
1199
  value = _whoami(client_factory, stored_credentials(store, base, device_view["id"]))
1089
1200
  value["credential_store"] = storage
@@ -1321,21 +1432,15 @@ def human(command: str, action: str | None, value: dict) -> list[str]:
1321
1432
  else:
1322
1433
  user = value.get("user") or {}
1323
1434
  verb = "Signed in to EvalRouter as" if command == "login" else "Signed in as"
1324
- lines = [f"{verb} {text(user.get('email'))} ({text(user.get('display_name'))})."]
1435
+ lines = [f"{verb} {text(user.get('email'))}."]
1325
1436
  if workspace:
1326
1437
  role = f", {text(workspace['role'])}" if workspace.get("role") else ""
1327
- lines.append(
1328
- f"Workspace: {text(workspace.get('name'))} ({text(workspace.get('id'))}{role})"
1329
- )
1330
- if value.get("scopes"):
1438
+ detail = f" ({text(workspace.get('id'))}{role})" if command == "whoami" else ""
1439
+ lines.append(f"Workspace: {text(workspace.get('name'))}{detail}")
1440
+ if value.get("scopes") and command == "whoami":
1331
1441
  lines.append("Scopes: " + ", ".join(text(s) for s in value["scopes"]))
1332
1442
  if command == "login":
1333
- where = (
1334
- "system keychain"
1335
- if value.get("credential_store") == "keyring"
1336
- else "private config file"
1337
- )
1338
- lines.append(f"Credentials stored in the {where}.")
1443
+ lines.append("Next: evalrouter catalog")
1339
1444
  if value.get("replaced_sign_in"):
1340
1445
  lines.append("This replaced the device sign-in for this server.")
1341
1446
  if value.get("api_key_overrides"):
@@ -523,11 +523,12 @@ def benchmark_human_result(action, value):
523
523
 
524
524
 
525
525
  ONBOARDING = """Get started:
526
- 1. Create an account: https://evalrouter.ai/register
527
- 2. Create a workspace API key: https://evalrouter.ai/settings/api-keys
528
- 3. Set EVALROUTER_API_KEY, EVALROUTER_BASE_URL and EVALROUTER_WORKSPACE_ID
529
- in your environment. Keep your API key private; never pass it as an argument.
530
- 4. Run evalrouter catalog --models to discover model routes.
526
+ 1. Run evalrouter login to sign in or create your account in the browser.
527
+ 2. Run evalrouter catalog to choose a benchmark, or catalog --models for models.
528
+ 3. Run evalrouter run to review a quote before starting an evaluation.
529
+
530
+ For CI and automation, use a workspace API key. See:
531
+ https://evalrouter.ai/developers/docs/authentication
531
532
  """
532
533
 
533
534
 
@@ -1575,6 +1576,11 @@ def main(argv=None):
1575
1576
  root.print_help()
1576
1577
  return 0
1577
1578
  args = root.parse_args(arguments)
1579
+ args.base_url = (
1580
+ getattr(args, "base_url", None)
1581
+ or os.environ.get("EVALROUTER_BASE_URL")
1582
+ or _account.DEFAULT_API_ORIGIN
1583
+ )
1578
1584
  # `benchmark init`, `validate` and `bundle` are local: they need no account,
1579
1585
  # open no connection, and must not be preceded by an onboarding notice or a
1580
1586
  # constructed client. Everything else keeps the existing behavior.
File without changes