nullius-eval 0.1.0__py3-none-any.whl

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 (291) hide show
  1. _nullius_app/.env.example +55 -0
  2. _nullius_app/app.py +96 -0
  3. _nullius_app/requirements.txt +1 -0
  4. _nullius_app/static/brand/README.md +20 -0
  5. _nullius_app/static/brand/docker.svg +1 -0
  6. _nullius_app/static/brand/favicon.svg +1 -0
  7. _nullius_app/static/brand/huggingface.svg +37 -0
  8. _nullius_app/static/brand/mark-dark.svg +1 -0
  9. _nullius_app/static/brand/marks.svg +34 -0
  10. _nullius_app/static/brand/tokens.json +51 -0
  11. _nullius_app/static/brand/typesafe.png +0 -0
  12. _nullius_app/static/brand/wordmark-dark.svg +1 -0
  13. _nullius_app/static/builder/command-builder-core.js +763 -0
  14. _nullius_app/static/builder/command-builder.css +248 -0
  15. _nullius_app/static/builder/command-builder.js +997 -0
  16. _nullius_app/static/builder/model-picker.js +113 -0
  17. _nullius_app/static/catalogue/add.js +46 -0
  18. _nullius_app/static/catalogue/agents/README.md +19 -0
  19. _nullius_app/static/catalogue/agents/goose.svg +1 -0
  20. _nullius_app/static/catalogue/agents/jiuwenswarm.svg +33 -0
  21. _nullius_app/static/catalogue/agents/marks.json +8 -0
  22. _nullius_app/static/catalogue/agents/mini-swe-agent.svg +7 -0
  23. _nullius_app/static/catalogue/agents/opencode.svg +7 -0
  24. _nullius_app/static/catalogue/catalogue.css +436 -0
  25. _nullius_app/static/catalogue/catalogue.js +87 -0
  26. _nullius_app/static/catalogue/marks.svg +29 -0
  27. _nullius_app/static/catalogue/new.js +78 -0
  28. _nullius_app/static/catalogue/versions.js +27 -0
  29. _nullius_app/static/compare/comparison.css +117 -0
  30. _nullius_app/static/controls.js +117 -0
  31. _nullius_app/static/disclosures.js +70 -0
  32. _nullius_app/static/fonts/0569c822cab6c510.ttf +0 -0
  33. _nullius_app/static/fonts/DMSans-Medium.woff2 +0 -0
  34. _nullius_app/static/fonts/DMSans-Regular.woff2 +0 -0
  35. _nullius_app/static/fonts/IBMPlexMono-Medium.woff2 +0 -0
  36. _nullius_app/static/fonts/IBMPlexMono-Regular.woff2 +0 -0
  37. _nullius_app/static/fonts/InstrumentSerif-Italic.woff2 +0 -0
  38. _nullius_app/static/fonts/InstrumentSerif-Regular.woff2 +0 -0
  39. _nullius_app/static/fonts/README.md +11 -0
  40. _nullius_app/static/fonts/c1e7453ea26a1d1e.ttf +0 -0
  41. _nullius_app/static/fonts/dmsans-OFL.txt +93 -0
  42. _nullius_app/static/fonts/ibmplexmono-OFL.txt +93 -0
  43. _nullius_app/static/fonts/instrumentserif-OFL.txt +93 -0
  44. _nullius_app/static/fonts.css +49 -0
  45. _nullius_app/static/notifications.js +49 -0
  46. _nullius_app/static/onboarding.css +78 -0
  47. _nullius_app/static/onboarding.js +158 -0
  48. _nullius_app/static/runs/board.css +358 -0
  49. _nullius_app/static/runs/board.js +127 -0
  50. _nullius_app/static/runs/launches.css +88 -0
  51. _nullius_app/static/runs/live-board.css +186 -0
  52. _nullius_app/static/runs/live-board.js +394 -0
  53. _nullius_app/static/runs/path-suggestions.js +119 -0
  54. _nullius_app/static/runs/start.css +38 -0
  55. _nullius_app/static/settings/autosave.js +162 -0
  56. _nullius_app/static/settings/custom-keys.js +100 -0
  57. _nullius_app/static/settings/data-providers.js +88 -0
  58. _nullius_app/static/settings/judges.js +61 -0
  59. _nullius_app/static/settings/modal.css +32 -0
  60. _nullius_app/static/settings/modal.js +91 -0
  61. _nullius_app/static/settings/navigation.js +55 -0
  62. _nullius_app/static/settings/prices.js +68 -0
  63. _nullius_app/static/settings/providers.js +134 -0
  64. _nullius_app/static/settings/sandbox.js +20 -0
  65. _nullius_app/static/settings/settings.css +288 -0
  66. _nullius_app/static/style.css +1752 -0
  67. _nullius_app/static/traces/conversation.css +49 -0
  68. _nullius_app/static/traces/conversation.js +215 -0
  69. _nullius_app/templates/agents/entry.html +145 -0
  70. _nullius_app/templates/agents/kits.html +55 -0
  71. _nullius_app/templates/agents/standard.html +58 -0
  72. _nullius_app/templates/base.html +479 -0
  73. _nullius_app/templates/builder/new_run.html +55 -0
  74. _nullius_app/templates/catalogue/add_dialog.html +32 -0
  75. _nullius_app/templates/catalogue/benchmark.html +270 -0
  76. _nullius_app/templates/catalogue/benchmarks.html +91 -0
  77. _nullius_app/templates/catalogue/new.html +141 -0
  78. _nullius_app/templates/catalogue/use_bundle.html +11 -0
  79. _nullius_app/templates/compare/_detail.html +37 -0
  80. _nullius_app/templates/compare/compare.html +298 -0
  81. _nullius_app/templates/compare/compare_picker.html +51 -0
  82. _nullius_app/templates/compare/compare_task.html +329 -0
  83. _nullius_app/templates/runs/_execution.html +131 -0
  84. _nullius_app/templates/runs/_runtime.html +5 -0
  85. _nullius_app/templates/runs/ascii-mark.html +485 -0
  86. _nullius_app/templates/runs/feasibility.html +127 -0
  87. _nullius_app/templates/runs/index.html +609 -0
  88. _nullius_app/templates/runs/job.html +460 -0
  89. _nullius_app/templates/runs/preparing.html +14 -0
  90. _nullius_app/templates/runs/reconcile.html +124 -0
  91. _nullius_app/templates/runs/setup.html +272 -0
  92. _nullius_app/templates/runs/start.html +51 -0
  93. _nullius_app/templates/settings/custom_keys.html +82 -0
  94. _nullius_app/templates/settings/data_providers.html +27 -0
  95. _nullius_app/templates/settings/settings.html +564 -0
  96. _nullius_app/templates/traces/_charts.html +165 -0
  97. _nullius_app/templates/traces/_conversation.html +37 -0
  98. _nullius_app/templates/traces/_judgement.html +72 -0
  99. _nullius_app/templates/traces/artifact.html +15 -0
  100. _nullius_app/templates/traces/trial.html +838 -0
  101. _nullius_app/templates/workspaces/workspaces.html +54 -0
  102. _nullius_app/web/__init__.py +1 -0
  103. _nullius_app/web/agents.py +230 -0
  104. _nullius_app/web/builder.py +406 -0
  105. _nullius_app/web/catalogue.py +370 -0
  106. _nullius_app/web/compare.py +489 -0
  107. _nullius_app/web/core.py +17 -0
  108. _nullius_app/web/execute.py +223 -0
  109. _nullius_app/web/feasibility.py +60 -0
  110. _nullius_app/web/filters.py +231 -0
  111. _nullius_app/web/judge.py +623 -0
  112. _nullius_app/web/judge_tasks.py +33 -0
  113. _nullius_app/web/onboarding.py +20 -0
  114. _nullius_app/web/reconcile.py +47 -0
  115. _nullius_app/web/runs.py +464 -0
  116. _nullius_app/web/settings.py +324 -0
  117. _nullius_app/web/shared.py +507 -0
  118. _nullius_app/web/traces.py +306 -0
  119. _nullius_app/web/workspaces.py +84 -0
  120. nullius/__init__.py +32 -0
  121. nullius/__main__.py +5 -0
  122. nullius/catalogue/__init__.py +0 -0
  123. nullius/catalogue/agents/codex/agent.json +222 -0
  124. nullius/catalogue/agents/codex/config.toml +25 -0
  125. nullius/catalogue/agents/goose/agent.json +131 -0
  126. nullius/catalogue/agents/goose/config.yaml +20 -0
  127. nullius/catalogue/agents/jiuwenswarm/agent.json +197 -0
  128. nullius/catalogue/agents/jiuwenswarm/agent.py +355 -0
  129. nullius/catalogue/agents/mini-swe-agent/agent.json +68 -0
  130. nullius/catalogue/agents/mini-swe-agent/run.py +37 -0
  131. nullius/catalogue/agents/opencode/agent.json +135 -0
  132. nullius/catalogue/agents/opencode/opencode.json +32 -0
  133. nullius/catalogue/agents/reference/agent.json +89 -0
  134. nullius/catalogue/agents/reference/agent.py +209 -0
  135. nullius/catalogue/agents/terminus-2/agent.json +64 -0
  136. nullius/catalogue/agents/terminus-2/run.py +139 -0
  137. nullius/catalogue/benchmarks/gaia/benchmark.json +72 -0
  138. nullius/catalogue/benchmarks/gaia/data-source.json +29 -0
  139. nullius/catalogue/benchmarks/gaia/driver.py +188 -0
  140. nullius/catalogue/benchmarks/gaia/env/data.Dockerfile +1 -0
  141. nullius/catalogue/benchmarks/gaia/standard.json +278 -0
  142. nullius/catalogue/benchmarks/gaia/upstream-settings.json +275 -0
  143. nullius/catalogue/benchmarks/gsm8k/benchmark.json +34 -0
  144. nullius/catalogue/benchmarks/gsm8k/driver.py +101 -0
  145. nullius/catalogue/benchmarks/gsm8k/standard.json +124 -0
  146. nullius/catalogue/benchmarks/gsm8k/upstream-settings.json +86 -0
  147. nullius/catalogue/benchmarks/humaneval/benchmark.json +36 -0
  148. nullius/catalogue/benchmarks/humaneval/driver.py +243 -0
  149. nullius/catalogue/benchmarks/humaneval/standard.json +115 -0
  150. nullius/catalogue/benchmarks/humaneval/upstream-settings.json +72 -0
  151. nullius/catalogue/benchmarks/locomo/benchmark.json +43 -0
  152. nullius/catalogue/benchmarks/locomo/driver.py +270 -0
  153. nullius/catalogue/benchmarks/locomo/standard.json +265 -0
  154. nullius/catalogue/benchmarks/locomo/upstream-settings.json +112 -0
  155. nullius/catalogue/benchmarks/longmemeval/benchmark.json +65 -0
  156. nullius/catalogue/benchmarks/longmemeval/driver.py +379 -0
  157. nullius/catalogue/benchmarks/longmemeval/standard.json +733 -0
  158. nullius/catalogue/benchmarks/longmemeval/upstream-settings.json +76 -0
  159. nullius/catalogue/benchmarks/swe-bench-verified/benchmark.json +87 -0
  160. nullius/catalogue/benchmarks/swe-bench-verified/driver.py +116 -0
  161. nullius/catalogue/benchmarks/swe-bench-verified/images.json +502 -0
  162. nullius/catalogue/benchmarks/swe-bench-verified/standard.json +108 -0
  163. nullius/catalogue/benchmarks/swe-bench-verified/upstream-settings.json +32 -0
  164. nullius/catalogue/benchmarks/tau3-bench/benchmark.json +49 -0
  165. nullius/catalogue/benchmarks/tau3-bench/driver.py +608 -0
  166. nullius/catalogue/benchmarks/tau3-bench/mcp_server.py +114 -0
  167. nullius/catalogue/benchmarks/tau3-bench/search_relay.py +19 -0
  168. nullius/catalogue/benchmarks/tau3-bench/standard.json +547 -0
  169. nullius/catalogue/benchmarks/tau3-bench/upstream-settings.json +639 -0
  170. nullius/catalogue/benchmarks/terminal-bench/benchmark.json +69 -0
  171. nullius/catalogue/benchmarks/terminal-bench/driver.py +267 -0
  172. nullius/catalogue/benchmarks/terminal-bench/standard.json +166 -0
  173. nullius/catalogue/benchmarks/terminal-bench/upstream-settings.json +36 -0
  174. nullius/catalogue/capabilities/keyword-memory/capability.json +33 -0
  175. nullius/catalogue/capabilities/keyword-memory/capability.py +55 -0
  176. nullius/catalogue/capabilities/mem0/capability.json +135 -0
  177. nullius/catalogue/capabilities/mem0/capability.py +173 -0
  178. nullius/catalogue/catalog.py +426 -0
  179. nullius/catalogue/citation.py +116 -0
  180. nullius/catalogue/harbor_entry.py +367 -0
  181. nullius/catalogue/sources.py +107 -0
  182. nullius/catalogue/storage.py +125 -0
  183. nullius/cli.py +85 -0
  184. nullius/compare/__init__.py +0 -0
  185. nullius/compare/cli.py +265 -0
  186. nullius/compare/comparison.py +184 -0
  187. nullius/execution.py +1653 -0
  188. nullius/gitrefs.py +128 -0
  189. nullius/harbor/__init__.py +0 -0
  190. nullius/harbor/feed.py +228 -0
  191. nullius/harbor/source.py +582 -0
  192. nullius/hosts.py +368 -0
  193. nullius/importers/__init__.py +140 -0
  194. nullius/importers/atif.py +387 -0
  195. nullius/importers/cli.py +135 -0
  196. nullius/importers/otel.py +274 -0
  197. nullius/judge/__init__.py +14 -0
  198. nullius/judge/batch.py +122 -0
  199. nullius/judge/client.py +433 -0
  200. nullius/judge/floors.json +86 -0
  201. nullius/judge/lanes.py +89 -0
  202. nullius/judge/questions.py +309 -0
  203. nullius/judge/reconcile.py +176 -0
  204. nullius/judge/state.py +224 -0
  205. nullius/judge/store.py +167 -0
  206. nullius/migrate.py +268 -0
  207. nullius/onboarding.py +116 -0
  208. nullius/paths.py +89 -0
  209. nullius/prerequisites.py +129 -0
  210. nullius/prices.py +283 -0
  211. nullius/progress.py +294 -0
  212. nullius/providers.py +335 -0
  213. nullius/recipes/__init__.py +0 -0
  214. nullius/recipes/launch.py +78 -0
  215. nullius/redact.py +72 -0
  216. nullius/runs/__init__.py +0 -0
  217. nullius/runs/artifacts.py +67 -0
  218. nullius/runs/classify.py +216 -0
  219. nullius/runs/cli.py +316 -0
  220. nullius/runs/feasibility.py +442 -0
  221. nullius/runs/launches.py +149 -0
  222. nullius/runs/live.py +715 -0
  223. nullius/runs/parse.py +1016 -0
  224. nullius/runs/verifier.py +241 -0
  225. nullius/sandbox.py +109 -0
  226. nullius/secrets.py +218 -0
  227. nullius/settings.py +544 -0
  228. nullius/standard/__init__.py +15 -0
  229. nullius/standard/acp.py +305 -0
  230. nullius/standard/cancellation.py +19 -0
  231. nullius/standard/cli.py +703 -0
  232. nullius/standard/conform.py +149 -0
  233. nullius/standard/container.py +1870 -0
  234. nullius/standard/definitions.py +1651 -0
  235. nullius/standard/egress.py +192 -0
  236. nullius/standard/fidelity.py +256 -0
  237. nullius/standard/forward.py +139 -0
  238. nullius/standard/hostreq.py +105 -0
  239. nullius/standard/howto.py +220 -0
  240. nullius/standard/install.py +428 -0
  241. nullius/standard/job.py +551 -0
  242. nullius/standard/jsonl.py +129 -0
  243. nullius/standard/kits/agent-conversation-v1/driver.py +27 -0
  244. nullius/standard/kits/agent-conversation-v1/standard.json +26 -0
  245. nullius/standard/kits/agent-search-v1/driver.py +171 -0
  246. nullius/standard/kits/agent-search-v1/standard.json +99 -0
  247. nullius/standard/kits/agent-task-v1/driver.py +25 -0
  248. nullius/standard/kits/agent-task-v1/standard.json +100 -0
  249. nullius/standard/kits/agent-tools-v1/driver.py +206 -0
  250. nullius/standard/kits/agent-tools-v1/mcp_kit.py +209 -0
  251. nullius/standard/kits/agent-tools-v1/standard.json +119 -0
  252. nullius/standard/kits/agent-workspace-v1/driver.py +65 -0
  253. nullius/standard/kits/agent-workspace-v1/standard.json +95 -0
  254. nullius/standard/kits/cap-memory-v1/driver.py +39 -0
  255. nullius/standard/kits/cap-memory-v1/standard.json +91 -0
  256. nullius/standard/ledger.py +326 -0
  257. nullius/standard/match.py +66 -0
  258. nullius/standard/mcp_bridge.py +62 -0
  259. nullius/standard/mcp_machine.py +193 -0
  260. nullius/standard/merge.py +239 -0
  261. nullius/standard/names.py +37 -0
  262. nullius/standard/network_requirements.py +44 -0
  263. nullius/standard/pace.py +53 -0
  264. nullius/standard/payload.py +278 -0
  265. nullius/standard/pins.py +130 -0
  266. nullius/standard/ports.py +70 -0
  267. nullius/standard/prove.py +373 -0
  268. nullius/standard/recipe.py +746 -0
  269. nullius/standard/relay.py +785 -0
  270. nullius/standard/run.py +1781 -0
  271. nullius/standard/setup_container.py +208 -0
  272. nullius/standard/shard.py +71 -0
  273. nullius/standard/web_services.py +30 -0
  274. nullius/traces/__init__.py +0 -0
  275. nullius/traces/behavior.py +131 -0
  276. nullius/traces/charts.py +898 -0
  277. nullius/traces/conversation.py +159 -0
  278. nullius/traces/otel.py +608 -0
  279. nullius/traces/trace.py +1477 -0
  280. nullius/traces/trajectory.py +586 -0
  281. nullius/workspace.py +417 -0
  282. nullius/workspace_cli.py +119 -0
  283. nullius_eval-0.1.0.dist-info/METADATA +93 -0
  284. nullius_eval-0.1.0.dist-info/RECORD +291 -0
  285. nullius_eval-0.1.0.dist-info/WHEEL +5 -0
  286. nullius_eval-0.1.0.dist-info/entry_points.txt +2 -0
  287. nullius_eval-0.1.0.dist-info/licenses/LICENSE +202 -0
  288. nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/dmsans-OFL.txt +93 -0
  289. nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/ibmplexmono-OFL.txt +93 -0
  290. nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/instrumentserif-OFL.txt +93 -0
  291. nullius_eval-0.1.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,324 @@
