From 2e409d709a7bd48e257cd4eff0948f82d867ce9c Mon Sep 17 00:00:00 2001 From: Hermes Date: Sun, 8 Nov 2026 08:41:57 +0000 Subject: [PATCH] repo: comment and doc text in English, systemd start limit where it counts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The configuration examples were the last mixed-language place: full-reference.conf (425 lines), config.example and prices.conf had German comments. Directives are byte-identical in every file (verified by diffing the non-comment lines against HEAD), each file still parses. web/README.md was German as well. systemd-analyze caught a real bug while checking the unit: StartLimitIntervalSec=0 sat in [Service], where systemd ignores it without a word — so the crash-loop protection was the default five starts in ten seconds, and a router that keeps dying would simply stay dead. It now sits in [Unit] together with StartLimitBurst=0, in packaging/junction.service and in the live unit (systemctl show: both values 0). --- config.example | 22 ++- examples/full-reference.conf | 346 ++++++++++++++++++----------------- examples/prices.conf | 39 ++-- packaging/junction.service | 25 +-- web/README.md | 32 ++-- 5 files changed, 236 insertions(+), 228 deletions(-) diff --git a/config.example b/config.example index b4d1ae8..e492247 100644 --- a/config.example +++ b/config.example @@ -87,18 +87,18 @@ endpoint workstation { endpoint cloud { base https://api.example.com/v1 kind cloud - # Rückfall, keine Wahrheit: die Grenzen der Modelle holt junction beim Start aus - # der Modellliste des Endpunkts (GET /models → limit.context / limit.output). - # Diese Zahl gilt nur, wenn der Abruf scheitert oder das Modell dort fehlt. + # A fallback, not a truth: junction reads the model limits from the endpoint's own + # model list at startup (GET /models -> limit.context / limit.output). This number + # applies only when that fetch fails or the model is missing from it. context 200000 priority 90 timeout 900 idle_timeout 120 cache off # never store cloud answers api_key_env EXAMPLE_API_KEY - # Zweites Konto, zweites Kontingent: die Zeile darf mehrfach stehen. Jeder Versuch - # nimmt den nächsten Schlüssel, ein 429 auf dem ersten wird also mit dem zweiten - # beantwortet, statt den Endpunkt aufzugeben. + # A second account is a second quota: the line may be repeated. Each attempt takes + # the next key, so a 429 on the first is answered with the second instead of giving + # the endpoint up. # api_key_env EXAMPLE_API_KEY_2 tls_verify on # off only for a self-signed internal endpoint # tls_ca /etc/junction/tls/internal-ca.pem @@ -107,13 +107,15 @@ endpoint cloud { # --------------------------------------------------------------------------- mcp # -# junction wird dadurch selbst zum MCP-Server: ein Agent verbindet sich mit -# http://127.0.0.1:8090/mcp und sieht die Werkzeuge aller hier eingetragenen -# Server, mit dem Servernamen als Präfix ("tasksd__task_create"). Ein toter -# Server wird übersprungen, die übrigen Werkzeuge kommen trotzdem. +# This turns junction into an MCP server itself: an agent connects to +# http://127.0.0.1:8090/mcp and sees the tools of every server listed here, with the +# server name as prefix ("tasksd__task_create"). A dead server is skipped and the other +# tools still arrive. # # mcp tasksd url http://127.0.0.1:8781/mcp # mcp skilld url http://127.0.0.1:8790/mcp header "Authorization: Bearer CHANGE_ME" +# A stdio server instead of an HTTP one is one quoted command: +# mcp local cmd "python3 /srv/mcp/filesystem.py --root /data" # mcp_cache_ttl 60 # A virtual key is a token junction mints: the client sends it, the real upstream key diff --git a/examples/full-reference.conf b/examples/full-reference.conf index bc33abb..15d5ca6 100644 --- a/examples/full-reference.conf +++ b/examples/full-reference.conf @@ -1,195 +1,196 @@ # ============================================================================ -# junction — vollständige Referenzkonfiguration +# junction — full reference configuration # ============================================================================ # -# Diese Datei enthält JEDEN Schlüssel, den der Parser kennt, jeweils mit einer -# Erklärung und einem sinnvollen Wert. Sie ist zum Abschreiben gedacht: für den -# Betrieb die überflüssigen Endpunkte löschen, nicht die Erklärungen. +# This file contains EVERY key the parser knows, each with an explanation and a +# sensible value. It is meant to be copied from: for production, delete the +# endpoints you do not need, not the explanations. # -# Grammatik: Schlüsselwort, Argumente, geschweifte Klammern. `#` ist Kommentar, -# doppelte Anführungszeichen fassen Wörter zusammen. Ein unbekanntes Schlüsselwort -# ist ein harter Fehler mit Zeilennummer — es gibt keine stillen Tippfehler. +# Grammar: keyword, arguments, braces. `#` starts a comment, double quotes group +# words. An unknown keyword is a hard error with a line number — there are no +# silent typos. # -# Prüfen ohne zu starten: junction --config diese-datei --check +# Check without starting: junction --config this-file --check # ============================================================================ -# ---------------------------------------------------------------- Zuhörer +# ---------------------------------------------------------------- listener # -# Wohin junction lauscht. Ohne `tls` reines HTTP. Mit `tls` zwei Zertifikatspfade -# in dieser Reihenfolge: Zertifikat, Schlüssel. +# Where junction listens. Plain HTTP without `tls`. With `tls`, two certificate +# paths in this order: certificate, key. # -# Loopback ist die richtige Wahl, wenn der Prozess echte Upstream-Schlüssel in -# seiner Umgebung hält — er ist dann kein offener Proxy für LAN oder VPN. +# Loopback is the right choice when the process holds real upstream keys in its +# environment — then it is not an open proxy for LAN or VPN. listen 127.0.0.1:8090 # listen 0.0.0.0:8443 tls /etc/junction/tls/cert.pem /etc/junction/tls/key.pem -# Präfix jeder Logzeile. Steht hier, damit im Code kein Produktname auftaucht. +# Prefix of every log line. It lives here so no product name appears in the code. log_prefix junction -# ---------------------------------------------------------------- Zeitlimits +# ---------------------------------------------------------------- time limits # -# Verbindungsaufbau zum Endpunkt. Ein Fehlschlag hier heißt sofort "offline" — -# das ist kein Wiederholfall, ein nicht antwortender Rechner wird nicht besser, -# wenn man ihn zweimal fragt. +# Connecting to the endpoint. A failure here means "offline" immediately — that is +# not a retry case, a machine that does not answer does not get better by asking +# twice. connect_timeout_ms 1500 -# Wie lange ein Endpunkt nach einem Verbindungsfehler als offline gilt, bevor -# ihn der nächste Versuch wieder prüft. Sekunden. +# How long an endpoint counts as offline after a connect failure, before the next +# attempt probes it again. Seconds. offline_hold_s 20 -# Obergrenze für einen Anfragekörper. Schutz gegen einen Client, der den Router -# als Speicher missbraucht. +# Upper bound for a request body. Protection against a client using the router as +# storage. max_body_bytes 67108864 -# ---------------------------------------------------------------- Nebenläufigkeit +# ---------------------------------------------------------------- concurrency # -# Wie viele Anfragen gleichzeitig zu Upstreams unterwegs sein dürfen. Der Rest -# wartet in einer Schlange, statt abgewiesen zu werden. +# How many requests may be on their way to upstreams at the same time. The rest +# wait in line instead of being refused. max_inflight 8 -# Wie lange ein Wartender höchstens in der Schlange steht, bevor er eine Antwort -# bekommt. Sekunden. Danach: Fehlerereignis, bei Streamern gefolgt von [DONE]. +# How long a waiting request may stand in line before it gets an answer. Seconds. +# Afterwards: an error event, followed by [DONE] for streamers. queue_timeout 300 -# Zweiter Versuch, bevor die Kette weiterzieht. 429/408/5xx sind oft in Sekunden -# vorbei; der nächste Link kostet dagegen Geld oder Kontext. Verbindungsfehler werden -# NICHT wiederholt (die heißen offline, dafür sind die Hooks da), und nach dem -# Streaming-Kopf wird nie wiederholt. Retry-After wird nicht ausgewertet. +# A second attempt before the chain moves on. 429/408/5xx are often over in +# seconds; the next link costs money or context instead. Connect failures are NOT +# retried (those mean offline, that is what the hooks are for), and nothing is +# retried after the streaming head has gone out. Retry-After is not evaluated. retry_num 1 retry_backoff 0.5 -# Ganze Kette offline? Ein Request darf so lange warten, statt sofort 503 zu bekommen. -# Im Van ist der Uplink oft für Sekunden weg. Bewusst vor dem Warteschlangenplatz: -# wer wartet, belegt keinen Upstream-Platz. 0 = nicht warten. +# Whole chain offline? A request may wait this long instead of getting a 503 at +# once. In the van the uplink is often gone for seconds. Deliberately before the +# queue slot: a request that waits holds no upstream place. 0 = do not wait. offline_wait 20 -# ---------------------------------------------------------------- Überwachung +# ---------------------------------------------------------------- monitoring # -# Ein zweiter Listener, der ausschließlich GET /metrics beantwortet. Prometheus läuft -# hier im Container und kommt an das Loopback des Hosts nicht heran; statt /v1 und -# /admin ins Netz zu legen, gibt es genau diesen einen lesenden Port. +# A second listener that answers GET /metrics and nothing else. Prometheus runs in +# a container here and cannot reach the host's loopback; instead of putting /v1 and +# /admin on the network, there is exactly this one read-only port. metrics tcp 192.168.1.148:9180 -# ---------------------------------------------------------------- Wächter +# ---------------------------------------------------------------- guard # -# Ein Kommando, das jede Anfrage sieht, bevor sie geroutet wird: exit 0 = durchlassen, -# alles andere = 403 mit stdout als Begründung. junction bringt keine eigene Inhaltsregel -# mit. Der Rumpf kommt als Datei (JUNCTION_BODY_FILE), nicht über stdin — ein Skript, das -# nur einen Teil liest, würde sonst beim Schreiben in eine volle Pipe hängen. +# A command that sees every request before it is routed: exit 0 = let it through, +# anything else = 403 with stdout as the reason. junction brings no content rule of +# its own. The body arrives as a file (JUNCTION_BODY_FILE), not on stdin — a script +# that reads only part of it would otherwise hang writing into a full pipe. # -# Nur die Anfrage wird geprüft. Eine Antwort zu prüfen hieße, jeden Stream zu puffern — -# genau das, was dieser Router nicht tut. +# Only the request is inspected. Inspecting the answer would mean buffering every +# stream — exactly what this router does not do. # # guard request cmd "/home/lotherk/.hermes/scripts/guard.sh" -# ---------------------------------------------------------------- Antwort-Cache +# ---------------------------------------------------------------- response cache # -# Nur im Speicher, LRU, Schlüssel ist Methode + Pfad + Modell + Körper. Streams -# werden nie zwischengespeichert. `Cache-Control: no-store/private` des Upstreams -# und `no-cache` des Clients werden respektiert. +# Memory only, LRU, key is method + path + model + body. Streams are never cached. +# The upstream's `Cache-Control: no-store/private` and the client's `no-cache` are +# respected. # -# 0 bedeutet: Cache aus. Ein Cache auf einem Router, der Modelle mit -# unterschiedlichen Temperaturen bedient, ist meist falsch — deshalb hier aus. +# 0 means: cache off. A cache on a router that serves models at different +# temperatures is usually wrong — hence off here. cache_ttl 0 cache_entries 0 cache_bytes 0 -# Nur Anfragen zwischenspeichern, deren Antwort vorhersagbar ist: Temperatur 0, oder -# ein Einbetter (derselbe Text ergibt immer denselben Vektor). Eine Antwort mit -# Temperatur 0.7 zwischenzuspeichern hieße, dem zweiten Fragesteller eine fremde -# Antwort zu geben — das ist keine Ersparnis, sondern eine falsche Antwort. +# Only cache requests whose answer is predictable: temperature 0, or an embedder +# (the same text always gives the same vector). Caching an answer with temperature +# 0.7 would hand the second caller someone else's answer — that is not a saving, +# it is a wrong answer. cache_deterministic_only on -# ---------------------------------------------------------------- Prompt-Größe +# ---------------------------------------------------------------- prompt size # -# Zeichen pro Token für die Schätzung, die Regeln mit `ctx` benutzen. 0 (Standard) heißt: -# keine Schätzung, und eine Regel mit ctx-Bedingung wird beim Laden abgelehnt — besser ein -# Fehler als eine Regel, die still nie greift. +# Characters per token for the estimate that `ctx` rules use. 0 (default) means: no +# estimate, and a rule with a ctx condition is refused at load time — an error beats +# a rule that silently never matches. # -# Der Wert ist eine Annahme über die Tokenisierung, keine Messung. Base64-Bilddaten werden -# bei der Zählung übersprungen, sonst zählt ein Foto als Hunderttausend Token. +# The value is an assumption about tokenisation, not a measurement. Base64 image +# data is skipped when counting, otherwise a photo counts as a hundred thousand +# tokens. ctx_chars_per_token 4 -# ---------------------------------------------------------------- Auswahlreihenfolge +# ---------------------------------------------------------------- selection order # -# Wie Ziele INNERHALB einer Regel geordnet werden, wenn mehrere genannt sind: -# first in der Reihenfolge der Regel (reiner Failover) -# round-robin reihum, gleichmäßig -# least-usage kleinster eigener Verbrauch zuerst (Prozent des Budgets) -# cost Verbrauch × Preis; im Off-Peak-Fenster halbiert sich der Preis +# How targets INSIDE one rule are ordered when several are named: +# first in the order of the rule (plain failover) +# round-robin in turns, evenly +# least-usage smallest own consumption first (percent of budget) +# cost consumption × price; in the off-peak window the price halves balance cost -# ---------------------------------------------------------------- virtuelle Schlüssel +# ---------------------------------------------------------------- virtual keys # -# Clients bekommen diese Schlüssel, nie den echten Upstream-Schlüssel. Der Wert -# steht in einer Umgebungsdatei (0600 root), hier steht nur der Name der Variable. +# Clients get these keys, never the real upstream key. The value lives in an +# environment file (0600 root); here stands only the name of the variable. # -# vkey "name" token_env VAR allow "" [endpoints "a,b"] [rpm N] [budget USD] +# vkey "name" token_env VAR allow "" [endpoints "a,b"] [rpm N] [budget USD] # -# `allow` begrenzt die Modelle, `endpoints` zusätzlich die Ziele. Ein Schlüssel, -# der nur DeepSeek darf, kann keinen GPT-Aufruf auslösen, selbst wenn eine Regel -# es erlauben würde. +# `allow` limits the models, `endpoints` additionally the targets. A key that may +# only use DeepSeek cannot trigger a GPT call, even if a rule would allow it. # -# rpm und budget begrenzen den Verbrauch EINES Clients (nicht den des Anbieters): -# über rpm antwortet junction mit 429 und Retry-After, über budget mit 403. Das -# Budget gilt je Kalendermonat und wird beim Start aus dem Spend-Log gerechnet — -# ohne das wäre es nach jedem Neustart wieder voll. +# rpm and budget limit the consumption of ONE client (not the provider's): above rpm +# junction answers 429 with Retry-After, above budget 403. The budget is per calendar +# month and is recomputed from the spend log at startup — without that it would be +# full again after every restart. vkey "webui" token_env VKEY_WEBUI allow "deepseek-*" rpm 60 budget 10 vkey "navigator" token_env VKEY_NAVIGATOR allow "*" endpoints "ollama1,ollama2" rpm 30 budget 5 vkey "hermes" token_env VKEY_HERMES allow "*" -# Buchführung: eine JSON-Zeile je Anfrage, die Verbrauch gemeldet hat. Ohne diese -# Datei gibt es keine Monatszahl und kein Budget, das einen Neustart übersteht. +# Bookkeeping: one JSON line per request that reported usage. Without this file +# there is no monthly figure and no budget that survives a restart. spend_log /var/lib/junction/spend.jsonl # ============================================================================ -# Endpunkte +# Endpoints # ============================================================================ -# ---------------------------------------------------------------- Abo-Cloud +# ---------------------------------------------------------------- subscription cloud # -# Der teuerste Weg pro Anfrage, aber bezahlt: die Grenzkosten sind fast null. -# `cost` ist hier ein Vergleichsgewicht, kein Geldbetrag. +# The most expensive path per request, but already paid for: the marginal cost is +# nearly zero. `cost` here is a comparison weight, not a sum of money. endpoint cloud { base https://opencode.ai/zen/go/v1 kind cloud context 200000 - # Niedrigere Zahl gewinnt, wenn eine Regel mehrere Ziele ohne eigene - # Reihenfolge nennt. Relevant nur bei balance first. + # Lower number wins when a rule names several targets without an order of its + # own. Only relevant with balance first. priority 90 - # Gesamtzeit für eine Anfrage und Stille-Zeit bis "still_working" im Log - # steht. Zwei Werte, weil ein denkendes Modell nicht hängt. + # Total time for one request and the silence until "still_working" appears in + # the log. Two values, because a thinking model is not hanging. timeout 900 idle_timeout 120 - # Eigenes Verbindungs-Zeitlimit: dieses Ziel steht hinter einem Tunnel, ein - # ausgefallener Aufbau soll die Kette nach 400 ms weiterreichen, nicht nach 1,5 s. + # Its own connect limit: this target sits behind a tunnel, a failed connect + # should pass the chain on after 400 ms, not after 1.5 s. connect_timeout_ms 400 tls_verify on api_key_env OPENCODE_GO_API_KEY - # Manche Upstreams hinter Cloudflare weisen fremde User-Agents ab (403/1010) - # und verlangen eine Session-Kennung. header ist wiederholbar. + # Some upstreams behind Cloudflare refuse foreign user agents (403/1010) and + # want a session id. header may be repeated. header "User-Agent: Mozilla/5.0 (X11; Linux x86_64) Olivia-UI/1.0" header "x-opencode-session: ses-olivia-webui" - # Verbrauch von außen messen: das Skript gibt eine Zahl aus, junction pollt sie. + # Measure consumption from outside: the script prints one number, junction + # polls it. usage_cmd /home/lotherk/.hermes/scripts/junction_usage_opencode.sh usage_poll 120 - # Weiche und harte Grenze in Prozent. Über soft wird gedrosselt, über hard - # übersprungen — aber nur, wenn eine Regel noch ein anderes Ziel nennt. + # Soft and hard limit in percent. Above soft the request is slowed, above hard + # the endpoint is skipped — but only when a rule names another target. budget soft 85 budget hard 96 on_soft delay 2 @@ -199,13 +200,12 @@ endpoint cloud { cache off } -# ---------------------------------------------------------------- Guthaben-Cloud, zwei Konten +# ---------------------------------------------------------------- credit cloud, two accounts # -# Zwei Konten desselben Anbieters, je mit eigenem Monatsguthaben. Beide Endpunkte -# sind gleich aufgebaut; unterschieden werden sie nur durch Schlüssel, Verbrauchs- -# messung und Priorität. -# Gewicht: höher = häufiger. Unter round-robin bekommt ein Ziel mit Gewicht 3 drei -# Plätze in der Runde, unter cost/least-usage zählt sein Verbrauch nur ein Drittel. +# Two accounts of the same provider, each with its own monthly credit. Both +# endpoints look alike; they differ only in key, usage measurement and priority. +# Weight: higher = more often. Under round-robin a target with weight 3 gets three +# slots in the round; under cost/least-usage its consumption counts one third. endpoint ollama1 { weight 3 base https://ollama.com/v1 @@ -224,9 +224,8 @@ endpoint ollama1 { on_soft delay 1 on_hard skip - # Fenster, in dem dieser Endpunkt billiger ist: von 18:00 bis 12:00 des - # Folgetages. Ein Fenster, nicht zwei — "Wochenende ganztägig" lässt sich - # damit nicht ausdrücken. + # Window in which this endpoint is cheaper: from 18:00 to 12:00 of the following + # day. One window, not two — "all weekend" cannot be expressed with it. offpeak 18:00-12:00 cost 1.5 } @@ -234,10 +233,10 @@ endpoint ollama1 { endpoint ollama2 { base https://ollama.com/v1 kind cloud - # Zwei Konten als zwei Endpunkte: so bleibt die Quote pro Konto sichtbar - # (usage_cmd 1 vs. 2). Als ein Endpunkt mit zwei api_key_env-Zeilen würde junction - # bei 429 auf das zweite Konto rotieren, aber usage_cmd und /api/show liefen nur - # mit dem ersten Schlüssel — die Quote des zweiten Kontos bliebe unsichtbar. + # Two accounts as two endpoints: that keeps the quota per account visible + # (usage_cmd 1 vs. 2). As one endpoint with two api_key_env lines junction would + # rotate to the second account on a 429, but usage_cmd and /api/show would only + # run with the first key — the second account's quota would stay invisible. context 128000 priority 50 timeout 900 @@ -254,10 +253,10 @@ endpoint ollama2 { cost 1.5 } -# ---------------------------------------------------------------- lokaler Rechner mit Aufwecken +# ---------------------------------------------------------------- local machine with wake-up # -# Der interessante Fall: eine Workstation, die schläft. `wake` läuft einmal, -# bevor die Haken wiederholt werden — erst wecken, dann warten. +# The interesting case: a workstation that sleeps. `wake` runs once before the hooks +# are repeated — wake first, then wait. endpoint workstation { base http://192.0.2.20:8080/v1 kind local @@ -266,33 +265,33 @@ endpoint workstation { timeout 1800 idle_timeout 30 - # Haken: Exit 0 heißt benutzbar, alles andere "noch nicht". Der Grund, den - # der Haken auf stdout schreibt, landet in /status und im 503-Körper. + # Hook: exit 0 means usable, anything else "not yet". The reason the hook prints + # on stdout lands in /status and in the 503 body. hook /usr/local/share/junction/hooks/check-http.sh - # Wie lange insgesamt auf den Rechner gewartet wird und in welchem Abstand. + # How long to wait for the machine in total, and at what interval. hook_retry 180 hook_backoff 5 - # Einmaliger Weckruf vor dem ersten Wiederholen. + # One wake-up call before the first repeat. wake /usr/local/share/junction/hooks/wake-wol.sh - # Statischer Kopfzeilen-Zusatz pro Endpunkt. + # Static header addition per endpoint. header "X-Box: workstation" - # Kann dieser Endpunkt Bilder? on = ja, off = nein, weglassen = keine Prüfung. - # Ein Text-Endpunkt wird für eine Bildanfrage übersprungen, statt sie anzunehmen - # und mit leerem Inhalt zu antworten. + # Can this endpoint read images? on = yes, off = no, omit = no check. + # A text endpoint is skipped for an image request instead of accepting it and + # answering with empty content. vision off - # Ein lokaler Rechner kostet Strom, kein Geld. Kleines Gewicht, damit er im - # Vergleich gewinnt, solange er wach ist. + # A local machine costs electricity, not money. Small weight so it wins the + # comparison while it is awake. cost 0.0 cache on tls_verify off } -# ---------------------------------------------------------------- privates TLS mit eigener CA +# ---------------------------------------------------------------- private TLS with its own CA endpoint private-tls { base https://llm.internal.example/v1 kind remote @@ -309,12 +308,12 @@ endpoint private-tls { # ---------------------------------------------------------------- opencode serve # -# opencode spricht kein OpenAI-Protokoll: seine API ist sitzungsorientiert -# (/api/session, /prompt, /model, /message). Mit `kind opencode` übersetzt junction das -# in beide Richtungen, sodass ein Client weiter /v1/chat/completions spricht. +# opencode does not speak the OpenAI protocol: its API is session-oriented +# (/api/session, /prompt, /model, /message). With `kind opencode` junction translates +# in both directions, so a client keeps speaking /v1/chat/completions. # -# Zwei Werte kommen aus Kommandos, weil opencode sie nicht festhält: der Hintergrund- -# dienst bindet einen freien Port, und er erzeugt bei jedem Start ein neues Passwort. +# Two values come from commands because opencode does not pin them: the background +# service binds a free port, and it creates a new password on every start. endpoint opencode { base http://127.0.0.1:4096 kind opencode @@ -323,12 +322,12 @@ endpoint opencode { idle_timeout 120 auth_basic opencode pass_cmd /home/lotherk/.hermes/scripts/opencode_password.sh - # Nur nötig, wenn der Dienst auf einem zufälligen Port läuft: + # Only needed when the service runs on a random port: # base_cmd "/home/lotherk/.opencode/bin/opencode service status" cost 0.0 } -# ---------------------------------------------------------------- Einbetter, klein und billig +# ---------------------------------------------------------------- embedder, small and cheap endpoint embed { base http://192.168.1.116:11434/v1 kind local @@ -336,90 +335,93 @@ endpoint embed { priority 10 timeout 120 idle_timeout 45 - # Nach einem Fehlschlag so viele Sekunden Pause, statt bei jeder Anfrage neu - # in ein Timeout zu laufen. + # After a failure, pause this many seconds instead of running into a timeout + # again on every request. cooldown 30 cache on } # ============================================================================ -# Regeln — erste Übereinstimmung gewinnt +# Rules — first match wins # ============================================================================ # -# req [for ] [path ] [need >N | ] [path ] [need >N | ] -# ( pass [,...] [as ] | block ) +# ( pass [,...] [as ] | block ) # -# for — Modellname aus dem Anfragekörper, fnmatch-Muster -# path — Pfad, fnmatch-Muster -# need — das vom Client ANGEGEBENE Ausgabebudget (max_tokens / -# max_completion_tokens). Kein Raten, keine Zeichenzählung: eine Anfrage -# ohne Angabe erfüllt keine need-Regel. >64000 heißt "mehr als 64k -# angefordert"; ein Endpunkt mit kleinerem context wird dann übersprungen. -# check — haken (Standard des Endpunkts) oder none (Haken überspringen, z.B. bei -# Modell-Listen, die auch dann sinnvoll sind, wenn nichts läuft) -# retry — Wartezeit für Haken, überschreibt hook_retry dieser Regel -# as — schreibt das Modellfeld NUR für dieses Ziel um. Der erste Ziel bekommt -# die lokale Kennung, der letzte die angefragte. +# for — model name from the request body, fnmatch pattern +# path — path, fnmatch pattern +# need — the output budget the client DECLARES (max_tokens / +# max_completion_tokens). No guessing, no character counting: a request +# that states nothing matches no need rule. >64000 means "more than 64k +# requested"; an endpoint with a smaller context is then skipped. +# check — hooks (the endpoint's default) or none (skip hooks, e.g. for model +# lists that make sense even when nothing is running) +# retry — wait time for hooks, overrides this rule's hook_retry +# as — rewrites the model field ONLY for that target. The first target gets the +# local id, the last the requested one. -# Modell-Liste: kein Haken nötig, sie beantwortet auch ein schlafender Rechner. +# Model list: no hook needed, a sleeping machine answers it too. req path "/v1/models" check none pass cloud -# Einbetter laufen lokal, egal was sonst gilt. +# Embedders run locally, no matter what else applies. req for "*embed*" check none pass embed -# Die freien opencode-Modelle gehen an den opencode-Endpunkt, alles andere nicht. +# The free opencode models go to the opencode endpoint, nothing else does. req for "opencode/*" pass opencode req for "*-free" pass opencode -# Bildanfragen: immer an das Bildmodell, unabhängig vom angefragten Namen. Erst der -# eigene Rechner (kostet nichts), dann die Cloud — dort mit umgeschriebenem Modellnamen. -# "as" gilt für das Ziel direkt davor, nicht für die ganze Regel. +# Image requests: always to the image model, independent of the requested name. +# First the own machine (costs nothing), then the cloud — there with a rewritten +# model name. "as" applies to the target directly before it, not to the whole rule. req vision pass workstation, cloud as "vision-capable-model" -# Kleine Anfragen an den eigenen Rechner, mittlere an das Guthaben, große an das Abo mit -# dem großen Kontext. Reihenfolge zählt: das engste Fenster zuerst, sonst fängt das -# größere alles ab. Die Zahlen sind Politik und gehören hierher, nicht in den Code. +# Small requests to the own machine, medium ones to the credit account, large ones to +# the subscription with the big context. Order matters: narrowest window first, +# otherwise the larger one catches everything. The numbers are policy and belong +# here, not in the code. req ctx <2000 pass workstation req ctx <50000 pass ollama1, cloud req ctx >50000 pass cloud -# Große Budgets kann der lokale Rechner nicht halten — also gar nicht erst hin. +# Large budgets cannot be held by the local machine — so do not send them there. req need >64000 pass cloud, ollama1 -# Ein Modell, das es nur lokal gibt, mit lokalem Namen; sonst dieselbe Anfrage -# an die Cloud weitergereicht. +# A model that only exists locally, with a local name; otherwise the same request is +# passed on to the cloud. req for "*coder*" retry 300 pass workstation as "qwen3.8-flash-next-q1m", cloud -# Ein Modell, das es nicht geben darf. 403, kein stilles Umleiten. +# A model that must not exist. 403, not a silent redirect. req for "blocked-*" block -# Alles Übrige: erst der wache lokale Rechner, dann die Cloud, dann Guthaben. -# Kein Treffer für eine Anfrage bedeutet 503 no_matching_rule — eine Lücke in der -# Konfiguration ist kein Fall für "irgendwohin schicken". -# Ketten einen Namen geben. Ein Pool darf auch auf einen anderen verweisen; beim Laden -# wird er aufgelöst, damit eine Regel nicht jedes Mal fünf Ziele ausschreiben muss. +# Everything else: first the awake local machine, then the cloud, then credits. +# No match for a request means 503 no_matching_rule — a gap in the configuration is +# not a case for "send it somewhere". +# Give chains a name. A pool may point at another pool; it is resolved at load time, +# so a rule does not have to spell out five targets every time. pool lokal ollama1, ollama2 pool alles cloud, lokal -# Ein Endpunkt darf auch in einer Zeile stehen, wenn er klein ist: +# An endpoint may also fit on one line when it is small: # endpoint kurz { base http://127.0.0.1:8080/v1; timeout 60 } -# Diese eine Regel will reines Failover, egal was global eingestellt ist. +# This one rule wants plain failover, whatever the global setting is. req for "starr*" balance first pass workstation, cloud req for "*" check hooks pass workstation, cloud, ollama1, ollama2 # ============================================================================ -# Steuerung zur Laufzeit +# Control at runtime # ============================================================================ # -# GET /status Endpunkte, Zähler, Cache, Regeln, Schlange -# POST /admin/pause/ dort nicht mehr routen -# POST /admin/resume/ Pause, Abkühlung und Offline zurücksetzen -# POST /admin/flush/cache jeden zwischengespeicherten Antwortkörper verwerfen +# GET /status endpoints, counters, cache, rules, queue +# GET /metrics the same numbers as Prometheus text +# GET /spend[?month=YYYY-MM] cost per key and model, from the spend log +# POST /admin/pause/ stop routing there +# POST /admin/resume/ clear pause, cooldown and offline +# POST /admin/flush/cache drop every cached response body # -# Alles andere wird an den Endpunkt weitergeleitet, den die Regeln wählen. -# Jede Antwort trägt X-Junction-Endpoint, X-Junction-Ms und X-Junction-Cache. +# Everything else is forwarded to the endpoint the rules choose. +# Every response carries X-Junction-Endpoint, X-Junction-Ms and X-Junction-Cache. diff --git a/examples/prices.conf b/examples/prices.conf index 9fc7acc..f8344da 100644 --- a/examples/prices.conf +++ b/examples/prices.conf @@ -1,19 +1,19 @@ -# junction — Preise und Budgets +# junction — prices and budgets # -# Alle Werte in US-Dollar pro Million Token. Quelle: die Preisseite des Anbieters, -# abgerufen am 5. November 2026 (ollama.com/pricing). Preise ändern sich — diese Datei -# ist eine Abschrift, keine Messung. Wer sie nicht pflegt, bekommt alte Zahlen. +# Every value in US dollars per million tokens. Source: the provider's pricing page, +# fetched on 5 November 2026 (ollama.com/pricing). Prices change — this file is a +# transcript, not a measurement. Whoever does not maintain it gets old numbers. # -# Spalten: modell input cached_input output [schlüssel=wert …] +# Columns: model input cached_input output [key=value …] # -# offpeak=IN,OUT Preis außerhalb der Hauptzeit (bei Ollama: werktags 12–18 UTC -# und das ganze Wochenende sind NICHT off-peak) -# budget=USD Monatsbudget oder Gegenwert, den der Anbieter dem Modell zubilligt -# requests=N/5h Anzahl Anfragen pro Zeitfenster +# offpeak=IN,OUT price outside peak hours (at Ollama: weekdays 12–18 UTC +# and the whole weekend are NOT off-peak) +# budget=USD monthly budget, or the allowance the provider grants the model +# requests=N/5h number of requests per window # -# Modelle ohne Eintrag kosten nicht 0, sondern unbekannt — das steht so im Log. +# A model without a line does not cost 0, it costs unknown — and the log says so. # -# --- Ollama Cloud (Pay as you go), Preise pro Million Token --------------------- +# --- Ollama Cloud (pay as you go), prices per million tokens -------------------- clef 0.24 0.24 0.24 deepseek-v4.1-flash 0.30 0.006 1.20 offpeak=0.15,0.60 deepseek-v4-pro 1.32 0.044 3.96 offpeak=0.66,1.98 @@ -39,13 +39,12 @@ nemotron-3-nano 0.06 0.00 0.24 nemotron-3-super 0.015 0.015 0.60 nemotron-3-ultra 0.10 0.10 3.00 -# --- OpenCode Go: Abo, kein Tokenpreis ------------------------------------------ +# --- OpenCode Go: subscription, not a token price ------------------------------- # -# Go kostet 10 USD im Monat (Go Plus 40) und begrenzt nicht das Geld, sondern die -# Anfragen pro Modell. Die Spalte budget ist hier der Gegenwert, den OpenCode dem Modell -# zubilligt, requests die Grenze pro Fünf-Stunden-Fenster. Ein Tokenpreis existiert -# nicht — deshalb in=out=0 und damit Kosten 0. Wer echte Kosten braucht, nimmt die -# Console (Pay as you go), nicht Go. +# Go costs 10 USD per month (Go Plus 40) and limits requests per model, not money. The +# budget column here is the allowance OpenCode grants the model, requests is the limit +# per five-hour window. There is no token price — hence in=out=0 and therefore cost 0. +# Whoever needs real costs takes the Console (pay as you go), not Go. kimi-k3-go 0 0 0 budget=15 requests=110/5h kimi-k3.1-pro-go 0 0 0 budget=15 requests=147/5h deepseek-v4-pro-go 0 0 0 budget=15 requests=1050/5h @@ -59,6 +58,6 @@ mimo-v2.6-flash-go 0 0 0 budget=60 requests=30100/5h deepseek-v4.1-flash-go 0 0 0 budget=100 requests=43330/5h muse-spark-open-go 0 0 0 budget=60 requests=45300/5h -# Kein "*"-Eintrag: ein Modell ohne Zeile kostet unbekannt, nicht null. Lokale Boxen -# lassen sich bei Bedarf mit ihrem Modellnamen und 0.0 eintragen — dann steht dort -# ausdrücklich "kostenlos" statt "vielleicht". +# No "*" line: a model without one costs unknown, not null. Local boxes can be listed +# with their model name and 0.0 when wanted — then it explicitly says "free" instead of +# "maybe". diff --git a/packaging/junction.service b/packaging/junction.service index 2dcf48d..3323a06 100644 --- a/packaging/junction.service +++ b/packaging/junction.service @@ -1,10 +1,16 @@ [Unit] -# Vorlage für /etc/systemd/system/junction.service (oder eine Kopie unter -# ~/.config/systemd/user/). make install legt nur das Binary ab, nicht die Einheit: -# Pfade und Umgebungsdateien sind je Host verschieden. +# Template for /etc/systemd/system/junction.service (or a copy under +# ~/.config/systemd/user/). make install only lays down the binary, not the unit: +# paths and environment files differ per host. Description=junction — model router (rules, failover, wake, passthrough) After=network-online.target Wants=network-online.target +# A router in front of the local agents must not be the thing that dies quietly: with +# Restart=always alone, systemd stops restarting after five starts in ten seconds (the +# default), and a crash loop leaves the router dead. These two keys belong in [Unit] — +# in [Service] systemd ignores them without a word. +StartLimitIntervalSec=0 +StartLimitBurst=0 [Service] Type=simple @@ -16,18 +22,15 @@ Environment=HOME=/home/lotherk EnvironmentFile=/home/lotherk/.hermes/.env # Upstream keys for ollama, budgets, virtual keys (0600 root) EnvironmentFile=-/etc/junction/junction.env -# Der Unix-Steuerkanal liegt unter /run/junction — /run ist tmpfs und nach jedem -# Neustart leer. Ohne RuntimeDirectory scheitert der Bind mit "No such file or -# directory": junction läuft weiter und meldet nur über TCP, das Dashboard (das den -# Socket benutzt) zeigt dagegen stillschweigend nichts mehr. Genau das ist einmal -# passiert — deshalb gehört die Zeile hierher und nicht in ein Gedächtnis. +# The unix control socket lives in /run/junction — /run is tmpfs and empty after every +# reboot. Without RuntimeDirectory the bind fails with "No such file or directory": +# junction keeps running and only reports over TCP, while the dashboard (which uses the +# socket) silently shows nothing. That is exactly what happened once — which is why the +# line belongs here and not in somebody's memory. RuntimeDirectory=junction RuntimeDirectoryMode=0750 ExecStart=/usr/local/bin/junction --config /etc/junction/junction.conf Restart=always RestartSec=3 -# A router in front of the local agents must not be the thing that dies quietly. -StartLimitIntervalSec=0 - [Install] WantedBy=multi-user.target diff --git a/web/README.md b/web/README.md index 8d5d15f..02378f5 100644 --- a/web/README.md +++ b/web/README.md @@ -1,26 +1,28 @@ # junction dashboard -Steuerung und Verlauf für den Router. Node, ohne Abhängigkeiten, ohne Build. +Control and history for the router. Node, no dependencies, no build step. ```sh JUNCTION_SOCKET=/run/junction/control.sock DASH_PORT=8092 node server.js ``` -Das Dashboard spricht ausschließlich über den Steuerkanal mit junction -(`control unix …` in der Konfiguration) und liest dort `status`, `rules.list` -und `config.get`. Es ändert nichts, was junction nicht auch selbst könnte. +The dashboard talks to junction exclusively over the control channel +(`control unix …` in the configuration) and reads `status`, `rules.list`, +`mcp.tools`, `bringup.list`, `wol.list`, `guard.list` and `spend.get`. It changes +nothing junction could not do itself. -| Seite | Zweck | +| Page | Purpose | |---|---| -| Übersicht | Anfragen/s, Token/s, Latenz, Kosten/h, Fehler — als Verlauf, nicht als Momentwert | -| Endpunkte | Zustand, Zähler, laufende Anfragen, letzte Dauer; pausieren und aufnehmen | -| Regeln | alle Regeln mit Bedingungen, löschen, neue Zeile setzen (greift sofort) | -| Konfiguration | Datei laden, ändern, prüfen und speichern — mit Sicherung als `.bak` | +| Overview | requests/s, tokens/s, latency, cost/h, errors — as history, not as a snapshot | +| Endpoints | state, counters, requests in flight, last duration; pause and resume | +| Rules | every rule with its conditions, delete, add a line (applies immediately) | +| Keys and month | per virtual key: model glob, rpm, budget, spend, requests, refusals; month total per model | +| Configuration | load the file, edit, check and save — with a `.bak` backup | -Der Server hält 15 Minuten Verlauf (1 Messpunkt je Sekunde). Was junction nicht -meldet, bleibt in der Anzeige leer (`—`) statt als Null durchzugehen: eine -Latenz von 0 wäre eine Behauptung, die niemand gemessen hat. +The server keeps 15 minutes of history (one sample per second). What junction does not +report stays empty (`—`) instead of passing as zero: a latency of 0 would be a claim +nobody measured. -Variablen: `DASH_PORT` (8092), `DASH_BIND` (0.0.0.0), `DASH_TOKEN` (optional, -dann `Authorization: Bearer …` oder `?token=`), `SAMPLE_MS`, `HISTORY`, -`JUNCTION_SOCKET` oder `JUNCTION_TCP=host:port`. +Variables: `DASH_PORT` (8092), `DASH_BIND` (0.0.0.0), `DASH_TOKEN` (optional, then +`Authorization: Bearer …` or `?token=`), `SAMPLE_MS`, `HISTORY`, `JUNCTION_SOCKET` or +`JUNCTION_TCP=host:port`.