- A rule may send a different model name per target: 'pass peer-a as M, peer-b, cloud' rewrites only for peer-a, so a mixed local/cloud rule still asks the cloud for the name the client wanted. - examples/olivia.conf: peers on the tunnel, embedding box, sleeping workstation with WoL + energy gate, cloud fallback, and the policy rules each with its reason. - tools/junction-wol.c replaces the Python magic-packet helper; hooks stay shell. - Forwarding no longer duplicates Host/Content-Length/X-Forwarded-*: Ollama answered 400 to a request that was valid because it arrived with two Host headers. - need_tokens: embeddings produce a vector, not tokens, so they are not charged default_max_tokens (a 2048-context embed endpoint refused every request). - /status lists every target with its model, plus the rule's need window.
32 lines
1.1 KiB
Bash
Executable File
32 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# "May I spend energy on this?" — refuse when a number from a JSON document is below
|
|
# a threshold. Typical source: a Home Assistant sensor state.
|
|
# JUNCTION_BUDGET_URL http://127.0.0.1:8123/api/states/sensor.smartshunt_soc
|
|
# JUNCTION_BUDGET_MIN 55
|
|
# JUNCTION_BUDGET_TOKEN optional bearer token for that URL
|
|
#
|
|
# Pure sh + sed/awk: a hook has no business starting an interpreter.
|
|
url="${JUNCTION_BUDGET_URL:-}"
|
|
min="${JUNCTION_BUDGET_MIN:-0}"
|
|
[ -z "$url" ] && exit 0 # not configured = do not gate
|
|
|
|
if [ -n "${JUNCTION_BUDGET_TOKEN:-}" ]; then
|
|
body=$(curl -s -m 4 -H "Authorization: Bearer $JUNCTION_BUDGET_TOKEN" "$url" 2>/dev/null)
|
|
else
|
|
body=$(curl -s -m 4 "$url" 2>/dev/null)
|
|
fi
|
|
[ -n "$body" ] || { echo "budget_source_unreachable"; exit 1; }
|
|
|
|
value=$(printf '%s' "$body" | tr -d '\n' |
|
|
sed -n 's/.*"state"[[:space:]]*:[[:space:]]*"\{0,1\}\([-0-9.][0-9.]*\)"\{0,1\}.*/\1/p' |
|
|
head -n 1)
|
|
case "$value" in
|
|
''|*[!0-9.]*) echo "budget_unreadable: ${value:-empty}"; exit 1 ;;
|
|
esac
|
|
|
|
if awk -v v="$value" -v m="$min" 'BEGIN { exit !(v + 0 >= m + 0) }'; then
|
|
exit 0
|
|
fi
|
|
echo "budget_${value}_below_${min}"
|
|
exit 1
|