1
+ """The Settings page and its one Save."""
2
+ from __future__ import annotations
3
+
4
+ import os
5
+ from flask import abort, flash, jsonify, redirect, render_template, request, url_for
6
+ from nullius import execution, hosts, paths, prices, providers, sandbox, secrets, settings
7
+ from nullius.standard import recipe as standard_recipe
8
+ from nullius.judge import client
9
+
10
+ from .core import app
11
+ from . import shared
12
+
13
+
14
+ def _local_client() -> bool:
15
+ """Only a browser on this machine may write settings: the request comes
16
+ from a loopback address and nothing says it was forwarded."""
17
+ forwarded = any(h in request.headers for h in ("X-Forwarded-For", "X-Real-Ip", "Forwarded"))
18
+ return request.remote_addr in ("127.0.0.1", "::1") and not forwarded
19
+
20
+
21
+ @app.route("/settings")
22
+ def settings_page():
23
+ """Every variable the application reads, its state and where it comes
24
+ from; a secret by presence only."""
25
+ rows = settings.states(shared.ENV_FILE)
26
+ withheld = set(execution.withheld()) # what a run never inherits, read or not
27
+ groups = [(g, [r for r in rows if r["group"] == g]) for g in settings.GROUPS]
28
+ access = []
29
+ filed = settings.in_file(shared.ENV_FILE)
30
+ for benchmark in shared._catalog_cached().benchmarks:
31
+ if "standard" not in benchmark.harness:
32
+ continue
33
+ needs = {}
34
+ for environment in standard_recipe.licences_of(benchmark.key):
35
+ for secret in environment["needs"]:
36
+ if secret.get("provider"): # a data provider's token: Data providers alone
37
+ continue
38
+ needs.setdefault(secret["name"], dict(secret, movable=secret["name"] in filed))
39
+ if needs:
40
+ access.append({"key": benchmark.key, "title": benchmark.title, "needs": list(needs.values())})
41
+ # A written value that goes unseen is said rather than left silent: a key no setting reads.
42
+ return render_template("settings/settings.html", embedded=request.args.get("embedded") == "1", groups=groups, benchmark_access=access, csrf=shared._csrf_token(), writable=_local_client(),
43
+ env_file=shared.ENV_FILE,
44
+ storage_paths=[("Settings", shared.ENV_FILE), ("User catalogue", paths.catalogue_dir()),
45
+ ("Workspaces", paths.workspaces_dir()), ("Runs", paths.runs_dir()),
46
+ ("Benchmark licences", paths.secrets_dir()), ("Model prices", paths.prices_file()),
47
+ ("Cache", paths.cache_dir())],
48
+ unread=[dict(u, inherited=u["name"] not in withheld, startup=u["instead"] in settings.STARTUP)
49
+ for u in settings.unread(shared.ENV_FILE)],
50
+ prices=prices.state(),
51
+ ssh_hosts=hosts.scan_ssh_config(), judges=(client.system_one(os.environ), client.llm_judge(os.environ)), llm_providers=client.llm_providers(os.environ), s1_providers=client.SYSTEM_ONE_PROVIDERS, agent_keys=settings.agent_key_names(),
52
+ endpoints=[(i, os.environ.get(f"MODEL_{i}_NAME") or i) for i in settings.endpoint_ids()],
53
+ tested={k: _shown(v) for k, v in providers.tests().items() if isinstance(v, dict)})
54
+
55
+
56
+ def _shown(result: dict) -> dict:
57
+ """A provider's test as its card shows it: the result, its line and its mark."""
58
+ return dict(result, said=providers.said(result), mark=providers.mark(result))
59
+
60
+
61
+ @app.route("/settings/providers/test", methods=["POST"])
62
+ def settings_provider_test():
63
+ """One provider asked with the saved settings, at no cost (``providers.test``), and its result kept
64
+ for the card and Review; only when Test is pressed. Same guards as Save."""
65
+ _sandbox_guard("Providers are tested")
66
+ choice = request.form.get("provider", "")
67
+ try:
68
+ got = providers.test(choice)
69
+ except ValueError as e:
70
+ return jsonify(ok=False, error=str(e)), 400
71
+ providers.remember({choice: got})
72
+ return jsonify(_shown(got))
73
+
74
+
75
+ @app.route("/settings/hosts/test", methods=["POST"])
76
+ def settings_host_test():
77
+ """One host, one ssh: does it answer without a prompt, and are uv, docker
78
+ and harbor there. Same guards as Save; nothing is stored, nothing but
79
+ the probe is sent. The entry need not be saved yet."""
80
+ shared._require_csrf()
81
+ if not _local_client():
82
+ abort(403, description="Hosts are tested from a browser on the application host only.")
83
+ try:
84
+ host = hosts.parse(request.form.get("entry", ""))
85
+ except ValueError as e:
86
+ return jsonify(ok=False, error=str(e)), 400
87
+ return jsonify(hosts.test(host))
88
+
89
+
90
+ def _host_form():
91
+ """user, host, port from the Add host form, checked as an entry would be."""
92
+ user, host, port = request.form.get("user", "").strip(), request.form.get("host", "").strip(), request.form.get("port", "").strip()
93
+ parsed = hosts.parse(f"{user}@{host}" + (f":{port}" if port else ""))
94
+ return parsed.user, parsed.host, parsed.port
95
+
96
+
97
+ @app.route("/settings/hosts/key", methods=["POST"])
98
+ def settings_host_key():
99
+ """A key file for a manual host, kept under <config>/ssh with mode
100
+ 0600 until Save removes its host; the entry that names it comes back.
101
+ Same guards as Save."""
102
+ shared._require_csrf()
103
+ if not _local_client():
104
+ abort(403, description="Hosts are added from a browser on the application host only.")
105
+ upload = request.files.get("key")
106
+ try:
107
+ user, host, port = _host_form()
108
+ if upload is None or not upload.filename:
109
+ raise ValueError("no key file")
110
+ path = hosts.save_key(user, host, upload.read(20001))
111
+ except ValueError as e:
112
+ return jsonify(ok=False, error=str(e)), 400
113
+ except OSError as e:
114
+ return jsonify(ok=False, error=f"not written: {e.strerror or e}"), 500
115
+ return jsonify(ok=True, entry=f"{user}@{host}" + (f":{port}" if port else "") + f":{path}")
116
+
117
+
118
+ @app.route("/settings/hosts/enrol", methods=["POST"])
119
+ def settings_host_enrol():
120
+ """A password, used once: Nullius's own public key goes into the host's
121
+ authorized_keys over ssh, and the entry that comes back names that key.
122
+ The password is neither stored nor logged. Same guards as Save."""
123
+ shared._require_csrf()
124
+ if not _local_client():
125
+ abort(403, description="Hosts are added from a browser on the application host only.")
126
+ try:
127
+ user, host, port = _host_form()
128
+ password = request.form.get("password", "")
129
+ if not password:
130
+ raise ValueError("no password")
131
+ entry = hosts.enrol(user, host, port, password)
132
+ except ValueError as e:
133
+ return jsonify(ok=False, error=str(e)), 400
134
+ except RuntimeError as e:
135
+ return jsonify(ok=False, error=str(e)), 502
136
+ return jsonify(ok=True, entry=entry.entry)
137
+
138
+
139
+ @app.route("/settings/sandbox")
140
+ def settings_sandbox():
141
+ """The Sandbox section's state, asked when the section opens: docker's."""
142
+ return jsonify(docker=sandbox.docker_state())
143
+
144
+
145
+ @app.route("/settings/data-providers")
146
+ def settings_data_providers():
147
+ """Connection metadata only; no credential is returned."""
148
+ return jsonify(huggingface=bool(secrets.status(secrets.HUGGINGFACE).get("HF_TOKEN", {}).get("set")),
149
+ dockerhub=sandbox.login_user())
150
+
151
+
152
+ @app.route("/settings/data-providers/huggingface", methods=["POST"])
153
+ def settings_huggingface():
154
+ _sandbox_guard("Data providers are changed")
155
+ action = request.form.get("action", "save")
156
+ try:
157
+ if action == "remove":
158
+ secrets.delete(secrets.HUGGINGFACE, "HF_TOKEN")
159
+ elif action == "save":
160
+ secrets.set(secrets.HUGGINGFACE, "HF_TOKEN", request.form.get("token", ""))
161
+ else:
162
+ return jsonify(ok=False, error="Unknown action."), 400
163
+ except ValueError as e:
164
+ return jsonify(ok=False, error=str(e)), 400
165
+ except OSError:
166
+ return jsonify(ok=False, error="Could not update the credential store."), 500
167
+ return jsonify(ok=True)
168
+
169
+
170
+ def _sandbox_guard(what):
171
+ shared._require_csrf()
172
+ if not _local_client():
173
+ abort(403, description=f"{what} from a browser on the application host only.")
174
+
175
+
176
+ @app.route("/settings/sandbox/login", methods=["POST"])
177
+ def settings_sandbox_login():
178
+ """A Docker Hub username and access token, handed to docker login once;
179
+ neither is stored or logged by Nullius. Same guards as Save."""
180
+ _sandbox_guard("Docker logs in")
181
+ got = sandbox.login(request.form.get("username", ""), request.form.get("token", ""))
182
+ return jsonify(got), (200 if got["ok"] else 400)
183
+
184
+
185
+ @app.route("/settings/sandbox/logout", methods=["POST"])
186
+ def settings_sandbox_logout():
187
+ _sandbox_guard("Docker logs out")
188
+ got = sandbox.logout()
189
+ return jsonify(got), (200 if got["ok"] else 502)
190
+
191
+
192
+ @app.route("/settings/prices/update", methods=["POST"])
193
+ def settings_prices_update():
194
+ """The public price list fetched and kept (``nullius.prices``): the one
195
+ fetch, asked for here and never by a run. Same guards as Save."""
196
+ _sandbox_guard("Prices are updated")
197
+ try:
198
+ prices.update()
199
+ except ValueError as e:
200
+ return jsonify(ok=False, error=str(e)), 502
201
+ return jsonify(ok=True, **prices.state())
202
+
203
+
204
+ @app.route("/settings/prices/set", methods=["POST"])
205
+ def settings_prices_set():
206
+ """A price of the user's own for one model, over the list."""
207
+ _sandbox_guard("Prices are set")
208
+ f = request.form
209
+ try:
210
+ prices.set_own(f.get("model", ""), prices.row(f.get("input") or None, f.get("output") or None, f.get("cached") or None,
211
+ f.get("cache_write") or None, cache_write_1h=f.get("cache_write_1h") or None))
212
+ except (ValueError, TypeError) as e:
213
+ return jsonify(ok=False, error=str(e)), 400
214
+ return jsonify(ok=True, **prices.state())
215
+
216
+
217
+ @app.route("/settings/prices/remove", methods=["POST"])
218
+ def settings_prices_remove():
219
+ _sandbox_guard("Prices are removed")
220
+ if not prices.remove_own(request.form.get("model", "")):
221
+ return jsonify(ok=False, error="not one of your own prices"), 404
222
+ return jsonify(ok=True, **prices.state())
223
+
224
+
225
+ # The settings each built-in provider card holds; an OpenAI-compatible endpoint's are its own.
226
+ _PROVIDER_SETTINGS = {"typesafe": ["TYPESAFE_API_KEY"], "openrouter": ["OPENROUTER_API_KEY"], "openai": ["OPENAI_API_KEY"],
227
+ "anthropic": ["ANTHROPIC_API_KEY"], "local": ["MODEL_API_URL", "MODEL_API_KEY"]}
228
+
229
+
230
+ def _provider_settings(card: str, ids) -> list:
231
+ """The settings a provider card names (``local:<id>``, an endpoint), or [] for none."""
232
+ kind, _, i = card.partition(":")
233
+ if kind == "local" and i:
234
+ return settings.endpoint_settings(i) if i in ids else []
235
+ return _PROVIDER_SETTINGS.get(card, [])
236
+
237
+
238
+ def _settings_return():
239
+ return url_for("settings_page", embedded="1") if request.form.get("embedded") == "1" else url_for("settings_page")
240
+
241
+
242
+ def _saved_response(message, ok=True, anchor="", retryable=False, reload=False):
243
+ if request.accept_mimetypes.best == "application/json":
244
+ # Re-render only masked state, never echo a submitted credential. reload: the page's cards changed.
245
+ return jsonify(ok=ok, message=message, retryable=retryable, reload=reload, html=settings_page() if ok else ""), (200 if ok else 500 if retryable else 400)
246
+ flash(message, "ok" if ok else "error")
247
+ return redirect(_settings_return() + anchor)
248
+
249
+
250
+ @app.route("/settings/save", methods=["POST"])
251
+ def settings_save():
252
+ """One form, one Save: every variable the page shows, in user settings. Same
253
+ guards as the environment mutations, plus: loopback clients only; every
254
+ value validated for its kind before any is written; values never echoed
255
+ back or logged. A field left empty keeps what is set; the row's × removes
256
+ the variable from the file. A variable the process environment also holds
257
+ is written to the file for the next start, and the message says so."""
258
+ shared._require_csrf()
259
+ if not _local_client():
260
+ abort(403, description="Settings are written from a browser on the application host only.")
261
+ current = {s["name"]: s for s in settings.states(shared.ENV_FILE)}
262
+ changes = {}
263
+ names = settings.agent_key_names()
264
+ ids = settings.endpoint_ids()
265
+ for var in (settings.VARIABLES + [settings.agent_variable(n) for n in names]
266
+ + [settings.endpoint_variable(n) for i in ids for n in settings.endpoint_settings(i)]):
267
+ posted = request.form.get("value:" + var.name)
268
+ if posted is None:
269
+ continue
270
+ posted = posted.strip()
271
+ if request.form.get("clear:" + var.name) == "1":
272
+ if current[var.name]["source"] != "unset":
273
+ changes[var.name] = None
274
+ elif posted and (var.secret or posted != current[var.name]["shown"]):
275
+ changes[var.name] = posted
276
+ # Agent keys: one added by name and value, one removed with its name; the list of names follows them
277
+ keep = [n for n in names if changes.get(n, "") is not None]
278
+ new_name = (request.form.get("agent_key_name") or "").strip().upper()
279
+ new_value = (request.form.get("agent_key_value") or "").strip()
280
+ if new_name or new_value:
281
+ if not (new_name and new_value):
282
+ return _saved_response("A custom key needs its name and its value.", False, "#custom-keys")
283
+ if new_name not in keep:
284
+ keep.append(new_name)
285
+ changes[new_name] = new_value
286
+ if keep != names:
287
+ changes["AGENT_KEYS"] = ",".join(keep) if keep else None
288
+ # A provider removed from its card: every setting of it, refused while the process environment holds one
289
+ gone = (request.form.get("remove_provider") or "").strip()
290
+ if gone:
291
+ held = _provider_settings(gone, ids)
292
+ if not held:
293
+ return _saved_response("Not a provider on this page.", False, "#providers")
294
+ env = [n for n in held if current[n]["source"] == "environment"]
295
+ if env:
296
+ return _saved_response(f"{', '.join(env)} is set in the process environment; remove it there.", False, "#providers")
297
+ changes.update({n: None for n in held if current[n]["source"] != "unset"})
298
+ # An endpoint added by name and URL, its key optional
299
+ new = {part: (request.form.get("endpoint_" + part) or "").strip() for part in ("name", "url", "key")}
300
+ if any(new.values()):
301
+ if not (new["name"] and new["url"]):
302
+ return _saved_response("An endpoint needs its name and its URL.", False, "#providers")
303
+ i = settings.new_endpoint_id(new["name"], set(ids) | set(settings.endpoint_ids(settings.in_file(shared.ENV_FILE))))
304
+ changes.update({f"MODEL_{i}_NAME": new["name"], f"MODEL_{i}_API_URL": new["url"], **({f"MODEL_{i}_API_KEY": new["key"]} if new["key"] else {})})
305
+ cards = bool(gone) or any(settings.endpoint_variable(n) and (n.endswith("_NAME") or n not in current or changes[n] is None) for n in changes)
306
+ if not changes:
307
+ return _saved_response("Nothing changed.")
308
+ try:
309
+ settings.save_many(shared.ENV_FILE, changes)
310
+ except ValueError as e:
311
+ return _saved_response(str(e), False)
312
+ except OSError as e:
313
+ return _saved_response(f"Not written: {e.strerror or e}", False, retryable=True)
314
+ # a provider whose settings changed is no longer what its last test asked
315
+ stale = {card.replace("local", "custom", 1): None for card in [*_PROVIDER_SETTINGS, *(f"local:{i}" for i in ids)]
316
+ if set(_provider_settings(card, ids)) & set(changes)}
317
+ if stale.keys() & providers.tests().keys():
318
+ providers.remember(stale)
319
+ later = any(current.get(n, {}).get("source") == "environment" for n in changes)
320
+ notes = ["Environment overrides still apply."] if later else []
321
+ if "HOSTS" in changes and current["HOSTS"]["source"] == "file": # a list from the environment is not this page's
322
+ notes += [f"The key file for {os.path.basename(p)} could not be removed: {why}."
323
+ for p, why in hosts.forget_keys(current["HOSTS"]["shown"], changes["HOSTS"] or "")]
324
+ return _saved_response(" ".join(["Saved."] + notes) if notes else "Saved", reload=cards)