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.
- _nullius_app/.env.example +55 -0
- _nullius_app/app.py +96 -0
- _nullius_app/requirements.txt +1 -0
- _nullius_app/static/brand/README.md +20 -0
- _nullius_app/static/brand/docker.svg +1 -0
- _nullius_app/static/brand/favicon.svg +1 -0
- _nullius_app/static/brand/huggingface.svg +37 -0
- _nullius_app/static/brand/mark-dark.svg +1 -0
- _nullius_app/static/brand/marks.svg +34 -0
- _nullius_app/static/brand/tokens.json +51 -0
- _nullius_app/static/brand/typesafe.png +0 -0
- _nullius_app/static/brand/wordmark-dark.svg +1 -0
- _nullius_app/static/builder/command-builder-core.js +763 -0
- _nullius_app/static/builder/command-builder.css +248 -0
- _nullius_app/static/builder/command-builder.js +997 -0
- _nullius_app/static/builder/model-picker.js +113 -0
- _nullius_app/static/catalogue/add.js +46 -0
- _nullius_app/static/catalogue/agents/README.md +19 -0
- _nullius_app/static/catalogue/agents/goose.svg +1 -0
- _nullius_app/static/catalogue/agents/jiuwenswarm.svg +33 -0
- _nullius_app/static/catalogue/agents/marks.json +8 -0
- _nullius_app/static/catalogue/agents/mini-swe-agent.svg +7 -0
- _nullius_app/static/catalogue/agents/opencode.svg +7 -0
- _nullius_app/static/catalogue/catalogue.css +436 -0
- _nullius_app/static/catalogue/catalogue.js +87 -0
- _nullius_app/static/catalogue/marks.svg +29 -0
- _nullius_app/static/catalogue/new.js +78 -0
- _nullius_app/static/catalogue/versions.js +27 -0
- _nullius_app/static/compare/comparison.css +117 -0
- _nullius_app/static/controls.js +117 -0
- _nullius_app/static/disclosures.js +70 -0
- _nullius_app/static/fonts/0569c822cab6c510.ttf +0 -0
- _nullius_app/static/fonts/DMSans-Medium.woff2 +0 -0
- _nullius_app/static/fonts/DMSans-Regular.woff2 +0 -0
- _nullius_app/static/fonts/IBMPlexMono-Medium.woff2 +0 -0
- _nullius_app/static/fonts/IBMPlexMono-Regular.woff2 +0 -0
- _nullius_app/static/fonts/InstrumentSerif-Italic.woff2 +0 -0
- _nullius_app/static/fonts/InstrumentSerif-Regular.woff2 +0 -0
- _nullius_app/static/fonts/README.md +11 -0
- _nullius_app/static/fonts/c1e7453ea26a1d1e.ttf +0 -0
- _nullius_app/static/fonts/dmsans-OFL.txt +93 -0
- _nullius_app/static/fonts/ibmplexmono-OFL.txt +93 -0
- _nullius_app/static/fonts/instrumentserif-OFL.txt +93 -0
- _nullius_app/static/fonts.css +49 -0
- _nullius_app/static/notifications.js +49 -0
- _nullius_app/static/onboarding.css +78 -0
- _nullius_app/static/onboarding.js +158 -0
- _nullius_app/static/runs/board.css +358 -0
- _nullius_app/static/runs/board.js +127 -0
- _nullius_app/static/runs/launches.css +88 -0
- _nullius_app/static/runs/live-board.css +186 -0
- _nullius_app/static/runs/live-board.js +394 -0
- _nullius_app/static/runs/path-suggestions.js +119 -0
- _nullius_app/static/runs/start.css +38 -0
- _nullius_app/static/settings/autosave.js +162 -0
- _nullius_app/static/settings/custom-keys.js +100 -0
- _nullius_app/static/settings/data-providers.js +88 -0
- _nullius_app/static/settings/judges.js +61 -0
- _nullius_app/static/settings/modal.css +32 -0
- _nullius_app/static/settings/modal.js +91 -0
- _nullius_app/static/settings/navigation.js +55 -0
- _nullius_app/static/settings/prices.js +68 -0
- _nullius_app/static/settings/providers.js +134 -0
- _nullius_app/static/settings/sandbox.js +20 -0
- _nullius_app/static/settings/settings.css +288 -0
- _nullius_app/static/style.css +1752 -0
- _nullius_app/static/traces/conversation.css +49 -0
- _nullius_app/static/traces/conversation.js +215 -0
- _nullius_app/templates/agents/entry.html +145 -0
- _nullius_app/templates/agents/kits.html +55 -0
- _nullius_app/templates/agents/standard.html +58 -0
- _nullius_app/templates/base.html +479 -0
- _nullius_app/templates/builder/new_run.html +55 -0
- _nullius_app/templates/catalogue/add_dialog.html +32 -0
- _nullius_app/templates/catalogue/benchmark.html +270 -0
- _nullius_app/templates/catalogue/benchmarks.html +91 -0
- _nullius_app/templates/catalogue/new.html +141 -0
- _nullius_app/templates/catalogue/use_bundle.html +11 -0
- _nullius_app/templates/compare/_detail.html +37 -0
- _nullius_app/templates/compare/compare.html +298 -0
- _nullius_app/templates/compare/compare_picker.html +51 -0
- _nullius_app/templates/compare/compare_task.html +329 -0
- _nullius_app/templates/runs/_execution.html +131 -0
- _nullius_app/templates/runs/_runtime.html +5 -0
- _nullius_app/templates/runs/ascii-mark.html +485 -0
- _nullius_app/templates/runs/feasibility.html +127 -0
- _nullius_app/templates/runs/index.html +609 -0
- _nullius_app/templates/runs/job.html +460 -0
- _nullius_app/templates/runs/preparing.html +14 -0
- _nullius_app/templates/runs/reconcile.html +124 -0
- _nullius_app/templates/runs/setup.html +272 -0
- _nullius_app/templates/runs/start.html +51 -0
- _nullius_app/templates/settings/custom_keys.html +82 -0
- _nullius_app/templates/settings/data_providers.html +27 -0
- _nullius_app/templates/settings/settings.html +564 -0
- _nullius_app/templates/traces/_charts.html +165 -0
- _nullius_app/templates/traces/_conversation.html +37 -0
- _nullius_app/templates/traces/_judgement.html +72 -0
- _nullius_app/templates/traces/artifact.html +15 -0
- _nullius_app/templates/traces/trial.html +838 -0
- _nullius_app/templates/workspaces/workspaces.html +54 -0
- _nullius_app/web/__init__.py +1 -0
- _nullius_app/web/agents.py +230 -0
- _nullius_app/web/builder.py +406 -0
- _nullius_app/web/catalogue.py +370 -0
- _nullius_app/web/compare.py +489 -0
- _nullius_app/web/core.py +17 -0
- _nullius_app/web/execute.py +223 -0
- _nullius_app/web/feasibility.py +60 -0
- _nullius_app/web/filters.py +231 -0
- _nullius_app/web/judge.py +623 -0
- _nullius_app/web/judge_tasks.py +33 -0
- _nullius_app/web/onboarding.py +20 -0
- _nullius_app/web/reconcile.py +47 -0
- _nullius_app/web/runs.py +464 -0
- _nullius_app/web/settings.py +324 -0
- _nullius_app/web/shared.py +507 -0
- _nullius_app/web/traces.py +306 -0
- _nullius_app/web/workspaces.py +84 -0
- nullius/__init__.py +32 -0
- nullius/__main__.py +5 -0
- nullius/catalogue/__init__.py +0 -0
- nullius/catalogue/agents/codex/agent.json +222 -0
- nullius/catalogue/agents/codex/config.toml +25 -0
- nullius/catalogue/agents/goose/agent.json +131 -0
- nullius/catalogue/agents/goose/config.yaml +20 -0
- nullius/catalogue/agents/jiuwenswarm/agent.json +197 -0
- nullius/catalogue/agents/jiuwenswarm/agent.py +355 -0
- nullius/catalogue/agents/mini-swe-agent/agent.json +68 -0
- nullius/catalogue/agents/mini-swe-agent/run.py +37 -0
- nullius/catalogue/agents/opencode/agent.json +135 -0
- nullius/catalogue/agents/opencode/opencode.json +32 -0
- nullius/catalogue/agents/reference/agent.json +89 -0
- nullius/catalogue/agents/reference/agent.py +209 -0
- nullius/catalogue/agents/terminus-2/agent.json +64 -0
- nullius/catalogue/agents/terminus-2/run.py +139 -0
- nullius/catalogue/benchmarks/gaia/benchmark.json +72 -0
- nullius/catalogue/benchmarks/gaia/data-source.json +29 -0
- nullius/catalogue/benchmarks/gaia/driver.py +188 -0
- nullius/catalogue/benchmarks/gaia/env/data.Dockerfile +1 -0
- nullius/catalogue/benchmarks/gaia/standard.json +278 -0
- nullius/catalogue/benchmarks/gaia/upstream-settings.json +275 -0
- nullius/catalogue/benchmarks/gsm8k/benchmark.json +34 -0
- nullius/catalogue/benchmarks/gsm8k/driver.py +101 -0
- nullius/catalogue/benchmarks/gsm8k/standard.json +124 -0
- nullius/catalogue/benchmarks/gsm8k/upstream-settings.json +86 -0
- nullius/catalogue/benchmarks/humaneval/benchmark.json +36 -0
- nullius/catalogue/benchmarks/humaneval/driver.py +243 -0
- nullius/catalogue/benchmarks/humaneval/standard.json +115 -0
- nullius/catalogue/benchmarks/humaneval/upstream-settings.json +72 -0
- nullius/catalogue/benchmarks/locomo/benchmark.json +43 -0
- nullius/catalogue/benchmarks/locomo/driver.py +270 -0
- nullius/catalogue/benchmarks/locomo/standard.json +265 -0
- nullius/catalogue/benchmarks/locomo/upstream-settings.json +112 -0
- nullius/catalogue/benchmarks/longmemeval/benchmark.json +65 -0
- nullius/catalogue/benchmarks/longmemeval/driver.py +379 -0
- nullius/catalogue/benchmarks/longmemeval/standard.json +733 -0
- nullius/catalogue/benchmarks/longmemeval/upstream-settings.json +76 -0
- nullius/catalogue/benchmarks/swe-bench-verified/benchmark.json +87 -0
- nullius/catalogue/benchmarks/swe-bench-verified/driver.py +116 -0
- nullius/catalogue/benchmarks/swe-bench-verified/images.json +502 -0
- nullius/catalogue/benchmarks/swe-bench-verified/standard.json +108 -0
- nullius/catalogue/benchmarks/swe-bench-verified/upstream-settings.json +32 -0
- nullius/catalogue/benchmarks/tau3-bench/benchmark.json +49 -0
- nullius/catalogue/benchmarks/tau3-bench/driver.py +608 -0
- nullius/catalogue/benchmarks/tau3-bench/mcp_server.py +114 -0
- nullius/catalogue/benchmarks/tau3-bench/search_relay.py +19 -0
- nullius/catalogue/benchmarks/tau3-bench/standard.json +547 -0
- nullius/catalogue/benchmarks/tau3-bench/upstream-settings.json +639 -0
- nullius/catalogue/benchmarks/terminal-bench/benchmark.json +69 -0
- nullius/catalogue/benchmarks/terminal-bench/driver.py +267 -0
- nullius/catalogue/benchmarks/terminal-bench/standard.json +166 -0
- nullius/catalogue/benchmarks/terminal-bench/upstream-settings.json +36 -0
- nullius/catalogue/capabilities/keyword-memory/capability.json +33 -0
- nullius/catalogue/capabilities/keyword-memory/capability.py +55 -0
- nullius/catalogue/capabilities/mem0/capability.json +135 -0
- nullius/catalogue/capabilities/mem0/capability.py +173 -0
- nullius/catalogue/catalog.py +426 -0
- nullius/catalogue/citation.py +116 -0
- nullius/catalogue/harbor_entry.py +367 -0
- nullius/catalogue/sources.py +107 -0
- nullius/catalogue/storage.py +125 -0
- nullius/cli.py +85 -0
- nullius/compare/__init__.py +0 -0
- nullius/compare/cli.py +265 -0
- nullius/compare/comparison.py +184 -0
- nullius/execution.py +1653 -0
- nullius/gitrefs.py +128 -0
- nullius/harbor/__init__.py +0 -0
- nullius/harbor/feed.py +228 -0
- nullius/harbor/source.py +582 -0
- nullius/hosts.py +368 -0
- nullius/importers/__init__.py +140 -0
- nullius/importers/atif.py +387 -0
- nullius/importers/cli.py +135 -0
- nullius/importers/otel.py +274 -0
- nullius/judge/__init__.py +14 -0
- nullius/judge/batch.py +122 -0
- nullius/judge/client.py +433 -0
- nullius/judge/floors.json +86 -0
- nullius/judge/lanes.py +89 -0
- nullius/judge/questions.py +309 -0
- nullius/judge/reconcile.py +176 -0
- nullius/judge/state.py +224 -0
- nullius/judge/store.py +167 -0
- nullius/migrate.py +268 -0
- nullius/onboarding.py +116 -0
- nullius/paths.py +89 -0
- nullius/prerequisites.py +129 -0
- nullius/prices.py +283 -0
- nullius/progress.py +294 -0
- nullius/providers.py +335 -0
- nullius/recipes/__init__.py +0 -0
- nullius/recipes/launch.py +78 -0
- nullius/redact.py +72 -0
- nullius/runs/__init__.py +0 -0
- nullius/runs/artifacts.py +67 -0
- nullius/runs/classify.py +216 -0
- nullius/runs/cli.py +316 -0
- nullius/runs/feasibility.py +442 -0
- nullius/runs/launches.py +149 -0
- nullius/runs/live.py +715 -0
- nullius/runs/parse.py +1016 -0
- nullius/runs/verifier.py +241 -0
- nullius/sandbox.py +109 -0
- nullius/secrets.py +218 -0
- nullius/settings.py +544 -0
- nullius/standard/__init__.py +15 -0
- nullius/standard/acp.py +305 -0
- nullius/standard/cancellation.py +19 -0
- nullius/standard/cli.py +703 -0
- nullius/standard/conform.py +149 -0
- nullius/standard/container.py +1870 -0
- nullius/standard/definitions.py +1651 -0
- nullius/standard/egress.py +192 -0
- nullius/standard/fidelity.py +256 -0
- nullius/standard/forward.py +139 -0
- nullius/standard/hostreq.py +105 -0
- nullius/standard/howto.py +220 -0
- nullius/standard/install.py +428 -0
- nullius/standard/job.py +551 -0
- nullius/standard/jsonl.py +129 -0
- nullius/standard/kits/agent-conversation-v1/driver.py +27 -0
- nullius/standard/kits/agent-conversation-v1/standard.json +26 -0
- nullius/standard/kits/agent-search-v1/driver.py +171 -0
- nullius/standard/kits/agent-search-v1/standard.json +99 -0
- nullius/standard/kits/agent-task-v1/driver.py +25 -0
- nullius/standard/kits/agent-task-v1/standard.json +100 -0
- nullius/standard/kits/agent-tools-v1/driver.py +206 -0
- nullius/standard/kits/agent-tools-v1/mcp_kit.py +209 -0
- nullius/standard/kits/agent-tools-v1/standard.json +119 -0
- nullius/standard/kits/agent-workspace-v1/driver.py +65 -0
- nullius/standard/kits/agent-workspace-v1/standard.json +95 -0
- nullius/standard/kits/cap-memory-v1/driver.py +39 -0
- nullius/standard/kits/cap-memory-v1/standard.json +91 -0
- nullius/standard/ledger.py +326 -0
- nullius/standard/match.py +66 -0
- nullius/standard/mcp_bridge.py +62 -0
- nullius/standard/mcp_machine.py +193 -0
- nullius/standard/merge.py +239 -0
- nullius/standard/names.py +37 -0
- nullius/standard/network_requirements.py +44 -0
- nullius/standard/pace.py +53 -0
- nullius/standard/payload.py +278 -0
- nullius/standard/pins.py +130 -0
- nullius/standard/ports.py +70 -0
- nullius/standard/prove.py +373 -0
- nullius/standard/recipe.py +746 -0
- nullius/standard/relay.py +785 -0
- nullius/standard/run.py +1781 -0
- nullius/standard/setup_container.py +208 -0
- nullius/standard/shard.py +71 -0
- nullius/standard/web_services.py +30 -0
- nullius/traces/__init__.py +0 -0
- nullius/traces/behavior.py +131 -0
- nullius/traces/charts.py +898 -0
- nullius/traces/conversation.py +159 -0
- nullius/traces/otel.py +608 -0
- nullius/traces/trace.py +1477 -0
- nullius/traces/trajectory.py +586 -0
- nullius/workspace.py +417 -0
- nullius/workspace_cli.py +119 -0
- nullius_eval-0.1.0.dist-info/METADATA +93 -0
- nullius_eval-0.1.0.dist-info/RECORD +291 -0
- nullius_eval-0.1.0.dist-info/WHEEL +5 -0
- nullius_eval-0.1.0.dist-info/entry_points.txt +2 -0
- nullius_eval-0.1.0.dist-info/licenses/LICENSE +202 -0
- nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/dmsans-OFL.txt +93 -0
- nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/ibmplexmono-OFL.txt +93 -0
- nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/instrumentserif-OFL.txt +93 -0
- 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)
|